Skip to content

Commit

Permalink
[Spotless] Applying Google Code Format for legacy directory (pt 1/4) #19
Browse files Browse the repository at this point in the history
 (#1988)

* spotless apply for OpenSearch P1.

Signed-off-by: Mitchell Gale <[email protected]>

* Manual spotless changes

Signed-off-by: Mitchell Gale <[email protected]>

* spotless apply for OpenSearch P2.

Signed-off-by: Mitchell Gale <[email protected]>

* 90 files checked after spotless apply for legacy

Signed-off-by: Mitchell Gale <[email protected]>

* Added checkstyle ignore failures to legacy

Signed-off-by: Mitchell Gale <[email protected]>

* Fixed comma issue

Signed-off-by: Mitchell Gale <[email protected]>

* Spotless apply

Signed-off-by: Mitchell Gale <[email protected]>

* Revert build.gradle

Signed-off-by: Mitchell Gale <[email protected]>

---------

Signed-off-by: Mitchell Gale <[email protected]>
Signed-off-by: Mitchell Gale <[email protected]>
  • Loading branch information
MitchellGale authored Aug 19, 2023
1 parent ff059f0 commit ac9b5d8
Show file tree
Hide file tree
Showing 92 changed files with 7,517 additions and 7,685 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@Fork(value = 1)
public class ComparisonOperatorBenchmark {

@Param(value = { "int", "string", "date" })
@Param(value = {"int", "string", "date"})
private String testDataType;

private final Map<String, ExprValue> params =
Expand All @@ -65,9 +65,7 @@ public void testGreaterOperator() {

private void run(Function<Expression[], FunctionExpression> dsl) {
ExprValue param = params.get(testDataType);
FunctionExpression func = dsl.apply(new Expression[] {
literal(param), literal(param)
});
FunctionExpression func = dsl.apply(new Expression[] {literal(param), literal(param)});
func.valueOf();
}
}
3 changes: 3 additions & 0 deletions legacy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ compileJava {
}
}

checkstyleTest.ignoreFailures = true
checkstyleMain.ignoreFailures = true

// TODO: Similarly, need to fix compiling errors in test source code
compileTestJava.options.warnings = false
compileTestJava {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.legacy.antlr.semantic.types.base;

import java.util.List;
import org.opensearch.sql.legacy.antlr.semantic.types.Type;

/**
* Base type interface
*/
/** Base type interface */
public interface BaseType extends Type {

@Override
default Type construct(List<Type> others) {
return this;
}
@Override
default Type construct(List<Type> others) {
return this;
}

@Override
default String usage() {
return getName();
}
@Override
default String usage() {
return getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.legacy.antlr.semantic.types.function;

import static org.opensearch.sql.legacy.antlr.semantic.types.base.OpenSearchDataType.DOUBLE;
Expand All @@ -15,41 +14,38 @@
import org.opensearch.sql.legacy.antlr.semantic.types.Type;
import org.opensearch.sql.legacy.antlr.semantic.types.TypeExpression;

/**
* Aggregate function
*/
/** Aggregate function */
public enum AggregateFunction implements TypeExpression {
COUNT(
func().to(INTEGER), // COUNT(*)
func(OPENSEARCH_TYPE).to(INTEGER)
),
MAX(func(T(NUMBER)).to(T)),
MIN(func(T(NUMBER)).to(T)),
AVG(func(T(NUMBER)).to(DOUBLE)),
SUM(func(T(NUMBER)).to(T));

private TypeExpressionSpec[] specifications;

AggregateFunction(TypeExpressionSpec... specifications) {
this.specifications = specifications;
}

@Override
public String getName() {
return name();
}

@Override
public TypeExpressionSpec[] specifications() {
return specifications;
}

private static TypeExpressionSpec func(Type... argTypes) {
return new TypeExpressionSpec().map(argTypes);
}

@Override
public String toString() {
return "Function [" + name() + "]";
}
COUNT(
func().to(INTEGER), // COUNT(*)
func(OPENSEARCH_TYPE).to(INTEGER)),
MAX(func(T(NUMBER)).to(T)),
MIN(func(T(NUMBER)).to(T)),
AVG(func(T(NUMBER)).to(DOUBLE)),
SUM(func(T(NUMBER)).to(T));

private TypeExpressionSpec[] specifications;

AggregateFunction(TypeExpressionSpec... specifications) {
this.specifications = specifications;
}

@Override
public String getName() {
return name();
}

@Override
public TypeExpressionSpec[] specifications() {
return specifications;
}

private static TypeExpressionSpec func(Type... argTypes) {
return new TypeExpressionSpec().map(argTypes);
}

@Override
public String toString() {
return "Function [" + name() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.legacy.antlr.semantic.types.operator;

import static org.opensearch.sql.legacy.antlr.semantic.types.base.OpenSearchDataType.BOOLEAN;
Expand All @@ -12,53 +11,50 @@
import java.util.List;
import org.opensearch.sql.legacy.antlr.semantic.types.Type;

/**
* Type for comparison operator
*/
/** Type for comparison operator */
public enum ComparisonOperator implements Type {

EQUAL("="),
NOT_EQUAL("<>"),
NOT_EQUAL2("!="),
GREATER_THAN(">"),
GREATER_THAN_OR_EQUAL_TO(">="),
SMALLER_THAN("<"),
SMALLER_THAN_OR_EQUAL_TO("<="),
IS("IS");

/** Actual name representing the operator */
private final String name;

ComparisonOperator(String name) {
this.name = name;
}

@Override
public String getName() {
return name;
}

@Override
public Type construct(List<Type> actualArgs) {
if (actualArgs.size() != 2) {
return TYPE_ERROR;
}

Type leftType = actualArgs.get(0);
Type rightType = actualArgs.get(1);
if (leftType.isCompatible(rightType) || rightType.isCompatible(leftType)) {
return BOOLEAN;
}
return TYPE_ERROR;
}

@Override
public String usage() {
return "Please use compatible types from each side.";
EQUAL("="),
NOT_EQUAL("<>"),
NOT_EQUAL2("!="),
GREATER_THAN(">"),
GREATER_THAN_OR_EQUAL_TO(">="),
SMALLER_THAN("<"),
SMALLER_THAN_OR_EQUAL_TO("<="),
IS("IS");

/** Actual name representing the operator */
private final String name;

ComparisonOperator(String name) {
this.name = name;
}

@Override
public String getName() {
return name;
}

@Override
public Type construct(List<Type> actualArgs) {
if (actualArgs.size() != 2) {
return TYPE_ERROR;
}

@Override
public String toString() {
return "Operator [" + getName() + "]";
Type leftType = actualArgs.get(0);
Type rightType = actualArgs.get(1);
if (leftType.isCompatible(rightType) || rightType.isCompatible(leftType)) {
return BOOLEAN;
}
return TYPE_ERROR;
}

@Override
public String usage() {
return "Please use compatible types from each side.";
}

@Override
public String toString() {
return "Operator [" + getName() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,71 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.legacy.antlr.syntax;

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.misc.Interval;

/**
* Custom stream to convert character to upper case for case insensitive grammar before sending to lexer.
* Custom stream to convert character to upper case for case insensitive grammar before sending to
* lexer.
*/
public class CaseInsensitiveCharStream implements CharStream {

/** Character stream */
private final CharStream charStream;
/** Character stream */
private final CharStream charStream;

public CaseInsensitiveCharStream(String sql) {
this.charStream = CharStreams.fromString(sql);
}
public CaseInsensitiveCharStream(String sql) {
this.charStream = CharStreams.fromString(sql);
}

@Override
public String getText(Interval interval) {
return charStream.getText(interval);
}
@Override
public String getText(Interval interval) {
return charStream.getText(interval);
}

@Override
public void consume() {
charStream.consume();
}
@Override
public void consume() {
charStream.consume();
}

@Override
public int LA(int i) {
int c = charStream.LA(i);
if (c <= 0) {
return c;
}
return Character.toUpperCase(c);
@Override
public int LA(int i) {
int c = charStream.LA(i);
if (c <= 0) {
return c;
}
return Character.toUpperCase(c);
}

@Override
public int mark() {
return charStream.mark();
}
@Override
public int mark() {
return charStream.mark();
}

@Override
public void release(int marker) {
charStream.release(marker);
}
@Override
public void release(int marker) {
charStream.release(marker);
}

@Override
public int index() {
return charStream.index();
}
@Override
public int index() {
return charStream.index();
}

@Override
public void seek(int index) {
charStream.seek(index);
}
@Override
public void seek(int index) {
charStream.seek(index);
}

@Override
public int size() {
return charStream.size();
}
@Override
public int size() {
return charStream.size();
}

@Override
public String getSourceName() {
return charStream.getSourceName();
}
@Override
public String getSourceName() {
return charStream.getSourceName();
}
}
Loading

0 comments on commit ac9b5d8

Please sign in to comment.