From 496fe8e5df5cfa3d15f8c6312bd89d54a51d6a83 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Tue, 25 Jul 2023 17:15:01 -0700 Subject: [PATCH 1/4] # This is a combination of 9 commits. # This is the 1st commit message: Fix create_index/create_index_with_IOException issue caused by OpenSearch PR change (#1899) * Added setDefaultMediaType for create_index and create_index_with_IOException Signed-off-by: Mitchell Gale (cherry picked from commit 7b932a7c882cbabbc9fcafcd864a39bb161bd122) Signed-off-by: Mitchell Gale Resolving merge conflicts for pre tag in java docs. Signed-off-by: Mitchell Gale running spotless check on newly pre tagged javadocs. Signed-off-by: Mitchell Gale Converts java doc table to proper java doc table. Signed-off-by: Mitchell Gale Resolving merge conflicts for pre tag in java docs 2 Signed-off-by: Mitchell Gale running spotless check on newly pre tagged javadocs. Signed-off-by: Mitchell Gale cherry pick 60c0018373b25e674d15c430f9754bcf2d02fb2a Signed-off-by: Mitchell Gale Addressed PR comment for table format in AbstractExprValue. Signed-off-by: Mitchell Gale Removed pre tag from ExpressionReferenceOptimizer. Signed-off-by: Mitchell Gale Removed pre tag from AstDSL.java Signed-off-by: Mitchell Gale Removed pre tag from AstDSL.java Signed-off-by: Mitchell Gale Removed pre tag from SelectExpressionAnalyzer.java Signed-off-by: Mitchell Gale fixed java doc in QualifiedName.java Signed-off-by: Mitchell Gale Removing checkstyle test for core and added spotless for relevant directories. Signed-off-by: Mitchell Gale # This is the commit message #2: Fixing spacing around headers in ExpressionReferenceOptimizer.java SelectExpressionAnalyzer.java Signed-off-by: Mitchell Gale # This is the commit message #3: Fix breaking changes. Disable some flaky tests in legacy. Signed-off-by: Yury-Fridlyand (cherry picked from commit 809e6567e77e5f47a93f3475e4badb7e3053b88c) Signed-off-by: Mitchell Gale # This is the commit message #4: Resolving merge conflicts for pre tag in java docs. Signed-off-by: Mitchell Gale # This is the commit message #5: running spotless check on newly pre tagged javadocs. Signed-off-by: Mitchell Gale # This is the commit message #6: Fixed java doc spelling and improving string concatination. Signed-off-by: Mitchell Gale # This is the commit message #7: improving string concatination. Signed-off-by: Mitchell Gale # This is the commit message #8: Improving failure format on some functions. Signed-off-by: Mitchell Gale # This is the commit message #9: spotless apply and fix of build.gradle Signed-off-by: Mitchell Gale --- build.gradle | 7 +- core/build.gradle | 3 + .../sql/analysis/AnalysisContext.java | 21 +- .../org/opensearch/sql/analysis/Analyzer.java | 242 +++++++++-------- ...ataSourceSchemaIdentifierNameResolver.java | 25 +- .../sql/analysis/ExpressionAnalyzer.java | 143 +++++----- .../ExpressionReferenceOptimizer.java | 83 +++--- .../sql/analysis/HighlightAnalyzer.java | 5 +- .../sql/analysis/NamedExpressionAnalyzer.java | 17 +- .../sql/analysis/NestedAnalyzer.java | 68 ++--- .../sql/analysis/QualifierAnalyzer.java | 22 +- .../analysis/SelectExpressionAnalyzer.java | 98 ++++--- .../sql/analysis/TypeEnvironment.java | 36 +-- .../analysis/WindowExpressionAnalyzer.java | 57 ++-- .../sql/analysis/symbol/Namespace.java | 7 +- .../sql/analysis/symbol/Symbol.java | 5 +- .../sql/analysis/symbol/SymbolTable.java | 78 +++--- .../sql/ast/AbstractNodeVisitor.java | 6 +- .../java/org/opensearch/sql/ast/Node.java | 5 +- .../org/opensearch/sql/ast/dsl/AstDSL.java | 16 +- .../sql/ast/expression/AggregateFunction.java | 9 +- .../opensearch/sql/ast/expression/Alias.java | 21 +- .../sql/ast/expression/AllFields.java | 8 +- .../opensearch/sql/ast/expression/And.java | 5 +- .../sql/ast/expression/Argument.java | 5 +- .../sql/ast/expression/AttributeList.java | 8 +- .../sql/ast/expression/Between.java | 4 +- .../opensearch/sql/ast/expression/Case.java | 18 +- .../opensearch/sql/ast/expression/Cast.java | 19 +- .../sql/ast/expression/Compare.java | 1 - .../sql/ast/expression/DataType.java | 9 +- .../sql/ast/expression/EqualTo.java | 11 +- .../opensearch/sql/ast/expression/Field.java | 9 +- .../sql/ast/expression/Function.java | 13 +- .../sql/ast/expression/HighlightFunction.java | 4 +- .../org/opensearch/sql/ast/expression/In.java | 8 +- .../sql/ast/expression/Interval.java | 1 - .../sql/ast/expression/IntervalUnit.java | 7 +- .../opensearch/sql/ast/expression/Let.java | 5 +- .../sql/ast/expression/Literal.java | 6 +- .../opensearch/sql/ast/expression/Map.java | 5 +- .../ast/expression/NestedAllTupleFields.java | 9 +- .../opensearch/sql/ast/expression/Not.java | 5 +- .../org/opensearch/sql/ast/expression/Or.java | 5 +- .../sql/ast/expression/ParseMethod.java | 4 +- .../sql/ast/expression/QualifiedName.java | 36 ++- .../ast/expression/RelevanceFieldList.java | 12 +- .../sql/ast/expression/ScoreFunction.java | 4 +- .../opensearch/sql/ast/expression/Span.java | 6 +- .../sql/ast/expression/SpanUnit.java | 5 +- .../ast/expression/UnresolvedArgument.java | 5 +- .../ast/expression/UnresolvedAttribute.java | 6 +- .../ast/expression/UnresolvedExpression.java | 1 - .../opensearch/sql/ast/expression/When.java | 14 +- .../sql/ast/expression/WindowFunction.java | 2 - .../opensearch/sql/ast/expression/Xor.java | 5 +- .../opensearch/sql/ast/statement/Explain.java | 4 +- .../opensearch/sql/ast/statement/Query.java | 4 +- .../sql/ast/statement/Statement.java | 4 +- .../java/org/opensearch/sql/ast/tree/AD.java | 1 - .../opensearch/sql/ast/tree/Aggregation.java | 31 +-- .../opensearch/sql/ast/tree/CloseCursor.java | 9 +- .../org/opensearch/sql/ast/tree/Dedupe.java | 5 +- .../org/opensearch/sql/ast/tree/Eval.java | 5 +- .../opensearch/sql/ast/tree/FetchCursor.java | 8 +- .../org/opensearch/sql/ast/tree/Filter.java | 5 +- .../org/opensearch/sql/ast/tree/Head.java | 5 +- .../org/opensearch/sql/ast/tree/Kmeans.java | 1 - .../org/opensearch/sql/ast/tree/Limit.java | 2 - .../java/org/opensearch/sql/ast/tree/ML.java | 9 +- .../org/opensearch/sql/ast/tree/Paginate.java | 8 +- .../org/opensearch/sql/ast/tree/Parse.java | 25 +- .../org/opensearch/sql/ast/tree/Project.java | 12 +- .../org/opensearch/sql/ast/tree/RareTopN.java | 5 +- .../org/opensearch/sql/ast/tree/Relation.java | 22 +- .../sql/ast/tree/RelationSubquery.java | 9 +- .../org/opensearch/sql/ast/tree/Rename.java | 1 - .../org/opensearch/sql/ast/tree/Sort.java | 18 +- .../sql/ast/tree/TableFunction.java | 10 +- .../sql/ast/tree/UnresolvedPlan.java | 5 +- .../org/opensearch/sql/ast/tree/Values.java | 6 +- .../data/model/AbstractExprNumberValue.java | 5 +- .../sql/data/model/AbstractExprValue.java | 51 ++-- .../sql/data/model/ExprBooleanValue.java | 5 +- .../sql/data/model/ExprByteValue.java | 5 +- .../sql/data/model/ExprCollectionValue.java | 13 +- .../sql/data/model/ExprDateValue.java | 13 +- .../sql/data/model/ExprDatetimeValue.java | 20 +- .../sql/data/model/ExprDoubleValue.java | 5 +- .../sql/data/model/ExprFloatValue.java | 5 +- .../sql/data/model/ExprIntegerValue.java | 5 +- .../sql/data/model/ExprIntervalValue.java | 11 +- .../sql/data/model/ExprLongValue.java | 5 +- .../sql/data/model/ExprMissingValue.java | 16 +- .../sql/data/model/ExprNullValue.java | 12 +- .../sql/data/model/ExprShortValue.java | 5 +- .../sql/data/model/ExprStringValue.java | 13 +- .../sql/data/model/ExprTimeValue.java | 17 +- .../sql/data/model/ExprTimestampValue.java | 29 +- .../sql/data/model/ExprTupleValue.java | 13 +- .../opensearch/sql/data/model/ExprValue.java | 81 ++---- .../sql/data/model/ExprValueUtils.java | 32 +-- .../sql/data/type/ExprCoreType.java | 56 ++-- .../opensearch/sql/data/type/ExprType.java | 28 +- .../sql/data/type/WideningTypeRule.java | 27 +- .../sql/data/utils/ExprValueOrdering.java | 1 - .../data/utils/NaturalExprValueOrdering.java | 1 - .../utils/NullsFirstExprValueOrdering.java | 1 - .../utils/NullsLastExprValueOrdering.java | 1 - .../data/utils/ReverseExprValueOrdering.java | 1 - .../sql/datasource/DataSourceService.java | 23 +- .../sql/datasource/model/DataSource.java | 8 +- .../datasource/model/DataSourceMetadata.java | 17 +- .../sql/ast/expression/CastTest.java | 2 - .../sql/ast/expression/QualifiedNameTest.java | 2 - .../sql/data/model/DateTimeValueTest.java | 92 ++++--- .../sql/data/model/ExprBooleanValueTest.java | 9 +- .../data/model/ExprCollectionValueTest.java | 6 +- .../sql/data/model/ExprIntervalValueTest.java | 9 +- .../sql/data/model/ExprMissingValueTest.java | 7 +- .../sql/data/model/ExprNullValueTest.java | 6 +- .../sql/data/model/ExprNumberValueTest.java | 6 +- .../sql/data/model/ExprStringValueTest.java | 8 +- .../sql/data/model/ExprTupleValueTest.java | 5 +- .../sql/data/model/ExprValueCompareTest.java | 248 +++++++++--------- .../sql/data/model/ExprValueUtilsTest.java | 218 +++++++-------- .../sql/data/type/ExprTypeTest.java | 1 - .../sql/data/utils/ExprValueOrderingTest.java | 7 +- .../NullsFirstExprValueOrderingTest.java | 1 - .../utils/NullsLastExprValueOrderingTest.java | 1 - .../utils/ReverseExprValueOrderingTest.java | 1 - .../expression/datetime/TimestampTest.java | 2 +- .../client/OpenSearchRestClientTest.java | 1 + 133 files changed, 1106 insertions(+), 1504 deletions(-) diff --git a/build.gradle b/build.gradle index bb0cd162f0..9868101878 100644 --- a/build.gradle +++ b/build.gradle @@ -84,7 +84,10 @@ repositories { spotless { java { target fileTree('.') { - include '**/*.java' + include 'core/src/main/java/org/opensearch/sql/analysis/**/*.java', + 'core/src/test/java/org/opensearch/sql/data/**/*.java', + 'core/src/test/java/org/opensearch/sql/datasource/**/*.java', + 'core/src/test/java/org/opensearch/sql/ast/**/*.java' exclude '**/build/**', '**/build-*/**' } // importOrder() @@ -95,7 +98,7 @@ spotless { // removeUnusedImports() // trimTrailingWhitespace() endWithNewline() -// googleJavaFormat('1.17.0').reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format') + googleJavaFormat('1.17.0').reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format') } } diff --git a/core/build.gradle b/core/build.gradle index 8205638138..89fac623f2 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -34,6 +34,9 @@ repositories { mavenCentral() } +checkstyleMain.ignoreFailures = true +checkstyleTest.ignoreFailures = true + pitest { targetClasses = ['org.opensearch.sql.*'] pitestVersion = '1.9.0' diff --git a/core/src/main/java/org/opensearch/sql/analysis/AnalysisContext.java b/core/src/main/java/org/opensearch/sql/analysis/AnalysisContext.java index 4704d0566b..f1f29e9b38 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/AnalysisContext.java +++ b/core/src/main/java/org/opensearch/sql/analysis/AnalysisContext.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.analysis; import java.util.ArrayList; @@ -13,19 +12,14 @@ import org.opensearch.sql.expression.NamedExpression; import org.opensearch.sql.expression.function.FunctionProperties; -/** - * The context used for Analyzer. - */ +/** The context used for Analyzer. */ public class AnalysisContext { - /** - * Environment stack for symbol scope management. - */ + /** Environment stack for symbol scope management. */ private TypeEnvironment environment; - @Getter - private final List namedParseExpressions; - @Getter - private final FunctionProperties functionProperties; + @Getter private final List namedParseExpressions; + + @Getter private final FunctionProperties functionProperties; public AnalysisContext() { this(new TypeEnvironment(null)); @@ -33,6 +27,7 @@ public AnalysisContext() { /** * Class CTOR. + * * @param environment Env to set to a new instance. */ public AnalysisContext(TypeEnvironment environment) { @@ -41,9 +36,7 @@ public AnalysisContext(TypeEnvironment environment) { this.functionProperties = new FunctionProperties(); } - /** - * Push a new environment. - */ + /** Push a new environment. */ public void push() { environment = new TypeEnvironment(environment); } diff --git a/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java b/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java index 2c4647004c..ad3713ec9a 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.analysis; import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; @@ -29,7 +28,6 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; -import org.apache.commons.math3.analysis.function.Exp; import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.analysis.symbol.Namespace; import org.opensearch.sql.analysis.symbol.Symbol; @@ -122,9 +120,7 @@ public class Analyzer extends AbstractNodeVisitor private final BuiltinFunctionRepository repository; - /** - * Constructor. - */ + /** Constructor. */ public Analyzer( ExpressionAnalyzer expressionAnalyzer, DataSourceService dataSourceService, @@ -143,8 +139,8 @@ public LogicalPlan analyze(UnresolvedPlan unresolved, AnalysisContext context) { @Override public LogicalPlan visitRelation(Relation node, AnalysisContext context) { QualifiedName qualifiedName = node.getTableQualifiedName(); - DataSourceSchemaIdentifierNameResolver dataSourceSchemaIdentifierNameResolver - = new DataSourceSchemaIdentifierNameResolver(dataSourceService, qualifiedName.getParts()); + DataSourceSchemaIdentifierNameResolver dataSourceSchemaIdentifierNameResolver = + new DataSourceSchemaIdentifierNameResolver(dataSourceService, qualifiedName.getParts()); String tableName = dataSourceSchemaIdentifierNameResolver.getIdentifierName(); context.push(); TypeEnvironment curEnv = context.peek(); @@ -152,28 +148,30 @@ public LogicalPlan visitRelation(Relation node, AnalysisContext context) { if (DATASOURCES_TABLE_NAME.equals(tableName)) { table = new DataSourceTable(dataSourceService); } else { - table = dataSourceService - .getDataSource(dataSourceSchemaIdentifierNameResolver.getDataSourceName()) - .getStorageEngine() - .getTable(new DataSourceSchemaName( - dataSourceSchemaIdentifierNameResolver.getDataSourceName(), - dataSourceSchemaIdentifierNameResolver.getSchemaName()), - dataSourceSchemaIdentifierNameResolver.getIdentifierName()); + table = + dataSourceService + .getDataSource(dataSourceSchemaIdentifierNameResolver.getDataSourceName()) + .getStorageEngine() + .getTable( + new DataSourceSchemaName( + dataSourceSchemaIdentifierNameResolver.getDataSourceName(), + dataSourceSchemaIdentifierNameResolver.getSchemaName()), + dataSourceSchemaIdentifierNameResolver.getIdentifierName()); } table.getFieldTypes().forEach((k, v) -> curEnv.define(new Symbol(Namespace.FIELD_NAME, k), v)); - table.getReservedFieldTypes().forEach( - (k, v) -> curEnv.addReservedWord(new Symbol(Namespace.FIELD_NAME, k), v) - ); + table + .getReservedFieldTypes() + .forEach((k, v) -> curEnv.addReservedWord(new Symbol(Namespace.FIELD_NAME, k), v)); // Put index name or its alias in index namespace on type environment so qualifier // can be removed when analyzing qualified name. The value (expr type) here doesn't matter. - curEnv.define(new Symbol(Namespace.INDEX_NAME, - (node.getAlias() == null) ? tableName : node.getAlias()), STRUCT); + curEnv.define( + new Symbol(Namespace.INDEX_NAME, (node.getAlias() == null) ? tableName : node.getAlias()), + STRUCT); return new LogicalRelation(tableName, table); } - @Override public LogicalPlan visitRelationSubquery(RelationSubquery node, AnalysisContext context) { LogicalPlan subquery = analyze(node.getChild().get(0), context); @@ -189,30 +187,41 @@ public LogicalPlan visitRelationSubquery(RelationSubquery node, AnalysisContext @Override public LogicalPlan visitTableFunction(TableFunction node, AnalysisContext context) { QualifiedName qualifiedName = node.getFunctionName(); - DataSourceSchemaIdentifierNameResolver dataSourceSchemaIdentifierNameResolver - = new DataSourceSchemaIdentifierNameResolver(this.dataSourceService, - qualifiedName.getParts()); - - FunctionName functionName - = FunctionName.of(dataSourceSchemaIdentifierNameResolver.getIdentifierName()); - List arguments = node.getArguments().stream() - .map(unresolvedExpression -> this.expressionAnalyzer.analyze(unresolvedExpression, context)) - .collect(Collectors.toList()); - TableFunctionImplementation tableFunctionImplementation - = (TableFunctionImplementation) repository.compile(context.getFunctionProperties(), - dataSourceService - .getDataSource(dataSourceSchemaIdentifierNameResolver.getDataSourceName()) - .getStorageEngine().getFunctions(), functionName, arguments); + DataSourceSchemaIdentifierNameResolver dataSourceSchemaIdentifierNameResolver = + new DataSourceSchemaIdentifierNameResolver( + this.dataSourceService, qualifiedName.getParts()); + + FunctionName functionName = + FunctionName.of(dataSourceSchemaIdentifierNameResolver.getIdentifierName()); + List arguments = + node.getArguments().stream() + .map( + unresolvedExpression -> + this.expressionAnalyzer.analyze(unresolvedExpression, context)) + .collect(Collectors.toList()); + TableFunctionImplementation tableFunctionImplementation = + (TableFunctionImplementation) + repository.compile( + context.getFunctionProperties(), + dataSourceService + .getDataSource(dataSourceSchemaIdentifierNameResolver.getDataSourceName()) + .getStorageEngine() + .getFunctions(), + functionName, + arguments); context.push(); TypeEnvironment curEnv = context.peek(); Table table = tableFunctionImplementation.applyArguments(); table.getFieldTypes().forEach((k, v) -> curEnv.define(new Symbol(Namespace.FIELD_NAME, k), v)); - table.getReservedFieldTypes().forEach( - (k, v) -> curEnv.addReservedWord(new Symbol(Namespace.FIELD_NAME, k), v) - ); - curEnv.define(new Symbol(Namespace.INDEX_NAME, - dataSourceSchemaIdentifierNameResolver.getIdentifierName()), STRUCT); - return new LogicalRelation(dataSourceSchemaIdentifierNameResolver.getIdentifierName(), + table + .getReservedFieldTypes() + .forEach((k, v) -> curEnv.addReservedWord(new Symbol(Namespace.FIELD_NAME, k), v)); + curEnv.define( + new Symbol( + Namespace.INDEX_NAME, dataSourceSchemaIdentifierNameResolver.getIdentifierName()), + STRUCT); + return new LogicalRelation( + dataSourceSchemaIdentifierNameResolver.getIdentifierName(), tableFunctionImplementation.applyArguments()); } @@ -234,30 +243,28 @@ public LogicalPlan visitFilter(Filter node, AnalysisContext context) { } /** - * Ensure NESTED function is not used in GROUP BY, and HAVING clauses. - * Fallback to legacy engine. Can remove when support is added for NESTED function in WHERE, - * GROUP BY, ORDER BY, and HAVING clauses. + * Ensure NESTED function is not used in GROUP BY, and HAVING clauses. Fallback to legacy engine. + * Can remove when support is added for NESTED function in WHERE, GROUP BY, ORDER BY, and HAVING + * clauses. + * * @param condition : Filter condition */ private void verifySupportsCondition(Expression condition) { if (condition instanceof FunctionExpression) { - if (((FunctionExpression) condition).getFunctionName().getFunctionName().equalsIgnoreCase( - BuiltinFunctionName.NESTED.name() - )) { + if (((FunctionExpression) condition) + .getFunctionName() + .getFunctionName() + .equalsIgnoreCase(BuiltinFunctionName.NESTED.name())) { throw new SyntaxCheckException( "Falling back to legacy engine. Nested function is not supported in WHERE," - + " GROUP BY, and HAVING clauses." - ); + + " GROUP BY, and HAVING clauses."); } - ((FunctionExpression)condition).getArguments().stream() - .forEach(e -> verifySupportsCondition(e) - ); + ((FunctionExpression) condition) + .getArguments().stream().forEach(e -> verifySupportsCondition(e)); } } - /** - * Build {@link LogicalRename}. - */ + /** Build {@link LogicalRename}. */ @Override public LogicalPlan visitRename(Rename node, AnalysisContext context) { LogicalPlan child = node.getChild().get(0).accept(this, context); @@ -268,8 +275,8 @@ public LogicalPlan visitRename(Rename node, AnalysisContext context) { // We should define the new target field in the context instead of analyze it. if (renameMap.getTarget() instanceof Field) { ReferenceExpression target = - new ReferenceExpression(((Field) renameMap.getTarget()).getField().toString(), - origin.type()); + new ReferenceExpression( + ((Field) renameMap.getTarget()).getField().toString(), origin.type()); ReferenceExpression originExpr = DSL.ref(origin.toString(), origin.type()); TypeEnvironment curEnv = context.peek(); curEnv.remove(originExpr); @@ -284,17 +291,15 @@ public LogicalPlan visitRename(Rename node, AnalysisContext context) { return new LogicalRename(child, renameMapBuilder.build()); } - /** - * Build {@link LogicalAggregation}. - */ + /** Build {@link LogicalAggregation}. */ @Override public LogicalPlan visitAggregation(Aggregation node, AnalysisContext context) { final LogicalPlan child = node.getChild().get(0).accept(this, context); ImmutableList.Builder aggregatorBuilder = new ImmutableList.Builder<>(); for (UnresolvedExpression expr : node.getAggExprList()) { NamedExpression aggExpr = namedExpressionAnalyzer.analyze(expr, context); - aggregatorBuilder - .add(new NamedAggregator(aggExpr.getNameOrAlias(), (Aggregator) aggExpr.getDelegated())); + aggregatorBuilder.add( + new NamedAggregator(aggExpr.getNameOrAlias(), (Aggregator) aggExpr.getDelegated())); } ImmutableList.Builder groupbyBuilder = new ImmutableList.Builder<>(); @@ -314,16 +319,17 @@ public LogicalPlan visitAggregation(Aggregation node, AnalysisContext context) { // new context context.push(); TypeEnvironment newEnv = context.peek(); - aggregators.forEach(aggregator -> newEnv.define(new Symbol(Namespace.FIELD_NAME, - aggregator.getName()), aggregator.type())); - groupBys.forEach(group -> newEnv.define(new Symbol(Namespace.FIELD_NAME, - group.getNameOrAlias()), group.type())); + aggregators.forEach( + aggregator -> + newEnv.define( + new Symbol(Namespace.FIELD_NAME, aggregator.getName()), aggregator.type())); + groupBys.forEach( + group -> + newEnv.define(new Symbol(Namespace.FIELD_NAME, group.getNameOrAlias()), group.type())); return new LogicalAggregation(child, aggregators, groupBys); } - /** - * Build {@link LogicalRareTopN}. - */ + /** Build {@link LogicalRareTopN}. */ @Override public LogicalPlan visitRareTopN(RareTopN node, AnalysisContext context) { final LogicalPlan child = node.getChild().get(0).accept(this, context); @@ -343,10 +349,10 @@ public LogicalPlan visitRareTopN(RareTopN node, AnalysisContext context) { // new context context.push(); TypeEnvironment newEnv = context.peek(); - groupBys.forEach(group -> newEnv.define(new Symbol(Namespace.FIELD_NAME, - group.toString()), group.type())); - fields.forEach(field -> newEnv.define(new Symbol(Namespace.FIELD_NAME, - field.toString()), field.type())); + groupBys.forEach( + group -> newEnv.define(new Symbol(Namespace.FIELD_NAME, group.toString()), group.type())); + fields.forEach( + field -> newEnv.define(new Symbol(Namespace.FIELD_NAME, field.toString()), field.type())); List options = node.getNoOfResults(); Integer noOfResults = (Integer) options.get(0).getValue().getValue(); @@ -397,28 +403,28 @@ public LogicalPlan visitProject(Project node, AnalysisContext context) { } List namedExpressions = - selectExpressionAnalyzer.analyze(node.getProjectList(), context, + selectExpressionAnalyzer.analyze( + node.getProjectList(), + context, new ExpressionReferenceOptimizer(expressionAnalyzer.getRepository(), child)); for (UnresolvedExpression expr : node.getProjectList()) { - NestedAnalyzer nestedAnalyzer = new NestedAnalyzer( - namedExpressions, expressionAnalyzer, child - ); + NestedAnalyzer nestedAnalyzer = + new NestedAnalyzer(namedExpressions, expressionAnalyzer, child); child = nestedAnalyzer.analyze(expr, context); } // new context context.push(); TypeEnvironment newEnv = context.peek(); - namedExpressions.forEach(expr -> newEnv.define(new Symbol(Namespace.FIELD_NAME, - expr.getNameOrAlias()), expr.type())); + namedExpressions.forEach( + expr -> + newEnv.define(new Symbol(Namespace.FIELD_NAME, expr.getNameOrAlias()), expr.type())); List namedParseExpressions = context.getNamedParseExpressions(); return new LogicalProject(child, namedExpressions, namedParseExpressions); } - /** - * Build {@link LogicalEval}. - */ + /** Build {@link LogicalEval}. */ @Override public LogicalPlan visitEval(Eval node, AnalysisContext context) { LogicalPlan child = node.getChild().get(0).accept(this, context); @@ -435,9 +441,7 @@ public LogicalPlan visitEval(Eval node, AnalysisContext context) { return new LogicalEval(child, expressionsBuilder.build()); } - /** - * Build {@link ParseExpression} to context and skip to child nodes. - */ + /** Build {@link ParseExpression} to context and skip to child nodes. */ @Override public LogicalPlan visitParse(Parse node, AnalysisContext context) { LogicalPlan child = node.getChild().get(0).accept(this, context); @@ -448,18 +452,19 @@ public LogicalPlan visitParse(Parse node, AnalysisContext context) { Expression patternExpression = DSL.literal(pattern); TypeEnvironment curEnv = context.peek(); - ParseUtils.getNamedGroupCandidates(parseMethod, pattern, arguments).forEach(group -> { - ParseExpression expr = ParseUtils.createParseExpression(parseMethod, sourceField, - patternExpression, DSL.literal(group)); - curEnv.define(new Symbol(Namespace.FIELD_NAME, group), expr.type()); - context.getNamedParseExpressions().add(new NamedExpression(group, expr)); - }); + ParseUtils.getNamedGroupCandidates(parseMethod, pattern, arguments) + .forEach( + group -> { + ParseExpression expr = + ParseUtils.createParseExpression( + parseMethod, sourceField, patternExpression, DSL.literal(group)); + curEnv.define(new Symbol(Namespace.FIELD_NAME, group), expr.type()); + context.getNamedParseExpressions().add(new NamedExpression(group, expr)); + }); return child; } - /** - * Build {@link LogicalSort}. - */ + /** Build {@link LogicalSort}. */ @Override public LogicalPlan visitSort(Sort node, AnalysisContext context) { LogicalPlan child = node.getChild().get(0).accept(this, context); @@ -473,8 +478,7 @@ public LogicalPlan visitSort(Sort node, AnalysisContext context) { var analyzed = expressionAnalyzer.analyze(sortField.getField(), context); if (analyzed == null) { throw new UnsupportedOperationException( - String.format("Invalid use of expression %s", sortField.getField()) - ); + String.format("Invalid use of expression %s", sortField.getField())); } Expression expression = optimizer.optimize(analyzed, context); return ImmutablePair.of(analyzeSortOption(sortField.getFieldArgs()), expression); @@ -483,9 +487,7 @@ public LogicalPlan visitSort(Sort node, AnalysisContext context) { return new LogicalSort(child, sortList); } - /** - * Build {@link LogicalDedupe}. - */ + /** Build {@link LogicalDedupe}. */ @Override public LogicalPlan visitDedupe(Dedupe node, AnalysisContext context) { LogicalPlan child = node.getChild().get(0).accept(this, context); @@ -505,9 +507,7 @@ public LogicalPlan visitDedupe(Dedupe node, AnalysisContext context) { consecutive); } - /** - * Logical head is identical to {@link LogicalLimit}. - */ + /** Logical head is identical to {@link LogicalLimit}. */ public LogicalPlan visitHead(Head node, AnalysisContext context) { LogicalPlan child = node.getChild().get(0).accept(this, context); return new LogicalLimit(child, node.getSize(), node.getFrom()); @@ -518,16 +518,15 @@ public LogicalPlan visitValues(Values node, AnalysisContext context) { List> values = node.getValues(); List> valueExprs = new ArrayList<>(); for (List value : values) { - valueExprs.add(value.stream() - .map(val -> (LiteralExpression) expressionAnalyzer.analyze(val, context)) - .collect(Collectors.toList())); + valueExprs.add( + value.stream() + .map(val -> (LiteralExpression) expressionAnalyzer.analyze(val, context)) + .collect(Collectors.toList())); } return new LogicalValues(valueExprs); } - /** - * Build {@link LogicalMLCommons} for Kmeans command. - */ + /** Build {@link LogicalMLCommons} for Kmeans command. */ @Override public LogicalPlan visitKmeans(Kmeans node, AnalysisContext context) { LogicalPlan child = node.getChild().get(0).accept(this, context); @@ -539,9 +538,7 @@ public LogicalPlan visitKmeans(Kmeans node, AnalysisContext context) { return new LogicalMLCommons(child, "kmeans", options); } - /** - * Build {@link LogicalAD} for AD command. - */ + /** Build {@link LogicalAD} for AD command. */ @Override public LogicalPlan visitAD(AD node, AnalysisContext context) { LogicalPlan child = node.getChild().get(0).accept(this, context); @@ -554,21 +551,21 @@ public LogicalPlan visitAD(AD node, AnalysisContext context) { currentEnv.define(new Symbol(Namespace.FIELD_NAME, RCF_ANOMALOUS), ExprCoreType.BOOLEAN); } else { currentEnv.define(new Symbol(Namespace.FIELD_NAME, RCF_ANOMALY_GRADE), ExprCoreType.DOUBLE); - currentEnv.define(new Symbol(Namespace.FIELD_NAME, - (String) node.getArguments().get(TIME_FIELD).getValue()), ExprCoreType.TIMESTAMP); + currentEnv.define( + new Symbol(Namespace.FIELD_NAME, (String) node.getArguments().get(TIME_FIELD).getValue()), + ExprCoreType.TIMESTAMP); } return new LogicalAD(child, options); } - /** - * Build {@link LogicalML} for ml command. - */ + /** Build {@link LogicalML} for ml command. */ @Override public LogicalPlan visitML(ML node, AnalysisContext context) { LogicalPlan child = node.getChild().get(0).accept(this, context); TypeEnvironment currentEnv = context.peek(); node.getOutputSchema(currentEnv).entrySet().stream() - .forEach(v -> currentEnv.define(new Symbol(Namespace.FIELD_NAME, v.getKey()), v.getValue())); + .forEach( + v -> currentEnv.define(new Symbol(Namespace.FIELD_NAME, v.getKey()), v.getValue())); return new LogicalML(child, node.getArguments()); } @@ -581,8 +578,9 @@ public LogicalPlan visitPaginate(Paginate paginate, AnalysisContext context) { @Override public LogicalPlan visitFetchCursor(FetchCursor cursor, AnalysisContext context) { - return new LogicalFetchCursor(cursor.getCursor(), - dataSourceService.getDataSource(DEFAULT_DATASOURCE_NAME).getStorageEngine()); + return new LogicalFetchCursor( + cursor.getCursor(), + dataSourceService.getDataSource(DEFAULT_DATASOURCE_NAME).getStorageEngine()); } @Override @@ -591,13 +589,13 @@ public LogicalPlan visitCloseCursor(CloseCursor closeCursor, AnalysisContext con } /** - * The first argument is always "asc", others are optional. - * Given nullFirst argument, use its value. Otherwise just use DEFAULT_ASC/DESC. + * The first argument is always "asc", others are optional. Given nullFirst argument, use its + * value. Otherwise just use DEFAULT_ASC/DESC. */ private SortOption analyzeSortOption(List fieldArgs) { Boolean asc = (Boolean) fieldArgs.get(0).getValue().getValue(); - Optional nullFirst = fieldArgs.stream() - .filter(option -> "nullFirst".equals(option.getArgName())).findFirst(); + Optional nullFirst = + fieldArgs.stream().filter(option -> "nullFirst".equals(option.getArgName())).findFirst(); if (nullFirst.isPresent()) { Boolean isNullFirst = (Boolean) nullFirst.get().getValue().getValue(); diff --git a/core/src/main/java/org/opensearch/sql/analysis/DataSourceSchemaIdentifierNameResolver.java b/core/src/main/java/org/opensearch/sql/analysis/DataSourceSchemaIdentifierNameResolver.java index 1bb8316907..01145dc7df 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/DataSourceSchemaIdentifierNameResolver.java +++ b/core/src/main/java/org/opensearch/sql/analysis/DataSourceSchemaIdentifierNameResolver.java @@ -7,13 +7,8 @@ package org.opensearch.sql.analysis; -import com.google.common.collect.ImmutableSet; import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import org.opensearch.sql.ast.expression.QualifiedName; import org.opensearch.sql.datasource.DataSourceService; -import org.opensearch.sql.datasource.model.DataSourceMetadata; public class DataSourceSchemaIdentifierNameResolver { @@ -29,19 +24,17 @@ public class DataSourceSchemaIdentifierNameResolver { private static final String DOT = "."; /** - * Data model for capturing dataSourceName, schema and identifier from - * fully qualifiedName. In the current state, it is used to capture - * DataSourceSchemaTable name and DataSourceSchemaFunction in case of table - * functions. + * Data model for capturing dataSourceName, schema and identifier from fully qualifiedName. In the + * current state, it is used to capture DataSourceSchemaTable name and DataSourceSchemaFunction in + * case of table functions. * * @param dataSourceService {@link DataSourceService}. - * @param parts parts of qualifiedName. + * @param parts parts of qualifiedName. */ - public DataSourceSchemaIdentifierNameResolver(DataSourceService dataSourceService, - List parts) { + public DataSourceSchemaIdentifierNameResolver( + DataSourceService dataSourceService, List parts) { this.dataSourceService = dataSourceService; - List remainingParts - = captureSchemaName(captureDataSourceName(parts)); + List remainingParts = captureSchemaName(captureDataSourceName(parts)); identifierName = String.join(DOT, remainingParts); } @@ -57,7 +50,6 @@ public String getSchemaName() { return schemaName; } - // Capture datasource name and return remaining parts(schema name and table name) // from the fully qualified name. private List captureDataSourceName(List parts) { @@ -74,12 +66,11 @@ private List captureDataSourceName(List parts) { private List captureSchemaName(List parts) { if (parts.size() > 1 && (DEFAULT_SCHEMA_NAME.equals(parts.get(0)) - || INFORMATION_SCHEMA_NAME.contains(parts.get(0)))) { + || INFORMATION_SCHEMA_NAME.contains(parts.get(0)))) { schemaName = parts.get(0); return parts.subList(1, parts.size()); } else { return parts; } } - } diff --git a/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java index 601e3e00cc..8e586f68ff 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.analysis; import static org.opensearch.sql.ast.dsl.AstDSL.and; @@ -49,7 +48,6 @@ import org.opensearch.sql.ast.expression.When; import org.opensearch.sql.ast.expression.WindowFunction; import org.opensearch.sql.ast.expression.Xor; -import org.opensearch.sql.common.antlr.SyntaxCheckException; import org.opensearch.sql.data.model.ExprValueUtils; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; @@ -78,19 +76,19 @@ * Expression}. */ public class ExpressionAnalyzer extends AbstractNodeVisitor { - @Getter - private final BuiltinFunctionRepository repository; + @Getter private final BuiltinFunctionRepository repository; @Override public Expression visitCast(Cast node, AnalysisContext context) { final Expression expression = node.getExpression().accept(this, context); - return (Expression) repository - .compile(context.getFunctionProperties(), node.convertFunctionName(), + return (Expression) + repository.compile( + context.getFunctionProperties(), + node.convertFunctionName(), Collections.singletonList(expression)); } - public ExpressionAnalyzer( - BuiltinFunctionRepository repository) { + public ExpressionAnalyzer(BuiltinFunctionRepository repository) { this.repository = repository; } @@ -113,8 +111,8 @@ public Expression visitEqualTo(EqualTo node, AnalysisContext context) { @Override public Expression visitLiteral(Literal node, AnalysisContext context) { - return DSL - .literal(ExprValueUtils.fromObjectValue(node.getValue(), node.getType().getCoreType())); + return DSL.literal( + ExprValueUtils.fromObjectValue(node.getValue(), node.getType().getCoreType())); } @Override @@ -163,8 +161,12 @@ public Expression visitAggregateFunction(AggregateFunction node, AnalysisContext for (UnresolvedExpression arg : node.getArgList()) { builder.add(arg.accept(this, context)); } - Aggregator aggregator = (Aggregator) repository.compile( - context.getFunctionProperties(), builtinFunctionName.get().getName(), builder.build()); + Aggregator aggregator = + (Aggregator) + repository.compile( + context.getFunctionProperties(), + builtinFunctionName.get().getName(), + builder.build()); aggregator.distinct(node.getDistinct()); if (node.condition() != null) { aggregator.condition(analyze(node.condition(), context)); @@ -177,8 +179,8 @@ public Expression visitAggregateFunction(AggregateFunction node, AnalysisContext @Override public Expression visitRelevanceFieldList(RelevanceFieldList node, AnalysisContext context) { - return new LiteralExpression(ExprValueUtils.tupleValue( - ImmutableMap.copyOf(node.getFieldList()))); + return new LiteralExpression( + ExprValueUtils.tupleValue(ImmutableMap.copyOf(node.getFieldList()))); } @Override @@ -186,19 +188,19 @@ public Expression visitFunction(Function node, AnalysisContext context) { FunctionName functionName = FunctionName.of(node.getFuncName()); List arguments = node.getFuncArgs().stream() - .map(unresolvedExpression -> { - var ret = analyze(unresolvedExpression, context); - if (ret == null) { - throw new UnsupportedOperationException( - String.format("Invalid use of expression %s", unresolvedExpression) - ); - } else { - return ret; - } - }) + .map( + unresolvedExpression -> { + var ret = analyze(unresolvedExpression, context); + if (ret == null) { + throw new UnsupportedOperationException( + String.format("Invalid use of expression %s", unresolvedExpression)); + } else { + return ret; + } + }) .collect(Collectors.toList()); - return (Expression) repository.compile(context.getFunctionProperties(), - functionName, arguments); + return (Expression) + repository.compile(context.getFunctionProperties(), functionName, arguments); } @SuppressWarnings("unchecked") @@ -220,18 +222,20 @@ public Expression visitHighlightFunction(HighlightFunction node, AnalysisContext /** * visitScoreFunction removes the score function from the AST and replaces it with the child - * relevance function node. If the optional boost variable is provided, the boost argument - * of the relevance function is combined. + * relevance function node. If the optional boost variable is provided, the boost argument of the + * relevance function is combined. * - * @param node score function node + * @param node score function node * @param context analysis context for the query * @return resolved relevance function */ public Expression visitScoreFunction(ScoreFunction node, AnalysisContext context) { Literal boostArg = node.getRelevanceFieldWeight(); if (!boostArg.getType().equals(DataType.DOUBLE)) { - throw new SemanticCheckException(String.format("Expected boost type '%s' but got '%s'", - DataType.DOUBLE.name(), boostArg.getType().name())); + throw new SemanticCheckException( + String.format( + "Expected boost type '%s' but got '%s'", + DataType.DOUBLE.name(), boostArg.getType().name())); } Double thisBoostValue = ((Double) boostArg.getValue()); @@ -249,10 +253,9 @@ public Expression visitScoreFunction(ScoreFunction node, AnalysisContext context Literal boostArgLiteral = (Literal) ((UnresolvedArgument) expr).getValue(); Double boostValue = Double.parseDouble((String) boostArgLiteral.getValue()) * thisBoostValue; - UnresolvedArgument newBoostArg = new UnresolvedArgument( - argumentName, - new Literal(boostValue.toString(), DataType.STRING) - ); + UnresolvedArgument newBoostArg = + new UnresolvedArgument( + argumentName, new Literal(boostValue.toString(), DataType.STRING)); updatedFuncArgs.add(newBoostArg); } else { updatedFuncArgs.add(expr); @@ -261,18 +264,18 @@ public Expression visitScoreFunction(ScoreFunction node, AnalysisContext context // since nothing was found, add an argument if (!doesFunctionContainBoostArgument) { - UnresolvedArgument newBoostArg = new UnresolvedArgument( + UnresolvedArgument newBoostArg = + new UnresolvedArgument( "boost", new Literal(Double.toString(thisBoostValue), DataType.STRING)); updatedFuncArgs.add(newBoostArg); } // create a new function expression with boost argument and resolve it - Function updatedRelevanceQueryUnresolvedExpr = new Function( - relevanceQueryUnresolvedExpr.getFuncName(), - updatedFuncArgs); + Function updatedRelevanceQueryUnresolvedExpr = + new Function(relevanceQueryUnresolvedExpr.getFuncName(), updatedFuncArgs); OpenSearchFunctions.OpenSearchFunction relevanceQueryExpr = - (OpenSearchFunctions.OpenSearchFunction) updatedRelevanceQueryUnresolvedExpr - .accept(this, context); + (OpenSearchFunctions.OpenSearchFunction) + updatedRelevanceQueryUnresolvedExpr.accept(this, context); relevanceQueryExpr.setScoreTracked(true); return relevanceQueryExpr; } @@ -301,16 +304,16 @@ public Expression visitCompare(Compare node, AnalysisContext context) { Expression left = analyze(node.getLeft(), context); Expression right = analyze(node.getRight(), context); return (Expression) - repository.compile(context.getFunctionProperties(), - functionName, Arrays.asList(left, right)); + repository.compile( + context.getFunctionProperties(), functionName, Arrays.asList(left, right)); } @Override public Expression visitBetween(Between node, AnalysisContext context) { return and( - compare(">=", node.getValue(), node.getLowerBound()), - compare("<=", node.getValue(), node.getUpperBound()) - ).accept(this, context); + compare(">=", node.getValue(), node.getLowerBound()), + compare("<=", node.getValue(), node.getUpperBound())) + .accept(this, context); } @Override @@ -321,16 +324,18 @@ public Expression visitCase(Case node, AnalysisContext context) { whens.add((WhenClause) analyze(when, context)); } else { // Merge case value and condition (compare value) into a single equal condition - whens.add((WhenClause) analyze( - new When( - new Function("=", Arrays.asList(node.getCaseValue(), when.getCondition())), - when.getResult() - ), context)); + whens.add( + (WhenClause) + analyze( + new When( + new Function("=", Arrays.asList(node.getCaseValue(), when.getCondition())), + when.getResult()), + context)); } } - Expression defaultResult = (node.getElseClause() == null) - ? null : analyze(node.getElseClause(), context); + Expression defaultResult = + (node.getElseClause() == null) ? null : analyze(node.getElseClause(), context); CaseClause caseClause = new CaseClause(whens, defaultResult); // To make this simple, require all result type same regardless of implicit convert @@ -346,8 +351,7 @@ public Expression visitCase(Case node, AnalysisContext context) { @Override public Expression visitWhen(When node, AnalysisContext context) { return new WhenClause( - analyze(node.getCondition(), context), - analyze(node.getResult(), context)); + analyze(node.getCondition(), context), analyze(node.getResult(), context)); } @Override @@ -371,16 +375,13 @@ public Expression visitQualifiedName(QualifiedName node, AnalysisContext context // check for reserved words in the identifier for (String part : node.getParts()) { for (TypeEnvironment typeEnv = context.peek(); - typeEnv != null; - typeEnv = typeEnv.getParent()) { - Optional exprType = typeEnv.getReservedSymbolTable().lookup( - new Symbol(Namespace.FIELD_NAME, part)); + typeEnv != null; + typeEnv = typeEnv.getParent()) { + Optional exprType = + typeEnv.getReservedSymbolTable().lookup(new Symbol(Namespace.FIELD_NAME, part)); if (exprType.isPresent()) { return visitMetadata( - qualifierAnalyzer.unqualified(node), - (ExprCoreType) exprType.get(), - context - ); + qualifierAnalyzer.unqualified(node), (ExprCoreType) exprType.get(), context); } } } @@ -401,15 +402,15 @@ public Expression visitUnresolvedArgument(UnresolvedArgument node, AnalysisConte } /** - * If QualifiedName is actually a reserved metadata field, return the expr type associated - * with the metadata field. - * @param ident metadata field name + * If QualifiedName is actually a reserved metadata field, return the expr type associated with + * the metadata field. + * + * @param ident metadata field name * @param context analysis context * @return DSL reference */ - private Expression visitMetadata(String ident, - ExprCoreType exprCoreType, - AnalysisContext context) { + private Expression visitMetadata( + String ident, ExprCoreType exprCoreType, AnalysisContext context) { return DSL.ref(ident, exprCoreType); } @@ -422,8 +423,8 @@ private Expression visitIdentifier(String ident, AnalysisContext context) { } TypeEnvironment typeEnv = context.peek(); - ReferenceExpression ref = DSL.ref(ident, - typeEnv.resolve(new Symbol(Namespace.FIELD_NAME, ident))); + ReferenceExpression ref = + DSL.ref(ident, typeEnv.resolve(new Symbol(Namespace.FIELD_NAME, ident))); return ref; } diff --git a/core/src/main/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizer.java b/core/src/main/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizer.java index eaf5c4abca..398f848f16 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizer.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.analysis; import java.util.HashMap; @@ -26,25 +25,25 @@ import org.opensearch.sql.planner.logical.LogicalWindow; /** - * The optimizer used to replace the expression referred in the SelectClause - * e.g. The query SELECT abs(name), sum(age)-avg(age) FROM test GROUP BY abs(name). - * will be translated the AST - * Project[abs(age), sub(sum(age), avg(age)) - * Agg(agg=[sum(age), avg(age)], group=[abs(age)]] - * Relation - * The sum(age) and avg(age) in the Project could be replace by the analyzed reference, the - * LogicalPlan should be - * LogicalProject[Ref("abs(age)"), sub(Ref("sum(age)"), Ref("avg(age)")) - * LogicalAgg(agg=[sum(age), avg(age)], group=[abs(age)]] - * LogicalRelation + * The optimizer used to replace the expression referred in the SelectClause
e.g. The query + * SELECT abs(name), sum(age)-avg(age) FROM test GROUP BY abs(name).
+ * will be translated the AST
+ * Project[abs(age), sub(sum(age), avg(age))
+ * &ensp Agg(agg=[sum(age), avg(age)], group=[abs(age)]]
+ * &emsp Relation
+ * The sum(age) and avg(age) in the Project could be replaced by the analyzed reference, the + * LogicalPlan should be
+ * LogicalProject[Ref("abs(age)"), sub(Ref("sum(age)"), Ref("avg(age)"))
+ * &ensp LogicalAgg(agg=[sum(age), avg(age)], group=[abs(age)]]
+ * &emsp LogicalRelation */ public class ExpressionReferenceOptimizer extends ExpressionNodeVisitor { private final BuiltinFunctionRepository repository; /** - * The map of expression and it's reference. - * For example, The NamedAggregator should produce the map of Aggregator to Ref(name) + * The map of expression and it's reference. For example, The NamedAggregator should produce the + * map of Aggregator to Ref(name) */ private final Map expressionMap = new HashMap<>(); @@ -69,17 +68,16 @@ public Expression visitFunction(FunctionExpression node, AnalysisContext context return expressionMap.get(node); } else { final List args = - node.getArguments().stream().map(expr -> expr.accept(this, context)) + node.getArguments().stream() + .map(expr -> expr.accept(this, context)) .collect(Collectors.toList()); - Expression optimizedFunctionExpression = (Expression) repository.compile( - context.getFunctionProperties(), - node.getFunctionName(), - args - ); + Expression optimizedFunctionExpression = + (Expression) + repository.compile(context.getFunctionProperties(), node.getFunctionName(), args); // Propagate scoreTracked for OpenSearch functions if (optimizedFunctionExpression instanceof OpenSearchFunctions.OpenSearchFunction) { - ((OpenSearchFunctions.OpenSearchFunction) optimizedFunctionExpression).setScoreTracked( - ((OpenSearchFunctions.OpenSearchFunction)node).isScoreTracked()); + ((OpenSearchFunctions.OpenSearchFunction) optimizedFunctionExpression) + .setScoreTracked(((OpenSearchFunctions.OpenSearchFunction) node).isScoreTracked()); } return optimizedFunctionExpression; } @@ -98,19 +96,17 @@ public Expression visitNamed(NamedExpression node, AnalysisContext context) { return node.getDelegated().accept(this, context); } - /** - * Implement this because Case/When is not registered in function repository. - */ + /** Implement this because Case/When is not registered in function repository. */ @Override public Expression visitCase(CaseClause node, AnalysisContext context) { if (expressionMap.containsKey(node)) { return expressionMap.get(node); } - List whenClauses = node.getWhenClauses() - .stream() - .map(expr -> (WhenClause) expr.accept(this, context)) - .collect(Collectors.toList()); + List whenClauses = + node.getWhenClauses().stream() + .map(expr -> (WhenClause) expr.accept(this, context)) + .collect(Collectors.toList()); Expression defaultResult = null; if (node.getDefaultResult() != null) { defaultResult = node.getDefaultResult().accept(this, context); @@ -121,14 +117,10 @@ public Expression visitCase(CaseClause node, AnalysisContext context) { @Override public Expression visitWhen(WhenClause node, AnalysisContext context) { return new WhenClause( - node.getCondition().accept(this, context), - node.getResult().accept(this, context)); + node.getCondition().accept(this, context), node.getResult().accept(this, context)); } - - /** - * Expression Map Builder. - */ + /** Expression Map Builder. */ class ExpressionMapBuilder extends LogicalPlanNodeVisitor { @Override @@ -140,20 +132,27 @@ public Void visitNode(LogicalPlan plan, Void context) { @Override public Void visitAggregation(LogicalAggregation plan, Void context) { // Create the mapping for all the aggregator. - plan.getAggregatorList().forEach(namedAggregator -> expressionMap - .put(namedAggregator.getDelegated(), - new ReferenceExpression(namedAggregator.getName(), namedAggregator.type()))); + plan.getAggregatorList() + .forEach( + namedAggregator -> + expressionMap.put( + namedAggregator.getDelegated(), + new ReferenceExpression(namedAggregator.getName(), namedAggregator.type()))); // Create the mapping for all the group by. - plan.getGroupByList().forEach(groupBy -> expressionMap - .put(groupBy.getDelegated(), - new ReferenceExpression(groupBy.getNameOrAlias(), groupBy.type()))); + plan.getGroupByList() + .forEach( + groupBy -> + expressionMap.put( + groupBy.getDelegated(), + new ReferenceExpression(groupBy.getNameOrAlias(), groupBy.type()))); return null; } @Override public Void visitWindow(LogicalWindow plan, Void context) { Expression windowFunc = plan.getWindowFunction(); - expressionMap.put(windowFunc, + expressionMap.put( + windowFunc, new ReferenceExpression(((NamedExpression) windowFunc).getName(), windowFunc.type())); return visitNode(plan, context); } diff --git a/core/src/main/java/org/opensearch/sql/analysis/HighlightAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/HighlightAnalyzer.java index 0a15c6bac8..386c6e9d9f 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/HighlightAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/HighlightAnalyzer.java @@ -14,10 +14,7 @@ import org.opensearch.sql.planner.logical.LogicalHighlight; import org.opensearch.sql.planner.logical.LogicalPlan; -/** - * Analyze the highlight in the {@link AnalysisContext} to construct the {@link - * LogicalPlan}. - */ +/** Analyze the highlight in the {@link AnalysisContext} to construct the {@link LogicalPlan}. */ @RequiredArgsConstructor public class HighlightAnalyzer extends AbstractNodeVisitor { private final ExpressionAnalyzer expressionAnalyzer; diff --git a/core/src/main/java/org/opensearch/sql/analysis/NamedExpressionAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/NamedExpressionAnalyzer.java index 1d318c5588..43bd411b42 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/NamedExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/NamedExpressionAnalyzer.java @@ -3,33 +3,26 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.analysis; import lombok.RequiredArgsConstructor; import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.expression.Alias; import org.opensearch.sql.ast.expression.QualifiedName; -import org.opensearch.sql.ast.expression.Span; import org.opensearch.sql.ast.expression.UnresolvedExpression; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.NamedExpression; -import org.opensearch.sql.expression.span.SpanExpression; /** - * Analyze the Alias node in the {@link AnalysisContext} to construct the list of - * {@link NamedExpression}. + * Analyze the Alias node in the {@link AnalysisContext} to construct the list of {@link + * NamedExpression}. */ @RequiredArgsConstructor -public class NamedExpressionAnalyzer extends - AbstractNodeVisitor { +public class NamedExpressionAnalyzer extends AbstractNodeVisitor { private final ExpressionAnalyzer expressionAnalyzer; - /** - * Analyze Select fields. - */ - public NamedExpression analyze(UnresolvedExpression expression, - AnalysisContext analysisContext) { + /** Analyze Select fields. */ + public NamedExpression analyze(UnresolvedExpression expression, AnalysisContext analysisContext) { return expression.accept(this, analysisContext); } diff --git a/core/src/main/java/org/opensearch/sql/analysis/NestedAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/NestedAnalyzer.java index f050824557..ef8f142801 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/NestedAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/NestedAnalyzer.java @@ -27,8 +27,7 @@ import org.opensearch.sql.planner.logical.LogicalPlan; /** - * Analyze the Nested Function in the {@link AnalysisContext} to construct the {@link - * LogicalPlan}. + * Analyze the Nested Function in the {@link AnalysisContext} to construct the {@link LogicalPlan}. */ @RequiredArgsConstructor public class NestedAnalyzer extends AbstractNodeVisitor { @@ -52,15 +51,15 @@ public LogicalPlan visitNestedAllTupleFields(NestedAllTupleFields node, Analysis for (NamedExpression namedExpr : namedExpressions) { if (isNestedFunction(namedExpr.getDelegated())) { ReferenceExpression field = - (ReferenceExpression) ((FunctionExpression) namedExpr.getDelegated()) - .getArguments().get(0); + (ReferenceExpression) + ((FunctionExpression) namedExpr.getDelegated()).getArguments().get(0); // If path is same as NestedAllTupleFields path - if (field.getAttr().substring(0, field.getAttr().lastIndexOf(".")) + if (field + .getAttr() + .substring(0, field.getAttr().lastIndexOf(".")) .equalsIgnoreCase(node.getPath())) { - args.add(Map.of( - "field", field, - "path", new ReferenceExpression(node.getPath(), STRING))); + args.add(Map.of("field", field, "path", new ReferenceExpression(node.getPath(), STRING))); } } } @@ -75,20 +74,24 @@ public LogicalPlan visitFunction(Function node, AnalysisContext context) { List expressions = node.getFuncArgs(); validateArgs(expressions); ReferenceExpression nestedField = - (ReferenceExpression)expressionAnalyzer.analyze(expressions.get(0), context); + (ReferenceExpression) expressionAnalyzer.analyze(expressions.get(0), context); Map args; // Path parameter is supplied if (expressions.size() == 2) { - args = Map.of( - "field", nestedField, - "path", (ReferenceExpression)expressionAnalyzer.analyze(expressions.get(1), context) - ); + args = + Map.of( + "field", + nestedField, + "path", + (ReferenceExpression) expressionAnalyzer.analyze(expressions.get(1), context)); } else { - args = Map.of( - "field", (ReferenceExpression)expressionAnalyzer.analyze(expressions.get(0), context), - "path", generatePath(nestedField.toString()) - ); + args = + Map.of( + "field", + (ReferenceExpression) expressionAnalyzer.analyze(expressions.get(0), context), + "path", + generatePath(nestedField.toString())); } return mergeChildIfLogicalNested(new ArrayList<>(Arrays.asList(args))); @@ -97,8 +100,9 @@ public LogicalPlan visitFunction(Function node, AnalysisContext context) { } /** - * NestedAnalyzer visits all functions in SELECT clause, creates logical plans for each and - * merges them. This is to avoid another merge rule in LogicalPlanOptimizer:create(). + * NestedAnalyzer visits all functions in SELECT clause, creates logical plans for each and merges + * them. This is to avoid another merge rule in LogicalPlanOptimizer:create(). + * * @param args field and path params to add to logical plan. * @return child of logical nested with added args, or new LogicalNested. */ @@ -113,34 +117,33 @@ private LogicalPlan mergeChildIfLogicalNested(List args) { if (args.size() < 1 || args.size() > 2) { throw new IllegalArgumentException( - "on nested object only allowed 2 parameters (field,path) or 1 parameter (field)" - ); + "on nested object only allowed 2 parameters (field,path) or 1 parameter (field)"); } for (int i = 0; i < args.size(); i++) { if (!(args.get(i) instanceof QualifiedName)) { throw new IllegalArgumentException( - String.format("Illegal nested field name: %s", args.get(i).toString()) - ); + String.format("Illegal nested field name: %s", args.get(i).toString())); } - if (i == 0 && ((QualifiedName)args.get(i)).getParts().size() < 2) { + if (i == 0 && ((QualifiedName) args.get(i)).getParts().size() < 2) { throw new IllegalArgumentException( - String.format("Illegal nested field name: %s", args.get(i).toString()) - ); + String.format("Illegal nested field name: %s", args.get(i).toString())); } } } /** * Generate nested path dynamically. Assumes at least one level of nesting in supplied string. + * * @param field : Nested field to generate path of. * @return : Path of field derived from last level of nesting. */ @@ -150,12 +153,15 @@ public static ReferenceExpression generatePath(String field) { /** * Check if supplied expression is a nested function. + * * @param expr Expression checking if is nested function. * @return True if expression is a nested function. */ public static Boolean isNestedFunction(Expression expr) { return (expr instanceof FunctionExpression - && ((FunctionExpression) expr).getFunctionName().getFunctionName() - .equalsIgnoreCase(BuiltinFunctionName.NESTED.name())); + && ((FunctionExpression) expr) + .getFunctionName() + .getFunctionName() + .equalsIgnoreCase(BuiltinFunctionName.NESTED.name())); } } diff --git a/core/src/main/java/org/opensearch/sql/analysis/QualifierAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/QualifierAnalyzer.java index d1e31d0079..27dd6a2243 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/QualifierAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/QualifierAnalyzer.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.analysis; import java.util.Arrays; @@ -15,9 +14,7 @@ import org.opensearch.sql.common.antlr.SyntaxCheckException; import org.opensearch.sql.exception.SemanticCheckException; -/** - * Analyzer that analyzes qualifier(s) in a full field name. - */ +/** Analyzer that analyzes qualifier(s) in a full field name. */ @RequiredArgsConstructor public class QualifierAnalyzer { @@ -28,11 +25,11 @@ public String unqualified(String... parts) { } /** - * Get unqualified name if its qualifier symbol found is in index namespace - * on type environment. Unqualified name means name with qualifier removed. - * For example, unqualified name of "accounts.age" or "acc.age" is "age". + * Get unqualified name if its qualifier symbol found is in index namespace on type environment. + * Unqualified name means name with qualifier removed. For example, unqualified name of + * "accounts.age" or "acc.age" is "age". * - * @return unqualified name if criteria met above, otherwise original name + * @return unqualified name if criteria met above, otherwise original name */ public String unqualified(QualifiedName fullName) { return isQualifierIndexOrAlias(fullName) ? fullName.rest().toString() : fullName.toString(); @@ -66,10 +63,11 @@ private void resolveQualifierSymbol(QualifiedName fullName, String qualifier) { } catch (SemanticCheckException e) { // Throw syntax check intentionally to indicate fall back to old engine. // Need change to semantic check exception in future. - throw new SyntaxCheckException(String.format( - "The qualifier [%s] of qualified name [%s] must be an field name, index name or its " - + "alias", qualifier, fullName)); + throw new SyntaxCheckException( + String.format( + "The qualifier [%s] of qualified name [%s] must be an field name, index name or its " + + "alias", + qualifier, fullName)); } } - } diff --git a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java index 734f37378b..afe003fb3d 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.analysis; import com.google.common.collect.ImmutableList; @@ -30,23 +29,21 @@ import org.opensearch.sql.expression.ReferenceExpression; /** - * Analyze the select list in the {@link AnalysisContext} to construct the list of - * {@link NamedExpression}. + * Analyze the select list in the {@link AnalysisContext} to construct the list of {@link + * NamedExpression}. */ @RequiredArgsConstructor public class SelectExpressionAnalyzer - extends - AbstractNodeVisitor, AnalysisContext> { + extends AbstractNodeVisitor, AnalysisContext> { private final ExpressionAnalyzer expressionAnalyzer; private ExpressionReferenceOptimizer optimizer; - /** - * Analyze Select fields. - */ - public List analyze(List selectList, - AnalysisContext analysisContext, - ExpressionReferenceOptimizer optimizer) { + /** Analyze Select fields. */ + public List analyze( + List selectList, + AnalysisContext analysisContext, + ExpressionReferenceOptimizer optimizer) { this.optimizer = optimizer; ImmutableList.Builder builder = new ImmutableList.Builder<>(); for (UnresolvedExpression unresolvedExpression : selectList) { @@ -68,50 +65,48 @@ public List visitAlias(Alias node, AnalysisContext context) { } Expression expr = referenceIfSymbolDefined(node, context); - return Collections.singletonList(DSL.named( - unqualifiedNameIfFieldOnly(node, context), - expr, - node.getAlias())); + return Collections.singletonList( + DSL.named(unqualifiedNameIfFieldOnly(node, context), expr, node.getAlias())); } /** - * The Alias could be - * 1. SELECT name, AVG(age) FROM s BY name -> - * Project(Alias("name", expr), Alias("AVG(age)", aggExpr)) - * Agg(Alias("AVG(age)", aggExpr)) - * 2. SELECT length(name), AVG(age) FROM s BY length(name) - * Project(Alias("name", expr), Alias("AVG(age)", aggExpr)) - * Agg(Alias("AVG(age)", aggExpr)) - * 3. SELECT length(name) as l, AVG(age) FROM s BY l - * Project(Alias("name", expr, l), Alias("AVG(age)", aggExpr)) - * Agg(Alias("AVG(age)", aggExpr), Alias("length(name)", groupExpr)) + * The Alias could be
+ * 1. SELECT name, AVG(age) FROM s BY name ->
+ * Project(Alias("name", expr), Alias("AVG(age)", aggExpr))
+ * Agg(Alias("AVG(age)", aggExpr))
+ * 2. SELECT length(name), AVG(age) FROM s BY length(name)
+ * Project(Alias("name", expr), Alias("AVG(age)", aggExpr))
+ * Agg(Alias("AVG(age)", aggExpr))
+ * 3. SELECT length(name) as l, AVG(age) FROM s BY l
+ * Project(Alias("name", expr, l), Alias("AVG(age)", aggExpr))
+ * Agg(Alias("AVG(age)", aggExpr), Alias("length(name)", groupExpr))
*/ - private Expression referenceIfSymbolDefined(Alias expr, - AnalysisContext context) { + private Expression referenceIfSymbolDefined(Alias expr, AnalysisContext context) { UnresolvedExpression delegatedExpr = expr.getDelegated(); // Pass named expression because expression like window function loses full name // (OVER clause) and thus depends on name in alias to be replaced correctly return optimizer.optimize( DSL.named( - expr.getName(), - delegatedExpr.accept(expressionAnalyzer, context), - expr.getAlias()), + expr.getName(), delegatedExpr.accept(expressionAnalyzer, context), expr.getAlias()), context); } @Override - public List visitAllFields(AllFields node, - AnalysisContext context) { + public List visitAllFields(AllFields node, AnalysisContext context) { TypeEnvironment environment = context.peek(); Map lookupAllFields = environment.lookupAllFields(Namespace.FIELD_NAME); - return lookupAllFields.entrySet().stream().map(entry -> DSL.named(entry.getKey(), - new ReferenceExpression(entry.getKey(), entry.getValue()))).collect(Collectors.toList()); + return lookupAllFields.entrySet().stream() + .map( + entry -> + DSL.named( + entry.getKey(), new ReferenceExpression(entry.getKey(), entry.getValue()))) + .collect(Collectors.toList()); } @Override - public List visitNestedAllTupleFields(NestedAllTupleFields node, - AnalysisContext context) { + public List visitNestedAllTupleFields( + NestedAllTupleFields node, AnalysisContext context) { TypeEnvironment environment = context.peek(); Map lookupAllTupleFields = environment.lookupAllTupleFields(Namespace.FIELD_NAME); @@ -121,25 +116,25 @@ public List visitNestedAllTupleFields(NestedAllTupleFields node Pattern p = Pattern.compile(node.getPath() + "\\.[^\\.]+$"); return lookupAllTupleFields.entrySet().stream() .filter(field -> p.matcher(field.getKey()).find()) - .map(entry -> { - Expression nestedFunc = new Function( - "nested", - List.of( - new QualifiedName(List.of(entry.getKey().split("\\.")))) - ).accept(expressionAnalyzer, context); - return DSL.named("nested(" + entry.getKey() + ")", nestedFunc); - }) + .map( + entry -> { + Expression nestedFunc = + new Function( + "nested", + List.of(new QualifiedName(List.of(entry.getKey().split("\\."))))) + .accept(expressionAnalyzer, context); + return DSL.named("nested(" + entry.getKey() + ")", nestedFunc); + }) .collect(Collectors.toList()); } /** - * Get unqualified name if select item is just a field. For example, suppose an index - * named "accounts", return "age" for "SELECT accounts.age". But do nothing for expression - * in "SELECT ABS(accounts.age)". - * Note that an assumption is made implicitly that original name field in Alias must be - * the same as the values in QualifiedName. This is true because AST builder does this. - * Otherwise, what unqualified() returns will override Alias's name as NamedExpression's name - * even though the QualifiedName doesn't have qualifier. + * Get unqualified name if select item is just a field. For example, suppose an index named + * "accounts", return "age" for "SELECT accounts.age". But do nothing for expression in "SELECT + * ABS(accounts.age)". Note that an assumption is made implicitly that original name field in + * Alias must be the same as the values in QualifiedName. This is true because AST builder does + * this. Otherwise, what unqualified() returns will override Alias's name as NamedExpression's + * name even though the QualifiedName doesn't have qualifier. */ private String unqualifiedNameIfFieldOnly(Alias node, AnalysisContext context) { UnresolvedExpression selectItem = node.getDelegated(); @@ -149,5 +144,4 @@ private String unqualifiedNameIfFieldOnly(Alias node, AnalysisContext context) { } return node.getName(); } - } diff --git a/core/src/main/java/org/opensearch/sql/analysis/TypeEnvironment.java b/core/src/main/java/org/opensearch/sql/analysis/TypeEnvironment.java index 17d203f66f..8baab64810 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/TypeEnvironment.java +++ b/core/src/main/java/org/opensearch/sql/analysis/TypeEnvironment.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.analysis; import static org.opensearch.sql.analysis.symbol.Namespace.FIELD_NAME; @@ -21,16 +20,12 @@ import org.opensearch.sql.expression.ReferenceExpression; import org.opensearch.sql.expression.env.Environment; -/** - * The definition of Type Environment. - */ +/** The definition of Type Environment. */ public class TypeEnvironment implements Environment { - @Getter - private final TypeEnvironment parent; + @Getter private final TypeEnvironment parent; private final SymbolTable symbolTable; - @Getter - private final SymbolTable reservedSymbolTable; + @Getter private final SymbolTable reservedSymbolTable; /** * Constructor with empty symbol tables. @@ -69,15 +64,14 @@ public ExprType resolve(Symbol symbol) { return typeOptional.get(); } } - throw new SemanticCheckException( - String.format("can't resolve %s in type env", symbol)); + throw new SemanticCheckException(String.format("can't resolve %s in type env", symbol)); } /** * Resolve all fields in the current environment. * - * @param namespace a namespace - * @return all symbols in the namespace + * @param namespace a namespace + * @return all symbols in the namespace */ public Map lookupAllFields(Namespace namespace) { Map result = new LinkedHashMap<>(); @@ -87,8 +81,9 @@ public Map lookupAllFields(Namespace namespace) { /** * Resolve all fields in the current environment. - * @param namespace a namespace - * @return all symbols in the namespace + * + * @param namespace a namespace + * @return all symbols in the namespace */ public Map lookupAllTupleFields(Namespace namespace) { Map result = new LinkedHashMap<>(); @@ -100,7 +95,7 @@ public Map lookupAllTupleFields(Namespace namespace) { * Define symbol with the type. * * @param symbol symbol to define - * @param type type + * @param type type */ public void define(Symbol symbol, ExprType type) { symbolTable.store(symbol, type); @@ -119,19 +114,14 @@ public void remove(Symbol symbol) { symbolTable.remove(symbol); } - /** - * Remove ref. - */ + /** Remove ref. */ public void remove(ReferenceExpression ref) { remove(new Symbol(FIELD_NAME, ref.getAttr())); } - /** - * Clear all fields in the current environment. - */ + /** Clear all fields in the current environment. */ public void clearAllFields() { - lookupAllFields(FIELD_NAME).keySet().forEach( - v -> remove(new Symbol(Namespace.FIELD_NAME, v))); + lookupAllFields(FIELD_NAME).keySet().forEach(v -> remove(new Symbol(Namespace.FIELD_NAME, v))); } public void addReservedWord(Symbol symbol, ExprType type) { diff --git a/core/src/main/java/org/opensearch/sql/analysis/WindowExpressionAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/WindowExpressionAnalyzer.java index 3abcf9e140..c4229e4664 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/WindowExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/WindowExpressionAnalyzer.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.analysis; import static org.opensearch.sql.ast.tree.Sort.SortOption.DEFAULT_ASC; @@ -29,28 +28,25 @@ import org.opensearch.sql.planner.logical.LogicalWindow; /** - * Window expression analyzer that analyzes window function expression in expression list - * in project operator. + * Window expression analyzer that analyzes window function expression in expression list in project + * operator. */ @RequiredArgsConstructor public class WindowExpressionAnalyzer extends AbstractNodeVisitor { - /** - * Expression analyzer. - */ + /** Expression analyzer. */ private final ExpressionAnalyzer expressionAnalyzer; - /** - * Child node to be wrapped by a new window operator. - */ + /** Child node to be wrapped by a new window operator. */ private final LogicalPlan child; /** - * Analyze the given project item and return window operator (with child node inside) - * if the given project item is a window function. - * @param projectItem project item - * @param context analysis context - * @return window operator or original child if not windowed + * Analyze the given project item and return window operator (with child node inside) if the given + * project item is a window function. + * + * @param projectItem project item + * @param context analysis context + * @return window operator or original child if not windowed */ public LogicalPlan analyze(UnresolvedExpression projectItem, AnalysisContext context) { LogicalPlan window = projectItem.accept(this, context); @@ -77,26 +73,24 @@ public LogicalPlan visitAlias(Alias node, AnalysisContext context) { return new LogicalWindow(child, namedWindowFunction, windowDefinition); } return new LogicalWindow( - new LogicalSort(child, allSortItems), - namedWindowFunction, - windowDefinition); + new LogicalSort(child, allSortItems), namedWindowFunction, windowDefinition); } private List analyzePartitionList(WindowFunction node, AnalysisContext context) { - return node.getPartitionByList() - .stream() - .map(expr -> expressionAnalyzer.analyze(expr, context)) - .collect(Collectors.toList()); + return node.getPartitionByList().stream() + .map(expr -> expressionAnalyzer.analyze(expr, context)) + .collect(Collectors.toList()); } - private List> analyzeSortList(WindowFunction node, - AnalysisContext context) { - return node.getSortList() - .stream() - .map(pair -> ImmutablePair - .of(analyzeSortOption(pair.getLeft()), - expressionAnalyzer.analyze(pair.getRight(), context))) - .collect(Collectors.toList()); + private List> analyzeSortList( + WindowFunction node, AnalysisContext context) { + return node.getSortList().stream() + .map( + pair -> + ImmutablePair.of( + analyzeSortOption(pair.getLeft()), + expressionAnalyzer.analyze(pair.getRight(), context))) + .collect(Collectors.toList()); } /** @@ -107,9 +101,6 @@ private SortOption analyzeSortOption(SortOption option) { if (option.getNullOrder() == null) { return (option.getSortOrder() == DESC) ? DEFAULT_DESC : DEFAULT_ASC; } - return new SortOption( - (option.getSortOrder() == DESC) ? DESC : ASC, - option.getNullOrder()); + return new SortOption((option.getSortOrder() == DESC) ? DESC : ASC, option.getNullOrder()); } - } diff --git a/core/src/main/java/org/opensearch/sql/analysis/symbol/Namespace.java b/core/src/main/java/org/opensearch/sql/analysis/symbol/Namespace.java index b5203033a8..8211207b2e 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/symbol/Namespace.java +++ b/core/src/main/java/org/opensearch/sql/analysis/symbol/Namespace.java @@ -3,14 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.analysis.symbol; -/** - * Namespace of symbol to avoid naming conflict. - */ +/** Namespace of symbol to avoid naming conflict. */ public enum Namespace { - INDEX_NAME("Index"), FIELD_NAME("Field"), FUNCTION_NAME("Function"); @@ -20,5 +16,4 @@ public enum Namespace { Namespace(String name) { this.name = name; } - } diff --git a/core/src/main/java/org/opensearch/sql/analysis/symbol/Symbol.java b/core/src/main/java/org/opensearch/sql/analysis/symbol/Symbol.java index 8cc9505710..98fa4b3569 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/symbol/Symbol.java +++ b/core/src/main/java/org/opensearch/sql/analysis/symbol/Symbol.java @@ -3,16 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.analysis.symbol; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.ToString; -/** - * Symbol in the scope. - */ +/** Symbol in the scope. */ @ToString @Getter @RequiredArgsConstructor diff --git a/core/src/main/java/org/opensearch/sql/analysis/symbol/SymbolTable.java b/core/src/main/java/org/opensearch/sql/analysis/symbol/SymbolTable.java index be7435c288..8bb6824a63 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/symbol/SymbolTable.java +++ b/core/src/main/java/org/opensearch/sql/analysis/symbol/SymbolTable.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.analysis.symbol; import static java.util.Collections.emptyMap; @@ -17,21 +16,16 @@ import java.util.TreeMap; import org.opensearch.sql.data.type.ExprType; -/** - * Symbol table for symbol definition and resolution. - */ +/** Symbol table for symbol definition and resolution. */ public class SymbolTable { - /** - * Two-dimension hash table to manage symbols with type in different namespace. - */ + /** Two-dimension hash table to manage symbols with type in different namespace. */ private Map> tableByNamespace = new EnumMap<>(Namespace.class); /** - * Two-dimension hash table to manage symbols with type in different namespace. - * Comparing with tableByNamespace, orderedTable use the LinkedHashMap to keep the order of - * symbol. + * Two-dimension hash table to manage symbols with type in different namespace. Comparing with + * tableByNamespace, orderedTable use the LinkedHashMap to keep the order of symbol. */ private Map> orderedTable = new EnumMap<>(Namespace.class); @@ -40,38 +34,32 @@ public class SymbolTable { * Store symbol with the type. Create new map for namespace for the first time. * * @param symbol symbol to define - * @param type symbol type + * @param type symbol type */ public void store(Symbol symbol, ExprType type) { - tableByNamespace.computeIfAbsent( - symbol.getNamespace(), - ns -> new TreeMap<>() - ).put(symbol.getName(), type); + tableByNamespace + .computeIfAbsent(symbol.getNamespace(), ns -> new TreeMap<>()) + .put(symbol.getName(), type); - orderedTable.computeIfAbsent( - symbol.getNamespace(), - ns -> new LinkedHashMap<>() - ).put(symbol.getName(), type); + orderedTable + .computeIfAbsent(symbol.getNamespace(), ns -> new LinkedHashMap<>()) + .put(symbol.getName(), type); } - /** - * Remove a symbol from SymbolTable. - */ + /** Remove a symbol from SymbolTable. */ public void remove(Symbol symbol) { tableByNamespace.computeIfPresent( symbol.getNamespace(), (k, v) -> { v.remove(symbol.getName()); return v; - } - ); + }); orderedTable.computeIfPresent( symbol.getNamespace(), (k, v) -> { v.remove(symbol.getName()); return v; - } - ); + }); } /** @@ -104,42 +92,42 @@ public Map lookupByPrefix(Symbol prefix) { } /** - * Look up all top level symbols in the namespace. - * this function is mainly used by SELECT * use case to get the top level fields - * Todo. currently, the top level fields is the field which doesn't include "." in the name or - * the prefix doesn't exist in the symbol table. - * e.g. The symbol table includes person, person.name, person/2.0. - * person, is the top level field - * person.name, isn't the top level field, because the prefix (person) in symbol table - * person/2.0, is the top level field, because the prefix (person/2) isn't in symbol table + * Look up all top level symbols in the namespace. this function is mainly used by SELECT * use + * case to get the top level fields Todo. currently, the top level fields is the field which + * doesn't include "." in the name or the prefix doesn't exist in the symbol table. e.g. The + * symbol table includes person, person.name, person/2.0. person, is the top level field + * person.name, isn't the top level field, because the prefix (person) in symbol table person/2.0, + * is the top level field, because the prefix (person/2) isn't in symbol table * - * @param namespace a namespace - * @return all symbols in the namespace map + * @param namespace a namespace + * @return all symbols in the namespace map */ public Map lookupAllFields(Namespace namespace) { final LinkedHashMap allSymbols = orderedTable.getOrDefault(namespace, new LinkedHashMap<>()); final LinkedHashMap results = new LinkedHashMap<>(); - allSymbols.entrySet().stream().filter(entry -> { - String symbolName = entry.getKey(); - int lastDot = symbolName.lastIndexOf("."); - return -1 == lastDot || !allSymbols.containsKey(symbolName.substring(0, lastDot)); - }).forEach(entry -> results.put(entry.getKey(), entry.getValue())); + allSymbols.entrySet().stream() + .filter( + entry -> { + String symbolName = entry.getKey(); + int lastDot = symbolName.lastIndexOf("."); + return -1 == lastDot || !allSymbols.containsKey(symbolName.substring(0, lastDot)); + }) + .forEach(entry -> results.put(entry.getKey(), entry.getValue())); return results; } /** * Look up all top level symbols in the namespace. * - * @param namespace a namespace - * @return all symbols in the namespace map + * @param namespace a namespace + * @return all symbols in the namespace map */ public Map lookupAllTupleFields(Namespace namespace) { final LinkedHashMap allSymbols = orderedTable.getOrDefault(namespace, new LinkedHashMap<>()); final LinkedHashMap result = new LinkedHashMap<>(); - allSymbols.entrySet().stream() - .forEach(entry -> result.put(entry.getKey(), entry.getValue())); + allSymbols.entrySet().stream().forEach(entry -> result.put(entry.getKey(), entry.getValue())); return result; } diff --git a/core/src/main/java/org/opensearch/sql/ast/AbstractNodeVisitor.java b/core/src/main/java/org/opensearch/sql/ast/AbstractNodeVisitor.java index f02bc07ccc..973b10310b 100644 --- a/core/src/main/java/org/opensearch/sql/ast/AbstractNodeVisitor.java +++ b/core/src/main/java/org/opensearch/sql/ast/AbstractNodeVisitor.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast; import org.opensearch.sql.ast.expression.AggregateFunction; @@ -62,9 +61,7 @@ import org.opensearch.sql.ast.tree.TableFunction; import org.opensearch.sql.ast.tree.Values; -/** - * AST nodes visitor Defines the traverse path. - */ +/** AST nodes visitor Defines the traverse path. */ public abstract class AbstractNodeVisitor { public T visit(Node node, C context) { @@ -73,6 +70,7 @@ public T visit(Node node, C context) { /** * Visit child node. + * * @param node {@link Node} * @param context Context * @return Return Type. diff --git a/core/src/main/java/org/opensearch/sql/ast/Node.java b/core/src/main/java/org/opensearch/sql/ast/Node.java index f3147eeb43..faaf51f221 100644 --- a/core/src/main/java/org/opensearch/sql/ast/Node.java +++ b/core/src/main/java/org/opensearch/sql/ast/Node.java @@ -3,16 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast; import java.util.List; import lombok.EqualsAndHashCode; import lombok.ToString; -/** - * AST node. - */ +/** AST node. */ @EqualsAndHashCode @ToString public abstract class Node { diff --git a/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java b/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java index d5f10fcfd4..98808f929b 100644 --- a/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java +++ b/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java @@ -249,10 +249,10 @@ public static Function function(String funcName, UnresolvedExpression... funcArg } /** - * CASE - * WHEN search_condition THEN result_expr - * [WHEN search_condition THEN result_expr] ... - * [ELSE result_expr] + * CASE
+ *   WHEN search_condition THEN result_expr
+ *   [WHEN search_condition THEN result_expr] ...
+ *   [ELSE result_expr]
* END */ public UnresolvedExpression caseWhen(UnresolvedExpression elseClause, @@ -261,10 +261,10 @@ public UnresolvedExpression caseWhen(UnresolvedExpression elseClause, } /** - * CASE case_value_expr - * WHEN compare_expr THEN result_expr - * [WHEN compare_expr THEN result_expr] ... - * [ELSE result_expr] + * CASE case_value_expr
+ *   WHEN compare_expr THEN result_expr
+ *   [WHEN compare_expr THEN result_expr] ...
+ *   [ELSE result_expr]
* END */ public UnresolvedExpression caseWhen(UnresolvedExpression caseValueExpr, diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/AggregateFunction.java b/core/src/main/java/org/opensearch/sql/ast/expression/AggregateFunction.java index e8f730d7e9..5208e39623 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/AggregateFunction.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/AggregateFunction.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Collections; @@ -17,8 +16,8 @@ import org.opensearch.sql.common.utils.StringUtils; /** - * Expression node of aggregate functions. - * Params include aggregate function name (AVG, SUM, MAX etc.) and the field to aggregate. + * Expression node of aggregate functions. Params include aggregate function name (AVG, SUM, MAX + * etc.) and the field to aggregate. */ @Getter @EqualsAndHashCode(callSuper = false) @@ -27,13 +26,16 @@ public class AggregateFunction extends UnresolvedExpression { private final String funcName; private final UnresolvedExpression field; private final List argList; + @Setter @Accessors(fluent = true) private UnresolvedExpression condition; + private Boolean distinct = false; /** * Constructor. + * * @param funcName function name. * @param field {@link UnresolvedExpression}. */ @@ -45,6 +47,7 @@ public AggregateFunction(String funcName, UnresolvedExpression field) { /** * Constructor. + * * @param funcName function name. * @param field {@link UnresolvedExpression}. * @param distinct whether distinct field is specified or not. diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Alias.java b/core/src/main/java/org/opensearch/sql/ast/expression/Alias.java index 4183b19a3e..7b3078629b 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Alias.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Alias.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import lombok.AllArgsConstructor; @@ -14,10 +13,10 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; /** - * Alias abstraction that associate an unnamed expression with a name and an optional alias. - * The name and alias information preserved is useful for semantic analysis and response - * formatting eventually. This can avoid restoring the info in toString() method which is - * inaccurate because original info is already lost. + * Alias abstraction that associate an unnamed expression with a name and an optional alias. The + * name and alias information preserved is useful for semantic analysis and response formatting + * eventually. This can avoid restoring the info in toString() method which is inaccurate because + * original info is already lost. */ @AllArgsConstructor @EqualsAndHashCode(callSuper = false) @@ -26,19 +25,13 @@ @ToString public class Alias extends UnresolvedExpression { - /** - * Original field name. - */ + /** Original field name. */ private final String name; - /** - * Expression aliased. - */ + /** Expression aliased. */ private final UnresolvedExpression delegated; - /** - * Optional field alias. - */ + /** Optional field alias. */ private String alias; @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/AllFields.java b/core/src/main/java/org/opensearch/sql/ast/expression/AllFields.java index 1f5d919817..b9b90ea24a 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/AllFields.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/AllFields.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Collections; @@ -13,16 +12,13 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.Node; -/** - * Represent the All fields which is been used in SELECT *. - */ +/** Represent the All fields which is been used in SELECT *. */ @ToString @EqualsAndHashCode(callSuper = false) public class AllFields extends UnresolvedExpression { public static final AllFields INSTANCE = new AllFields(); - private AllFields() { - } + private AllFields() {} public static AllFields of() { return INSTANCE; diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/And.java b/core/src/main/java/org/opensearch/sql/ast/expression/And.java index 8d8c48f3b2..565f1eb4ab 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/And.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/And.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Arrays; @@ -14,9 +13,7 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Expression node of logic AND. - */ +/** Expression node of logic AND. */ @Getter @ToString @EqualsAndHashCode(callSuper = false) diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Argument.java b/core/src/main/java/org/opensearch/sql/ast/expression/Argument.java index f054710a32..4c2a485ea7 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Argument.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Argument.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Arrays; @@ -14,9 +13,7 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Argument. - */ +/** Argument. */ @Getter @ToString @RequiredArgsConstructor diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/AttributeList.java b/core/src/main/java/org/opensearch/sql/ast/expression/AttributeList.java index 7e1fdb1516..d137a83957 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/AttributeList.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/AttributeList.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import com.google.common.collect.ImmutableList; @@ -14,15 +13,12 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Expression node that includes a list of Expression nodes. - */ +/** Expression node that includes a list of Expression nodes. */ @ToString @EqualsAndHashCode(callSuper = false) @AllArgsConstructor public class AttributeList extends UnresolvedExpression { - @Getter - private List attrList; + @Getter private List attrList; @Override public List getChild() { diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Between.java b/core/src/main/java/org/opensearch/sql/ast/expression/Between.java index 886c9a9282..e13c3fb187 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Between.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Between.java @@ -12,9 +12,7 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.Node; -/** - * Unresolved expression for BETWEEN. - */ +/** Unresolved expression for BETWEEN. */ @Data @EqualsAndHashCode(callSuper = false) public class Between extends UnresolvedExpression { diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Case.java b/core/src/main/java/org/opensearch/sql/ast/expression/Case.java index 81c74f3ea4..583bd0de97 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Case.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Case.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import com.google.common.collect.ImmutableList; @@ -15,29 +14,23 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.Node; -/** - * AST node that represents CASE clause similar as Switch statement in programming language. - */ +/** AST node that represents CASE clause similar as Switch statement in programming language. */ @AllArgsConstructor @EqualsAndHashCode(callSuper = false) @Getter @ToString public class Case extends UnresolvedExpression { - /** - * Value to be compared by WHEN statements. Null in the case of CASE WHEN conditions. - */ + /** Value to be compared by WHEN statements. Null in the case of CASE WHEN conditions. */ private final UnresolvedExpression caseValue; /** - * Expression list that represents WHEN statements. Each is a mapping from condition - * to its result. + * Expression list that represents WHEN statements. Each is a mapping from condition to its + * result. */ private final List whenClauses; - /** - * Expression that represents ELSE statement result. - */ + /** Expression that represents ELSE statement result. */ private final UnresolvedExpression elseClause; @Override @@ -58,5 +51,4 @@ public List getChild() { public T accept(AbstractNodeVisitor nodeVisitor, C context) { return nodeVisitor.visitCase(this, context); } - } diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Cast.java b/core/src/main/java/org/opensearch/sql/ast/expression/Cast.java index 9121dbd87c..2019346fb5 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Cast.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Cast.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BOOLEAN; @@ -33,9 +32,7 @@ import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.expression.function.FunctionName; -/** - * AST node that represents Cast clause. - */ +/** AST node that represents Cast clause. */ @AllArgsConstructor @EqualsAndHashCode(callSuper = false) @Getter @@ -59,19 +56,16 @@ public class Cast extends UnresolvedExpression { .put("datetime", CAST_TO_DATETIME.getName()) .build(); - /** - * The source expression cast from. - */ + /** The source expression cast from. */ private final UnresolvedExpression expression; - /** - * Expression that represents name of the target type. - */ + /** Expression that represents name of the target type. */ private final UnresolvedExpression convertedType; /** * Check if the given function name is a cast function or not. - * @param name function name + * + * @param name function name * @return true if cast function, otherwise false. */ public static boolean isCastFunction(FunctionName name) { @@ -80,7 +74,8 @@ public static boolean isCastFunction(FunctionName name) { /** * Get the cast function name for a given target data type. - * @param targetType target data type + * + * @param targetType target data type * @return cast function name corresponding */ public static FunctionName getCastFunctionName(ExprType targetType) { diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Compare.java b/core/src/main/java/org/opensearch/sql/ast/expression/Compare.java index 25cf3e0f73..8ba6ba5116 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Compare.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Compare.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Arrays; diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/DataType.java b/core/src/main/java/org/opensearch/sql/ast/expression/DataType.java index 8755a15177..0b9add8f55 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/DataType.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/DataType.java @@ -3,17 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import lombok.Getter; import lombok.RequiredArgsConstructor; import org.opensearch.sql.data.type.ExprCoreType; -/** - * The DataType defintion in AST. - * Question, could we use {@link ExprCoreType} directly in AST? - */ +/** The DataType defintion in AST. Question, could we use {@link ExprCoreType} directly in AST? */ @RequiredArgsConstructor public enum DataType { TYPE_ERROR(ExprCoreType.UNKNOWN), @@ -32,6 +28,5 @@ public enum DataType { TIMESTAMP(ExprCoreType.TIMESTAMP), INTERVAL(ExprCoreType.INTERVAL); - @Getter - private final ExprCoreType coreType; + @Getter private final ExprCoreType coreType; } diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/EqualTo.java b/core/src/main/java/org/opensearch/sql/ast/expression/EqualTo.java index 806f897abf..344f3c5164 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/EqualTo.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/EqualTo.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Arrays; @@ -14,17 +13,13 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Expression node of binary operator or comparison relation EQUAL. - */ +/** Expression node of binary operator or comparison relation EQUAL. */ @ToString @EqualsAndHashCode(callSuper = false) @AllArgsConstructor public class EqualTo extends UnresolvedExpression { - @Getter - private UnresolvedExpression left; - @Getter - private UnresolvedExpression right; + @Getter private UnresolvedExpression left; + @Getter private UnresolvedExpression right; @Override public List getChild() { diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Field.java b/core/src/main/java/org/opensearch/sql/ast/expression/Field.java index 9a8109fbe3..0a2d726ad4 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Field.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Field.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import com.google.common.collect.ImmutableList; @@ -23,16 +22,12 @@ public class Field extends UnresolvedExpression { private final List fieldArgs; - /** - * Constructor of Field. - */ + /** Constructor of Field. */ public Field(UnresolvedExpression field) { this(field, Collections.emptyList()); } - /** - * Constructor of Field. - */ + /** Constructor of Field. */ public Field(UnresolvedExpression field, List fieldArgs) { this.field = field; this.fieldArgs = fieldArgs; diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Function.java b/core/src/main/java/org/opensearch/sql/ast/expression/Function.java index c712d860f4..184342c5e3 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Function.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Function.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Collections; @@ -14,10 +13,9 @@ import lombok.RequiredArgsConstructor; import org.opensearch.sql.ast.AbstractNodeVisitor; - /** - * Expression node of scalar function. - * Params include function name (@funcName) and function arguments (@funcArgs) + * Expression node of scalar function. Params include function name (@funcName) and function + * arguments (@funcArgs) */ @Getter @EqualsAndHashCode(callSuper = false) @@ -38,9 +36,8 @@ public R accept(AbstractNodeVisitor nodeVisitor, C context) { @Override public String toString() { - return String.format("%s(%s)", funcName, - funcArgs.stream() - .map(Object::toString) - .collect(Collectors.joining(", "))); + return String.format( + "%s(%s)", + funcName, funcArgs.stream().map(Object::toString).collect(Collectors.joining(", "))); } } diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/HighlightFunction.java b/core/src/main/java/org/opensearch/sql/ast/expression/HighlightFunction.java index 0d4e57a78c..128d9327e8 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/HighlightFunction.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/HighlightFunction.java @@ -13,9 +13,7 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Expression node of Highlight function. - */ +/** Expression node of Highlight function. */ @AllArgsConstructor @EqualsAndHashCode(callSuper = false) @Getter diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/In.java b/core/src/main/java/org/opensearch/sql/ast/expression/In.java index 9ce1c124cb..38c1b91b43 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/In.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/In.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Arrays; @@ -15,10 +14,9 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; /** - * Expression node of one-to-many mapping relation IN. - * Params include the field expression and/or wildcard field expression, - * nested field expression (@field). - * And the values that the field is mapped to (@valueList). + * Expression node of one-to-many mapping relation IN. Params include the field expression and/or + * wildcard field expression, nested field expression (@field). And the values that the field is + * mapped to (@valueList). */ @Getter @ToString diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Interval.java b/core/src/main/java/org/opensearch/sql/ast/expression/Interval.java index 84b6ba02d1..c26f829f48 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Interval.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Interval.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Collections; diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/IntervalUnit.java b/core/src/main/java/org/opensearch/sql/ast/expression/IntervalUnit.java index 2a86c89cf6..19e1b07e39 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/IntervalUnit.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/IntervalUnit.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import com.google.common.collect.ImmutableList; @@ -13,7 +12,7 @@ @Getter @RequiredArgsConstructor -public enum IntervalUnit { +public enum IntervalUnit { UNKNOWN, MICROSECOND, @@ -44,9 +43,7 @@ public enum IntervalUnit { INTERVAL_UNITS = builder.add(IntervalUnit.values()).build(); } - /** - * Util method to get interval unit given the unit name. - */ + /** Util method to get interval unit given the unit name. */ public static IntervalUnit of(String unit) { return INTERVAL_UNITS.stream() .filter(v -> unit.equalsIgnoreCase(v.name())) diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Let.java b/core/src/main/java/org/opensearch/sql/ast/expression/Let.java index cea2a091e5..2f63a25f10 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Let.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Let.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import com.google.common.collect.ImmutableList; @@ -14,9 +13,7 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Represent the assign operation. e.g. velocity = distance/speed. - */ +/** Represent the assign operation. e.g. velocity = distance/speed. */ @Getter @ToString @EqualsAndHashCode(callSuper = false) diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Literal.java b/core/src/main/java/org/opensearch/sql/ast/expression/Literal.java index 3ff360dbf0..80c877dd97 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Literal.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Literal.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import com.google.common.collect.ImmutableList; @@ -14,9 +13,8 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; /** - * Expression node of literal type - * Params include literal value (@value) and - * literal data type (@type) which can be selected from {@link DataType}. + * Expression node of literal type Params include literal value (@value) and literal data type + * (@type) which can be selected from {@link DataType}. */ @Getter @EqualsAndHashCode(callSuper = false) diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Map.java b/core/src/main/java/org/opensearch/sql/ast/expression/Map.java index 45e98f127f..73d8d77261 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Map.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Map.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Arrays; @@ -14,9 +13,7 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Expression node of one-to-one mapping relation. - */ +/** Expression node of one-to-one mapping relation. */ @Getter @ToString @EqualsAndHashCode(callSuper = false) diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/NestedAllTupleFields.java b/core/src/main/java/org/opensearch/sql/ast/expression/NestedAllTupleFields.java index adf2025e6c..be89dd9f19 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/NestedAllTupleFields.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/NestedAllTupleFields.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Collections; @@ -11,18 +10,14 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; -import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.Node; -/** - * Represents all tuple fields used in nested function. - */ +/** Represents all tuple fields used in nested function. */ @RequiredArgsConstructor @EqualsAndHashCode(callSuper = false) public class NestedAllTupleFields extends UnresolvedExpression { - @Getter - private final String path; + @Getter private final String path; @Override public List getChild() { diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Not.java b/core/src/main/java/org/opensearch/sql/ast/expression/Not.java index 2926c7e5cd..423cb088ef 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Not.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Not.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Arrays; @@ -14,9 +13,7 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Expression node of the logic NOT. - */ +/** Expression node of the logic NOT. */ @Getter @ToString @EqualsAndHashCode(callSuper = false) diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Or.java b/core/src/main/java/org/opensearch/sql/ast/expression/Or.java index b0dabb6e4e..cc59170d31 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Or.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Or.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Arrays; @@ -14,9 +13,7 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Expression node of the logic OR. - */ +/** Expression node of the logic OR. */ @Getter @ToString @EqualsAndHashCode(callSuper = false) diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/ParseMethod.java b/core/src/main/java/org/opensearch/sql/ast/expression/ParseMethod.java index 83a46323e6..7a2587c5f0 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/ParseMethod.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/ParseMethod.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import lombok.Getter; @@ -15,6 +14,5 @@ public enum ParseMethod { GROK("grok"), PATTERNS("patterns"); - @Getter - private final String name; + @Getter private final String name; } diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/QualifiedName.java b/core/src/main/java/org/opensearch/sql/ast/expression/QualifiedName.java index 8b16119dc0..73c6e3782a 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/QualifiedName.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/QualifiedName.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import static java.util.Objects.requireNonNull; @@ -29,9 +28,7 @@ public QualifiedName(String name) { this.parts = Collections.singletonList(name); } - /** - * QualifiedName Constructor. - */ + /** QualifiedName Constructor. */ public QualifiedName(Iterable parts) { List partsList = StreamSupport.stream(parts.spliterator(), false).collect(toList()); if (partsList.isEmpty()) { @@ -40,9 +37,7 @@ public QualifiedName(Iterable parts) { this.parts = partsList; } - /** - * Construct {@link QualifiedName} from list of string. - */ + /** Construct {@link QualifiedName} from list of string. */ public static QualifiedName of(String first, String... rest) { requireNonNull(first); ArrayList parts = new ArrayList<>(); @@ -55,9 +50,7 @@ public static QualifiedName of(Iterable parts) { return new QualifiedName(parts); } - /** - * Get Prefix of {@link QualifiedName}. - */ + /** Get Prefix of {@link QualifiedName}. */ public Optional getPrefix() { if (parts.size() == 1) { return Optional.empty(); @@ -71,7 +64,8 @@ public String getSuffix() { /** * Get first part of the qualified name. - * @return first part + * + * @return first part */ public Optional first() { if (parts.size() == 1) { @@ -81,17 +75,17 @@ public Optional first() { } /** - * Get rest parts of the qualified name. Assume that there must be remaining parts - * so caller is responsible for the check (first() or size() must be called first). - * For example: - * {@code - * QualifiedName name = ... - * Optional first = name.first(); - * if (first.isPresent()) { - * name.rest() ... - * } + * Get rest parts of the qualified name. Assume that there must be remaining parts so caller is + * responsible for the check (first() or size() must be called first).
+ * For example:
+ * {@code
+ *   QualifiedName name = ...
+ *   Optional first = name.first();
+ *   if (first.isPresent()) {
+ *   name.rest() ...
+ *   }
* } - * @return rest part(s) + * @return rest part(s) */ public QualifiedName rest() { return QualifiedName.of(parts.subList(1, parts.size())); diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/RelevanceFieldList.java b/core/src/main/java/org/opensearch/sql/ast/expression/RelevanceFieldList.java index 3166fe45c3..a9e26a611f 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/RelevanceFieldList.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/RelevanceFieldList.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.List; @@ -13,14 +12,11 @@ import lombok.Getter; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Expression node that includes a list of RelevanceField nodes. - */ +/** Expression node that includes a list of RelevanceField nodes. */ @EqualsAndHashCode(callSuper = false) @AllArgsConstructor public class RelevanceFieldList extends UnresolvedExpression { - @Getter - private java.util.Map fieldList; + @Getter private java.util.Map fieldList; @Override public List getChild() { @@ -34,9 +30,7 @@ public R accept(AbstractNodeVisitor nodeVisitor, C context) { @Override public String toString() { - return fieldList - .entrySet() - .stream() + return fieldList.entrySet().stream() .map(e -> String.format("\"%s\" ^ %s", e.getKey(), e.getValue())) .collect(Collectors.joining(", ")); } diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/ScoreFunction.java b/core/src/main/java/org/opensearch/sql/ast/expression/ScoreFunction.java index 1b73f9bd95..26d784dd8c 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/ScoreFunction.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/ScoreFunction.java @@ -13,8 +13,8 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; /** - * Expression node of Score function. - * Score takes a relevance-search expression as an argument and returns it + * Expression node of Score function. Score takes a relevance-search expression as an argument and + * returns it */ @AllArgsConstructor @EqualsAndHashCode(callSuper = false) diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Span.java b/core/src/main/java/org/opensearch/sql/ast/expression/Span.java index e57205c19c..edd309b22d 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Span.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Span.java @@ -13,10 +13,7 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Span expression node. - * Params include field expression and the span value. - */ +/** Span expression node. Params include field expression and the span value. */ @Getter @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @@ -35,5 +32,4 @@ public List getChild() { public R accept(AbstractNodeVisitor nodeVisitor, C context) { return nodeVisitor.visitSpan(this, context); } - } diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/SpanUnit.java b/core/src/main/java/org/opensearch/sql/ast/expression/SpanUnit.java index f1f3fb19d4..5252781edb 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/SpanUnit.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/SpanUnit.java @@ -42,9 +42,7 @@ public enum SpanUnit { SPAN_UNITS = builder.add(SpanUnit.values()).build(); } - /** - * Util method to get span unit given the unit name. - */ + /** Util method to get span unit given the unit name. */ public static SpanUnit of(String unit) { switch (unit) { case "": @@ -64,5 +62,4 @@ public static SpanUnit of(String unit) { public static String getName(SpanUnit unit) { return unit.name; } - } diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedArgument.java b/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedArgument.java index e4def038ed..2c6eee46e9 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedArgument.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedArgument.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Arrays; @@ -13,9 +12,7 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Argument. - */ +/** Argument. */ @Getter @ToString @EqualsAndHashCode(callSuper = false) diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedAttribute.java b/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedAttribute.java index f4bc88853f..e1754cbf76 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedAttribute.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedAttribute.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import com.google.common.collect.ImmutableList; @@ -15,9 +14,8 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; /** - * Expression node, representing the syntax that is not resolved to - * any other expression nodes yet but non-negligible - * This expression is often created as the index name, field name etc. + * Expression node, representing the syntax that is not resolved to any other expression nodes yet + * but non-negligible This expression is often created as the index name, field name etc. */ @ToString @EqualsAndHashCode(callSuper = false) diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedExpression.java b/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedExpression.java index ee3922f797..9b2d530b7f 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedExpression.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedExpression.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import lombok.EqualsAndHashCode; diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/When.java b/core/src/main/java/org/opensearch/sql/ast/expression/When.java index a52870b408..db747592e5 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/When.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/When.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import com.google.common.collect.ImmutableList; @@ -15,23 +14,17 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.Node; -/** - * AST node that represents WHEN clause. - */ +/** AST node that represents WHEN clause. */ @EqualsAndHashCode(callSuper = false) @Getter @RequiredArgsConstructor @ToString public class When extends UnresolvedExpression { - /** - * WHEN condition, either a search condition or compare value if case value present. - */ + /** WHEN condition, either a search condition or compare value if case value present. */ private final UnresolvedExpression condition; - /** - * Result to return if condition matched. - */ + /** Result to return if condition matched. */ private final UnresolvedExpression result; @Override @@ -43,5 +36,4 @@ public List getChild() { public T accept(AbstractNodeVisitor nodeVisitor, C context) { return nodeVisitor.visitWhen(this, context); } - } diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/WindowFunction.java b/core/src/main/java/org/opensearch/sql/ast/expression/WindowFunction.java index 9a7535e1fe..47f5265765 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/WindowFunction.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/WindowFunction.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import com.google.common.collect.ImmutableList; @@ -42,5 +41,4 @@ public List getChild() { public T accept(AbstractNodeVisitor nodeVisitor, C context) { return nodeVisitor.visitWindowFunction(this, context); } - } diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Xor.java b/core/src/main/java/org/opensearch/sql/ast/expression/Xor.java index 731feccd33..40db015fd7 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Xor.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Xor.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import java.util.Arrays; @@ -14,9 +13,7 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Expression node of the logic XOR. - */ +/** Expression node of the logic XOR. */ @Getter @ToString @EqualsAndHashCode(callSuper = false) diff --git a/core/src/main/java/org/opensearch/sql/ast/statement/Explain.java b/core/src/main/java/org/opensearch/sql/ast/statement/Explain.java index 1e364d69fd..5ee260c130 100644 --- a/core/src/main/java/org/opensearch/sql/ast/statement/Explain.java +++ b/core/src/main/java/org/opensearch/sql/ast/statement/Explain.java @@ -12,9 +12,7 @@ import lombok.EqualsAndHashCode; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Explain Statement. - */ +/** Explain Statement. */ @Data @EqualsAndHashCode(callSuper = false) public class Explain extends Statement { diff --git a/core/src/main/java/org/opensearch/sql/ast/statement/Query.java b/core/src/main/java/org/opensearch/sql/ast/statement/Query.java index 82efdde4dd..6366451b72 100644 --- a/core/src/main/java/org/opensearch/sql/ast/statement/Query.java +++ b/core/src/main/java/org/opensearch/sql/ast/statement/Query.java @@ -16,9 +16,7 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.tree.UnresolvedPlan; -/** - * Query Statement. - */ +/** Query Statement. */ @Getter @Setter @ToString diff --git a/core/src/main/java/org/opensearch/sql/ast/statement/Statement.java b/core/src/main/java/org/opensearch/sql/ast/statement/Statement.java index e32a8dbfd8..d90071a0ca 100644 --- a/core/src/main/java/org/opensearch/sql/ast/statement/Statement.java +++ b/core/src/main/java/org/opensearch/sql/ast/statement/Statement.java @@ -11,9 +11,7 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.Node; -/** - * Statement is the high interface of core engine. - */ +/** Statement is the high interface of core engine. */ public abstract class Statement extends Node { @Override public R accept(AbstractNodeVisitor visitor, C context) { diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/AD.java b/core/src/main/java/org/opensearch/sql/ast/tree/AD.java index e9aee25c23..0e1cc33db9 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/AD.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/AD.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Aggregation.java b/core/src/main/java/org/opensearch/sql/ast/tree/Aggregation.java index e9fa26e981..f098d0ec53 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Aggregation.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Aggregation.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; @@ -17,9 +16,7 @@ import org.opensearch.sql.ast.expression.Argument; import org.opensearch.sql.ast.expression.UnresolvedExpression; -/** - * Logical plan node of Aggregation, the interface for building aggregation actions in queries. - */ +/** Logical plan node of Aggregation, the interface for building aggregation actions in queries. */ @Getter @Setter @ToString @@ -32,23 +29,21 @@ public class Aggregation extends UnresolvedPlan { private List argExprList; private UnresolvedPlan child; - /** - * Aggregation Constructor without span and argument. - */ - public Aggregation(List aggExprList, - List sortExprList, - List groupExprList) { + /** Aggregation Constructor without span and argument. */ + public Aggregation( + List aggExprList, + List sortExprList, + List groupExprList) { this(aggExprList, sortExprList, groupExprList, null, Collections.emptyList()); } - /** - * Aggregation Constructor. - */ - public Aggregation(List aggExprList, - List sortExprList, - List groupExprList, - UnresolvedExpression span, - List argExprList) { + /** Aggregation Constructor. */ + public Aggregation( + List aggExprList, + List sortExprList, + List groupExprList, + UnresolvedExpression span, + List argExprList) { this.aggExprList = aggExprList; this.sortExprList = sortExprList; this.groupExprList = groupExprList; diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/CloseCursor.java b/core/src/main/java/org/opensearch/sql/ast/tree/CloseCursor.java index cf82c2b070..832b79d34a 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/CloseCursor.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/CloseCursor.java @@ -9,15 +9,10 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.Node; -/** - * AST node to represent close cursor operation. - * Actually a wrapper to the AST. - */ +/** AST node to represent close cursor operation. Actually a wrapper to the AST. */ public class CloseCursor extends UnresolvedPlan { - /** - * An instance of {@link FetchCursor}. - */ + /** An instance of {@link FetchCursor}. */ private UnresolvedPlan cursor; @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Dedupe.java b/core/src/main/java/org/opensearch/sql/ast/tree/Dedupe.java index 6514d65a04..3173f42f9c 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Dedupe.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Dedupe.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; @@ -18,9 +17,7 @@ import org.opensearch.sql.ast.expression.Argument; import org.opensearch.sql.ast.expression.Field; -/** - * AST node represent Dedupe operation. - */ +/** AST node represent Dedupe operation. */ @Getter @Setter @ToString diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Eval.java b/core/src/main/java/org/opensearch/sql/ast/tree/Eval.java index 184f2ac497..ecceabd757 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Eval.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Eval.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; @@ -16,9 +15,7 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.expression.Let; -/** - * AST node represent Eval operation. - */ +/** AST node represent Eval operation. */ @Getter @Setter @ToString diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/FetchCursor.java b/core/src/main/java/org/opensearch/sql/ast/tree/FetchCursor.java index aa327c295b..d6a260ad0b 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/FetchCursor.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/FetchCursor.java @@ -10,15 +10,11 @@ import lombok.RequiredArgsConstructor; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * An unresolved plan that represents fetching the next - * batch in paginationed plan. - */ +/** An unresolved plan that represents fetching the next batch in paginated plan. */ @RequiredArgsConstructor @EqualsAndHashCode(callSuper = false) public class FetchCursor extends UnresolvedPlan { - @Getter - final String cursor; + @Getter final String cursor; @Override public T accept(AbstractNodeVisitor nodeVisitor, C context) { diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Filter.java b/core/src/main/java/org/opensearch/sql/ast/tree/Filter.java index 8128078930..6c57275db9 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Filter.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Filter.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; @@ -14,9 +13,7 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.expression.UnresolvedExpression; -/** - * Logical plan node of Filter, the interface for building filters in queries. - */ +/** Logical plan node of Filter, the interface for building filters in queries. */ @ToString @EqualsAndHashCode(callSuper = false) @Getter diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Head.java b/core/src/main/java/org/opensearch/sql/ast/tree/Head.java index 8590c212ad..bf6b2caed1 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Head.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Head.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; @@ -16,9 +15,7 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * AST node represent Head operation. - */ +/** AST node represent Head operation. */ @Getter @Setter @ToString diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Kmeans.java b/core/src/main/java/org/opensearch/sql/ast/tree/Kmeans.java index 5d2e32c28b..ed03efed8a 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Kmeans.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Kmeans.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Limit.java b/core/src/main/java/org/opensearch/sql/ast/tree/Limit.java index f9b8a8feab..9290776172 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Limit.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Limit.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; @@ -38,5 +37,4 @@ public List getChild() { public T accept(AbstractNodeVisitor visitor, C context) { return visitor.visitLimit(this, context); } - } diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/ML.java b/core/src/main/java/org/opensearch/sql/ast/tree/ML.java index 2f83a993b7..320fb2bcf7 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/ML.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/ML.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import static org.opensearch.sql.utils.MLCommonsConstants.ACTION; @@ -66,7 +65,7 @@ public List getChild() { } private String getAction() { - return (String) arguments.get(ACTION).getValue(); + return (String) arguments.get(ACTION).getValue(); } /** @@ -85,7 +84,7 @@ public Map getOutputSchema(TypeEnvironment env) { return getPredictOutputSchema(); default: throw new IllegalArgumentException( - "Action error. Please indicate train, predict or trainandpredict."); + "Action error. Please indicate train, predict or trainandpredict."); } } @@ -122,8 +121,8 @@ public Map getPredictOutputSchema() { * @return the schema */ public Map getTrainOutputSchema() { - boolean isAsync = arguments.containsKey(ASYNC) - ? (boolean) arguments.get(ASYNC).getValue() : false; + boolean isAsync = + arguments.containsKey(ASYNC) ? (boolean) arguments.get(ASYNC).getValue() : false; Map res = new HashMap<>(Map.of(STATUS, ExprCoreType.STRING)); if (isAsync) { res.put(TASKID, ExprCoreType.STRING); diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Paginate.java b/core/src/main/java/org/opensearch/sql/ast/tree/Paginate.java index 55e0e8c7a6..69b11600c9 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Paginate.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Paginate.java @@ -13,16 +13,12 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.Node; -/** - * AST node to represent pagination operation. - * Actually a wrapper to the AST. - */ +/** AST node to represent pagination operation. Actually a wrapper to the AST. */ @RequiredArgsConstructor @EqualsAndHashCode(callSuper = false) @ToString public class Paginate extends UnresolvedPlan { - @Getter - private final int pageSize; + @Getter private final int pageSize; private UnresolvedPlan child; public Paginate(int pageSize, UnresolvedPlan child) { diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Parse.java b/core/src/main/java/org/opensearch/sql/ast/tree/Parse.java index 02a69c93af..e91c4a68ff 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Parse.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Parse.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; @@ -20,9 +19,7 @@ import org.opensearch.sql.ast.expression.ParseMethod; import org.opensearch.sql.ast.expression.UnresolvedExpression; -/** - * AST node represent Parse with regex operation. - */ +/** AST node represent Parse with regex operation. */ @Getter @Setter @ToString @@ -30,29 +27,19 @@ @RequiredArgsConstructor @AllArgsConstructor public class Parse extends UnresolvedPlan { - /** - * Method used to parse a field. - */ + /** Method used to parse a field. */ private final ParseMethod parseMethod; - /** - * Field. - */ + /** Field. */ private final UnresolvedExpression sourceField; - /** - * Pattern. - */ + /** Pattern. */ private final Literal pattern; - /** - * Optional arguments. - */ + /** Optional arguments. */ private final Map arguments; - /** - * Child Plan. - */ + /** Child Plan. */ private UnresolvedPlan child; @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Project.java b/core/src/main/java/org/opensearch/sql/ast/tree/Project.java index 33c7128855..cffb4dfdce 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Project.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Project.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; @@ -17,15 +16,12 @@ import org.opensearch.sql.ast.expression.Argument; import org.opensearch.sql.ast.expression.UnresolvedExpression; -/** - * Logical plan node of Project, the interface for building the list of searching fields. - */ +/** Logical plan node of Project, the interface for building the list of searching fields. */ @ToString @Getter @EqualsAndHashCode(callSuper = false) public class Project extends UnresolvedPlan { - @Setter - private List projectList; + @Setter private List projectList; private List argExprList; private UnresolvedPlan child; @@ -43,9 +39,7 @@ public boolean hasArgument() { return !argExprList.isEmpty(); } - /** - * The Project could been used to exclude fields from the source. - */ + /** The Project could been used to exclude fields from the source. */ public boolean isExcluded() { if (hasArgument()) { Argument argument = argExprList.get(0); diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java b/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java index 407d37e8e4..2cbe170541 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import java.util.Collections; @@ -19,9 +18,7 @@ import org.opensearch.sql.ast.expression.Field; import org.opensearch.sql.ast.expression.UnresolvedExpression; -/** - * AST node represent RareTopN operation. - */ +/** AST node represent RareTopN operation. */ @Getter @Setter @ToString diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java b/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java index 8c3868329f..ec5264a86b 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; @@ -18,9 +17,7 @@ import org.opensearch.sql.ast.expression.QualifiedName; import org.opensearch.sql.ast.expression.UnresolvedExpression; -/** - * Logical plan node of Relation, the interface for building the searching sources. - */ +/** Logical plan node of Relation, the interface for building the searching sources. */ @AllArgsConstructor @ToString @EqualsAndHashCode(callSuper = false) @@ -39,9 +36,7 @@ public Relation(UnresolvedExpression tableName, String alias) { this.alias = alias; } - /** - * Optional alias name for the relation. - */ + /** Optional alias name for the relation. */ private String alias; /** @@ -72,9 +67,9 @@ public String getAlias() { } /** - * Get Qualified name preservs parts of the user given identifiers. - * This can later be utilized to determine DataSource,Schema and Table Name during - * Analyzer stage. So Passing QualifiedName directly to Analyzer Stage. + * Get Qualified name preservs parts of the user given identifiers. This can later be utilized to + * determine DataSource,Schema and Table Name during Analyzer stage. So Passing QualifiedName + * directly to Analyzer Stage. * * @return TableQualifiedName. */ @@ -82,9 +77,10 @@ public QualifiedName getTableQualifiedName() { if (tableName.size() == 1) { return (QualifiedName) tableName.get(0); } else { - return new QualifiedName(tableName.stream() - .map(UnresolvedExpression::toString) - .collect(Collectors.joining(COMMA))); + return new QualifiedName( + tableName.stream() + .map(UnresolvedExpression::toString) + .collect(Collectors.joining(COMMA))); } } diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/RelationSubquery.java b/core/src/main/java/org/opensearch/sql/ast/tree/RelationSubquery.java index 89122bea7f..5ab4d71dd9 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/RelationSubquery.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/RelationSubquery.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; @@ -14,9 +13,7 @@ import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -/** - * Logical plan node of RelationSubquery. - */ +/** Logical plan node of RelationSubquery. */ @AllArgsConstructor @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @@ -25,9 +22,7 @@ public class RelationSubquery extends UnresolvedPlan { private UnresolvedPlan query; private String alias; - /** - * Take subquery alias as table name. - */ + /** Take subquery alias as table name. */ public String getAliasAsTableName() { return alias; } diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Rename.java b/core/src/main/java/org/opensearch/sql/ast/tree/Rename.java index 69700c871c..e6f760aca0 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Rename.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Rename.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Sort.java b/core/src/main/java/org/opensearch/sql/ast/tree/Sort.java index 5fb4139bea..073cb7aa1b 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Sort.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Sort.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import static org.opensearch.sql.ast.tree.Sort.NullOrder.NULL_FIRST; @@ -22,9 +21,7 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.expression.Field; -/** - * AST node for Sort {@link Sort#sortList} represent a list of sort expression and sort options. - */ +/** AST node for Sort {@link Sort#sortList} represent a list of sort expression and sort options. */ @ToString @EqualsAndHashCode(callSuper = false) @Getter @@ -50,19 +47,14 @@ public T accept(AbstractNodeVisitor nodeVisitor, C context) { return nodeVisitor.visitSort(this, context); } - /** - * Sort Options. - */ + /** Sort Options. */ @Data public static class SortOption { - /** - * Default ascending sort option, null first. - */ + /** Default ascending sort option, null first. */ public static SortOption DEFAULT_ASC = new SortOption(ASC, NULL_FIRST); - /** - * Default descending sort option, null last. - */ + + /** Default descending sort option, null last. */ public static SortOption DEFAULT_DESC = new SortOption(DESC, NULL_LAST); private final SortOrder sortOrder; diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/TableFunction.java b/core/src/main/java/org/opensearch/sql/ast/tree/TableFunction.java index 064cbf24fe..a67a943dcb 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/TableFunction.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/TableFunction.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; @@ -11,16 +10,12 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; -import lombok.Setter; import lombok.ToString; import org.opensearch.sql.ast.AbstractNodeVisitor; -import org.opensearch.sql.ast.expression.Let; import org.opensearch.sql.ast.expression.QualifiedName; import org.opensearch.sql.ast.expression.UnresolvedExpression; -/** - * ASTNode for Table Function. - */ +/** AST Node for Table Function. */ @ToString @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @@ -28,8 +23,7 @@ public class TableFunction extends UnresolvedPlan { private final UnresolvedExpression functionName; - @Getter - private final List arguments; + @Getter private final List arguments; public QualifiedName getFunctionName() { return (QualifiedName) functionName; diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/UnresolvedPlan.java b/core/src/main/java/org/opensearch/sql/ast/tree/UnresolvedPlan.java index 672a4602ed..3074303b0d 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/UnresolvedPlan.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/UnresolvedPlan.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import lombok.EqualsAndHashCode; @@ -11,9 +10,7 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; import org.opensearch.sql.ast.Node; -/** - * Abstract unresolved plan. - */ +/** Abstract unresolved plan. */ @EqualsAndHashCode(callSuper = false) @ToString public abstract class UnresolvedPlan extends Node { diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Values.java b/core/src/main/java/org/opensearch/sql/ast/tree/Values.java index 5a662912f9..65d7e8d7cb 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Values.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Values.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; @@ -16,9 +15,7 @@ import org.opensearch.sql.ast.Node; import org.opensearch.sql.ast.expression.Literal; -/** - * AST node class for a sequence of literal values. - */ +/** AST node class for a sequence of literal values. */ @ToString @Getter @EqualsAndHashCode(callSuper = false) @@ -41,5 +38,4 @@ public T accept(AbstractNodeVisitor nodeVisitor, C context) { public List getChild() { return ImmutableList.of(); } - } diff --git a/core/src/main/java/org/opensearch/sql/data/model/AbstractExprNumberValue.java b/core/src/main/java/org/opensearch/sql/data/model/AbstractExprNumberValue.java index 1f6363c068..48781df847 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/AbstractExprNumberValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/AbstractExprNumberValue.java @@ -3,15 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import com.google.common.base.Objects; import lombok.RequiredArgsConstructor; -/** - * Expression Number Value. - */ +/** Expression Number Value. */ @RequiredArgsConstructor public abstract class AbstractExprNumberValue extends AbstractExprValue { private final Number value; diff --git a/core/src/main/java/org/opensearch/sql/data/model/AbstractExprValue.java b/core/src/main/java/org/opensearch/sql/data/model/AbstractExprValue.java index ad2c2ddb49..f5ac4d493b 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/AbstractExprValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/AbstractExprValue.java @@ -3,23 +3,18 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import org.opensearch.sql.exception.ExpressionEvaluationException; -/** - * Abstract ExprValue. - */ +/** Abstract ExprValue. */ public abstract class AbstractExprValue implements ExprValue { - /** - * The customize compareTo logic. - */ + /** The customize compareTo logic. */ @Override public int compareTo(ExprValue other) { if (this.isNull() || this.isMissing() || other.isNull() || other.isMissing()) { throw new IllegalStateException( - "[BUG] Unreachable, Comparing with NULL or MISSING is undefined"); + "[BUG] Unreachable, Comparing with NULL or MISSING is undefined"); } if ((this.isNumber() && other.isNumber()) || (this.isDateTime() && other.isDateTime()) @@ -36,11 +31,33 @@ public int compareTo(ExprValue other) { /** * The customize equals logic. * The table below list the NULL and MISSING handling logic. - * A B A == B - * NULL NULL TRUE - * NULL MISSING FALSE - * MISSING NULL FALSE - * MISSING MISSING TRUE + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
ABA == B
NULLNULLTRUE
NULLMISSINGFALSE
MISSINGNULLFALSE
MISSINGMISSINGTRUE
*/ @Override public boolean equals(Object o) { @@ -59,13 +76,9 @@ public boolean equals(Object o) { } } - /** - * The expression value compare. - */ + /** The expression value compare. */ public abstract int compare(ExprValue other); - /** - * The expression value equal. - */ + /** The expression value equal. */ public abstract boolean equal(ExprValue other); } diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprBooleanValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprBooleanValue.java index d655c0dabb..ee97cf2228 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprBooleanValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprBooleanValue.java @@ -3,16 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import com.google.common.base.Objects; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; -/** - * Expression Boolean Value. - */ +/** Expression Boolean Value. */ public class ExprBooleanValue extends AbstractExprValue { private static final ExprBooleanValue TRUE = new ExprBooleanValue(true); private static final ExprBooleanValue FALSE = new ExprBooleanValue(false); diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprByteValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprByteValue.java index b39e6e9d7f..8e74a83cf3 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprByteValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprByteValue.java @@ -3,15 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; -/** - * Expression Byte Value. - */ +/** Expression Byte Value. */ public class ExprByteValue extends AbstractExprNumberValue { public ExprByteValue(Number value) { diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprCollectionValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprCollectionValue.java index 1326733263..d1f56c3d76 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprCollectionValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprCollectionValue.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import com.google.common.base.Objects; @@ -15,9 +14,7 @@ import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; -/** - * Expression Collection Value. - */ +/** Expression Collection Value. */ @RequiredArgsConstructor public class ExprCollectionValue extends AbstractExprValue { private final List valueList; @@ -43,9 +40,7 @@ public List collectionValue() { @Override public String toString() { - return valueList.stream() - .map(Object::toString) - .collect(Collectors.joining(", ", "[", "]")); + return valueList.stream().map(Object::toString).collect(Collectors.joining(", ", "[", "]")); } @Override @@ -68,9 +63,7 @@ public boolean equal(ExprValue o) { } } - /** - * Only compare the size of the list. - */ + /** Only compare the size of the list. */ @Override public int compare(ExprValue other) { return Integer.compare(valueList.size(), other.collectionValue().size()); diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java index 57ce87df47..3f3f67a4fa 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL; @@ -22,23 +21,19 @@ import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.exception.SemanticCheckException; -/** - * Expression Date Value. - */ +/** Expression Date Value. */ @RequiredArgsConstructor public class ExprDateValue extends AbstractExprValue { private final LocalDate date; - /** - * Constructor of ExprDateValue. - */ + /** Constructor of ExprDateValue. */ public ExprDateValue(String date) { try { this.date = LocalDate.parse(date, DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL); } catch (DateTimeParseException e) { - throw new SemanticCheckException(String.format("date:%s in unsupported format, please use " - + "yyyy-MM-dd", date)); + throw new SemanticCheckException( + String.format("date:%s in unsupported format, please use 'yyyy-MM-dd'", date)); } } diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprDatetimeValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprDatetimeValue.java index 8d40aaf82c..305958043f 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprDatetimeValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprDatetimeValue.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_WITH_TZ; @@ -23,20 +22,19 @@ import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.exception.SemanticCheckException; - @RequiredArgsConstructor public class ExprDatetimeValue extends AbstractExprValue { private final LocalDateTime datetime; - /** - * Constructor with datetime string as input. - */ + /** Constructor with datetime string as input. */ public ExprDatetimeValue(String datetime) { try { this.datetime = LocalDateTime.parse(datetime, DATE_TIME_FORMATTER_WITH_TZ); } catch (DateTimeParseException e) { - throw new SemanticCheckException(String.format("datetime:%s in unsupported format, please " - + "use yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]", datetime)); + throw new SemanticCheckException( + String.format( + "datetime:%s in unsupported format, please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", + datetime)); } } @@ -77,9 +75,11 @@ public boolean equal(ExprValue other) { @Override public String value() { - return String.format("%s %s", DateTimeFormatter.ISO_DATE.format(datetime), - DateTimeFormatter.ISO_TIME.format((datetime.getNano() == 0) - ? datetime.truncatedTo(ChronoUnit.SECONDS) : datetime)); + return String.format( + "%s %s", + DateTimeFormatter.ISO_DATE.format(datetime), + DateTimeFormatter.ISO_TIME.format( + (datetime.getNano() == 0) ? datetime.truncatedTo(ChronoUnit.SECONDS) : datetime)); } @Override diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprDoubleValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprDoubleValue.java index 171b064e68..c192fe901c 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprDoubleValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprDoubleValue.java @@ -3,15 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; -/** - * Expression Double Value. - */ +/** Expression Double Value. */ public class ExprDoubleValue extends AbstractExprNumberValue { public ExprDoubleValue(Number value) { diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprFloatValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprFloatValue.java index dc454b4b50..6d321687fb 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprFloatValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprFloatValue.java @@ -3,15 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; -/** - * Expression Float Value. - */ +/** Expression Float Value. */ public class ExprFloatValue extends AbstractExprNumberValue { public ExprFloatValue(Number value) { diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprIntegerValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprIntegerValue.java index 06947766fc..81321c1f12 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprIntegerValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprIntegerValue.java @@ -3,15 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; -/** - * Expression Integer Value. - */ +/** Expression Integer Value. */ public class ExprIntegerValue extends AbstractExprNumberValue { public ExprIntegerValue(Number value) { diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprIntervalValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprIntervalValue.java index 25a3115e8c..754520d7c8 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprIntervalValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprIntervalValue.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import java.time.temporal.TemporalAmount; @@ -27,7 +26,8 @@ public int compare(ExprValue other) { TemporalAmount otherInterval = other.intervalValue(); if (!interval.getClass().equals(other.intervalValue().getClass())) { throw new ExpressionEvaluationException( - String.format("invalid to compare intervals with units %s and %s", + String.format( + "invalid to compare intervals with units %s and %s", unit(), ((ExprIntervalValue) other).unit())); } return Long.compare( @@ -49,12 +49,9 @@ public ExprType type() { return ExprCoreType.INTERVAL; } - /** - * Util method to get temporal unit stored locally. - */ + /** Util method to get temporal unit stored locally. */ public TemporalUnit unit() { - return interval.getUnits() - .stream() + return interval.getUnits().stream() .filter(v -> interval.get(v) != 0) .findAny() .orElse(interval.getUnits().get(0)); diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprLongValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprLongValue.java index 1df590246c..537a164490 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprLongValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprLongValue.java @@ -3,15 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; -/** - * Expression Long Value. - */ +/** Expression Long Value. */ public class ExprLongValue extends AbstractExprNumberValue { public ExprLongValue(Number value) { diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprMissingValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprMissingValue.java index 9908074773..80add24042 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprMissingValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprMissingValue.java @@ -3,21 +3,17 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import java.util.Objects; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; -/** - * Expression Missing Value. - */ +/** Expression Missing Value. */ public class ExprMissingValue extends AbstractExprValue { private static final ExprMissingValue instance = new ExprMissingValue(); - private ExprMissingValue() { - } + private ExprMissingValue() {} public static ExprMissingValue of() { return instance; @@ -40,13 +36,13 @@ public boolean isMissing() { @Override public int compare(ExprValue other) { - throw new IllegalStateException(String.format("[BUG] Unreachable, Comparing with MISSING is " - + "undefined")); + throw new IllegalStateException( + String.format("[BUG] Unreachable, Comparing with MISSING is " + "undefined")); } /** - * Missing value is equal to Missing value. - * Notes, this function should only used for Java Object Compare. + * Missing value is equal to Missing value. Notes, this function should only used for Java Object + * Compare. */ @Override public boolean equal(ExprValue other) { diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprNullValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprNullValue.java index 54d4811d33..ac2e185e65 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprNullValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprNullValue.java @@ -3,21 +3,17 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import java.util.Objects; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; -/** - * Expression Null Value. - */ +/** Expression Null Value. */ public class ExprNullValue extends AbstractExprValue { private static final ExprNullValue instance = new ExprNullValue(); - private ExprNullValue() { - } + private ExprNullValue() {} @Override public int hashCode() { @@ -55,8 +51,8 @@ public int compare(ExprValue other) { } /** - * NULL value is equal to NULL value. - * Notes, this function should only used for Java Object Compare. + * NULL value is equal to NULL value. Notes, this function should only used for Java Object + * Compare. */ @Override public boolean equal(ExprValue other) { diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprShortValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprShortValue.java index 3e5f6858bc..418cefa166 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprShortValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprShortValue.java @@ -3,15 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.data.type.ExprType; -/** - * Expression Short Value. - */ +/** Expression Short Value. */ public class ExprShortValue extends AbstractExprNumberValue { public ExprShortValue(Number value) { diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java index c41c23d6ac..7745af62b6 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import java.time.LocalDate; @@ -15,9 +14,7 @@ import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.exception.SemanticCheckException; -/** - * Expression String Value. - */ +/** Expression String Value. */ @RequiredArgsConstructor public class ExprStringValue extends AbstractExprValue { private final String value; @@ -44,11 +41,13 @@ public LocalDateTime datetimeValue() { } catch (SemanticCheckException e) { try { return new ExprDatetimeValue( - LocalDateTime.of(new ExprDateValue(value).dateValue(), LocalTime.of(0, 0, 0))) + LocalDateTime.of(new ExprDateValue(value).dateValue(), LocalTime.of(0, 0, 0))) .datetimeValue(); } catch (SemanticCheckException exception) { - throw new SemanticCheckException(String.format("datetime:%s in unsupported format, please " - + "use yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]", value)); + throw new SemanticCheckException( + String.format( + "datetime:%s in unsupported format, please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", + value)); } } } diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java index db5bf7cb52..c22b423c7d 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME; @@ -23,23 +22,20 @@ import org.opensearch.sql.exception.SemanticCheckException; import org.opensearch.sql.expression.function.FunctionProperties; -/** - * Expression Time Value. - */ +/** Expression Time Value. */ @RequiredArgsConstructor public class ExprTimeValue extends AbstractExprValue { private final LocalTime time; - /** - * Constructor of ExprTimeValue. - */ + /** Constructor of ExprTimeValue. */ public ExprTimeValue(String time) { try { this.time = LocalTime.parse(time, DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL); } catch (DateTimeParseException e) { - throw new SemanticCheckException(String.format("time:%s in unsupported format, please use " - + "HH:mm:ss[.SSSSSSSSS]", time)); + throw new SemanticCheckException( + String.format( + "time:%s in unsupported format, please use 'HH:mm:ss[.SSSSSSSSS]'", time)); } } @@ -67,8 +63,7 @@ public LocalDateTime datetimeValue(FunctionProperties functionProperties) { } public Instant timestampValue(FunctionProperties functionProperties) { - return ZonedDateTime.of(dateValue(functionProperties), timeValue(), UTC_ZONE_ID) - .toInstant(); + return ZonedDateTime.of(dateValue(functionProperties), timeValue(), UTC_ZONE_ID).toInstant(); } @Override diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprTimestampValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprTimestampValue.java index d15cee5e71..455a379b03 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprTimestampValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprTimestampValue.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS; @@ -22,33 +21,33 @@ import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.exception.SemanticCheckException; -/** - * Expression Timestamp Value. - */ +/** Expression Timestamp Value. */ @RequiredArgsConstructor public class ExprTimestampValue extends AbstractExprValue { private final Instant timestamp; - /** - * Constructor. - */ + /** Constructor. */ public ExprTimestampValue(String timestamp) { try { - this.timestamp = LocalDateTime.parse(timestamp, DATE_TIME_FORMATTER_VARIABLE_NANOS) - .atZone(UTC_ZONE_ID) - .toInstant(); + this.timestamp = + LocalDateTime.parse(timestamp, DATE_TIME_FORMATTER_VARIABLE_NANOS) + .atZone(UTC_ZONE_ID) + .toInstant(); } catch (DateTimeParseException e) { - throw new SemanticCheckException(String.format("timestamp:%s in unsupported format, please " - + "use yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]", timestamp)); + throw new SemanticCheckException( + String.format( + "timestamp:%s in unsupported format, please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", + timestamp)); } - } @Override public String value() { - return timestamp.getNano() == 0 ? DATE_TIME_FORMATTER_WITHOUT_NANO.withZone(UTC_ZONE_ID) - .format(timestamp.truncatedTo(ChronoUnit.SECONDS)) + return timestamp.getNano() == 0 + ? DATE_TIME_FORMATTER_WITHOUT_NANO + .withZone(UTC_ZONE_ID) + .format(timestamp.truncatedTo(ChronoUnit.SECONDS)) : DATE_TIME_FORMATTER_VARIABLE_NANOS.withZone(UTC_ZONE_ID).format(timestamp); } diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprTupleValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprTupleValue.java index 749de931ee..856075bed8 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprTupleValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprTupleValue.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import java.util.Iterator; @@ -18,9 +17,7 @@ import org.opensearch.sql.storage.bindingtuple.BindingTuple; import org.opensearch.sql.storage.bindingtuple.LazyBindingTuple; -/** - * Expression Tuple Value. - */ +/** Expression Tuple Value. */ @RequiredArgsConstructor public class ExprTupleValue extends AbstractExprValue { @@ -47,8 +44,7 @@ public ExprType type() { @Override public String toString() { - return valueMap.entrySet() - .stream() + return valueMap.entrySet().stream() .map(entry -> String.format("%s:%s", entry.getKey(), entry.getValue())) .collect(Collectors.joining(",", "{", "}")); } @@ -70,6 +66,7 @@ public ExprValue keyValue(String key) { /** * Override the equals method. + * * @return true for equal, otherwise false. */ public boolean equal(ExprValue o) { @@ -91,9 +88,7 @@ public boolean equal(ExprValue o) { } } - /** - * Only compare the size of the map. - */ + /** Only compare the size of the map. */ @Override public int compare(ExprValue other) { return Integer.compare(valueMap.size(), other.tupleValue().size()); diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprValue.java index 1ae03de37b..86bead77b7 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprValue.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import java.io.Serializable; @@ -19,18 +18,12 @@ import org.opensearch.sql.exception.ExpressionEvaluationException; import org.opensearch.sql.storage.bindingtuple.BindingTuple; -/** - * The definition of the Expression Value. - */ +/** The definition of the Expression Value. */ public interface ExprValue extends Serializable, Comparable { - /** - * Get the Object value of the Expression Value. - */ + /** Get the Object value of the Expression Value. */ Object value(); - /** - * Get the {@link ExprCoreType} of the Expression Value. - */ + /** Get the {@link ExprCoreType} of the Expression Value. */ ExprType type(); /** @@ -69,136 +62,104 @@ default boolean isDateTime() { return false; } - /** - * Get the {@link BindingTuple}. - */ + /** Get the {@link BindingTuple}. */ default BindingTuple bindingTuples() { return BindingTuple.EMPTY; } - /** - * Get byte value. - */ + /** Get byte value. */ default Byte byteValue() { throw new ExpressionEvaluationException( "invalid to get byteValue from value of type " + type()); } - /** - * Get short value. - */ + /** Get short value. */ default Short shortValue() { throw new ExpressionEvaluationException( "invalid to get shortValue from value of type " + type()); } - /** - * Get integer value. - */ + /** Get integer value. */ default Integer integerValue() { throw new ExpressionEvaluationException( "invalid to get integerValue from value of type " + type()); } - /** - * Get long value. - */ + /** Get long value. */ default Long longValue() { throw new ExpressionEvaluationException( "invalid to get longValue from value of type " + type()); } - /** - * Get float value. - */ + /** Get float value. */ default Float floatValue() { throw new ExpressionEvaluationException( "invalid to get floatValue from value of type " + type()); } - /** - * Get float value. - */ + /** Get float value. */ default Double doubleValue() { throw new ExpressionEvaluationException( "invalid to get doubleValue from value of type " + type()); } - /** - * Get string value. - */ + /** Get string value. */ default String stringValue() { throw new ExpressionEvaluationException( "invalid to get stringValue from value of type " + type()); } - /** - * Get boolean value. - */ + /** Get boolean value. */ default Boolean booleanValue() { throw new ExpressionEvaluationException( "invalid to get booleanValue from value of type " + type()); } - /** - * Get timestamp value. - */ + /** Get timestamp value. */ default Instant timestampValue() { throw new ExpressionEvaluationException( "invalid to get timestampValue from value of type " + type()); } - /** - * Get time value. - */ + /** Get time value. */ default LocalTime timeValue() { throw new ExpressionEvaluationException( "invalid to get timeValue from value of type " + type()); } - /** - * Get date value. - */ + /** Get date value. */ default LocalDate dateValue() { throw new ExpressionEvaluationException( "invalid to get dateValue from value of type " + type()); } - /** - * Get datetime value. - */ + /** Get datetime value. */ default LocalDateTime datetimeValue() { throw new ExpressionEvaluationException( "invalid to get datetimeValue from value of type " + type()); } - /** - * Get interval value. - */ + /** Get interval value. */ default TemporalAmount intervalValue() { throw new ExpressionEvaluationException( "invalid to get intervalValue from value of type " + type()); } - /** - * Get map value. - */ + /** Get map value. */ default Map tupleValue() { throw new ExpressionEvaluationException( "invalid to get tupleValue from value of type " + type()); } - /** - * Get collection value. - */ + /** Get collection value. */ default List collectionValue() { throw new ExpressionEvaluationException( "invalid to get collectionValue from value of type " + type()); } /** - * Get the value specified by key from {@link ExprTupleValue}. - * This method only be implemented in {@link ExprTupleValue}. + * Get the value specified by key from {@link ExprTupleValue}. This method only be implemented in + * {@link ExprTupleValue}. */ default ExprValue keyValue(String key) { return ExprMissingValue.of(); diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java b/core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java index 43a3140ef3..a259eb9fba 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java @@ -18,9 +18,7 @@ import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.exception.ExpressionEvaluationException; -/** - * The definition of {@link ExprValue} factory. - */ +/** The definition of {@link ExprValue} factory. */ @UtilityClass public class ExprValueUtils { public static final ExprValue LITERAL_TRUE = ExprBooleanValue.of(true); @@ -80,19 +78,15 @@ public static ExprValue timestampValue(Instant value) { return new ExprTimestampValue(value); } - /** - * {@link ExprTupleValue} constructor. - */ + /** {@link ExprTupleValue} constructor. */ public static ExprValue tupleValue(Map map) { LinkedHashMap valueMap = new LinkedHashMap<>(); - map.forEach((k, v) -> valueMap - .put(k, v instanceof ExprValue ? (ExprValue) v : fromObjectValue(v))); + map.forEach( + (k, v) -> valueMap.put(k, v instanceof ExprValue ? (ExprValue) v : fromObjectValue(v))); return new ExprTupleValue(valueMap); } - /** - * {@link ExprCollectionValue} constructor. - */ + /** {@link ExprCollectionValue} constructor. */ public static ExprValue collectionValue(List list) { List valueList = new ArrayList<>(); list.forEach(o -> valueList.add(fromObjectValue(o))); @@ -107,9 +101,7 @@ public static ExprValue nullValue() { return ExprNullValue.of(); } - /** - * Construct ExprValue from Object. - */ + /** Construct ExprValue from Object. */ public static ExprValue fromObjectValue(Object o) { if (null == o) { return LITERAL_NULL; @@ -149,19 +141,17 @@ public static ExprValue fromObjectValue(Object o) { } } - /** - * Construct ExprValue from Object with ExprCoreType. - */ + /** Construct ExprValue from Object with ExprCoreType. */ public static ExprValue fromObjectValue(Object o, ExprCoreType type) { switch (type) { case TIMESTAMP: - return new ExprTimestampValue((String)o); + return new ExprTimestampValue((String) o); case DATE: - return new ExprDateValue((String)o); + return new ExprDateValue((String) o); case TIME: - return new ExprTimeValue((String)o); + return new ExprTimeValue((String) o); case DATETIME: - return new ExprDatetimeValue((String)o); + return new ExprDatetimeValue((String) o); default: return fromObjectValue(o); } diff --git a/core/src/main/java/org/opensearch/sql/data/type/ExprCoreType.java b/core/src/main/java/org/opensearch/sql/data/type/ExprCoreType.java index 815f94a9df..f1979d8666 100644 --- a/core/src/main/java/org/opensearch/sql/data/type/ExprCoreType.java +++ b/core/src/main/java/org/opensearch/sql/data/type/ExprCoreType.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.type; import com.google.common.collect.ImmutableMap; @@ -15,25 +14,18 @@ import java.util.Set; import java.util.stream.Collectors; -/** - * Expression Type. - */ +/** Expression Type. */ public enum ExprCoreType implements ExprType { - /** - * Unknown due to unsupported data type. - */ + /** Unknown due to unsupported data type. */ UNKNOWN, /** - * Undefined type for special literal such as NULL. - * As the root of data type tree, it is compatible with any other type. - * In other word, undefined type is the "narrowest" type. + * Undefined type for special literal such as NULL. As the root of data type tree, it is + * compatible with any other type. In other word, undefined type is the "narrowest" type. */ UNDEFINED, - /** - * Numbers. - */ + /** Numbers. */ BYTE(UNDEFINED), SHORT(BYTE), INTEGER(SHORT), @@ -41,43 +33,29 @@ public enum ExprCoreType implements ExprType { FLOAT(LONG), DOUBLE(FLOAT), - /** - * String. - */ + /** String. */ STRING(UNDEFINED), - /** - * Boolean. - */ + /** Boolean. */ BOOLEAN(STRING), - /** - * Date. - */ + /** Date. */ DATE(STRING), TIME(STRING), DATETIME(STRING, DATE, TIME), TIMESTAMP(STRING, DATETIME), INTERVAL(UNDEFINED), - /** - * Struct. - */ + /** Struct. */ STRUCT(UNDEFINED), - /** - * Array. - */ + /** Array. */ ARRAY(UNDEFINED); - /** - * Parents (wider/compatible types) of current base type. - */ + /** Parents (wider/compatible types) of current base type. */ private final List parents = new ArrayList<>(); - /** - * The mapping between Type and legacy JDBC type name. - */ + /** The mapping between Type and legacy JDBC type name. */ private static final Map LEGACY_TYPE_NAME_MAPPING = new ImmutableMap.Builder() .put(STRUCT, "OBJECT") @@ -116,14 +94,12 @@ public String legacyTypeName() { return LEGACY_TYPE_NAME_MAPPING.getOrDefault(this, this.name()); } - /** - * Return all the valid ExprCoreType. - */ + /** Return all the valid ExprCoreType. */ public static List coreTypes() { return Arrays.stream(ExprCoreType.values()) - .filter(type -> type != UNKNOWN) - .filter(type -> type != UNDEFINED) - .collect(Collectors.toList()); + .filter(type -> type != UNKNOWN) + .filter(type -> type != UNDEFINED) + .collect(Collectors.toList()); } public static Set numberTypes() { diff --git a/core/src/main/java/org/opensearch/sql/data/type/ExprType.java b/core/src/main/java/org/opensearch/sql/data/type/ExprType.java index 782714ba70..58d6ee346b 100644 --- a/core/src/main/java/org/opensearch/sql/data/type/ExprType.java +++ b/core/src/main/java/org/opensearch/sql/data/type/ExprType.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.type; import static org.opensearch.sql.data.type.ExprCoreType.UNKNOWN; @@ -13,13 +12,9 @@ import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.expression.Expression; -/** - * The Type of {@link Expression} and {@link ExprValue}. - */ +/** The Type of {@link Expression} and {@link ExprValue}. */ public interface ExprType { - /** - * Is compatible with other types. - */ + /** Is compatible with other types. */ default boolean isCompatible(ExprType other) { if (this.equals(other)) { return true; @@ -37,30 +32,25 @@ default boolean isCompatible(ExprType other) { } /** - * Should cast this type to other type or not. By default, cast is always required - * if the given type is different from this type. + * Should cast this type to other type or not. By default, cast is always required if the given + * type is different from this type. + * * @param other other data type - * @return true if cast is required, otherwise false + * @return true if cast is required, otherwise false */ default boolean shouldCast(ExprType other) { return !this.equals(other); } - /** - * Get the parent type. - */ + /** Get the parent type. */ default List getParent() { return Arrays.asList(UNKNOWN); } - /** - * Get the type name. - */ + /** Get the type name. */ String typeName(); - /** - * Get the legacy type name for old engine. - */ + /** Get the legacy type name for old engine. */ default String legacyTypeName() { return typeName(); } diff --git a/core/src/main/java/org/opensearch/sql/data/type/WideningTypeRule.java b/core/src/main/java/org/opensearch/sql/data/type/WideningTypeRule.java index e1f356782f..c9b5c29157 100644 --- a/core/src/main/java/org/opensearch/sql/data/type/WideningTypeRule.java +++ b/core/src/main/java/org/opensearch/sql/data/type/WideningTypeRule.java @@ -13,15 +13,17 @@ /** * The definition of widening type rule for expression value. - * ExprType Widens to data types - * INTEGER LONG, FLOAT, DOUBLE - * LONG FLOAT, DOUBLE - * FLOAT DOUBLE - * DOUBLE DOUBLE - * STRING STRING - * BOOLEAN BOOLEAN - * ARRAY ARRAY - * STRUCT STRUCT + * + * + * + * + * + * + * + * + * + * + *
ExprTypeWidens to data types
INTEGERLONG, FLOAT, DOUBLE
LONGFLOAT, DOUBLE
FLOATDOUBLE
DOUBLEDOUBLE
STRINGSTRING
BOOLEANBOOLEAN
ARRAYARRAY
STRUCTSTRUCT
*/ @UtilityClass public class WideningTypeRule { @@ -53,10 +55,9 @@ private static int distance(ExprType type1, ExprType type2, int distance) { } /** - * The max type among two types. The max is defined as follow - * if type1 could widen to type2, then max is type2, vice versa - * if type1 could't widen to type2 and type2 could't widen to type1, - * then throw {@link ExpressionEvaluationException}. + * The max type among two types. The max is defined as follow if type1 could widen to type2, then + * max is type2, vice versa if type1 couldn't widen to type2 and type2 could't widen to type1, then + * throw {@link ExpressionEvaluationException}. * * @param type1 type1 * @param type2 type2 diff --git a/core/src/main/java/org/opensearch/sql/data/utils/ExprValueOrdering.java b/core/src/main/java/org/opensearch/sql/data/utils/ExprValueOrdering.java index ef390dc53b..812c8dba3d 100644 --- a/core/src/main/java/org/opensearch/sql/data/utils/ExprValueOrdering.java +++ b/core/src/main/java/org/opensearch/sql/data/utils/ExprValueOrdering.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.utils; import com.google.common.collect.Ordering; diff --git a/core/src/main/java/org/opensearch/sql/data/utils/NaturalExprValueOrdering.java b/core/src/main/java/org/opensearch/sql/data/utils/NaturalExprValueOrdering.java index 13c3606f72..f3285fd6f9 100644 --- a/core/src/main/java/org/opensearch/sql/data/utils/NaturalExprValueOrdering.java +++ b/core/src/main/java/org/opensearch/sql/data/utils/NaturalExprValueOrdering.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.utils; import com.google.common.collect.Ordering; diff --git a/core/src/main/java/org/opensearch/sql/data/utils/NullsFirstExprValueOrdering.java b/core/src/main/java/org/opensearch/sql/data/utils/NullsFirstExprValueOrdering.java index 03890bba61..82fac55e0c 100644 --- a/core/src/main/java/org/opensearch/sql/data/utils/NullsFirstExprValueOrdering.java +++ b/core/src/main/java/org/opensearch/sql/data/utils/NullsFirstExprValueOrdering.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.utils; import com.google.common.collect.Ordering; diff --git a/core/src/main/java/org/opensearch/sql/data/utils/NullsLastExprValueOrdering.java b/core/src/main/java/org/opensearch/sql/data/utils/NullsLastExprValueOrdering.java index 589d4b3043..0221e50887 100644 --- a/core/src/main/java/org/opensearch/sql/data/utils/NullsLastExprValueOrdering.java +++ b/core/src/main/java/org/opensearch/sql/data/utils/NullsLastExprValueOrdering.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.utils; import com.google.common.collect.Ordering; diff --git a/core/src/main/java/org/opensearch/sql/data/utils/ReverseExprValueOrdering.java b/core/src/main/java/org/opensearch/sql/data/utils/ReverseExprValueOrdering.java index 65fceacf99..ca3cb251f4 100644 --- a/core/src/main/java/org/opensearch/sql/data/utils/ReverseExprValueOrdering.java +++ b/core/src/main/java/org/opensearch/sql/data/utils/ReverseExprValueOrdering.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.utils; import com.google.common.collect.Ordering; diff --git a/core/src/main/java/org/opensearch/sql/datasource/DataSourceService.java b/core/src/main/java/org/opensearch/sql/datasource/DataSourceService.java index 9167737a70..3d6ddc864e 100644 --- a/core/src/main/java/org/opensearch/sql/datasource/DataSourceService.java +++ b/core/src/main/java/org/opensearch/sql/datasource/DataSourceService.java @@ -9,9 +9,7 @@ import org.opensearch.sql.datasource.model.DataSource; import org.opensearch.sql.datasource.model.DataSourceMetadata; -/** - * DataSource Service manage {@link DataSource}. - */ +/** DataSource Service manage {@link DataSource}. */ public interface DataSourceService { /** @@ -22,21 +20,19 @@ public interface DataSourceService { */ DataSource getDataSource(String dataSourceName); - /** - * Returns all dataSource Metadata objects. The returned objects won't contain - * any of the credential info. + * Returns all dataSource Metadata objects. The returned objects won't contain any of the + * credential info. * - * @param isDefaultDataSourceRequired is used to specify - * if default opensearch connector is required in the output list. + * @param isDefaultDataSourceRequired is used to specify if default opensearch connector is + * required in the output list. * @return set of {@link DataSourceMetadata}. */ Set getDataSourceMetadata(boolean isDefaultDataSourceRequired); - /** - * Returns dataSourceMetadata object with specific name. - * The returned objects won't contain any crendetial info. + * Returns dataSourceMetadata object with specific name. The returned objects won't contain any + * crendetial info. * * @param name name of the {@link DataSource}. * @return set of {@link DataSourceMetadata}. @@ -57,7 +53,6 @@ public interface DataSourceService { */ void updateDataSource(DataSourceMetadata dataSourceMetadata); - /** * Deletes {@link DataSource} corresponding to the DataSource name. * @@ -66,8 +61,8 @@ public interface DataSourceService { void deleteDataSource(String dataSourceName); /** - * Returns true {@link Boolean} if datasource with dataSourceName exists - * or else false {@link Boolean}. + * Returns true {@link Boolean} if datasource with dataSourceName exists or else false {@link + * Boolean}. * * @param dataSourceName name of the {@link DataSource}. */ diff --git a/core/src/main/java/org/opensearch/sql/datasource/model/DataSource.java b/core/src/main/java/org/opensearch/sql/datasource/model/DataSource.java index 5deb460961..9623102efb 100644 --- a/core/src/main/java/org/opensearch/sql/datasource/model/DataSource.java +++ b/core/src/main/java/org/opensearch/sql/datasource/model/DataSource.java @@ -12,9 +12,7 @@ import lombok.RequiredArgsConstructor; import org.opensearch.sql.storage.StorageEngine; -/** - * Each user configured datasource mapping to one instance of DataSource per JVM. - */ +/** Each user configured datasource mapping to one instance of DataSource per JVM. */ @Getter @RequiredArgsConstructor @EqualsAndHashCode @@ -24,7 +22,5 @@ public class DataSource { private final DataSourceType connectorType; - @EqualsAndHashCode.Exclude - private final StorageEngine storageEngine; - + @EqualsAndHashCode.Exclude private final StorageEngine storageEngine; } diff --git a/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceMetadata.java b/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceMetadata.java index 7945f8aec3..8e5ff7e1a6 100644 --- a/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceMetadata.java +++ b/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceMetadata.java @@ -5,7 +5,6 @@ package org.opensearch.sql.datasource.model; - import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; import com.fasterxml.jackson.annotation.JsonFormat; @@ -30,25 +29,25 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class DataSourceMetadata { - @JsonProperty - private String name; + @JsonProperty private String name; @JsonProperty @JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES) private DataSourceType connector; - @JsonProperty - private List allowedRoles; + @JsonProperty private List allowedRoles; - @JsonProperty - private Map properties; + @JsonProperty private Map properties; /** * Default OpenSearch {@link DataSourceMetadata}. Which is used to register default OpenSearch * {@link DataSource} to {@link DataSourceService}. */ public static DataSourceMetadata defaultOpenSearchDataSourceMetadata() { - return new DataSourceMetadata(DEFAULT_DATASOURCE_NAME, - DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of()); + return new DataSourceMetadata( + DEFAULT_DATASOURCE_NAME, + DataSourceType.OPENSEARCH, + Collections.emptyList(), + ImmutableMap.of()); } } diff --git a/core/src/test/java/org/opensearch/sql/ast/expression/CastTest.java b/core/src/test/java/org/opensearch/sql/ast/expression/CastTest.java index d9386ab122..741db07eb3 100644 --- a/core/src/test/java/org/opensearch/sql/ast/expression/CastTest.java +++ b/core/src/test/java/org/opensearch/sql/ast/expression/CastTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -23,5 +22,4 @@ void cast_to_int_and_integer_should_convert_to_same_function_impl() { new Cast(booleanLiteral(true), stringLiteral("INT")).convertFunctionName(), new Cast(booleanLiteral(true), stringLiteral("INTEGER")).convertFunctionName()); } - } diff --git a/core/src/test/java/org/opensearch/sql/ast/expression/QualifiedNameTest.java b/core/src/test/java/org/opensearch/sql/ast/expression/QualifiedNameTest.java index b0ab66bc0e..c211f36ba7 100644 --- a/core/src/test/java/org/opensearch/sql/ast/expression/QualifiedNameTest.java +++ b/core/src/test/java/org/opensearch/sql/ast/expression/QualifiedNameTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.ast.expression; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -36,5 +35,4 @@ void should_return_empty_if_only_single_part() { assertFalse(name.first().isPresent()); assertFalse(name.getPrefix().isPresent()); } - } diff --git a/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java b/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java index c78545f9ae..01fe4a5e4e 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -47,13 +46,14 @@ public void timeValueInterfaceTest() { assertEquals(today, timeValue.dateValue(functionProperties)); assertEquals(today.atTime(1, 1, 1), timeValue.datetimeValue(functionProperties)); - assertEquals(ZonedDateTime.of(LocalTime.parse("01:01:01").atDate(today), - UTC_ZONE_ID).toInstant(), timeValue.timestampValue(functionProperties)); + assertEquals( + ZonedDateTime.of(LocalTime.parse("01:01:01").atDate(today), UTC_ZONE_ID).toInstant(), + timeValue.timestampValue(functionProperties)); assertEquals("01:01:01", timeValue.value()); assertEquals("TIME '01:01:01'", timeValue.toString()); - exception = assertThrows(ExpressionEvaluationException.class, - () -> integerValue(1).timeValue()); + exception = + assertThrows(ExpressionEvaluationException.class, () -> integerValue(1).timeValue()); assertEquals("invalid to get timeValue from value of type INTEGER", exception.getMessage()); } @@ -62,14 +62,17 @@ public void timestampValueInterfaceTest() { ExprValue timestampValue = new ExprTimestampValue("2020-07-07 01:01:01"); assertEquals(TIMESTAMP, timestampValue.type()); - assertEquals(ZonedDateTime.of(LocalDateTime.parse("2020-07-07T01:01:01"), - UTC_ZONE_ID).toInstant(), timestampValue.timestampValue()); + assertEquals( + ZonedDateTime.of(LocalDateTime.parse("2020-07-07T01:01:01"), UTC_ZONE_ID).toInstant(), + timestampValue.timestampValue()); assertEquals("2020-07-07 01:01:01", timestampValue.value()); assertEquals("TIMESTAMP '2020-07-07 01:01:01'", timestampValue.toString()); assertEquals(LocalDate.parse("2020-07-07"), timestampValue.dateValue()); assertEquals(LocalTime.parse("01:01:01"), timestampValue.timeValue()); assertEquals(LocalDateTime.parse("2020-07-07T01:01:01"), timestampValue.datetimeValue()); - assertThrows(ExpressionEvaluationException.class, () -> integerValue(1).timestampValue(), + assertThrows( + ExpressionEvaluationException.class, + () -> integerValue(1).timestampValue(), "invalid to get timestampValue from value of type INTEGER"); } @@ -80,12 +83,12 @@ public void dateValueInterfaceTest() { assertEquals(LocalDate.parse("2012-07-07"), dateValue.dateValue()); assertEquals(LocalTime.parse("00:00:00"), dateValue.timeValue()); assertEquals(LocalDateTime.parse("2012-07-07T00:00:00"), dateValue.datetimeValue()); - assertEquals(ZonedDateTime.of(LocalDateTime.parse("2012-07-07T00:00:00"), - UTC_ZONE_ID).toInstant(), dateValue.timestampValue()); + assertEquals( + ZonedDateTime.of(LocalDateTime.parse("2012-07-07T00:00:00"), UTC_ZONE_ID).toInstant(), + dateValue.timestampValue()); ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, () -> integerValue(1).dateValue()); - assertEquals("invalid to get dateValue from value of type INTEGER", - exception.getMessage()); + assertEquals("invalid to get dateValue from value of type INTEGER", exception.getMessage()); } @Test @@ -95,10 +98,13 @@ public void datetimeValueInterfaceTest() { assertEquals(LocalDateTime.parse("2020-08-17T19:44:00"), datetimeValue.datetimeValue()); assertEquals(LocalDate.parse("2020-08-17"), datetimeValue.dateValue()); assertEquals(LocalTime.parse("19:44:00"), datetimeValue.timeValue()); - assertEquals(ZonedDateTime.of(LocalDateTime.parse("2020-08-17T19:44:00"), - UTC_ZONE_ID).toInstant(), datetimeValue.timestampValue()); + assertEquals( + ZonedDateTime.of(LocalDateTime.parse("2020-08-17T19:44:00"), UTC_ZONE_ID).toInstant(), + datetimeValue.timestampValue()); assertEquals("DATETIME '2020-08-17 19:44:00'", datetimeValue.toString()); - assertThrows(ExpressionEvaluationException.class, () -> integerValue(1).datetimeValue(), + assertThrows( + ExpressionEvaluationException.class, + () -> integerValue(1).datetimeValue(), "invalid to get datetimeValue from value of type INTEGER"); } @@ -106,37 +112,38 @@ public void datetimeValueInterfaceTest() { public void dateInUnsupportedFormat() { SemanticCheckException exception = assertThrows(SemanticCheckException.class, () -> new ExprDateValue("2020-07-07Z")); - assertEquals("date:2020-07-07Z in unsupported format, please use yyyy-MM-dd", - exception.getMessage()); + assertEquals( + "date:2020-07-07Z in unsupported format, please use 'yyyy-MM-dd'", exception.getMessage()); } @Test public void timeInUnsupportedFormat() { SemanticCheckException exception = assertThrows(SemanticCheckException.class, () -> new ExprTimeValue("01:01:0")); - assertEquals("time:01:01:0 in unsupported format, please use HH:mm:ss[.SSSSSSSSS]", + assertEquals( + "time:01:01:0 in unsupported format, please use 'HH:mm:ss[.SSSSSSSSS]'", exception.getMessage()); } @Test public void timestampInUnsupportedFormat() { SemanticCheckException exception = - assertThrows(SemanticCheckException.class, - () -> new ExprTimestampValue("2020-07-07T01:01:01Z")); + assertThrows( + SemanticCheckException.class, () -> new ExprTimestampValue("2020-07-07T01:01:01Z")); assertEquals( "timestamp:2020-07-07T01:01:01Z in unsupported format, " - + "please use yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]", + + "please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", exception.getMessage()); } @Test public void datetimeInUnsupportedFormat() { SemanticCheckException exception = - assertThrows(SemanticCheckException.class, - () -> new ExprDatetimeValue("2020-07-07T01:01:01Z")); + assertThrows( + SemanticCheckException.class, () -> new ExprDatetimeValue("2020-07-07T01:01:01Z")); assertEquals( "datetime:2020-07-07T01:01:01Z in unsupported format, " - + "please use yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]", + + "please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", exception.getMessage()); } @@ -150,11 +157,12 @@ public void stringDateTimeValue() { assertEquals("\"2020-08-17 19:44:00\"", stringValue.toString()); SemanticCheckException exception = - assertThrows(SemanticCheckException.class, + assertThrows( + SemanticCheckException.class, () -> new ExprStringValue("2020-07-07T01:01:01Z").datetimeValue()); assertEquals( "datetime:2020-07-07T01:01:01Z in unsupported format, " - + "please use yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]", + + "please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", exception.getMessage()); } @@ -167,10 +175,10 @@ public void stringDateValue() { assertEquals("\"2020-08-17\"", stringValue.toString()); SemanticCheckException exception = - assertThrows(SemanticCheckException.class, - () -> new ExprStringValue("2020-07-07Z").dateValue()); - assertEquals("date:2020-07-07Z in unsupported format, please use yyyy-MM-dd", - exception.getMessage()); + assertThrows( + SemanticCheckException.class, () -> new ExprStringValue("2020-07-07Z").dateValue()); + assertEquals( + "date:2020-07-07Z in unsupported format, please use 'yyyy-MM-dd'", exception.getMessage()); } @Test @@ -181,9 +189,10 @@ public void stringTimeValue() { assertEquals("\"19:44:00\"", stringValue.toString()); SemanticCheckException exception = - assertThrows(SemanticCheckException.class, - () -> new ExprStringValue("01:01:0").timeValue()); - assertEquals("time:01:01:0 in unsupported format, please use HH:mm:ss[.SSSSSSSSS]", + assertThrows( + SemanticCheckException.class, () -> new ExprStringValue("01:01:0").timeValue()); + assertEquals( + "time:01:01:0 in unsupported format, please use 'HH:mm:ss[.SSSSSSSSS]'", exception.getMessage()); } @@ -247,32 +256,33 @@ public void datetimeWithVariableNanoPrecision() { @Test public void timestampOverMaxNanoPrecision() { SemanticCheckException exception = - assertThrows(SemanticCheckException.class, + assertThrows( + SemanticCheckException.class, () -> new ExprTimestampValue("2020-07-07 01:01:01.1234567890")); assertEquals( - "timestamp:2020-07-07 01:01:01.1234567890 in unsupported format, " - + "please use yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]", + "timestamp:2020-07-07 01:01:01.1234567890 in unsupported format, please use " + + "'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", exception.getMessage()); } @Test public void datetimeOverMaxNanoPrecision() { SemanticCheckException exception = - assertThrows(SemanticCheckException.class, + assertThrows( + SemanticCheckException.class, () -> new ExprDatetimeValue("2020-07-07 01:01:01.1234567890")); assertEquals( "datetime:2020-07-07 01:01:01.1234567890 in unsupported format, " - + "please use yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]", + + "please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", exception.getMessage()); } @Test public void timeOverMaxNanoPrecision() { SemanticCheckException exception = - assertThrows(SemanticCheckException.class, - () -> new ExprTimeValue("01:01:01.1234567890")); + assertThrows(SemanticCheckException.class, () -> new ExprTimeValue("01:01:01.1234567890")); assertEquals( - "time:01:01:01.1234567890 in unsupported format, please use HH:mm:ss[.SSSSSSSSS]", + "time:01:01:01.1234567890 in unsupported format, please use 'HH:mm:ss[.SSSSSSSSS]'", exception.getMessage()); } } diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprBooleanValueTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprBooleanValueTest.java index 07aac33129..b77112528c 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/ExprBooleanValueTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/ExprBooleanValueTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -29,8 +28,8 @@ public void equal() { ExprValue v2 = ExprBooleanValue.of(true); assertTrue(v1.equals(v2)); assertTrue(v2.equals(v1)); - assertEquals(0, ((ExprBooleanValue)v1).compare((ExprBooleanValue)v2)); - assertEquals(0, ((ExprBooleanValue)v2).compare((ExprBooleanValue)v1)); + assertEquals(0, ((ExprBooleanValue) v1).compare((ExprBooleanValue) v2)); + assertEquals(0, ((ExprBooleanValue) v2).compare((ExprBooleanValue) v1)); } @Test @@ -44,7 +43,9 @@ public void compare() { @Test public void invalid_get_value() { ExprDateValue value = new ExprDateValue("2020-08-20"); - assertThrows(ExpressionEvaluationException.class, value::booleanValue, + assertThrows( + ExpressionEvaluationException.class, + value::booleanValue, String.format("invalid to get booleanValue from value of type %s", value.type())); } diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprCollectionValueTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprCollectionValueTest.java index e61bdb111d..edd4e0d844 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/ExprCollectionValueTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/ExprCollectionValueTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -48,8 +47,9 @@ public void compare_collection_with_int_object() { @Test public void comparabilityTest() { ExprValue collectionValue = ExprValueUtils.collectionValue(Arrays.asList(0, 1)); - ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, - () -> compare(collectionValue, collectionValue)); + ExpressionEvaluationException exception = + assertThrows( + ExpressionEvaluationException.class, () -> compare(collectionValue, collectionValue)); assertEquals("ExprCollectionValue instances are not comparable", exception.getMessage()); } } diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprIntervalValueTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprIntervalValueTest.java index ff86ad70a1..36785d383e 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/ExprIntervalValueTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/ExprIntervalValueTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -41,14 +40,18 @@ public void compare() { public void invalid_compare() { ExprIntervalValue v1 = new ExprIntervalValue(Period.ofYears(1)); ExprIntervalValue v2 = new ExprIntervalValue(Duration.ofHours(1)); - assertThrows(ExpressionEvaluationException.class, () -> v1.compare(v2), + assertThrows( + ExpressionEvaluationException.class, + () -> v1.compare(v2), String.format("invalid to compare intervals with units %s and %s", v1.unit(), v2.unit())); } @Test public void invalid_get_value() { ExprDateValue value = new ExprDateValue("2020-08-20"); - assertThrows(ExpressionEvaluationException.class, value::intervalValue, + assertThrows( + ExpressionEvaluationException.class, + value::intervalValue, String.format("invalid to get intervalValue from value of type %s", value.type())); } diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprMissingValueTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprMissingValueTest.java index 871f312c6f..121ceb6ce2 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/ExprMissingValueTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/ExprMissingValueTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -19,7 +18,6 @@ import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.exception.ExpressionEvaluationException; - class ExprMissingValueTest { @Test @@ -51,8 +49,9 @@ public void equal() { @Test public void comparabilityTest() { - ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, - () -> compare(LITERAL_MISSING, LITERAL_MISSING)); + ExpressionEvaluationException exception = + assertThrows( + ExpressionEvaluationException.class, () -> compare(LITERAL_MISSING, LITERAL_MISSING)); assertEquals("invalid to call compare operation on missing value", exception.getMessage()); } } diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprNullValueTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprNullValueTest.java index f7087a949d..81bcf8f7b3 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/ExprNullValueTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/ExprNullValueTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -50,8 +49,9 @@ public void equal() { @Test public void comparabilityTest() { - ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, - () -> compare(LITERAL_NULL, LITERAL_NULL)); + ExpressionEvaluationException exception = + assertThrows( + ExpressionEvaluationException.class, () -> compare(LITERAL_NULL, LITERAL_NULL)); assertEquals("invalid to call compare operation on null value", exception.getMessage()); } } diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprNumberValueTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprNumberValueTest.java index 8c3f9dc742..ee245d73b4 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/ExprNumberValueTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/ExprNumberValueTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -17,8 +16,9 @@ public class ExprNumberValueTest { @Test public void getShortValueFromIncompatibleExprValue() { ExprBooleanValue booleanValue = ExprBooleanValue.of(true); - ExpressionEvaluationException exception = Assertions - .assertThrows(ExpressionEvaluationException.class, () -> booleanValue.shortValue()); + ExpressionEvaluationException exception = + Assertions.assertThrows( + ExpressionEvaluationException.class, () -> booleanValue.shortValue()); assertEquals("invalid to get shortValue from value of type BOOLEAN", exception.getMessage()); } diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprStringValueTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprStringValueTest.java index abbb730a0c..2a5e5033f7 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/ExprStringValueTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/ExprStringValueTest.java @@ -27,8 +27,8 @@ public void equal() { ExprValue v2 = ExprValueUtils.stringValue("str"); assertTrue(v1.equals(v2)); assertTrue(v2.equals(v1)); - assertEquals(0, ((ExprStringValue)v1).compare((ExprStringValue)v2)); - assertEquals(0, ((ExprStringValue)v2).compare((ExprStringValue)v1)); + assertEquals(0, ((ExprStringValue) v1).compare((ExprStringValue) v2)); + assertEquals(0, ((ExprStringValue) v2).compare((ExprStringValue) v1)); } @Test @@ -42,7 +42,9 @@ public void compare() { @Test public void invalid_get_value() { ExprDateValue value = new ExprDateValue("2020-08-20"); - assertThrows(ExpressionEvaluationException.class, value::stringValue, + assertThrows( + ExpressionEvaluationException.class, + value::stringValue, String.format("invalid to get intervalValue from value of type %s", value.type())); } diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprTupleValueTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprTupleValueTest.java index f2568e5cb4..567e1e78db 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/ExprTupleValueTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/ExprTupleValueTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -52,8 +51,8 @@ public void compare_tuple_with_different_size() { @Test public void comparabilityTest() { ExprValue tupleValue = ExprValueUtils.tupleValue(ImmutableMap.of("integer_value", 2)); - ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, - () -> compare(tupleValue, tupleValue)); + ExpressionEvaluationException exception = + assertThrows(ExpressionEvaluationException.class, () -> compare(tupleValue, tupleValue)); assertEquals("ExprTupleValue instances are not comparable", exception.getMessage()); } } diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprValueCompareTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprValueCompareTest.java index 3ece5e9a96..b965dff643 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/ExprValueCompareTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/ExprValueCompareTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -42,136 +41,148 @@ public void dateValueCompare() { @Test public void datetimeValueCompare() { - assertEquals(0, + assertEquals( + 0, new ExprDatetimeValue("2012-08-07 18:00:00") .compareTo(new ExprDatetimeValue("2012-08-07 18:00:00"))); - assertEquals(1, + assertEquals( + 1, new ExprDatetimeValue("2012-08-07 19:00:00") .compareTo(new ExprDatetimeValue("2012-08-07 18:00:00"))); - assertEquals(-1, + assertEquals( + -1, new ExprDatetimeValue("2012-08-07 18:00:00") .compareTo(new ExprDatetimeValue("2012-08-07 19:00:00"))); } @Test public void timestampValueCompare() { - assertEquals(0, + assertEquals( + 0, new ExprTimestampValue("2012-08-07 18:00:00") .compareTo(new ExprTimestampValue("2012-08-07 18:00:00"))); - assertEquals(1, + assertEquals( + 1, new ExprTimestampValue("2012-08-07 19:00:00") .compareTo(new ExprTimestampValue("2012-08-07 18:00:00"))); - assertEquals(-1, + assertEquals( + -1, new ExprTimestampValue("2012-08-07 18:00:00") .compareTo(new ExprTimestampValue("2012-08-07 19:00:00"))); } private static Stream getEqualDatetimeValuesOfDifferentTypes() { return Stream.of( - Arguments.of(new ExprTimestampValue("1961-04-12 09:07:00"), - new ExprDatetimeValue("1961-04-12 09:07:00")), - Arguments.of(new ExprTimestampValue("1984-11-22 00:00:00"), - new ExprDateValue("1984-11-22")), - Arguments.of(new ExprTimestampValue(LocalDate.now() + " 00:00:00"), - new ExprDateValue(LocalDate.now())), - Arguments.of(new ExprDatetimeValue(LocalDate.now() + " 17:42:15"), - new ExprTimeValue("17:42:15")), - Arguments.of(new ExprDatetimeValue("2012-08-07 19:14:38"), - new ExprTimestampValue("2012-08-07 19:14:38")), - Arguments.of(new ExprDateValue("2012-08-07"), - new ExprDatetimeValue("2012-08-07 00:00:00")), - Arguments.of(new ExprDateValue("2007-01-27"), - new ExprDatetimeValue("2007-01-27 00:00:00")), - Arguments.of(new ExprDateValue(LocalDate.now()), - new ExprTimeValue("00:00:00")), - Arguments.of(new ExprTimestampValue("1984-11-22 00:00:00"), - new ExprDateValue("1984-11-22")), - Arguments.of(new ExprTimeValue("19:14:38"), - new ExprDatetimeValue(LocalDate.now() + " 19:14:38")), - Arguments.of(new ExprTimeValue("17:42:15"), - new ExprTimestampValue(LocalDate.now() + " 17:42:15")) - ); + Arguments.of( + new ExprTimestampValue("1961-04-12 09:07:00"), + new ExprDatetimeValue("1961-04-12 09:07:00")), + Arguments.of( + new ExprTimestampValue("1984-11-22 00:00:00"), new ExprDateValue("1984-11-22")), + Arguments.of( + new ExprTimestampValue(LocalDate.now() + " 00:00:00"), + new ExprDateValue(LocalDate.now())), + Arguments.of( + new ExprDatetimeValue(LocalDate.now() + " 17:42:15"), new ExprTimeValue("17:42:15")), + Arguments.of( + new ExprDatetimeValue("2012-08-07 19:14:38"), + new ExprTimestampValue("2012-08-07 19:14:38")), + Arguments.of(new ExprDateValue("2012-08-07"), new ExprDatetimeValue("2012-08-07 00:00:00")), + Arguments.of(new ExprDateValue("2007-01-27"), new ExprDatetimeValue("2007-01-27 00:00:00")), + Arguments.of(new ExprDateValue(LocalDate.now()), new ExprTimeValue("00:00:00")), + Arguments.of( + new ExprTimestampValue("1984-11-22 00:00:00"), new ExprDateValue("1984-11-22")), + Arguments.of( + new ExprTimeValue("19:14:38"), new ExprDatetimeValue(LocalDate.now() + " 19:14:38")), + Arguments.of( + new ExprTimeValue("17:42:15"), new ExprTimestampValue(LocalDate.now() + " 17:42:15"))); } /** - * We can't compare directly ExprValues of different datetime types, we need to use - * `FunctionProperties` object to extract comparable values. + * We can't compare directly ExprValues of different datetime types, we need to use + * `FunctionProperties` object to extract comparable values. */ @ParameterizedTest @MethodSource("getEqualDatetimeValuesOfDifferentTypes") public void compareEqDifferentDateTimeValueTypes(ExprValue left, ExprValue right) { - assertEquals(0, extractDateTime(left, functionProperties) - .compareTo(extractDateTime(right, functionProperties))); - assertEquals(0, extractDateTime(right, functionProperties) - .compareTo(extractDateTime(left, functionProperties))); + assertEquals( + 0, + extractDateTime(left, functionProperties) + .compareTo(extractDateTime(right, functionProperties))); + assertEquals( + 0, + extractDateTime(right, functionProperties) + .compareTo(extractDateTime(left, functionProperties))); } private static Stream getNotEqualDatetimeValuesOfDifferentTypes() { return Stream.of( - Arguments.of(new ExprDatetimeValue("2012-08-07 19:14:38"), + Arguments.of( + new ExprDatetimeValue("2012-08-07 19:14:38"), new ExprTimestampValue("1961-04-12 09:07:00")), - Arguments.of(new ExprDatetimeValue("2012-08-07 19:14:38"), - new ExprTimeValue("09:07:00")), - Arguments.of(new ExprDatetimeValue(LocalDate.now() + " 19:14:38"), - new ExprTimeValue("09:07:00")), - Arguments.of(new ExprDatetimeValue("2012-08-07 00:00:00"), - new ExprDateValue("1961-04-12")), - Arguments.of(new ExprDatetimeValue("1961-04-12 19:14:38"), - new ExprDateValue("1961-04-12")), - Arguments.of(new ExprDateValue("1984-11-22"), - new ExprDatetimeValue("1961-04-12 19:14:38")), - Arguments.of(new ExprDateValue("1984-11-22"), - new ExprTimestampValue("2020-09-16 17:30:00")), - Arguments.of(new ExprDateValue("1984-11-22"), - new ExprTimeValue("19:14:38")), - Arguments.of(new ExprTimeValue("19:14:38"), - new ExprDateValue(LocalDate.now())), - Arguments.of(new ExprTimeValue("19:14:38"), - new ExprDatetimeValue("2012-08-07 09:07:00")), - Arguments.of(new ExprTimeValue("19:14:38"), - new ExprTimestampValue("1984-02-03 04:05:07")), - Arguments.of(new ExprTimestampValue("2012-08-07 19:14:38"), + Arguments.of(new ExprDatetimeValue("2012-08-07 19:14:38"), new ExprTimeValue("09:07:00")), + Arguments.of( + new ExprDatetimeValue(LocalDate.now() + " 19:14:38"), new ExprTimeValue("09:07:00")), + Arguments.of(new ExprDatetimeValue("2012-08-07 00:00:00"), new ExprDateValue("1961-04-12")), + Arguments.of(new ExprDatetimeValue("1961-04-12 19:14:38"), new ExprDateValue("1961-04-12")), + Arguments.of(new ExprDateValue("1984-11-22"), new ExprDatetimeValue("1961-04-12 19:14:38")), + Arguments.of( + new ExprDateValue("1984-11-22"), new ExprTimestampValue("2020-09-16 17:30:00")), + Arguments.of(new ExprDateValue("1984-11-22"), new ExprTimeValue("19:14:38")), + Arguments.of(new ExprTimeValue("19:14:38"), new ExprDateValue(LocalDate.now())), + Arguments.of(new ExprTimeValue("19:14:38"), new ExprDatetimeValue("2012-08-07 09:07:00")), + Arguments.of(new ExprTimeValue("19:14:38"), new ExprTimestampValue("1984-02-03 04:05:07")), + Arguments.of( + new ExprTimestampValue("2012-08-07 19:14:38"), new ExprDatetimeValue("1961-04-12 09:07:00")), - Arguments.of(new ExprTimestampValue("2012-08-07 19:14:38"), - new ExprTimeValue("09:07:00")), - Arguments.of(new ExprTimestampValue(LocalDate.now() + " 19:14:38"), - new ExprTimeValue("09:07:00")), - Arguments.of(new ExprTimestampValue("2012-08-07 00:00:00"), - new ExprDateValue("1961-04-12")), - Arguments.of(new ExprTimestampValue("1961-04-12 19:14:38"), - new ExprDateValue("1961-04-12")) - ); + Arguments.of(new ExprTimestampValue("2012-08-07 19:14:38"), new ExprTimeValue("09:07:00")), + Arguments.of( + new ExprTimestampValue(LocalDate.now() + " 19:14:38"), new ExprTimeValue("09:07:00")), + Arguments.of( + new ExprTimestampValue("2012-08-07 00:00:00"), new ExprDateValue("1961-04-12")), + Arguments.of( + new ExprTimestampValue("1961-04-12 19:14:38"), new ExprDateValue("1961-04-12"))); } /** - * We can't compare directly ExprValues of different datetime types, we need to use - * `FunctionProperties` object to extract comparable values. + * We can't compare directly ExprValues of different datetime types, we need to use + * `FunctionProperties` object to extract comparable values. */ @ParameterizedTest @MethodSource("getNotEqualDatetimeValuesOfDifferentTypes") public void compareNeqDifferentDateTimeValueTypes(ExprValue left, ExprValue right) { - assertNotEquals(0, extractDateTime(left, functionProperties) - .compareTo(extractDateTime(right, functionProperties))); - assertNotEquals(0, extractDateTime(right, functionProperties) - .compareTo(extractDateTime(left, functionProperties))); + assertNotEquals( + 0, + extractDateTime(left, functionProperties) + .compareTo(extractDateTime(right, functionProperties))); + assertNotEquals( + 0, + extractDateTime(right, functionProperties) + .compareTo(extractDateTime(left, functionProperties))); } @Test public void compareDateTimeWithNotADateTime() { - var exception = assertThrows(ExpressionEvaluationException.class, () -> - new ExprDoubleValue(3.1415).compareTo(new ExprIntervalValue(Period.ofDays(1)))); - assertEquals("compare expected value have same type, but with [DOUBLE, INTERVAL]", + var exception = + assertThrows( + ExpressionEvaluationException.class, + () -> new ExprDoubleValue(3.1415).compareTo(new ExprIntervalValue(Period.ofDays(1)))); + assertEquals( + "compare expected value have same type, but with [DOUBLE, INTERVAL]", exception.getMessage()); - exception = assertThrows(ExpressionEvaluationException.class, () -> - new ExprDateValue("1961-04-12").compareTo(new ExprIntegerValue(1))); - assertEquals("compare expected value have same type, but with [DATE, INTEGER]", - exception.getMessage()); + exception = + assertThrows( + ExpressionEvaluationException.class, + () -> new ExprDateValue("1961-04-12").compareTo(new ExprIntegerValue(1))); + assertEquals( + "compare expected value have same type, but with [DATE, INTEGER]", exception.getMessage()); - exception = assertThrows(ExpressionEvaluationException.class, () -> - new ExprStringValue("something").compareTo(new ExprTimeValue("10:20:30"))); - assertEquals("compare expected value have same type, but with [STRING, TIME]", - exception.getMessage()); + exception = + assertThrows( + ExpressionEvaluationException.class, + () -> new ExprStringValue("something").compareTo(new ExprTimeValue("10:20:30"))); + assertEquals( + "compare expected value have same type, but with [STRING, TIME]", exception.getMessage()); } @Test @@ -194,8 +205,7 @@ private static Stream getEqualNumericValuesOfDifferentTypes() { Arguments.of(new ExprIntegerValue(42), new ExprShortValue(42)), Arguments.of(new ExprIntegerValue(42), new ExprLongValue(42)), Arguments.of(new ExprIntegerValue(42), new ExprFloatValue(42)), - Arguments.of(new ExprIntegerValue(42), new ExprDoubleValue(42)) - ); + Arguments.of(new ExprIntegerValue(42), new ExprDoubleValue(42))); } @ParameterizedTest @@ -211,8 +221,7 @@ private static Stream getNotEqualNumericValuesOfDifferentTypes() { Arguments.of(new ExprIntegerValue(42), new ExprShortValue(146)), Arguments.of(new ExprIntegerValue(42), new ExprLongValue(100500)), Arguments.of(new ExprIntegerValue(42), new ExprFloatValue(-1.5)), - Arguments.of(new ExprIntegerValue(42), new ExprDoubleValue(1468.84138)) - ); + Arguments.of(new ExprIntegerValue(42), new ExprDoubleValue(1468.84138))); } @ParameterizedTest @@ -231,47 +240,50 @@ public void stringValueCompare() { @Test public void intervalValueCompare() { - assertEquals(0, new ExprIntervalValue(Period.ofDays(1)) - .compareTo(new ExprIntervalValue(Period.ofDays(1)))); - assertEquals(1, new ExprIntervalValue(Period.ofDays(2)) - .compareTo(new ExprIntervalValue(Period.ofDays(1)))); - assertEquals(-1, new ExprIntervalValue(Period.ofDays(1)) - .compareTo(new ExprIntervalValue(Period.ofDays(2)))); + assertEquals( + 0, + new ExprIntervalValue(Period.ofDays(1)).compareTo(new ExprIntervalValue(Period.ofDays(1)))); + assertEquals( + 1, + new ExprIntervalValue(Period.ofDays(2)).compareTo(new ExprIntervalValue(Period.ofDays(1)))); + assertEquals( + -1, + new ExprIntervalValue(Period.ofDays(1)).compareTo(new ExprIntervalValue(Period.ofDays(2)))); } @Test public void missingCompareToMethodShouldNotBeenCalledDirectly() { - IllegalStateException exception = assertThrows(IllegalStateException.class, - () -> LITERAL_MISSING.compareTo(LITERAL_FALSE)); - assertEquals("[BUG] Unreachable, Comparing with NULL or MISSING is undefined", - exception.getMessage()); + IllegalStateException exception = + assertThrows(IllegalStateException.class, () -> LITERAL_MISSING.compareTo(LITERAL_FALSE)); + assertEquals( + "[BUG] Unreachable, Comparing with NULL or MISSING is undefined", exception.getMessage()); - exception = assertThrows(IllegalStateException.class, - () -> LITERAL_FALSE.compareTo(LITERAL_MISSING)); - assertEquals("[BUG] Unreachable, Comparing with NULL or MISSING is undefined", - exception.getMessage()); + exception = + assertThrows(IllegalStateException.class, () -> LITERAL_FALSE.compareTo(LITERAL_MISSING)); + assertEquals( + "[BUG] Unreachable, Comparing with NULL or MISSING is undefined", exception.getMessage()); - exception = assertThrows(IllegalStateException.class, - () -> ExprMissingValue.of().compare(LITERAL_MISSING)); - assertEquals("[BUG] Unreachable, Comparing with MISSING is undefined", - exception.getMessage()); + exception = + assertThrows( + IllegalStateException.class, () -> ExprMissingValue.of().compare(LITERAL_MISSING)); + assertEquals("[BUG] Unreachable, Comparing with MISSING is undefined", exception.getMessage()); } @Test public void nullCompareToMethodShouldNotBeenCalledDirectly() { - IllegalStateException exception = assertThrows(IllegalStateException.class, - () -> LITERAL_NULL.compareTo(LITERAL_FALSE)); - assertEquals("[BUG] Unreachable, Comparing with NULL or MISSING is undefined", - exception.getMessage()); + IllegalStateException exception = + assertThrows(IllegalStateException.class, () -> LITERAL_NULL.compareTo(LITERAL_FALSE)); + assertEquals( + "[BUG] Unreachable, Comparing with NULL or MISSING is undefined", exception.getMessage()); - exception = assertThrows(IllegalStateException.class, - () -> LITERAL_FALSE.compareTo(LITERAL_NULL)); - assertEquals("[BUG] Unreachable, Comparing with NULL or MISSING is undefined", - exception.getMessage()); + exception = + assertThrows(IllegalStateException.class, () -> LITERAL_FALSE.compareTo(LITERAL_NULL)); + assertEquals( + "[BUG] Unreachable, Comparing with NULL or MISSING is undefined", exception.getMessage()); - exception = assertThrows(IllegalStateException.class, - () -> ExprNullValue.of().compare(LITERAL_MISSING)); - assertEquals("[BUG] Unreachable, Comparing with NULL is undefined", - exception.getMessage()); + exception = + assertThrows( + IllegalStateException.class, () -> ExprNullValue.of().compare(LITERAL_MISSING)); + assertEquals("[BUG] Unreachable, Comparing with NULL is undefined", exception.getMessage()); } } diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java index c4a00fe5ca..c879384955 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.model; import static org.hamcrest.MatcherAssert.assertThat; @@ -58,71 +57,87 @@ public class ExprValueUtilsTest { testTuple.put("1", new ExprIntegerValue(1)); } - private static List numberValues = Stream.of((byte) 1, (short) 1, 1, 1L, 1f, 1D) - .map(ExprValueUtils::fromObjectValue).collect(Collectors.toList()); + private static List numberValues = + Stream.of((byte) 1, (short) 1, 1, 1L, 1f, 1D) + .map(ExprValueUtils::fromObjectValue) + .collect(Collectors.toList()); - private static List nonNumberValues = Arrays.asList( - new ExprStringValue("1"), - ExprBooleanValue.of(true), - new ExprCollectionValue(ImmutableList.of(new ExprIntegerValue(1))), - new ExprTupleValue(testTuple), - new ExprDateValue("2012-08-07"), - new ExprTimeValue("18:00:00"), - new ExprDatetimeValue("2012-08-07 18:00:00"), - new ExprTimestampValue("2012-08-07 18:00:00"), - new ExprIntervalValue(Duration.ofSeconds(100))); + private static List nonNumberValues = + Arrays.asList( + new ExprStringValue("1"), + ExprBooleanValue.of(true), + new ExprCollectionValue(ImmutableList.of(new ExprIntegerValue(1))), + new ExprTupleValue(testTuple), + new ExprDateValue("2012-08-07"), + new ExprTimeValue("18:00:00"), + new ExprDatetimeValue("2012-08-07 18:00:00"), + new ExprTimestampValue("2012-08-07 18:00:00"), + new ExprIntervalValue(Duration.ofSeconds(100))); private static List allValues = Lists.newArrayList(Iterables.concat(numberValues, nonNumberValues)); - private static List> numberValueExtractor = Arrays.asList( - ExprValueUtils::getByteValue, - ExprValueUtils::getShortValue, - ExprValueUtils::getIntegerValue, - ExprValueUtils::getLongValue, - ExprValueUtils::getFloatValue, - ExprValueUtils::getDoubleValue); - private static List> nonNumberValueExtractor = Arrays.asList( - ExprValueUtils::getStringValue, - ExprValueUtils::getBooleanValue, - ExprValueUtils::getCollectionValue, - ExprValueUtils::getTupleValue - ); - private static List> dateAndTimeValueExtractor = Arrays.asList( - ExprValue::dateValue, - ExprValue::timeValue, - ExprValue::datetimeValue, - ExprValue::timestampValue, - ExprValue::intervalValue); - private static List> allValueExtractor = Lists.newArrayList( - Iterables.concat(numberValueExtractor, nonNumberValueExtractor, dateAndTimeValueExtractor)); + private static List> numberValueExtractor = + Arrays.asList( + ExprValueUtils::getByteValue, + ExprValueUtils::getShortValue, + ExprValueUtils::getIntegerValue, + ExprValueUtils::getLongValue, + ExprValueUtils::getFloatValue, + ExprValueUtils::getDoubleValue); + private static List> nonNumberValueExtractor = + Arrays.asList( + ExprValueUtils::getStringValue, + ExprValueUtils::getBooleanValue, + ExprValueUtils::getCollectionValue, + ExprValueUtils::getTupleValue); + private static List> dateAndTimeValueExtractor = + Arrays.asList( + ExprValue::dateValue, + ExprValue::timeValue, + ExprValue::datetimeValue, + ExprValue::timestampValue, + ExprValue::intervalValue); + private static List> allValueExtractor = + Lists.newArrayList( + Iterables.concat( + numberValueExtractor, nonNumberValueExtractor, dateAndTimeValueExtractor)); private static List numberTypes = - Arrays.asList(ExprCoreType.BYTE, ExprCoreType.SHORT, ExprCoreType.INTEGER, ExprCoreType.LONG, - ExprCoreType.FLOAT, ExprCoreType.DOUBLE); - private static List nonNumberTypes = - Arrays.asList(STRING, BOOLEAN, ARRAY, STRUCT); + Arrays.asList( + ExprCoreType.BYTE, + ExprCoreType.SHORT, + ExprCoreType.INTEGER, + ExprCoreType.LONG, + ExprCoreType.FLOAT, + ExprCoreType.DOUBLE); + private static List nonNumberTypes = Arrays.asList(STRING, BOOLEAN, ARRAY, STRUCT); private static List dateAndTimeTypes = Arrays.asList(DATE, TIME, DATETIME, TIMESTAMP, INTERVAL); private static List allTypes = Lists.newArrayList(Iterables.concat(numberTypes, nonNumberTypes, dateAndTimeTypes)); private static Stream getValueTestArgumentStream() { - List expectedValues = Arrays.asList((byte) 1, (short) 1, 1, 1L, 1f, 1D, "1", true, - Arrays.asList(integerValue(1)), - ImmutableMap.of("1", integerValue(1)), - LocalDate.parse("2012-08-07"), - LocalTime.parse("18:00:00"), - LocalDateTime.parse("2012-08-07T18:00:00"), - ZonedDateTime.of(LocalDateTime.parse("2012-08-07T18:00:00"), UTC_ZONE_ID).toInstant(), - Duration.ofSeconds(100) - ); + List expectedValues = + Arrays.asList( + (byte) 1, + (short) 1, + 1, + 1L, + 1f, + 1D, + "1", + true, + Arrays.asList(integerValue(1)), + ImmutableMap.of("1", integerValue(1)), + LocalDate.parse("2012-08-07"), + LocalTime.parse("18:00:00"), + LocalDateTime.parse("2012-08-07T18:00:00"), + ZonedDateTime.of(LocalDateTime.parse("2012-08-07T18:00:00"), UTC_ZONE_ID).toInstant(), + Duration.ofSeconds(100)); Stream.Builder builder = Stream.builder(); for (int i = 0; i < expectedValues.size(); i++) { - builder.add(Arguments.of( - allValues.get(i), - allValueExtractor.get(i), - expectedValues.get(i))); + builder.add(Arguments.of(allValues.get(i), allValueExtractor.get(i), expectedValues.get(i))); } return builder.build(); } @@ -130,16 +145,13 @@ private static Stream getValueTestArgumentStream() { private static Stream getTypeTestArgumentStream() { Stream.Builder builder = Stream.builder(); for (int i = 0; i < allValues.size(); i++) { - builder.add(Arguments.of( - allValues.get(i), - allTypes.get(i))); + builder.add(Arguments.of(allValues.get(i), allTypes.get(i))); } return builder.build(); } private static Stream invalidGetNumberValueArgumentStream() { - return Lists.cartesianProduct(nonNumberValues, numberValueExtractor) - .stream() + return Lists.cartesianProduct(nonNumberValues, numberValueExtractor).stream() .map(list -> Arguments.of(list.get(0), list.get(1))); } @@ -151,23 +163,20 @@ private static Stream invalidConvert() { extractorWithTypeList.add( new AbstractMap.SimpleEntry<>(nonNumberValueExtractor.get(i), nonNumberTypes.get(i))); } - return Lists.cartesianProduct(allValues, extractorWithTypeList) - .stream() - .filter(list -> { - ExprValue value = (ExprValue) list.get(0); - Map.Entry, ExprCoreType> entry = - (Map.Entry, - ExprCoreType>) list - .get(1); - return entry.getValue() != value.type(); - }) - .map(list -> { - Map.Entry, ExprCoreType> entry = - (Map.Entry, - ExprCoreType>) list - .get(1); - return Arguments.of(list.get(0), entry.getKey(), entry.getValue()); - }); + return Lists.cartesianProduct(allValues, extractorWithTypeList).stream() + .filter( + list -> { + ExprValue value = (ExprValue) list.get(0); + Map.Entry, ExprCoreType> entry = + (Map.Entry, ExprCoreType>) list.get(1); + return entry.getValue() != value.type(); + }) + .map( + list -> { + Map.Entry, ExprCoreType> entry = + (Map.Entry, ExprCoreType>) list.get(1); + return Arguments.of(list.get(0), entry.getKey(), entry.getValue()); + }); } @ParameterizedTest(name = "the value of ExprValue:{0} is: {2} ") @@ -182,36 +191,33 @@ public void getType(ExprValue value, ExprCoreType expectType) { assertEquals(expectType, value.type()); } - /** - * Test Invalid to get number. - */ + /** Test Invalid to get number. */ @ParameterizedTest(name = "invalid to get number value of ExprValue:{0}") @MethodSource("invalidGetNumberValueArgumentStream") public void invalidGetNumberValue(ExprValue value, Function extractor) { - Exception exception = assertThrows(ExpressionEvaluationException.class, - () -> extractor.apply(value)); + Exception exception = + assertThrows(ExpressionEvaluationException.class, () -> extractor.apply(value)); assertThat(exception.getMessage(), Matchers.containsString("invalid")); } - /** - * Test Invalid to convert. - */ + /** Test Invalid to convert. */ @ParameterizedTest(name = "invalid convert ExprValue:{0} to ExprType:{2}") @MethodSource("invalidConvert") - public void invalidConvertExprValue(ExprValue value, Function extractor, - ExprCoreType toType) { - Exception exception = assertThrows(ExpressionEvaluationException.class, - () -> extractor.apply(value)); + public void invalidConvertExprValue( + ExprValue value, Function extractor, ExprCoreType toType) { + Exception exception = + assertThrows(ExpressionEvaluationException.class, () -> extractor.apply(value)); assertThat(exception.getMessage(), Matchers.containsString("invalid")); } @Test public void unSupportedObject() { - Exception exception = assertThrows(ExpressionEvaluationException.class, - () -> ExprValueUtils.fromObjectValue(integerValue(1))); + Exception exception = + assertThrows( + ExpressionEvaluationException.class, + () -> ExprValueUtils.fromObjectValue(integerValue(1))); assertEquals( - "unsupported object " - + "class org.opensearch.sql.data.model.ExprIntegerValue", + "unsupported object " + "class org.opensearch.sql.data.model.ExprIntegerValue", exception.getMessage()); } @@ -228,13 +234,14 @@ public void bindingTuples() { @Test public void constructDateAndTimeValue() { - assertEquals(new ExprDateValue("2012-07-07"), - ExprValueUtils.fromObjectValue("2012-07-07", DATE)); - assertEquals(new ExprTimeValue("01:01:01"), - ExprValueUtils.fromObjectValue("01:01:01", TIME)); - assertEquals(new ExprDatetimeValue("2012-07-07 01:01:01"), + assertEquals( + new ExprDateValue("2012-07-07"), ExprValueUtils.fromObjectValue("2012-07-07", DATE)); + assertEquals(new ExprTimeValue("01:01:01"), ExprValueUtils.fromObjectValue("01:01:01", TIME)); + assertEquals( + new ExprDatetimeValue("2012-07-07 01:01:01"), ExprValueUtils.fromObjectValue("2012-07-07 01:01:01", DATETIME)); - assertEquals(new ExprTimestampValue("2012-07-07 01:01:01"), + assertEquals( + new ExprTimestampValue("2012-07-07 01:01:01"), ExprValueUtils.fromObjectValue("2012-07-07 01:01:01", TIMESTAMP)); } @@ -244,17 +251,20 @@ public void hashCodeTest() { assertEquals(new ExprShortValue(1).hashCode(), new ExprShortValue(1).hashCode()); assertEquals(new ExprIntegerValue(1).hashCode(), new ExprIntegerValue(1).hashCode()); assertEquals(new ExprStringValue("1").hashCode(), new ExprStringValue("1").hashCode()); - assertEquals(new ExprCollectionValue(ImmutableList.of(new ExprIntegerValue(1))).hashCode(), + assertEquals( + new ExprCollectionValue(ImmutableList.of(new ExprIntegerValue(1))).hashCode(), new ExprCollectionValue(ImmutableList.of(new ExprIntegerValue(1))).hashCode()); - assertEquals(new ExprTupleValue(testTuple).hashCode(), - new ExprTupleValue(testTuple).hashCode()); - assertEquals(new ExprDateValue("2012-08-07").hashCode(), - new ExprDateValue("2012-08-07").hashCode()); - assertEquals(new ExprTimeValue("18:00:00").hashCode(), - new ExprTimeValue("18:00:00").hashCode()); - assertEquals(new ExprDatetimeValue("2012-08-07 18:00:00").hashCode(), + assertEquals( + new ExprTupleValue(testTuple).hashCode(), new ExprTupleValue(testTuple).hashCode()); + assertEquals( + new ExprDateValue("2012-08-07").hashCode(), new ExprDateValue("2012-08-07").hashCode()); + assertEquals( + new ExprTimeValue("18:00:00").hashCode(), new ExprTimeValue("18:00:00").hashCode()); + assertEquals( + new ExprDatetimeValue("2012-08-07 18:00:00").hashCode(), new ExprDatetimeValue("2012-08-07 18:00:00").hashCode()); - assertEquals(new ExprTimestampValue("2012-08-07 18:00:00").hashCode(), + assertEquals( + new ExprTimestampValue("2012-08-07 18:00:00").hashCode(), new ExprTimestampValue("2012-08-07 18:00:00").hashCode()); } } diff --git a/core/src/test/java/org/opensearch/sql/data/type/ExprTypeTest.java b/core/src/test/java/org/opensearch/sql/data/type/ExprTypeTest.java index 7db856d092..1def15cc6f 100644 --- a/core/src/test/java/org/opensearch/sql/data/type/ExprTypeTest.java +++ b/core/src/test/java/org/opensearch/sql/data/type/ExprTypeTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.type; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/core/src/test/java/org/opensearch/sql/data/utils/ExprValueOrderingTest.java b/core/src/test/java/org/opensearch/sql/data/utils/ExprValueOrderingTest.java index ec00aebe18..cf9bb538c4 100644 --- a/core/src/test/java/org/opensearch/sql/data/utils/ExprValueOrderingTest.java +++ b/core/src/test/java/org/opensearch/sql/data/utils/ExprValueOrderingTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.utils; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -32,10 +31,8 @@ @ExtendWith(MockitoExtension.class) class ExprValueOrderingTest { - @Mock - ExprValue left; - @Mock - ExprValue right; + @Mock ExprValue left; + @Mock ExprValue right; @Test public void natural() { diff --git a/core/src/test/java/org/opensearch/sql/data/utils/NullsFirstExprValueOrderingTest.java b/core/src/test/java/org/opensearch/sql/data/utils/NullsFirstExprValueOrderingTest.java index c13f95ad63..97014fc410 100644 --- a/core/src/test/java/org/opensearch/sql/data/utils/NullsFirstExprValueOrderingTest.java +++ b/core/src/test/java/org/opensearch/sql/data/utils/NullsFirstExprValueOrderingTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.utils; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/core/src/test/java/org/opensearch/sql/data/utils/NullsLastExprValueOrderingTest.java b/core/src/test/java/org/opensearch/sql/data/utils/NullsLastExprValueOrderingTest.java index ab36247089..3625dc3760 100644 --- a/core/src/test/java/org/opensearch/sql/data/utils/NullsLastExprValueOrderingTest.java +++ b/core/src/test/java/org/opensearch/sql/data/utils/NullsLastExprValueOrderingTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.utils; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/core/src/test/java/org/opensearch/sql/data/utils/ReverseExprValueOrderingTest.java b/core/src/test/java/org/opensearch/sql/data/utils/ReverseExprValueOrderingTest.java index 297079fca5..ad88eb2c76 100644 --- a/core/src/test/java/org/opensearch/sql/data/utils/ReverseExprValueOrderingTest.java +++ b/core/src/test/java/org/opensearch/sql/data/utils/ReverseExprValueOrderingTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.data.utils; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/TimestampTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/TimestampTest.java index 957dac5c74..677ad9310e 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/TimestampTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/TimestampTest.java @@ -59,7 +59,7 @@ public void timestamp_one_arg_string_invalid_format(String value, String testNam var exception = assertThrows(SemanticCheckException.class, () -> DSL.timestamp(functionProperties, DSL.literal(value)).valueOf()); assertEquals(String.format("timestamp:%s in unsupported format, please " - + "use yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]", value), exception.getMessage()); + + "use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", value), exception.getMessage()); } @Test diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java index 7f968733c1..ecc3019298 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java @@ -34,6 +34,7 @@ import lombok.SneakyThrows; import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.lucene.search.TotalHits; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; From 757992523a4487b82047bdbc62d38f849b40c724 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Thu, 3 Aug 2023 09:38:30 -0700 Subject: [PATCH 2/4] parent 496fe8e5df5cfa3d15f8c6312bd89d54a51d6a83 author Mitchell Gale 1691080710 -0700 committer Mitchell Gale 1691080766 -0700 Fix create_index/create_index_with_IOException issue caused by OpenSearch PR change (#1899) * Added setDefaultMediaType for create_index and create_index_with_IOException Signed-off-by: Mitchell Gale (cherry picked from commit 7b932a7c882cbabbc9fcafcd864a39bb161bd122) Signed-off-by: Mitchell Gale Resolving merge conflicts for pre tag in java docs. Signed-off-by: Mitchell Gale running spotless check on newly pre tagged javadocs. Signed-off-by: Mitchell Gale Converts java doc table to proper java doc table. Signed-off-by: Mitchell Gale Resolving merge conflicts for pre tag in java docs 2 Signed-off-by: Mitchell Gale running spotless check on newly pre tagged javadocs. Signed-off-by: Mitchell Gale cherry pick 60c0018373b25e674d15c430f9754bcf2d02fb2a Signed-off-by: Mitchell Gale Addressed PR comment for table format in AbstractExprValue. Signed-off-by: Mitchell Gale Removed pre tag from ExpressionReferenceOptimizer. Signed-off-by: Mitchell Gale Removed pre tag from AstDSL.java Signed-off-by: Mitchell Gale Removed pre tag from AstDSL.java Signed-off-by: Mitchell Gale Removed pre tag from SelectExpressionAnalyzer.java Signed-off-by: Mitchell Gale fixed java doc in QualifiedName.java Signed-off-by: Mitchell Gale Removing checkstyle test for core and added spotless for relevant directories. Signed-off-by: Mitchell Gale Fixing spacing around headers in ExpressionReferenceOptimizer.java SelectExpressionAnalyzer.java Signed-off-by: Mitchell Gale Fix breaking changes. Disable some flaky tests in legacy. Signed-off-by: Yury-Fridlyand (cherry picked from commit 809e6567e77e5f47a93f3475e4badb7e3053b88c) Signed-off-by: Mitchell Gale Resolving merge conflicts for pre tag in java docs. Signed-off-by: Mitchell Gale running spotless check on newly pre tagged javadocs. Signed-off-by: Mitchell Gale Fixed java doc spelling and improving string concatination. Signed-off-by: Mitchell Gale improving string concatination. Signed-off-by: Mitchell Gale Improving failure format on some functions. Signed-off-by: Mitchell Gale spotless apply and fix of build.gradle Signed-off-by: Mitchell Gale Resolving merge conflicts for pre tag in java docs. Signed-off-by: Mitchell Gale running spotless check on newly pre tagged javadocs. Signed-off-by: Mitchell Gale Converts java doc table to proper java doc table. Signed-off-by: Mitchell Gale Removing unused import in OpenSearchRestClientTest.java Signed-off-by: Mitchell Gale --- .../analysis/SelectExpressionAnalyzer.java | 22 ++++++++++--------- .../org/opensearch/sql/ast/dsl/AstDSL.java | 8 +++---- .../client/OpenSearchRestClientTest.java | 1 - 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java index afe003fb3d..b727d67e75 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java @@ -70,16 +70,18 @@ public List visitAlias(Alias node, AnalysisContext context) { } /** - * The Alias could be
- * 1. SELECT name, AVG(age) FROM s BY name ->
- * Project(Alias("name", expr), Alias("AVG(age)", aggExpr))
- * Agg(Alias("AVG(age)", aggExpr))
- * 2. SELECT length(name), AVG(age) FROM s BY length(name)
- * Project(Alias("name", expr), Alias("AVG(age)", aggExpr))
- * Agg(Alias("AVG(age)", aggExpr))
- * 3. SELECT length(name) as l, AVG(age) FROM s BY l
- * Project(Alias("name", expr, l), Alias("AVG(age)", aggExpr))
- * Agg(Alias("AVG(age)", aggExpr), Alias("length(name)", groupExpr))
+ * The Alias could be + *
    + *
  1. 1. SELECT name, AVG(age) FROM s BY name -> + * Project(Alias("name", expr), Alias("AVG(age)", aggExpr)) + * Agg(Alias("AVG(age)", aggExpr))
  2. + *
  3. SELECT length(name), AVG(age) FROM s BY length(name) + * Project(Alias("name", expr), Alias("AVG(age)", aggExpr)) + * Agg(Alias("AVG(age)", aggExpr))
  4. + *
  5. SELECT length(name) as l, AVG(age) FROM s BY l + * Project(Alias("name", expr, l), Alias("AVG(age)", aggExpr)) + * Agg(Alias("AVG(age)", aggExpr), Alias("length(name)", groupExpr))
  6. + *
*/ private Expression referenceIfSymbolDefined(Alias expr, AnalysisContext context) { UnresolvedExpression delegatedExpr = expr.getDelegated(); diff --git a/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java b/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java index 98808f929b..da018f7b20 100644 --- a/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java +++ b/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java @@ -261,10 +261,10 @@ public UnresolvedExpression caseWhen(UnresolvedExpression elseClause, } /** - * CASE case_value_expr
- *   WHEN compare_expr THEN result_expr
- *   [WHEN compare_expr THEN result_expr] ...
- *   [ELSE result_expr]
+ * CASE case_value_expr + * WHEN compare_expr THEN result_expr + * [WHEN compare_expr THEN result_expr] ... + * [ELSE result_expr] * END */ public UnresolvedExpression caseWhen(UnresolvedExpression caseValueExpr, diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java index ecc3019298..7f968733c1 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java @@ -34,7 +34,6 @@ import lombok.SneakyThrows; import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.lucene.search.TotalHits; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; From c88dc8098cdf26279b0af1bb4d386568b096d01f Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Thu, 3 Aug 2023 10:35:59 -0700 Subject: [PATCH 3/4] running spotless apply. Signed-off-by: Mitchell Gale --- .../sql/analysis/SelectExpressionAnalyzer.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java index b727d67e75..3ea6c74e62 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java @@ -71,16 +71,15 @@ public List visitAlias(Alias node, AnalysisContext context) { /** * The Alias could be + * *
    - *
  1. 1. SELECT name, AVG(age) FROM s BY name -> - * Project(Alias("name", expr), Alias("AVG(age)", aggExpr)) - * Agg(Alias("AVG(age)", aggExpr))
  2. - *
  3. SELECT length(name), AVG(age) FROM s BY length(name) - * Project(Alias("name", expr), Alias("AVG(age)", aggExpr)) - * Agg(Alias("AVG(age)", aggExpr))
  4. - *
  5. SELECT length(name) as l, AVG(age) FROM s BY l - * Project(Alias("name", expr, l), Alias("AVG(age)", aggExpr)) - * Agg(Alias("AVG(age)", aggExpr), Alias("length(name)", groupExpr))
  6. + *
  7. 1. SELECT name, AVG(age) FROM s BY name -> Project(Alias("name", expr), Alias("AVG(age)", + * aggExpr)) Agg(Alias("AVG(age)", aggExpr)) + *
  8. SELECT length(name), AVG(age) FROM s BY length(name) Project(Alias("name", expr), + * Alias("AVG(age)", aggExpr)) Agg(Alias("AVG(age)", aggExpr)) + *
  9. SELECT length(name) as l, AVG(age) FROM s BY l Project(Alias("name", expr, l), + * Alias("AVG(age)", aggExpr)) Agg(Alias("AVG(age)", aggExpr), Alias("length(name)", + * groupExpr)) *
*/ private Expression referenceIfSymbolDefined(Alias expr, AnalysisContext context) { From f93a82d3c7d9cdfe0dc12058b1687a209bc859d1 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Wed, 9 Aug 2023 09:25:39 -0700 Subject: [PATCH 4/4] Addressed comments in PR 5. Signed-off-by: Mitchell Gale --- .../sql/analysis/SelectExpressionAnalyzer.java | 2 +- .../main/java/org/opensearch/sql/ast/dsl/AstDSL.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java index 3ea6c74e62..5e46cfa629 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java @@ -73,7 +73,7 @@ public List visitAlias(Alias node, AnalysisContext context) { * The Alias could be * *
    - *
  1. 1. SELECT name, AVG(age) FROM s BY name -> Project(Alias("name", expr), Alias("AVG(age)", + *
  2. SELECT name, AVG(age) FROM s BY name -> Project(Alias("name", expr), Alias("AVG(age)", * aggExpr)) Agg(Alias("AVG(age)", aggExpr)) *
  3. SELECT length(name), AVG(age) FROM s BY length(name) Project(Alias("name", expr), * Alias("AVG(age)", aggExpr)) Agg(Alias("AVG(age)", aggExpr)) diff --git a/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java b/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java index da018f7b20..4ceb387076 100644 --- a/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java +++ b/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java @@ -249,11 +249,13 @@ public static Function function(String funcName, UnresolvedExpression... funcArg } /** - * CASE
    - *   WHEN search_condition THEN result_expr
    - *   [WHEN search_condition THEN result_expr] ...
    - *   [ELSE result_expr]
    + *
    +   * CASE
    +   *    WHEN search_condition THEN result_expr
    + * [WHEN search_condition THEN result_expr] ... + * [ELSE result_expr] * END + *
    */ public UnresolvedExpression caseWhen(UnresolvedExpression elseClause, When... whenClauses) { @@ -261,11 +263,13 @@ public UnresolvedExpression caseWhen(UnresolvedExpression elseClause, } /** + *
        * CASE case_value_expr
        *     WHEN compare_expr THEN result_expr
        *     [WHEN compare_expr THEN result_expr] ...
        *     [ELSE result_expr]
        * END
    +   * 
    */ public UnresolvedExpression caseWhen(UnresolvedExpression caseValueExpr, UnresolvedExpression elseClause,