diff --git a/build.gradle b/build.gradle index c15b67c56f..3e75433d83 100644 --- a/build.gradle +++ b/build.gradle @@ -86,10 +86,18 @@ spotless { target fileTree('.') { include 'core/src/main/java/org/opensearch/sql/planner/**/*.java', 'core/src/main/java/org/opensearch/sql/storage/**/*.java', - 'core/src/main/java/org/opensearch/sql/utils/**/*.java' + 'core/src/main/java/org/opensearch/sql/utils/**/*.java', + 'core/src/main/java/org/opensearch/sql/monitor/**/*.java', + 'core/src/main/java/org/opensearch/sql/expression/**/*.java', + 'core/src/main/java/org/opensearch/sql/executor/**/*.java', + 'core/src/main/java/org/opensearch/sql/exception/**/*.java', + '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() + importOrder() // licenseHeader("/*\n" + // " * Copyright OpenSearch Contributors\n" + // " * SPDX-License-Identifier: Apache-2.0\n" + diff --git a/core/build.gradle b/core/build.gradle index cb603419d2..89fac623f2 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -34,8 +34,8 @@ repositories { mavenCentral() } -checkstyleTest.ignoreFailures = true checkstyleMain.ignoreFailures = true +checkstyleTest.ignoreFailures = true pitest { targetClasses = ['org.opensearch.sql.*'] 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 370dd1a3f1..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; @@ -121,9 +120,7 @@ public class Analyzer extends AbstractNodeVisitor private final BuiltinFunctionRepository repository; - /** - * Constructor. - */ + /** Constructor. */ public Analyzer( ExpressionAnalyzer expressionAnalyzer, DataSourceService dataSourceService, @@ -142,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(); @@ -151,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); @@ -188,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()); } @@ -233,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); @@ -267,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); @@ -283,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<>(); @@ -313,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); @@ -342,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(); @@ -396,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); @@ -434,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); @@ -447,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); @@ -472,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); @@ -482,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); @@ -504,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()); @@ -517,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); @@ -538,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); @@ -553,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()); } @@ -580,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 @@ -590,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 a90fc3d2c1..01145dc7df 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/DataSourceSchemaIdentifierNameResolver.java +++ b/core/src/main/java/org/opensearch/sql/analysis/DataSourceSchemaIdentifierNameResolver.java @@ -24,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); } @@ -52,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) { @@ -69,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 60e5b40a82..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; @@ -77,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; } @@ -112,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 @@ -162,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)); @@ -176,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 @@ -185,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") @@ -219,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()); @@ -248,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); @@ -260,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; } @@ -300,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 @@ -320,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 @@ -345,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 @@ -370,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); } } } @@ -400,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); } @@ -421,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 d0e6968b07..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,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.analysis; import lombok.RequiredArgsConstructor; @@ -15,19 +14,15 @@ import org.opensearch.sql.expression.NamedExpression; /** - * 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..5e46cfa629 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,49 @@ 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)) + * + *
    + *
  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 +117,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 +145,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..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]
+   *    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, 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 7d94cf8f31..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; @@ -14,14 +13,11 @@ 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 70ab852571..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; @@ -16,9 +15,7 @@ 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 @@ -26,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/main/java/org/opensearch/sql/exception/ExpressionEvaluationException.java b/core/src/main/java/org/opensearch/sql/exception/ExpressionEvaluationException.java index 65ea187666..d11f6e4f9e 100644 --- a/core/src/main/java/org/opensearch/sql/exception/ExpressionEvaluationException.java +++ b/core/src/main/java/org/opensearch/sql/exception/ExpressionEvaluationException.java @@ -3,12 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.exception; -/** - * Exception for Expression Evaluation. - */ +/** Exception for Expression Evaluation. */ public class ExpressionEvaluationException extends QueryEngineException { public ExpressionEvaluationException(String message) { super(message); diff --git a/core/src/main/java/org/opensearch/sql/exception/NoCursorException.java b/core/src/main/java/org/opensearch/sql/exception/NoCursorException.java index 9383bece57..57f75c2cb0 100644 --- a/core/src/main/java/org/opensearch/sql/exception/NoCursorException.java +++ b/core/src/main/java/org/opensearch/sql/exception/NoCursorException.java @@ -6,8 +6,7 @@ package org.opensearch.sql.exception; /** - * This should be thrown on serialization of a PhysicalPlan tree if paging is finished. - * Processing of such exception should outcome of responding no cursor to the user. + * This should be thrown on serialization of a PhysicalPlan tree if paging is finished. Processing + * of such exception should outcome of responding no cursor to the user. */ -public class NoCursorException extends RuntimeException { -} +public class NoCursorException extends RuntimeException {} diff --git a/core/src/main/java/org/opensearch/sql/exception/QueryEngineException.java b/core/src/main/java/org/opensearch/sql/exception/QueryEngineException.java index ce90ecff5c..b3d13bef71 100644 --- a/core/src/main/java/org/opensearch/sql/exception/QueryEngineException.java +++ b/core/src/main/java/org/opensearch/sql/exception/QueryEngineException.java @@ -3,12 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.exception; -/** - * Query analysis abstract exception. - */ +/** Query analysis abstract exception. */ public class QueryEngineException extends RuntimeException { public QueryEngineException(String message) { diff --git a/core/src/main/java/org/opensearch/sql/exception/SemanticCheckException.java b/core/src/main/java/org/opensearch/sql/exception/SemanticCheckException.java index 8673dbfc3c..6e0c184af8 100644 --- a/core/src/main/java/org/opensearch/sql/exception/SemanticCheckException.java +++ b/core/src/main/java/org/opensearch/sql/exception/SemanticCheckException.java @@ -3,12 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.exception; -/** - * Semantic Check Exception. - */ +/** Semantic Check Exception. */ public class SemanticCheckException extends QueryEngineException { public SemanticCheckException(String message) { super(message); diff --git a/core/src/main/java/org/opensearch/sql/exception/UnsupportedCursorRequestException.java b/core/src/main/java/org/opensearch/sql/exception/UnsupportedCursorRequestException.java index 6ed8e02e5f..8117304571 100644 --- a/core/src/main/java/org/opensearch/sql/exception/UnsupportedCursorRequestException.java +++ b/core/src/main/java/org/opensearch/sql/exception/UnsupportedCursorRequestException.java @@ -5,8 +5,5 @@ package org.opensearch.sql.exception; -/** - * This should be thrown by V2 engine to support fallback scenario. - */ -public class UnsupportedCursorRequestException extends RuntimeException { -} +/** This should be thrown by V2 engine to support fallback scenario. */ +public class UnsupportedCursorRequestException extends RuntimeException {} diff --git a/core/src/main/java/org/opensearch/sql/executor/ExecutionContext.java b/core/src/main/java/org/opensearch/sql/executor/ExecutionContext.java index 8a3162068f..22d14972eb 100644 --- a/core/src/main/java/org/opensearch/sql/executor/ExecutionContext.java +++ b/core/src/main/java/org/opensearch/sql/executor/ExecutionContext.java @@ -9,12 +9,9 @@ import lombok.Getter; import org.opensearch.sql.storage.split.Split; -/** - * Execution context hold planning related information. - */ +/** Execution context hold planning related information. */ public class ExecutionContext { - @Getter - private final Optional split; + @Getter private final Optional split; public ExecutionContext(Split split) { this.split = Optional.of(split); diff --git a/core/src/main/java/org/opensearch/sql/executor/ExecutionEngine.java b/core/src/main/java/org/opensearch/sql/executor/ExecutionEngine.java index 9465da22c9..43b8ccb62e 100644 --- a/core/src/main/java/org/opensearch/sql/executor/ExecutionEngine.java +++ b/core/src/main/java/org/opensearch/sql/executor/ExecutionEngine.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.executor; import java.util.List; @@ -17,39 +16,33 @@ import org.opensearch.sql.executor.pagination.Cursor; import org.opensearch.sql.planner.physical.PhysicalPlan; -/** - * Execution engine that encapsulates execution details. - */ +/** Execution engine that encapsulates execution details. */ public interface ExecutionEngine { /** - * Execute physical plan and call back response listener. + * Execute physical plan and call back response listener.
* Todo. deprecated this interface after finalize {@link ExecutionContext}. * - * @param plan executable physical plan + * @param plan executable physical plan * @param listener response listener */ void execute(PhysicalPlan plan, ResponseListener listener); - /** - * Execute physical plan with {@link ExecutionContext} and call back response listener. - */ - void execute(PhysicalPlan plan, ExecutionContext context, - ResponseListener listener); + /** Execute physical plan with {@link ExecutionContext} and call back response listener. */ + void execute( + PhysicalPlan plan, ExecutionContext context, ResponseListener listener); /** - * Explain physical plan and call back response listener. The reason why this has to - * be part of execution engine interface is that the physical plan probably needs to - * be executed to get more info for profiling, such as actual execution time, rows fetched etc. + * Explain physical plan and call back response listener. The reason why this has to be part of + * execution engine interface is that the physical plan probably needs to be executed to get more + * info for profiling, such as actual execution time, rows fetched etc. * - * @param plan physical plan to explain + * @param plan physical plan to explain * @param listener response listener */ void explain(PhysicalPlan plan, ResponseListener listener); - /** - * Data class that encapsulates ExprValue. - */ + /** Data class that encapsulates ExprValue. */ @Data class QueryResponse { private final Schema schema; @@ -70,8 +63,8 @@ public static class Column { } /** - * Data class that encapsulates explain result. This can help decouple core engine - * from concrete explain response format. + * Data class that encapsulates explain result. This can help decouple core engine from concrete + * explain response format. */ @Data class ExplainResponse { @@ -86,5 +79,4 @@ class ExplainResponseNode { private Map description; private List children; } - } diff --git a/core/src/main/java/org/opensearch/sql/executor/Explain.java b/core/src/main/java/org/opensearch/sql/executor/Explain.java index 7c16e0b720..0f05b99383 100644 --- a/core/src/main/java/org/opensearch/sql/executor/Explain.java +++ b/core/src/main/java/org/opensearch/sql/executor/Explain.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.executor; import com.google.common.collect.ImmutableMap; @@ -35,11 +34,9 @@ import org.opensearch.sql.planner.physical.WindowOperator; import org.opensearch.sql.storage.TableScanOperator; -/** - * Visitor that explains a physical plan to JSON format. - */ +/** Visitor that explains a physical plan to JSON format. */ public class Explain extends PhysicalPlanNodeVisitor - implements Function { + implements Function { @Override public ExplainResponse apply(PhysicalPlan plan) { @@ -48,109 +45,160 @@ public ExplainResponse apply(PhysicalPlan plan) { @Override public ExplainResponseNode visitProject(ProjectOperator node, Object context) { - return explain(node, context, explainNode -> explainNode.setDescription(ImmutableMap.of( - "fields", node.getProjectList().toString()))); + return explain( + node, + context, + explainNode -> + explainNode.setDescription( + ImmutableMap.of("fields", node.getProjectList().toString()))); } @Override public ExplainResponseNode visitFilter(FilterOperator node, Object context) { - return explain(node, context, explainNode -> explainNode.setDescription(ImmutableMap.of( - "conditions", node.getConditions().toString()))); + return explain( + node, + context, + explainNode -> + explainNode.setDescription( + ImmutableMap.of("conditions", node.getConditions().toString()))); } @Override public ExplainResponseNode visitSort(SortOperator node, Object context) { - return explain(node, context, explainNode -> explainNode.setDescription(ImmutableMap.of( - "sortList", describeSortList(node.getSortList())))); + return explain( + node, + context, + explainNode -> + explainNode.setDescription( + ImmutableMap.of("sortList", describeSortList(node.getSortList())))); } @Override public ExplainResponseNode visitTableScan(TableScanOperator node, Object context) { - return explain(node, context, explainNode -> explainNode.setDescription(ImmutableMap.of( - "request", node.toString()))); + return explain( + node, + context, + explainNode -> explainNode.setDescription(ImmutableMap.of("request", node.toString()))); } @Override public ExplainResponseNode visitAggregation(AggregationOperator node, Object context) { - return explain(node, context, explainNode -> explainNode.setDescription(ImmutableMap.of( - "aggregators", node.getAggregatorList().toString(), - "groupBy", node.getGroupByExprList().toString()))); + return explain( + node, + context, + explainNode -> + explainNode.setDescription( + ImmutableMap.of( + "aggregators", node.getAggregatorList().toString(), + "groupBy", node.getGroupByExprList().toString()))); } @Override public ExplainResponseNode visitWindow(WindowOperator node, Object context) { - return explain(node, context, explainNode -> explainNode.setDescription(ImmutableMap.of( - "function", node.getWindowFunction().toString(), - "definition", ImmutableMap.of( - "partitionBy", node.getWindowDefinition().getPartitionByList().toString(), - "sortList", describeSortList(node.getWindowDefinition().getSortList()))))); + return explain( + node, + context, + explainNode -> + explainNode.setDescription( + ImmutableMap.of( + "function", node.getWindowFunction().toString(), + "definition", + ImmutableMap.of( + "partitionBy", + node.getWindowDefinition().getPartitionByList().toString(), + "sortList", + describeSortList(node.getWindowDefinition().getSortList()))))); } @Override public ExplainResponseNode visitRename(RenameOperator node, Object context) { Map renameMappingDescription = - node.getMapping() - .entrySet() - .stream() - .collect(Collectors.toMap( - e -> e.getKey().toString(), - e -> e.getValue().toString())); + node.getMapping().entrySet().stream() + .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString())); - return explain(node, context, explainNode -> explainNode.setDescription(ImmutableMap.of( - "mapping", renameMappingDescription))); + return explain( + node, + context, + explainNode -> + explainNode.setDescription(ImmutableMap.of("mapping", renameMappingDescription))); } @Override public ExplainResponseNode visitRemove(RemoveOperator node, Object context) { - return explain(node, context, explainNode -> explainNode.setDescription(ImmutableMap.of( - "removeList", node.getRemoveList().toString()))); + return explain( + node, + context, + explainNode -> + explainNode.setDescription( + ImmutableMap.of("removeList", node.getRemoveList().toString()))); } @Override public ExplainResponseNode visitEval(EvalOperator node, Object context) { - return explain(node, context, explainNode -> explainNode.setDescription(ImmutableMap.of( - "expressions", convertPairListToMap(node.getExpressionList())))); + return explain( + node, + context, + explainNode -> + explainNode.setDescription( + ImmutableMap.of("expressions", convertPairListToMap(node.getExpressionList())))); } @Override public ExplainResponseNode visitDedupe(DedupeOperator node, Object context) { - return explain(node, context, explainNode -> explainNode.setDescription(ImmutableMap.of( - "dedupeList", node.getDedupeList().toString(), - "allowedDuplication", node.getAllowedDuplication(), - "keepEmpty", node.getKeepEmpty(), - "consecutive", node.getConsecutive()))); + return explain( + node, + context, + explainNode -> + explainNode.setDescription( + ImmutableMap.of( + "dedupeList", node.getDedupeList().toString(), + "allowedDuplication", node.getAllowedDuplication(), + "keepEmpty", node.getKeepEmpty(), + "consecutive", node.getConsecutive()))); } @Override public ExplainResponseNode visitRareTopN(RareTopNOperator node, Object context) { - return explain(node, context, explainNode -> explainNode.setDescription(ImmutableMap.of( - "commandType", node.getCommandType(), - "noOfResults", node.getNoOfResults(), - "fields", node.getFieldExprList().toString(), - "groupBy", node.getGroupByExprList().toString() - ))); + return explain( + node, + context, + explainNode -> + explainNode.setDescription( + ImmutableMap.of( + "commandType", node.getCommandType(), + "noOfResults", node.getNoOfResults(), + "fields", node.getFieldExprList().toString(), + "groupBy", node.getGroupByExprList().toString()))); } @Override public ExplainResponseNode visitValues(ValuesOperator node, Object context) { - return explain(node, context, explainNode -> explainNode.setDescription(ImmutableMap.of( - "values", node.getValues()))); + return explain( + node, + context, + explainNode -> explainNode.setDescription(ImmutableMap.of("values", node.getValues()))); } @Override public ExplainResponseNode visitLimit(LimitOperator node, Object context) { - return explain(node, context, explanNode -> explanNode.setDescription(ImmutableMap.of( - "limit", node.getLimit(), "offset", node.getOffset()))); + return explain( + node, + context, + explanNode -> + explanNode.setDescription( + ImmutableMap.of("limit", node.getLimit(), "offset", node.getOffset()))); } @Override public ExplainResponseNode visitNested(NestedOperator node, Object context) { - return explain(node, context, explanNode -> explanNode.setDescription(ImmutableMap.of( - "nested", node.getFields()))); + return explain( + node, + context, + explanNode -> explanNode.setDescription(ImmutableMap.of("nested", node.getFields()))); } - protected ExplainResponseNode explain(PhysicalPlan node, Object context, - Consumer doExplain) { + protected ExplainResponseNode explain( + PhysicalPlan node, Object context, Consumer doExplain) { ExplainResponseNode explainNode = new ExplainResponseNode(getOperatorName(node)); List children = new ArrayList<>(); @@ -169,19 +217,18 @@ private String getOperatorName(PhysicalPlan node) { private Map convertPairListToMap(List> pairs) { return pairs.stream() - .collect(Collectors.toMap( - p -> p.getLeft().toString(), - p -> p.getRight().toString())); + .collect(Collectors.toMap(p -> p.getLeft().toString(), p -> p.getRight().toString())); } private Map> describeSortList( List> sortList) { return sortList.stream() - .collect(Collectors.toMap( - p -> p.getRight().toString(), - p -> ImmutableMap.of( - "sortOrder", p.getLeft().getSortOrder().toString(), - "nullOrder", p.getLeft().getNullOrder().toString()))); + .collect( + Collectors.toMap( + p -> p.getRight().toString(), + p -> + ImmutableMap.of( + "sortOrder", p.getLeft().getSortOrder().toString(), + "nullOrder", p.getLeft().getNullOrder().toString()))); } - } diff --git a/core/src/main/java/org/opensearch/sql/executor/QueryId.java b/core/src/main/java/org/opensearch/sql/executor/QueryId.java index 933cb5d82d..eea8166e2a 100644 --- a/core/src/main/java/org/opensearch/sql/executor/QueryId.java +++ b/core/src/main/java/org/opensearch/sql/executor/QueryId.java @@ -12,18 +12,14 @@ import org.apache.commons.lang3.RandomStringUtils; import org.opensearch.sql.executor.execution.AbstractPlan; -/** - * Query id of {@link AbstractPlan}. - */ +/** Query id of {@link AbstractPlan}. */ public class QueryId { - /** - * Query id. - */ - @Getter - private final String queryId; + /** Query id. */ + @Getter private final String queryId; /** * Generate {@link QueryId}. + * * @return {@link QueryId}. */ public static QueryId queryId() { diff --git a/core/src/main/java/org/opensearch/sql/executor/QueryManager.java b/core/src/main/java/org/opensearch/sql/executor/QueryManager.java index 5b41d7ce2e..44d6a1cd84 100644 --- a/core/src/main/java/org/opensearch/sql/executor/QueryManager.java +++ b/core/src/main/java/org/opensearch/sql/executor/QueryManager.java @@ -11,13 +11,14 @@ import org.opensearch.sql.executor.execution.AbstractPlan; /** - * QueryManager is the high-level interface of core engine. - * Frontend submit {@link AbstractPlan} to QueryManager. + * QueryManager is the high-level interface of core engine. Frontend submit an {@link AbstractPlan} + * to QueryManager. */ public interface QueryManager { /** * Submit {@link AbstractPlan}. + * * @param queryPlan {@link AbstractPlan}. * @return {@link QueryId}. */ diff --git a/core/src/main/java/org/opensearch/sql/executor/QueryService.java b/core/src/main/java/org/opensearch/sql/executor/QueryService.java index 94e7081920..3e939212bf 100644 --- a/core/src/main/java/org/opensearch/sql/executor/QueryService.java +++ b/core/src/main/java/org/opensearch/sql/executor/QueryService.java @@ -18,9 +18,7 @@ import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.physical.PhysicalPlan; -/** - * The low level interface of core engine. - */ +/** The low level interface of core engine. */ @RequiredArgsConstructor public class QueryService { @@ -31,14 +29,14 @@ public class QueryService { private final Planner planner; /** - * Execute the {@link UnresolvedPlan}, using {@link ResponseListener} to get response. + * Execute the {@link UnresolvedPlan}, using {@link ResponseListener} to get response.
* Todo. deprecated this interface after finalize {@link PlanContext}. * - * @param plan {@link UnresolvedPlan} + * @param plan {@link UnresolvedPlan} * @param listener {@link ResponseListener} */ - public void execute(UnresolvedPlan plan, - ResponseListener listener) { + public void execute( + UnresolvedPlan plan, ResponseListener listener) { try { executePlan(analyze(plan), PlanContext.emptyPlanContext(), listener); } catch (Exception e) { @@ -48,22 +46,24 @@ public void execute(UnresolvedPlan plan, /** * Execute the {@link UnresolvedPlan}, with {@link PlanContext} and using {@link ResponseListener} - * to get response. + * to get response.
* Todo. Pass split from PlanContext to ExecutionEngine in following PR. * * @param plan {@link LogicalPlan} * @param planContext {@link PlanContext} * @param listener {@link ResponseListener} */ - public void executePlan(LogicalPlan plan, - PlanContext planContext, - ResponseListener listener) { + public void executePlan( + LogicalPlan plan, + PlanContext planContext, + ResponseListener listener) { try { planContext .getSplit() .ifPresentOrElse( split -> executionEngine.execute(plan(plan), new ExecutionContext(split), listener), - () -> executionEngine.execute( + () -> + executionEngine.execute( plan(plan), ExecutionContext.emptyExecutionContext(), listener)); } catch (Exception e) { listener.onFailure(e); @@ -71,14 +71,14 @@ public void executePlan(LogicalPlan plan, } /** - * Explain the query in {@link UnresolvedPlan} using {@link ResponseListener} to - * get and format explain response. + * Explain the query in {@link UnresolvedPlan} using {@link ResponseListener} to get and format + * explain response. * * @param plan {@link UnresolvedPlan} * @param listener {@link ResponseListener} for explain response */ - public void explain(UnresolvedPlan plan, - ResponseListener listener) { + public void explain( + UnresolvedPlan plan, ResponseListener listener) { try { executionEngine.explain(plan(analyze(plan)), listener); } catch (Exception e) { @@ -86,16 +86,12 @@ public void explain(UnresolvedPlan plan, } } - /** - * Analyze {@link UnresolvedPlan}. - */ + /** Analyze {@link UnresolvedPlan}. */ public LogicalPlan analyze(UnresolvedPlan plan) { return analyzer.analyze(plan, new AnalysisContext()); } - /** - * Translate {@link LogicalPlan} to {@link PhysicalPlan}. - */ + /** Translate {@link LogicalPlan} to {@link PhysicalPlan}. */ public PhysicalPlan plan(LogicalPlan plan) { return planner.plan(plan); } diff --git a/core/src/main/java/org/opensearch/sql/executor/execution/AbstractPlan.java b/core/src/main/java/org/opensearch/sql/executor/execution/AbstractPlan.java index 1654293c04..23091777ce 100644 --- a/core/src/main/java/org/opensearch/sql/executor/execution/AbstractPlan.java +++ b/core/src/main/java/org/opensearch/sql/executor/execution/AbstractPlan.java @@ -8,28 +8,20 @@ package org.opensearch.sql.executor.execution; - import lombok.Getter; import lombok.RequiredArgsConstructor; import org.opensearch.sql.common.response.ResponseListener; import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.executor.QueryId; -/** - * AbstractPlan represent the execution entity of the Statement. - */ +/** AbstractPlan represent the execution entity of the Statement. */ @RequiredArgsConstructor public abstract class AbstractPlan { - /** - * Uniq query id. - */ - @Getter - private final QueryId queryId; + /** Uniq query id. */ + @Getter private final QueryId queryId; - /** - * Start query execution. - */ + /** Start query execution. */ public abstract void execute(); /** diff --git a/core/src/main/java/org/opensearch/sql/executor/execution/CommandPlan.java b/core/src/main/java/org/opensearch/sql/executor/execution/CommandPlan.java index 0ea5266084..103e0e1081 100644 --- a/core/src/main/java/org/opensearch/sql/executor/execution/CommandPlan.java +++ b/core/src/main/java/org/opensearch/sql/executor/execution/CommandPlan.java @@ -15,26 +15,25 @@ import org.opensearch.sql.executor.QueryService; /** - * Query plan which does not reflect a search query being executed. - * It contains a command or an action, for example, a DDL query. + * Query plan which does not reflect a search query being executed. It contains a command or an + * action, for example, a DDL query. */ public class CommandPlan extends AbstractPlan { - /** - * The query plan ast. - */ + /** The query plan ast. */ protected final UnresolvedPlan plan; - /** - * Query service. - */ + /** Query service. */ protected final QueryService queryService; protected final ResponseListener listener; /** Constructor. */ - public CommandPlan(QueryId queryId, UnresolvedPlan plan, QueryService queryService, - ResponseListener listener) { + public CommandPlan( + QueryId queryId, + UnresolvedPlan plan, + QueryService queryService, + ResponseListener listener) { super(queryId); this.plan = plan; this.queryService = queryService; diff --git a/core/src/main/java/org/opensearch/sql/executor/execution/ExplainPlan.java b/core/src/main/java/org/opensearch/sql/executor/execution/ExplainPlan.java index 8c784f82ed..7868a39001 100644 --- a/core/src/main/java/org/opensearch/sql/executor/execution/ExplainPlan.java +++ b/core/src/main/java/org/opensearch/sql/executor/execution/ExplainPlan.java @@ -12,21 +12,18 @@ import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.executor.QueryId; -/** - * Explain plan. - */ +/** Explain plan. */ public class ExplainPlan extends AbstractPlan { private final AbstractPlan plan; private final ResponseListener explainListener; - /** - * Constructor. - */ - public ExplainPlan(QueryId queryId, - AbstractPlan plan, - ResponseListener explainListener) { + /** Constructor. */ + public ExplainPlan( + QueryId queryId, + AbstractPlan plan, + ResponseListener explainListener) { super(queryId); this.plan = plan; this.explainListener = explainListener; diff --git a/core/src/main/java/org/opensearch/sql/executor/execution/QueryPlan.java b/core/src/main/java/org/opensearch/sql/executor/execution/QueryPlan.java index aeecf3e76f..0ebdb875f6 100644 --- a/core/src/main/java/org/opensearch/sql/executor/execution/QueryPlan.java +++ b/core/src/main/java/org/opensearch/sql/executor/execution/QueryPlan.java @@ -17,19 +17,13 @@ import org.opensearch.sql.executor.QueryId; import org.opensearch.sql.executor.QueryService; -/** - * Query plan which includes a select query. - */ +/** Query plan which includes a select query. */ public class QueryPlan extends AbstractPlan { - /** - * The query plan ast. - */ + /** The query plan ast. */ protected final UnresolvedPlan plan; - /** - * Query service. - */ + /** Query service. */ protected final QueryService queryService; protected final ResponseListener listener; @@ -75,8 +69,9 @@ public void execute() { @Override public void explain(ResponseListener listener) { if (pageSize.isPresent()) { - listener.onFailure(new NotImplementedException( - "`explain` feature for paginated requests is not implemented yet.")); + listener.onFailure( + new NotImplementedException( + "`explain` feature for paginated requests is not implemented yet.")); } else { queryService.explain(plan, listener); } diff --git a/core/src/main/java/org/opensearch/sql/executor/execution/QueryPlanFactory.java b/core/src/main/java/org/opensearch/sql/executor/execution/QueryPlanFactory.java index 3273eb3c18..52d7126e17 100644 --- a/core/src/main/java/org/opensearch/sql/executor/execution/QueryPlanFactory.java +++ b/core/src/main/java/org/opensearch/sql/executor/execution/QueryPlanFactory.java @@ -27,9 +27,7 @@ import org.opensearch.sql.executor.QueryService; import org.opensearch.sql.executor.pagination.CanPaginateVisitor; -/** - * QueryExecution Factory. - */ +/** QueryExecution Factory. */ @RequiredArgsConstructor public class QueryPlanFactory extends AbstractNodeVisitor< @@ -38,14 +36,12 @@ public class QueryPlanFactory Optional>, Optional>>> { - /** - * Query Service. - */ + /** Query Service. */ private final QueryService queryService; /** - * NO_CONSUMER_RESPONSE_LISTENER should never be called. It is only used as constructor - * parameter of {@link QueryPlan}. + * NO_CONSUMER_RESPONSE_LISTENER should never be called. It is only used as constructor parameter + * of {@link QueryPlan}. */ @VisibleForTesting protected static final ResponseListener @@ -64,9 +60,7 @@ public void onFailure(Exception e) { } }; - /** - * Create QueryExecution from Statement. - */ + /** Create QueryExecution from Statement. */ public AbstractPlan create( Statement statement, Optional> queryListener, @@ -74,12 +68,12 @@ public AbstractPlan create( return statement.accept(this, Pair.of(queryListener, explainListener)); } - /** - * Creates a QueryPlan from a cursor. - */ - public AbstractPlan create(String cursor, boolean isExplain, - ResponseListener queryResponseListener, - ResponseListener explainListener) { + /** Creates a QueryPlan from a cursor. */ + public AbstractPlan create( + String cursor, + boolean isExplain, + ResponseListener queryResponseListener, + ResponseListener explainListener) { QueryId queryId = QueryId.queryId(); var plan = new QueryPlan(queryId, new FetchCursor(cursor), queryService, queryResponseListener); return isExplain ? new ExplainPlan(queryId, plan, explainListener) : plan; @@ -89,27 +83,32 @@ boolean canConvertToCursor(UnresolvedPlan plan) { return plan.accept(new CanPaginateVisitor(), null); } - /** - * Creates a {@link CloseCursor} command on a cursor. - */ - public AbstractPlan createCloseCursor(String cursor, - ResponseListener queryResponseListener) { - return new CommandPlan(QueryId.queryId(), new CloseCursor().attach(new FetchCursor(cursor)), - queryService, queryResponseListener); + /** Creates a {@link CloseCursor} command on a cursor. */ + public AbstractPlan createCloseCursor( + String cursor, ResponseListener queryResponseListener) { + return new CommandPlan( + QueryId.queryId(), + new CloseCursor().attach(new FetchCursor(cursor)), + queryService, + queryResponseListener); } @Override public AbstractPlan visitQuery( Query node, - Pair>, - Optional>> + Pair< + Optional>, + Optional>> context) { Preconditions.checkArgument( context.getLeft().isPresent(), "[BUG] query listener must be not null"); if (node.getFetchSize() > 0) { if (canConvertToCursor(node.getPlan())) { - return new QueryPlan(QueryId.queryId(), node.getPlan(), node.getFetchSize(), + return new QueryPlan( + QueryId.queryId(), + node.getPlan(), + node.getFetchSize(), queryService, context.getLeft().get()); } else { @@ -117,24 +116,24 @@ public AbstractPlan visitQuery( throw new UnsupportedCursorRequestException(); } } else { - return new QueryPlan(QueryId.queryId(), node.getPlan(), queryService, - context.getLeft().get()); + return new QueryPlan( + QueryId.queryId(), node.getPlan(), queryService, context.getLeft().get()); } } @Override public AbstractPlan visitExplain( Explain node, - Pair>, - Optional>> + Pair< + Optional>, + Optional>> context) { Preconditions.checkArgument( context.getRight().isPresent(), "[BUG] explain listener must be not null"); return new ExplainPlan( QueryId.queryId(), - create(node.getStatement(), - Optional.of(NO_CONSUMER_RESPONSE_LISTENER), Optional.empty()), + create(node.getStatement(), Optional.of(NO_CONSUMER_RESPONSE_LISTENER), Optional.empty()), context.getRight().get()); } } diff --git a/core/src/main/java/org/opensearch/sql/executor/execution/StreamingQueryPlan.java b/core/src/main/java/org/opensearch/sql/executor/execution/StreamingQueryPlan.java index 9bb37b064c..5adb9644e9 100644 --- a/core/src/main/java/org/opensearch/sql/executor/execution/StreamingQueryPlan.java +++ b/core/src/main/java/org/opensearch/sql/executor/execution/StreamingQueryPlan.java @@ -24,9 +24,7 @@ import org.opensearch.sql.planner.logical.LogicalPlanNodeVisitor; import org.opensearch.sql.planner.logical.LogicalRelation; -/** - * Streaming Query Plan. - */ +/** Streaming Query Plan. */ public class StreamingQueryPlan extends QueryPlan { private static final Logger log = LogManager.getLogger(StreamingQueryPlan.class); @@ -35,14 +33,13 @@ public class StreamingQueryPlan extends QueryPlan { private MicroBatchStreamingExecution streamingExecution; - /** - * constructor. - */ - public StreamingQueryPlan(QueryId queryId, - UnresolvedPlan plan, - QueryService queryService, - ResponseListener listener, - ExecutionStrategy executionStrategy) { + /** constructor. */ + public StreamingQueryPlan( + QueryId queryId, + UnresolvedPlan plan, + QueryService queryService, + ResponseListener listener, + ExecutionStrategy executionStrategy) { super(queryId, plan, queryService, listener); this.executionStrategy = executionStrategy; @@ -70,15 +67,13 @@ public void execute() { } interface ExecutionStrategy { - /** - * execute task. - */ + /** execute task. */ void execute(Runnable task) throws InterruptedException; } /** - * execute task with fixed interval. - * if task run time < interval, trigger next task on next interval. + * execute task with fixed interval.
+ * if task run time < interval, trigger next task on next interval.
* if task run time >= interval, trigger next task immediately. */ @RequiredArgsConstructor diff --git a/core/src/main/java/org/opensearch/sql/executor/pagination/CanPaginateVisitor.java b/core/src/main/java/org/opensearch/sql/executor/pagination/CanPaginateVisitor.java index e304c132bd..9f14ba1e5d 100644 --- a/core/src/main/java/org/opensearch/sql/executor/pagination/CanPaginateVisitor.java +++ b/core/src/main/java/org/opensearch/sql/executor/pagination/CanPaginateVisitor.java @@ -41,18 +41,26 @@ import org.opensearch.sql.expression.function.BuiltinFunctionName; /** - * Use this unresolved plan visitor to check if a plan can be serialized by PaginatedPlanCache. - * If
plan.accept(new CanPaginateVisitor(...))
returns true, - * then PaginatedPlanCache.convertToCursor will succeed. Otherwise, it will fail. - * The purpose of this visitor is to activate legacy engine fallback mechanism. - * Currently, V2 engine does not support queries with: - * - aggregation (GROUP BY clause or aggregation functions like min/max) - * - in memory aggregation (window function) - * - LIMIT/OFFSET clause(s) - * - without FROM clause - * - JOIN - * - a subquery - * V2 also requires that the table being queried should be an OpenSearch index. + * Use this unresolved plan visitor to check if a plan can be serialized by PaginatedPlanCache.
+ * If + * + *
plan.accept(new CanPaginateVisitor(...))
+ * + * returns true, PaginatedPlanCache.convertToCursor will succeed.
+ * Otherwise, it will fail.
+ * The purpose of this visitor is to activate legacy engine fallback mechanism.
+ * Currently, V2 engine does not support queries with:
+ * + *
    + *
  • aggregation (GROUP BY clause or aggregation functions like min/max) + *
  • in memory aggregation (window function) + *
  • LIMIT/OFFSET clause(s) + *
  • without FROM clause + *
  • JOIN + *
  • a subquery + *
+ * + * V2 also requires that the table being queried should be an OpenSearch index.
* See PaginatedPlanCache.canConvertToCursor for usage. */ public class CanPaginateVisitor extends AbstractNodeVisitor { @@ -80,8 +88,8 @@ protected Boolean canPaginate(Node node, Object context) { // https://github.com/opensearch-project/sql/issues/1471 @Override public Boolean visitSort(Sort node, Object context) { - return node.getSortList().stream().allMatch(f -> f.getField() instanceof QualifiedName - && visitField(f, context)) + return node.getSortList().stream() + .allMatch(f -> f.getField() instanceof QualifiedName && visitField(f, context)) && canPaginate(node, context); } @@ -116,8 +124,8 @@ public Boolean visitLiteral(Literal node, Object context) { @Override public Boolean visitField(Field node, Object context) { - return canPaginate(node, context) && node.getFieldArgs().stream() - .allMatch(n -> n.accept(this, context)); + return canPaginate(node, context) + && node.getFieldArgs().stream().allMatch(n -> n.accept(this, context)); } @Override @@ -192,8 +200,8 @@ public Boolean visitFunction(Function node, Object context) { @Override public Boolean visitIn(In node, Object context) { - return canPaginate(node, context) && node.getValueList().stream() - .allMatch(n -> n.accept(this, context)); + return canPaginate(node, context) + && node.getValueList().stream().allMatch(n -> n.accept(this, context)); } @Override diff --git a/core/src/main/java/org/opensearch/sql/executor/pagination/Cursor.java b/core/src/main/java/org/opensearch/sql/executor/pagination/Cursor.java index bb320f5c67..59a14a2d72 100644 --- a/core/src/main/java/org/opensearch/sql/executor/pagination/Cursor.java +++ b/core/src/main/java/org/opensearch/sql/executor/pagination/Cursor.java @@ -14,8 +14,7 @@ public class Cursor { public static final Cursor None = new Cursor(null); - @Getter - private final String data; + @Getter private final String data; public String toString() { return data; diff --git a/core/src/main/java/org/opensearch/sql/executor/pagination/PlanSerializer.java b/core/src/main/java/org/opensearch/sql/executor/pagination/PlanSerializer.java index 07cf174d73..40a6cdfa84 100644 --- a/core/src/main/java/org/opensearch/sql/executor/pagination/PlanSerializer.java +++ b/core/src/main/java/org/opensearch/sql/executor/pagination/PlanSerializer.java @@ -24,8 +24,8 @@ import org.opensearch.sql.storage.StorageEngine; /** - * This class is entry point to paged requests. It is responsible to cursor serialization - * and deserialization. + * This class is entry point to paged requests. It is responsible to cursor serialization and + * deserialization. */ @RequiredArgsConstructor public class PlanSerializer { @@ -33,14 +33,11 @@ public class PlanSerializer { private final StorageEngine engine; - - /** - * Converts a physical plan tree to a cursor. - */ + /** Converts a physical plan tree to a cursor. */ public Cursor convertToCursor(PhysicalPlan plan) { try { - return new Cursor(CURSOR_PREFIX - + serialize(((SerializablePlan) plan).getPlanForSerialization())); + return new Cursor( + CURSOR_PREFIX + serialize(((SerializablePlan) plan).getPlanForSerialization())); // ClassCastException thrown when a plan in the tree doesn't implement SerializablePlan } catch (NotSerializableException | ClassCastException | NoCursorException e) { return Cursor.None; @@ -49,6 +46,7 @@ public Cursor convertToCursor(PhysicalPlan plan) { /** * Serializes and compresses the object. + * * @param object The object. * @return Encoded binary data. */ @@ -61,9 +59,12 @@ protected String serialize(Serializable object) throws NotSerializableException ByteArrayOutputStream out = new ByteArrayOutputStream(); // GZIP provides 35-45%, lzma from apache commons-compress has few % better compression - GZIPOutputStream gzip = new GZIPOutputStream(out) { { - this.def.setLevel(Deflater.BEST_COMPRESSION); - } }; + GZIPOutputStream gzip = + new GZIPOutputStream(out) { + { + this.def.setLevel(Deflater.BEST_COMPRESSION); + } + }; gzip.write(output.toByteArray()); gzip.close(); @@ -77,24 +78,23 @@ protected String serialize(Serializable object) throws NotSerializableException /** * Decompresses and deserializes the binary data. + * * @param code Encoded binary data. * @return An object. */ protected Serializable deserialize(String code) { try { - GZIPInputStream gzip = new GZIPInputStream( - new ByteArrayInputStream(HashCode.fromString(code).asBytes())); - ObjectInputStream objectInput = new CursorDeserializationStream( - new ByteArrayInputStream(gzip.readAllBytes())); + GZIPInputStream gzip = + new GZIPInputStream(new ByteArrayInputStream(HashCode.fromString(code).asBytes())); + ObjectInputStream objectInput = + new CursorDeserializationStream(new ByteArrayInputStream(gzip.readAllBytes())); return (Serializable) objectInput.readObject(); } catch (Exception e) { throw new IllegalStateException("Failed to deserialize object", e); } } - /** - * Converts a cursor to a physical plan tree. - */ + /** Converts a cursor to a physical plan tree. */ public PhysicalPlan convertToPlan(String cursor) { if (!cursor.startsWith(CURSOR_PREFIX)) { throw new UnsupportedOperationException("Unsupported cursor"); diff --git a/core/src/main/java/org/opensearch/sql/executor/streaming/Batch.java b/core/src/main/java/org/opensearch/sql/executor/streaming/Batch.java index cd7d7dae5a..ab03c4fb53 100644 --- a/core/src/main/java/org/opensearch/sql/executor/streaming/Batch.java +++ b/core/src/main/java/org/opensearch/sql/executor/streaming/Batch.java @@ -8,9 +8,7 @@ import lombok.Data; import org.opensearch.sql.storage.split.Split; -/** - * A batch of streaming execution. - */ +/** A batch of streaming execution. */ @Data public class Batch { private final Split split; diff --git a/core/src/main/java/org/opensearch/sql/executor/streaming/MicroBatchStreamingExecution.java b/core/src/main/java/org/opensearch/sql/executor/streaming/MicroBatchStreamingExecution.java index d85c17fe66..4e05484f15 100644 --- a/core/src/main/java/org/opensearch/sql/executor/streaming/MicroBatchStreamingExecution.java +++ b/core/src/main/java/org/opensearch/sql/executor/streaming/MicroBatchStreamingExecution.java @@ -20,9 +20,7 @@ import org.opensearch.sql.planner.PlanContext; import org.opensearch.sql.planner.logical.LogicalPlan; -/** - * Micro batch streaming execution. - */ +/** Micro batch streaming execution. */ public class MicroBatchStreamingExecution { private static final Logger log = LogManager.getLogger(MicroBatchStreamingExecution.class); @@ -46,9 +44,7 @@ public class MicroBatchStreamingExecution { /** keep track the latest commit batchId. */ private final MetadataLog committedLog; - /** - * Constructor. - */ + /** Constructor. */ public MicroBatchStreamingExecution( StreamingSource source, LogicalPlan batchPlan, @@ -63,9 +59,7 @@ public MicroBatchStreamingExecution( this.committedLog = committedLog; } - /** - * Pull the {@link Batch} from {@link StreamingSource} and execute the {@link Batch}. - */ + /** Pull the {@link Batch} from {@link StreamingSource} and execute the {@link Batch}. */ public void execute() { Long latestBatchId = offsetLog.getLatest().map(Pair::getKey).orElse(INITIAL_LATEST_BATCH_ID); Long latestCommittedBatchId = diff --git a/core/src/main/java/org/opensearch/sql/executor/streaming/Offset.java b/core/src/main/java/org/opensearch/sql/executor/streaming/Offset.java index 00f040e437..27960da84d 100644 --- a/core/src/main/java/org/opensearch/sql/executor/streaming/Offset.java +++ b/core/src/main/java/org/opensearch/sql/executor/streaming/Offset.java @@ -7,9 +7,7 @@ import lombok.Data; -/** - * Offset. - */ +/** Offset. */ @Data public class Offset { diff --git a/core/src/main/java/org/opensearch/sql/executor/streaming/StreamingSource.java b/core/src/main/java/org/opensearch/sql/executor/streaming/StreamingSource.java index ebd3fa714b..2b45a45d9a 100644 --- a/core/src/main/java/org/opensearch/sql/executor/streaming/StreamingSource.java +++ b/core/src/main/java/org/opensearch/sql/executor/streaming/StreamingSource.java @@ -7,9 +7,7 @@ import java.util.Optional; -/** - * Streaming source. - */ +/** Streaming source. */ public interface StreamingSource { /** * Get current {@link Offset} of stream data. diff --git a/core/src/main/java/org/opensearch/sql/expression/DSL.java b/core/src/main/java/org/opensearch/sql/expression/DSL.java index f1a8110a29..4341668b69 100644 --- a/core/src/main/java/org/opensearch/sql/expression/DSL.java +++ b/core/src/main/java/org/opensearch/sql/expression/DSL.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression; import java.util.Arrays; @@ -29,8 +28,7 @@ public class DSL { - private DSL() { - } + private DSL() {} public static LiteralExpression literal(Byte value) { return new LiteralExpression(ExprValueUtils.byteValue(value)); @@ -68,9 +66,7 @@ public static LiteralExpression literal(ExprValue value) { return new LiteralExpression(value); } - /** - * Wrap a number to {@link LiteralExpression}. - */ + /** Wrap a number to {@link LiteralExpression}. */ public static LiteralExpression literal(Number value) { if (value instanceof Integer) { return new LiteralExpression(ExprValueUtils.integerValue(value.intValue())); @@ -88,21 +84,21 @@ public static ReferenceExpression ref(String ref, ExprType type) { } /** - * Wrap a named expression if not yet. The intent is that different languages may use - * Alias or not when building AST. This caused either named or unnamed expression - * is resolved by analyzer. To make unnamed expression acceptable for logical project, - * it is required to wrap it by named expression here before passing to logical project. + * Wrap a named expression if not yet. The intent is that different languages may use Alias or not + * when building AST. This caused either named or unnamed expression is resolved by analyzer. To + * make unnamed expression acceptable for logical project, it is required to wrap it by named + * expression here before passing to logical project. * - * @param expression expression - * @return expression if named already or expression wrapped by named expression. + * @param expression expression + * @return expression if named already or expression wrapped by named expression. */ public static NamedExpression named(Expression expression) { if (expression instanceof NamedExpression) { return (NamedExpression) expression; } if (expression instanceof ParseExpression) { - return named(((ParseExpression) expression).getIdentifier().valueOf().stringValue(), - expression); + return named( + ((ParseExpression) expression).getIdentifier().valueOf().stringValue(), expression); } return named(expression.toString(), expression); } @@ -127,18 +123,18 @@ public static NamedArgumentExpression namedArgument(String name, String value) { return namedArgument(name, literal(value)); } - public static GrokExpression grok(Expression sourceField, Expression pattern, - Expression identifier) { + public static GrokExpression grok( + Expression sourceField, Expression pattern, Expression identifier) { return new GrokExpression(sourceField, pattern, identifier); } - public static RegexExpression regex(Expression sourceField, Expression pattern, - Expression identifier) { + public static RegexExpression regex( + Expression sourceField, Expression pattern, Expression identifier) { return new RegexExpression(sourceField, pattern, identifier); } - public static PatternsExpression patterns(Expression sourceField, Expression pattern, - Expression identifier) { + public static PatternsExpression patterns( + Expression sourceField, Expression pattern, Expression identifier) { return new PatternsExpression(sourceField, pattern, identifier); } @@ -268,7 +264,6 @@ public static FunctionExpression signum(Expression... expressions) { public static FunctionExpression sinh(Expression... expressions) { return compile(FunctionProperties.None, BuiltinFunctionName.SINH, expressions); - } public static FunctionExpression sqrt(Expression... expressions) { @@ -364,8 +359,7 @@ public static FunctionExpression dayname(Expression... expressions) { } public static FunctionExpression dayofmonth( - FunctionProperties functionProperties, - Expression... expressions) { + FunctionProperties functionProperties, Expression... expressions) { return compile(functionProperties, BuiltinFunctionName.DAYOFMONTH, expressions); } @@ -379,8 +373,7 @@ public static FunctionExpression dayofyear(Expression... expressions) { } public static FunctionExpression day_of_month( - FunctionProperties functionProperties, - Expression... expressions) { + FunctionProperties functionProperties, Expression... expressions) { return compile(functionProperties, BuiltinFunctionName.DAY_OF_MONTH, expressions); } @@ -394,8 +387,8 @@ public static FunctionExpression day_of_week( return compile(functionProperties, BuiltinFunctionName.DAY_OF_WEEK, expressions); } - public static FunctionExpression extract(FunctionProperties functionProperties, - Expression... expressions) { + public static FunctionExpression extract( + FunctionProperties functionProperties, Expression... expressions) { return compile(functionProperties, BuiltinFunctionName.EXTRACT, expressions); } @@ -419,8 +412,8 @@ public static FunctionExpression hour_of_day(Expression... expressions) { return compile(FunctionProperties.None, BuiltinFunctionName.HOUR_OF_DAY, expressions); } - public static FunctionExpression last_day(FunctionProperties functionProperties, - Expression... expressions) { + public static FunctionExpression last_day( + FunctionProperties functionProperties, Expression... expressions) { return compile(functionProperties, BuiltinFunctionName.LAST_DAY, expressions); } @@ -477,14 +470,13 @@ public static FunctionExpression timestamp(Expression... expressions) { return timestamp(FunctionProperties.None, expressions); } - public static FunctionExpression timestamp(FunctionProperties functionProperties, - Expression... expressions) { + public static FunctionExpression timestamp( + FunctionProperties functionProperties, Expression... expressions) { return compile(functionProperties, BuiltinFunctionName.TIMESTAMP, expressions); } public static FunctionExpression date_format( - FunctionProperties functionProperties, - Expression... expressions) { + FunctionProperties functionProperties, Expression... expressions) { return compile(functionProperties, BuiltinFunctionName.DATE_FORMAT, expressions); } @@ -492,8 +484,8 @@ public static FunctionExpression to_days(Expression... expressions) { return compile(FunctionProperties.None, BuiltinFunctionName.TO_DAYS, expressions); } - public static FunctionExpression to_seconds(FunctionProperties functionProperties, - Expression... expressions) { + public static FunctionExpression to_seconds( + FunctionProperties functionProperties, Expression... expressions) { return compile(functionProperties, BuiltinFunctionName.TO_SECONDS, expressions); } @@ -506,8 +498,8 @@ public static FunctionExpression week( return compile(functionProperties, BuiltinFunctionName.WEEK, expressions); } - public static FunctionExpression weekday(FunctionProperties functionProperties, - Expression... expressions) { + public static FunctionExpression weekday( + FunctionProperties functionProperties, Expression... expressions) { return compile(functionProperties, BuiltinFunctionName.WEEKDAY, expressions); } @@ -530,13 +522,13 @@ public static FunctionExpression yearweek( return compile(functionProperties, BuiltinFunctionName.YEARWEEK, expressions); } - public static FunctionExpression str_to_date(FunctionProperties functionProperties, - Expression... expressions) { + public static FunctionExpression str_to_date( + FunctionProperties functionProperties, Expression... expressions) { return compile(functionProperties, BuiltinFunctionName.STR_TO_DATE, expressions); } public static FunctionExpression sec_to_time(Expression... expressions) { - return compile(FunctionProperties.None, BuiltinFunctionName.SEC_TO_TIME, expressions); + return compile(FunctionProperties.None, BuiltinFunctionName.SEC_TO_TIME, expressions); } public static FunctionExpression substr(Expression... expressions) { @@ -771,8 +763,7 @@ public static FunctionExpression iffunction(Expression... expressions) { return compile(FunctionProperties.None, BuiltinFunctionName.IF, expressions); } - public static Expression cases(Expression defaultResult, - WhenClause... whenClauses) { + public static Expression cases(Expression defaultResult, WhenClause... whenClauses) { return new CaseClause(Arrays.asList(whenClauses), defaultResult); } @@ -884,53 +875,52 @@ public static FunctionExpression score_query(Expression... args) { return compile(FunctionProperties.None, BuiltinFunctionName.SCORE_QUERY, args); } - public static FunctionExpression now(FunctionProperties functionProperties, - Expression... args) { + public static FunctionExpression now(FunctionProperties functionProperties, Expression... args) { return compile(functionProperties, BuiltinFunctionName.NOW, args); } - public static FunctionExpression current_timestamp(FunctionProperties functionProperties, - Expression... args) { + public static FunctionExpression current_timestamp( + FunctionProperties functionProperties, Expression... args) { return compile(functionProperties, BuiltinFunctionName.CURRENT_TIMESTAMP, args); } - public static FunctionExpression localtimestamp(FunctionProperties functionProperties, - Expression... args) { + public static FunctionExpression localtimestamp( + FunctionProperties functionProperties, Expression... args) { return compile(functionProperties, BuiltinFunctionName.LOCALTIMESTAMP, args); } - public static FunctionExpression localtime(FunctionProperties functionProperties, - Expression... args) { + public static FunctionExpression localtime( + FunctionProperties functionProperties, Expression... args) { return compile(functionProperties, BuiltinFunctionName.LOCALTIME, args); } - public static FunctionExpression sysdate(FunctionProperties functionProperties, - Expression... args) { + public static FunctionExpression sysdate( + FunctionProperties functionProperties, Expression... args) { return compile(functionProperties, BuiltinFunctionName.SYSDATE, args); } - public static FunctionExpression curtime(FunctionProperties functionProperties, - Expression... args) { + public static FunctionExpression curtime( + FunctionProperties functionProperties, Expression... args) { return compile(functionProperties, BuiltinFunctionName.CURTIME, args); } - public static FunctionExpression current_time(FunctionProperties functionProperties, - Expression... args) { + public static FunctionExpression current_time( + FunctionProperties functionProperties, Expression... args) { return compile(functionProperties, BuiltinFunctionName.CURRENT_TIME, args); } - public static FunctionExpression curdate(FunctionProperties functionProperties, - Expression... args) { + public static FunctionExpression curdate( + FunctionProperties functionProperties, Expression... args) { return compile(functionProperties, BuiltinFunctionName.CURDATE, args); } - public static FunctionExpression current_date(FunctionProperties functionProperties, - Expression... args) { + public static FunctionExpression current_date( + FunctionProperties functionProperties, Expression... args) { return compile(functionProperties, BuiltinFunctionName.CURRENT_DATE, args); } - public static FunctionExpression time_format(FunctionProperties functionProperties, - Expression... expressions) { + public static FunctionExpression time_format( + FunctionProperties functionProperties, Expression... expressions) { return compile(functionProperties, BuiltinFunctionName.TIME_FORMAT, expressions); } @@ -938,38 +928,36 @@ public static FunctionExpression timestampadd(Expression... expressions) { return timestampadd(FunctionProperties.None, expressions); } - public static FunctionExpression timestampadd(FunctionProperties functionProperties, - Expression... expressions) { + public static FunctionExpression timestampadd( + FunctionProperties functionProperties, Expression... expressions) { return compile(functionProperties, BuiltinFunctionName.TIMESTAMPADD, expressions); } - public static FunctionExpression timestampdiff(FunctionProperties functionProperties, - Expression... expressions) { + public static FunctionExpression timestampdiff( + FunctionProperties functionProperties, Expression... expressions) { return compile(functionProperties, BuiltinFunctionName.TIMESTAMPDIFF, expressions); } - - public static FunctionExpression utc_date(FunctionProperties functionProperties, - Expression... args) { + public static FunctionExpression utc_date( + FunctionProperties functionProperties, Expression... args) { return compile(functionProperties, BuiltinFunctionName.UTC_DATE, args); } - public static FunctionExpression utc_time(FunctionProperties functionProperties, - Expression... args) { + public static FunctionExpression utc_time( + FunctionProperties functionProperties, Expression... args) { return compile(functionProperties, BuiltinFunctionName.UTC_TIME, args); } - public static FunctionExpression utc_timestamp(FunctionProperties functionProperties, - Expression... args) { + public static FunctionExpression utc_timestamp( + FunctionProperties functionProperties, Expression... args) { return compile(functionProperties, BuiltinFunctionName.UTC_TIMESTAMP, args); - } @SuppressWarnings("unchecked") - private static - T compile(FunctionProperties functionProperties, - BuiltinFunctionName bfn, Expression... args) { - return (T) BuiltinFunctionRepository.getInstance().compile(functionProperties, - bfn.getName(), Arrays.asList(args)); + private static T compile( + FunctionProperties functionProperties, BuiltinFunctionName bfn, Expression... args) { + return (T) + BuiltinFunctionRepository.getInstance() + .compile(functionProperties, bfn.getName(), Arrays.asList(args)); } } diff --git a/core/src/main/java/org/opensearch/sql/expression/Expression.java b/core/src/main/java/org/opensearch/sql/expression/Expression.java index 25a8173efa..e4a5f908e5 100644 --- a/core/src/main/java/org/opensearch/sql/expression/Expression.java +++ b/core/src/main/java/org/opensearch/sql/expression/Expression.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression; import java.io.Serializable; @@ -11,36 +10,28 @@ import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.expression.env.Environment; -/** - * The definition of the resolved expression. - */ +/** The definition of the resolved expression. */ public interface Expression extends Serializable { - /** - * Evaluate the value of expression that does not depend on value environment. - */ + /** Evaluate the value of expression that does not depend on value environment. */ default ExprValue valueOf() { return valueOf(null); } - /** - * Evaluate the value of expression in the value environment. - */ + /** Evaluate the value of expression in the value environment. */ ExprValue valueOf(Environment valueEnv); - /** - * The type of the expression. - */ + /** The type of the expression. */ ExprType type(); /** * Accept a visitor to visit current expression node. - * @param visitor visitor - * @param context context - * @param result type - * @param context type - * @return result accumulated by visitor when visiting + * + * @param visitor visitor + * @param context context + * @param result type + * @param context type + * @return result accumulated by visitor when visiting */ T accept(ExpressionNodeVisitor visitor, C context); - } diff --git a/core/src/main/java/org/opensearch/sql/expression/ExpressionNodeVisitor.java b/core/src/main/java/org/opensearch/sql/expression/ExpressionNodeVisitor.java index e3d4e38674..17dc7f5cd7 100644 --- a/core/src/main/java/org/opensearch/sql/expression/ExpressionNodeVisitor.java +++ b/core/src/main/java/org/opensearch/sql/expression/ExpressionNodeVisitor.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression; import org.opensearch.sql.expression.aggregation.Aggregator; @@ -15,8 +14,9 @@ /** * Abstract visitor for expression tree nodes. - * @param type of return value to accumulate when visiting. - * @param type of context. + * + * @param type of return value to accumulate when visiting. + * @param type of context. */ public abstract class ExpressionNodeVisitor { @@ -26,9 +26,10 @@ public T visitNode(Expression node, C context) { /** * Visit children nodes in function arguments. - * @param node function node - * @param context context - * @return result + * + * @param node function node + * @param context context + * @return result */ public T visitChildren(FunctionImplementation node, C context) { T result = defaultResult(); @@ -81,10 +82,13 @@ public T visitNamedAggregator(NamedAggregator node, C context) { } /** - * Call visitFunction() by default rather than visitChildren(). - * This makes CASE/WHEN able to be handled: - * 1) by visitFunction() if not overwritten: ex. FilterQueryBuilder - * 2) by visitCase/When() otherwise if any special logic: ex. ExprReferenceOptimizer + * Call visitFunction() by default rather than visitChildren(). This makes CASE/WHEN able to be + * handled: + * + *
    + *
  1. by visitFunction() if not overwritten: ex. FilterQueryBuilder + *
  2. by visitCase/When() otherwise if any special logic: ex. ExprReferenceOptimizer + *
*/ public T visitCase(CaseClause node, C context) { return visitFunction(node, context); diff --git a/core/src/main/java/org/opensearch/sql/expression/FunctionExpression.java b/core/src/main/java/org/opensearch/sql/expression/FunctionExpression.java index 2a695f26e6..b67eb38c00 100644 --- a/core/src/main/java/org/opensearch/sql/expression/FunctionExpression.java +++ b/core/src/main/java/org/opensearch/sql/expression/FunctionExpression.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression; import java.util.List; @@ -14,22 +13,17 @@ import org.opensearch.sql.expression.function.FunctionImplementation; import org.opensearch.sql.expression.function.FunctionName; -/** - * Function Expression. - */ +/** Function Expression. */ @EqualsAndHashCode @RequiredArgsConstructor @ToString public abstract class FunctionExpression implements Expression, FunctionImplementation { - @Getter - private final FunctionName functionName; + @Getter private final FunctionName functionName; - @Getter - private final List arguments; + @Getter private final List arguments; @Override public T accept(ExpressionNodeVisitor visitor, C context) { return visitor.visitFunction(this, context); } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/HighlightExpression.java b/core/src/main/java/org/opensearch/sql/expression/HighlightExpression.java index 804c38a6f7..79cc07f048 100644 --- a/core/src/main/java/org/opensearch/sql/expression/HighlightExpression.java +++ b/core/src/main/java/org/opensearch/sql/expression/HighlightExpression.java @@ -20,9 +20,7 @@ import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.BuiltinFunctionName; -/** - * Highlight Expression. - */ +/** Highlight Expression. */ @Getter public class HighlightExpression extends FunctionExpression { private final Expression highlightField; @@ -30,17 +28,19 @@ public class HighlightExpression extends FunctionExpression { /** * HighlightExpression Constructor. + * * @param highlightField : Highlight field for expression. */ public HighlightExpression(Expression highlightField) { super(BuiltinFunctionName.HIGHLIGHT.getName(), List.of(highlightField)); this.highlightField = highlightField; - this.type = this.highlightField.toString().contains("*") - ? ExprCoreType.STRUCT : ExprCoreType.ARRAY; + this.type = + this.highlightField.toString().contains("*") ? ExprCoreType.STRUCT : ExprCoreType.ARRAY; } /** * Return collection value matching highlight field. + * * @param valueEnv : Dataset to parse value from. * @return : collection value of highlight fields. */ @@ -57,15 +57,15 @@ public ExprValue valueOf(Environment valueEnv) { // used in conjunction with other highlight calls, we need to ensure // only wildcard regex matching is mapped to wildcard call. if (this.type == ExprCoreType.STRUCT && value.type() == ExprCoreType.STRUCT) { - value = new ExprTupleValue( - new LinkedHashMap(value.tupleValue() - .entrySet() - .stream() - .filter(s -> matchesHighlightRegex(s.getKey(), - StringUtils.unquoteText(highlightField.toString()))) - .collect(Collectors.toMap( - e -> e.getKey(), - e -> e.getValue())))); + value = + new ExprTupleValue( + new LinkedHashMap( + value.tupleValue().entrySet().stream() + .filter( + s -> + matchesHighlightRegex( + s.getKey(), StringUtils.unquoteText(highlightField.toString()))) + .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())))); if (value.tupleValue().isEmpty()) { value = ExprValueUtils.missingValue(); } @@ -76,6 +76,7 @@ public ExprValue valueOf(Environment valueEnv) { /** * Get type for HighlightExpression. + * * @return : Expression type. */ @Override @@ -90,6 +91,7 @@ public T accept(ExpressionNodeVisitor visitor, C context) { /** * Check if field matches the wildcard pattern used in highlight query. + * * @param field Highlight selected field for query * @param pattern Wildcard regex to match field against * @return True if field matches wildcard pattern diff --git a/core/src/main/java/org/opensearch/sql/expression/LiteralExpression.java b/core/src/main/java/org/opensearch/sql/expression/LiteralExpression.java index adb8e197d1..eba03e8430 100644 --- a/core/src/main/java/org/opensearch/sql/expression/LiteralExpression.java +++ b/core/src/main/java/org/opensearch/sql/expression/LiteralExpression.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression; import lombok.EqualsAndHashCode; @@ -12,9 +11,7 @@ import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.expression.env.Environment; -/** - * Literal Expression. - */ +/** Literal Expression. */ @EqualsAndHashCode @RequiredArgsConstructor public class LiteralExpression implements Expression { diff --git a/core/src/main/java/org/opensearch/sql/expression/NamedArgumentExpression.java b/core/src/main/java/org/opensearch/sql/expression/NamedArgumentExpression.java index 0f4601f1bf..c3ce60bd4a 100644 --- a/core/src/main/java/org/opensearch/sql/expression/NamedArgumentExpression.java +++ b/core/src/main/java/org/opensearch/sql/expression/NamedArgumentExpression.java @@ -13,9 +13,7 @@ import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.expression.env.Environment; -/** - * Named argument expression that represents function argument with name. - */ +/** Named argument expression that represents function argument with name. */ @RequiredArgsConstructor @Getter @EqualsAndHashCode diff --git a/core/src/main/java/org/opensearch/sql/expression/NamedExpression.java b/core/src/main/java/org/opensearch/sql/expression/NamedExpression.java index 26996eb93d..03118311a9 100644 --- a/core/src/main/java/org/opensearch/sql/expression/NamedExpression.java +++ b/core/src/main/java/org/opensearch/sql/expression/NamedExpression.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression; import com.google.common.base.Strings; @@ -16,8 +15,8 @@ import org.opensearch.sql.expression.env.Environment; /** - * Named expression that represents expression with name. - * Please see more details in associated unresolved expression operator + * Named expression that represents expression with name.
+ * Please see more details in associated unresolved expression operator
* {@link org.opensearch.sql.ast.expression.Alias}. */ @AllArgsConstructor @@ -26,19 +25,13 @@ @RequiredArgsConstructor public class NamedExpression implements Expression { - /** - * Expression name. - */ + /** Expression name. */ private final String name; - /** - * Expression that being named. - */ + /** Expression that being named. */ private final Expression delegated; - /** - * Optional alias. - */ + /** Optional alias. */ private String alias; @Override @@ -53,7 +46,8 @@ public ExprType type() { /** * Get expression name using name or its alias (if it's present). - * @return expression name + * + * @return expression name */ public String getNameOrAlias() { return Strings.isNullOrEmpty(alias) ? name : alias; @@ -68,5 +62,4 @@ public T accept(ExpressionNodeVisitor visitor, C context) { public String toString() { return getNameOrAlias(); } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/ReferenceExpression.java b/core/src/main/java/org/opensearch/sql/expression/ReferenceExpression.java index 3c5b2af23c..eb510e3b8a 100644 --- a/core/src/main/java/org/opensearch/sql/expression/ReferenceExpression.java +++ b/core/src/main/java/org/opensearch/sql/expression/ReferenceExpression.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression; import static org.opensearch.sql.utils.ExpressionUtils.PATH_SEP; @@ -22,16 +21,15 @@ @EqualsAndHashCode @RequiredArgsConstructor public class ReferenceExpression implements Expression { - @Getter - private final String attr; + @Getter private final String attr; - @Getter - private final List paths; + @Getter private final List paths; private final ExprType type; /** * Constructor of ReferenceExpression. + * * @param ref the field name. e.g. addr.state/addr. * @param type type. */ @@ -63,6 +61,7 @@ public String toString() { } /** + *
    * Resolve the ExprValue from {@link ExprTupleValue} using paths.
    * Considering the following sample data.
    * {
@@ -95,6 +94,7 @@ public String toString() {
    *
    * @param value {@link ExprTupleValue}.
    * @return {@link ExprTupleValue}.
+   * 
*/ public ExprValue resolve(ExprTupleValue value) { return resolve(value, paths); diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregationState.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregationState.java index 345c6c00dd..478e3caf54 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregationState.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregationState.java @@ -3,18 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.aggregation; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.storage.bindingtuple.BindingTuple; -/** - * Maintain the state when {@link Aggregator} iterate on the {@link BindingTuple}. - */ +/** Maintain the state when {@link Aggregator} iterate on the {@link BindingTuple}. */ public interface AggregationState { - /** - * Get {@link ExprValue} result. - */ + /** Get {@link ExprValue} result. */ ExprValue result(); } diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/Aggregator.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/Aggregator.java index a122ea6540..a2a3ce76c3 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/Aggregator.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/Aggregator.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.aggregation; import java.util.List; @@ -26,36 +25,34 @@ import org.opensearch.sql.storage.bindingtuple.BindingTuple; /** - * Aggregator which will iterate on the {@link BindingTuple}s to aggregate the result. - * The Aggregator is not well fit into Expression, because it has side effect. - * But we still want to make it implement {@link Expression} interface to make - * {@link ExpressionAnalyzer} easier. + * Aggregator which will iterate on the {@link BindingTuple}s to aggregate the result. The + * Aggregator is not well fit into Expression, because it has side effect. But we still want to make + * it implement {@link Expression} interface to make {@link ExpressionAnalyzer} easier. */ @EqualsAndHashCode @RequiredArgsConstructor public abstract class Aggregator implements FunctionImplementation, Expression { - @Getter - private final FunctionName functionName; - @Getter - private final List arguments; + @Getter private final FunctionName functionName; + @Getter private final List arguments; protected final ExprCoreType returnType; + @Setter @Getter @Accessors(fluent = true) protected Expression condition; + @Setter @Getter @Accessors(fluent = true) protected Boolean distinct = false; - /** - * Create an {@link AggregationState} which will be used for aggregation. - */ + /** Create an {@link AggregationState} which will be used for aggregation. */ public abstract S create(); /** * Iterate on {@link ExprValue}. + * * @param value {@link ExprValue} * @param state {@link AggregationState} * @return {@link AggregationState} @@ -63,9 +60,9 @@ public abstract class Aggregator protected abstract S iterate(ExprValue value, S state); /** - * Let the aggregator iterate on the {@link BindingTuple} - * To filter out ExprValues that are missing, null or cannot satisfy {@link #condition} - * Before the specific aggregator iterating ExprValue in the tuple. + * Let the aggregator iterate on the {@link BindingTuple} To filter out ExprValues that are + * missing, null or cannot satisfy {@link #condition} Before the specific aggregator iterating + * ExprValue in the tuple. * * @param tuple {@link BindingTuple} * @param state {@link AggregationState} @@ -95,14 +92,11 @@ public T accept(ExpressionNodeVisitor visitor, C context) { return visitor.visitAggregator(this, context); } - /** - * Util method to get value of condition in aggregation filter. - */ + /** Util method to get value of condition in aggregation filter. */ public boolean conditionValue(BindingTuple tuple) { if (condition == null) { return true; } return ExprValueUtils.getBooleanValue(condition.valueOf(tuple)); } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java index a24eeca1c1..4a1d4d309b 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.aggregation; import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; @@ -35,12 +34,11 @@ import org.opensearch.sql.expression.function.FunctionSignature; /** - * The definition of aggregator function - * avg, Accepts two numbers and produces a number. - * sum, Accepts two numbers and produces a number. - * max, Accepts two numbers and produces a number. - * min, Accepts two numbers and produces a number. - * count, Accepts two numbers and produces a number. + * The definition of aggregator functions avg, sum, min, max and + * count.
+ * All of them accept a list of numbers and produce a number. avg, min and + * max also accept datetime types.
+ * count accepts values of all types. */ @UtilityClass public class AggregatorFunction { @@ -67,26 +65,37 @@ private static DefaultFunctionResolver avg() { return new DefaultFunctionResolver( functionName, new ImmutableMap.Builder() - .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> new AvgAggregator(arguments, DOUBLE)) - .put(new FunctionSignature(functionName, Collections.singletonList(DATE)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DATE)), (functionProperties, arguments) -> new AvgAggregator(arguments, DATE)) - .put(new FunctionSignature(functionName, Collections.singletonList(DATETIME)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DATETIME)), (functionProperties, arguments) -> new AvgAggregator(arguments, DATETIME)) - .put(new FunctionSignature(functionName, Collections.singletonList(TIME)), + .put( + new FunctionSignature(functionName, Collections.singletonList(TIME)), (functionProperties, arguments) -> new AvgAggregator(arguments, TIME)) - .put(new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), + .put( + new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), (functionProperties, arguments) -> new AvgAggregator(arguments, TIMESTAMP)) - .build() - ); + .build()); } private static DefaultFunctionResolver count() { FunctionName functionName = BuiltinFunctionName.COUNT.getName(); - DefaultFunctionResolver functionResolver = new DefaultFunctionResolver(functionName, - ExprCoreType.coreTypes().stream().collect(Collectors.toMap( - type -> new FunctionSignature(functionName, Collections.singletonList(type)), - type -> (functionProperties, arguments) -> new CountAggregator(arguments, INTEGER)))); + DefaultFunctionResolver functionResolver = + new DefaultFunctionResolver( + functionName, + ExprCoreType.coreTypes().stream() + .collect( + Collectors.toMap( + type -> + new FunctionSignature(functionName, Collections.singletonList(type)), + type -> + (functionProperties, arguments) -> + new CountAggregator(arguments, INTEGER)))); return functionResolver; } @@ -95,16 +104,19 @@ private static DefaultFunctionResolver sum() { return new DefaultFunctionResolver( functionName, new ImmutableMap.Builder() - .put(new FunctionSignature(functionName, Collections.singletonList(INTEGER)), + .put( + new FunctionSignature(functionName, Collections.singletonList(INTEGER)), (functionProperties, arguments) -> new SumAggregator(arguments, INTEGER)) - .put(new FunctionSignature(functionName, Collections.singletonList(LONG)), + .put( + new FunctionSignature(functionName, Collections.singletonList(LONG)), (functionProperties, arguments) -> new SumAggregator(arguments, LONG)) - .put(new FunctionSignature(functionName, Collections.singletonList(FLOAT)), + .put( + new FunctionSignature(functionName, Collections.singletonList(FLOAT)), (functionProperties, arguments) -> new SumAggregator(arguments, FLOAT)) - .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> new SumAggregator(arguments, DOUBLE)) - .build() - ); + .build()); } private static DefaultFunctionResolver min() { @@ -112,23 +124,32 @@ private static DefaultFunctionResolver min() { return new DefaultFunctionResolver( functionName, new ImmutableMap.Builder() - .put(new FunctionSignature(functionName, Collections.singletonList(INTEGER)), + .put( + new FunctionSignature(functionName, Collections.singletonList(INTEGER)), (functionProperties, arguments) -> new MinAggregator(arguments, INTEGER)) - .put(new FunctionSignature(functionName, Collections.singletonList(LONG)), + .put( + new FunctionSignature(functionName, Collections.singletonList(LONG)), (functionProperties, arguments) -> new MinAggregator(arguments, LONG)) - .put(new FunctionSignature(functionName, Collections.singletonList(FLOAT)), + .put( + new FunctionSignature(functionName, Collections.singletonList(FLOAT)), (functionProperties, arguments) -> new MinAggregator(arguments, FLOAT)) - .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> new MinAggregator(arguments, DOUBLE)) - .put(new FunctionSignature(functionName, Collections.singletonList(STRING)), + .put( + new FunctionSignature(functionName, Collections.singletonList(STRING)), (functionProperties, arguments) -> new MinAggregator(arguments, STRING)) - .put(new FunctionSignature(functionName, Collections.singletonList(DATE)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DATE)), (functionProperties, arguments) -> new MinAggregator(arguments, DATE)) - .put(new FunctionSignature(functionName, Collections.singletonList(DATETIME)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DATETIME)), (functionProperties, arguments) -> new MinAggregator(arguments, DATETIME)) - .put(new FunctionSignature(functionName, Collections.singletonList(TIME)), + .put( + new FunctionSignature(functionName, Collections.singletonList(TIME)), (functionProperties, arguments) -> new MinAggregator(arguments, TIME)) - .put(new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), + .put( + new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), (functionProperties, arguments) -> new MinAggregator(arguments, TIMESTAMP)) .build()); } @@ -138,26 +159,34 @@ private static DefaultFunctionResolver max() { return new DefaultFunctionResolver( functionName, new ImmutableMap.Builder() - .put(new FunctionSignature(functionName, Collections.singletonList(INTEGER)), + .put( + new FunctionSignature(functionName, Collections.singletonList(INTEGER)), (functionProperties, arguments) -> new MaxAggregator(arguments, INTEGER)) - .put(new FunctionSignature(functionName, Collections.singletonList(LONG)), + .put( + new FunctionSignature(functionName, Collections.singletonList(LONG)), (functionProperties, arguments) -> new MaxAggregator(arguments, LONG)) - .put(new FunctionSignature(functionName, Collections.singletonList(FLOAT)), + .put( + new FunctionSignature(functionName, Collections.singletonList(FLOAT)), (functionProperties, arguments) -> new MaxAggregator(arguments, FLOAT)) - .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> new MaxAggregator(arguments, DOUBLE)) - .put(new FunctionSignature(functionName, Collections.singletonList(STRING)), + .put( + new FunctionSignature(functionName, Collections.singletonList(STRING)), (functionProperties, arguments) -> new MaxAggregator(arguments, STRING)) - .put(new FunctionSignature(functionName, Collections.singletonList(DATE)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DATE)), (functionProperties, arguments) -> new MaxAggregator(arguments, DATE)) - .put(new FunctionSignature(functionName, Collections.singletonList(DATETIME)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DATETIME)), (functionProperties, arguments) -> new MaxAggregator(arguments, DATETIME)) - .put(new FunctionSignature(functionName, Collections.singletonList(TIME)), + .put( + new FunctionSignature(functionName, Collections.singletonList(TIME)), (functionProperties, arguments) -> new MaxAggregator(arguments, TIME)) - .put(new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), + .put( + new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), (functionProperties, arguments) -> new MaxAggregator(arguments, TIMESTAMP)) - .build() - ); + .build()); } private static DefaultFunctionResolver varSamp() { @@ -165,10 +194,10 @@ private static DefaultFunctionResolver varSamp() { return new DefaultFunctionResolver( functionName, new ImmutableMap.Builder() - .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> varianceSample(arguments, DOUBLE)) - .build() - ); + .build()); } private static DefaultFunctionResolver varPop() { @@ -176,10 +205,10 @@ private static DefaultFunctionResolver varPop() { return new DefaultFunctionResolver( functionName, new ImmutableMap.Builder() - .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> variancePopulation(arguments, DOUBLE)) - .build() - ); + .build()); } private static DefaultFunctionResolver stddevSamp() { @@ -187,10 +216,10 @@ private static DefaultFunctionResolver stddevSamp() { return new DefaultFunctionResolver( functionName, new ImmutableMap.Builder() - .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> stddevSample(arguments, DOUBLE)) - .build() - ); + .build()); } private static DefaultFunctionResolver stddevPop() { @@ -198,20 +227,22 @@ private static DefaultFunctionResolver stddevPop() { return new DefaultFunctionResolver( functionName, new ImmutableMap.Builder() - .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + .put( + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> stddevPopulation(arguments, DOUBLE)) - .build() - ); + .build()); } private static DefaultFunctionResolver take() { FunctionName functionName = BuiltinFunctionName.TAKE.getName(); - DefaultFunctionResolver functionResolver = new DefaultFunctionResolver(functionName, - new ImmutableMap.Builder() - .put(new FunctionSignature(functionName, ImmutableList.of(STRING, INTEGER)), - (functionProperties, arguments) -> new TakeAggregator(arguments, ARRAY)) - .build()); + DefaultFunctionResolver functionResolver = + new DefaultFunctionResolver( + functionName, + new ImmutableMap.Builder() + .put( + new FunctionSignature(functionName, ImmutableList.of(STRING, INTEGER)), + (functionProperties, arguments) -> new TakeAggregator(arguments, ARRAY)) + .build()); return functionResolver; } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/AvgAggregator.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/AvgAggregator.java index a899a6b45b..c528968018 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/AvgAggregator.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/AvgAggregator.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.aggregation; import static java.time.temporal.ChronoUnit.MILLIS; @@ -27,14 +26,14 @@ import org.opensearch.sql.expression.function.BuiltinFunctionName; /** - * The average aggregator aggregate the value evaluated by the expression. - * If the expression evaluated result is NULL or MISSING, then the result is NULL. + * The average aggregator aggregate the value evaluated by the expression. If the expression + * evaluated result is NULL or MISSING, then the result is NULL. */ public class AvgAggregator extends Aggregator { /** - * To process by different ways different data types, we need to store the type. - * Input data has the same type as the result. + * To process by different ways different data types, we need to store the type. Input data has + * the same type as the result. */ private final ExprCoreType dataType; @@ -56,7 +55,7 @@ public AvgState create() { return new TimeAvgState(); case DOUBLE: return new DoubleAvgState(); - default: //unreachable code - we don't expose signatures for unsupported types + default: // unreachable code - we don't expose signatures for unsupported types throw new IllegalArgumentException( String.format("avg aggregation over %s type is not supported", dataType)); } @@ -72,9 +71,7 @@ public String toString() { return String.format(Locale.ROOT, "avg(%s)", format(getArguments())); } - /** - * Average State. - */ + /** Average State. */ protected abstract static class AvgState implements AggregationState { protected ExprValue count; protected ExprValue total; @@ -117,15 +114,16 @@ public ExprValue result() { } return new ExprDateValue( - new ExprTimestampValue(Instant.ofEpochMilli( - DSL.divide(DSL.literal(total), DSL.literal(count)).valueOf().longValue())) - .dateValue()); + new ExprTimestampValue( + Instant.ofEpochMilli( + DSL.divide(DSL.literal(total), DSL.literal(count)).valueOf().longValue())) + .dateValue()); } @Override protected AvgState iterate(ExprValue value) { - total = DSL.add(DSL.literal(total), DSL.literal(value.timestampValue().toEpochMilli())) - .valueOf(); + total = + DSL.add(DSL.literal(total), DSL.literal(value.timestampValue().toEpochMilli())).valueOf(); return super.iterate(value); } } @@ -138,15 +136,16 @@ public ExprValue result() { } return new ExprDatetimeValue( - new ExprTimestampValue(Instant.ofEpochMilli( - DSL.divide(DSL.literal(total), DSL.literal(count)).valueOf().longValue())) - .datetimeValue()); + new ExprTimestampValue( + Instant.ofEpochMilli( + DSL.divide(DSL.literal(total), DSL.literal(count)).valueOf().longValue())) + .datetimeValue()); } @Override protected AvgState iterate(ExprValue value) { - total = DSL.add(DSL.literal(total), DSL.literal(value.timestampValue().toEpochMilli())) - .valueOf(); + total = + DSL.add(DSL.literal(total), DSL.literal(value.timestampValue().toEpochMilli())).valueOf(); return super.iterate(value); } } @@ -158,14 +157,15 @@ public ExprValue result() { return ExprNullValue.of(); } - return new ExprTimestampValue(Instant.ofEpochMilli( - DSL.divide(DSL.literal(total), DSL.literal(count)).valueOf().longValue())); + return new ExprTimestampValue( + Instant.ofEpochMilli( + DSL.divide(DSL.literal(total), DSL.literal(count)).valueOf().longValue())); } @Override protected AvgState iterate(ExprValue value) { - total = DSL.add(DSL.literal(total), DSL.literal(value.timestampValue().toEpochMilli())) - .valueOf(); + total = + DSL.add(DSL.literal(total), DSL.literal(value.timestampValue().toEpochMilli())).valueOf(); return super.iterate(value); } } @@ -177,14 +177,16 @@ public ExprValue result() { return ExprNullValue.of(); } - return new ExprTimeValue(LocalTime.MIN.plus( - DSL.divide(DSL.literal(total), DSL.literal(count)).valueOf().longValue(), MILLIS)); + return new ExprTimeValue( + LocalTime.MIN.plus( + DSL.divide(DSL.literal(total), DSL.literal(count)).valueOf().longValue(), MILLIS)); } @Override protected AvgState iterate(ExprValue value) { - total = DSL.add(DSL.literal(total), - DSL.literal(MILLIS.between(LocalTime.MIN, value.timeValue()))).valueOf(); + total = + DSL.add(DSL.literal(total), DSL.literal(MILLIS.between(LocalTime.MIN, value.timeValue()))) + .valueOf(); return super.iterate(value); } } diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/CountAggregator.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/CountAggregator.java index 813842cadc..c4c02eb1d3 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/CountAggregator.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/CountAggregator.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.aggregation; import static org.opensearch.sql.utils.ExpressionUtils.format; @@ -43,9 +42,7 @@ public String toString() { : String.format(Locale.ROOT, "count(%s)", format(getArguments())); } - /** - * Count State. - */ + /** Count State. */ protected static class CountState implements AggregationState { protected int count; diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/MaxAggregator.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/MaxAggregator.java index e9123c0ac2..863d4603a7 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/MaxAggregator.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/MaxAggregator.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.aggregation; import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_NULL; @@ -45,9 +44,7 @@ protected static class MaxState implements AggregationState { } public void max(ExprValue value) { - maxResult = maxResult.isNull() ? value - : (maxResult.compareTo(value) > 0) - ? maxResult : value; + maxResult = maxResult.isNull() ? value : (maxResult.compareTo(value) > 0) ? maxResult : value; } @Override diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/MinAggregator.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/MinAggregator.java index 897fe857ff..c1b9ebcd4f 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/MinAggregator.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/MinAggregator.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.aggregation; import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_NULL; @@ -16,8 +15,8 @@ import org.opensearch.sql.expression.function.BuiltinFunctionName; /** - * The minimum aggregator aggregate the value evaluated by the expression. - * If the expression evaluated result is NULL or MISSING, then the result is NULL. + * The minimum aggregator aggregate the value evaluated by the expression. If the expression + * evaluated result is NULL or MISSING, then the result is NULL. */ public class MinAggregator extends Aggregator { @@ -25,7 +24,6 @@ public MinAggregator(List arguments, ExprCoreType returnType) { super(BuiltinFunctionName.MIN.getName(), arguments, returnType); } - @Override public MinState create() { return new MinState(); @@ -50,9 +48,7 @@ protected static class MinState implements AggregationState { } public void min(ExprValue value) { - minResult = minResult.isNull() ? value - : (minResult.compareTo(value) < 0) - ? minResult : value; + minResult = minResult.isNull() ? value : (minResult.compareTo(value) < 0) ? minResult : value; } @Override diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/NamedAggregator.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/NamedAggregator.java index 510c5d1e45..fa84b74ba5 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/NamedAggregator.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/NamedAggregator.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.aggregation; import lombok.EqualsAndHashCode; @@ -12,35 +11,27 @@ import org.opensearch.sql.expression.ExpressionNodeVisitor; /** - * NamedAggregator expression that represents expression with name. - * Please see more details in associated unresolved expression operator + * NamedAggregator expression that represents expression with name. Please see more details in + * associated unresolved expression operator
* {@link org.opensearch.sql.ast.expression.Alias}. */ @EqualsAndHashCode(callSuper = false) public class NamedAggregator extends Aggregator { - /** - * Aggregator name. - */ + /** Aggregator name. */ private final String name; - /** - * Aggregator that being named. - */ - @Getter - private final Aggregator delegated; + /** Aggregator that being named. */ + @Getter private final Aggregator delegated; /** - * NamedAggregator. - * The aggregator properties {@link #condition} and {@link #distinct} - * are inherited by named aggregator to avoid errors introduced by the property inconsistency. + * NamedAggregator. The aggregator properties {@link #condition} and {@link #distinct} are + * inherited by named aggregator to avoid errors introduced by the property inconsistency. * * @param name name * @param delegated delegated */ - public NamedAggregator( - String name, - Aggregator delegated) { + public NamedAggregator(String name, Aggregator delegated) { super(delegated.getFunctionName(), delegated.getArguments(), delegated.returnType); this.name = name; this.delegated = delegated; @@ -60,7 +51,8 @@ protected AggregationState iterate(ExprValue value, AggregationState state) { /** * Get expression name using name or its alias (if it's present). - * @return expression name + * + * @return expression name */ public String getName() { return name; @@ -75,5 +67,4 @@ public T accept(ExpressionNodeVisitor visitor, C context) { public String toString() { return getName(); } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/StdDevAggregator.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/StdDevAggregator.java index 0cd8494449..d5422bc788 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/StdDevAggregator.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/StdDevAggregator.java @@ -26,26 +26,18 @@ import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.function.BuiltinFunctionName; -/** - * StandardDeviation Aggregator. - */ +/** StandardDeviation Aggregator. */ public class StdDevAggregator extends Aggregator { private final boolean isSampleStdDev; - /** - * Build Population Variance {@link VarianceAggregator}. - */ - public static Aggregator stddevPopulation(List arguments, - ExprCoreType returnType) { + /** Build Population Variance {@link VarianceAggregator}. */ + public static Aggregator stddevPopulation(List arguments, ExprCoreType returnType) { return new StdDevAggregator(false, arguments, returnType); } - /** - * Build Sample Variance {@link VarianceAggregator}. - */ - public static Aggregator stddevSample(List arguments, - ExprCoreType returnType) { + /** Build Sample Variance {@link VarianceAggregator}. */ + public static Aggregator stddevSample(List arguments, ExprCoreType returnType) { return new StdDevAggregator(true, arguments, returnType); } @@ -53,7 +45,7 @@ public static Aggregator stddevSample(List arguments, * VarianceAggregator constructor. * * @param isSampleStdDev true for sample standard deviation aggregator, false for population - * standard deviation aggregator. + * standard deviation aggregator. * @param arguments aggregator arguments. * @param returnType aggregator return types. */ @@ -74,8 +66,8 @@ public StdDevAggregator.StdDevState create() { } @Override - protected StdDevAggregator.StdDevState iterate(ExprValue value, - StdDevAggregator.StdDevState state) { + protected StdDevAggregator.StdDevState iterate( + ExprValue value, StdDevAggregator.StdDevState state) { state.evaluate(value); return state; } diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/SumAggregator.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/SumAggregator.java index f5b042034a..d637721980 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/SumAggregator.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/SumAggregator.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.aggregation; import static org.opensearch.sql.data.model.ExprValueUtils.doubleValue; @@ -28,8 +27,8 @@ import org.opensearch.sql.expression.function.BuiltinFunctionName; /** - * The sum aggregator aggregate the value evaluated by the expression. - * If the expression evaluated result is NULL or MISSING, then the result is NULL. + * The sum aggregator aggregate the value evaluated by the expression. If the expression evaluated + * result is NULL or MISSING, then the result is NULL. */ public class SumAggregator extends Aggregator { @@ -54,9 +53,7 @@ public String toString() { return String.format(Locale.ROOT, "sum(%s)", format(getArguments())); } - /** - * Sum State. - */ + /** Sum State. */ protected static class SumState implements AggregationState { private final ExprCoreType type; @@ -69,9 +66,7 @@ protected static class SumState implements AggregationState { isEmptyCollection = true; } - /** - * Add value to current sumResult. - */ + /** Add value to current sumResult. */ public void add(ExprValue value) { switch (type) { case INTEGER: diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/TakeAggregator.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/TakeAggregator.java index cff08bb098..8791973353 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/TakeAggregator.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/TakeAggregator.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.aggregation; import static org.opensearch.sql.utils.ExpressionUtils.format; @@ -18,8 +17,8 @@ import org.opensearch.sql.expression.function.BuiltinFunctionName; /** - * The take aggregator keeps and returns the original values of a field. - * If the field value is NULL or MISSING, then it is skipped. + * The take aggregator keeps and returns the original values of a field. If the field value is NULL + * or MISSING, then it is skipped. */ public class TakeAggregator extends Aggregator { @@ -43,9 +42,7 @@ public String toString() { return String.format(Locale.ROOT, "take(%s)", format(getArguments())); } - /** - * Take State. - */ + /** Take State. */ protected static class TakeState implements AggregationState { protected int index; protected int size; diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/VarianceAggregator.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/VarianceAggregator.java index bd9f0948f6..920830d266 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/VarianceAggregator.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/VarianceAggregator.java @@ -26,26 +26,18 @@ import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.function.BuiltinFunctionName; -/** - * Variance Aggregator. - */ +/** Variance Aggregator. */ public class VarianceAggregator extends Aggregator { private final boolean isSampleVariance; - /** - * Build Population Variance {@link VarianceAggregator}. - */ - public static Aggregator variancePopulation(List arguments, - ExprCoreType returnType) { + /** Build Population Variance {@link VarianceAggregator}. */ + public static Aggregator variancePopulation(List arguments, ExprCoreType returnType) { return new VarianceAggregator(false, arguments, returnType); } - /** - * Build Sample Variance {@link VarianceAggregator}. - */ - public static Aggregator varianceSample(List arguments, - ExprCoreType returnType) { + /** Build Sample Variance {@link VarianceAggregator}. */ + public static Aggregator varianceSample(List arguments, ExprCoreType returnType) { return new VarianceAggregator(true, arguments, returnType); } diff --git a/core/src/main/java/org/opensearch/sql/expression/conditional/cases/CaseClause.java b/core/src/main/java/org/opensearch/sql/expression/conditional/cases/CaseClause.java index ad7860a6dc..e18f33c6ae 100644 --- a/core/src/main/java/org/opensearch/sql/expression/conditional/cases/CaseClause.java +++ b/core/src/main/java/org/opensearch/sql/expression/conditional/cases/CaseClause.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.conditional.cases; import static org.opensearch.sql.data.type.ExprCoreType.UNDEFINED; @@ -32,19 +31,13 @@ @ToString public class CaseClause extends FunctionExpression { - /** - * List of WHEN clauses. - */ + /** List of WHEN clauses. */ private final List whenClauses; - /** - * Default result if none of WHEN conditions match. - */ + /** Default result if none of WHEN conditions match. */ private final Expression defaultResult; - /** - * Initialize case clause. - */ + /** Initialize case clause. */ public CaseClause(List whenClauses, Expression defaultResult) { super(FunctionName.of("case"), concatArgs(whenClauses, defaultResult)); this.whenClauses = whenClauses; @@ -75,15 +68,13 @@ public T accept(ExpressionNodeVisitor visitor, C context) { } /** - * Get types of each result in WHEN clause and ELSE clause. - * Exclude UNKNOWN type from NULL literal which means NULL in THEN or ELSE clause - * is not included in result. + * Get types of each result in WHEN clause and ELSE clause. Exclude UNKNOWN type from NULL literal + * which means NULL in THEN or ELSE clause is not included in result. + * * @return all result types. Use list so caller can generate friendly error message. */ public List allResultTypes() { - List types = whenClauses.stream() - .map(WhenClause::type) - .collect(Collectors.toList()); + List types = whenClauses.stream().map(WhenClause::type).collect(Collectors.toList()); if (defaultResult != null) { types.add(defaultResult.type()); } @@ -92,8 +83,8 @@ public List allResultTypes() { return types; } - private static List concatArgs(List whenClauses, - Expression defaultResult) { + private static List concatArgs( + List whenClauses, Expression defaultResult) { ImmutableList.Builder args = ImmutableList.builder(); whenClauses.forEach(args::add); @@ -102,5 +93,4 @@ private static List concatArgs(List whenClauses, } return args.build(); } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/conditional/cases/WhenClause.java b/core/src/main/java/org/opensearch/sql/expression/conditional/cases/WhenClause.java index fd2eeab983..7eb731a1f2 100644 --- a/core/src/main/java/org/opensearch/sql/expression/conditional/cases/WhenClause.java +++ b/core/src/main/java/org/opensearch/sql/expression/conditional/cases/WhenClause.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.conditional.cases; import com.google.common.collect.ImmutableList; @@ -18,27 +17,19 @@ import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.FunctionName; -/** - * WHEN clause that consists of a condition and a result corresponding. - */ +/** WHEN clause that consists of a condition and a result corresponding. */ @EqualsAndHashCode(callSuper = false) @Getter @ToString public class WhenClause extends FunctionExpression { - /** - * Condition that must be a predicate. - */ + /** Condition that must be a predicate. */ private final Expression condition; - /** - * Result to return if condition is evaluated to true. - */ + /** Result to return if condition is evaluated to true. */ private final Expression result; - /** - * Initialize when clause. - */ + /** Initialize when clause. */ public WhenClause(Expression condition, Expression result) { super(FunctionName.of("when"), ImmutableList.of(condition, result)); this.condition = condition; @@ -47,8 +38,9 @@ public WhenClause(Expression condition, Expression result) { /** * Evaluate when condition. - * @param valueEnv value env - * @return is condition satisfied + * + * @param valueEnv value env + * @return is condition satisfied */ public boolean isTrue(Environment valueEnv) { ExprValue result = condition.valueOf(valueEnv); @@ -72,5 +64,4 @@ public ExprType type() { public T accept(ExpressionNodeVisitor visitor, C context) { return visitor.visitWhen(this, context); } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/CalendarLookup.java b/core/src/main/java/org/opensearch/sql/expression/datetime/CalendarLookup.java index c5b6343991..0837075f7c 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/CalendarLookup.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/CalendarLookup.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.datetime; import com.google.common.collect.ImmutableList; @@ -18,6 +17,7 @@ class CalendarLookup { /** * Get a calendar for the specific mode. + * * @param mode Mode to get calendar for. * @param date Date to get calendar for. */ @@ -38,6 +38,7 @@ private static Calendar getCalendar(int mode, LocalDate date) { /** * Set first day of week, minimal days in first week and date in calendar. + * * @param firstDayOfWeek the given first day of the week. * @param minimalDaysInWeek the given minimal days required in the first week of the year. * @param date the given date. @@ -52,6 +53,7 @@ private static Calendar getCalendar(int firstDayOfWeek, int minimalDaysInWeek, L /** * Returns week number for date according to mode. + * * @param mode Integer for mode. Valid mode values are 0 to 7. * @param date LocalDate for date. */ @@ -68,6 +70,7 @@ static int getWeekNumber(int mode, LocalDate date) { /** * Returns year for date according to mode. + * * @param mode Integer for mode. Valid mode values are 0 to 7. * @param date LocalDate for date. */ diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java index 55bfa67f3f..13f9a077e4 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java @@ -28,8 +28,8 @@ import org.opensearch.sql.expression.function.FunctionProperties; /** - * This class converts a SQL style DATE_FORMAT format specifier and converts it to a - * Java SimpleDateTime format. + * This class converts a SQL style DATE_FORMAT format specifier and converts it to a Java + * SimpleDateTime format. */ class DateTimeFormatterUtil { private static final int SUFFIX_SPECIAL_START_TH = 11; @@ -39,8 +39,7 @@ class DateTimeFormatterUtil { private static final String NANO_SEC_FORMAT = "'%06d'"; private static final Map SUFFIX_CONVERTER = - ImmutableMap.builder() - .put(1, "st").put(2, "nd").put(3, "rd").build(); + ImmutableMap.builder().put(1, "st").put(2, "nd").put(3, "rd").build(); // The following have special cases that need handling outside of the format options provided // by the DateTimeFormatter class. @@ -50,52 +49,70 @@ interface DateTimeFormatHandler { private static final Map DATE_HANDLERS = ImmutableMap.builder() - .put("%a", (date) -> "EEE") // %a => EEE - Abbreviated weekday name (Sun..Sat) - .put("%b", (date) -> "LLL") // %b => LLL - Abbreviated month name (Jan..Dec) - .put("%c", (date) -> "MM") // %c => MM - Month, numeric (0..12) - .put("%d", (date) -> "dd") // %d => dd - Day of the month, numeric (00..31) - .put("%e", (date) -> "d") // %e => d - Day of the month, numeric (0..31) - .put("%H", (date) -> "HH") // %H => HH - (00..23) - .put("%h", (date) -> "hh") // %h => hh - (01..12) - .put("%I", (date) -> "hh") // %I => hh - (01..12) - .put("%i", (date) -> "mm") // %i => mm - Minutes, numeric (00..59) - .put("%j", (date) -> "DDD") // %j => DDD - (001..366) - .put("%k", (date) -> "H") // %k => H - (0..23) - .put("%l", (date) -> "h") // %l => h - (1..12) - .put("%p", (date) -> "a") // %p => a - AM or PM - .put("%M", (date) -> "LLLL") // %M => LLLL - Month name (January..December) - .put("%m", (date) -> "MM") // %m => MM - Month, numeric (00..12) - .put("%r", (date) -> "hh:mm:ss a") // %r => hh:mm:ss a - hh:mm:ss followed by AM or PM - .put("%S", (date) -> "ss") // %S => ss - Seconds (00..59) - .put("%s", (date) -> "ss") // %s => ss - Seconds (00..59) - .put("%T", (date) -> "HH:mm:ss") // %T => HH:mm:ss - .put("%W", (date) -> "EEEE") // %W => EEEE - Weekday name (Sunday..Saturday) - .put("%Y", (date) -> "yyyy") // %Y => yyyy - Year, numeric, 4 digits - .put("%y", (date) -> "yy") // %y => yy - Year, numeric, 2 digits - // The following are not directly supported by DateTimeFormatter. - .put("%D", (date) -> // %w - Day of month with English suffix - String.format("'%d%s'", date.getDayOfMonth(), getSuffix(date.getDayOfMonth()))) - .put("%f", (date) -> // %f - Microseconds - String.format(NANO_SEC_FORMAT, (date.getNano() / 1000))) - .put("%w", (date) -> // %w - Day of week (0 indexed) - String.format("'%d'", date.getDayOfWeek().getValue())) - .put("%U", (date) -> // %U Week where Sunday is the first day - WEEK() mode 0 - String.format("'%d'", CalendarLookup.getWeekNumber(0, date.toLocalDate()))) - .put("%u", (date) -> // %u Week where Monday is the first day - WEEK() mode 1 - String.format("'%d'", CalendarLookup.getWeekNumber(1, date.toLocalDate()))) - .put("%V", (date) -> // %V Week where Sunday is the first day - WEEK() mode 2 used with %X - String.format("'%d'", CalendarLookup.getWeekNumber(2, date.toLocalDate()))) - .put("%v", (date) -> // %v Week where Monday is the first day - WEEK() mode 3 used with %x - String.format("'%d'", CalendarLookup.getWeekNumber(3, date.toLocalDate()))) - .put("%X", (date) -> // %X Year for week where Sunday is the first day, 4 digits used with %V - String.format("'%d'", CalendarLookup.getYearNumber(2, date.toLocalDate()))) - .put("%x", (date) -> // %x Year for week where Monday is the first day, 4 digits used with %v - String.format("'%d'", CalendarLookup.getYearNumber(3, date.toLocalDate()))) - .build(); - - //Handlers for the time_format function. - //Some format specifiers return 0 or null to align with MySQL. - //https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_time-format + .put("%a", (date) -> "EEE") // %a => EEE - Abbreviated weekday name (Sun..Sat) + .put("%b", (date) -> "LLL") // %b => LLL - Abbreviated month name (Jan..Dec) + .put("%c", (date) -> "MM") // %c => MM - Month, numeric (0..12) + .put("%d", (date) -> "dd") // %d => dd - Day of the month, numeric (00..31) + .put("%e", (date) -> "d") // %e => d - Day of the month, numeric (0..31) + .put("%H", (date) -> "HH") // %H => HH - (00..23) + .put("%h", (date) -> "hh") // %h => hh - (01..12) + .put("%I", (date) -> "hh") // %I => hh - (01..12) + .put("%i", (date) -> "mm") // %i => mm - Minutes, numeric (00..59) + .put("%j", (date) -> "DDD") // %j => DDD - (001..366) + .put("%k", (date) -> "H") // %k => H - (0..23) + .put("%l", (date) -> "h") // %l => h - (1..12) + .put("%p", (date) -> "a") // %p => a - AM or PM + .put("%M", (date) -> "LLLL") // %M => LLLL - Month name (January..December) + .put("%m", (date) -> "MM") // %m => MM - Month, numeric (00..12) + .put("%r", (date) -> "hh:mm:ss a") // %r => hh:mm:ss a - hh:mm:ss followed by AM or PM + .put("%S", (date) -> "ss") // %S => ss - Seconds (00..59) + .put("%s", (date) -> "ss") // %s => ss - Seconds (00..59) + .put("%T", (date) -> "HH:mm:ss") // %T => HH:mm:ss + .put("%W", (date) -> "EEEE") // %W => EEEE - Weekday name (Sunday..Saturday) + .put("%Y", (date) -> "yyyy") // %Y => yyyy - Year, numeric, 4 digits + .put("%y", (date) -> "yy") // %y => yy - Year, numeric, 2 digits + // The following are not directly supported by DateTimeFormatter. + .put( + "%D", + (date) -> // %w - Day of month with English suffix + String.format("'%d%s'", date.getDayOfMonth(), getSuffix(date.getDayOfMonth()))) + .put( + "%f", + (date) -> // %f - Microseconds + String.format(NANO_SEC_FORMAT, (date.getNano() / 1000))) + .put( + "%w", + (date) -> // %w - Day of week (0 indexed) + String.format("'%d'", date.getDayOfWeek().getValue())) + .put( + "%U", + (date) -> // %U Week where Sunday is the first day - WEEK() mode 0 + String.format("'%d'", CalendarLookup.getWeekNumber(0, date.toLocalDate()))) + .put( + "%u", + (date) -> // %u Week where Monday is the first day - WEEK() mode 1 + String.format("'%d'", CalendarLookup.getWeekNumber(1, date.toLocalDate()))) + .put( + "%V", + (date) -> // %V Week where Sunday is the first day - WEEK() mode 2 used with %X + String.format("'%d'", CalendarLookup.getWeekNumber(2, date.toLocalDate()))) + .put( + "%v", + (date) -> // %v Week where Monday is the first day - WEEK() mode 3 used with %x + String.format("'%d'", CalendarLookup.getWeekNumber(3, date.toLocalDate()))) + .put( + "%X", + (date) -> // %X Year for week where Sunday is the first day, 4 digits used with %V + String.format("'%d'", CalendarLookup.getYearNumber(2, date.toLocalDate()))) + .put( + "%x", + (date) -> // %x Year for week where Monday is the first day, 4 digits used with %v + String.format("'%d'", CalendarLookup.getYearNumber(3, date.toLocalDate()))) + .build(); + + // Handlers for the time_format function. + // Some format specifiers return 0 or null to align with MySQL. + // https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_time-format private static final Map TIME_HANDLERS = ImmutableMap.builder() .put("%a", (date) -> null) @@ -121,8 +138,8 @@ interface DateTimeFormatHandler { .put("%Y", (date) -> "0000") .put("%y", (date) -> "00") .put("%D", (date) -> null) - .put("%f", (date) -> // %f - Microseconds - String.format(NANO_SEC_FORMAT, (date.getNano() / 1000))) + // %f - Microseconds + .put("%f", (date) -> String.format(NANO_SEC_FORMAT, (date.getNano() / 1000))) .put("%w", (date) -> null) .put("%U", (date) -> null) .put("%u", (date) -> null) @@ -157,7 +174,7 @@ interface DateTimeFormatHandler { .put("%Y", "u") // %Y => yyyy - Year, numeric, 4 digits .put("%y", "u") // %y => yy - Year, numeric, 2 digits .put("%f", "n") // %f => n - Nanoseconds - //The following have been implemented but cannot be aligned with + // The following have been implemented but cannot be aligned with // MySQL due to the limitations of the DatetimeFormatter .put("%D", "d") // %w - Day of month with English suffix .put("%w", "e") // %w - Day of week (0 indexed) @@ -170,20 +187,19 @@ interface DateTimeFormatHandler { .build(); private static final Pattern pattern = Pattern.compile("%."); - private static final Pattern CHARACTERS_WITH_NO_MOD_LITERAL_BEHIND_PATTERN - = Pattern.compile("(? handler, - LocalDateTime datetime) { + static ExprValue getFormattedString( + ExprValue formatExpr, Map handler, LocalDateTime datetime) { StringBuffer cleanFormat = getCleanFormat(formatExpr); final Matcher matcher = pattern.matcher(cleanFormat.toString()); final StringBuffer format = new StringBuffer(); try { while (matcher.find()) { - matcher.appendReplacement(format, - handler.getOrDefault(matcher.group(), (d) -> - String.format("'%s'", matcher.group().replaceFirst(MOD_LITERAL, ""))) + matcher.appendReplacement( + format, + handler + .getOrDefault( + matcher.group(), + (d) -> String.format("'%s'", matcher.group().replaceFirst(MOD_LITERAL, ""))) .getFormat(datetime)); } } catch (Exception e) { @@ -219,12 +238,13 @@ static ExprValue getFormattedString(ExprValue formatExpr, // English Locale matches SQL requirements. // 'AM'/'PM' instead of 'a.m.'/'p.m.' // 'Sat' instead of 'Sat.' etc - return new ExprStringValue(datetime.format( - DateTimeFormatter.ofPattern(format.toString(), Locale.ENGLISH))); + return new ExprStringValue( + datetime.format(DateTimeFormatter.ofPattern(format.toString(), Locale.ENGLISH))); } /** * Format the date using the date format String. + * * @param dateExpr the date ExprValue of Date/Datetime/Timestamp/String type. * @param formatExpr the format ExprValue of String type. * @return Date formatted using format and returned as a String. @@ -242,13 +262,14 @@ static ExprValue getFormattedDateOfToday(ExprValue formatExpr, ExprValue time, C /** * Format the date using the date format String. + * * @param timeExpr the date ExprValue of Date/Datetime/Timestamp/String type. * @param formatExpr the format ExprValue of String type. * @return Date formatted using format and returned as a String. */ static ExprValue getFormattedTime(ExprValue timeExpr, ExprValue formatExpr) { - //Initializes DateTime with LocalDate.now(). This is safe because the date is ignored. - //The time_format function will only return 0 or null for invalid string format specifiers. + // Initializes DateTime with LocalDate.now(). This is safe because the date is ignored. + // The time_format function will only return 0 or null for invalid string format specifiers. final LocalDateTime time = LocalDateTime.of(LocalDate.now(), timeExpr.timeValue()); return getFormattedString(formatExpr, TIME_HANDLERS, time); @@ -266,30 +287,33 @@ private static boolean canGetTime(TemporalAccessor ta) { && ta.isSupported(ChronoField.SECOND_OF_MINUTE)); } - static ExprValue parseStringWithDateOrTime(FunctionProperties fp, - ExprValue datetimeStringExpr, - ExprValue formatExpr) { + static ExprValue parseStringWithDateOrTime( + FunctionProperties fp, ExprValue datetimeStringExpr, ExprValue formatExpr) { - //Replace patterns with % for Java DateTimeFormatter + // Replace patterns with % for Java DateTimeFormatter StringBuffer cleanFormat = getCleanFormat(formatExpr); final Matcher matcher = pattern.matcher(cleanFormat.toString()); final StringBuffer format = new StringBuffer(); while (matcher.find()) { - matcher.appendReplacement(format, - STR_TO_DATE_FORMATS.getOrDefault(matcher.group(), + matcher.appendReplacement( + format, + STR_TO_DATE_FORMATS.getOrDefault( + matcher.group(), String.format("'%s'", matcher.group().replaceFirst(MOD_LITERAL, "")))); } matcher.appendTail(format); TemporalAccessor taWithMissingFields; - //Return NULL for invalid parse in string to align with MySQL + // Return NULL for invalid parse in string to align with MySQL try { - //Get Temporal Accessor to initially parse string without default values - taWithMissingFields = new DateTimeFormatterBuilder() - .appendPattern(format.toString()) - .toFormatter().withResolverStyle(ResolverStyle.STRICT) - .parseUnresolved(datetimeStringExpr.stringValue(), new ParsePosition(0)); + // Get Temporal Accessor to initially parse string without default values + taWithMissingFields = + new DateTimeFormatterBuilder() + .appendPattern(format.toString()) + .toFormatter() + .withResolverStyle(ResolverStyle.STRICT) + .parseUnresolved(datetimeStringExpr.stringValue(), new ParsePosition(0)); if (taWithMissingFields == null) { throw new DateTimeException("Input string could not be parsed properly."); } @@ -300,31 +324,42 @@ static ExprValue parseStringWithDateOrTime(FunctionProperties fp, return ExprNullValue.of(); } - int year = taWithMissingFields.isSupported(ChronoField.YEAR) - ? taWithMissingFields.get(ChronoField.YEAR) : 2000; - - int month = taWithMissingFields.isSupported(ChronoField.MONTH_OF_YEAR) - ? taWithMissingFields.get(ChronoField.MONTH_OF_YEAR) : 1; - - int day = taWithMissingFields.isSupported(ChronoField.DAY_OF_MONTH) - ? taWithMissingFields.get(ChronoField.DAY_OF_MONTH) : 1; - - int hour = taWithMissingFields.isSupported(ChronoField.HOUR_OF_DAY) - ? taWithMissingFields.get(ChronoField.HOUR_OF_DAY) : 0; - - int minute = taWithMissingFields.isSupported(ChronoField.MINUTE_OF_HOUR) - ? taWithMissingFields.get(ChronoField.MINUTE_OF_HOUR) : 0; - - int second = taWithMissingFields.isSupported(ChronoField.SECOND_OF_MINUTE) - ? taWithMissingFields.get(ChronoField.SECOND_OF_MINUTE) : 0; - - //Fill returned datetime with current date if only Time information was parsed + int year = + taWithMissingFields.isSupported(ChronoField.YEAR) + ? taWithMissingFields.get(ChronoField.YEAR) + : 2000; + + int month = + taWithMissingFields.isSupported(ChronoField.MONTH_OF_YEAR) + ? taWithMissingFields.get(ChronoField.MONTH_OF_YEAR) + : 1; + + int day = + taWithMissingFields.isSupported(ChronoField.DAY_OF_MONTH) + ? taWithMissingFields.get(ChronoField.DAY_OF_MONTH) + : 1; + + int hour = + taWithMissingFields.isSupported(ChronoField.HOUR_OF_DAY) + ? taWithMissingFields.get(ChronoField.HOUR_OF_DAY) + : 0; + + int minute = + taWithMissingFields.isSupported(ChronoField.MINUTE_OF_HOUR) + ? taWithMissingFields.get(ChronoField.MINUTE_OF_HOUR) + : 0; + + int second = + taWithMissingFields.isSupported(ChronoField.SECOND_OF_MINUTE) + ? taWithMissingFields.get(ChronoField.SECOND_OF_MINUTE) + : 0; + + // Fill returned datetime with current date if only Time information was parsed LocalDateTime output; if (!canGetDate(taWithMissingFields)) { - output = LocalDateTime.of( - LocalDate.now(fp.getQueryStartClock()), - LocalTime.of(hour, minute, second) - ); + output = + LocalDateTime.of( + LocalDate.now(fp.getQueryStartClock()), LocalTime.of(hour, minute, second)); } else { output = LocalDateTime.of(year, month, day, hour, minute, second); } @@ -334,6 +369,7 @@ static ExprValue parseStringWithDateOrTime(FunctionProperties fp, /** * Returns English suffix of incoming value. + * * @param val Incoming value. * @return English suffix as String (st, nd, rd, th) */ diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java index 0ea1d02eaf..d17d59d358 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java @@ -3,10 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.datetime; - import static java.time.temporal.ChronoUnit.DAYS; import static java.time.temporal.ChronoUnit.HOURS; import static java.time.temporal.ChronoUnit.MICROS; @@ -100,14 +98,13 @@ import org.opensearch.sql.utils.DateTimeUtils; /** - * The definition of date and time functions. - * 1) have the clear interface for function define. - * 2) the implementation should rely on ExprValue. + * The definition of date and time functions. 1) have the clear interface for function define. 2) + * the implementation should rely on ExprValue. */ @UtilityClass @SuppressWarnings("unchecked") public class DateTimeFunction { - //The number of seconds per day + // The number of seconds per day public static final long SECONDS_PER_DAY = 86400; // The number of days from year zero to year 1970. @@ -254,11 +251,12 @@ public void register(BuiltinFunctionRepository repository) { * `now(y) return different values. */ private FunctionResolver now(FunctionName functionName) { - return define(functionName, + return define( + functionName, implWithProperties( - functionProperties -> new ExprDatetimeValue( - formatNow(functionProperties.getQueryStartClock())), DATETIME) - ); + functionProperties -> + new ExprDatetimeValue(formatNow(functionProperties.getQueryStartClock())), + DATETIME)); } private FunctionResolver now() { @@ -277,25 +275,28 @@ private FunctionResolver localtime() { return now(BuiltinFunctionName.LOCALTIME.getName()); } - /** - * SYSDATE() returns the time at which it executes. - */ + /** SYSDATE() returns the time at which it executes. */ private FunctionResolver sysdate() { - return define(BuiltinFunctionName.SYSDATE.getName(), - implWithProperties(functionProperties - -> new ExprDatetimeValue(formatNow(Clock.systemDefaultZone())), DATETIME), - FunctionDSL.implWithProperties((functionProperties, v) -> new ExprDatetimeValue( - formatNow(Clock.systemDefaultZone(), v.integerValue())), DATETIME, INTEGER) - ); + return define( + BuiltinFunctionName.SYSDATE.getName(), + implWithProperties( + functionProperties -> new ExprDatetimeValue(formatNow(Clock.systemDefaultZone())), + DATETIME), + FunctionDSL.implWithProperties( + (functionProperties, v) -> + new ExprDatetimeValue(formatNow(Clock.systemDefaultZone(), v.integerValue())), + DATETIME, + INTEGER)); } - /** - * Synonym for @see `now`. - */ + /** Synonym for @see `now`. */ private FunctionResolver curtime(FunctionName functionName) { - return define(functionName, - implWithProperties(functionProperties -> new ExprTimeValue( - formatNow(functionProperties.getQueryStartClock()).toLocalTime()), TIME)); + return define( + functionName, + implWithProperties( + functionProperties -> + new ExprTimeValue(formatNow(functionProperties.getQueryStartClock()).toLocalTime()), + TIME)); } private FunctionResolver curtime() { @@ -307,9 +308,12 @@ private FunctionResolver current_time() { } private FunctionResolver curdate(FunctionName functionName) { - return define(functionName, - implWithProperties(functionProperties -> new ExprDateValue( - formatNow(functionProperties.getQueryStartClock()).toLocalDate()), DATE)); + return define( + functionName, + implWithProperties( + functionProperties -> + new ExprDateValue(formatNow(functionProperties.getQueryStartClock()).toLocalDate()), + DATE)); } private FunctionResolver curdate() { @@ -321,32 +325,32 @@ private FunctionResolver current_date() { } /** - * A common signature for `date_add` and `date_sub`. - * Specify a start date and add/subtract a temporal amount to/from the date. + * A common signature for `date_add` and `date_sub`.
+ * Specify a start date and add/subtract a temporal amount to/from the date.
* The return type depends on the date type and the interval unit. Detailed supported signatures: - * (DATE/DATETIME/TIMESTAMP/TIME, INTERVAL) -> DATETIME - * MySQL has these signatures too - * (DATE, INTERVAL) -> DATE // when interval has no time part - * (TIME, INTERVAL) -> TIME // when interval has no date part - * (STRING, INTERVAL) -> STRING // when argument has date or datetime string, - * // result has date or datetime depending on interval type + *
+ * (DATE/DATETIME/TIMESTAMP/TIME, INTERVAL) -> DATETIME
+ * MySQL has these signatures too
+ * (DATE, INTERVAL) -> DATE // when interval has no time part
+ * (TIME, INTERVAL) -> TIME // when interval has no date part
+ * (STRING, INTERVAL) -> STRING // when argument has date or datetime string,
+ * // result has date or datetime depending on interval type
*/ private Stream> get_date_add_date_sub_signatures( SerializableTriFunction function) { return Stream.of( implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, DATE, INTERVAL), - implWithProperties(nullMissingHandlingWithProperties(function), - DATETIME, DATETIME, INTERVAL), - implWithProperties(nullMissingHandlingWithProperties(function), - DATETIME, TIMESTAMP, INTERVAL), - implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, TIME, INTERVAL) - ); + implWithProperties( + nullMissingHandlingWithProperties(function), DATETIME, DATETIME, INTERVAL), + implWithProperties( + nullMissingHandlingWithProperties(function), DATETIME, TIMESTAMP, INTERVAL), + implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, TIME, INTERVAL)); } /** - * A common signature for `adddate` and `subdate`. - * Adds/subtracts an integer number of days to/from the first argument. - * (DATE, LONG) -> DATE + * A common signature for `adddate` and `subdate`.
+ * Adds/subtracts an integer number of days to/from the first argument.
+ * (DATE, LONG) -> DATE
* (TIME/DATETIME/TIMESTAMP, LONG) -> DATETIME */ private Stream> get_adddate_subdate_signatures( @@ -355,87 +359,128 @@ private FunctionResolver current_date() { implWithProperties(nullMissingHandlingWithProperties(function), DATE, DATE, LONG), implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, DATETIME, LONG), implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, TIMESTAMP, LONG), - implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, TIME, LONG) - ); + implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, TIME, LONG)); } private DefaultFunctionResolver adddate() { - return define(BuiltinFunctionName.ADDDATE.getName(), + return define( + BuiltinFunctionName.ADDDATE.getName(), (SerializableFunction>[]) (Stream.concat( - get_date_add_date_sub_signatures(DateTimeFunction::exprAddDateInterval), - get_adddate_subdate_signatures(DateTimeFunction::exprAddDateDays)) + get_date_add_date_sub_signatures(DateTimeFunction::exprAddDateInterval), + get_adddate_subdate_signatures(DateTimeFunction::exprAddDateDays)) .toArray(SerializableFunction[]::new))); } /** - * Adds expr2 to expr1 and returns the result. - * (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME - * (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME - * TODO: MySQL has these signatures too - * (STRING, STRING/TIME) -> STRING // second arg - string with time only - * (x, STRING) -> NULL // second arg - string with timestamp - * (x, STRING/DATE) -> x // second arg - string with date only + * Adds expr2 to expr1 and returns the result.
+ * (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME
+ * (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME
+ * TODO: MySQL has these signatures too
+ * (STRING, STRING/TIME) -> STRING // second arg - string with time only
+ * (x, STRING) -> NULL // second arg - string with timestamp
+ * (x, STRING/DATE) -> x // second arg - string with date only */ private DefaultFunctionResolver addtime() { - return define(BuiltinFunctionName.ADDTIME.getName(), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - TIME, TIME, TIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - TIME, TIME, DATE), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - TIME, TIME, DATETIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - TIME, TIME, TIMESTAMP), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, DATETIME, TIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, DATETIME, DATE), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, DATETIME, DATETIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, DATETIME, TIMESTAMP), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, DATE, TIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, DATE, DATE), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, DATE, DATETIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, DATE, TIMESTAMP), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, TIMESTAMP, TIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, TIMESTAMP, DATE), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, TIMESTAMP, DATETIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, TIMESTAMP, TIMESTAMP) - ); - } - - /** - * Converts date/time from a specified timezone to another specified timezone. - * The supported signatures: - * (DATETIME, STRING, STRING) -> DATETIME - * (STRING, STRING, STRING) -> DATETIME - */ - private DefaultFunctionResolver convert_tz() { - return define(BuiltinFunctionName.CONVERT_TZ.getName(), - impl(nullMissingHandling(DateTimeFunction::exprConvertTZ), - DATETIME, DATETIME, STRING, STRING), - impl(nullMissingHandling(DateTimeFunction::exprConvertTZ), - DATETIME, STRING, STRING, STRING) - ); + return define( + BuiltinFunctionName.ADDTIME.getName(), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), TIME, TIME, TIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), TIME, TIME, DATE), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), TIME, TIME, DATETIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), + TIME, + TIME, + TIMESTAMP), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), + DATETIME, + DATETIME, + TIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), + DATETIME, + DATETIME, + DATE), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), + DATETIME, + DATETIME, + DATETIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), + DATETIME, + DATETIME, + TIMESTAMP), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), DATETIME, DATE, TIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), DATETIME, DATE, DATE), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), + DATETIME, + DATE, + DATETIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), + DATETIME, + DATE, + TIMESTAMP), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), + DATETIME, + TIMESTAMP, + TIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), + DATETIME, + TIMESTAMP, + DATE), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), + DATETIME, + TIMESTAMP, + DATETIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), + DATETIME, + TIMESTAMP, + TIMESTAMP)); } /** - * Extracts the date part of a date and time value. - * Also to construct a date type. The supported signatures: - * STRING/DATE/DATETIME/TIMESTAMP -> DATE + * Converts date/time from a specified timezone to another specified timezone.
+ * The supported signatures:
+ * (DATETIME, STRING, STRING) -> DATETIME
+ * (STRING, STRING, STRING) -> DATETIME + */ + private DefaultFunctionResolver convert_tz() { + return define( + BuiltinFunctionName.CONVERT_TZ.getName(), + impl( + nullMissingHandling(DateTimeFunction::exprConvertTZ), + DATETIME, + DATETIME, + STRING, + STRING), + impl( + nullMissingHandling(DateTimeFunction::exprConvertTZ), + DATETIME, + STRING, + STRING, + STRING)); + } + + /** + * Extracts the date part of a date and time value. Also to construct a date type. The supported + * signatures: STRING/DATE/DATETIME/TIMESTAMP -> DATE */ private DefaultFunctionResolver date() { - return define(BuiltinFunctionName.DATE.getName(), + return define( + BuiltinFunctionName.DATE.getName(), impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, STRING), impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, DATE), impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, DATETIME), @@ -447,273 +492,310 @@ private DefaultFunctionResolver date() { * (DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME) -> LONG */ private DefaultFunctionResolver datediff() { - return define(BuiltinFunctionName.DATEDIFF.getName(), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, DATE, DATE), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, DATETIME, DATE), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, DATE, DATETIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, DATETIME, DATETIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, DATE, TIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, TIME, DATE), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, TIME, TIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, TIMESTAMP, DATE), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, DATE, TIMESTAMP), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, TIMESTAMP, TIMESTAMP), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, TIMESTAMP, TIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, TIME, TIMESTAMP), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, TIMESTAMP, DATETIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, DATETIME, TIMESTAMP), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, TIME, DATETIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, DATETIME, TIME)); - } - - /** - * Specify a datetime with time zone field and a time zone to convert to. - * Returns a local date time. - * (STRING, STRING) -> DATETIME + return define( + BuiltinFunctionName.DATEDIFF.getName(), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), LONG, DATE, DATE), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), + LONG, + DATETIME, + DATE), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), + LONG, + DATE, + DATETIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), + LONG, + DATETIME, + DATETIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), LONG, DATE, TIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), LONG, TIME, DATE), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), LONG, TIME, TIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), + LONG, + TIMESTAMP, + DATE), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), + LONG, + DATE, + TIMESTAMP), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), + LONG, + TIMESTAMP, + TIMESTAMP), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), + LONG, + TIMESTAMP, + TIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), + LONG, + TIME, + TIMESTAMP), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), + LONG, + TIMESTAMP, + DATETIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), + LONG, + DATETIME, + TIMESTAMP), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), + LONG, + TIME, + DATETIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), + LONG, + DATETIME, + TIME)); + } + + /** + * Specify a datetime with time zone field and a time zone to convert to.
+ * Returns a local date time.
+ * (STRING, STRING) -> DATETIME
* (STRING) -> DATETIME */ private FunctionResolver datetime() { - return define(BuiltinFunctionName.DATETIME.getName(), - impl(nullMissingHandling(DateTimeFunction::exprDateTime), - DATETIME, STRING, STRING), - impl(nullMissingHandling(DateTimeFunction::exprDateTimeNoTimezone), - DATETIME, STRING) - ); + return define( + BuiltinFunctionName.DATETIME.getName(), + impl(nullMissingHandling(DateTimeFunction::exprDateTime), DATETIME, STRING, STRING), + impl(nullMissingHandling(DateTimeFunction::exprDateTimeNoTimezone), DATETIME, STRING)); } private DefaultFunctionResolver date_add() { - return define(BuiltinFunctionName.DATE_ADD.getName(), + return define( + BuiltinFunctionName.DATE_ADD.getName(), (SerializableFunction>[]) get_date_add_date_sub_signatures(DateTimeFunction::exprAddDateInterval) .toArray(SerializableFunction[]::new)); } private DefaultFunctionResolver date_sub() { - return define(BuiltinFunctionName.DATE_SUB.getName(), + return define( + BuiltinFunctionName.DATE_SUB.getName(), (SerializableFunction>[]) get_date_add_date_sub_signatures(DateTimeFunction::exprSubDateInterval) .toArray(SerializableFunction[]::new)); } - /** - * DAY(STRING/DATE/DATETIME/TIMESTAMP). return the day of the month (1-31). - */ + /** DAY(STRING/DATE/DATETIME/TIMESTAMP). return the day of the month (1-31). */ private DefaultFunctionResolver day() { - return define(BuiltinFunctionName.DAY.getName(), + return define( + BuiltinFunctionName.DAY.getName(), impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, STRING) - ); + impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, STRING)); } /** - * DAYNAME(STRING/DATE/DATETIME/TIMESTAMP). - * return the name of the weekday for date, including Monday, Tuesday, Wednesday, - * Thursday, Friday, Saturday and Sunday. + * DAYNAME(STRING/DATE/DATETIME/TIMESTAMP). return the name of the weekday for date, including + * Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. */ private DefaultFunctionResolver dayName() { - return define(BuiltinFunctionName.DAYNAME.getName(), + return define( + BuiltinFunctionName.DAYNAME.getName(), impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, DATE), impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, STRING) - ); + impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, STRING)); } - /** - * DAYOFMONTH(STRING/DATE/DATETIME/TIMESTAMP). return the day of the month (1-31). - */ + /** DAYOFMONTH(STRING/DATE/DATETIME/TIMESTAMP). return the day of the month (1-31). */ private DefaultFunctionResolver dayOfMonth(BuiltinFunctionName name) { - return define(name.getName(), - implWithProperties(nullMissingHandlingWithProperties( - (functionProperties, arg) -> DateTimeFunction.dayOfMonthToday( - functionProperties.getQueryStartClock())), INTEGER, TIME), + return define( + name.getName(), + implWithProperties( + nullMissingHandlingWithProperties( + (functionProperties, arg) -> + DateTimeFunction.dayOfMonthToday(functionProperties.getQueryStartClock())), + INTEGER, + TIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, STRING), - impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, TIMESTAMP) - ); + impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, TIMESTAMP)); } /** - * DAYOFWEEK(STRING/DATE/DATETIME/TIME/TIMESTAMP). - * return the weekday index for date (1 = Sunday, 2 = Monday, ..., 7 = Saturday). + * DAYOFWEEK(STRING/DATE/DATETIME/TIME/TIMESTAMP). return the weekday index for date (1 = Sunday, + * 2 = Monday, ..., 7 = Saturday). */ private DefaultFunctionResolver dayOfWeek(FunctionName name) { - return define(name, - implWithProperties(nullMissingHandlingWithProperties( - (functionProperties, arg) -> DateTimeFunction.dayOfWeekToday( - functionProperties.getQueryStartClock())), INTEGER, TIME), + return define( + name, + implWithProperties( + nullMissingHandlingWithProperties( + (functionProperties, arg) -> + DateTimeFunction.dayOfWeekToday(functionProperties.getQueryStartClock())), + INTEGER, + TIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, STRING) - ); + impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, STRING)); } - /** - * DAYOFYEAR(STRING/DATE/DATETIME/TIMESTAMP). - * return the day of the year for date (1-366). - */ + /** DAYOFYEAR(STRING/DATE/DATETIME/TIMESTAMP). return the day of the year for date (1-366). */ private DefaultFunctionResolver dayOfYear(BuiltinFunctionName dayOfYear) { - return define(dayOfYear.getName(), - implWithProperties(nullMissingHandlingWithProperties((functionProperties, arg) - -> DateTimeFunction.dayOfYearToday( - functionProperties.getQueryStartClock())), INTEGER, TIME), + return define( + dayOfYear.getName(), + implWithProperties( + nullMissingHandlingWithProperties( + (functionProperties, arg) -> + DateTimeFunction.dayOfYearToday(functionProperties.getQueryStartClock())), + INTEGER, + TIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, STRING) - ); + impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, STRING)); } private DefaultFunctionResolver extract() { - return define(BuiltinFunctionName.EXTRACT.getName(), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprExtractForTime), - LONG, STRING, TIME), + return define( + BuiltinFunctionName.EXTRACT.getName(), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprExtractForTime), + LONG, + STRING, + TIME), impl(nullMissingHandling(DateTimeFunction::exprExtract), LONG, STRING, DATE), impl(nullMissingHandling(DateTimeFunction::exprExtract), LONG, STRING, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprExtract), LONG, STRING, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprExtract), LONG, STRING, STRING) - ); + impl(nullMissingHandling(DateTimeFunction::exprExtract), LONG, STRING, STRING)); } - /** - * FROM_DAYS(LONG). return the date value given the day number N. - */ + /** FROM_DAYS(LONG). return the date value given the day number N. */ private DefaultFunctionResolver from_days() { - return define(BuiltinFunctionName.FROM_DAYS.getName(), + return define( + BuiltinFunctionName.FROM_DAYS.getName(), impl(nullMissingHandling(DateTimeFunction::exprFromDays), DATE, LONG)); } private FunctionResolver from_unixtime() { - return define(BuiltinFunctionName.FROM_UNIXTIME.getName(), + return define( + BuiltinFunctionName.FROM_UNIXTIME.getName(), impl(nullMissingHandling(DateTimeFunction::exprFromUnixTime), DATETIME, DOUBLE), - impl(nullMissingHandling(DateTimeFunction::exprFromUnixTimeFormat), - STRING, DOUBLE, STRING)); + impl( + nullMissingHandling(DateTimeFunction::exprFromUnixTimeFormat), STRING, DOUBLE, STRING)); } private DefaultFunctionResolver get_format() { - return define(BuiltinFunctionName.GET_FORMAT.getName(), - impl(nullMissingHandling(DateTimeFunction::exprGetFormat), STRING, STRING, STRING) - ); + return define( + BuiltinFunctionName.GET_FORMAT.getName(), + impl(nullMissingHandling(DateTimeFunction::exprGetFormat), STRING, STRING, STRING)); } - /** - * HOUR(STRING/TIME/DATETIME/DATE/TIMESTAMP). return the hour value for time. - */ + /** HOUR(STRING/TIME/DATETIME/DATE/TIMESTAMP). return the hour value for time. */ private DefaultFunctionResolver hour(BuiltinFunctionName name) { - return define(name.getName(), + return define( + name.getName(), impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, STRING), impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, DATETIME), - impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, TIMESTAMP) - ); + impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, TIMESTAMP)); } - private DefaultFunctionResolver last_day() { - return define(BuiltinFunctionName.LAST_DAY.getName(), + private DefaultFunctionResolver last_day() { + return define( + BuiltinFunctionName.LAST_DAY.getName(), impl(nullMissingHandling(DateTimeFunction::exprLastDay), DATE, STRING), - implWithProperties(nullMissingHandlingWithProperties((functionProperties, arg) - -> DateTimeFunction.exprLastDayToday( - functionProperties.getQueryStartClock())), DATE, TIME), + implWithProperties( + nullMissingHandlingWithProperties( + (functionProperties, arg) -> + DateTimeFunction.exprLastDayToday(functionProperties.getQueryStartClock())), + DATE, + TIME), impl(nullMissingHandling(DateTimeFunction::exprLastDay), DATE, DATE), impl(nullMissingHandling(DateTimeFunction::exprLastDay), DATE, DATETIME), - impl(nullMissingHandling(DateTimeFunction::exprLastDay), DATE, TIMESTAMP) - ); + impl(nullMissingHandling(DateTimeFunction::exprLastDay), DATE, TIMESTAMP)); } private FunctionResolver makedate() { - return define(BuiltinFunctionName.MAKEDATE.getName(), + return define( + BuiltinFunctionName.MAKEDATE.getName(), impl(nullMissingHandling(DateTimeFunction::exprMakeDate), DATE, DOUBLE, DOUBLE)); } private FunctionResolver maketime() { - return define(BuiltinFunctionName.MAKETIME.getName(), + return define( + BuiltinFunctionName.MAKETIME.getName(), impl(nullMissingHandling(DateTimeFunction::exprMakeTime), TIME, DOUBLE, DOUBLE, DOUBLE)); } - /** - * MICROSECOND(STRING/TIME/DATETIME/TIMESTAMP). return the microsecond value for time. - */ + /** MICROSECOND(STRING/TIME/DATETIME/TIMESTAMP). return the microsecond value for time. */ private DefaultFunctionResolver microsecond() { - return define(BuiltinFunctionName.MICROSECOND.getName(), + return define( + BuiltinFunctionName.MICROSECOND.getName(), impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, STRING), impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, DATETIME), - impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, TIMESTAMP) - ); + impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, TIMESTAMP)); } - /** - * MINUTE(STRING/TIME/DATETIME/TIMESTAMP). return the minute value for time. - */ + /** MINUTE(STRING/TIME/DATETIME/TIMESTAMP). return the minute value for time. */ private DefaultFunctionResolver minute(BuiltinFunctionName name) { - return define(name.getName(), + return define( + name.getName(), impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, STRING), impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, TIMESTAMP) - ); + impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, TIMESTAMP)); } - /** - * MINUTE(STRING/TIME/DATETIME/TIMESTAMP). return the minute value for time. - */ + /** MINUTE(STRING/TIME/DATETIME/TIMESTAMP). return the minute value for time. */ private DefaultFunctionResolver minute_of_day() { - return define(BuiltinFunctionName.MINUTE_OF_DAY.getName(), + return define( + BuiltinFunctionName.MINUTE_OF_DAY.getName(), impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, STRING), impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, DATETIME), - impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, TIMESTAMP) - ); + impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, TIMESTAMP)); } - /** - * MONTH(STRING/DATE/DATETIME/TIMESTAMP). return the month for date (1-12). - */ + /** MONTH(STRING/DATE/DATETIME/TIMESTAMP). return the month for date (1-12). */ private DefaultFunctionResolver month(BuiltinFunctionName month) { - return define(month.getName(), - implWithProperties(nullMissingHandlingWithProperties((functionProperties, arg) - -> DateTimeFunction.monthOfYearToday( - functionProperties.getQueryStartClock())), INTEGER, TIME), + return define( + month.getName(), + implWithProperties( + nullMissingHandlingWithProperties( + (functionProperties, arg) -> + DateTimeFunction.monthOfYearToday(functionProperties.getQueryStartClock())), + INTEGER, + TIME), impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, STRING) - ); + impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, STRING)); } - /** - * MONTHNAME(STRING/DATE/DATETIME/TIMESTAMP). return the full name of the month for date. - */ + /** MONTHNAME(STRING/DATE/DATETIME/TIMESTAMP). return the full name of the month for date. */ private DefaultFunctionResolver monthName() { - return define(BuiltinFunctionName.MONTHNAME.getName(), + return define( + BuiltinFunctionName.MONTHNAME.getName(), impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, DATE), impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, STRING) - ); + impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, STRING)); } /** @@ -721,130 +803,164 @@ private DefaultFunctionResolver monthName() { * (INTEGER, INTEGER) -> INTEGER */ private DefaultFunctionResolver period_add() { - return define(BuiltinFunctionName.PERIOD_ADD.getName(), - impl(nullMissingHandling(DateTimeFunction::exprPeriodAdd), INTEGER, INTEGER, INTEGER) - ); + return define( + BuiltinFunctionName.PERIOD_ADD.getName(), + impl(nullMissingHandling(DateTimeFunction::exprPeriodAdd), INTEGER, INTEGER, INTEGER)); } /** - * Returns the number of months between periods P1 and P2. - * P1 and P2 should be in the format YYMM or YYYYMM. + * Returns the number of months between periods P1 and P2. P1 and P2 should be in the format YYMM + * or YYYYMM.
* (INTEGER, INTEGER) -> INTEGER */ private DefaultFunctionResolver period_diff() { - return define(BuiltinFunctionName.PERIOD_DIFF.getName(), - impl(nullMissingHandling(DateTimeFunction::exprPeriodDiff), INTEGER, INTEGER, INTEGER) - ); + return define( + BuiltinFunctionName.PERIOD_DIFF.getName(), + impl(nullMissingHandling(DateTimeFunction::exprPeriodDiff), INTEGER, INTEGER, INTEGER)); } - /** - * QUARTER(STRING/DATE/DATETIME/TIMESTAMP). return the month for date (1-4). - */ + /** QUARTER(STRING/DATE/DATETIME/TIMESTAMP). return the month for date (1-4). */ private DefaultFunctionResolver quarter() { - return define(BuiltinFunctionName.QUARTER.getName(), + return define( + BuiltinFunctionName.QUARTER.getName(), impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, STRING) - ); + impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, STRING)); } private DefaultFunctionResolver sec_to_time() { - return define(BuiltinFunctionName.SEC_TO_TIME.getName(), + return define( + BuiltinFunctionName.SEC_TO_TIME.getName(), impl((nullMissingHandling(DateTimeFunction::exprSecToTime)), TIME, INTEGER), impl((nullMissingHandling(DateTimeFunction::exprSecToTime)), TIME, LONG), impl((nullMissingHandling(DateTimeFunction::exprSecToTimeWithNanos)), TIME, DOUBLE), - impl((nullMissingHandling(DateTimeFunction::exprSecToTimeWithNanos)), TIME, FLOAT) - ); + impl((nullMissingHandling(DateTimeFunction::exprSecToTimeWithNanos)), TIME, FLOAT)); } - /** - * SECOND(STRING/TIME/DATETIME/TIMESTAMP). return the second value for time. - */ + /** SECOND(STRING/TIME/DATETIME/TIMESTAMP). return the second value for time. */ private DefaultFunctionResolver second(BuiltinFunctionName name) { - return define(name.getName(), + return define( + name.getName(), impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, STRING), impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, DATETIME), - impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, TIMESTAMP) - ); + impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, TIMESTAMP)); } private DefaultFunctionResolver subdate() { - return define(BuiltinFunctionName.SUBDATE.getName(), + return define( + BuiltinFunctionName.SUBDATE.getName(), (SerializableFunction>[]) (Stream.concat( - get_date_add_date_sub_signatures(DateTimeFunction::exprSubDateInterval), - get_adddate_subdate_signatures(DateTimeFunction::exprSubDateDays)) + get_date_add_date_sub_signatures(DateTimeFunction::exprSubDateInterval), + get_adddate_subdate_signatures(DateTimeFunction::exprSubDateDays)) .toArray(SerializableFunction[]::new))); } /** - * Subtracts expr2 from expr1 and returns the result. - * (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME - * (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME - * TODO: MySQL has these signatures too - * (STRING, STRING/TIME) -> STRING // second arg - string with time only - * (x, STRING) -> NULL // second arg - string with timestamp - * (x, STRING/DATE) -> x // second arg - string with date only + * Subtracts expr2 from expr1 and returns the result.
+ * (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME
+ * (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME
+ * TODO: MySQL has these signatures too
+ * (STRING, STRING/TIME) -> STRING // second arg - string with time only
+ * (x, STRING) -> NULL // second arg - string with timestamp
+ * (x, STRING/DATE) -> x // second arg - string with date only */ private DefaultFunctionResolver subtime() { - return define(BuiltinFunctionName.SUBTIME.getName(), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - TIME, TIME, TIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - TIME, TIME, DATE), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - TIME, TIME, DATETIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - TIME, TIME, TIMESTAMP), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, DATETIME, TIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, DATETIME, DATE), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, DATETIME, DATETIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, DATETIME, TIMESTAMP), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, DATE, TIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, DATE, DATE), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, DATE, DATETIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, DATE, TIMESTAMP), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, TIMESTAMP, TIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, TIMESTAMP, DATE), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, TIMESTAMP, DATETIME), - implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, TIMESTAMP, TIMESTAMP) - ); - } - - /** - * Extracts a date, time, or datetime from the given string. - * It accomplishes this using another string which specifies the input format. + return define( + BuiltinFunctionName.SUBTIME.getName(), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), TIME, TIME, TIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), TIME, TIME, DATE), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), TIME, TIME, DATETIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), + TIME, + TIME, + TIMESTAMP), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), + DATETIME, + DATETIME, + TIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), + DATETIME, + DATETIME, + DATE), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), + DATETIME, + DATETIME, + DATETIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), + DATETIME, + DATETIME, + TIMESTAMP), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), DATETIME, DATE, TIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), DATETIME, DATE, DATE), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), + DATETIME, + DATE, + DATETIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), + DATETIME, + DATE, + TIMESTAMP), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), + DATETIME, + TIMESTAMP, + TIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), + DATETIME, + TIMESTAMP, + DATE), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), + DATETIME, + TIMESTAMP, + DATETIME), + implWithProperties( + nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), + DATETIME, + TIMESTAMP, + TIMESTAMP)); + } + + /** + * Extracts a date, time, or datetime from the given string. It accomplishes this using another + * string which specifies the input format. */ private DefaultFunctionResolver str_to_date() { - return define(BuiltinFunctionName.STR_TO_DATE.getName(), + return define( + BuiltinFunctionName.STR_TO_DATE.getName(), implWithProperties( - nullMissingHandlingWithProperties((functionProperties, arg, format) - -> DateTimeFunction.exprStrToDate(functionProperties, arg, format)), - DATETIME, STRING, STRING)); + nullMissingHandlingWithProperties( + (functionProperties, arg, format) -> + DateTimeFunction.exprStrToDate(functionProperties, arg, format)), + DATETIME, + STRING, + STRING)); } /** - * Extracts the time part of a date and time value. - * Also to construct a time type. The supported signatures: - * STRING/DATE/DATETIME/TIME/TIMESTAMP -> TIME + * Extracts the time part of a date and time value. Also to construct a time type. The supported + * signatures: STRING/DATE/DATETIME/TIME/TIMESTAMP -> TIME */ private DefaultFunctionResolver time() { - return define(BuiltinFunctionName.TIME.getName(), + return define( + BuiltinFunctionName.TIME.getName(), impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, STRING), impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, DATE), impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, DATETIME), @@ -853,18 +969,19 @@ private DefaultFunctionResolver time() { } /** - * Returns different between two times as a time. - * (TIME, TIME) -> TIME - * MySQL has these signatures too - * (DATE, DATE) -> TIME // result is > 24 hours - * (DATETIME, DATETIME) -> TIME // result is > 24 hours - * (TIMESTAMP, TIMESTAMP) -> TIME // result is > 24 hours - * (x, x) -> NULL // when args have different types - * (STRING, STRING) -> TIME // argument strings contain same types only - * (STRING, STRING) -> NULL // argument strings are different types + * Returns different between two times as a time.
+ * (TIME, TIME) -> TIME
+ * MySQL has these signatures too
+ * (DATE, DATE) -> TIME // result is > 24 hours
+ * (DATETIME, DATETIME) -> TIME // result is > 24 hours
+ * (TIMESTAMP, TIMESTAMP) -> TIME // result is > 24 hours
+ * (x, x) -> NULL // when args have different types
+ * (STRING, STRING) -> TIME // argument strings contain same types only
+ * (STRING, STRING) -> NULL // argument strings are different types */ private DefaultFunctionResolver timediff() { - return define(BuiltinFunctionName.TIMEDIFF.getName(), + return define( + BuiltinFunctionName.TIMEDIFF.getName(), impl(nullMissingHandling(DateTimeFunction::exprTimeDiff), TIME, TIME, TIME)); } @@ -872,90 +989,122 @@ private DefaultFunctionResolver timediff() { * TIME_TO_SEC(STRING/TIME/DATETIME/TIMESTAMP). return the time argument, converted to seconds. */ private DefaultFunctionResolver time_to_sec() { - return define(BuiltinFunctionName.TIME_TO_SEC.getName(), + return define( + BuiltinFunctionName.TIME_TO_SEC.getName(), impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, STRING), impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, TIME), impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, DATETIME) - ); + impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, DATETIME)); } /** - * Extracts the timestamp of a date and time value. - * Input strings may contain a timestamp only in format 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]' - * STRING/DATE/TIME/DATETIME/TIMESTAMP -> TIMESTAMP - * STRING/DATE/TIME/DATETIME/TIMESTAMP, STRING/DATE/TIME/DATETIME/TIMESTAMP -> TIMESTAMP + * Extracts the timestamp of a date and time value.
+ * Input strings may contain a timestamp only in format 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'
+ * STRING/DATE/TIME/DATETIME/TIMESTAMP -> TIMESTAMP
+ * STRING/DATE/TIME/DATETIME/TIMESTAMP, STRING/DATE/TIME/DATETIME/TIMESTAMP -> TIMESTAMP
* All types are converted to TIMESTAMP actually before the function call - it is responsibility + *
* of the automatic cast mechanism defined in `ExprCoreType` and performed by `TypeCastOperator`. */ private DefaultFunctionResolver timestamp() { - return define(BuiltinFunctionName.TIMESTAMP.getName(), + return define( + BuiltinFunctionName.TIMESTAMP.getName(), impl(nullMissingHandling(v -> v), TIMESTAMP, TIMESTAMP), // We can use FunctionProperties.None, because it is not used. It is required to convert // TIME to other datetime types, but arguments there are already converted. - impl(nullMissingHandling((v1, v2) -> exprAddTime(FunctionProperties.None, v1, v2)), - TIMESTAMP, TIMESTAMP, TIMESTAMP)); + impl( + nullMissingHandling((v1, v2) -> exprAddTime(FunctionProperties.None, v1, v2)), + TIMESTAMP, + TIMESTAMP, + TIMESTAMP)); } /** - * Adds an interval of time to the provided DATE/DATETIME/TIME/TIMESTAMP/STRING argument. - * The interval of time added is determined by the given first and second arguments. - * The first argument is an interval type, and must be one of the tokens below... - * [MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR] - * The second argument is the amount of the interval type to be added. - * The third argument is the DATE/DATETIME/TIME/TIMESTAMP/STRING to add to. + * Adds an interval of time to the provided DATE/DATETIME/TIME/TIMESTAMP/STRING argument. The + * interval of time added is determined by the given first and second arguments. The first + * argument is an interval type, and must be one of the tokens below... [MICROSECOND, SECOND, + * MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR] The second argument is the amount of the + * interval type to be added. The third argument is the DATE/DATETIME/TIME/TIMESTAMP/STRING to add + * to. + * * @return The DATETIME representing the summed DATE/DATETIME/TIME/TIMESTAMP and interval. */ private DefaultFunctionResolver timestampadd() { - return define(BuiltinFunctionName.TIMESTAMPADD.getName(), - impl(nullMissingHandling(DateTimeFunction::exprTimestampAdd), - DATETIME, STRING, INTEGER, DATETIME), - impl(nullMissingHandling(DateTimeFunction::exprTimestampAdd), - DATETIME, STRING, INTEGER, TIMESTAMP), + return define( + BuiltinFunctionName.TIMESTAMPADD.getName(), + impl( + nullMissingHandling(DateTimeFunction::exprTimestampAdd), + DATETIME, + STRING, + INTEGER, + DATETIME), + impl( + nullMissingHandling(DateTimeFunction::exprTimestampAdd), + DATETIME, + STRING, + INTEGER, + TIMESTAMP), implWithProperties( nullMissingHandlingWithProperties( - (functionProperties, part, amount, time) -> exprTimestampAddForTimeType( - functionProperties.getQueryStartClock(), - part, - amount, - time)), - DATETIME, STRING, INTEGER, TIME)); + (functionProperties, part, amount, time) -> + exprTimestampAddForTimeType( + functionProperties.getQueryStartClock(), part, amount, time)), + DATETIME, + STRING, + INTEGER, + TIME)); } /** - * Finds the difference between provided DATE/DATETIME/TIME/TIMESTAMP/STRING arguments. - * The first argument is an interval type, and must be one of the tokens below... - * [MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR] - * The second argument the DATE/DATETIME/TIME/TIMESTAMP/STRING representing the start time. - * The third argument is the DATE/DATETIME/TIME/TIMESTAMP/STRING representing the end time. + * Finds the difference between provided DATE/DATETIME/TIME/TIMESTAMP/STRING arguments. The first + * argument is an interval type, and must be one of the tokens below... [MICROSECOND, SECOND, + * MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR] The second argument the + * DATE/DATETIME/TIME/TIMESTAMP/STRING representing the start time. The third argument is the + * DATE/DATETIME/TIME/TIMESTAMP/STRING representing the end time. + * * @return A LONG representing the difference between arguments, using the given interval type. */ private DefaultFunctionResolver timestampdiff() { - return define(BuiltinFunctionName.TIMESTAMPDIFF.getName(), - impl(nullMissingHandling(DateTimeFunction::exprTimestampDiff), - DATETIME, STRING, DATETIME, DATETIME), - impl(nullMissingHandling(DateTimeFunction::exprTimestampDiff), - DATETIME, STRING, DATETIME, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprTimestampDiff), - DATETIME, STRING, TIMESTAMP, DATETIME), - impl(nullMissingHandling(DateTimeFunction::exprTimestampDiff), - DATETIME, STRING, TIMESTAMP, TIMESTAMP), + return define( + BuiltinFunctionName.TIMESTAMPDIFF.getName(), + impl( + nullMissingHandling(DateTimeFunction::exprTimestampDiff), + DATETIME, + STRING, + DATETIME, + DATETIME), + impl( + nullMissingHandling(DateTimeFunction::exprTimestampDiff), + DATETIME, + STRING, + DATETIME, + TIMESTAMP), + impl( + nullMissingHandling(DateTimeFunction::exprTimestampDiff), + DATETIME, + STRING, + TIMESTAMP, + DATETIME), + impl( + nullMissingHandling(DateTimeFunction::exprTimestampDiff), + DATETIME, + STRING, + TIMESTAMP, + TIMESTAMP), implWithProperties( nullMissingHandlingWithProperties( - (functionProperties, part, startTime, endTime) -> exprTimestampDiffForTimeType( - functionProperties, - part, - startTime, - endTime)), - DATETIME, STRING, TIME, TIME) - ); + (functionProperties, part, startTime, endTime) -> + exprTimestampDiffForTimeType(functionProperties, part, startTime, endTime)), + DATETIME, + STRING, + TIME, + TIME)); } - /** - * TO_DAYS(STRING/DATE/DATETIME/TIMESTAMP). return the day number of the given date. - */ + /** TO_DAYS(STRING/DATE/DATETIME/TIMESTAMP). return the day number of the given date. */ private DefaultFunctionResolver to_days() { - return define(BuiltinFunctionName.TO_DAYS.getName(), + return define( + BuiltinFunctionName.TO_DAYS.getName(), impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, STRING), impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, DATE), @@ -963,156 +1112,166 @@ private DefaultFunctionResolver to_days() { } /** - * TO_SECONDS(TIMESTAMP/LONG). return the seconds number of the given date. - * Arguments of type STRING/TIMESTAMP/LONG are also accepted. - * STRING/TIMESTAMP/LONG arguments are automatically cast to TIMESTAMP. + * TO_SECONDS(TIMESTAMP/LONG). return the seconds number of the given date. Arguments of type + * STRING/TIMESTAMP/LONG are also accepted. STRING/TIMESTAMP/LONG arguments are automatically cast + * to TIMESTAMP. */ private DefaultFunctionResolver to_seconds() { - return define(BuiltinFunctionName.TO_SECONDS.getName(), + return define( + BuiltinFunctionName.TO_SECONDS.getName(), impl(nullMissingHandling(DateTimeFunction::exprToSeconds), LONG, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprToSecondsForIntType), LONG, LONG)); } private FunctionResolver unix_timestamp() { - return define(BuiltinFunctionName.UNIX_TIMESTAMP.getName(), - implWithProperties(functionProperties - -> DateTimeFunction.unixTimeStamp(functionProperties.getQueryStartClock()), LONG), + return define( + BuiltinFunctionName.UNIX_TIMESTAMP.getName(), + implWithProperties( + functionProperties -> + DateTimeFunction.unixTimeStamp(functionProperties.getQueryStartClock()), + LONG), impl(nullMissingHandling(DateTimeFunction::unixTimeStampOf), DOUBLE, DATE), impl(nullMissingHandling(DateTimeFunction::unixTimeStampOf), DOUBLE, DATETIME), impl(nullMissingHandling(DateTimeFunction::unixTimeStampOf), DOUBLE, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::unixTimeStampOf), DOUBLE, DOUBLE) - ); + impl(nullMissingHandling(DateTimeFunction::unixTimeStampOf), DOUBLE, DOUBLE)); } - /** - * UTC_DATE(). return the current UTC Date in format yyyy-MM-dd - */ + /** UTC_DATE(). return the current UTC Date in format yyyy-MM-dd */ private DefaultFunctionResolver utc_date() { - return define(BuiltinFunctionName.UTC_DATE.getName(), - implWithProperties(functionProperties - -> exprUtcDate(functionProperties), DATE)); + return define( + BuiltinFunctionName.UTC_DATE.getName(), + implWithProperties(functionProperties -> exprUtcDate(functionProperties), DATE)); } - /** - * UTC_TIME(). return the current UTC Time in format HH:mm:ss - */ + /** UTC_TIME(). return the current UTC Time in format HH:mm:ss */ private DefaultFunctionResolver utc_time() { - return define(BuiltinFunctionName.UTC_TIME.getName(), - implWithProperties(functionProperties - -> exprUtcTime(functionProperties), TIME)); + return define( + BuiltinFunctionName.UTC_TIME.getName(), + implWithProperties(functionProperties -> exprUtcTime(functionProperties), TIME)); } - /** - * UTC_TIMESTAMP(). return the current UTC TimeStamp in format yyyy-MM-dd HH:mm:ss - */ + /** UTC_TIMESTAMP(). return the current UTC TimeStamp in format yyyy-MM-dd HH:mm:ss */ private DefaultFunctionResolver utc_timestamp() { - return define(BuiltinFunctionName.UTC_TIMESTAMP.getName(), - implWithProperties(functionProperties - -> exprUtcTimeStamp(functionProperties), DATETIME)); + return define( + BuiltinFunctionName.UTC_TIMESTAMP.getName(), + implWithProperties(functionProperties -> exprUtcTimeStamp(functionProperties), DATETIME)); } - /** - * WEEK(DATE[,mode]). return the week number for date. - */ + /** WEEK(DATE[,mode]). return the week number for date. */ private DefaultFunctionResolver week(BuiltinFunctionName week) { - return define(week.getName(), - implWithProperties(nullMissingHandlingWithProperties((functionProperties, arg) - -> DateTimeFunction.weekOfYearToday( - DEFAULT_WEEK_OF_YEAR_MODE, - functionProperties.getQueryStartClock())), INTEGER, TIME), + return define( + week.getName(), + implWithProperties( + nullMissingHandlingWithProperties( + (functionProperties, arg) -> + DateTimeFunction.weekOfYearToday( + DEFAULT_WEEK_OF_YEAR_MODE, functionProperties.getQueryStartClock())), + INTEGER, + TIME), impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, STRING), - implWithProperties(nullMissingHandlingWithProperties((functionProperties, time, modeArg) - -> DateTimeFunction.weekOfYearToday( - modeArg, - functionProperties.getQueryStartClock())), INTEGER, TIME, INTEGER), + implWithProperties( + nullMissingHandlingWithProperties( + (functionProperties, time, modeArg) -> + DateTimeFunction.weekOfYearToday( + modeArg, functionProperties.getQueryStartClock())), + INTEGER, + TIME, + INTEGER), impl(nullMissingHandling(DateTimeFunction::exprWeek), INTEGER, DATE, INTEGER), impl(nullMissingHandling(DateTimeFunction::exprWeek), INTEGER, DATETIME, INTEGER), impl(nullMissingHandling(DateTimeFunction::exprWeek), INTEGER, TIMESTAMP, INTEGER), - impl(nullMissingHandling(DateTimeFunction::exprWeek), INTEGER, STRING, INTEGER) - ); + impl(nullMissingHandling(DateTimeFunction::exprWeek), INTEGER, STRING, INTEGER)); } private DefaultFunctionResolver weekday() { - return define(BuiltinFunctionName.WEEKDAY.getName(), - implWithProperties(nullMissingHandlingWithProperties( - (functionProperties, arg) -> new ExprIntegerValue( - formatNow(functionProperties.getQueryStartClock()).getDayOfWeek().getValue() - 1)), - INTEGER, TIME), + return define( + BuiltinFunctionName.WEEKDAY.getName(), + implWithProperties( + nullMissingHandlingWithProperties( + (functionProperties, arg) -> + new ExprIntegerValue( + formatNow(functionProperties.getQueryStartClock()).getDayOfWeek().getValue() + - 1)), + INTEGER, + TIME), impl(nullMissingHandling(DateTimeFunction::exprWeekday), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprWeekday), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprWeekday), INTEGER, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprWeekday), INTEGER, STRING) - ); + impl(nullMissingHandling(DateTimeFunction::exprWeekday), INTEGER, STRING)); } - /** - * YEAR(STRING/DATE/DATETIME/TIMESTAMP). return the year for date (1000-9999). - */ + /** YEAR(STRING/DATE/DATETIME/TIMESTAMP). return the year for date (1000-9999). */ private DefaultFunctionResolver year() { - return define(BuiltinFunctionName.YEAR.getName(), + return define( + BuiltinFunctionName.YEAR.getName(), impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, STRING) - ); + impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, STRING)); } - /** - * YEARWEEK(DATE[,mode]). return the week number for date. - */ + /** YEARWEEK(DATE[,mode]). return the week number for date. */ private DefaultFunctionResolver yearweek() { - return define(BuiltinFunctionName.YEARWEEK.getName(), - implWithProperties(nullMissingHandlingWithProperties((functionProperties, arg) - -> yearweekToday( - DEFAULT_WEEK_OF_YEAR_MODE, - functionProperties.getQueryStartClock())), INTEGER, TIME), + return define( + BuiltinFunctionName.YEARWEEK.getName(), + implWithProperties( + nullMissingHandlingWithProperties( + (functionProperties, arg) -> + yearweekToday( + DEFAULT_WEEK_OF_YEAR_MODE, functionProperties.getQueryStartClock())), + INTEGER, + TIME), impl(nullMissingHandling(DateTimeFunction::exprYearweekWithoutMode), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprYearweekWithoutMode), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprYearweekWithoutMode), INTEGER, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprYearweekWithoutMode), INTEGER, STRING), - implWithProperties(nullMissingHandlingWithProperties((functionProperties, time, modeArg) - -> yearweekToday( - modeArg, - functionProperties.getQueryStartClock())), INTEGER, TIME, INTEGER), + implWithProperties( + nullMissingHandlingWithProperties( + (functionProperties, time, modeArg) -> + yearweekToday(modeArg, functionProperties.getQueryStartClock())), + INTEGER, + TIME, + INTEGER), impl(nullMissingHandling(DateTimeFunction::exprYearweek), INTEGER, DATE, INTEGER), impl(nullMissingHandling(DateTimeFunction::exprYearweek), INTEGER, DATETIME, INTEGER), impl(nullMissingHandling(DateTimeFunction::exprYearweek), INTEGER, TIMESTAMP, INTEGER), - impl(nullMissingHandling(DateTimeFunction::exprYearweek), INTEGER, STRING, INTEGER) - ); + impl(nullMissingHandling(DateTimeFunction::exprYearweek), INTEGER, STRING, INTEGER)); } /** - * Formats date according to format specifier. First argument is date, second is format. - * Detailed supported signatures: - * (STRING, STRING) -> STRING - * (DATE, STRING) -> STRING - * (DATETIME, STRING) -> STRING - * (TIME, STRING) -> STRING + * Formats date according to format specifier. First argument is date, second is format.
+ * Detailed supported signatures:
+ * (STRING, STRING) -> STRING
+ * (DATE, STRING) -> STRING
+ * (DATETIME, STRING) -> STRING
+ * (TIME, STRING) -> STRING
* (TIMESTAMP, STRING) -> STRING */ private DefaultFunctionResolver date_format() { - return define(BuiltinFunctionName.DATE_FORMAT.getName(), - impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), - STRING, STRING, STRING), - impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), - STRING, DATE, STRING), - impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), - STRING, DATETIME, STRING), + return define( + BuiltinFunctionName.DATE_FORMAT.getName(), + impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), STRING, STRING, STRING), + impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), STRING, DATE, STRING), + impl( + nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), STRING, DATETIME, STRING), implWithProperties( nullMissingHandlingWithProperties( - (functionProperties, time, formatString) - -> DateTimeFormatterUtil.getFormattedDateOfToday( + (functionProperties, time, formatString) -> + DateTimeFormatterUtil.getFormattedDateOfToday( formatString, time, functionProperties.getQueryStartClock())), - STRING, TIME, STRING), - impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), - STRING, TIMESTAMP, STRING) - ); + STRING, + TIME, + STRING), + impl( + nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), + STRING, + TIMESTAMP, + STRING)); } - private ExprValue dayOfMonthToday(Clock clock) { return new ExprIntegerValue(LocalDateTime.now(clock).getDayOfMonth()); } @@ -1144,8 +1303,8 @@ private ExprValue dayOfWeekToday(Clock clock) { * @param interval ExprValue of Interval type, the temporal amount to add. * @return Datetime resulted from `interval` added to `datetime`. */ - private ExprValue exprAddDateInterval(FunctionProperties functionProperties, - ExprValue datetime, ExprValue interval) { + private ExprValue exprAddDateInterval( + FunctionProperties functionProperties, ExprValue datetime, ExprValue interval) { return exprDateApplyInterval(functionProperties, datetime, interval.intervalValue(), true); } @@ -1158,36 +1317,37 @@ private ExprValue exprAddDateInterval(FunctionProperties functionProperties, * @param isAdd A flag: true to isAdd, false to subtract. * @return Datetime calculated. */ - private ExprValue exprDateApplyInterval(FunctionProperties functionProperties, - ExprValue datetime, - TemporalAmount interval, - Boolean isAdd) { + private ExprValue exprDateApplyInterval( + FunctionProperties functionProperties, + ExprValue datetime, + TemporalAmount interval, + Boolean isAdd) { var dt = extractDateTime(datetime, functionProperties); return new ExprDatetimeValue(isAdd ? dt.plus(interval) : dt.minus(interval)); } /** - * Formats date according to format specifier. First argument is time, second is format. - * Detailed supported signatures: - * (STRING, STRING) -> STRING - * (DATE, STRING) -> STRING - * (DATETIME, STRING) -> STRING - * (TIME, STRING) -> STRING + * Formats date according to format specifier. First argument is time, second is format.
+ * Detailed supported signatures:
+ * (STRING, STRING) -> STRING
+ * (DATE, STRING) -> STRING
+ * (DATETIME, STRING) -> STRING
+ * (TIME, STRING) -> STRING
* (TIMESTAMP, STRING) -> STRING */ private DefaultFunctionResolver time_format() { - return define(BuiltinFunctionName.TIME_FORMAT.getName(), - impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), - STRING, STRING, STRING), - impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), - STRING, DATE, STRING), - impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), - STRING, DATETIME, STRING), - impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), - STRING, TIME, STRING), - impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), - STRING, TIMESTAMP, STRING) - ); + return define( + BuiltinFunctionName.TIME_FORMAT.getName(), + impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), STRING, STRING, STRING), + impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), STRING, DATE, STRING), + impl( + nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), STRING, DATETIME, STRING), + impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), STRING, TIME, STRING), + impl( + nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), + STRING, + TIMESTAMP, + STRING)); } /** @@ -1198,8 +1358,8 @@ private DefaultFunctionResolver time_format() { * @param days ExprValue of Long type, representing the number of days to add. * @return Date/Datetime resulted from days added to `datetime`. */ - private ExprValue exprAddDateDays(FunctionProperties functionProperties, - ExprValue datetime, ExprValue days) { + private ExprValue exprAddDateDays( + FunctionProperties functionProperties, ExprValue datetime, ExprValue days) { return exprDateApplyDays(functionProperties, datetime, days.longValue(), true); } @@ -1212,11 +1372,11 @@ private ExprValue exprAddDateDays(FunctionProperties functionProperties, * @param isAdd A flag: true to add, false to subtract. * @return Datetime calculated. */ - private ExprValue exprDateApplyDays(FunctionProperties functionProperties, - ExprValue datetime, Long days, Boolean isAdd) { + private ExprValue exprDateApplyDays( + FunctionProperties functionProperties, ExprValue datetime, Long days, Boolean isAdd) { if (datetime.type() == DATE) { - return new ExprDateValue(isAdd ? datetime.dateValue().plusDays(days) - : datetime.dateValue().minusDays(days)); + return new ExprDateValue( + isAdd ? datetime.dateValue().plusDays(days) : datetime.dateValue().minusDays(days)); } var dt = extractDateTime(datetime, functionProperties); return new ExprDatetimeValue(isAdd ? dt.plusDays(days) : dt.minusDays(days)); @@ -1231,12 +1391,16 @@ private ExprValue exprDateApplyDays(FunctionProperties functionProperties, * @param isAdd A flag: true to add, false to subtract. * @return A value calculated. */ - private ExprValue exprApplyTime(FunctionProperties functionProperties, - ExprValue temporal, ExprValue temporalDelta, Boolean isAdd) { + private ExprValue exprApplyTime( + FunctionProperties functionProperties, + ExprValue temporal, + ExprValue temporalDelta, + Boolean isAdd) { var interval = Duration.between(LocalTime.MIN, temporalDelta.timeValue()); - var result = isAdd - ? extractDateTime(temporal, functionProperties).plus(interval) - : extractDateTime(temporal, functionProperties).minus(interval); + var result = + isAdd + ? extractDateTime(temporal, functionProperties).plus(interval) + : extractDateTime(temporal, functionProperties).minus(interval); return temporal.type() == TIME ? new ExprTimeValue(result.toLocalTime()) : new ExprDatetimeValue(result); @@ -1250,18 +1414,18 @@ private ExprValue exprApplyTime(FunctionProperties functionProperties, * @param temporalDelta A Date/Time/Datetime/Timestamp object to add time from. * @return A value calculated. */ - private ExprValue exprAddTime(FunctionProperties functionProperties, - ExprValue temporal, ExprValue temporalDelta) { + private ExprValue exprAddTime( + FunctionProperties functionProperties, ExprValue temporal, ExprValue temporalDelta) { return exprApplyTime(functionProperties, temporal, temporalDelta, true); } /** - * CONVERT_TZ function implementation for ExprValue. - * Returns null for time zones outside of +13:00 and -12:00. + * CONVERT_TZ function implementation for ExprValue. Returns null for time zones outside of +13:00 + * and -12:00. * * @param startingDateTime ExprValue of DateTime that is being converted from - * @param fromTz ExprValue of time zone, representing the time to convert from. - * @param toTz ExprValue of time zone, representing the time to convert to. + * @param fromTz ExprValue of time zone, representing the time to convert from. + * @param toTz ExprValue of time zone, representing the time to convert to. * @return DateTime that has been converted to the to_tz timezone. */ private ExprValue exprConvertTZ(ExprValue startingDateTime, ExprValue fromTz, ExprValue toTz) { @@ -1278,8 +1442,7 @@ private ExprValue exprConvertTZ(ExprValue startingDateTime, ExprValue fromTz, Ex || !DateTimeUtils.isValidMySqlTimeZoneId(convertedToTz)) { return ExprNullValue.of(); } - ZonedDateTime zonedDateTime = - startingDateTime.datetimeValue().atZone(convertedFromTz); + ZonedDateTime zonedDateTime = startingDateTime.datetimeValue().atZone(convertedFromTz); return new ExprDatetimeValue( zonedDateTime.withZoneSameInstant(convertedToTz).toLocalDateTime()); @@ -1305,19 +1468,19 @@ private ExprValue exprDate(ExprValue exprValue) { } /** - * Calculate the value in days from one date to the other. - * Only the date parts of the values are used in the calculation. + * Calculate the value in days from one date to the other. Only the date parts of the values are + * used in the calculation. * * @param first The first value. * @param second The second value. * @return The diff. */ - private ExprValue exprDateDiff(FunctionProperties functionProperties, - ExprValue first, ExprValue second) { + private ExprValue exprDateDiff( + FunctionProperties functionProperties, ExprValue first, ExprValue second) { // java inverses the value, so we have to swap 1 and 2 - return new ExprLongValue(DAYS.between( - extractDate(second, functionProperties), - extractDate(first, functionProperties))); + return new ExprLongValue( + DAYS.between( + extractDate(second, functionProperties), extractDate(first, functionProperties))); } /** @@ -1357,10 +1520,7 @@ private ExprValue exprDateTime(ExprValue dateTime, ExprValue timeZone) { ldt = new ExprDatetimeValue(dateTime.stringValue()); toTz = defaultTimeZone; } - convertTZResult = exprConvertTZ( - ldt, - new ExprStringValue(toTz), - timeZone); + convertTZResult = exprConvertTZ(ldt, new ExprStringValue(toTz), timeZone); return convertTZResult; } @@ -1426,8 +1586,8 @@ private ExprValue exprDayOfYear(ExprValue date) { public ExprLongValue formatExtractFunction(ExprValue part, ExprValue datetime) { String partName = part.stringValue().toUpperCase(); LocalDateTime arg = datetime.datetimeValue(); - String text = arg.format(DateTimeFormatter.ofPattern( - extract_formats.get(partName), Locale.ENGLISH)); + String text = + arg.format(DateTimeFormatter.ofPattern(extract_formats.get(partName), Locale.ENGLISH)); return new ExprLongValue(Long.parseLong(text)); } @@ -1450,12 +1610,10 @@ private ExprValue exprExtract(ExprValue part, ExprValue datetime) { * @param time The time to be formatted. * @return A LONG */ - private ExprValue exprExtractForTime(FunctionProperties functionProperties, - ExprValue part, - ExprValue time) { + private ExprValue exprExtractForTime( + FunctionProperties functionProperties, ExprValue part, ExprValue time) { return formatExtractFunction( - part, - new ExprDatetimeValue(extractDateTime(time, functionProperties))); + part, new ExprDatetimeValue(extractDateTime(time, functionProperties))); } /** @@ -1484,9 +1642,8 @@ private ExprValue exprFromUnixTime(ExprValue time) { private LocalDateTime exprFromUnixTimeImpl(ExprValue time) { return LocalDateTime.ofInstant( - Instant.ofEpochSecond((long)Math.floor(time.doubleValue())), - UTC_ZONE_ID) - .withNano((int)((time.doubleValue() % 1) * 1E9)); + Instant.ofEpochSecond((long) Math.floor(time.doubleValue())), UTC_ZONE_ID) + .withNano((int) ((time.doubleValue() % 1) * 1E9)); } private ExprValue exprFromUnixTimeFormat(ExprValue time, ExprValue format) { @@ -1506,9 +1663,8 @@ private ExprValue exprFromUnixTimeFormat(ExprValue time, ExprValue format) { */ private ExprValue exprGetFormat(ExprValue type, ExprValue format) { if (formats.contains(type.stringValue().toLowerCase(), format.stringValue().toLowerCase())) { - return new ExprStringValue(formats.get( - type.stringValue().toLowerCase(), - format.stringValue().toLowerCase())); + return new ExprStringValue( + formats.get(type.stringValue().toLowerCase(), format.stringValue().toLowerCase())); } return ExprNullValue.of(); @@ -1521,8 +1677,7 @@ private ExprValue exprGetFormat(ExprValue type, ExprValue format) { * @return ExprValue. */ private ExprValue exprHour(ExprValue time) { - return new ExprIntegerValue( - HOURS.between(LocalTime.MIN, time.timeValue())); + return new ExprIntegerValue(HOURS.between(LocalTime.MIN, time.timeValue())); } /** @@ -1533,9 +1688,7 @@ private ExprValue exprHour(ExprValue time) { */ private LocalDate getLastDay(LocalDate today) { return LocalDate.of( - today.getYear(), - today.getMonth(), - today.getMonth().length(today.isLeapYear())); + today.getYear(), today.getMonth(), today.getMonth().length(today.isLeapYear())); } /** @@ -1559,12 +1712,15 @@ private ExprValue exprLastDayToday(Clock clock) { } /** - * Following MySQL, function receives arguments of type double and rounds them before use. - * Furthermore: - * - zero year interpreted as 2000 - * - negative year is not accepted - * - @dayOfYear should be greater than 1 - * - if @dayOfYear is greater than 365/366, calculation goes to the next year(s) + * Following MySQL, function receives arguments of type double and rounds them before use.
+ * Furthermore:
+ * + *
    + *
  • zero year interpreted as 2000 + *
  • negative year is not accepted + *
  • @dayOfYear should be greater than 1 + *
  • if @dayOfYear is greater than 365/366, calculation goes to the next year(s) + *
* * @param yearExpr year * @param dayOfYearExp day of the @year, starting from 1 @@ -1580,12 +1736,13 @@ private ExprValue exprMakeDate(ExprValue yearExpr, ExprValue dayOfYearExp) { if (0 == year) { year = 2000; } - return new ExprDateValue(LocalDate.ofYearDay((int)year, 1).plusDays(dayOfYear - 1)); + return new ExprDateValue(LocalDate.ofYearDay((int) year, 1).plusDays(dayOfYear - 1)); } /** * Following MySQL, function receives arguments of type double. @hour and @minute are rounded, * while @second used as is, including fraction part. + * * @param hourExpr hour * @param minuteExpr minute * @param secondExpr second @@ -1598,8 +1755,9 @@ private ExprValue exprMakeTime(ExprValue hourExpr, ExprValue minuteExpr, ExprVal if (0 > hour || 0 > minute || 0 > second) { return ExprNullValue.of(); } - return new ExprTimeValue(LocalTime.parse(String.format("%02d:%02d:%012.9f", - hour, minute, second), DateTimeFormatter.ISO_TIME)); + return new ExprTimeValue( + LocalTime.parse( + String.format("%02d:%02d:%012.9f", hour, minute, second), DateTimeFormatter.ISO_TIME)); } /** @@ -1620,8 +1778,7 @@ private ExprValue exprMicrosecond(ExprValue time) { * @return ExprValue. */ private ExprValue exprMinute(ExprValue time) { - return new ExprIntegerValue( - (MINUTES.between(LocalTime.MIN, time.timeValue()) % 60)); + return new ExprIntegerValue((MINUTES.between(LocalTime.MIN, time.timeValue()) % 60)); } /** @@ -1631,8 +1788,7 @@ private ExprValue exprMinute(ExprValue time) { * @return ExprValue. */ private ExprValue exprMinuteOfDay(ExprValue time) { - return new ExprIntegerValue( - MINUTES.between(LocalTime.MIN, time.timeValue())); + return new ExprIntegerValue(MINUTES.between(LocalTime.MIN, time.timeValue())); } /** @@ -1675,8 +1831,7 @@ private LocalDate parseDatePeriod(Integer period) { } /** - * Adds N months to period P (in the format YYMM or YYYYMM). - * Returns a value in the format YYYYMM. + * Adds N months to period P (in the format YYMM or YYYYMM). Returns a value in the format YYYYMM. * * @param period Period in the format YYMM or YYYYMM. * @param months Amount of months to add. @@ -1684,19 +1839,20 @@ private LocalDate parseDatePeriod(Integer period) { */ private ExprValue exprPeriodAdd(ExprValue period, ExprValue months) { // We should add a day to make string parsable and remove it afterwards - var input = period.integerValue() * 100 + 1; // adds 01 to end of the string + var input = period.integerValue() * 100 + 1; // adds 01 to end of the string var parsedDate = parseDatePeriod(input); if (parsedDate == null) { return ExprNullValue.of(); } var res = DATE_FORMATTER_LONG_YEAR.format(parsedDate.plusMonths(months.integerValue())); - return new ExprIntegerValue(Integer.parseInt( - res.substring(0, res.length() - 2))); // Remove the day part, .eg. 20070101 -> 200701 + return new ExprIntegerValue( + Integer.parseInt( + res.substring(0, res.length() - 2))); // Remove the day part, .eg. 20070101 -> 200701 } /** - * Returns the number of months between periods P1 and P2. - * P1 and P2 should be in the format YYMM or YYYYMM. + * Returns the number of months between periods P1 and P2. P1 and P2 should be in the format YYMM + * or YYYYMM. * * @param period1 Period in the format YYMM or YYYYMM. * @param period2 Period in the format YYMM or YYYYMM. @@ -1724,6 +1880,7 @@ private ExprValue exprQuarter(ExprValue date) { /** * Returns TIME value of sec_to_time function for an INTEGER or LONG arguments. + * * @param totalSeconds The total number of seconds * @return A TIME value */ @@ -1732,17 +1889,17 @@ private ExprValue exprSecToTime(ExprValue totalSeconds) { } /** - * Helper function which obtains the decimal portion of the seconds value passed in. - * Uses BigDecimal to prevent issues with math on floating point numbers. - * Return is formatted to be used with Duration.ofSeconds(); + * Helper function which obtains the decimal portion of the seconds value passed in. Uses + * BigDecimal to prevent issues with math on floating point numbers. Return is formatted to be + * used with Duration.ofSeconds(); * * @param seconds and ExprDoubleValue or ExprFloatValue for the seconds * @return A LONG representing the nanoseconds portion */ private long formatNanos(ExprValue seconds) { - //Convert ExprValue to BigDecimal + // Convert ExprValue to BigDecimal BigDecimal formattedNanos = BigDecimal.valueOf(seconds.doubleValue()); - //Extract only the nanosecond part + // Extract only the nanosecond part formattedNanos = formattedNanos.subtract(BigDecimal.valueOf(formattedNanos.intValue())); return formattedNanos.scaleByPowerOfTen(9).longValue(); @@ -1750,6 +1907,7 @@ private long formatNanos(ExprValue seconds) { /** * Returns TIME value of sec_to_time function for FLOAT or DOUBLE arguments. + * * @param totalSeconds The total number of seconds * @return A TIME value */ @@ -1767,8 +1925,7 @@ private ExprValue exprSecToTimeWithNanos(ExprValue totalSeconds) { * @return ExprValue. */ private ExprValue exprSecond(ExprValue time) { - return new ExprIntegerValue( - (SECONDS.between(LocalTime.MIN, time.timeValue()) % 60)); + return new ExprIntegerValue((SECONDS.between(LocalTime.MIN, time.timeValue()) % 60)); } /** @@ -1779,8 +1936,8 @@ private ExprValue exprSecond(ExprValue time) { * @param days ExprValue of Long type, representing the number of days to subtract. * @return Date/Datetime resulted from days subtracted to date. */ - private ExprValue exprSubDateDays(FunctionProperties functionProperties, - ExprValue date, ExprValue days) { + private ExprValue exprSubDateDays( + FunctionProperties functionProperties, ExprValue date, ExprValue days) { return exprDateApplyDays(functionProperties, date, days.longValue(), false); } @@ -1792,8 +1949,8 @@ private ExprValue exprSubDateDays(FunctionProperties functionProperties, * @param expr ExprValue of Interval type, the temporal amount to subtract. * @return Datetime resulted from expr subtracted to `datetime`. */ - private ExprValue exprSubDateInterval(FunctionProperties functionProperties, - ExprValue datetime, ExprValue expr) { + private ExprValue exprSubDateInterval( + FunctionProperties functionProperties, ExprValue datetime, ExprValue expr) { return exprDateApplyInterval(functionProperties, datetime, expr.intervalValue(), false); } @@ -1804,14 +1961,13 @@ private ExprValue exprSubDateInterval(FunctionProperties functionProperties, * @param temporalDelta A Date/Time/Datetime/Timestamp to subtract time from. * @return A value calculated. */ - private ExprValue exprSubTime(FunctionProperties functionProperties, - ExprValue temporal, ExprValue temporalDelta) { + private ExprValue exprSubTime( + FunctionProperties functionProperties, ExprValue temporal, ExprValue temporalDelta) { return exprApplyTime(functionProperties, temporal, temporalDelta, false); } - private ExprValue exprStrToDate(FunctionProperties fp, - ExprValue dateTimeExpr, - ExprValue formatStringExp) { + private ExprValue exprStrToDate( + FunctionProperties fp, ExprValue dateTimeExpr, ExprValue formatStringExp) { return DateTimeFormatterUtil.parseStringWithDateOrTime(fp, dateTimeExpr, formatStringExp); } @@ -1838,8 +1994,8 @@ private ExprValue exprTime(ExprValue exprValue) { */ private ExprValue exprTimeDiff(ExprValue first, ExprValue second) { // java inverses the value, so we have to swap 1 and 2 - return new ExprTimeValue(LocalTime.MIN.plus( - Duration.between(second.timeValue(), first.timeValue()))); + return new ExprTimeValue( + LocalTime.MIN.plus(Duration.between(second.timeValue(), first.timeValue()))); } /** @@ -1852,9 +2008,8 @@ private ExprValue exprTimeToSec(ExprValue time) { return new ExprLongValue(time.timeValue().toSecondOfDay()); } - private ExprValue exprTimestampAdd(ExprValue partExpr, - ExprValue amountExpr, - ExprValue datetimeExpr) { + private ExprValue exprTimestampAdd( + ExprValue partExpr, ExprValue amountExpr, ExprValue datetimeExpr) { String part = partExpr.stringValue(); int amount = amountExpr.integerValue(); LocalDateTime datetime = datetimeExpr.datetimeValue(); @@ -1895,13 +2050,9 @@ private ExprValue exprTimestampAdd(ExprValue partExpr, return new ExprDatetimeValue(datetime.plus(amount, temporalUnit)); } - private ExprValue exprTimestampAddForTimeType(Clock clock, - ExprValue partExpr, - ExprValue amountExpr, - ExprValue timeExpr) { - LocalDateTime datetime = LocalDateTime.of( - formatNow(clock).toLocalDate(), - timeExpr.timeValue()); + private ExprValue exprTimestampAddForTimeType( + Clock clock, ExprValue partExpr, ExprValue amountExpr, ExprValue timeExpr) { + LocalDateTime datetime = LocalDateTime.of(formatNow(clock).toLocalDate(), timeExpr.timeValue()); return exprTimestampAdd(partExpr, amountExpr, new ExprDatetimeValue(datetime)); } @@ -1942,19 +2093,13 @@ private ExprValue getTimeDifference(String part, LocalDateTime startTime, LocalD } private ExprValue exprTimestampDiff( - ExprValue partExpr, - ExprValue startTimeExpr, - ExprValue endTimeExpr) { + ExprValue partExpr, ExprValue startTimeExpr, ExprValue endTimeExpr) { return getTimeDifference( - partExpr.stringValue(), - startTimeExpr.datetimeValue(), - endTimeExpr.datetimeValue()); + partExpr.stringValue(), startTimeExpr.datetimeValue(), endTimeExpr.datetimeValue()); } - private ExprValue exprTimestampDiffForTimeType(FunctionProperties fp, - ExprValue partExpr, - ExprValue startTimeExpr, - ExprValue endTimeExpr) { + private ExprValue exprTimestampDiffForTimeType( + FunctionProperties fp, ExprValue partExpr, ExprValue startTimeExpr, ExprValue endTimeExpr) { return getTimeDifference( partExpr.stringValue(), extractDateTime(startTimeExpr, fp), @@ -1988,8 +2133,8 @@ private ExprValue exprUtcTime(FunctionProperties functionProperties) { * @return ExprValue. */ private ExprValue exprUtcTimeStamp(FunctionProperties functionProperties) { - var zdt = ZonedDateTime.now(functionProperties.getQueryStartClock()) - .withZoneSameInstant(UTC_ZONE_ID); + var zdt = + ZonedDateTime.now(functionProperties.getQueryStartClock()).withZoneSameInstant(UTC_ZONE_ID); return new ExprDatetimeValue(zdt.toLocalDateTime()); } @@ -2027,25 +2172,25 @@ private DateTimeFormatter getFormatter(int dateAsInt) { throw new DateTimeException("Integer argument was out of range"); } - //Check below from YYYYMMDD - MMDD which format should be used + // Check below from YYYYMMDD - MMDD which format should be used switch (length) { - //Check if dateAsInt is at least 8 digits long + // Check if dateAsInt is at least 8 digits long case FULL_DATE_LENGTH: return DATE_FORMATTER_LONG_YEAR; - //Check if dateAsInt is at least 6 digits long + // Check if dateAsInt is at least 6 digits long case SHORT_DATE_LENGTH: return DATE_FORMATTER_SHORT_YEAR; - //Check if dateAsInt is at least 5 digits long + // Check if dateAsInt is at least 5 digits long case SINGLE_DIGIT_YEAR_DATE_LENGTH: return DATE_FORMATTER_SINGLE_DIGIT_YEAR; - //Check if dateAsInt is at least 4 digits long + // Check if dateAsInt is at least 4 digits long case NO_YEAR_DATE_LENGTH: return DATE_FORMATTER_NO_YEAR; - //Check if dateAsInt is at least 3 digits long + // Check if dateAsInt is at least 3 digits long case SINGLE_DIGIT_MONTH_DATE_LENGTH: return DATE_FORMATTER_SINGLE_DIGIT_MONTH; @@ -2064,15 +2209,16 @@ private DateTimeFormatter getFormatter(int dateAsInt) { */ private ExprValue exprToSecondsForIntType(ExprValue dateExpr) { try { - //Attempt to parse integer argument as date - LocalDate date = LocalDate.parse(String.valueOf(dateExpr.integerValue()), - getFormatter(dateExpr.integerValue())); + // Attempt to parse integer argument as date + LocalDate date = + LocalDate.parse( + String.valueOf(dateExpr.integerValue()), getFormatter(dateExpr.integerValue())); - return new ExprLongValue(date.toEpochSecond(LocalTime.MIN, ZoneOffset.UTC) - + DAYS_0000_TO_1970 * SECONDS_PER_DAY); + return new ExprLongValue( + date.toEpochSecond(LocalTime.MIN, ZoneOffset.UTC) + DAYS_0000_TO_1970 * SECONDS_PER_DAY); } catch (DateTimeException ignored) { - //Return null if parsing error + // Return null if parsing error return ExprNullValue.of(); } } @@ -2121,12 +2267,14 @@ private ExprValue unixTimeStampOf(ExprValue value) { private Double unixTimeStampOfImpl(ExprValue value) { // Also, according to MySQL documentation: // The date argument may be a DATE, DATETIME, or TIMESTAMP ... - switch ((ExprCoreType)value.type()) { - case DATE: return value.dateValue().toEpochSecond(LocalTime.MIN, ZoneOffset.UTC) + 0d; - case DATETIME: return value.datetimeValue().toEpochSecond(ZoneOffset.UTC) - + value.datetimeValue().getNano() / 1E9; - case TIMESTAMP: return value.timestampValue().getEpochSecond() - + value.timestampValue().getNano() / 1E9; + switch ((ExprCoreType) value.type()) { + case DATE: + return value.dateValue().toEpochSecond(LocalTime.MIN, ZoneOffset.UTC) + 0d; + case DATETIME: + return value.datetimeValue().toEpochSecond(ZoneOffset.UTC) + + value.datetimeValue().getNano() / 1E9; + case TIMESTAMP: + return value.timestampValue().getEpochSecond() + value.timestampValue().getNano() / 1E9; default: // ... or a number in YYMMDD, YYMMDDhhmmss, YYYYMMDD, or YYYYMMDDhhmmss format. // If the argument includes a time part, it may optionally include a fractional @@ -2172,8 +2320,8 @@ private Double unixTimeStampOfImpl(ExprValue value) { } /** - * Week for date implementation for ExprValue. - * When mode is not specified default value mode 0 is used for default_week_format. + * Week for date implementation for ExprValue. When mode is not specified default value mode 0 is + * used for default_week_format. * * @param date ExprValue of Date/Datetime/Timestamp/String type. * @return ExprValue. @@ -2203,12 +2351,11 @@ private ExprIntegerValue extractYearweek(LocalDate date, int mode) { // Needed to align with MySQL. Due to how modes for this function work. // See description of modes here ... // https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_week - int modeJava = CalendarLookup.getWeekNumber(mode, date) != 0 ? mode : - mode <= 4 ? 2 : - 7; + int modeJava = CalendarLookup.getWeekNumber(mode, date) != 0 ? mode : mode <= 4 ? 2 : 7; - int formatted = CalendarLookup.getYearNumber(modeJava, date) * 100 - + CalendarLookup.getWeekNumber(modeJava, date); + int formatted = + CalendarLookup.getYearNumber(modeJava, date) * 100 + + CalendarLookup.getWeekNumber(modeJava, date); return new ExprIntegerValue(formatted); } @@ -2224,8 +2371,8 @@ private ExprValue exprYearweek(ExprValue date, ExprValue mode) { } /** - * Yearweek for date implementation for ExprValue. - * When mode is not specified default value mode 0 is used. + * Yearweek for date implementation for ExprValue. When mode is not specified default value mode 0 + * is used. * * @param date ExprValue of Date/Datetime/Time/Timestamp/String type. * @return ExprValue. @@ -2248,19 +2395,22 @@ private LocalDateTime formatNow(Clock clock) { /** * Prepare LocalDateTime value. Truncate fractional second part according to the argument. - * @param fsp argument is given to specify a fractional seconds precision from 0 to 6, - * the return value includes a fractional seconds part of that many digits. + * + * @param fsp argument is given to specify a fractional seconds precision from 0 to 6, the return + * value includes a fractional seconds part of that many digits. * @return LocalDateTime object. */ - private LocalDateTime formatNow(Clock clock, Integer fsp) { + private LocalDateTime formatNow(Clock clock, Integer fsp) { var res = LocalDateTime.now(clock); var defaultPrecision = 9; // There are 10^9 nanoseconds in one second if (fsp < 0 || fsp > 6) { // Check that the argument is in the allowed range [0, 6] throw new IllegalArgumentException( String.format("Invalid `fsp` value: %d, allowed 0 to 6", fsp)); } - var nano = new BigDecimal(res.getNano()) - .setScale(fsp - defaultPrecision, RoundingMode.DOWN).intValue(); + var nano = + new BigDecimal(res.getNano()) + .setScale(fsp - defaultPrecision, RoundingMode.DOWN) + .intValue(); return res.withNano(nano); } } diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/IntervalClause.java b/core/src/main/java/org/opensearch/sql/expression/datetime/IntervalClause.java index 3df8489b20..5170d49fc7 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/IntervalClause.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/IntervalClause.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.datetime; import static org.opensearch.sql.data.model.ExprValueUtils.getIntegerValue; @@ -45,7 +44,8 @@ public void register(BuiltinFunctionRepository repository) { } private DefaultFunctionResolver interval() { - return define(BuiltinFunctionName.INTERVAL.getName(), + return define( + BuiltinFunctionName.INTERVAL.getName(), impl(nullMissingHandling(IntervalClause::interval), INTERVAL, INTEGER, STRING), impl(nullMissingHandling(IntervalClause::interval), INTERVAL, LONG, STRING)); } diff --git a/core/src/main/java/org/opensearch/sql/expression/env/Environment.java b/core/src/main/java/org/opensearch/sql/expression/env/Environment.java index d96d0c0a50..b1377f22ae 100644 --- a/core/src/main/java/org/opensearch/sql/expression/env/Environment.java +++ b/core/src/main/java/org/opensearch/sql/expression/env/Environment.java @@ -3,33 +3,30 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.env; /** * The definition of the environment. - * @param the type of expression + * + * @param the type of expression * @param the type of expression value */ public interface Environment { - /** - * resolve the value of expression from the environment. - */ + /** resolve the value of expression from the environment. */ V resolve(E var); /** * Extend the environment. * - * @param env environment - * @param expr expression. - * @param value expression value. - * @param the type of expression + * @param env environment + * @param expr expression. + * @param value expression value. + * @param the type of expression * @param the type of expression value * @return extended environment. */ - static Environment extendEnv( - Environment env, E expr, V value) { + static Environment extendEnv(Environment env, E expr, V value) { return var -> { if (var.equals(expr)) { return value; diff --git a/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.java b/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.java index 728712f537..f50fa927b8 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.java @@ -12,15 +12,11 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -/** - * Builtin Function Name. - */ +/** Builtin Function Name. */ @Getter @RequiredArgsConstructor public enum BuiltinFunctionName { - /** - * Mathematical Functions. - */ + /** Mathematical Functions. */ ABS(FunctionName.of("abs")), CEIL(FunctionName.of("ceil")), CEILING(FunctionName.of("ceiling")), @@ -59,9 +55,7 @@ public enum BuiltinFunctionName { SIN(FunctionName.of("sin")), TAN(FunctionName.of("tan")), - /** - * Date and Time Functions. - */ + /** Date and Time Functions. */ ADDDATE(FunctionName.of("adddate")), ADDTIME(FunctionName.of("addtime")), CONVERT_TZ(FunctionName.of("convert_tz")), @@ -135,14 +129,10 @@ public enum BuiltinFunctionName { LOCALTIMESTAMP(FunctionName.of("localtimestamp")), SYSDATE(FunctionName.of("sysdate")), - /** - * Text Functions. - */ + /** Text Functions. */ TOSTRING(FunctionName.of("tostring")), - /** - * Arithmetic Operators. - */ + /** Arithmetic Operators. */ ADD(FunctionName.of("+")), ADDFUNCTION(FunctionName.of("add")), DIVIDE(FunctionName.of("/")), @@ -155,9 +145,7 @@ public enum BuiltinFunctionName { SUBTRACT(FunctionName.of("-")), SUBTRACTFUNCTION(FunctionName.of("subtract")), - /** - * Boolean Operators. - */ + /** Boolean Operators. */ AND(FunctionName.of("and")), OR(FunctionName.of("or")), XOR(FunctionName.of("xor")), @@ -171,9 +159,7 @@ public enum BuiltinFunctionName { LIKE(FunctionName.of("like")), NOT_LIKE(FunctionName.of("not like")), - /** - * Aggregation Function. - */ + /** Aggregation Function. */ AVG(FunctionName.of("avg")), SUM(FunctionName.of("sum")), COUNT(FunctionName.of("count")), @@ -192,9 +178,7 @@ public enum BuiltinFunctionName { // Not always an aggregation query NESTED(FunctionName.of("nested")), - /** - * Text Functions. - */ + /** Text Functions. */ ASCII(FunctionName.of("ascii")), CONCAT(FunctionName.of("concat")), CONCAT_WS(FunctionName.of("concat_ws")), @@ -215,9 +199,7 @@ public enum BuiltinFunctionName { TRIM(FunctionName.of("trim")), UPPER(FunctionName.of("upper")), - /** - * NULL Test. - */ + /** NULL Test. */ IS_NULL(FunctionName.of("is null")), IS_NOT_NULL(FunctionName.of("is not null")), IFNULL(FunctionName.of("ifnull")), @@ -231,9 +213,7 @@ public enum BuiltinFunctionName { INTERVAL(FunctionName.of("interval")), - /** - * Data Type Convert Function. - */ + /** Data Type Convert Function. */ CAST_TO_STRING(FunctionName.of("cast_to_string")), CAST_TO_BYTE(FunctionName.of("cast_to_byte")), CAST_TO_SHORT(FunctionName.of("cast_to_short")), @@ -248,9 +228,7 @@ public enum BuiltinFunctionName { CAST_TO_DATETIME(FunctionName.of("cast_to_datetime")), TYPEOF(FunctionName.of("typeof")), - /** - * Relevance Function. - */ + /** Relevance Function. */ MATCH(FunctionName.of("match")), SIMPLE_QUERY_STRING(FunctionName.of("simple_query_string")), MATCH_PHRASE(FunctionName.of("match_phrase")), @@ -264,9 +242,7 @@ public enum BuiltinFunctionName { SCOREQUERY(FunctionName.of("scorequery")), SCORE_QUERY(FunctionName.of("score_query")), - /** - * Legacy Relevance Function. - */ + /** Legacy Relevance Function. */ QUERY(FunctionName.of("query")), MATCH_QUERY(FunctionName.of("match_query")), MATCHQUERY(FunctionName.of("matchquery")), diff --git a/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionRepository.java b/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionRepository.java index 0eb11a9280..2e16d5f01f 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionRepository.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionRepository.java @@ -38,10 +38,8 @@ import org.opensearch.sql.storage.StorageEngine; /** - * Builtin Function Repository. - * Repository registers datasource specific functions under datasource namespace and - * universal functions under default namespace. - * + * Builtin Function Repository. Repository registers datasource specific functions under datasource + * namespace and universal functions under default namespace. */ public class BuiltinFunctionRepository { @@ -96,23 +94,20 @@ public void register(FunctionResolver resolver) { functionResolverMap.put(resolver.getFunctionName(), resolver); } - /** - * Compile FunctionExpression using core function resolver. - * - */ - public FunctionImplementation compile(FunctionProperties functionProperties, - FunctionName functionName, List expressions) { + /** Compile FunctionExpression using core function resolver. */ + public FunctionImplementation compile( + FunctionProperties functionProperties, + FunctionName functionName, + List expressions) { return compile(functionProperties, Collections.emptyList(), functionName, expressions); } - - /** - * Compile FunctionExpression within {@link StorageEngine} provided {@link FunctionResolver}. - */ - public FunctionImplementation compile(FunctionProperties functionProperties, - Collection dataSourceFunctionResolver, - FunctionName functionName, - List expressions) { + /** Compile FunctionExpression within {@link StorageEngine} provided {@link FunctionResolver}. */ + public FunctionImplementation compile( + FunctionProperties functionProperties, + Collection dataSourceFunctionResolver, + FunctionName functionName, + List expressions) { FunctionBuilder resolvedFunctionBuilder = resolve( dataSourceFunctionResolver, @@ -134,8 +129,9 @@ public FunctionImplementation compile(FunctionProperties functionProperties, public FunctionBuilder resolve( Collection dataSourceFunctionResolver, FunctionSignature functionSignature) { - Map dataSourceFunctionMap = dataSourceFunctionResolver.stream() - .collect(Collectors.toMap(FunctionResolver::getFunctionName, t -> t)); + Map dataSourceFunctionMap = + dataSourceFunctionResolver.stream() + .collect(Collectors.toMap(FunctionResolver::getFunctionName, t -> t)); // first, resolve in datasource provide function resolver. // second, resolve in builtin function resolver. @@ -171,14 +167,13 @@ private Optional resolve( } /** - * Wrap resolved function builder's arguments by cast function to cast input expression value - * to value of target type at runtime. For example, suppose unresolved signature is - * equal(BOOL,STRING) and its resolved function builder is F with signature equal(BOOL,BOOL). - * In this case, wrap F and return equal(BOOL, cast_to_bool(STRING)). + * Wrap resolved function builder's arguments by cast function to cast input expression value to + * value of target type at runtime. For example, suppose unresolved signature is + * equal(BOOL,STRING) and its resolved function builder is F with signature equal(BOOL,BOOL). In + * this case, wrap F and return equal(BOOL, cast_to_bool(STRING)). */ - private FunctionBuilder castArguments(List sourceTypes, - List targetTypes, - FunctionBuilder funcBuilder) { + private FunctionBuilder castArguments( + List sourceTypes, List targetTypes, FunctionBuilder funcBuilder) { return (fp, arguments) -> { List argsCasted = new ArrayList<>(); for (int i = 0; i < arguments.size(); i++) { @@ -208,10 +203,10 @@ private boolean isCastRequired(ExprType sourceType, ExprType targetType) { private Function cast(Expression arg, ExprType targetType) { FunctionName castFunctionName = getCastFunctionName(targetType); if (castFunctionName == null) { - throw new ExpressionEvaluationException(StringUtils.format( - "Type conversion to type %s is not supported", targetType)); + throw new ExpressionEvaluationException( + StringUtils.format("Type conversion to type %s is not supported", targetType)); } - return functionProperties -> (Expression) compile(functionProperties, - castFunctionName, List.of(arg)); + return functionProperties -> + (Expression) compile(functionProperties, castFunctionName, List.of(arg)); } } diff --git a/core/src/main/java/org/opensearch/sql/expression/function/DefaultFunctionResolver.java b/core/src/main/java/org/opensearch/sql/expression/function/DefaultFunctionResolver.java index a28fa7e0ad..5d0f31594b 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/DefaultFunctionResolver.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/DefaultFunctionResolver.java @@ -18,52 +18,53 @@ import org.opensearch.sql.exception.ExpressionEvaluationException; /** - * The Function Resolver hold the overload {@link FunctionBuilder} implementation. - * is composed by {@link FunctionName} which identified the function name - * and a map of {@link FunctionSignature} and {@link FunctionBuilder} - * to represent the overloaded implementation + * The Function Resolver hold the overload {@link FunctionBuilder} implementation. is composed by + * {@link FunctionName} which identified the function name and a map of {@link FunctionSignature} + * and {@link FunctionBuilder} to represent the overloaded implementation */ @Builder @RequiredArgsConstructor public class DefaultFunctionResolver implements FunctionResolver { - @Getter - private final FunctionName functionName; + @Getter private final FunctionName functionName; + @Singular("functionBundle") private final Map functionBundle; /** - * Resolve the {@link FunctionBuilder} by using input {@link FunctionSignature}. - * If the {@link FunctionBuilder} exactly match the input {@link FunctionSignature}, return it. - * If applying the widening rule, found the most match one, return it. - * If nothing found, throw {@link ExpressionEvaluationException} + * Resolve the {@link FunctionBuilder} by using input {@link FunctionSignature}. If the {@link + * FunctionBuilder} exactly match the input {@link FunctionSignature}, return it. If applying the + * widening rule, found the most match one, return it. If nothing found, throw {@link + * ExpressionEvaluationException} * * @return function signature and its builder */ @Override public Pair resolve(FunctionSignature unresolvedSignature) { - PriorityQueue> functionMatchQueue = new PriorityQueue<>( - Map.Entry.comparingByKey()); + PriorityQueue> functionMatchQueue = + new PriorityQueue<>(Map.Entry.comparingByKey()); for (FunctionSignature functionSignature : functionBundle.keySet()) { functionMatchQueue.add( - new AbstractMap.SimpleEntry<>(unresolvedSignature.match(functionSignature), - functionSignature)); + new AbstractMap.SimpleEntry<>( + unresolvedSignature.match(functionSignature), functionSignature)); } Map.Entry bestMatchEntry = functionMatchQueue.peek(); if (FunctionSignature.isVarArgFunction(bestMatchEntry.getValue().getParamTypeList()) - && (unresolvedSignature.getParamTypeList().isEmpty() + && (unresolvedSignature.getParamTypeList().isEmpty() || unresolvedSignature.getParamTypeList().size() > 9)) { throw new ExpressionEvaluationException( - String.format("%s function expected 1-9 arguments, but got %d", - functionName, unresolvedSignature.getParamTypeList().size())); + String.format( + "%s function expected 1-9 arguments, but got %d", + functionName, unresolvedSignature.getParamTypeList().size())); } if (FunctionSignature.NOT_MATCH.equals(bestMatchEntry.getKey()) - && !FunctionSignature.isVarArgFunction(bestMatchEntry.getValue().getParamTypeList())) { + && !FunctionSignature.isVarArgFunction(bestMatchEntry.getValue().getParamTypeList())) { throw new ExpressionEvaluationException( - String.format("%s function expected %s, but get %s", functionName, + String.format( + "%s function expected %s, but get %s", + functionName, formatFunctions(functionBundle.keySet()), - unresolvedSignature.formatTypes() - )); + unresolvedSignature.formatTypes())); } else { FunctionSignature resolvedSignature = bestMatchEntry.getValue(); return Pair.of(resolvedSignature, functionBundle.get(resolvedSignature)); @@ -71,7 +72,8 @@ public Pair resolve(FunctionSignature unreso } private String formatFunctions(Set functionSignatures) { - return functionSignatures.stream().map(FunctionSignature::formatTypes) + return functionSignatures.stream() + .map(FunctionSignature::formatTypes) .collect(Collectors.joining(",", "{", "}")); } } diff --git a/core/src/main/java/org/opensearch/sql/expression/function/FunctionBuilder.java b/core/src/main/java/org/opensearch/sql/expression/function/FunctionBuilder.java index b6e32a1d27..a529885c16 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/FunctionBuilder.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/FunctionBuilder.java @@ -3,15 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.function; import java.util.List; import org.opensearch.sql.expression.Expression; /** - * The definition of function which create {@link FunctionImplementation} - * from input {@link Expression} list. + * The definition of function which create {@link FunctionImplementation} from input {@link + * Expression} list. */ public interface FunctionBuilder { @@ -19,7 +18,7 @@ public interface FunctionBuilder { * Create {@link FunctionImplementation} from input {@link Expression} list. * * @param functionProperties context for function execution. - * @param arguments {@link Expression} list. + * @param arguments {@link Expression} list. * @return {@link FunctionImplementation} */ FunctionImplementation apply(FunctionProperties functionProperties, List arguments); diff --git a/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java b/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java index c57d96caea..8ebbfd3a3c 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.function; import java.util.Arrays; @@ -21,21 +20,19 @@ import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.DefaultFunctionResolver.DefaultFunctionResolverBuilder; -/** - * Function Define Utility. - */ +/** Function Define Utility. */ @UtilityClass public class FunctionDSL { /** * Define overloaded function with implementation. * * @param functionName function name. - * @param functions a list of function implementation. + * @param functions a list of function implementation. * @return FunctionResolver. */ - public static DefaultFunctionResolver define(FunctionName functionName, - SerializableFunction>... functions) { + public static DefaultFunctionResolver define( + FunctionName functionName, + SerializableFunction>... functions) { return define(functionName, List.of(functions)); } @@ -43,11 +40,13 @@ public static DefaultFunctionResolver define(FunctionName functionName, * Define overloaded function with implementation. * * @param functionName function name. - * @param functions a list of function implementation. + * @param functions a list of function implementation. * @return FunctionResolver. */ - public static DefaultFunctionResolver define(FunctionName functionName, List< - SerializableFunction>> functions) { + public static DefaultFunctionResolver define( + FunctionName functionName, + List>> + functions) { DefaultFunctionResolverBuilder builder = DefaultFunctionResolver.builder(); builder.functionName(functionName); @@ -58,7 +57,6 @@ public static DefaultFunctionResolver define(FunctionName functionName, List< return builder.build(); } - /** * Implementation of no args function that uses FunctionProperties. * @@ -67,8 +65,8 @@ public static DefaultFunctionResolver define(FunctionName functionName, List< * @return no args function implementation. */ public static SerializableFunction> - implWithProperties(SerializableFunction function, - ExprType returnType) { + implWithProperties( + SerializableFunction function, ExprType returnType) { return functionName -> { FunctionSignature functionSignature = new FunctionSignature(functionName, Collections.emptyList()); @@ -95,53 +93,54 @@ public String toString() { } /** - * Implementation of a function that takes one argument, returns a value, and - * requires FunctionProperties to complete. + * Implementation of a function that takes one argument, returns a value, and requires + * FunctionProperties to complete. * - * @param function {@link ExprValue} based unary function. + * @param function {@link ExprValue} based unary function. * @param returnType return type. * @param argsType argument type. * @return Unary Function Implementation. */ public static SerializableFunction> implWithProperties( - SerializableBiFunction function, - ExprType returnType, - ExprType argsType) { + SerializableBiFunction function, + ExprType returnType, + ExprType argsType) { return functionName -> { FunctionSignature functionSignature = new FunctionSignature(functionName, Collections.singletonList(argsType)); FunctionBuilder functionBuilder = - (functionProperties, arguments) -> new FunctionExpression(functionName, arguments) { - @Override - public ExprValue valueOf(Environment valueEnv) { - ExprValue value = arguments.get(0).valueOf(valueEnv); - return function.apply(functionProperties, value); - } - - @Override - public ExprType type() { - return returnType; - } - - @Override - public String toString() { - return String.format("%s(%s)", functionName, - arguments.stream() - .map(Object::toString) - .collect(Collectors.joining(", "))); - } - }; + (functionProperties, arguments) -> + new FunctionExpression(functionName, arguments) { + @Override + public ExprValue valueOf(Environment valueEnv) { + ExprValue value = arguments.get(0).valueOf(valueEnv); + return function.apply(functionProperties, value); + } + + @Override + public ExprType type() { + return returnType; + } + + @Override + public String toString() { + return String.format( + "%s(%s)", + functionName, + arguments.stream().map(Object::toString).collect(Collectors.joining(", "))); + } + }; return Pair.of(functionSignature, functionBuilder); }; } /** - * Implementation of a function that takes two arguments, returns a value, and - * requires FunctionProperties to complete. + * Implementation of a function that takes two arguments, returns a value, and requires + * FunctionProperties to complete. * - * @param function {@link ExprValue} based Binary function. + * @param function {@link ExprValue} based Binary function. * @param returnType return type. * @param args1Type first argument type. * @param args2Type second argument type. @@ -149,45 +148,46 @@ public String toString() { */ public static SerializableFunction> implWithProperties( - SerializableTriFunction function, - ExprType returnType, - ExprType args1Type, - ExprType args2Type) { + SerializableTriFunction function, + ExprType returnType, + ExprType args1Type, + ExprType args2Type) { return functionName -> { FunctionSignature functionSignature = new FunctionSignature(functionName, Arrays.asList(args1Type, args2Type)); FunctionBuilder functionBuilder = - (functionProperties, arguments) -> new FunctionExpression(functionName, arguments) { - @Override - public ExprValue valueOf(Environment valueEnv) { - ExprValue arg1 = arguments.get(0).valueOf(valueEnv); - ExprValue arg2 = arguments.get(1).valueOf(valueEnv); - return function.apply(functionProperties, arg1, arg2); - } - - @Override - public ExprType type() { - return returnType; - } - - @Override - public String toString() { - return String.format("%s(%s)", functionName, - arguments.stream() - .map(Object::toString) - .collect(Collectors.joining(", "))); - } - }; + (functionProperties, arguments) -> + new FunctionExpression(functionName, arguments) { + @Override + public ExprValue valueOf(Environment valueEnv) { + ExprValue arg1 = arguments.get(0).valueOf(valueEnv); + ExprValue arg2 = arguments.get(1).valueOf(valueEnv); + return function.apply(functionProperties, arg1, arg2); + } + + @Override + public ExprType type() { + return returnType; + } + + @Override + public String toString() { + return String.format( + "%s(%s)", + functionName, + arguments.stream().map(Object::toString).collect(Collectors.joining(", "))); + } + }; return Pair.of(functionSignature, functionBuilder); }; } /** - * Implementation of a function that takes three arguments, returns a value, and - * requires FunctionProperties to complete. + * Implementation of a function that takes three arguments, returns a value, and requires + * FunctionProperties to complete. * - * @param function {@link ExprValue} based Binary function. + * @param function {@link ExprValue} based Binary function. * @param returnType return type. * @param args1Type first argument type. * @param args2Type second argument type. @@ -196,43 +196,40 @@ public String toString() { */ public static SerializableFunction> implWithProperties( - SerializableQuadFunction< - FunctionProperties, - ExprValue, - ExprValue, - ExprValue, - ExprValue> function, - ExprType returnType, - ExprType args1Type, - ExprType args2Type, - ExprType args3Type) { + SerializableQuadFunction + function, + ExprType returnType, + ExprType args1Type, + ExprType args2Type, + ExprType args3Type) { return functionName -> { FunctionSignature functionSignature = new FunctionSignature(functionName, Arrays.asList(args1Type, args2Type, args3Type)); FunctionBuilder functionBuilder = - (functionProperties, arguments) -> new FunctionExpression(functionName, arguments) { - @Override - public ExprValue valueOf(Environment valueEnv) { - ExprValue arg1 = arguments.get(0).valueOf(valueEnv); - ExprValue arg2 = arguments.get(1).valueOf(valueEnv); - ExprValue arg3 = arguments.get(2).valueOf(valueEnv); - return function.apply(functionProperties, arg1, arg2, arg3); - } - - @Override - public ExprType type() { - return returnType; - } - - @Override - public String toString() { - return String.format("%s(%s)", functionName, - arguments.stream() - .map(Object::toString) - .collect(Collectors.joining(", "))); - } - }; + (functionProperties, arguments) -> + new FunctionExpression(functionName, arguments) { + @Override + public ExprValue valueOf(Environment valueEnv) { + ExprValue arg1 = arguments.get(0).valueOf(valueEnv); + ExprValue arg2 = arguments.get(1).valueOf(valueEnv); + ExprValue arg3 = arguments.get(2).valueOf(valueEnv); + return function.apply(functionProperties, arg1, arg2, arg3); + } + + @Override + public ExprType type() { + return returnType; + } + + @Override + public String toString() { + return String.format( + "%s(%s)", + functionName, + arguments.stream().map(Object::toString).collect(Collectors.joining(", "))); + } + }; return Pair.of(functionSignature, functionBuilder); }; } @@ -240,28 +237,25 @@ public String toString() { /** * No Arg Function Implementation. * - * @param function {@link ExprValue} based unary function. + * @param function {@link ExprValue} based unary function. * @param returnType return type. * @return Unary Function Implementation. */ public static SerializableFunction> impl( - SerializableNoArgFunction function, - ExprType returnType) { + SerializableNoArgFunction function, ExprType returnType) { return implWithProperties(fp -> function.get(), returnType); } /** * Unary Function Implementation. * - * @param function {@link ExprValue} based unary function. + * @param function {@link ExprValue} based unary function. * @param returnType return type. - * @param argsType argument type. + * @param argsType argument type. * @return Unary Function Implementation. */ public static SerializableFunction> impl( - SerializableFunction function, - ExprType returnType, - ExprType argsType) { + SerializableFunction function, ExprType returnType, ExprType argsType) { return implWithProperties((fp, arg) -> function.apply(arg), returnType, argsType); } @@ -269,10 +263,10 @@ public static SerializableFunction> impl( @@ -281,17 +275,17 @@ public static SerializableFunction - function.apply(arg1, arg2), returnType, args1Type, args2Type); + return implWithProperties( + (fp, arg1, arg2) -> function.apply(arg1, arg2), returnType, args1Type, args2Type); } /** * Triple Function Implementation. * - * @param function {@link ExprValue} based unary function. + * @param function {@link ExprValue} based unary function. * @param returnType return type. - * @param args1Type argument type. - * @param args2Type argument type. + * @param args1Type argument type. + * @param args2Type argument type. * @return Binary Function Implementation. */ public static SerializableFunction> impl( @@ -305,26 +299,31 @@ public static SerializableFunction new FunctionExpression(functionName, arguments) { - @Override - public ExprValue valueOf(Environment valueEnv) { - ExprValue arg1 = arguments.get(0).valueOf(valueEnv); - ExprValue arg2 = arguments.get(1).valueOf(valueEnv); - ExprValue arg3 = arguments.get(2).valueOf(valueEnv); - return function.apply(arg1, arg2, arg3); - } - - @Override - public ExprType type() { - return returnType; - } - - @Override - public String toString() { - return String.format("%s(%s, %s, %s)", functionName, arguments.get(0).toString(), - arguments.get(1).toString(), arguments.get(2).toString()); - } - }; + (functionProperties, arguments) -> + new FunctionExpression(functionName, arguments) { + @Override + public ExprValue valueOf(Environment valueEnv) { + ExprValue arg1 = arguments.get(0).valueOf(valueEnv); + ExprValue arg2 = arguments.get(1).valueOf(valueEnv); + ExprValue arg3 = arguments.get(2).valueOf(valueEnv); + return function.apply(arg1, arg2, arg3); + } + + @Override + public ExprType type() { + return returnType; + } + + @Override + public String toString() { + return String.format( + "%s(%s, %s, %s)", + functionName, + arguments.get(0).toString(), + arguments.get(1).toString(), + arguments.get(2).toString()); + } + }; return Pair.of(functionSignature, functionBuilder); }; } @@ -332,11 +331,11 @@ public String toString() { /** * Quadruple Function Implementation. * - * @param function {@link ExprValue} based unary function. + * @param function {@link ExprValue} based unary function. * @param returnType return type. - * @param args1Type argument type. - * @param args2Type argument type. - * @param args3Type argument type. + * @param args1Type argument type. + * @param args2Type argument type. + * @param args3Type argument type. * @return Quadruple Function Implementation. */ public static SerializableFunction> impl( @@ -349,42 +348,41 @@ public static SerializableFunction { FunctionSignature functionSignature = - new FunctionSignature(functionName, Arrays.asList( - args1Type, - args2Type, - args3Type, - args4Type)); + new FunctionSignature( + functionName, Arrays.asList(args1Type, args2Type, args3Type, args4Type)); FunctionBuilder functionBuilder = - (functionProperties, arguments) -> new FunctionExpression(functionName, arguments) { - @Override - public ExprValue valueOf(Environment valueEnv) { - ExprValue arg1 = arguments.get(0).valueOf(valueEnv); - ExprValue arg2 = arguments.get(1).valueOf(valueEnv); - ExprValue arg3 = arguments.get(2).valueOf(valueEnv); - ExprValue arg4 = arguments.get(3).valueOf(valueEnv); - return function.apply(arg1, arg2, arg3, arg4); - } - - @Override - public ExprType type() { - return returnType; - } - - @Override - public String toString() { - return String.format("%s(%s, %s, %s, %s)", functionName, arguments.get(0).toString(), - arguments.get(1).toString(), - arguments.get(2).toString(), - arguments.get(3).toString()); - } - }; + (functionProperties, arguments) -> + new FunctionExpression(functionName, arguments) { + @Override + public ExprValue valueOf(Environment valueEnv) { + ExprValue arg1 = arguments.get(0).valueOf(valueEnv); + ExprValue arg2 = arguments.get(1).valueOf(valueEnv); + ExprValue arg3 = arguments.get(2).valueOf(valueEnv); + ExprValue arg4 = arguments.get(3).valueOf(valueEnv); + return function.apply(arg1, arg2, arg3, arg4); + } + + @Override + public ExprType type() { + return returnType; + } + + @Override + public String toString() { + return String.format( + "%s(%s, %s, %s, %s)", + functionName, + arguments.get(0).toString(), + arguments.get(1).toString(), + arguments.get(2).toString(), + arguments.get(3).toString()); + } + }; return Pair.of(functionSignature, functionBuilder); }; } - /** - * Wrapper the unary ExprValue function with default NULL and MISSING handling. - */ + /** Wrapper the unary ExprValue function with default NULL and MISSING handling. */ public static SerializableFunction nullMissingHandling( SerializableFunction function) { return value -> { @@ -398,9 +396,7 @@ public static SerializableFunction nullMissingHandling( }; } - /** - * Wrapper the binary ExprValue function with default NULL and MISSING handling. - */ + /** Wrapper the binary ExprValue function with default NULL and MISSING handling. */ public static SerializableBiFunction nullMissingHandling( SerializableBiFunction function) { return (v1, v2) -> { @@ -414,9 +410,7 @@ public static SerializableBiFunction nullMissin }; } - /** - * Wrapper the triple ExprValue function with default NULL and MISSING handling. - */ + /** Wrapper the triple ExprValue function with default NULL and MISSING handling. */ public SerializableTriFunction nullMissingHandling( SerializableTriFunction function) { return (v1, v2, v3) -> { @@ -431,12 +425,12 @@ public SerializableTriFunction nullM } /** - * Wrapper the unary ExprValue function that is aware of FunctionProperties, - * with default NULL and MISSING handling. + * Wrapper the unary ExprValue function that is aware of FunctionProperties, with default NULL and + * MISSING handling. */ public static SerializableBiFunction - nullMissingHandlingWithProperties( - SerializableBiFunction implementation) { + nullMissingHandlingWithProperties( + SerializableBiFunction implementation) { return (functionProperties, v1) -> { if (v1.isMissing()) { return ExprValueUtils.missingValue(); @@ -453,8 +447,9 @@ public SerializableTriFunction nullM * with default NULL and MISSING handling. */ public static SerializableTriFunction - nullMissingHandlingWithProperties( - SerializableTriFunction implementation) { + nullMissingHandlingWithProperties( + SerializableTriFunction + implementation) { return (functionProperties, v1, v2) -> { if (v1.isMissing() || v2.isMissing()) { return ExprValueUtils.missingValue(); @@ -471,18 +466,10 @@ public SerializableTriFunction nullM * with default NULL and MISSING handling. */ public static SerializableQuadFunction< - FunctionProperties, - ExprValue, - ExprValue, - ExprValue, - ExprValue> + FunctionProperties, ExprValue, ExprValue, ExprValue, ExprValue> nullMissingHandlingWithProperties( - SerializableQuadFunction< - FunctionProperties, - ExprValue, - ExprValue, - ExprValue, - ExprValue> implementation) { + SerializableQuadFunction + implementation) { return (functionProperties, v1, v2, v3) -> { if (v1.isMissing() || v2.isMissing() || v3.isMissing()) { return ExprValueUtils.missingValue(); diff --git a/core/src/main/java/org/opensearch/sql/expression/function/FunctionImplementation.java b/core/src/main/java/org/opensearch/sql/expression/function/FunctionImplementation.java index d829e01225..4fd265a890 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/FunctionImplementation.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/FunctionImplementation.java @@ -3,24 +3,17 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.function; import java.util.List; import org.opensearch.sql.expression.Expression; -/** - * The definition of Function Implementation. - */ +/** The definition of Function Implementation. */ public interface FunctionImplementation { - /** - * Get Function Name. - */ + /** Get Function Name. */ FunctionName getFunctionName(); - /** - * Get Function Arguments. - */ + /** Get Function Arguments. */ List getArguments(); } diff --git a/core/src/main/java/org/opensearch/sql/expression/function/FunctionName.java b/core/src/main/java/org/opensearch/sql/expression/function/FunctionName.java index cb3d5fab92..ae2987a164 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/FunctionName.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/FunctionName.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.function; import java.io.Serializable; @@ -11,14 +10,11 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -/** - * The definition of Function Name. - */ +/** The definition of Function Name. */ @EqualsAndHashCode @RequiredArgsConstructor public class FunctionName implements Serializable { - @Getter - private final String functionName; + @Getter private final String functionName; public static FunctionName of(String functionName) { return new FunctionName(functionName.toLowerCase()); diff --git a/core/src/main/java/org/opensearch/sql/expression/function/FunctionProperties.java b/core/src/main/java/org/opensearch/sql/expression/function/FunctionProperties.java index 4222748051..100c98bd38 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/FunctionProperties.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/FunctionProperties.java @@ -19,9 +19,7 @@ public class FunctionProperties implements Serializable { private final Instant nowInstant; private final ZoneId currentZoneId; - /** - * By default, use current time and current timezone. - */ + /** By default, use current time and current timezone. */ public FunctionProperties() { nowInstant = Instant.now(); currentZoneId = ZoneId.systemDefault(); @@ -29,6 +27,7 @@ public FunctionProperties() { /** * Method to access current system clock. + * * @return a ticking clock that tells the time. */ public Clock getSystemClock() { @@ -36,29 +35,28 @@ public Clock getSystemClock() { } /** - * Method to get time when query began execution. - * Clock class combines an instant Supplier and a time zone. - * @return a fixed clock that returns the time execution started at. + * Method to get time when query began execution. Clock class combines an instant Supplier and a + * time zone. * + * @return a fixed clock that returns the time execution started at. */ public Clock getQueryStartClock() { return Clock.fixed(nowInstant, currentZoneId); } - /** - * Use when compiling functions that do not rely on function properties. - */ - public static final FunctionProperties None = new FunctionProperties() { - @Override - public Clock getSystemClock() { - throw new UnexpectedCallException(); - } + /** Use when compiling functions that do not rely on function properties. */ + public static final FunctionProperties None = + new FunctionProperties() { + @Override + public Clock getSystemClock() { + throw new UnexpectedCallException(); + } - @Override - public Clock getQueryStartClock() { - throw new UnexpectedCallException(); - } - }; + @Override + public Clock getQueryStartClock() { + throw new UnexpectedCallException(); + } + }; class UnexpectedCallException extends RuntimeException { public UnexpectedCallException() { diff --git a/core/src/main/java/org/opensearch/sql/expression/function/FunctionResolver.java b/core/src/main/java/org/opensearch/sql/expression/function/FunctionResolver.java index 1635b6f846..eaede1da7e 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/FunctionResolver.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/FunctionResolver.java @@ -8,8 +8,8 @@ import org.apache.commons.lang3.tuple.Pair; /** - * An interface for any class that can provide a {@ref FunctionBuilder} - * given a {@ref FunctionSignature}. + * An interface for any class that can provide a {@ref FunctionBuilder} given a {@ref + * FunctionSignature}. */ public interface FunctionResolver { Pair resolve(FunctionSignature unresolvedSignature); diff --git a/core/src/main/java/org/opensearch/sql/expression/function/FunctionSignature.java b/core/src/main/java/org/opensearch/sql/expression/function/FunctionSignature.java index 0c59d71c25..e1246cde28 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/FunctionSignature.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/FunctionSignature.java @@ -15,9 +15,7 @@ import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.data.type.WideningTypeRule; -/** - * Function signature is composed by function name and arguments list. - */ +/** Function signature is composed by function name and arguments list. */ @Getter @RequiredArgsConstructor @EqualsAndHashCode @@ -31,9 +29,10 @@ public class FunctionSignature { /** * calculate the function signature match degree. * - * @return EXACTLY_MATCH: exactly match - * NOT_MATCH: not match - * By widening rule, the small number means better match + * @return
+ * EXACTLY_MATCH: exactly match
+ * NOT_MATCH: not match
+ * By widening rule, the small number means better match */ public int match(FunctionSignature functionSignature) { List functionTypeList = functionSignature.getParamTypeList(); @@ -60,18 +59,14 @@ public int match(FunctionSignature functionSignature) { return matchDegree; } - /** - * util function for formatted arguments list. - */ + /** util function for formatted arguments list. */ public String formatTypes() { return getParamTypeList().stream() .map(ExprType::typeName) .collect(Collectors.joining(",", "[", "]")); } - /** - * util function - returns true if function has variable arguments. - */ + /** util function - returns true if function has variable arguments. */ protected static boolean isVarArgFunction(List argTypes) { return argTypes.size() == 1 && argTypes.get(0) == ARRAY; } diff --git a/core/src/main/java/org/opensearch/sql/expression/function/OpenSearchFunctions.java b/core/src/main/java/org/opensearch/sql/expression/function/OpenSearchFunctions.java index c5fcb010f5..8d8928c16a 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/OpenSearchFunctions.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/OpenSearchFunctions.java @@ -22,9 +22,7 @@ @UtilityClass public class OpenSearchFunctions { - /** - * Add functions specific to OpenSearch to repository. - */ + /** Add functions specific to OpenSearch to repository. */ public void register(BuiltinFunctionRepository repository) { repository.register(match_bool_prefix()); repository.register(multi_match(BuiltinFunctionName.MULTI_MATCH)); @@ -101,19 +99,20 @@ private static FunctionResolver nested() { @Override public Pair resolve( FunctionSignature unresolvedSignature) { - return Pair.of(unresolvedSignature, + return Pair.of( + unresolvedSignature, (functionProperties, arguments) -> - new FunctionExpression(BuiltinFunctionName.NESTED.getName(), arguments) { - @Override - public ExprValue valueOf(Environment valueEnv) { - return valueEnv.resolve(getArguments().get(0)); - } - - @Override - public ExprType type() { - return getArguments().get(0).type(); - } - }); + new FunctionExpression(BuiltinFunctionName.NESTED.getName(), arguments) { + @Override + public ExprValue valueOf(Environment valueEnv) { + return valueEnv.resolve(getArguments().get(0)); + } + + @Override + public ExprType type() { + return getArguments().get(0).type(); + } + }); } @Override @@ -123,9 +122,6 @@ public FunctionName getFunctionName() { }; } - - - private static FunctionResolver score(BuiltinFunctionName score) { FunctionName funcName = score.getName(); return new RelevanceFunctionResolver(funcName); @@ -135,12 +131,11 @@ public static class OpenSearchFunction extends FunctionExpression { private final FunctionName functionName; private final List arguments; - @Getter - @Setter - private boolean isScoreTracked; + @Getter @Setter private boolean isScoreTracked; /** * Required argument constructor. + * * @param functionName name of the function * @param arguments a list of expressions */ @@ -153,9 +148,10 @@ public OpenSearchFunction(FunctionName functionName, List arguments) @Override public ExprValue valueOf(Environment valueEnv) { - throw new UnsupportedOperationException(String.format( - "OpenSearch defined function [%s] is only supported in WHERE and HAVING clause.", - functionName)); + throw new UnsupportedOperationException( + String.format( + "OpenSearch defined function [%s] is only supported in WHERE and HAVING clause.", + functionName)); } @Override @@ -165,10 +161,15 @@ public ExprType type() { @Override public String toString() { - List args = arguments.stream() - .map(arg -> String.format("%s=%s", ((NamedArgumentExpression) arg) - .getArgName(), ((NamedArgumentExpression) arg).getValue().toString())) - .collect(Collectors.toList()); + List args = + arguments.stream() + .map( + arg -> + String.format( + "%s=%s", + ((NamedArgumentExpression) arg).getArgName(), + ((NamedArgumentExpression) arg).getValue().toString())) + .collect(Collectors.toList()); return String.format("%s(%s)", functionName, String.join(", ", args)); } } diff --git a/core/src/main/java/org/opensearch/sql/expression/function/RelevanceFunctionResolver.java b/core/src/main/java/org/opensearch/sql/expression/function/RelevanceFunctionResolver.java index ef0ac9226c..ae882897d0 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/RelevanceFunctionResolver.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/RelevanceFunctionResolver.java @@ -14,17 +14,18 @@ import org.opensearch.sql.exception.SemanticCheckException; @RequiredArgsConstructor -public class RelevanceFunctionResolver - implements FunctionResolver { +public class RelevanceFunctionResolver implements FunctionResolver { - @Getter - private final FunctionName functionName; + @Getter private final FunctionName functionName; @Override public Pair resolve(FunctionSignature unresolvedSignature) { if (!unresolvedSignature.getFunctionName().equals(functionName)) { - throw new SemanticCheckException(String.format("Expected '%s' but got '%s'", - functionName.getFunctionName(), unresolvedSignature.getFunctionName().getFunctionName())); + throw new SemanticCheckException( + String.format( + "Expected '%s' but got '%s'", + functionName.getFunctionName(), + unresolvedSignature.getFunctionName().getFunctionName())); } List paramTypes = unresolvedSignature.getParamTypeList(); // Check if all but the first parameter are of type STRING. @@ -36,13 +37,15 @@ public Pair resolve(FunctionSignature unreso } } - FunctionBuilder buildFunction = (functionProperties, args) - -> new OpenSearchFunctions.OpenSearchFunction(functionName, args); + FunctionBuilder buildFunction = + (functionProperties, args) -> + new OpenSearchFunctions.OpenSearchFunction(functionName, args); return Pair.of(unresolvedSignature, buildFunction); } - /** Returns a helpful error message when expected parameter type does not match the - * specified parameter type. + /** + * Returns a helpful error message when expected parameter type does not match the specified + * parameter type. * * @param i 0-based index of the parameter in a function signature. * @param paramType the type of the ith parameter at run-time. @@ -50,7 +53,8 @@ public Pair resolve(FunctionSignature unreso * @return A user-friendly error message that informs of the type difference. */ private String getWrongParameterErrorMessage(int i, ExprType paramType, ExprType expectedType) { - return String.format("Expected type %s instead of %s for parameter #%d", + return String.format( + "Expected type %s instead of %s for parameter #%d", expectedType.typeName(), paramType.typeName(), i + 1); } } diff --git a/core/src/main/java/org/opensearch/sql/expression/function/SerializableBiFunction.java b/core/src/main/java/org/opensearch/sql/expression/function/SerializableBiFunction.java index 5b3aaf31f3..9f182e4c85 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/SerializableBiFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/SerializableBiFunction.java @@ -3,14 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.function; import java.io.Serializable; import java.util.function.BiFunction; -/** - * Serializable BiFunction. - */ -public interface SerializableBiFunction extends BiFunction, Serializable { -} +/** Serializable BiFunction. */ +public interface SerializableBiFunction extends BiFunction, Serializable {} diff --git a/core/src/main/java/org/opensearch/sql/expression/function/SerializableFunction.java b/core/src/main/java/org/opensearch/sql/expression/function/SerializableFunction.java index 467c034c39..fb3e2f2cfb 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/SerializableFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/SerializableFunction.java @@ -3,11 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.function; import java.io.Serializable; import java.util.function.Function; -public interface SerializableFunction extends Function, Serializable { -} +public interface SerializableFunction extends Function, Serializable {} diff --git a/core/src/main/java/org/opensearch/sql/expression/function/SerializableNoArgFunction.java b/core/src/main/java/org/opensearch/sql/expression/function/SerializableNoArgFunction.java index e68d6084b4..6eaf699bf9 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/SerializableNoArgFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/SerializableNoArgFunction.java @@ -3,14 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.function; import java.io.Serializable; import java.util.function.Supplier; -/** - * Serializable no argument function. - */ -public interface SerializableNoArgFunction extends Supplier, Serializable { -} +/** Serializable no argument function. */ +public interface SerializableNoArgFunction extends Supplier, Serializable {} diff --git a/core/src/main/java/org/opensearch/sql/expression/function/SerializableQuadFunction.java b/core/src/main/java/org/opensearch/sql/expression/function/SerializableQuadFunction.java index 056a17d5b3..7285d9a32f 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/SerializableQuadFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/SerializableQuadFunction.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.function; import java.io.Serializable; diff --git a/core/src/main/java/org/opensearch/sql/expression/function/SerializableTriFunction.java b/core/src/main/java/org/opensearch/sql/expression/function/SerializableTriFunction.java index 911012fcdb..e980b1c82a 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/SerializableTriFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/SerializableTriFunction.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.function; import java.io.Serializable; diff --git a/core/src/main/java/org/opensearch/sql/expression/function/TableFunctionImplementation.java b/core/src/main/java/org/opensearch/sql/expression/function/TableFunctionImplementation.java index f35ffe4898..b8b90bf5e3 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/TableFunctionImplementation.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/TableFunctionImplementation.java @@ -9,11 +9,8 @@ import org.opensearch.sql.storage.Table; -/** - * Interface for table function which returns Table when executed. - */ +/** Interface for table function which returns Table when executed. */ public interface TableFunctionImplementation extends FunctionImplementation { Table applyArguments(); - } diff --git a/core/src/main/java/org/opensearch/sql/expression/operator/arthmetic/ArithmeticFunction.java b/core/src/main/java/org/opensearch/sql/expression/operator/arthmetic/ArithmeticFunction.java index e25c5cda20..82b91e1d34 100644 --- a/core/src/main/java/org/opensearch/sql/expression/operator/arthmetic/ArithmeticFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/operator/arthmetic/ArithmeticFunction.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.operator.arthmetic; import static org.opensearch.sql.data.type.ExprCoreType.BYTE; @@ -30,11 +29,11 @@ import org.opensearch.sql.expression.function.FunctionName; /** - * The definition of arithmetic function - * add, Accepts two numbers and produces a number. - * subtract, Accepts two numbers and produces a number. - * multiply, Accepts two numbers and produces a number. - * divide, Accepts two numbers and produces a number. + * The definition of arithmetic function
+ * add, Accepts two numbers and produces a number.
+ * subtract, Accepts two numbers and produces a number.
+ * multiply, Accepts two numbers and produces a number.
+ * divide, Accepts two numbers and produces a number.
* module, Accepts two numbers and produces a number. */ @UtilityClass @@ -59,33 +58,49 @@ public static void register(BuiltinFunctionRepository repository) { } /** - * Definition of add(x, y) function. - * Returns the number x plus number y - * The supported signature of add function is - * (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE) + * Definition of add(x, y) function.
+ * Returns the number x plus number y
+ * The supported signature of add function is
+ * (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE)
* -> wider type between types of x and y */ private static DefaultFunctionResolver addBase(FunctionName functionName) { - return define(functionName, - impl(nullMissingHandling( - (v1, v2) -> new ExprByteValue(v1.byteValue() + v2.byteValue())), - BYTE, BYTE, BYTE), - impl(nullMissingHandling( - (v1, v2) -> new ExprShortValue(v1.shortValue() + v2.shortValue())), - SHORT, SHORT, SHORT), - impl(nullMissingHandling( - (v1, v2) -> new ExprIntegerValue(Math.addExact(v1.integerValue(), v2.integerValue()))), - INTEGER, INTEGER, INTEGER), - impl(nullMissingHandling( - (v1, v2) -> new ExprLongValue(Math.addExact(v1.longValue(), v2.longValue()))), - LONG, LONG, LONG), - impl(nullMissingHandling( - (v1, v2) -> new ExprFloatValue(v1.floatValue() + v2.floatValue())), - FLOAT, FLOAT, FLOAT), - impl(nullMissingHandling( - (v1, v2) -> new ExprDoubleValue(v1.doubleValue() + v2.doubleValue())), - DOUBLE, DOUBLE, DOUBLE) - ); + return define( + functionName, + impl( + nullMissingHandling((v1, v2) -> new ExprByteValue(v1.byteValue() + v2.byteValue())), + BYTE, + BYTE, + BYTE), + impl( + nullMissingHandling((v1, v2) -> new ExprShortValue(v1.shortValue() + v2.shortValue())), + SHORT, + SHORT, + SHORT), + impl( + nullMissingHandling( + (v1, v2) -> + new ExprIntegerValue(Math.addExact(v1.integerValue(), v2.integerValue()))), + INTEGER, + INTEGER, + INTEGER), + impl( + nullMissingHandling( + (v1, v2) -> new ExprLongValue(Math.addExact(v1.longValue(), v2.longValue()))), + LONG, + LONG, + LONG), + impl( + nullMissingHandling((v1, v2) -> new ExprFloatValue(v1.floatValue() + v2.floatValue())), + FLOAT, + FLOAT, + FLOAT), + impl( + nullMissingHandling( + (v1, v2) -> new ExprDoubleValue(v1.doubleValue() + v2.doubleValue())), + DOUBLE, + DOUBLE, + DOUBLE)); } private static DefaultFunctionResolver add() { @@ -97,39 +112,69 @@ private static DefaultFunctionResolver addFunction() { } /** - * Definition of divide(x, y) function. - * Returns the number x divided by number y - * The supported signature of divide function is - * (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE) + * Definition of divide(x, y) function.
+ * Returns the number x divided by number y
+ * The supported signature of divide function is
+ * (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE)
* -> wider type between types of x and y */ private static DefaultFunctionResolver divideBase(FunctionName functionName) { - return define(functionName, - impl(nullMissingHandling( - (v1, v2) -> v2.byteValue() == 0 ? ExprNullValue.of() : - new ExprByteValue(v1.byteValue() / v2.byteValue())), - BYTE, BYTE, BYTE), - impl(nullMissingHandling( - (v1, v2) -> v2.shortValue() == 0 ? ExprNullValue.of() : - new ExprShortValue(v1.shortValue() / v2.shortValue())), - SHORT, SHORT, SHORT), - impl(nullMissingHandling( - (v1, v2) -> v2.integerValue() == 0 ? ExprNullValue.of() : - new ExprIntegerValue(v1.integerValue() / v2.integerValue())), - INTEGER, INTEGER, INTEGER), - impl(nullMissingHandling( - (v1, v2) -> v2.longValue() == 0 ? ExprNullValue.of() : - new ExprLongValue(v1.longValue() / v2.longValue())), - LONG, LONG, LONG), - impl(nullMissingHandling( - (v1, v2) -> v2.floatValue() == 0 ? ExprNullValue.of() : - new ExprFloatValue(v1.floatValue() / v2.floatValue())), - FLOAT, FLOAT, FLOAT), - impl(nullMissingHandling( - (v1, v2) -> v2.doubleValue() == 0 ? ExprNullValue.of() : - new ExprDoubleValue(v1.doubleValue() / v2.doubleValue())), - DOUBLE, DOUBLE, DOUBLE) - ); + return define( + functionName, + impl( + nullMissingHandling( + (v1, v2) -> + v2.byteValue() == 0 + ? ExprNullValue.of() + : new ExprByteValue(v1.byteValue() / v2.byteValue())), + BYTE, + BYTE, + BYTE), + impl( + nullMissingHandling( + (v1, v2) -> + v2.shortValue() == 0 + ? ExprNullValue.of() + : new ExprShortValue(v1.shortValue() / v2.shortValue())), + SHORT, + SHORT, + SHORT), + impl( + nullMissingHandling( + (v1, v2) -> + v2.integerValue() == 0 + ? ExprNullValue.of() + : new ExprIntegerValue(v1.integerValue() / v2.integerValue())), + INTEGER, + INTEGER, + INTEGER), + impl( + nullMissingHandling( + (v1, v2) -> + v2.longValue() == 0 + ? ExprNullValue.of() + : new ExprLongValue(v1.longValue() / v2.longValue())), + LONG, + LONG, + LONG), + impl( + nullMissingHandling( + (v1, v2) -> + v2.floatValue() == 0 + ? ExprNullValue.of() + : new ExprFloatValue(v1.floatValue() / v2.floatValue())), + FLOAT, + FLOAT, + FLOAT), + impl( + nullMissingHandling( + (v1, v2) -> + v2.doubleValue() == 0 + ? ExprNullValue.of() + : new ExprDoubleValue(v1.doubleValue() / v2.doubleValue())), + DOUBLE, + DOUBLE, + DOUBLE)); } private static DefaultFunctionResolver divide() { @@ -141,39 +186,69 @@ private static DefaultFunctionResolver divideFunction() { } /** - * Definition of modulus(x, y) function. - * Returns the number x modulo by number y - * The supported signature of modulo function is - * (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE) + * Definition of modulus(x, y) function.
+ * Returns the number x modulo by number y
+ * The supported signature of modulo function is
+ * (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE)
* -> wider type between types of x and y */ private static DefaultFunctionResolver modulusBase(FunctionName functionName) { - return define(functionName, - impl(nullMissingHandling( - (v1, v2) -> v2.byteValue() == 0 ? ExprNullValue.of() : - new ExprByteValue(v1.byteValue() % v2.byteValue())), - BYTE, BYTE, BYTE), - impl(nullMissingHandling( - (v1, v2) -> v2.shortValue() == 0 ? ExprNullValue.of() : - new ExprShortValue(v1.shortValue() % v2.shortValue())), - SHORT, SHORT, SHORT), - impl(nullMissingHandling( - (v1, v2) -> v2.integerValue() == 0 ? ExprNullValue.of() : - new ExprIntegerValue(v1.integerValue() % v2.integerValue())), - INTEGER, INTEGER, INTEGER), - impl(nullMissingHandling( - (v1, v2) -> v2.longValue() == 0 ? ExprNullValue.of() : - new ExprLongValue(v1.longValue() % v2.longValue())), - LONG, LONG, LONG), - impl(nullMissingHandling( - (v1, v2) -> v2.floatValue() == 0 ? ExprNullValue.of() : - new ExprFloatValue(v1.floatValue() % v2.floatValue())), - FLOAT, FLOAT, FLOAT), - impl(nullMissingHandling( - (v1, v2) -> v2.doubleValue() == 0 ? ExprNullValue.of() : - new ExprDoubleValue(v1.doubleValue() % v2.doubleValue())), - DOUBLE, DOUBLE, DOUBLE) - ); + return define( + functionName, + impl( + nullMissingHandling( + (v1, v2) -> + v2.byteValue() == 0 + ? ExprNullValue.of() + : new ExprByteValue(v1.byteValue() % v2.byteValue())), + BYTE, + BYTE, + BYTE), + impl( + nullMissingHandling( + (v1, v2) -> + v2.shortValue() == 0 + ? ExprNullValue.of() + : new ExprShortValue(v1.shortValue() % v2.shortValue())), + SHORT, + SHORT, + SHORT), + impl( + nullMissingHandling( + (v1, v2) -> + v2.integerValue() == 0 + ? ExprNullValue.of() + : new ExprIntegerValue(v1.integerValue() % v2.integerValue())), + INTEGER, + INTEGER, + INTEGER), + impl( + nullMissingHandling( + (v1, v2) -> + v2.longValue() == 0 + ? ExprNullValue.of() + : new ExprLongValue(v1.longValue() % v2.longValue())), + LONG, + LONG, + LONG), + impl( + nullMissingHandling( + (v1, v2) -> + v2.floatValue() == 0 + ? ExprNullValue.of() + : new ExprFloatValue(v1.floatValue() % v2.floatValue())), + FLOAT, + FLOAT, + FLOAT), + impl( + nullMissingHandling( + (v1, v2) -> + v2.doubleValue() == 0 + ? ExprNullValue.of() + : new ExprDoubleValue(v1.doubleValue() % v2.doubleValue())), + DOUBLE, + DOUBLE, + DOUBLE)); } private static DefaultFunctionResolver mod() { @@ -189,34 +264,49 @@ private static DefaultFunctionResolver modulusFunction() { } /** - * Definition of multiply(x, y) function. - * Returns the number x multiplied by number y - * The supported signature of multiply function is - * (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE) - * -> wider type between types of x and y + * Definition of multiply(x, y) function.
+ * Returns the number x multiplied by number y
+ * The supported signature of multiply function is
+ * (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE)
+ * -> wider type between types of x and y */ private static DefaultFunctionResolver multiplyBase(FunctionName functionName) { - return define(functionName, - impl(nullMissingHandling( - (v1, v2) -> new ExprByteValue(v1.byteValue() * v2.byteValue())), - BYTE, BYTE, BYTE), - impl(nullMissingHandling( - (v1, v2) -> new ExprShortValue(v1.shortValue() * v2.shortValue())), - SHORT, SHORT, SHORT), - impl(nullMissingHandling( - (v1, v2) -> new ExprIntegerValue(Math.multiplyExact(v1.integerValue(), - v2.integerValue()))), - INTEGER, INTEGER, INTEGER), - impl(nullMissingHandling( + return define( + functionName, + impl( + nullMissingHandling((v1, v2) -> new ExprByteValue(v1.byteValue() * v2.byteValue())), + BYTE, + BYTE, + BYTE), + impl( + nullMissingHandling((v1, v2) -> new ExprShortValue(v1.shortValue() * v2.shortValue())), + SHORT, + SHORT, + SHORT), + impl( + nullMissingHandling( + (v1, v2) -> + new ExprIntegerValue(Math.multiplyExact(v1.integerValue(), v2.integerValue()))), + INTEGER, + INTEGER, + INTEGER), + impl( + nullMissingHandling( (v1, v2) -> new ExprLongValue(Math.multiplyExact(v1.longValue(), v2.longValue()))), - LONG, LONG, LONG), - impl(nullMissingHandling( - (v1, v2) -> new ExprFloatValue(v1.floatValue() * v2.floatValue())), - FLOAT, FLOAT, FLOAT), - impl(nullMissingHandling( + LONG, + LONG, + LONG), + impl( + nullMissingHandling((v1, v2) -> new ExprFloatValue(v1.floatValue() * v2.floatValue())), + FLOAT, + FLOAT, + FLOAT), + impl( + nullMissingHandling( (v1, v2) -> new ExprDoubleValue(v1.doubleValue() * v2.doubleValue())), - DOUBLE, DOUBLE, DOUBLE) - ); + DOUBLE, + DOUBLE, + DOUBLE)); } private static DefaultFunctionResolver multiply() { @@ -228,34 +318,49 @@ private static DefaultFunctionResolver multiplyFunction() { } /** - * Definition of subtract(x, y) function. - * Returns the number x minus number y - * The supported signature of subtract function is - * (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE) + * Definition of subtract(x, y) function.
+ * Returns the number x minus number y
+ * The supported signature of subtract function is
+ * (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE)
* -> wider type between types of x and y */ private static DefaultFunctionResolver subtractBase(FunctionName functionName) { - return define(functionName, - impl(nullMissingHandling( - (v1, v2) -> new ExprByteValue(v1.byteValue() - v2.byteValue())), - BYTE, BYTE, BYTE), - impl(nullMissingHandling( - (v1, v2) -> new ExprShortValue(v1.shortValue() - v2.shortValue())), - SHORT, SHORT, SHORT), - impl(nullMissingHandling( - (v1, v2) -> new ExprIntegerValue(Math.subtractExact(v1.integerValue(), - v2.integerValue()))), - INTEGER, INTEGER, INTEGER), - impl(nullMissingHandling( + return define( + functionName, + impl( + nullMissingHandling((v1, v2) -> new ExprByteValue(v1.byteValue() - v2.byteValue())), + BYTE, + BYTE, + BYTE), + impl( + nullMissingHandling((v1, v2) -> new ExprShortValue(v1.shortValue() - v2.shortValue())), + SHORT, + SHORT, + SHORT), + impl( + nullMissingHandling( + (v1, v2) -> + new ExprIntegerValue(Math.subtractExact(v1.integerValue(), v2.integerValue()))), + INTEGER, + INTEGER, + INTEGER), + impl( + nullMissingHandling( (v1, v2) -> new ExprLongValue(Math.subtractExact(v1.longValue(), v2.longValue()))), - LONG, LONG, LONG), - impl(nullMissingHandling( - (v1, v2) -> new ExprFloatValue(v1.floatValue() - v2.floatValue())), - FLOAT, FLOAT, FLOAT), - impl(nullMissingHandling( + LONG, + LONG, + LONG), + impl( + nullMissingHandling((v1, v2) -> new ExprFloatValue(v1.floatValue() - v2.floatValue())), + FLOAT, + FLOAT, + FLOAT), + impl( + nullMissingHandling( (v1, v2) -> new ExprDoubleValue(v1.doubleValue() - v2.doubleValue())), - DOUBLE, DOUBLE, DOUBLE) - ); + DOUBLE, + DOUBLE, + DOUBLE)); } private static DefaultFunctionResolver subtract() { diff --git a/core/src/main/java/org/opensearch/sql/expression/operator/arthmetic/MathematicalFunction.java b/core/src/main/java/org/opensearch/sql/expression/operator/arthmetic/MathematicalFunction.java index 810d292ca2..22f4b76573 100644 --- a/core/src/main/java/org/opensearch/sql/expression/operator/arthmetic/MathematicalFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/operator/arthmetic/MathematicalFunction.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.operator.arthmetic; import static org.opensearch.sql.data.type.ExprCoreType.BYTE; @@ -102,126 +101,155 @@ public static void register(BuiltinFunctionRepository repository) { * @return DefaultFunctionResolver for math functions. */ private static DefaultFunctionResolver baseMathFunction( - FunctionName functionName, SerializableFunction formula, ExprCoreType returnType) { - return define(functionName, ExprCoreType.numberTypes().stream().map(type -> - impl(nullMissingHandling(formula), returnType, type)).collect(Collectors.toList())); + FunctionName functionName, + SerializableFunction formula, + ExprCoreType returnType) { + return define( + functionName, + ExprCoreType.numberTypes().stream() + .map(type -> impl(nullMissingHandling(formula), returnType, type)) + .collect(Collectors.toList())); } /** - * Definition of abs() function. The supported signature of abs() function are INT -> INT LONG -> - * LONG FLOAT -> FLOAT DOUBLE -> DOUBLE + * Definition of abs() function.<\b>
+ * The supported signature of abs() function are
+ * INT/LONG/FLOAT/DOUBLE -> INT/LONG/FLOAT/DOUBLE */ private static DefaultFunctionResolver abs() { - return define(BuiltinFunctionName.ABS.getName(), - impl(nullMissingHandling(v -> new ExprByteValue(Math.abs(v.byteValue()))), - BYTE, BYTE), - impl(nullMissingHandling(v -> new ExprShortValue(Math.abs(v.shortValue()))), - SHORT, SHORT), - impl(nullMissingHandling(v -> new ExprIntegerValue(Math.abs(v.integerValue()))), - INTEGER, INTEGER), - impl(nullMissingHandling(v -> new ExprLongValue(Math.abs(v.longValue()))), - LONG, LONG), - impl(nullMissingHandling(v -> new ExprFloatValue(Math.abs(v.floatValue()))), - FLOAT, FLOAT), - impl(nullMissingHandling(v -> new ExprDoubleValue(Math.abs(v.doubleValue()))), - DOUBLE, DOUBLE) - ); - } - - /** - * Definition of ceil(x)/ceiling(x) function. Calculate the next highest integer that x rounds up - * to The supported signature of ceil/ceiling function is DOUBLE -> INTEGER + return define( + BuiltinFunctionName.ABS.getName(), + impl(nullMissingHandling(v -> new ExprByteValue(Math.abs(v.byteValue()))), BYTE, BYTE), + impl(nullMissingHandling(v -> new ExprShortValue(Math.abs(v.shortValue()))), SHORT, SHORT), + impl( + nullMissingHandling(v -> new ExprIntegerValue(Math.abs(v.integerValue()))), + INTEGER, + INTEGER), + impl(nullMissingHandling(v -> new ExprLongValue(Math.abs(v.longValue()))), LONG, LONG), + impl(nullMissingHandling(v -> new ExprFloatValue(Math.abs(v.floatValue()))), FLOAT, FLOAT), + impl( + nullMissingHandling(v -> new ExprDoubleValue(Math.abs(v.doubleValue()))), + DOUBLE, + DOUBLE)); + } + + /** + * Definition of ceil(x)/ceiling(x) function.<\b>
+ * Calculate the next highest integer that x rounds up to The supported signature of ceil/ceiling + * function is DOUBLE -> INTEGER */ private static DefaultFunctionResolver ceil() { - return define(BuiltinFunctionName.CEIL.getName(), - impl(nullMissingHandling(v -> new ExprLongValue(Math.ceil(v.doubleValue()))), - LONG, DOUBLE) - ); + return define( + BuiltinFunctionName.CEIL.getName(), + impl( + nullMissingHandling(v -> new ExprLongValue(Math.ceil(v.doubleValue()))), LONG, DOUBLE)); } private static DefaultFunctionResolver ceiling() { - return define(BuiltinFunctionName.CEILING.getName(), - impl(nullMissingHandling(v -> new ExprLongValue(Math.ceil(v.doubleValue()))), - LONG, DOUBLE) - ); + return define( + BuiltinFunctionName.CEILING.getName(), + impl( + nullMissingHandling(v -> new ExprLongValue(Math.ceil(v.doubleValue()))), LONG, DOUBLE)); } /** - * Definition of conv(x, a, b) function. - * Convert number x from base a to base b - * The supported signature of floor function is - * (STRING, INTEGER, INTEGER) -> STRING + * Definition of conv(x, a, b) function.<\b>
+ * Convert number x from base a to base b
+ * The supported signature of floor function is
+ * (STRING, INTEGER, INTEGER) -> STRING
* (INTEGER, INTEGER, INTEGER) -> STRING */ private static DefaultFunctionResolver conv() { - return define(BuiltinFunctionName.CONV.getName(), - impl(nullMissingHandling((x, a, b) -> new ExprStringValue( - Integer.toString(Integer.parseInt(x.stringValue(), a.integerValue()), - b.integerValue()))), - STRING, STRING, INTEGER, INTEGER), - impl(nullMissingHandling((x, a, b) -> new ExprStringValue( - Integer.toString(Integer.parseInt(x.integerValue().toString(), a.integerValue()), - b.integerValue()))), - STRING, INTEGER, INTEGER, INTEGER) - ); - } - - /** - * Definition of crc32(x) function. - * Calculate a cyclic redundancy check value and returns a 32-bit unsigned value - * The supported signature of crc32 function is + return define( + BuiltinFunctionName.CONV.getName(), + impl( + nullMissingHandling( + (x, a, b) -> + new ExprStringValue( + Integer.toString( + Integer.parseInt(x.stringValue(), a.integerValue()), + b.integerValue()))), + STRING, + STRING, + INTEGER, + INTEGER), + impl( + nullMissingHandling( + (x, a, b) -> + new ExprStringValue( + Integer.toString( + Integer.parseInt(x.integerValue().toString(), a.integerValue()), + b.integerValue()))), + STRING, + INTEGER, + INTEGER, + INTEGER)); + } + + /** + * Definition of crc32(x) function.<\b>
+ * Calculate a cyclic redundancy check value and returns a 32-bit unsigned value
+ * The supported signature of crc32 function is
* STRING -> LONG */ private static DefaultFunctionResolver crc32() { - return define(BuiltinFunctionName.CRC32.getName(), - impl(nullMissingHandling(v -> { - CRC32 crc = new CRC32(); - crc.update(v.stringValue().getBytes()); - return new ExprLongValue(crc.getValue()); - }), - LONG, STRING) - ); + return define( + BuiltinFunctionName.CRC32.getName(), + impl( + nullMissingHandling( + v -> { + CRC32 crc = new CRC32(); + crc.update(v.stringValue().getBytes()); + return new ExprLongValue(crc.getValue()); + }), + LONG, + STRING)); } /** - * Definition of e() function. - * Get the Euler's number. - * () -> DOUBLE + * Definition of e() function.
+ * Get the Euler's number. () -> DOUBLE */ private static DefaultFunctionResolver euler() { - return define(BuiltinFunctionName.E.getName(), - impl(() -> new ExprDoubleValue(Math.E), DOUBLE) - ); + return define(BuiltinFunctionName.E.getName(), impl(() -> new ExprDoubleValue(Math.E), DOUBLE)); } /** - * Definition of exp(x) function. Calculate exponent function e to the x - * The supported signature of exp function is INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE + * Definition of exp(x) function.
+ * Calculate exponent function e to the x The supported signature of exp function is + * INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver exp() { - return baseMathFunction(BuiltinFunctionName.EXP.getName(), - v -> new ExprDoubleValue(Math.exp(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.EXP.getName(), + v -> new ExprDoubleValue(Math.exp(v.doubleValue())), + DOUBLE); } /** - * Definition of expm1(x) function. Calculate exponent function e to the x, minus 1 - * The supported signature of exp function is INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE + * Definition of expm1(x) function.
+ * Calculate exponent function e to the x, minus 1 The supported signature of exp function is + * INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver expm1() { - return baseMathFunction(BuiltinFunctionName.EXPM1.getName(), - v -> new ExprDoubleValue(Math.expm1(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.EXPM1.getName(), + v -> new ExprDoubleValue(Math.expm1(v.doubleValue())), + DOUBLE); } /** - * Definition of floor(x) function. Calculate the next nearest whole integer that x rounds down to - * The supported signature of floor function is DOUBLE -> INTEGER + * Definition of floor(x) function.
+ * Calculate the next nearest whole integer that x rounds down to The supported signature of floor + * function is DOUBLE -> INTEGER */ private static DefaultFunctionResolver floor() { - return define(BuiltinFunctionName.FLOOR.getName(), - impl(nullMissingHandling(v -> new ExprLongValue(Math.floor(v.doubleValue()))), - LONG, DOUBLE) - ); + return define( + BuiltinFunctionName.FLOOR.getName(), + impl( + nullMissingHandling(v -> new ExprLongValue(Math.floor(v.doubleValue()))), + LONG, + DOUBLE)); } /** @@ -229,108 +257,171 @@ private static DefaultFunctionResolver floor() { * ln function is INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver ln() { - return baseMathFunction(BuiltinFunctionName.LN.getName(), - v -> v.doubleValue() <= 0 ? ExprNullValue.of() : - new ExprDoubleValue(Math.log(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.LN.getName(), + v -> + v.doubleValue() <= 0 + ? ExprNullValue.of() + : new ExprDoubleValue(Math.log(v.doubleValue())), + DOUBLE); } /** - * Definition of log(b, x) function. Calculate the logarithm of x using b as the base The - * supported signature of log function is (b: INTEGER/LONG/FLOAT/DOUBLE, x: - * INTEGER/LONG/FLOAT/DOUBLE]) -> DOUBLE + * Definition of log(b, x) function.
+ * Calculate the logarithm of x using b as the base The supported signature of log function is
+ * (b: INTEGER/LONG/FLOAT/DOUBLE, x: INTEGER/LONG/FLOAT/DOUBLE]) -> DOUBLE */ private static DefaultFunctionResolver log() { - ImmutableList.Builder>> builder = new ImmutableList.Builder<>(); + ImmutableList.Builder< + SerializableFunction>> + builder = new ImmutableList.Builder<>(); // build unary log(x), SHORT/INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE for (ExprType type : ExprCoreType.numberTypes()) { - builder.add(impl(nullMissingHandling(v -> v.doubleValue() <= 0 ? ExprNullValue.of() : - new ExprDoubleValue(Math.log(v.doubleValue()))), - DOUBLE, type)); + builder.add( + impl( + nullMissingHandling( + v -> + v.doubleValue() <= 0 + ? ExprNullValue.of() + : new ExprDoubleValue(Math.log(v.doubleValue()))), + DOUBLE, + type)); } // build binary function log(b, x) for (ExprType baseType : ExprCoreType.numberTypes()) { for (ExprType numberType : ExprCoreType.numberTypes()) { - builder.add(impl(nullMissingHandling((b, x) -> b.doubleValue() <= 0 || x.doubleValue() <= 0 - ? ExprNullValue.of() : new ExprDoubleValue( - Math.log(x.doubleValue()) / Math.log(b.doubleValue()))), - DOUBLE, baseType, numberType)); + builder.add( + impl( + nullMissingHandling( + (b, x) -> + b.doubleValue() <= 0 || x.doubleValue() <= 0 + ? ExprNullValue.of() + : new ExprDoubleValue( + Math.log(x.doubleValue()) / Math.log(b.doubleValue()))), + DOUBLE, + baseType, + numberType)); } } return define(BuiltinFunctionName.LOG.getName(), builder.build()); } - /** - * Definition of log10(x) function. Calculate base-10 logarithm of x The supported signature of + * Definition of log10(x) function.
+ * Calculate base-10 logarithm of x The supported signature of
* log function is SHORT/INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver log10() { - return baseMathFunction(BuiltinFunctionName.LOG10.getName(), - v -> v.doubleValue() <= 0 ? ExprNullValue.of() : - new ExprDoubleValue(Math.log10(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.LOG10.getName(), + v -> + v.doubleValue() <= 0 + ? ExprNullValue.of() + : new ExprDoubleValue(Math.log10(v.doubleValue())), + DOUBLE); } /** - * Definition of log2(x) function. Calculate base-2 logarithm of x The supported signature of log + * Definition of log2(x) function.
+ * Calculate base-2 logarithm of x The supported signature of log
* function is SHORT/INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver log2() { - return baseMathFunction(BuiltinFunctionName.LOG2.getName(), - v -> v.doubleValue() <= 0 ? ExprNullValue.of() : - new ExprDoubleValue(Math.log(v.doubleValue()) / Math.log(2)), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.LOG2.getName(), + v -> + v.doubleValue() <= 0 + ? ExprNullValue.of() + : new ExprDoubleValue(Math.log(v.doubleValue()) / Math.log(2)), + DOUBLE); } /** - * Definition of mod(x, y) function. - * Calculate the remainder of x divided by y - * The supported signature of mod function is - * (x: INTEGER/LONG/FLOAT/DOUBLE, y: INTEGER/LONG/FLOAT/DOUBLE) + * Definition of mod(x, y) function.
+ * Calculate the remainder of x divided by y
+ * The supported signature of mod function is
+ * (x: INTEGER/LONG/FLOAT/DOUBLE, y: INTEGER/LONG/FLOAT/DOUBLE)
* -> wider type between types of x and y */ private static DefaultFunctionResolver mod() { - return define(BuiltinFunctionName.MOD.getName(), - impl(nullMissingHandling((v1, v2) -> v2.byteValue() == 0 ? ExprNullValue.of() : - new ExprByteValue(v1.byteValue() % v2.byteValue())), - BYTE, BYTE, BYTE), - impl(nullMissingHandling((v1, v2) -> v2.shortValue() == 0 ? ExprNullValue.of() : - new ExprShortValue(v1.shortValue() % v2.shortValue())), - SHORT, SHORT, SHORT), - impl(nullMissingHandling((v1, v2) -> v2.shortValue() == 0 ? ExprNullValue.of() : - new ExprIntegerValue(Math.floorMod(v1.integerValue(), v2.integerValue()))), - INTEGER, INTEGER, INTEGER), - impl(nullMissingHandling((v1, v2) -> v2.shortValue() == 0 ? ExprNullValue.of() : - new ExprLongValue(Math.floorMod(v1.longValue(), v2.longValue()))), - LONG, LONG, LONG), - impl(nullMissingHandling((v1, v2) -> v2.shortValue() == 0 ? ExprNullValue.of() : - new ExprFloatValue(v1.floatValue() % v2.floatValue())), - FLOAT, FLOAT, FLOAT), - impl(nullMissingHandling((v1, v2) -> v2.shortValue() == 0 ? ExprNullValue.of() : - new ExprDoubleValue(v1.doubleValue() % v2.doubleValue())), - DOUBLE, DOUBLE, DOUBLE) - ); - } - - /** - * Definition of pi() function. - * Get the value of pi. + return define( + BuiltinFunctionName.MOD.getName(), + impl( + nullMissingHandling( + (v1, v2) -> + v2.byteValue() == 0 + ? ExprNullValue.of() + : new ExprByteValue(v1.byteValue() % v2.byteValue())), + BYTE, + BYTE, + BYTE), + impl( + nullMissingHandling( + (v1, v2) -> + v2.shortValue() == 0 + ? ExprNullValue.of() + : new ExprShortValue(v1.shortValue() % v2.shortValue())), + SHORT, + SHORT, + SHORT), + impl( + nullMissingHandling( + (v1, v2) -> + v2.shortValue() == 0 + ? ExprNullValue.of() + : new ExprIntegerValue( + Math.floorMod(v1.integerValue(), v2.integerValue()))), + INTEGER, + INTEGER, + INTEGER), + impl( + nullMissingHandling( + (v1, v2) -> + v2.shortValue() == 0 + ? ExprNullValue.of() + : new ExprLongValue(Math.floorMod(v1.longValue(), v2.longValue()))), + LONG, + LONG, + LONG), + impl( + nullMissingHandling( + (v1, v2) -> + v2.shortValue() == 0 + ? ExprNullValue.of() + : new ExprFloatValue(v1.floatValue() % v2.floatValue())), + FLOAT, + FLOAT, + FLOAT), + impl( + nullMissingHandling( + (v1, v2) -> + v2.shortValue() == 0 + ? ExprNullValue.of() + : new ExprDoubleValue(v1.doubleValue() % v2.doubleValue())), + DOUBLE, + DOUBLE, + DOUBLE)); + } + + /** + * Definition of pi() function.
+ * Get the value of pi.
* () -> DOUBLE */ private static DefaultFunctionResolver pi() { - return define(BuiltinFunctionName.PI.getName(), - impl(() -> new ExprDoubleValue(Math.PI), DOUBLE) - ); + return define( + BuiltinFunctionName.PI.getName(), impl(() -> new ExprDoubleValue(Math.PI), DOUBLE)); } /** - * Definition of pow(x, y)/power(x, y) function. - * Calculate the value of x raised to the power of y - * The supported signature of pow/power function is - * (INTEGER, INTEGER) -> DOUBLE - * (LONG, LONG) -> DOUBLE - * (FLOAT, FLOAT) -> DOUBLE + * Definition of pow(x, y)/power(x, y) function.
+ * Calculate the value of x raised to the power of y
+ * The supported signature of pow/power function is
+ * (INTEGER, INTEGER) -> DOUBLE
+ * (LONG, LONG) -> DOUBLE
+ * (FLOAT, FLOAT) -> DOUBLE
* (DOUBLE, DOUBLE) -> DOUBLE */ private static DefaultFunctionResolver pow() { @@ -341,336 +432,485 @@ private static DefaultFunctionResolver power() { return define(BuiltinFunctionName.POWER.getName(), powerFunctionImpl()); } - private List>> powerFunctionImpl() { + private List>> + powerFunctionImpl() { return Arrays.asList( - impl(nullMissingHandling( - (v1, v2) -> new ExprDoubleValue(Math.pow(v1.shortValue(), v2.shortValue()))), - DOUBLE, SHORT, SHORT), - impl(nullMissingHandling( - (v1, v2) -> new ExprDoubleValue(Math.pow(v1.integerValue(), v2.integerValue()))), - DOUBLE, INTEGER, INTEGER), - impl(nullMissingHandling( - (v1, v2) -> new ExprDoubleValue(Math.pow(v1.longValue(), v2.longValue()))), - DOUBLE, LONG, LONG), - impl(nullMissingHandling( - (v1, v2) -> v1.floatValue() <= 0 && v2.floatValue() != Math.floor(v2.floatValue()) - ? ExprNullValue.of() : - new ExprDoubleValue(Math.pow(v1.floatValue(), v2.floatValue()))), - DOUBLE, FLOAT, FLOAT), - impl(nullMissingHandling( - (v1, v2) -> v1.doubleValue() <= 0 && v2.doubleValue() != Math.floor(v2.doubleValue()) - ? ExprNullValue.of() : - new ExprDoubleValue(Math.pow(v1.doubleValue(), v2.doubleValue()))), - DOUBLE, DOUBLE, DOUBLE)); - } - - /** - * Definition of rand() and rand(N) function. - * rand() returns a random floating-point value in the range 0 <= value < 1.0 - * If integer N is specified, the seed is initialized prior to execution. + impl( + nullMissingHandling( + (v1, v2) -> new ExprDoubleValue(Math.pow(v1.shortValue(), v2.shortValue()))), + DOUBLE, + SHORT, + SHORT), + impl( + nullMissingHandling( + (v1, v2) -> new ExprDoubleValue(Math.pow(v1.integerValue(), v2.integerValue()))), + DOUBLE, + INTEGER, + INTEGER), + impl( + nullMissingHandling( + (v1, v2) -> new ExprDoubleValue(Math.pow(v1.longValue(), v2.longValue()))), + DOUBLE, + LONG, + LONG), + impl( + nullMissingHandling( + (v1, v2) -> + v1.floatValue() <= 0 && v2.floatValue() != Math.floor(v2.floatValue()) + ? ExprNullValue.of() + : new ExprDoubleValue(Math.pow(v1.floatValue(), v2.floatValue()))), + DOUBLE, + FLOAT, + FLOAT), + impl( + nullMissingHandling( + (v1, v2) -> + v1.doubleValue() <= 0 && v2.doubleValue() != Math.floor(v2.doubleValue()) + ? ExprNullValue.of() + : new ExprDoubleValue(Math.pow(v1.doubleValue(), v2.doubleValue()))), + DOUBLE, + DOUBLE, + DOUBLE)); + } + + /** + * Definition of rand() and rand(N) function.
+ * rand() returns a random floating-point value in the range 0 <= value < 1.0
+ * If integer N is specified, the seed is initialized prior to execution.
* One implication of this behavior is with identical argument N,rand(N) returns the same value - * each time, and thus produces a repeatable sequence of column values. - * The supported signature of rand function is - * ([INTEGER]) -> FLOAT + *
+ * each time, and thus produces a repeatable sequence of column values. The supported signature of + *
+ * rand function is ([INTEGER]) -> FLOAT */ private static DefaultFunctionResolver rand() { - return define(BuiltinFunctionName.RAND.getName(), + return define( + BuiltinFunctionName.RAND.getName(), impl(() -> new ExprFloatValue(new Random().nextFloat()), FLOAT), - impl(nullMissingHandling( - v -> new ExprFloatValue(new Random(v.integerValue()).nextFloat())), FLOAT, INTEGER) - ); + impl( + nullMissingHandling(v -> new ExprFloatValue(new Random(v.integerValue()).nextFloat())), + FLOAT, + INTEGER)); } /** - * Definition of rint(x) function. - * Returns the closest whole integer value to x - * The supported signature is + * Definition of rint(x) function.
+ * Returns the closest whole integer value to x
+ * The supported signature is
* BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver rint() { - return baseMathFunction(BuiltinFunctionName.RINT.getName(), - v -> new ExprDoubleValue(Math.rint(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.RINT.getName(), + v -> new ExprDoubleValue(Math.rint(v.doubleValue())), + DOUBLE); } /** - * Definition of round(x)/round(x, d) function. - * Rounds the argument x to d decimal places, d defaults to 0 if not specified. - * The supported signature of round function is - * (x: INTEGER [, y: INTEGER]) -> INTEGER - * (x: LONG [, y: INTEGER]) -> LONG - * (x: FLOAT [, y: INTEGER]) -> FLOAT + * Definition of round(x)/round(x, d) function.
+ * Rounds the argument x to d decimal places, d defaults to 0 if not specified.
+ * The supported signature of round function is
+ * (x: INTEGER [, y: INTEGER]) -> INTEGER
+ * (x: LONG [, y: INTEGER]) -> LONG
+ * (x: FLOAT [, y: INTEGER]) -> FLOAT
* (x: DOUBLE [, y: INTEGER]) -> DOUBLE */ private static DefaultFunctionResolver round() { - return define(BuiltinFunctionName.ROUND.getName(), + return define( + BuiltinFunctionName.ROUND.getName(), // rand(x) - impl(nullMissingHandling(v -> new ExprLongValue((long) Math.round(v.integerValue()))), - LONG, INTEGER), - impl(nullMissingHandling(v -> new ExprLongValue((long) Math.round(v.longValue()))), - LONG, LONG), - impl(nullMissingHandling(v -> new ExprDoubleValue((double) Math.round(v.floatValue()))), - DOUBLE, FLOAT), - impl(nullMissingHandling(v -> new ExprDoubleValue(new BigDecimal(v.doubleValue()) - .setScale(0, RoundingMode.HALF_UP).doubleValue())), - DOUBLE, DOUBLE), + impl( + nullMissingHandling(v -> new ExprLongValue((long) Math.round(v.integerValue()))), + LONG, + INTEGER), + impl( + nullMissingHandling(v -> new ExprLongValue((long) Math.round(v.longValue()))), + LONG, + LONG), + impl( + nullMissingHandling(v -> new ExprDoubleValue((double) Math.round(v.floatValue()))), + DOUBLE, + FLOAT), + impl( + nullMissingHandling( + v -> + new ExprDoubleValue( + new BigDecimal(v.doubleValue()) + .setScale(0, RoundingMode.HALF_UP) + .doubleValue())), + DOUBLE, + DOUBLE), // rand(x, d) - impl(nullMissingHandling((x, d) -> new ExprLongValue(new BigDecimal(x.integerValue()) - .setScale(d.integerValue(), RoundingMode.HALF_UP).longValue())), - LONG, INTEGER, INTEGER), - impl(nullMissingHandling((x, d) -> new ExprLongValue(new BigDecimal(x.longValue()) - .setScale(d.integerValue(), RoundingMode.HALF_UP).longValue())), - LONG, LONG, INTEGER), - impl(nullMissingHandling((x, d) -> new ExprDoubleValue(new BigDecimal(x.floatValue()) - .setScale(d.integerValue(), RoundingMode.HALF_UP).doubleValue())), - DOUBLE, FLOAT, INTEGER), - impl(nullMissingHandling((x, d) -> new ExprDoubleValue(new BigDecimal(x.doubleValue()) - .setScale(d.integerValue(), RoundingMode.HALF_UP).doubleValue())), - DOUBLE, DOUBLE, INTEGER)); - } - - /** - * Definition of sign(x) function. - * Returns the sign of the argument as -1, 0, or 1 - * depending on whether x is negative, zero, or positive - * The supported signature is + impl( + nullMissingHandling( + (x, d) -> + new ExprLongValue( + new BigDecimal(x.integerValue()) + .setScale(d.integerValue(), RoundingMode.HALF_UP) + .longValue())), + LONG, + INTEGER, + INTEGER), + impl( + nullMissingHandling( + (x, d) -> + new ExprLongValue( + new BigDecimal(x.longValue()) + .setScale(d.integerValue(), RoundingMode.HALF_UP) + .longValue())), + LONG, + LONG, + INTEGER), + impl( + nullMissingHandling( + (x, d) -> + new ExprDoubleValue( + new BigDecimal(x.floatValue()) + .setScale(d.integerValue(), RoundingMode.HALF_UP) + .doubleValue())), + DOUBLE, + FLOAT, + INTEGER), + impl( + nullMissingHandling( + (x, d) -> + new ExprDoubleValue( + new BigDecimal(x.doubleValue()) + .setScale(d.integerValue(), RoundingMode.HALF_UP) + .doubleValue())), + DOUBLE, + DOUBLE, + INTEGER)); + } + + /** + * Definition of sign(x) function.
+ * Returns the sign of the argument as -1, 0, or 1
+ * depending on whether x is negative, zero, or positive
+ * The supported signature is
* SHORT/INTEGER/LONG/FLOAT/DOUBLE -> INTEGER */ private static DefaultFunctionResolver sign() { - return baseMathFunction(BuiltinFunctionName.SIGN.getName(), - v -> new ExprIntegerValue(Math.signum(v.doubleValue())), INTEGER); + return baseMathFunction( + BuiltinFunctionName.SIGN.getName(), + v -> new ExprIntegerValue(Math.signum(v.doubleValue())), + INTEGER); } /** - * Definition of signum(x) function. - * Returns the sign of the argument as -1.0, 0, or 1.0 - * depending on whether x is negative, zero, or positive - * The supported signature is + * Definition of signum(x) function.
+ * Returns the sign of the argument as -1.0, 0, or 1.0
+ * depending on whether x is negative, zero, or positive
+ * The supported signature is
* BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE -> INTEGER */ private static DefaultFunctionResolver signum() { - return baseMathFunction(BuiltinFunctionName.SIGNUM.getName(), - v -> new ExprIntegerValue(Math.signum(v.doubleValue())), INTEGER); + return baseMathFunction( + BuiltinFunctionName.SIGNUM.getName(), + v -> new ExprIntegerValue(Math.signum(v.doubleValue())), + INTEGER); } /** - * Definition of sinh(x) function. - * Returns the hyperbolix sine of x, defined as (((e^x) - (e^(-x))) / 2) - * The supported signature is + * Definition of sinh(x) function.
+ * Returns the hyperbolix sine of x, defined as (((e^x) - (e^(-x))) / 2)
+ * The supported signature is
* BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver sinh() { - return baseMathFunction(BuiltinFunctionName.SINH.getName(), - v -> new ExprDoubleValue(Math.sinh(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.SINH.getName(), + v -> new ExprDoubleValue(Math.sinh(v.doubleValue())), + DOUBLE); } /** - * Definition of sqrt(x) function. - * Calculate the square root of a non-negative number x - * The supported signature is + * Definition of sqrt(x) function.
+ * Calculate the square root of a non-negative number x
+ * The supported signature is
* INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver sqrt() { - return baseMathFunction(BuiltinFunctionName.SQRT.getName(), - v -> v.doubleValue() < 0 ? ExprNullValue.of() : - new ExprDoubleValue(Math.sqrt(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.SQRT.getName(), + v -> + v.doubleValue() < 0 + ? ExprNullValue.of() + : new ExprDoubleValue(Math.sqrt(v.doubleValue())), + DOUBLE); } /** - * Definition of cbrt(x) function. - * Calculate the cube root of a number x - * The supported signature is + * Definition of cbrt(x) function.
+ * Calculate the cube root of a number x
+ * The supported signature is
* INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver cbrt() { - return baseMathFunction(BuiltinFunctionName.CBRT.getName(), - v -> new ExprDoubleValue(Math.cbrt(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.CBRT.getName(), + v -> new ExprDoubleValue(Math.cbrt(v.doubleValue())), + DOUBLE); } /** - * Definition of truncate(x, d) function. - * Returns the number x, truncated to d decimal places - * The supported signature of round function is - * (x: INTEGER, y: INTEGER) -> LONG - * (x: LONG, y: INTEGER) -> LONG - * (x: FLOAT, y: INTEGER) -> DOUBLE + * Definition of truncate(x, d) function.
+ * Returns the number x, truncated to d decimal places
+ * The supported signature of round function is
+ * (x: INTEGER, y: INTEGER) -> LONG
+ * (x: LONG, y: INTEGER) -> LONG
+ * (x: FLOAT, y: INTEGER) -> DOUBLE
* (x: DOUBLE, y: INTEGER) -> DOUBLE */ private static DefaultFunctionResolver truncate() { - return define(BuiltinFunctionName.TRUNCATE.getName(), - impl(nullMissingHandling((x, y) -> new ExprLongValue(BigDecimal.valueOf(x.integerValue()) - .setScale(y.integerValue(), RoundingMode.DOWN).longValue())), - LONG, INTEGER, INTEGER), - impl(nullMissingHandling((x, y) -> new ExprLongValue(BigDecimal.valueOf(x.longValue()) - .setScale(y.integerValue(), RoundingMode.DOWN).longValue())), - LONG, LONG, INTEGER), - impl(nullMissingHandling((x, y) -> new ExprDoubleValue(BigDecimal.valueOf(x.floatValue()) - .setScale(y.integerValue(), RoundingMode.DOWN).doubleValue())), - DOUBLE, FLOAT, INTEGER), - impl(nullMissingHandling((x, y) -> new ExprDoubleValue(BigDecimal.valueOf(x.doubleValue()) - .setScale(y.integerValue(), RoundingMode.DOWN).doubleValue())), - DOUBLE, DOUBLE, INTEGER)); - } - - /** - * Definition of acos(x) function. - * Calculates the arc cosine of x, that is, the value whose cosine is x. - * Returns NULL if x is not in the range -1 to 1. - * The supported signature of acos function is + return define( + BuiltinFunctionName.TRUNCATE.getName(), + impl( + nullMissingHandling( + (x, y) -> + new ExprLongValue( + BigDecimal.valueOf(x.integerValue()) + .setScale(y.integerValue(), RoundingMode.DOWN) + .longValue())), + LONG, + INTEGER, + INTEGER), + impl( + nullMissingHandling( + (x, y) -> + new ExprLongValue( + BigDecimal.valueOf(x.longValue()) + .setScale(y.integerValue(), RoundingMode.DOWN) + .longValue())), + LONG, + LONG, + INTEGER), + impl( + nullMissingHandling( + (x, y) -> + new ExprDoubleValue( + BigDecimal.valueOf(x.floatValue()) + .setScale(y.integerValue(), RoundingMode.DOWN) + .doubleValue())), + DOUBLE, + FLOAT, + INTEGER), + impl( + nullMissingHandling( + (x, y) -> + new ExprDoubleValue( + BigDecimal.valueOf(x.doubleValue()) + .setScale(y.integerValue(), RoundingMode.DOWN) + .doubleValue())), + DOUBLE, + DOUBLE, + INTEGER)); + } + + /** + * Definition of acos(x) function.
+ * Calculates the arc cosine of x, that is, the value whose cosine is x.
+ * Returns NULL if x is not in the range -1 to 1.
+ * The supported signature of acos function is
* INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver acos() { - return define(BuiltinFunctionName.ACOS.getName(), + return define( + BuiltinFunctionName.ACOS.getName(), ExprCoreType.numberTypes().stream() - .map(type -> impl(nullMissingHandling( - v -> v.doubleValue() < -1 || v.doubleValue() > 1 ? ExprNullValue.of() : - new ExprDoubleValue(Math.acos(v.doubleValue()))), - DOUBLE, type)).collect(Collectors.toList())); - } - - /** - * Definition of asin(x) function. - * Calculates the arc sine of x, that is, the value whose sine is x. - * Returns NULL if x is not in the range -1 to 1. - * The supported signature of asin function is - * INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE + .map( + type -> + impl( + nullMissingHandling( + v -> + v.doubleValue() < -1 || v.doubleValue() > 1 + ? ExprNullValue.of() + : new ExprDoubleValue(Math.acos(v.doubleValue()))), + DOUBLE, + type)) + .collect(Collectors.toList())); + } + + /** + * Definition of asin(x) function.
+ * Calculates the arc sine of x, that is, the value whose sine is x.
+ * Returns NULL if x is not in the range -1 to 1.
+ * The supported signature of asin function is
+ * INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE
*/ private static DefaultFunctionResolver asin() { - return define(BuiltinFunctionName.ASIN.getName(), + return define( + BuiltinFunctionName.ASIN.getName(), ExprCoreType.numberTypes().stream() - .map(type -> impl(nullMissingHandling( - v -> v.doubleValue() < -1 || v.doubleValue() > 1 ? ExprNullValue.of() : - new ExprDoubleValue(Math.asin(v.doubleValue()))), - DOUBLE, type)).collect(Collectors.toList())); - } - - /** - * Definition of atan(x) and atan(y, x) function. - * atan(x) calculates the arc tangent of x, that is, the value whose tangent is x. - * atan(y, x) calculates the arc tangent of y / x, except that the signs of both arguments - * are used to determine the quadrant of the result. - * The supported signature of atan function is + .map( + type -> + impl( + nullMissingHandling( + v -> + v.doubleValue() < -1 || v.doubleValue() > 1 + ? ExprNullValue.of() + : new ExprDoubleValue(Math.asin(v.doubleValue()))), + DOUBLE, + type)) + .collect(Collectors.toList())); + } + + /** + * Definition of atan(x) and atan(y, x) function.
+ * atan(x) calculates the arc tangent of x, that is, the value whose tangent is x.
+ * atan(y, x) calculates the arc tangent of y / x, except that the signs of both arguments
+ * are used to determine the quadrant of the result.
+ * The supported signature of atan function is
* (x: INTEGER/LONG/FLOAT/DOUBLE, y: INTEGER/LONG/FLOAT/DOUBLE) -> DOUBLE */ private static DefaultFunctionResolver atan() { - ImmutableList.Builder>> builder = new ImmutableList.Builder<>(); + ImmutableList.Builder< + SerializableFunction>> + builder = new ImmutableList.Builder<>(); for (ExprType type : ExprCoreType.numberTypes()) { - builder.add(impl(nullMissingHandling(x -> new ExprDoubleValue(Math.atan(x.doubleValue()))), - type, DOUBLE)); - builder.add(impl(nullMissingHandling((y, x) -> new ExprDoubleValue(Math.atan2(y.doubleValue(), - x.doubleValue()))), - DOUBLE, type, type)); + builder.add( + impl( + nullMissingHandling(x -> new ExprDoubleValue(Math.atan(x.doubleValue()))), + type, + DOUBLE)); + builder.add( + impl( + nullMissingHandling( + (y, x) -> new ExprDoubleValue(Math.atan2(y.doubleValue(), x.doubleValue()))), + DOUBLE, + type, + type)); } return define(BuiltinFunctionName.ATAN.getName(), builder.build()); } /** - * Definition of atan2(y, x) function. - * Calculates the arc tangent of y / x, except that the signs of both arguments - * are used to determine the quadrant of the result. - * The supported signature of atan2 function is + * Definition of atan2(y, x) function.
+ * Calculates the arc tangent of y / x, except that the signs of both arguments are used to + * determine the quadrant of the result.
+ * The supported signature of atan2 function is
* (x: INTEGER/LONG/FLOAT/DOUBLE, y: INTEGER/LONG/FLOAT/DOUBLE) -> DOUBLE */ private static DefaultFunctionResolver atan2() { - ImmutableList.Builder>> builder = new ImmutableList.Builder<>(); + ImmutableList.Builder< + SerializableFunction>> + builder = new ImmutableList.Builder<>(); for (ExprType type : ExprCoreType.numberTypes()) { - builder.add(impl(nullMissingHandling((y, x) -> new ExprDoubleValue(Math.atan2(y.doubleValue(), - x.doubleValue()))), DOUBLE, type, type)); + builder.add( + impl( + nullMissingHandling( + (y, x) -> new ExprDoubleValue(Math.atan2(y.doubleValue(), x.doubleValue()))), + DOUBLE, + type, + type)); } return define(BuiltinFunctionName.ATAN2.getName(), builder.build()); } /** - * Definition of cos(x) function. - * Calculates the cosine of X, where X is given in radians - * The supported signature of cos function is + * Definition of cos(x) function.
+ * Calculates the cosine of X, where X is given in radians
+ * The supported signature of cos function is
* INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver cos() { - return baseMathFunction(BuiltinFunctionName.COS.getName(), - v -> new ExprDoubleValue(Math.cos(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.COS.getName(), + v -> new ExprDoubleValue(Math.cos(v.doubleValue())), + DOUBLE); } /** - * Definition of cosh(x) function. - * Returns the hyperbolic cosine of x, defined as (((e^x) + (e^(-x))) / 2) - * The supported signature is + * Definition of cosh(x) function.
+ * Returns the hyperbolic cosine of x, defined as (((e^x) + (e^(-x))) / 2)
+ * The supported signature is
* BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver cosh() { - return baseMathFunction(BuiltinFunctionName.COSH.getName(), - v -> new ExprDoubleValue(Math.cosh(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.COSH.getName(), + v -> new ExprDoubleValue(Math.cosh(v.doubleValue())), + DOUBLE); } /** - * Definition of cot(x) function. - * Calculates the cotangent of x - * The supported signature of cot function is + * Definition of cot(x) function.<\b>
+ * Calculates the cotangent of x The supported signature of cot function is * INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver cot() { - return define(BuiltinFunctionName.COT.getName(), + return define( + BuiltinFunctionName.COT.getName(), ExprCoreType.numberTypes().stream() - .map(type -> impl(nullMissingHandling( - v -> { - Double value = v.doubleValue(); - if (value == 0) { - throw new ArithmeticException( - String.format("Out of range value for cot(%s)", value)); - } - return new ExprDoubleValue(1 / Math.tan(value)); - }), - DOUBLE, type)).collect(Collectors.toList())); - } - - /** - * Definition of degrees(x) function. - * Converts x from radians to degrees - * The supported signature of degrees function is + .map( + type -> + impl( + nullMissingHandling( + v -> { + Double value = v.doubleValue(); + if (value == 0) { + throw new ArithmeticException( + String.format("Out of range value for cot(%s)", value)); + } + return new ExprDoubleValue(1 / Math.tan(value)); + }), + DOUBLE, + type)) + .collect(Collectors.toList())); + } + + /** + * Definition of degrees(x) function.
+ * Converts x from radians to degrees The supported signature of degrees function is * INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver degrees() { - return baseMathFunction(BuiltinFunctionName.DEGREES.getName(), - v -> new ExprDoubleValue(Math.toDegrees(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.DEGREES.getName(), + v -> new ExprDoubleValue(Math.toDegrees(v.doubleValue())), + DOUBLE); } /** - * Definition of radians(x) function. - * Converts x from degrees to radians - * The supported signature of radians function is + * Definition of radians(x) function.
+ * Converts x from degrees to radians The supported signature of radians function is * INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver radians() { - return baseMathFunction(BuiltinFunctionName.RADIANS.getName(), - v -> new ExprDoubleValue(Math.toRadians(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.RADIANS.getName(), + v -> new ExprDoubleValue(Math.toRadians(v.doubleValue())), + DOUBLE); } /** - * Definition of sin(x) function. - * Calculates the sine of x, where x is given in radians - * The supported signature of sin function is + * Definition of sin(x) function.
+ * Calculates the sine of x, where x is given in radians The supported signature of sin function + * is
* INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver sin() { - return baseMathFunction(BuiltinFunctionName.SIN.getName(), - v -> new ExprDoubleValue(Math.sin(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.SIN.getName(), + v -> new ExprDoubleValue(Math.sin(v.doubleValue())), + DOUBLE); } /** - * Definition of tan(x) function. - * Calculates the tangent of x, where x is given in radians - * The supported signature of tan function is + * Definition of tan(x) function.
+ * Calculates the tangent of x, where x is given in radians The supported signature of tan + * function is
* INTEGER/LONG/FLOAT/DOUBLE -> DOUBLE */ private static DefaultFunctionResolver tan() { - return baseMathFunction(BuiltinFunctionName.TAN.getName(), - v -> new ExprDoubleValue(Math.tan(v.doubleValue())), DOUBLE); + return baseMathFunction( + BuiltinFunctionName.TAN.getName(), + v -> new ExprDoubleValue(Math.tan(v.doubleValue())), + DOUBLE); } } diff --git a/core/src/main/java/org/opensearch/sql/expression/operator/convert/TypeCastOperator.java b/core/src/main/java/org/opensearch/sql/expression/operator/convert/TypeCastOperator.java index d3295a53f0..7c3565f69c 100644 --- a/core/src/main/java/org/opensearch/sql/expression/operator/convert/TypeCastOperator.java +++ b/core/src/main/java/org/opensearch/sql/expression/operator/convert/TypeCastOperator.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.operator.convert; import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN; @@ -46,9 +45,7 @@ @UtilityClass public class TypeCastOperator { - /** - * Register Type Cast Operator. - */ + /** Register Type Cast Operator. */ public static void register(BuiltinFunctionRepository repository) { repository.register(castToString()); repository.register(castToByte()); @@ -64,148 +61,175 @@ public static void register(BuiltinFunctionRepository repository) { repository.register(castToDatetime()); } - private static DefaultFunctionResolver castToString() { - return FunctionDSL.define(BuiltinFunctionName.CAST_TO_STRING.getName(), + return FunctionDSL.define( + BuiltinFunctionName.CAST_TO_STRING.getName(), Stream.concat( - Arrays.asList(BYTE, SHORT, INTEGER, LONG, FLOAT, DOUBLE, BOOLEAN, TIME, DATE, - TIMESTAMP, DATETIME).stream() - .map(type -> impl( - nullMissingHandling((v) -> new ExprStringValue(v.value().toString())), - STRING, type)), - Stream.of(impl(nullMissingHandling((v) -> v), STRING, STRING))) - .collect(Collectors.toList()) - ); + Arrays.asList( + BYTE, SHORT, INTEGER, LONG, FLOAT, DOUBLE, BOOLEAN, TIME, DATE, TIMESTAMP, + DATETIME) + .stream() + .map( + type -> + impl( + nullMissingHandling( + (v) -> new ExprStringValue(v.value().toString())), + STRING, + type)), + Stream.of(impl(nullMissingHandling((v) -> v), STRING, STRING))) + .collect(Collectors.toList())); } private static DefaultFunctionResolver castToByte() { - return FunctionDSL.define(BuiltinFunctionName.CAST_TO_BYTE.getName(), - impl(nullMissingHandling( - (v) -> new ExprByteValue(Byte.valueOf(v.stringValue()))), BYTE, STRING), - impl(nullMissingHandling( - (v) -> new ExprByteValue(v.byteValue())), BYTE, DOUBLE), - impl(nullMissingHandling( - (v) -> new ExprByteValue(v.booleanValue() ? 1 : 0)), BYTE, BOOLEAN) - ); + return FunctionDSL.define( + BuiltinFunctionName.CAST_TO_BYTE.getName(), + impl( + nullMissingHandling((v) -> new ExprByteValue(Byte.valueOf(v.stringValue()))), + BYTE, + STRING), + impl(nullMissingHandling((v) -> new ExprByteValue(v.byteValue())), BYTE, DOUBLE), + impl( + nullMissingHandling((v) -> new ExprByteValue(v.booleanValue() ? 1 : 0)), + BYTE, + BOOLEAN)); } private static DefaultFunctionResolver castToShort() { - return FunctionDSL.define(BuiltinFunctionName.CAST_TO_SHORT.getName(), - impl(nullMissingHandling( - (v) -> new ExprShortValue(Short.valueOf(v.stringValue()))), SHORT, STRING), - impl(nullMissingHandling( - (v) -> new ExprShortValue(v.shortValue())), SHORT, DOUBLE), - impl(nullMissingHandling( - (v) -> new ExprShortValue(v.booleanValue() ? 1 : 0)), SHORT, BOOLEAN) - ); + return FunctionDSL.define( + BuiltinFunctionName.CAST_TO_SHORT.getName(), + impl( + nullMissingHandling((v) -> new ExprShortValue(Short.valueOf(v.stringValue()))), + SHORT, + STRING), + impl(nullMissingHandling((v) -> new ExprShortValue(v.shortValue())), SHORT, DOUBLE), + impl( + nullMissingHandling((v) -> new ExprShortValue(v.booleanValue() ? 1 : 0)), + SHORT, + BOOLEAN)); } private static DefaultFunctionResolver castToInt() { - return FunctionDSL.define(BuiltinFunctionName.CAST_TO_INT.getName(), - impl(nullMissingHandling( - (v) -> new ExprIntegerValue(Integer.valueOf(v.stringValue()))), INTEGER, STRING), - impl(nullMissingHandling( - (v) -> new ExprIntegerValue(v.integerValue())), INTEGER, DOUBLE), - impl(nullMissingHandling( - (v) -> new ExprIntegerValue(v.booleanValue() ? 1 : 0)), INTEGER, BOOLEAN) - ); + return FunctionDSL.define( + BuiltinFunctionName.CAST_TO_INT.getName(), + impl( + nullMissingHandling((v) -> new ExprIntegerValue(Integer.valueOf(v.stringValue()))), + INTEGER, + STRING), + impl(nullMissingHandling((v) -> new ExprIntegerValue(v.integerValue())), INTEGER, DOUBLE), + impl( + nullMissingHandling((v) -> new ExprIntegerValue(v.booleanValue() ? 1 : 0)), + INTEGER, + BOOLEAN)); } private static DefaultFunctionResolver castToLong() { - return FunctionDSL.define(BuiltinFunctionName.CAST_TO_LONG.getName(), - impl(nullMissingHandling( - (v) -> new ExprLongValue(Long.valueOf(v.stringValue()))), LONG, STRING), - impl(nullMissingHandling( - (v) -> new ExprLongValue(v.longValue())), LONG, DOUBLE), - impl(nullMissingHandling( - (v) -> new ExprLongValue(v.booleanValue() ? 1L : 0L)), LONG, BOOLEAN) - ); + return FunctionDSL.define( + BuiltinFunctionName.CAST_TO_LONG.getName(), + impl( + nullMissingHandling((v) -> new ExprLongValue(Long.valueOf(v.stringValue()))), + LONG, + STRING), + impl(nullMissingHandling((v) -> new ExprLongValue(v.longValue())), LONG, DOUBLE), + impl( + nullMissingHandling((v) -> new ExprLongValue(v.booleanValue() ? 1L : 0L)), + LONG, + BOOLEAN)); } private static DefaultFunctionResolver castToFloat() { - return FunctionDSL.define(BuiltinFunctionName.CAST_TO_FLOAT.getName(), - impl(nullMissingHandling( - (v) -> new ExprFloatValue(Float.valueOf(v.stringValue()))), FLOAT, STRING), - impl(nullMissingHandling( - (v) -> new ExprFloatValue(v.floatValue())), FLOAT, DOUBLE), - impl(nullMissingHandling( - (v) -> new ExprFloatValue(v.booleanValue() ? 1f : 0f)), FLOAT, BOOLEAN) - ); + return FunctionDSL.define( + BuiltinFunctionName.CAST_TO_FLOAT.getName(), + impl( + nullMissingHandling((v) -> new ExprFloatValue(Float.valueOf(v.stringValue()))), + FLOAT, + STRING), + impl(nullMissingHandling((v) -> new ExprFloatValue(v.floatValue())), FLOAT, DOUBLE), + impl( + nullMissingHandling((v) -> new ExprFloatValue(v.booleanValue() ? 1f : 0f)), + FLOAT, + BOOLEAN)); } private static DefaultFunctionResolver castToDouble() { - return FunctionDSL.define(BuiltinFunctionName.CAST_TO_DOUBLE.getName(), - impl(nullMissingHandling( - (v) -> new ExprDoubleValue(Double.valueOf(v.stringValue()))), DOUBLE, STRING), - impl(nullMissingHandling( - (v) -> new ExprDoubleValue(v.doubleValue())), DOUBLE, DOUBLE), - impl(nullMissingHandling( - (v) -> new ExprDoubleValue(v.booleanValue() ? 1D : 0D)), DOUBLE, BOOLEAN) - ); + return FunctionDSL.define( + BuiltinFunctionName.CAST_TO_DOUBLE.getName(), + impl( + nullMissingHandling((v) -> new ExprDoubleValue(Double.valueOf(v.stringValue()))), + DOUBLE, + STRING), + impl(nullMissingHandling((v) -> new ExprDoubleValue(v.doubleValue())), DOUBLE, DOUBLE), + impl( + nullMissingHandling((v) -> new ExprDoubleValue(v.booleanValue() ? 1D : 0D)), + DOUBLE, + BOOLEAN)); } private static DefaultFunctionResolver castToBoolean() { - return FunctionDSL.define(BuiltinFunctionName.CAST_TO_BOOLEAN.getName(), - impl(nullMissingHandling( - (v) -> ExprBooleanValue.of(Boolean.valueOf(v.stringValue()))), BOOLEAN, STRING), - impl(nullMissingHandling( - (v) -> ExprBooleanValue.of(v.doubleValue() != 0)), BOOLEAN, DOUBLE), - impl(nullMissingHandling((v) -> v), BOOLEAN, BOOLEAN) - ); + return FunctionDSL.define( + BuiltinFunctionName.CAST_TO_BOOLEAN.getName(), + impl( + nullMissingHandling((v) -> ExprBooleanValue.of(Boolean.valueOf(v.stringValue()))), + BOOLEAN, + STRING), + impl( + nullMissingHandling((v) -> ExprBooleanValue.of(v.doubleValue() != 0)), BOOLEAN, DOUBLE), + impl(nullMissingHandling((v) -> v), BOOLEAN, BOOLEAN)); } private static DefaultFunctionResolver castToDate() { - return FunctionDSL.define(BuiltinFunctionName.CAST_TO_DATE.getName(), - impl(nullMissingHandling( - (v) -> new ExprDateValue(v.stringValue())), DATE, STRING), - impl(nullMissingHandling( - (v) -> new ExprDateValue(v.dateValue())), DATE, DATETIME), - impl(nullMissingHandling( - (v) -> new ExprDateValue(v.dateValue())), DATE, TIMESTAMP), - impl(nullMissingHandling((v) -> v), DATE, DATE) - ); + return FunctionDSL.define( + BuiltinFunctionName.CAST_TO_DATE.getName(), + impl(nullMissingHandling((v) -> new ExprDateValue(v.stringValue())), DATE, STRING), + impl(nullMissingHandling((v) -> new ExprDateValue(v.dateValue())), DATE, DATETIME), + impl(nullMissingHandling((v) -> new ExprDateValue(v.dateValue())), DATE, TIMESTAMP), + impl(nullMissingHandling((v) -> v), DATE, DATE)); } private static DefaultFunctionResolver castToTime() { - return FunctionDSL.define(BuiltinFunctionName.CAST_TO_TIME.getName(), - impl(nullMissingHandling( - (v) -> new ExprTimeValue(v.stringValue())), TIME, STRING), - impl(nullMissingHandling( - (v) -> new ExprTimeValue(v.timeValue())), TIME, DATETIME), - impl(nullMissingHandling( - (v) -> new ExprTimeValue(v.timeValue())), TIME, TIMESTAMP), - impl(nullMissingHandling((v) -> v), TIME, TIME) - ); + return FunctionDSL.define( + BuiltinFunctionName.CAST_TO_TIME.getName(), + impl(nullMissingHandling((v) -> new ExprTimeValue(v.stringValue())), TIME, STRING), + impl(nullMissingHandling((v) -> new ExprTimeValue(v.timeValue())), TIME, DATETIME), + impl(nullMissingHandling((v) -> new ExprTimeValue(v.timeValue())), TIME, TIMESTAMP), + impl(nullMissingHandling((v) -> v), TIME, TIME)); } // `DATE`/`TIME`/`DATETIME` -> `DATETIME`/TIMESTAMP` cast tested in BinaryPredicateOperatorTest private static DefaultFunctionResolver castToTimestamp() { - return FunctionDSL.define(BuiltinFunctionName.CAST_TO_TIMESTAMP.getName(), - impl(nullMissingHandling( - (v) -> new ExprTimestampValue(v.stringValue())), TIMESTAMP, STRING), - impl(nullMissingHandling( - (v) -> new ExprTimestampValue(v.timestampValue())), TIMESTAMP, DATETIME), - impl(nullMissingHandling( - (v) -> new ExprTimestampValue(v.timestampValue())), TIMESTAMP, DATE), - implWithProperties(nullMissingHandlingWithProperties( - (fp, v) -> new ExprTimestampValue(((ExprTimeValue)v).timestampValue(fp))), - TIMESTAMP, TIME), - impl(nullMissingHandling((v) -> v), TIMESTAMP, TIMESTAMP) - ); + return FunctionDSL.define( + BuiltinFunctionName.CAST_TO_TIMESTAMP.getName(), + impl( + nullMissingHandling((v) -> new ExprTimestampValue(v.stringValue())), TIMESTAMP, STRING), + impl( + nullMissingHandling((v) -> new ExprTimestampValue(v.timestampValue())), + TIMESTAMP, + DATETIME), + impl( + nullMissingHandling((v) -> new ExprTimestampValue(v.timestampValue())), + TIMESTAMP, + DATE), + implWithProperties( + nullMissingHandlingWithProperties( + (fp, v) -> new ExprTimestampValue(((ExprTimeValue) v).timestampValue(fp))), + TIMESTAMP, + TIME), + impl(nullMissingHandling((v) -> v), TIMESTAMP, TIMESTAMP)); } private static DefaultFunctionResolver castToDatetime() { - return FunctionDSL.define(BuiltinFunctionName.CAST_TO_DATETIME.getName(), - impl(nullMissingHandling( - (v) -> new ExprDatetimeValue(v.stringValue())), DATETIME, STRING), - impl(nullMissingHandling( - (v) -> new ExprDatetimeValue(v.datetimeValue())), DATETIME, TIMESTAMP), - impl(nullMissingHandling( - (v) -> new ExprDatetimeValue(v.datetimeValue())), DATETIME, DATE), - implWithProperties(nullMissingHandlingWithProperties( - (fp, v) -> new ExprDatetimeValue(((ExprTimeValue)v).datetimeValue(fp))), - DATETIME, TIME), - impl(nullMissingHandling((v) -> v), DATETIME, DATETIME) - ); + return FunctionDSL.define( + BuiltinFunctionName.CAST_TO_DATETIME.getName(), + impl(nullMissingHandling((v) -> new ExprDatetimeValue(v.stringValue())), DATETIME, STRING), + impl( + nullMissingHandling((v) -> new ExprDatetimeValue(v.datetimeValue())), + DATETIME, + TIMESTAMP), + impl(nullMissingHandling((v) -> new ExprDatetimeValue(v.datetimeValue())), DATETIME, DATE), + implWithProperties( + nullMissingHandlingWithProperties( + (fp, v) -> new ExprDatetimeValue(((ExprTimeValue) v).datetimeValue(fp))), + DATETIME, + TIME), + impl(nullMissingHandling((v) -> v), DATETIME, DATETIME)); } } diff --git a/core/src/main/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperator.java b/core/src/main/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperator.java index cc5b47bde1..bf6b3c22f5 100644 --- a/core/src/main/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperator.java +++ b/core/src/main/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperator.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.operator.predicate; import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_FALSE; @@ -30,10 +29,10 @@ import org.opensearch.sql.utils.OperatorUtils; /** - * The definition of binary predicate function - * and, Accepts two Boolean values and produces a Boolean. - * or, Accepts two Boolean values and produces a Boolean. - * xor, Accepts two Boolean values and produces a Boolean. + * The definition of binary predicate function
+ * and, Accepts two Boolean values and produces a Boolean.
+ * or, Accepts two Boolean values and produces a Boolean.
+ * xor, Accepts two Boolean values and produces a Boolean.
* equalTo, Compare the left expression and right expression and produces a Boolean. */ @UtilityClass @@ -60,17 +59,64 @@ public static void register(BuiltinFunctionRepository repository) { /** * The and logic. - * A B A AND B - * TRUE TRUE TRUE - * TRUE FALSE FALSE - * TRUE NULL NULL - * TRUE MISSING MISSING - * FALSE FALSE FALSE - * FALSE NULL FALSE - * FALSE MISSING FALSE - * NULL NULL NULL - * NULL MISSING MISSING - * MISSING MISSING MISSING + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
ABA AND B
TRUETRUETRUE
TRUEFALSEFALSE
TRUENULLNULL
TRUEMISSINGMISSING
FALSEFALSEFALSE
FALSENULLFALSE
FALSEMISSINGFALSE
NULLNULLNULL
NULLMISSINGMISSING
MISSINGMISSINGMISSING
*/ private static Table andTable = new ImmutableTable.Builder() @@ -88,17 +134,64 @@ public static void register(BuiltinFunctionRepository repository) { /** * The or logic. - * A B A AND B - * TRUE TRUE TRUE - * TRUE FALSE TRUE - * TRUE NULL TRUE - * TRUE MISSING TRUE - * FALSE FALSE FALSE - * FALSE NULL NULL - * FALSE MISSING MISSING - * NULL NULL NULL - * NULL MISSING NULL - * MISSING MISSING MISSING + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
ABA OR B
TRUETRUETRUE
TRUEFALSETRUE
TRUENULLTRUE
TRUEMISSINGTRUE
FALSEFALSEFALSE
FALSENULLNULL
FALSEMISSINGMISSING
NULLNULLNULL
NULLMISSINGNULL
MISSINGMISSINGMISSING
*/ private static Table orTable = new ImmutableTable.Builder() @@ -116,17 +209,64 @@ public static void register(BuiltinFunctionRepository repository) { /** * The xor logic. - * A B A AND B - * TRUE TRUE FALSE - * TRUE FALSE TRUE - * TRUE NULL TRUE - * TRUE MISSING TRUE - * FALSE FALSE FALSE - * FALSE NULL NULL - * FALSE MISSING MISSING - * NULL NULL NULL - * NULL MISSING NULL - * MISSING MISSING MISSING + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
ABA XOR B
TRUETRUEFALSE
TRUEFALSETRUE
TRUENULLTRUE
TRUEMISSINGTRUE
FALSEFALSEFALSE
FALSENULLNULL
FALSEMISSINGMISSING
NULLNULLNULL
NULLMISSINGNULL
MISSINGMISSINGMISSING
*/ private static Table xorTable = new ImmutableTable.Builder() @@ -143,87 +283,132 @@ public static void register(BuiltinFunctionRepository repository) { .build(); private static DefaultFunctionResolver and() { - return define(BuiltinFunctionName.AND.getName(), + return define( + BuiltinFunctionName.AND.getName(), impl((v1, v2) -> lookupTableFunction(v1, v2, andTable), BOOLEAN, BOOLEAN, BOOLEAN)); } private static DefaultFunctionResolver or() { - return define(BuiltinFunctionName.OR.getName(), + return define( + BuiltinFunctionName.OR.getName(), impl((v1, v2) -> lookupTableFunction(v1, v2, orTable), BOOLEAN, BOOLEAN, BOOLEAN)); } private static DefaultFunctionResolver xor() { - return define(BuiltinFunctionName.XOR.getName(), + return define( + BuiltinFunctionName.XOR.getName(), impl((v1, v2) -> lookupTableFunction(v1, v2, xorTable), BOOLEAN, BOOLEAN, BOOLEAN)); } private static DefaultFunctionResolver equal() { - return define(BuiltinFunctionName.EQUAL.getName(), ExprCoreType.coreTypes().stream() - .map(type -> impl(nullMissingHandling( - (v1, v2) -> ExprBooleanValue.of(v1.equals(v2))), - BOOLEAN, type, type)) - .collect(Collectors.toList())); + return define( + BuiltinFunctionName.EQUAL.getName(), + ExprCoreType.coreTypes().stream() + .map( + type -> + impl( + nullMissingHandling((v1, v2) -> ExprBooleanValue.of(v1.equals(v2))), + BOOLEAN, + type, + type)) + .collect(Collectors.toList())); } private static DefaultFunctionResolver notEqual() { - return define(BuiltinFunctionName.NOTEQUAL.getName(), ExprCoreType.coreTypes().stream() - .map(type -> impl(nullMissingHandling( - (v1, v2) -> ExprBooleanValue.of(!v1.equals(v2))), - BOOLEAN, type, type)) - .collect(Collectors.toList())); + return define( + BuiltinFunctionName.NOTEQUAL.getName(), + ExprCoreType.coreTypes().stream() + .map( + type -> + impl( + nullMissingHandling((v1, v2) -> ExprBooleanValue.of(!v1.equals(v2))), + BOOLEAN, + type, + type)) + .collect(Collectors.toList())); } private static DefaultFunctionResolver less() { - return define(BuiltinFunctionName.LESS.getName(), ExprCoreType.coreTypes().stream() - .map(type -> impl(nullMissingHandling( - (v1, v2) -> ExprBooleanValue.of(v1.compareTo(v2) < 0)), - BOOLEAN,type, type)) - .collect(Collectors.toList())); + return define( + BuiltinFunctionName.LESS.getName(), + ExprCoreType.coreTypes().stream() + .map( + type -> + impl( + nullMissingHandling((v1, v2) -> ExprBooleanValue.of(v1.compareTo(v2) < 0)), + BOOLEAN, + type, + type)) + .collect(Collectors.toList())); } private static DefaultFunctionResolver lte() { - return define(BuiltinFunctionName.LTE.getName(), ExprCoreType.coreTypes().stream() - .map(type -> impl(nullMissingHandling( - (v1, v2) -> ExprBooleanValue.of(v1.compareTo(v2) <= 0)), - BOOLEAN, type, type)) - .collect(Collectors.toList())); + return define( + BuiltinFunctionName.LTE.getName(), + ExprCoreType.coreTypes().stream() + .map( + type -> + impl( + nullMissingHandling((v1, v2) -> ExprBooleanValue.of(v1.compareTo(v2) <= 0)), + BOOLEAN, + type, + type)) + .collect(Collectors.toList())); } private static DefaultFunctionResolver greater() { - return define(BuiltinFunctionName.GREATER.getName(), ExprCoreType.coreTypes().stream() - .map(type -> impl(nullMissingHandling( - (v1, v2) -> ExprBooleanValue.of(v1.compareTo(v2) > 0)), - BOOLEAN, type, type)) - .collect(Collectors.toList())); + return define( + BuiltinFunctionName.GREATER.getName(), + ExprCoreType.coreTypes().stream() + .map( + type -> + impl( + nullMissingHandling((v1, v2) -> ExprBooleanValue.of(v1.compareTo(v2) > 0)), + BOOLEAN, + type, + type)) + .collect(Collectors.toList())); } private static DefaultFunctionResolver gte() { - return define(BuiltinFunctionName.GTE.getName(), ExprCoreType.coreTypes().stream() - .map(type -> impl(nullMissingHandling( - (v1, v2) -> ExprBooleanValue.of(v1.compareTo(v2) >= 0)), - BOOLEAN, type, type)) - .collect(Collectors.toList())); + return define( + BuiltinFunctionName.GTE.getName(), + ExprCoreType.coreTypes().stream() + .map( + type -> + impl( + nullMissingHandling((v1, v2) -> ExprBooleanValue.of(v1.compareTo(v2) >= 0)), + BOOLEAN, + type, + type)) + .collect(Collectors.toList())); } private static DefaultFunctionResolver like() { - return define(BuiltinFunctionName.LIKE.getName(), + return define( + BuiltinFunctionName.LIKE.getName(), impl(nullMissingHandling(OperatorUtils::matches), BOOLEAN, STRING, STRING)); } private static DefaultFunctionResolver regexp() { - return define(BuiltinFunctionName.REGEXP.getName(), + return define( + BuiltinFunctionName.REGEXP.getName(), impl(nullMissingHandling(OperatorUtils::matchesRegexp), INTEGER, STRING, STRING)); } private static DefaultFunctionResolver notLike() { - return define(BuiltinFunctionName.NOT_LIKE.getName(), - impl(nullMissingHandling( - (v1, v2) -> UnaryPredicateOperator.not(OperatorUtils.matches(v1, v2))), - BOOLEAN, STRING, STRING)); + return define( + BuiltinFunctionName.NOT_LIKE.getName(), + impl( + nullMissingHandling( + (v1, v2) -> UnaryPredicateOperator.not(OperatorUtils.matches(v1, v2))), + BOOLEAN, + STRING, + STRING)); } - private static ExprValue lookupTableFunction(ExprValue arg1, ExprValue arg2, - Table table) { + private static ExprValue lookupTableFunction( + ExprValue arg1, ExprValue arg2, Table table) { if (table.contains(arg1, arg2)) { return table.get(arg1, arg2); } else { diff --git a/core/src/main/java/org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator.java b/core/src/main/java/org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator.java index 7d79d9d923..ad9d9ac934 100644 --- a/core/src/main/java/org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator.java +++ b/core/src/main/java/org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.operator.predicate; import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_NULL; @@ -28,14 +27,11 @@ import org.opensearch.sql.expression.function.SerializableFunction; /** - * The definition of unary predicate function - * not, Accepts one Boolean value and produces a Boolean. + * The definition of unary predicate function not, Accepts one Boolean value and produces a Boolean. */ @UtilityClass public class UnaryPredicateOperator { - /** - * Register Unary Predicate Function. - */ + /** Register Unary Predicate Function. */ public static void register(BuiltinFunctionRepository repository) { repository.register(not()); repository.register(isNotNull()); @@ -47,17 +43,36 @@ public static void register(BuiltinFunctionRepository repository) { } private static DefaultFunctionResolver not() { - return FunctionDSL.define(BuiltinFunctionName.NOT.getName(), FunctionDSL - .impl(UnaryPredicateOperator::not, BOOLEAN, BOOLEAN)); + return FunctionDSL.define( + BuiltinFunctionName.NOT.getName(), + FunctionDSL.impl(UnaryPredicateOperator::not, BOOLEAN, BOOLEAN)); } /** * The not logic. - * A NOT A - * TRUE FALSE - * FALSE TRUE - * NULL NULL - * MISSING MISSING + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
ANOT A
TRUEFALSE
FALSETRUE
NULLNULL
MISSINGMISSING
*/ public ExprValue not(ExprValue v) { if (v.isMissing() || v.isNull()) { @@ -68,31 +83,33 @@ public ExprValue not(ExprValue v) { } private static DefaultFunctionResolver isNull(BuiltinFunctionName funcName) { - return FunctionDSL - .define(funcName.getName(), Arrays.stream(ExprCoreType.values()) - .map(type -> FunctionDSL - .impl((v) -> ExprBooleanValue.of(v.isNull()), BOOLEAN, type)) - .collect( - Collectors.toList())); + return FunctionDSL.define( + funcName.getName(), + Arrays.stream(ExprCoreType.values()) + .map(type -> FunctionDSL.impl((v) -> ExprBooleanValue.of(v.isNull()), BOOLEAN, type)) + .collect(Collectors.toList())); } private static DefaultFunctionResolver isNotNull() { - return FunctionDSL - .define(BuiltinFunctionName.IS_NOT_NULL.getName(), Arrays.stream(ExprCoreType.values()) - .map(type -> FunctionDSL - .impl((v) -> ExprBooleanValue.of(!v.isNull()), BOOLEAN, type)) - .collect( - Collectors.toList())); + return FunctionDSL.define( + BuiltinFunctionName.IS_NOT_NULL.getName(), + Arrays.stream(ExprCoreType.values()) + .map(type -> FunctionDSL.impl((v) -> ExprBooleanValue.of(!v.isNull()), BOOLEAN, type)) + .collect(Collectors.toList())); } private static DefaultFunctionResolver ifFunction() { FunctionName functionName = BuiltinFunctionName.IF.getName(); List typeList = ExprCoreType.coreTypes(); - List>> functionsOne = typeList.stream().map(v -> - impl((UnaryPredicateOperator::exprIf), v, BOOLEAN, v, v)) - .collect(Collectors.toList()); + List< + SerializableFunction< + FunctionName, + org.apache.commons.lang3.tuple.Pair>> + functionsOne = + typeList.stream() + .map(v -> impl((UnaryPredicateOperator::exprIf), v, BOOLEAN, v, v)) + .collect(Collectors.toList()); DefaultFunctionResolver functionResolver = FunctionDSL.define(functionName, functionsOne); return functionResolver; @@ -102,10 +119,14 @@ private static DefaultFunctionResolver ifNull() { FunctionName functionName = BuiltinFunctionName.IFNULL.getName(); List typeList = ExprCoreType.coreTypes(); - List>> functionsOne = typeList.stream().map(v -> - impl((UnaryPredicateOperator::exprIfNull), v, v, v)) - .collect(Collectors.toList()); + List< + SerializableFunction< + FunctionName, + org.apache.commons.lang3.tuple.Pair>> + functionsOne = + typeList.stream() + .map(v -> impl((UnaryPredicateOperator::exprIfNull), v, v, v)) + .collect(Collectors.toList()); DefaultFunctionResolver functionResolver = FunctionDSL.define(functionName, functionsOne); return functionResolver; @@ -116,14 +137,16 @@ private static DefaultFunctionResolver nullIf() { List typeList = ExprCoreType.coreTypes(); DefaultFunctionResolver functionResolver = - FunctionDSL.define(functionName, - typeList.stream().map(v -> - impl((UnaryPredicateOperator::exprNullIf), v, v, v)) - .collect(Collectors.toList())); + FunctionDSL.define( + functionName, + typeList.stream() + .map(v -> impl((UnaryPredicateOperator::exprNullIf), v, v, v)) + .collect(Collectors.toList())); return functionResolver; } - /** v2 if v1 is null. + /** + * v2 if v1 is null. * * @param v1 varable 1 * @param v2 varable 2 @@ -133,7 +156,8 @@ public static ExprValue exprIfNull(ExprValue v1, ExprValue v2) { return (v1.isNull() || v1.isMissing()) ? v2 : v1; } - /** return null if v1 equls to v2. + /** + * return null if v1 equls to v2. * * @param v1 varable 1 * @param v2 varable 2 @@ -146,5 +170,4 @@ public static ExprValue exprNullIf(ExprValue v1, ExprValue v2) { public static ExprValue exprIf(ExprValue v1, ExprValue v2, ExprValue v3) { return !v1.isNull() && !v1.isMissing() && LITERAL_TRUE.equals(v1) ? v2 : v3; } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/parse/GrokExpression.java b/core/src/main/java/org/opensearch/sql/expression/parse/GrokExpression.java index 9797832f07..748ce5f559 100644 --- a/core/src/main/java/org/opensearch/sql/expression/parse/GrokExpression.java +++ b/core/src/main/java/org/opensearch/sql/expression/parse/GrokExpression.java @@ -20,9 +20,7 @@ import org.opensearch.sql.exception.ExpressionEvaluationException; import org.opensearch.sql.expression.Expression; -/** - * GrokExpression with grok patterns. - */ +/** GrokExpression with grok patterns. */ @EqualsAndHashCode(callSuper = true) @ToString public class GrokExpression extends ParseExpression { @@ -33,15 +31,14 @@ public class GrokExpression extends ParseExpression { grokCompiler.registerDefaultPatterns(); } - @EqualsAndHashCode.Exclude - private final Grok grok; + @EqualsAndHashCode.Exclude private final Grok grok; /** * GrokExpression. * * @param sourceField source text field - * @param pattern pattern used for parsing - * @param identifier derived field + * @param pattern pattern used for parsing + * @param identifier derived field */ public GrokExpression(Expression sourceField, Expression pattern, Expression identifier) { super("grok", sourceField, pattern, identifier); @@ -69,7 +66,9 @@ ExprValue parseValue(ExprValue value) throws ExpressionEvaluationException { */ public static List getNamedGroupCandidates(String pattern) { Grok grok = grokCompiler.compile(pattern); - return grok.namedGroups.stream().map(grok::getNamedRegexCollectionById) - .filter(group -> !group.equals("UNWANTED")).collect(Collectors.toUnmodifiableList()); + return grok.namedGroups.stream() + .map(grok::getNamedRegexCollectionById) + .filter(group -> !group.equals("UNWANTED")) + .collect(Collectors.toUnmodifiableList()); } } diff --git a/core/src/main/java/org/opensearch/sql/expression/parse/ParseExpression.java b/core/src/main/java/org/opensearch/sql/expression/parse/ParseExpression.java index 8d1ebcce08..6e2456ecc2 100644 --- a/core/src/main/java/org/opensearch/sql/expression/parse/ParseExpression.java +++ b/core/src/main/java/org/opensearch/sql/expression/parse/ParseExpression.java @@ -21,29 +21,25 @@ import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.FunctionName; -/** - * ParseExpression. - */ +/** ParseExpression. */ @EqualsAndHashCode(callSuper = false) @ToString public abstract class ParseExpression extends FunctionExpression { - @Getter - protected final Expression sourceField; + @Getter protected final Expression sourceField; protected final Expression pattern; - @Getter - protected final Expression identifier; + @Getter protected final Expression identifier; protected final String identifierStr; /** * ParseExpression. * * @param functionName name of function expression - * @param sourceField source text field - * @param pattern pattern used for parsing - * @param identifier derived field + * @param sourceField source text field + * @param pattern pattern used for parsing + * @param identifier derived field */ - public ParseExpression(String functionName, Expression sourceField, Expression pattern, - Expression identifier) { + public ParseExpression( + String functionName, Expression sourceField, Expression pattern, Expression identifier) { super(FunctionName.of(functionName), ImmutableList.of(sourceField, pattern, identifier)); this.sourceField = sourceField; this.pattern = pattern; diff --git a/core/src/main/java/org/opensearch/sql/expression/parse/PatternsExpression.java b/core/src/main/java/org/opensearch/sql/expression/parse/PatternsExpression.java index 67160dad58..5b92779c35 100644 --- a/core/src/main/java/org/opensearch/sql/expression/parse/PatternsExpression.java +++ b/core/src/main/java/org/opensearch/sql/expression/parse/PatternsExpression.java @@ -17,30 +17,28 @@ import org.opensearch.sql.exception.ExpressionEvaluationException; import org.opensearch.sql.expression.Expression; -/** - * PatternsExpression with regex filter. - */ +/** PatternsExpression with regex filter. */ @EqualsAndHashCode(callSuper = true) @ToString public class PatternsExpression extends ParseExpression { - /** - * Default name of the derived field. - */ + /** Default name of the derived field. */ public static final String DEFAULT_NEW_FIELD = "patterns_field"; - private static final ImmutableSet DEFAULT_IGNORED_CHARS = ImmutableSet.copyOf( - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".chars() - .mapToObj(c -> (char) c).toArray(Character[]::new)); + private static final ImmutableSet DEFAULT_IGNORED_CHARS = + ImmutableSet.copyOf( + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + .chars() + .mapToObj(c -> (char) c) + .toArray(Character[]::new)); private final boolean useCustomPattern; - @EqualsAndHashCode.Exclude - private Pattern pattern; + @EqualsAndHashCode.Exclude private Pattern pattern; /** * PatternsExpression. * * @param sourceField source text field - * @param pattern pattern used for parsing - * @param identifier derived field + * @param pattern pattern used for parsing + * @param identifier derived field */ public PatternsExpression(Expression sourceField, Expression pattern, Expression identifier) { super("patterns", sourceField, pattern, identifier); diff --git a/core/src/main/java/org/opensearch/sql/expression/parse/RegexExpression.java b/core/src/main/java/org/opensearch/sql/expression/parse/RegexExpression.java index f3a3ff0b66..7514c9df69 100644 --- a/core/src/main/java/org/opensearch/sql/expression/parse/RegexExpression.java +++ b/core/src/main/java/org/opensearch/sql/expression/parse/RegexExpression.java @@ -19,24 +19,20 @@ import org.opensearch.sql.exception.ExpressionEvaluationException; import org.opensearch.sql.expression.Expression; -/** - * RegexExpression with regex and named capture group. - */ +/** RegexExpression with regex and named capture group. */ @EqualsAndHashCode(callSuper = true) @ToString public class RegexExpression extends ParseExpression { private static final Logger log = LogManager.getLogger(RegexExpression.class); private static final Pattern GROUP_PATTERN = Pattern.compile("\\(\\?<([a-zA-Z][a-zA-Z0-9]*)>"); - @Getter - @EqualsAndHashCode.Exclude - private final Pattern regexPattern; + @Getter @EqualsAndHashCode.Exclude private final Pattern regexPattern; /** * RegexExpression. * * @param sourceField source text field - * @param pattern pattern used for parsing - * @param identifier derived field + * @param pattern pattern used for parsing + * @param identifier derived field */ public RegexExpression(Expression sourceField, Expression pattern, Expression identifier) { super("regex", sourceField, pattern, identifier); diff --git a/core/src/main/java/org/opensearch/sql/expression/span/SpanExpression.java b/core/src/main/java/org/opensearch/sql/expression/span/SpanExpression.java index aff114145e..949ed52e7f 100644 --- a/core/src/main/java/org/opensearch/sql/expression/span/SpanExpression.java +++ b/core/src/main/java/org/opensearch/sql/expression/span/SpanExpression.java @@ -24,9 +24,7 @@ public class SpanExpression implements Expression { private final Expression value; private final SpanUnit unit; - /** - * Construct a span expression by field and span interval expression. - */ + /** Construct a span expression by field and span interval expression. */ public SpanExpression(Expression field, Expression value, SpanUnit unit) { this.field = field; this.value = value; @@ -35,18 +33,46 @@ public SpanExpression(Expression field, Expression value, SpanUnit unit) { @Override public ExprValue valueOf(Environment valueEnv) { - Rounding rounding = Rounding.createRounding(this); //TODO: will integrate with WindowAssigner + Rounding rounding = + Rounding.createRounding(this); // TODO: will integrate with WindowAssigner return rounding.round(field.valueOf(valueEnv)); } /** * Return type follows the following table. - * FIELD VALUE RETURN_TYPE - * int/long integer int/long (field type) - * int/long double double - * float/double integer float/double (field type) - * float/double double float/double (field type) - * other any field type + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
FIELDVALUERETURN_TYPE
int/longintegerint/long (field type)
int/longdoubledouble
float/doubleintegerfloat/double (field type)
float/doubledoublefloat/double (field type)
otheranyfield type
*/ @Override public ExprType type() { diff --git a/core/src/main/java/org/opensearch/sql/expression/system/SystemFunctions.java b/core/src/main/java/org/opensearch/sql/expression/system/SystemFunctions.java index e12bcd0a58..cf071c4f31 100644 --- a/core/src/main/java/org/opensearch/sql/expression/system/SystemFunctions.java +++ b/core/src/main/java/org/opensearch/sql/expression/system/SystemFunctions.java @@ -24,9 +24,7 @@ @UtilityClass public class SystemFunctions { - /** - * Register TypeOf Operator. - */ + /** Register TypeOf Operator. */ public static void register(BuiltinFunctionRepository repository) { repository.register(typeof()); } @@ -37,19 +35,20 @@ private static FunctionResolver typeof() { @Override public Pair resolve( FunctionSignature unresolvedSignature) { - return Pair.of(unresolvedSignature, + return Pair.of( + unresolvedSignature, (functionProperties, arguments) -> new FunctionExpression(BuiltinFunctionName.TYPEOF.getName(), arguments) { - @Override - public ExprValue valueOf(Environment valueEnv) { - return new ExprStringValue(getArguments().get(0).type().legacyTypeName()); - } + @Override + public ExprValue valueOf(Environment valueEnv) { + return new ExprStringValue(getArguments().get(0).type().legacyTypeName()); + } - @Override - public ExprType type() { - return STRING; - } - }); + @Override + public ExprType type() { + return STRING; + } + }); } @Override diff --git a/core/src/main/java/org/opensearch/sql/expression/text/TextFunction.java b/core/src/main/java/org/opensearch/sql/expression/text/TextFunction.java index 0bbfb65154..1cf7f64867 100644 --- a/core/src/main/java/org/opensearch/sql/expression/text/TextFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/text/TextFunction.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.text; import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; @@ -35,9 +34,8 @@ import org.opensearch.sql.expression.function.SerializableTriFunction; /** - * The definition of text functions. - * 1) have the clear interface for function define. - * 2) the implementation should rely on ExprValue. + * The definition of text functions. 1) have the clear interface for function define. 2) the + * implementation should rely on ExprValue. */ @UtilityClass public class TextFunction { @@ -70,17 +68,21 @@ public void register(BuiltinFunctionRepository repository) { } /** - * Gets substring starting at given point, for optional given length. - * Form of this function using keywords instead of comma delimited variables is not supported. - * Supports following signatures: + * Gets substring starting at given point, for optional given length.
+ * Form of this function using keywords instead of comma delimited variables is not supported.
+ * Supports following signatures:
* (STRING, INTEGER)/(STRING, INTEGER, INTEGER) -> STRING */ private DefaultFunctionResolver substringSubstr(FunctionName functionName) { - return define(functionName, - impl(nullMissingHandling(TextFunction::exprSubstrStart), - STRING, STRING, INTEGER), - impl(nullMissingHandling(TextFunction::exprSubstrStartLength), - STRING, STRING, INTEGER, INTEGER)); + return define( + functionName, + impl(nullMissingHandling(TextFunction::exprSubstrStart), STRING, STRING, INTEGER), + impl( + nullMissingHandling(TextFunction::exprSubstrStartLength), + STRING, + STRING, + INTEGER, + INTEGER)); } private DefaultFunctionResolver substring() { @@ -92,222 +94,277 @@ private DefaultFunctionResolver substr() { } /** - * Removes leading whitespace from string. - * Supports following signatures: + * Removes leading whitespace from string.
+ * Supports following signatures:
* STRING -> STRING */ private DefaultFunctionResolver ltrim() { - return define(BuiltinFunctionName.LTRIM.getName(), - impl(nullMissingHandling((v) -> new ExprStringValue(v.stringValue().stripLeading())), - STRING, STRING)); + return define( + BuiltinFunctionName.LTRIM.getName(), + impl( + nullMissingHandling((v) -> new ExprStringValue(v.stringValue().stripLeading())), + STRING, + STRING)); } /** - * Removes trailing whitespace from string. - * Supports following signatures: + * Removes trailing whitespace from string.
+ * Supports following signatures:
* STRING -> STRING */ private DefaultFunctionResolver rtrim() { - return define(BuiltinFunctionName.RTRIM.getName(), - impl(nullMissingHandling((v) -> new ExprStringValue(v.stringValue().stripTrailing())), - STRING, STRING)); + return define( + BuiltinFunctionName.RTRIM.getName(), + impl( + nullMissingHandling((v) -> new ExprStringValue(v.stringValue().stripTrailing())), + STRING, + STRING)); } /** - * Removes leading and trailing whitespace from string. - * Has option to specify a String to trim instead of whitespace but this is not yet supported. - * Supporting String specification requires finding keywords inside TRIM command. - * Supports following signatures: + * Removes leading and trailing whitespace from string.
+ * Has option to specify a String to trim instead of whitespace but this is not yet supported.
+ * Supporting String specification requires finding keywords inside TRIM command.
+ * Supports following signatures:
* STRING -> STRING */ private DefaultFunctionResolver trim() { - return define(BuiltinFunctionName.TRIM.getName(), - impl(nullMissingHandling((v) -> new ExprStringValue(v.stringValue().trim())), - STRING, STRING)); + return define( + BuiltinFunctionName.TRIM.getName(), + impl( + nullMissingHandling((v) -> new ExprStringValue(v.stringValue().trim())), + STRING, + STRING)); } /** - * Converts String to lowercase. - * Supports following signatures: + * Converts String to lowercase.
+ * Supports following signatures:
* STRING -> STRING */ private DefaultFunctionResolver lower() { - return define(BuiltinFunctionName.LOWER.getName(), - impl(nullMissingHandling((v) -> new ExprStringValue((v.stringValue().toLowerCase()))), - STRING, STRING) - ); + return define( + BuiltinFunctionName.LOWER.getName(), + impl( + nullMissingHandling((v) -> new ExprStringValue((v.stringValue().toLowerCase()))), + STRING, + STRING)); } /** - * Converts String to uppercase. - * Supports following signatures: + * Converts String to uppercase.
+ * Supports following signatures:
* STRING -> STRING */ private DefaultFunctionResolver upper() { - return define(BuiltinFunctionName.UPPER.getName(), - impl(nullMissingHandling((v) -> new ExprStringValue((v.stringValue().toUpperCase()))), - STRING, STRING) - ); + return define( + BuiltinFunctionName.UPPER.getName(), + impl( + nullMissingHandling((v) -> new ExprStringValue((v.stringValue().toUpperCase()))), + STRING, + STRING)); } /** - * Concatenates a list of Strings. - * Supports following signatures: + * Concatenates a list of Strings.
+ * Supports following signatures:
* (STRING, STRING, ...., STRING) -> STRING */ private DefaultFunctionResolver concat() { FunctionName concatFuncName = BuiltinFunctionName.CONCAT.getName(); - return define(concatFuncName, funcName -> + return define( + concatFuncName, + funcName -> Pair.of( - new FunctionSignature(concatFuncName, Collections.singletonList(ARRAY)), - (funcProp, args) -> new FunctionExpression(funcName, args) { + new FunctionSignature(concatFuncName, Collections.singletonList(ARRAY)), + (funcProp, args) -> + new FunctionExpression(funcName, args) { @Override public ExprValue valueOf(Environment valueEnv) { - List exprValues = args.stream() - .map(arg -> arg.valueOf(valueEnv)).collect(Collectors.toList()); - if (exprValues.stream().anyMatch(ExprValue::isMissing)) { - return ExprValueUtils.missingValue(); - } - if (exprValues.stream().anyMatch(ExprValue::isNull)) { - return ExprValueUtils.nullValue(); - } - return new ExprStringValue(exprValues.stream() - .map(ExprValue::stringValue) - .collect(Collectors.joining())); + List exprValues = + args.stream() + .map(arg -> arg.valueOf(valueEnv)) + .collect(Collectors.toList()); + if (exprValues.stream().anyMatch(ExprValue::isMissing)) { + return ExprValueUtils.missingValue(); + } + if (exprValues.stream().anyMatch(ExprValue::isNull)) { + return ExprValueUtils.nullValue(); + } + return new ExprStringValue( + exprValues.stream() + .map(ExprValue::stringValue) + .collect(Collectors.joining())); } @Override public ExprType type() { return STRING; } - } - )); + })); } /** - * TODO: https://github.com/opendistro-for-elasticsearch/sql/issues/710 - * Extend to accept variable argument amounts. - * Concatenates a list of Strings with a separator string. - * Supports following signatures: + * TODO: https://github.com/opendistro-for-elasticsearch/sql/issues/710
+ * Extend to accept variable argument amounts.
+ *
+ * Concatenates a list of Strings with a separator string. Supports following
+ * signatures:
* (STRING, STRING, STRING) -> STRING */ private DefaultFunctionResolver concat_ws() { - return define(BuiltinFunctionName.CONCAT_WS.getName(), - impl(nullMissingHandling((sep, str1, str2) -> - new ExprStringValue(str1.stringValue() + sep.stringValue() + str2.stringValue())), - STRING, STRING, STRING, STRING)); + return define( + BuiltinFunctionName.CONCAT_WS.getName(), + impl( + nullMissingHandling( + (sep, str1, str2) -> + new ExprStringValue( + str1.stringValue() + sep.stringValue() + str2.stringValue())), + STRING, + STRING, + STRING, + STRING)); } /** - * Calculates length of String in bytes. - * Supports following signatures: + * Calculates length of String in bytes.
+ * Supports following signatures:
* STRING -> INTEGER */ private DefaultFunctionResolver length() { - return define(BuiltinFunctionName.LENGTH.getName(), - impl(nullMissingHandling((str) -> - new ExprIntegerValue(str.stringValue().getBytes().length)), INTEGER, STRING)); + return define( + BuiltinFunctionName.LENGTH.getName(), + impl( + nullMissingHandling((str) -> new ExprIntegerValue(str.stringValue().getBytes().length)), + INTEGER, + STRING)); } /** - * Does String comparison of two Strings and returns Integer value. - * Supports following signatures: + * Does String comparison of two Strings and returns Integer value.
+ * Supports following signatures:
* (STRING, STRING) -> INTEGER */ private DefaultFunctionResolver strcmp() { - return define(BuiltinFunctionName.STRCMP.getName(), - impl(nullMissingHandling((str1, str2) -> - new ExprIntegerValue(Integer.compare( - str1.stringValue().compareTo(str2.stringValue()), 0))), - INTEGER, STRING, STRING)); + return define( + BuiltinFunctionName.STRCMP.getName(), + impl( + nullMissingHandling( + (str1, str2) -> + new ExprIntegerValue( + Integer.compare(str1.stringValue().compareTo(str2.stringValue()), 0))), + INTEGER, + STRING, + STRING)); } /** - * Returns the rightmost len characters from the string str, or NULL if any argument is NULL. - * Supports following signatures: + * Returns the rightmost len characters from the string str, or NULL if any argument is + * NULL.
+ * Supports following signatures:
* (STRING, INTEGER) -> STRING */ private DefaultFunctionResolver right() { - return define(BuiltinFunctionName.RIGHT.getName(), - impl(nullMissingHandling(TextFunction::exprRight), STRING, STRING, INTEGER)); + return define( + BuiltinFunctionName.RIGHT.getName(), + impl(nullMissingHandling(TextFunction::exprRight), STRING, STRING, INTEGER)); } /** - * Returns the leftmost len characters from the string str, or NULL if any argument is NULL. - * Supports following signature: + * Returns the leftmost len characters from the string str, or NULL if any argument is + * NULL.
+ * Supports following signature:
* (STRING, INTEGER) -> STRING */ private DefaultFunctionResolver left() { - return define(BuiltinFunctionName.LEFT.getName(), + return define( + BuiltinFunctionName.LEFT.getName(), impl(nullMissingHandling(TextFunction::exprLeft), STRING, STRING, INTEGER)); } /** - * Returns the numeric value of the leftmost character of the string str. - * Returns 0 if str is the empty string. Returns NULL if str is NULL. - * ASCII() works for 8-bit characters. - * Supports following signature: + * Returns the numeric value of the leftmost character of the string str.
+ * Returns 0 if str is the empty string. Returns NULL if str is NULL.
+ * ASCII() works for 8-bit characters.
+ * Supports following signature:
* STRING -> INTEGER */ private DefaultFunctionResolver ascii() { - return define(BuiltinFunctionName.ASCII.getName(), + return define( + BuiltinFunctionName.ASCII.getName(), impl(nullMissingHandling(TextFunction::exprAscii), INTEGER, STRING)); } /** - * LOCATE(substr, str) returns the position of the first occurrence of substring substr - * in string str. LOCATE(substr, str, pos) returns the position of the first occurrence - * of substring substr in string str, starting at position pos. - * Returns 0 if substr is not in str. - * Returns NULL if any argument is NULL. - * Supports following signature: - * (STRING, STRING) -> INTEGER + * LOCATE(substr, str) returns the position of the first occurrence of substring substr
+ * in string str. LOCATE(substr, str, pos) returns the position of the first occurrence
+ * of substring substr in string str, starting at position pos.
+ * Returns 0 if substr is not in str.
+ * Returns NULL if any argument is NULL.
+ * Supports following signature:
+ * (STRING, STRING) -> INTEGER
* (STRING, STRING, INTEGER) -> INTEGER */ private DefaultFunctionResolver locate() { - return define(BuiltinFunctionName.LOCATE.getName(), - impl(nullMissingHandling( - (SerializableBiFunction) - TextFunction::exprLocate), INTEGER, STRING, STRING), - impl(nullMissingHandling( - (SerializableTriFunction) - TextFunction::exprLocate), INTEGER, STRING, STRING, INTEGER)); + return define( + BuiltinFunctionName.LOCATE.getName(), + impl( + nullMissingHandling( + (SerializableBiFunction) TextFunction::exprLocate), + INTEGER, + STRING, + STRING), + impl( + nullMissingHandling( + (SerializableTriFunction) + TextFunction::exprLocate), + INTEGER, + STRING, + STRING, + INTEGER)); } /** - * Returns the position of the first occurrence of a substring in a string starting from 1. - * Returns 0 if substring is not in string. - * Returns NULL if any argument is NULL. - * Supports following signature: + * Returns the position of the first occurrence of a substring in a string starting from 1. + *
+ * Returns 0 if substring is not in string.
+ * Returns NULL if any argument is NULL.
+ * Supports following signature:
* (STRING IN STRING) -> INTEGER */ private DefaultFunctionResolver position() { - return define(BuiltinFunctionName.POSITION.getName(), - impl(nullMissingHandling( - (SerializableBiFunction) - TextFunction::exprLocate), INTEGER, STRING, STRING)); + return define( + BuiltinFunctionName.POSITION.getName(), + impl( + nullMissingHandling( + (SerializableBiFunction) TextFunction::exprLocate), + INTEGER, + STRING, + STRING)); } /** - * REPLACE(str, from_str, to_str) returns the string str with all occurrences of - * the string from_str replaced by the string to_str. - * REPLACE() performs a case-sensitive match when searching for from_str. - * Supports following signature: + * REPLACE(str, from_str, to_str) returns the string str with all occurrences of
+ * the string from_str replaced by the string to_str.

+ * REPLACE() performs a case-sensitive match when searching for from_str.
+ * Supports following signature:
* (STRING, STRING, STRING) -> STRING */ private DefaultFunctionResolver replace() { - return define(BuiltinFunctionName.REPLACE.getName(), + return define( + BuiltinFunctionName.REPLACE.getName(), impl(nullMissingHandling(TextFunction::exprReplace), STRING, STRING, STRING, STRING)); } /** - * REVERSE(str) returns reversed string of the string supplied as an argument - * Returns NULL if the argument is NULL. - * Supports the following signature: + * REVERSE(str) returns reversed string of the string supplied as an argument

+ * Returns NULL if the argument is NULL.
+ * Supports the following signature:
* (STRING) -> STRING */ private DefaultFunctionResolver reverse() { - return define(BuiltinFunctionName.REVERSE.getName(), + return define( + BuiltinFunctionName.REVERSE.getName(), impl(nullMissingHandling(TextFunction::exprReverse), STRING, STRING)); } @@ -321,7 +378,7 @@ private static ExprValue exprSubstrStart(ExprValue exprValue, ExprValue start) { } private static ExprValue exprSubstrStartLength( - ExprValue exprValue, ExprValue start, ExprValue length) { + ExprValue exprValue, ExprValue start, ExprValue length) { int startIdx = start.integerValue(); int len = length.integerValue(); if ((startIdx == 0) || (len == 0)) { diff --git a/core/src/main/java/org/opensearch/sql/expression/window/WindowDefinition.java b/core/src/main/java/org/opensearch/sql/expression/window/WindowDefinition.java index 24751633de..2030ce8062 100644 --- a/core/src/main/java/org/opensearch/sql/expression/window/WindowDefinition.java +++ b/core/src/main/java/org/opensearch/sql/expression/window/WindowDefinition.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.window; import static org.opensearch.sql.ast.tree.Sort.SortOption; @@ -16,9 +15,7 @@ import org.apache.commons.lang3.tuple.Pair; import org.opensearch.sql.expression.Expression; -/** - * Window definition that consists of partition and sort by information for a window. - */ +/** Window definition that consists of partition and sort by information for a window. */ @Data public class WindowDefinition { @@ -27,7 +24,8 @@ public class WindowDefinition { /** * Return all items in partition by and sort list. - * @return all sort items + * + * @return all sort items */ public List> getAllSortItems() { List> allSorts = new ArrayList<>(); @@ -35,5 +33,4 @@ public List> getAllSortItems() { allSorts.addAll(sortList); return allSorts; } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/window/WindowFunctionExpression.java b/core/src/main/java/org/opensearch/sql/expression/window/WindowFunctionExpression.java index a15919bf03..73f0734953 100644 --- a/core/src/main/java/org/opensearch/sql/expression/window/WindowFunctionExpression.java +++ b/core/src/main/java/org/opensearch/sql/expression/window/WindowFunctionExpression.java @@ -3,27 +3,27 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.window; import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.window.frame.WindowFrame; -/** - * Window function abstraction. - */ +/** Window function abstraction. */ public interface WindowFunctionExpression extends Expression { /** - * Create specific window frame based on window definition and what's current window function. - * For now two types of cumulative window frame is returned: - * 1. Ranking window functions: ignore frame definition and always operates on - * previous and current row. - * 2. Aggregate window functions: frame partition into peers and sliding window is not supported. + * Create specific window frame based on window definition and what's current window function. For + * now two types of cumulative window frame is returned: + * + *
    + *
  1. Ranking window functions: ignore frame definition and always operates on previous and + * current row. + *
  2. Aggregate window functions: frame partition into peers and sliding window is not + * supported. + *
* * @param definition window definition - * @return window frame + * @return window frame */ WindowFrame createWindowFrame(WindowDefinition definition); - } diff --git a/core/src/main/java/org/opensearch/sql/expression/window/WindowFunctions.java b/core/src/main/java/org/opensearch/sql/expression/window/WindowFunctions.java index 9a9e0c4c86..3df59c52c0 100644 --- a/core/src/main/java/org/opensearch/sql/expression/window/WindowFunctions.java +++ b/core/src/main/java/org/opensearch/sql/expression/window/WindowFunctions.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.window; import static java.util.Collections.emptyList; @@ -22,16 +21,14 @@ import org.opensearch.sql.expression.window.ranking.RankingWindowFunction; import org.opensearch.sql.expression.window.ranking.RowNumberFunction; -/** - * Window functions that register all window functions in function repository. - */ +/** Window functions that register all window functions in function repository. */ @UtilityClass public class WindowFunctions { /** * Register all window functions to function repository. * - * @param repository function repository + * @param repository function repository */ public void register(BuiltinFunctionRepository repository) { repository.register(rowNumber()); @@ -51,11 +48,11 @@ private DefaultFunctionResolver denseRank() { return rankingFunction(BuiltinFunctionName.DENSE_RANK.getName(), DenseRankFunction::new); } - private DefaultFunctionResolver rankingFunction(FunctionName functionName, - Supplier constructor) { + private DefaultFunctionResolver rankingFunction( + FunctionName functionName, Supplier constructor) { FunctionSignature functionSignature = new FunctionSignature(functionName, emptyList()); FunctionBuilder functionBuilder = (functionProperties, arguments) -> constructor.get(); - return new DefaultFunctionResolver(functionName, - ImmutableMap.of(functionSignature, functionBuilder)); + return new DefaultFunctionResolver( + functionName, ImmutableMap.of(functionSignature, functionBuilder)); } } diff --git a/core/src/main/java/org/opensearch/sql/expression/window/aggregation/AggregateWindowFunction.java b/core/src/main/java/org/opensearch/sql/expression/window/aggregation/AggregateWindowFunction.java index 604f65e6ff..63922ac3fd 100644 --- a/core/src/main/java/org/opensearch/sql/expression/window/aggregation/AggregateWindowFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/window/aggregation/AggregateWindowFunction.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.window.aggregation; import java.util.List; @@ -21,9 +20,7 @@ import org.opensearch.sql.expression.window.frame.PeerRowsWindowFrame; import org.opensearch.sql.expression.window.frame.WindowFrame; -/** - * Aggregate function adapter that adapts Aggregator for window operator use. - */ +/** Aggregate function adapter that adapts Aggregator for window operator use. */ @EqualsAndHashCode @RequiredArgsConstructor public class AggregateWindowFunction implements WindowFunctionExpression { @@ -64,5 +61,4 @@ public T accept(ExpressionNodeVisitor visitor, C context) { public String toString() { return aggregator.toString(); } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/window/frame/CurrentRowWindowFrame.java b/core/src/main/java/org/opensearch/sql/expression/window/frame/CurrentRowWindowFrame.java index 06b19a1488..359486a4ef 100644 --- a/core/src/main/java/org/opensearch/sql/expression/window/frame/CurrentRowWindowFrame.java +++ b/core/src/main/java/org/opensearch/sql/expression/window/frame/CurrentRowWindowFrame.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.window.frame; import com.google.common.collect.PeekingIterator; @@ -21,18 +20,17 @@ import org.opensearch.sql.expression.window.WindowDefinition; /** - * Conceptually, cumulative window frame should hold all seen rows till next partition. - * This class is actually an optimized version that only hold previous and current row. This is - * efficient and sufficient for ranking and aggregate window function support for now, though need - * to add "real" cumulative frame implementation in future as needed. + * Conceptually, cumulative window frame should hold all seen rows till next partition. This class + * is actually an optimized version that only hold previous and current row. This is efficient and + * sufficient for ranking and aggregate window function support for now, though need to add "real" + * cumulative frame implementation in future as needed. */ @EqualsAndHashCode @RequiredArgsConstructor @ToString public class CurrentRowWindowFrame implements WindowFrame { - @Getter - private final WindowDefinition windowDefinition; + @Getter private final WindowDefinition windowDefinition; private ExprValue previous; private ExprValue current; @@ -67,14 +65,12 @@ public ExprValue previous() { private List resolve(List expressions, ExprValue row) { Environment valueEnv = row.bindingTuples(); - return expressions.stream() - .map(expr -> expr.valueOf(valueEnv)) - .collect(Collectors.toList()); + return expressions.stream().map(expr -> expr.valueOf(valueEnv)).collect(Collectors.toList()); } /** - * Current row window frame won't pre-fetch any row ahead. - * So always return false as nothing "cached" in frame. + * Current row window frame won't pre-fetch any row ahead. So always return false as nothing + * "cached" in frame. */ @Override public boolean hasNext() { @@ -85,5 +81,4 @@ public boolean hasNext() { public List next() { return Collections.emptyList(); } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/window/frame/PeerRowsWindowFrame.java b/core/src/main/java/org/opensearch/sql/expression/window/frame/PeerRowsWindowFrame.java index a3e8de40c1..a98826d333 100644 --- a/core/src/main/java/org/opensearch/sql/expression/window/frame/PeerRowsWindowFrame.java +++ b/core/src/main/java/org/opensearch/sql/expression/window/frame/PeerRowsWindowFrame.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.window.frame; import com.google.common.collect.PeekingIterator; @@ -19,9 +18,9 @@ import org.opensearch.sql.expression.window.WindowDefinition; /** - * Window frame that only keep peers (tuples with same value of fields specified in sort list - * in window definition). See PeerWindowFrameTest for details about how this window frame - * interacts with window operator and window function. + * Window frame that only keep peers (tuples with same value of fields specified in sort list in + * window definition). See PeerWindowFrameTest for details about how this window frame interacts + * with window operator and window function. */ @RequiredArgsConstructor public class PeerRowsWindowFrame implements WindowFrame { @@ -29,34 +28,27 @@ public class PeerRowsWindowFrame implements WindowFrame { private final WindowDefinition windowDefinition; /** - * All peer rows (peer means rows in a partition that share same sort key - * based on sort list in window definition. + * All peer rows (peer means rows in a partition that share same sort key based on sort list in + * window definition. */ private final List peers = new ArrayList<>(); - /** - * Which row in the peer is currently being enriched by window function. - */ + /** Which row in the peer is currently being enriched by window function. */ private int position; - /** - * Does row at current position represents a new partition. - */ + /** Does row at current position represents a new partition. */ private boolean isNewPartition = true; - /** - * If any more pre-fetched rows not returned to window operator yet. - */ + /** If any more pre-fetched rows not returned to window operator yet. */ @Override public boolean hasNext() { return position < peers.size(); } /** - * Move position and clear new partition flag. - * Note that because all peer rows have same result from window function, - * this is only returned at first time to change window function state. - * Afterwards, empty list is returned to avoid changes until next peer loaded. + * Move position and clear new partition flag. Note that because all peer rows have same result + * from window function, this is only returned at first time to change window function state. + * Afterward, empty list is returned to avoid changes until next peer loaded. * * @return all rows for the peer */ @@ -70,8 +62,9 @@ public List next() { } /** - * Current row at the position. Because rows are pre-fetched here, - * window operator needs to get them from here too. + * Current row at the position. Because rows are pre-fetched here, window operator needs to get + * them from here too. + * * @return row at current position that being enriched by window function */ @Override @@ -82,11 +75,16 @@ public ExprValue current() { /** * Preload all peer rows if last peer rows done. Note that when no more data in peeking iterator, * there must be rows in frame (hasNext()=true), so no need to check it.hasNext() in this method. - * Load until: - * 1. Different peer found (row with different sort key) - * 2. Or new partition (row with different partition key) - * 3. Or no more rows - * @param it rows iterator + *
+ * Load until:
+ * + *
    + *
  1. Different peer found (row with different sort key) + *
  2. Or new partition (row with different partition key) + *
  3. Or no more rows + *
+ * + * @param it rows iterator */ @Override public void load(PeekingIterator it) { @@ -118,10 +116,7 @@ public boolean isNewPartition() { private boolean isPeer(ExprValue next) { List sortFields = - windowDefinition.getSortList() - .stream() - .map(Pair::getRight) - .collect(Collectors.toList()); + windowDefinition.getSortList().stream().map(Pair::getRight).collect(Collectors.toList()); ExprValue last = peers.get(peers.size() - 1); return resolve(sortFields, last).equals(resolve(sortFields, next)); @@ -139,9 +134,6 @@ private boolean isSamePartition(ExprValue next) { private List resolve(List expressions, ExprValue row) { Environment valueEnv = row.bindingTuples(); - return expressions.stream() - .map(expr -> expr.valueOf(valueEnv)) - .collect(Collectors.toList()); + return expressions.stream().map(expr -> expr.valueOf(valueEnv)).collect(Collectors.toList()); } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/window/frame/WindowFrame.java b/core/src/main/java/org/opensearch/sql/expression/window/frame/WindowFrame.java index 323656547f..657f63e4c9 100644 --- a/core/src/main/java/org/opensearch/sql/expression/window/frame/WindowFrame.java +++ b/core/src/main/java/org/opensearch/sql/expression/window/frame/WindowFrame.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.window.frame; import com.google.common.collect.PeekingIterator; @@ -14,13 +13,17 @@ import org.opensearch.sql.expression.env.Environment; /** - * Window frame that represents a subset of a window which is all data accessible to - * the window function when calculation. Basically there are 3 types of window frame: - * 1) Entire window frame that holds all data of the window - * 2) Cumulative window frame that accumulates one row by another - * 3) Sliding window frame that maintains a sliding window of fixed size - * Note that which type of window frame is used is determined by both window function itself - * and frame definition in a window definition. + * Window frame that represents a subset of a window which is all data accessible to the window + * function when calculation. Basically there are 3 types of window frame: + * + *
    + *
  1. Entire window frame that holds all data of the window + *
  2. Cumulative window frame that accumulates one row by another + *
  3. Sliding window frame that maintains a sliding window of fixed size + *
+ * + * Note that which type of window frame is used is determined by both window function itself and + * frame definition in a window definition. */ public interface WindowFrame extends Environment, Iterator> { @@ -31,20 +34,22 @@ default ExprValue resolve(Expression var) { /** * Check is current row the beginning of a new partition according to window definition. - * @return true if a new partition begins here, otherwise false. + * + * @return true if a new partition begins here, otherwise false. */ boolean isNewPartition(); /** * Load one or more rows as window function calculation needed. - * @param iterator peeking iterator that can peek next element without moving iterator + * + * @param iterator peeking iterator that can peek next element without moving iterator */ void load(PeekingIterator iterator); /** * Get current data row for giving window operator chance to get rows preloaded into frame. + * * @return data row */ ExprValue current(); - } diff --git a/core/src/main/java/org/opensearch/sql/expression/window/ranking/DenseRankFunction.java b/core/src/main/java/org/opensearch/sql/expression/window/ranking/DenseRankFunction.java index ba6e88d98d..87506ef63e 100644 --- a/core/src/main/java/org/opensearch/sql/expression/window/ranking/DenseRankFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/window/ranking/DenseRankFunction.java @@ -3,15 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.window.ranking; import org.opensearch.sql.expression.function.BuiltinFunctionName; import org.opensearch.sql.expression.window.frame.CurrentRowWindowFrame; /** - * Dense rank window function that assigns a rank number to each row similarly as - * rank function. The difference is there is no gap between rank number assigned. + * Dense rank window function that assigns a rank number to each row similarly as rank function. The + * difference is there is no gap between rank number assigned. */ public class DenseRankFunction extends RankingWindowFunction { @@ -30,5 +29,4 @@ protected int rank(CurrentRowWindowFrame frame) { } return rank; } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankFunction.java b/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankFunction.java index c1f33e6137..f72a28cd9a 100644 --- a/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankFunction.java @@ -3,22 +3,18 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.window.ranking; import org.opensearch.sql.expression.function.BuiltinFunctionName; import org.opensearch.sql.expression.window.frame.CurrentRowWindowFrame; /** - * Rank window function that assigns a rank number to each row based on sort items - * defined in window definition. Use same rank number if sort item values same on - * previous and current row. + * Rank window function that assigns a rank number to each row based on sort items defined in window + * definition. Use same rank number if sort item values same on previous and current row. */ public class RankFunction extends RankingWindowFunction { - /** - * Total number of rows have seen in current partition. - */ + /** Total number of rows have seen in current partition. */ private int total; public RankFunction() { @@ -38,5 +34,4 @@ protected int rank(CurrentRowWindowFrame frame) { } return rank; } - } diff --git a/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunction.java b/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunction.java index 07a4b42dbd..c119629cda 100644 --- a/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunction.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.window.ranking; import static java.util.Collections.emptyList; @@ -30,11 +29,9 @@ * such as same return type (integer), same argument list (no arg). */ public abstract class RankingWindowFunction extends FunctionExpression - implements WindowFunctionExpression { + implements WindowFunctionExpression { - /** - * Current rank number assigned. - */ + /** Current rank number assigned. */ protected int rank; public RankingWindowFunction(FunctionName functionName) { @@ -58,26 +55,27 @@ public ExprValue valueOf(Environment valueEnv) { /** * Rank logic that sub-class needs to implement. - * @param frame window frame - * @return rank number + * + * @param frame window frame + * @return rank number */ protected abstract int rank(CurrentRowWindowFrame frame); /** * Check sort field to see if current value is different from previous. - * @param frame window frame - * @return true if different, false if same or no sort list defined + * + * @param frame window frame + * @return true if different, false if same or no sort list defined */ protected boolean isSortFieldValueDifferent(CurrentRowWindowFrame frame) { if (isSortItemsNotDefined(frame)) { return false; } - List sortItems = frame.getWindowDefinition() - .getSortList() - .stream() - .map(Pair::getRight) - .collect(Collectors.toList()); + List sortItems = + frame.getWindowDefinition().getSortList().stream() + .map(Pair::getRight) + .collect(Collectors.toList()); List previous = resolve(frame, sortItems, frame.previous()); List current = resolve(frame, sortItems, frame.current()); @@ -90,9 +88,7 @@ private boolean isSortItemsNotDefined(CurrentRowWindowFrame frame) { private List resolve(WindowFrame frame, List expressions, ExprValue row) { BindingTuple valueEnv = row.bindingTuples(); - return expressions.stream() - .map(expr -> expr.valueOf(valueEnv)) - .collect(Collectors.toList()); + return expressions.stream().map(expr -> expr.valueOf(valueEnv)).collect(Collectors.toList()); } @Override diff --git a/core/src/main/java/org/opensearch/sql/expression/window/ranking/RowNumberFunction.java b/core/src/main/java/org/opensearch/sql/expression/window/ranking/RowNumberFunction.java index 067dfa569d..90bb2ed8ff 100644 --- a/core/src/main/java/org/opensearch/sql/expression/window/ranking/RowNumberFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/window/ranking/RowNumberFunction.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.expression.window.ranking; import org.opensearch.sql.expression.function.BuiltinFunctionName; @@ -25,5 +24,4 @@ protected int rank(CurrentRowWindowFrame frame) { } return rank++; } - } diff --git a/core/src/main/java/org/opensearch/sql/monitor/AlwaysHealthyMonitor.java b/core/src/main/java/org/opensearch/sql/monitor/AlwaysHealthyMonitor.java index 94bb8d6936..84cec4c9c7 100644 --- a/core/src/main/java/org/opensearch/sql/monitor/AlwaysHealthyMonitor.java +++ b/core/src/main/java/org/opensearch/sql/monitor/AlwaysHealthyMonitor.java @@ -3,19 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.monitor; -/** - * Always healthy resource monitor. - */ +/** Always healthy resource monitor. */ public class AlwaysHealthyMonitor extends ResourceMonitor { - public static final ResourceMonitor ALWAYS_HEALTHY_MONITOR = - new AlwaysHealthyMonitor(); + public static final ResourceMonitor ALWAYS_HEALTHY_MONITOR = new AlwaysHealthyMonitor(); - /** - * always healthy. - */ + /** always healthy. */ @Override public boolean isHealthy() { return true; diff --git a/core/src/main/java/org/opensearch/sql/monitor/ResourceMonitor.java b/core/src/main/java/org/opensearch/sql/monitor/ResourceMonitor.java index ce76a3f982..bbd1c67a62 100644 --- a/core/src/main/java/org/opensearch/sql/monitor/ResourceMonitor.java +++ b/core/src/main/java/org/opensearch/sql/monitor/ResourceMonitor.java @@ -3,12 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.monitor; /** - * The abstract interface of ResourceMonitor. - * When an fault is detected, the circuit breaker is open. + * The abstract interface of ResourceMonitor. When an fault is detected, the circuit breaker is + * open. */ public abstract class ResourceMonitor { /** 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/integ-test/build.gradle b/integ-test/build.gradle index 4a5f2015e0..b52cfd5f22 100644 --- a/integ-test/build.gradle +++ b/integ-test/build.gradle @@ -100,7 +100,7 @@ dependencies { testImplementation('org.junit.jupiter:junit-jupiter-api:5.6.2') testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.6.2') - testImplementation group: 'com.h2database', name: 'h2', version: '2.1.214' + testImplementation group: 'com.h2database', name: 'h2', version: '2.2.220' testImplementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.41.2.2' testImplementation group: 'com.google.code.gson', name: 'gson', version: '2.8.9' diff --git a/integ-test/src/test/java/org/opensearch/sql/bwc/SQLBackwardsCompatibilityIT.java b/integ-test/src/test/java/org/opensearch/sql/bwc/SQLBackwardsCompatibilityIT.java index c32a3336c0..799dadcd2d 100644 --- a/integ-test/src/test/java/org/opensearch/sql/bwc/SQLBackwardsCompatibilityIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/bwc/SQLBackwardsCompatibilityIT.java @@ -7,23 +7,6 @@ package org.opensearch.sql.bwc; -import org.json.JSONObject; -import org.junit.Assert; -import org.opensearch.client.Request; -import org.opensearch.client.RequestOptions; -import org.opensearch.client.Response; -import org.opensearch.common.settings.Settings; -import org.opensearch.sql.legacy.SQLIntegTestCase; -import org.opensearch.sql.legacy.TestsConstants; -import org.opensearch.test.rest.OpenSearchRestTestCase; - -import java.io.IOException; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - import static org.opensearch.sql.legacy.TestUtils.createIndexByRestClient; import static org.opensearch.sql.legacy.TestUtils.isIndexExist; import static org.opensearch.sql.legacy.TestUtils.loadDataByRestClient; @@ -36,6 +19,22 @@ import static org.opensearch.sql.util.MatcherUtils.verifySchema; import static org.opensearch.sql.util.TestUtils.getResponseBody; +import java.io.IOException; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import org.json.JSONObject; +import org.junit.Assert; +import org.opensearch.client.Request; +import org.opensearch.client.RequestOptions; +import org.opensearch.client.Response; +import org.opensearch.common.settings.Settings; +import org.opensearch.sql.legacy.SQLIntegTestCase; +import org.opensearch.sql.legacy.TestsConstants; +import org.opensearch.test.rest.OpenSearchRestTestCase; + public class SQLBackwardsCompatibilityIT extends SQLIntegTestCase { private static final ClusterType CLUSTER_TYPE = ClusterType.parse(System.getProperty("tests.rest.bwcsuite")); diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/CorrectnessIT.java b/integ-test/src/test/java/org/opensearch/sql/correctness/CorrectnessIT.java index 889f60f4ad..9ec80c55a7 100644 --- a/integ-test/src/test/java/org/opensearch/sql/correctness/CorrectnessIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/correctness/CorrectnessIT.java @@ -10,7 +10,6 @@ import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; import com.google.common.collect.Maps; - import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestConfigTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestConfigTest.java index c75bca15b1..1abe6ea109 100644 --- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestConfigTest.java +++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestConfigTest.java @@ -7,11 +7,11 @@ package org.opensearch.sql.correctness.tests; import static java.util.Collections.emptyMap; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.emptyString; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.is; -import static org.hamcrest.MatcherAssert.assertThat; import com.google.common.collect.ImmutableMap; import java.util.Map; diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestDataSetTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestDataSetTest.java index 284e167d6b..3967d96658 100644 --- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestDataSetTest.java +++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestDataSetTest.java @@ -6,9 +6,9 @@ package org.opensearch.sql.correctness.tests; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.junit.Assert.assertEquals; -import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test; import org.opensearch.sql.correctness.testset.TestDataSet; diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestQuerySetTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestQuerySetTest.java index 8ad9e6b921..1c97f743f4 100644 --- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestQuerySetTest.java +++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestQuerySetTest.java @@ -6,8 +6,8 @@ package org.opensearch.sql.correctness.tests; -import static org.hamcrest.Matchers.contains; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; import org.junit.Test; import org.opensearch.sql.correctness.testset.TestQuerySet; diff --git a/integ-test/src/test/java/org/opensearch/sql/jdbc/CursorIT.java b/integ-test/src/test/java/org/opensearch/sql/jdbc/CursorIT.java index 7691c00ea5..959621dbad 100644 --- a/integ-test/src/test/java/org/opensearch/sql/jdbc/CursorIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/jdbc/CursorIT.java @@ -28,12 +28,12 @@ import org.junit.AfterClass; import org.junit.Assume; import org.junit.BeforeClass; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; import org.opensearch.client.Request; import org.opensearch.client.RequestOptions; import org.opensearch.client.Response; diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/NestedFieldQueryIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/NestedFieldQueryIT.java index e568be0ae6..378fbda937 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/NestedFieldQueryIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/NestedFieldQueryIT.java @@ -34,9 +34,9 @@ import org.opensearch.client.ResponseException; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.json.JsonXContentParser; +import org.opensearch.core.rest.RestStatus; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; -import org.opensearch.core.rest.RestStatus; import org.opensearch.search.SearchHit; /** diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java b/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java index e057c58969..7b5961de35 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java @@ -6,6 +6,8 @@ package org.opensearch.sql.legacy; +import static java.util.Collections.unmodifiableList; + import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -40,8 +42,6 @@ import org.opensearch.common.util.io.IOUtils; import org.opensearch.test.rest.OpenSearchRestTestCase; -import static java.util.Collections.unmodifiableList; - /** * OpenSearch SQL integration test base class to support both security disabled and enabled OpenSearch cluster. * Allows interaction with multiple external test clusters using OpenSearch's {@link RestClient}. diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/RestIntegTestCase.java b/integ-test/src/test/java/org/opensearch/sql/legacy/RestIntegTestCase.java index e6f567e2db..dd48d82114 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/RestIntegTestCase.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/RestIntegTestCase.java @@ -44,10 +44,9 @@ import org.junit.Before; import org.opensearch.client.Request; import org.opensearch.client.Response; -import org.opensearch.common.Strings; -import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.rest.RestStatus; +import org.opensearch.core.xcontent.XContentBuilder; /** * SQL plugin integration test base class (migrated from SQLIntegTestCase) @@ -164,7 +163,7 @@ protected static void updateClusterSetting(String settingKey, Object value, bool .endObject() .endObject(); Request request = new Request("PUT", "_cluster/settings"); - request.setJsonEntity(Strings.toString(builder)); + request.setJsonEntity(builder.toString()); Response response = client().performRequest(request); Assert .assertEquals(RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode())); diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java b/integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java index 7216c03d08..58e55c4101 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java @@ -6,35 +6,6 @@ package org.opensearch.sql.legacy; -import com.google.common.base.Strings; -import com.google.gson.Gson; -import org.apache.commons.lang3.StringUtils; -import org.json.JSONArray; -import org.json.JSONObject; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.opensearch.client.Request; -import org.opensearch.client.RequestOptions; -import org.opensearch.client.Response; -import org.opensearch.client.RestClient; -import org.opensearch.sql.common.setting.Settings; - -import javax.management.MBeanServerInvocationHandler; -import javax.management.ObjectName; -import javax.management.remote.JMXConnector; -import javax.management.remote.JMXConnectorFactory; -import javax.management.remote.JMXServiceURL; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Locale; -import org.opensearch.sql.datasource.model.DataSourceMetadata; - import static com.google.common.base.Strings.isNullOrEmpty; import static org.opensearch.sql.legacy.TestUtils.createIndexByRestClient; import static org.opensearch.sql.legacy.TestUtils.getAccountIndexMapping; @@ -69,6 +40,34 @@ import static org.opensearch.sql.legacy.plugin.RestSqlAction.EXPLAIN_API_ENDPOINT; import static org.opensearch.sql.legacy.plugin.RestSqlAction.QUERY_API_ENDPOINT; +import com.google.common.base.Strings; +import com.google.gson.Gson; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Locale; +import javax.management.MBeanServerInvocationHandler; +import javax.management.ObjectName; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; +import org.apache.commons.lang3.StringUtils; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.opensearch.client.Request; +import org.opensearch.client.RequestOptions; +import org.opensearch.client.Response; +import org.opensearch.client.RestClient; +import org.opensearch.sql.common.setting.Settings; +import org.opensearch.sql.datasource.model.DataSourceMetadata; + /** * OpenSearch Rest integration test base for SQL testing */ diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/TypeInformationIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/TypeInformationIT.java index e827059f1b..646a38b011 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/TypeInformationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/TypeInformationIT.java @@ -10,7 +10,6 @@ import static org.opensearch.sql.util.MatcherUtils.verifySchema; import org.json.JSONObject; - import org.junit.Test; public class TypeInformationIT extends SQLIntegTestCase { diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java index 272e0a34d3..4fb61ae2e9 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java @@ -13,13 +13,12 @@ import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import static org.opensearch.sql.util.MatcherUtils.verifySchema; +import com.carrotsearch.randomizedtesting.annotations.Name; +import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import java.io.IOException; import java.time.LocalDate; import java.util.Arrays; import java.util.TimeZone; - -import com.carrotsearch.randomizedtesting.annotations.Name; -import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import org.junit.After; import org.junit.Before; import org.junit.jupiter.api.Test; diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java index 5e51a60856..3f24b619f5 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java @@ -5,17 +5,16 @@ package org.opensearch.sql.ppl; -import org.json.JSONObject; -import org.junit.Test; - -import java.io.IOException; - import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATE; import static org.opensearch.sql.util.MatcherUtils.rows; import static org.opensearch.sql.util.MatcherUtils.schema; import static org.opensearch.sql.util.MatcherUtils.verifySchema; import static org.opensearch.sql.util.MatcherUtils.verifySome; +import java.io.IOException; +import org.json.JSONObject; +import org.junit.Test; + public class DateTimeImplementationIT extends PPLIntegTestCase { diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/MultiMatchIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/MultiMatchIT.java index 0113d77cf2..6562c551da 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/MultiMatchIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/MultiMatchIT.java @@ -9,7 +9,6 @@ import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BEER; import java.io.IOException; - import org.json.JSONObject; import org.junit.Test; diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/PositionFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/PositionFunctionIT.java index 24319a0cb8..59aade8bbd 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/PositionFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/PositionFunctionIT.java @@ -5,14 +5,13 @@ package org.opensearch.sql.ppl; -import org.junit.Test; - -import java.io.IOException; - import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_CALCS; import static org.opensearch.sql.util.MatcherUtils.rows; import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; +import java.io.IOException; +import org.junit.Test; + public class PositionFunctionIT extends PPLIntegTestCase { @Override public void init() throws IOException { diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/RelevanceFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/RelevanceFunctionIT.java index 9e05a2a919..7c57bd5481 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/RelevanceFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/RelevanceFunctionIT.java @@ -8,7 +8,6 @@ import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BEER; import java.io.IOException; - import org.junit.Test; public class RelevanceFunctionIT extends PPLIntegTestCase { diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/SimpleQueryStringIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/SimpleQueryStringIT.java index abc0ad6f59..46111b902e 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/SimpleQueryStringIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/SimpleQueryStringIT.java @@ -8,7 +8,6 @@ import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BEER; import java.io.IOException; - import org.json.JSONObject; import org.junit.Test; diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java index b1fcbf7d1b..8ef8787597 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java @@ -31,11 +31,11 @@ import org.opensearch.sql.analysis.ExpressionAnalyzer; import org.opensearch.sql.common.response.ResponseListener; import org.opensearch.sql.common.setting.Settings; -import org.opensearch.sql.datasources.service.DataSourceMetadataStorage; import org.opensearch.sql.datasource.DataSourceService; -import org.opensearch.sql.datasources.service.DataSourceServiceImpl; -import org.opensearch.sql.datasources.auth.DataSourceUserAuthorizationHelper; import org.opensearch.sql.datasource.model.DataSourceMetadata; +import org.opensearch.sql.datasources.auth.DataSourceUserAuthorizationHelper; +import org.opensearch.sql.datasources.service.DataSourceMetadataStorage; +import org.opensearch.sql.datasources.service.DataSourceServiceImpl; import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.executor.ExecutionEngine.QueryResponse; import org.opensearch.sql.executor.QueryManager; @@ -45,25 +45,25 @@ import org.opensearch.sql.expression.function.BuiltinFunctionRepository; import org.opensearch.sql.monitor.AlwaysHealthyMonitor; import org.opensearch.sql.monitor.ResourceMonitor; +import org.opensearch.sql.opensearch.client.OpenSearchClient; +import org.opensearch.sql.opensearch.client.OpenSearchRestClient; import org.opensearch.sql.opensearch.executor.OpenSearchExecutionEngine; import org.opensearch.sql.opensearch.executor.protector.ExecutionProtector; import org.opensearch.sql.opensearch.executor.protector.OpenSearchExecutionProtector; +import org.opensearch.sql.opensearch.security.SecurityAccess; +import org.opensearch.sql.opensearch.storage.OpenSearchDataSourceFactory; import org.opensearch.sql.opensearch.storage.OpenSearchStorageEngine; import org.opensearch.sql.planner.Planner; import org.opensearch.sql.planner.optimizer.LogicalPlanOptimizer; import org.opensearch.sql.ppl.antlr.PPLSyntaxParser; -import org.opensearch.sql.sql.SQLService; -import org.opensearch.sql.sql.antlr.SQLSyntaxParser; -import org.opensearch.sql.storage.StorageEngine; -import org.opensearch.sql.util.ExecuteOnCallerThreadQueryManager; -import org.opensearch.sql.opensearch.client.OpenSearchClient; -import org.opensearch.sql.opensearch.client.OpenSearchRestClient; -import org.opensearch.sql.opensearch.security.SecurityAccess; -import org.opensearch.sql.opensearch.storage.OpenSearchDataSourceFactory; import org.opensearch.sql.ppl.domain.PPLQueryRequest; import org.opensearch.sql.protocol.response.QueryResult; import org.opensearch.sql.protocol.response.format.SimpleJsonResponseFormatter; +import org.opensearch.sql.sql.SQLService; +import org.opensearch.sql.sql.antlr.SQLSyntaxParser; import org.opensearch.sql.storage.DataSourceFactory; +import org.opensearch.sql.storage.StorageEngine; +import org.opensearch.sql.util.ExecuteOnCallerThreadQueryManager; /** * Run PPL with query engine outside OpenSearch cluster. This IT doesn't require our plugin diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/AdminIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/AdminIT.java index 8429ab3897..1ca21041a3 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/AdminIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/AdminIT.java @@ -16,7 +16,6 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.Locale; - import org.json.JSONArray; import org.json.JSONObject; import org.junit.Test; diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/ArithmeticFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/ArithmeticFunctionIT.java index 5b6c742e28..dd99cf2e75 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/ArithmeticFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/ArithmeticFunctionIT.java @@ -15,7 +15,6 @@ import java.io.IOException; import java.util.Locale; - import org.json.JSONObject; import org.junit.jupiter.api.Test; import org.opensearch.client.Request; diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/ConvertTZFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/ConvertTZFunctionIT.java index 308fe7cdcd..b719edd5b0 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/ConvertTZFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/ConvertTZFunctionIT.java @@ -5,14 +5,15 @@ package org.opensearch.sql.sql; -import org.junit.Test; -import org.opensearch.sql.legacy.SQLIntegTestCase; -import java.io.IOException; import static org.opensearch.sql.util.MatcherUtils.rows; import static org.opensearch.sql.util.MatcherUtils.schema; import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import static org.opensearch.sql.util.MatcherUtils.verifySchema; +import java.io.IOException; +import org.junit.Test; +import org.opensearch.sql.legacy.SQLIntegTestCase; + public class ConvertTZFunctionIT extends SQLIntegTestCase { diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/CsvFormatIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/CsvFormatIT.java index aa2737cbac..3af4db89de 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/CsvFormatIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/CsvFormatIT.java @@ -11,7 +11,6 @@ import java.io.IOException; import java.util.Locale; - import org.junit.Test; import org.opensearch.client.Request; import org.opensearch.client.Response; diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeComparisonIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeComparisonIT.java index 108687da27..e935b269f1 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeComparisonIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeComparisonIT.java @@ -14,14 +14,13 @@ import static org.opensearch.sql.util.MatcherUtils.verifySchema; import static org.opensearch.sql.util.TestUtils.getResponseBody; +import com.carrotsearch.randomizedtesting.annotations.Name; +import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import java.io.IOException; import java.time.LocalDate; import java.util.Arrays; import java.util.Locale; import java.util.TimeZone; - -import com.carrotsearch.randomizedtesting.annotations.Name; -import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import org.json.JSONObject; import org.junit.After; import org.junit.Before; diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeImplementationIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeImplementationIT.java index ff2c4c07a6..94a5b4fb16 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeImplementationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeImplementationIT.java @@ -5,16 +5,15 @@ package org.opensearch.sql.sql; -import org.junit.Test; -import org.opensearch.sql.legacy.SQLIntegTestCase; - -import java.io.IOException; - import static org.opensearch.sql.util.MatcherUtils.rows; import static org.opensearch.sql.util.MatcherUtils.schema; import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import static org.opensearch.sql.util.MatcherUtils.verifySchema; +import java.io.IOException; +import org.junit.Test; +import org.opensearch.sql.legacy.SQLIntegTestCase; + public class DateTimeImplementationIT extends SQLIntegTestCase { diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/HighlightFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/HighlightFunctionIT.java index 0ab6d5c70f..d55972691c 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/HighlightFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/HighlightFunctionIT.java @@ -11,12 +11,12 @@ import static org.opensearch.sql.util.MatcherUtils.verifySchema; import com.google.common.collect.ImmutableMap; +import java.util.List; import org.json.JSONArray; import org.json.JSONObject; import org.junit.Test; import org.opensearch.sql.legacy.SQLIntegTestCase; import org.opensearch.sql.legacy.TestsConstants; -import java.util.List; public class HighlightFunctionIT extends SQLIntegTestCase { diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/LikeQueryIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/LikeQueryIT.java index f0e82adb6f..0dbb0404f9 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/LikeQueryIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/LikeQueryIT.java @@ -6,16 +6,15 @@ package org.opensearch.sql.sql; -import org.json.JSONObject; -import org.junit.Test; -import org.opensearch.sql.legacy.SQLIntegTestCase; - -import java.io.IOException; - import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_WILDCARD; import static org.opensearch.sql.util.MatcherUtils.rows; import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; +import java.io.IOException; +import org.json.JSONObject; +import org.junit.Test; +import org.opensearch.sql.legacy.SQLIntegTestCase; + public class LikeQueryIT extends SQLIntegTestCase { @Override protected void init() throws Exception { diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/PaginationBlackboxIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/PaginationBlackboxIT.java index 2a34dabd79..e6f4e18468 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/PaginationBlackboxIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/PaginationBlackboxIT.java @@ -6,12 +6,11 @@ package org.opensearch.sql.sql; +import com.carrotsearch.randomizedtesting.annotations.Name; +import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import java.io.IOException; import java.util.ArrayList; import java.util.List; - -import com.carrotsearch.randomizedtesting.annotations.Name; -import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import lombok.SneakyThrows; import org.json.JSONArray; import org.json.JSONObject; diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/PaginationIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/PaginationIT.java index bd8949203c..224a1e95e4 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/PaginationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/PaginationIT.java @@ -11,7 +11,6 @@ import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ONLINE; import java.io.IOException; - import lombok.SneakyThrows; import org.json.JSONArray; import org.json.JSONObject; diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/PositionFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/PositionFunctionIT.java index f51a3a0977..d0587eab7f 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/PositionFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/PositionFunctionIT.java @@ -5,16 +5,16 @@ package org.opensearch.sql.sql; -import org.json.JSONObject; -import org.junit.Test; -import org.opensearch.sql.legacy.SQLIntegTestCase; -import org.opensearch.sql.legacy.TestsConstants; - import static org.opensearch.sql.util.MatcherUtils.rows; import static org.opensearch.sql.util.MatcherUtils.schema; import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import static org.opensearch.sql.util.MatcherUtils.verifySchema; +import org.json.JSONObject; +import org.junit.Test; +import org.opensearch.sql.legacy.SQLIntegTestCase; +import org.opensearch.sql.legacy.TestsConstants; + public class PositionFunctionIT extends SQLIntegTestCase { @Override diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/ScoreQueryIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/ScoreQueryIT.java index 03df7d0e29..e824b1ab2b 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/ScoreQueryIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/ScoreQueryIT.java @@ -5,21 +5,20 @@ package org.opensearch.sql.sql; -import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Test; -import org.opensearch.sql.legacy.SQLIntegTestCase; -import org.opensearch.sql.legacy.TestsConstants; - -import java.io.IOException; -import java.util.Locale; - import static org.hamcrest.Matchers.containsString; import static org.opensearch.sql.util.MatcherUtils.rows; import static org.opensearch.sql.util.MatcherUtils.schema; import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import static org.opensearch.sql.util.MatcherUtils.verifySchema; +import java.io.IOException; +import java.util.Locale; +import org.json.JSONObject; +import org.junit.Assert; +import org.junit.Test; +import org.opensearch.sql.legacy.SQLIntegTestCase; +import org.opensearch.sql.legacy.TestsConstants; + public class ScoreQueryIT extends SQLIntegTestCase { @Override protected void init() throws Exception { diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/SimpleQueryStringIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/SimpleQueryStringIT.java index afacc5fefd..44f4e5ca9c 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/SimpleQueryStringIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/SimpleQueryStringIT.java @@ -9,7 +9,6 @@ import static org.opensearch.sql.protocol.response.format.JsonResponseFormatter.CONTENT_TYPE; import java.io.IOException; - import org.json.JSONObject; import org.junit.Test; import org.opensearch.client.Request; diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/StandalonePaginationIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/StandalonePaginationIT.java index aad39c4074..4738d233bf 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/StandalonePaginationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/StandalonePaginationIT.java @@ -33,13 +33,13 @@ import org.opensearch.sql.datasource.DataSourceService; import org.opensearch.sql.datasources.service.DataSourceServiceImpl; import org.opensearch.sql.executor.ExecutionEngine; -import org.opensearch.sql.executor.pagination.PlanSerializer; import org.opensearch.sql.executor.QueryService; +import org.opensearch.sql.executor.pagination.Cursor; +import org.opensearch.sql.executor.pagination.PlanSerializer; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.legacy.SQLIntegTestCase; import org.opensearch.sql.opensearch.client.OpenSearchClient; import org.opensearch.sql.opensearch.client.OpenSearchRestClient; -import org.opensearch.sql.executor.pagination.Cursor; import org.opensearch.sql.opensearch.storage.OpenSearchDataSourceFactory; import org.opensearch.sql.opensearch.storage.OpenSearchIndex; import org.opensearch.sql.planner.PlanContext; diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/StringLiteralIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/StringLiteralIT.java index ba77ea1c2f..e54000f80d 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/StringLiteralIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/StringLiteralIT.java @@ -6,17 +6,16 @@ package org.opensearch.sql.sql; -import org.json.JSONObject; -import org.junit.Test; -import org.opensearch.sql.legacy.SQLIntegTestCase; - -import java.io.IOException; - import static org.opensearch.sql.util.MatcherUtils.rows; import static org.opensearch.sql.util.MatcherUtils.schema; import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import static org.opensearch.sql.util.MatcherUtils.verifySchema; +import java.io.IOException; +import org.json.JSONObject; +import org.junit.Test; +import org.opensearch.sql.legacy.SQLIntegTestCase; + public class StringLiteralIT extends SQLIntegTestCase { diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/WildcardQueryIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/WildcardQueryIT.java index 3f6a3afb72..030c07c5fa 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/WildcardQueryIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/WildcardQueryIT.java @@ -7,15 +7,14 @@ package org.opensearch.sql.sql; import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_WILDCARD; +import static org.opensearch.sql.util.MatcherUtils.rows; +import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import java.io.IOException; import org.json.JSONObject; import org.junit.Test; import org.opensearch.sql.legacy.SQLIntegTestCase; -import static org.opensearch.sql.util.MatcherUtils.rows; -import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; - public class WildcardQueryIT extends SQLIntegTestCase { @Override protected void init() throws Exception { diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/WindowFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/WindowFunctionIT.java index ac042b4a47..b586125af3 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/WindowFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/WindowFunctionIT.java @@ -10,7 +10,6 @@ import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import static org.opensearch.sql.util.MatcherUtils.verifyDataRowsInOrder; - import org.json.JSONObject; import org.junit.Test; import org.opensearch.sql.legacy.SQLIntegTestCase; diff --git a/integ-test/src/test/java/org/opensearch/sql/util/MatcherUtils.java b/integ-test/src/test/java/org/opensearch/sql/util/MatcherUtils.java index f5fbcf9666..4cb2aa299d 100644 --- a/integ-test/src/test/java/org/opensearch/sql/util/MatcherUtils.java +++ b/integ-test/src/test/java/org/opensearch/sql/util/MatcherUtils.java @@ -6,6 +6,7 @@ package org.opensearch.sql.util; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.arrayContaining; import static org.hamcrest.Matchers.arrayContainingInAnyOrder; @@ -17,7 +18,6 @@ import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.hasItems; import static org.junit.Assert.assertEquals; -import static org.hamcrest.MatcherAssert.assertThat; import com.google.common.base.Strings; import com.google.gson.JsonParser; diff --git a/integ-test/src/test/java/org/opensearch/sql/util/StandaloneModule.java b/integ-test/src/test/java/org/opensearch/sql/util/StandaloneModule.java index c347ea5244..ad8afc47ca 100644 --- a/integ-test/src/test/java/org/opensearch/sql/util/StandaloneModule.java +++ b/integ-test/src/test/java/org/opensearch/sql/util/StandaloneModule.java @@ -15,10 +15,10 @@ import org.opensearch.sql.common.setting.Settings; import org.opensearch.sql.datasource.DataSourceService; import org.opensearch.sql.executor.ExecutionEngine; -import org.opensearch.sql.executor.pagination.PlanSerializer; import org.opensearch.sql.executor.QueryManager; import org.opensearch.sql.executor.QueryService; import org.opensearch.sql.executor.execution.QueryPlanFactory; +import org.opensearch.sql.executor.pagination.PlanSerializer; import org.opensearch.sql.expression.function.BuiltinFunctionRepository; import org.opensearch.sql.monitor.AlwaysHealthyMonitor; import org.opensearch.sql.monitor.ResourceMonitor; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/AsyncRestExecutor.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/AsyncRestExecutor.java index 1df0036bab..d251585f89 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/AsyncRestExecutor.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/AsyncRestExecutor.java @@ -15,9 +15,9 @@ import org.opensearch.OpenSearchException; import org.opensearch.client.Client; import org.opensearch.common.unit.TimeValue; +import org.opensearch.core.rest.RestStatus; import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.RestChannel; -import org.opensearch.core.rest.RestStatus; import org.opensearch.sql.common.setting.Settings; import org.opensearch.sql.common.utils.QueryContext; import org.opensearch.sql.legacy.esdomain.LocalClusterState; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/ElasticDefaultRestExecutor.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/ElasticDefaultRestExecutor.java index 35ab9facb3..220903d49d 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/ElasticDefaultRestExecutor.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/ElasticDefaultRestExecutor.java @@ -18,11 +18,11 @@ import org.opensearch.action.search.SearchResponse; import org.opensearch.action.search.SearchScrollRequest; import org.opensearch.client.Client; +import org.opensearch.core.rest.RestStatus; import org.opensearch.index.reindex.BulkIndexByScrollResponseContentListener; import org.opensearch.index.reindex.DeleteByQueryRequest; import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.RestChannel; -import org.opensearch.core.rest.RestStatus; import org.opensearch.rest.action.RestStatusToXContentListener; import org.opensearch.search.SearchHits; import org.opensearch.sql.legacy.exception.SqlParseException; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/GetIndexRequestRestListener.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/GetIndexRequestRestListener.java index 591319c74c..be6677a405 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/GetIndexRequestRestListener.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/GetIndexRequestRestListener.java @@ -8,18 +8,17 @@ import java.io.IOException; import java.util.List; - import org.opensearch.action.admin.indices.get.GetIndexRequest; import org.opensearch.action.admin.indices.get.GetIndexResponse; import org.opensearch.cluster.metadata.AliasMetadata; import org.opensearch.cluster.metadata.MappingMetadata; import org.opensearch.common.settings.Settings; +import org.opensearch.core.rest.RestStatus; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.RestChannel; import org.opensearch.rest.RestResponse; -import org.opensearch.core.rest.RestStatus; import org.opensearch.rest.action.RestBuilderListener; import org.opensearch.sql.legacy.antlr.semantic.SemanticAnalysisException; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/csv/CSVResultRestExecutor.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/csv/CSVResultRestExecutor.java index ae7623e3a2..da99652e13 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/csv/CSVResultRestExecutor.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/csv/CSVResultRestExecutor.java @@ -10,9 +10,9 @@ import java.util.List; import java.util.Map; import org.opensearch.client.Client; +import org.opensearch.core.rest.RestStatus; import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.RestChannel; -import org.opensearch.core.rest.RestStatus; import org.opensearch.sql.legacy.executor.QueryActionElasticExecutor; import org.opensearch.sql.legacy.executor.RestExecutor; import org.opensearch.sql.legacy.query.QueryAction; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/csv/CSVResultsExtractor.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/csv/CSVResultsExtractor.java index 70cdd91452..a22d96c133 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/csv/CSVResultsExtractor.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/csv/CSVResultsExtractor.java @@ -14,6 +14,7 @@ import java.util.Set; import java.util.stream.Collectors; import org.opensearch.common.document.DocumentField; +import org.opensearch.geo.search.aggregations.metrics.GeoBounds; import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; import org.opensearch.search.aggregations.Aggregation; @@ -21,7 +22,6 @@ import org.opensearch.search.aggregations.bucket.MultiBucketsAggregation; import org.opensearch.search.aggregations.bucket.SingleBucketAggregation; import org.opensearch.search.aggregations.metrics.ExtendedStats; -import org.opensearch.geo.search.aggregations.metrics.GeoBounds; import org.opensearch.search.aggregations.metrics.NumericMetricsAggregation; import org.opensearch.search.aggregations.metrics.Percentile; import org.opensearch.search.aggregations.metrics.Percentiles; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/cursor/CursorAsyncRestExecutor.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/cursor/CursorAsyncRestExecutor.java index 92703dde2a..9b8e70c168 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/cursor/CursorAsyncRestExecutor.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/cursor/CursorAsyncRestExecutor.java @@ -13,9 +13,9 @@ import org.apache.logging.log4j.Logger; import org.opensearch.client.Client; import org.opensearch.common.unit.TimeValue; +import org.opensearch.core.rest.RestStatus; import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.RestChannel; -import org.opensearch.core.rest.RestStatus; import org.opensearch.sql.common.setting.Settings; import org.opensearch.sql.common.utils.QueryContext; import org.opensearch.sql.legacy.esdomain.LocalClusterState; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/format/PrettyFormatRestExecutor.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/format/PrettyFormatRestExecutor.java index 65fd6b7022..411fb90a24 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/format/PrettyFormatRestExecutor.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/format/PrettyFormatRestExecutor.java @@ -13,9 +13,9 @@ import org.opensearch.action.search.SearchResponse; import org.opensearch.client.Client; import org.opensearch.core.common.Strings; +import org.opensearch.core.rest.RestStatus; import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.RestChannel; -import org.opensearch.core.rest.RestStatus; import org.opensearch.sql.legacy.cursor.Cursor; import org.opensearch.sql.legacy.cursor.DefaultCursor; import org.opensearch.sql.legacy.exception.SqlParseException; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/join/ElasticJoinExecutor.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/join/ElasticJoinExecutor.java index f7d1fbf641..e8536567dd 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/join/ElasticJoinExecutor.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/join/ElasticJoinExecutor.java @@ -22,11 +22,11 @@ import org.opensearch.client.Client; import org.opensearch.common.document.DocumentField; import org.opensearch.common.unit.TimeValue; +import org.opensearch.core.rest.RestStatus; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.index.mapper.MapperService; import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.RestChannel; -import org.opensearch.core.rest.RestStatus; import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; import org.opensearch.search.sort.FieldSortBuilder; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/join/ElasticUtils.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/join/ElasticUtils.java index aa6ea05389..7269e271f4 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/join/ElasticUtils.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/join/ElasticUtils.java @@ -17,10 +17,10 @@ import org.opensearch.action.search.SearchRequestBuilder; import org.opensearch.action.search.SearchResponse; import org.opensearch.client.Client; -import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.xcontent.XContentFactory; +import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.core.xcontent.ToXContent.Params; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.search.SearchHit; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSQLQueryAction.java b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSQLQueryAction.java index 9ee9a8a683..cd8056aed1 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSQLQueryAction.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSQLQueryAction.java @@ -16,11 +16,11 @@ import org.apache.logging.log4j.Logger; import org.opensearch.client.node.NodeClient; import org.opensearch.common.inject.Injector; +import org.opensearch.core.rest.RestStatus; import org.opensearch.rest.BaseRestHandler; import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.RestChannel; import org.opensearch.rest.RestRequest; -import org.opensearch.core.rest.RestStatus; import org.opensearch.sql.common.antlr.SyntaxCheckException; import org.opensearch.sql.common.response.ResponseListener; import org.opensearch.sql.common.utils.QueryContext; @@ -30,11 +30,11 @@ import org.opensearch.sql.legacy.metrics.Metrics; import org.opensearch.sql.opensearch.security.SecurityAccess; import org.opensearch.sql.protocol.response.QueryResult; +import org.opensearch.sql.protocol.response.format.CommandResponseFormatter; import org.opensearch.sql.protocol.response.format.CsvResponseFormatter; import org.opensearch.sql.protocol.response.format.Format; import org.opensearch.sql.protocol.response.format.JdbcResponseFormatter; import org.opensearch.sql.protocol.response.format.JsonResponseFormatter; -import org.opensearch.sql.protocol.response.format.CommandResponseFormatter; import org.opensearch.sql.protocol.response.format.RawResponseFormatter; import org.opensearch.sql.protocol.response.format.ResponseFormatter; import org.opensearch.sql.sql.SQLService; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java index 9a15cc9e21..69ed469fed 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java @@ -28,12 +28,12 @@ import org.opensearch.client.node.NodeClient; import org.opensearch.common.inject.Injector; import org.opensearch.common.settings.Settings; +import org.opensearch.core.rest.RestStatus; import org.opensearch.index.IndexNotFoundException; import org.opensearch.rest.BaseRestHandler; import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.RestChannel; import org.opensearch.rest.RestRequest; -import org.opensearch.core.rest.RestStatus; import org.opensearch.sql.common.antlr.SyntaxCheckException; import org.opensearch.sql.common.utils.QueryContext; import org.opensearch.sql.exception.ExpressionEvaluationException; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlStatsAction.java b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlStatsAction.java index d300ea7177..cf3a3e3f96 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlStatsAction.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlStatsAction.java @@ -17,11 +17,11 @@ import org.apache.logging.log4j.Logger; import org.opensearch.client.node.NodeClient; import org.opensearch.common.settings.Settings; +import org.opensearch.core.rest.RestStatus; import org.opensearch.rest.BaseRestHandler; import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.RestController; import org.opensearch.rest.RestRequest; -import org.opensearch.core.rest.RestStatus; import org.opensearch.sql.common.utils.QueryContext; import org.opensearch.sql.legacy.executor.format.ErrorMessageFactory; import org.opensearch.sql.legacy.metrics.Metrics; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/join/JoinRequestBuilder.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/join/JoinRequestBuilder.java index c7b28d8a0a..195abcadec 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/join/JoinRequestBuilder.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/join/JoinRequestBuilder.java @@ -12,8 +12,8 @@ import org.opensearch.action.ActionRequestBuilder; import org.opensearch.action.ActionResponse; import org.opensearch.action.search.MultiSearchRequest; -import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.xcontent.XContentFactory; +import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.sql.legacy.query.SqlElasticRequestBuilder; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/join/NestedLoopsElasticRequestBuilder.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/join/NestedLoopsElasticRequestBuilder.java index 899e0f5e1d..c14d8f3012 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/join/NestedLoopsElasticRequestBuilder.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/join/NestedLoopsElasticRequestBuilder.java @@ -10,8 +10,8 @@ import java.io.IOException; import org.json.JSONObject; import org.json.JSONStringer; -import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.xcontent.XContentFactory; +import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.sql.legacy.domain.Condition; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/maker/AggMaker.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/maker/AggMaker.java index 0c9caab03d..9c3f1104a7 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/maker/AggMaker.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/maker/AggMaker.java @@ -18,14 +18,16 @@ import java.util.Map; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; -import org.opensearch.core.common.ParsingException; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.common.xcontent.json.JsonXContentParser; +import org.opensearch.core.common.ParsingException; import org.opensearch.core.common.Strings; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; +import org.opensearch.geo.search.aggregations.bucket.geogrid.GeoGridAggregationBuilder; import org.opensearch.geo.search.aggregations.bucket.geogrid.GeoHashGridAggregationBuilder; +import org.opensearch.geo.search.aggregations.metrics.GeoBoundsAggregationBuilder; import org.opensearch.join.aggregations.JoinAggregationBuilders; import org.opensearch.script.Script; import org.opensearch.script.ScriptType; @@ -35,7 +37,6 @@ import org.opensearch.search.aggregations.BucketOrder; import org.opensearch.search.aggregations.InternalOrder; import org.opensearch.search.aggregations.bucket.filter.FilterAggregationBuilder; -import org.opensearch.geo.search.aggregations.bucket.geogrid.GeoGridAggregationBuilder; import org.opensearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; import org.opensearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.opensearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; @@ -45,7 +46,6 @@ import org.opensearch.search.aggregations.bucket.range.RangeAggregationBuilder; import org.opensearch.search.aggregations.bucket.terms.IncludeExclude; import org.opensearch.search.aggregations.bucket.terms.TermsAggregationBuilder; -import org.opensearch.geo.search.aggregations.metrics.GeoBoundsAggregationBuilder; import org.opensearch.search.aggregations.metrics.PercentilesAggregationBuilder; import org.opensearch.search.aggregations.metrics.ScriptedMetricAggregationBuilder; import org.opensearch.search.aggregations.metrics.TopHitsAggregationBuilder; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/multi/MultiQueryRequestBuilder.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/multi/MultiQueryRequestBuilder.java index af2a1e90cf..2a5e356073 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/multi/MultiQueryRequestBuilder.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/multi/MultiQueryRequestBuilder.java @@ -15,8 +15,8 @@ import org.opensearch.action.ActionRequestBuilder; import org.opensearch.action.ActionResponse; import org.opensearch.action.search.SearchRequestBuilder; -import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.xcontent.XContentFactory; +import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.sql.legacy.domain.Field; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/join/BlockHashJoin.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/join/BlockHashJoin.java index cfb6265e52..19c0ae41d2 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/join/BlockHashJoin.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/join/BlockHashJoin.java @@ -16,8 +16,8 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import org.opensearch.common.Strings; import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.common.Strings; import org.opensearch.index.query.BoolQueryBuilder; import org.opensearch.sql.legacy.query.planner.core.ExecuteParams; import org.opensearch.sql.legacy.query.planner.physical.PhysicalOperator; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/scroll/Scroll.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/scroll/Scroll.java index 6dd8ff6e89..2d781d7c3d 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/scroll/Scroll.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/scroll/Scroll.java @@ -9,13 +9,12 @@ import java.util.Arrays; import java.util.Collection; import java.util.Objects; - import org.opensearch.action.search.ClearScrollResponse; import org.opensearch.action.search.SearchResponse; import org.opensearch.client.Client; -import org.opensearch.common.Strings; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.common.Strings; import org.opensearch.index.query.BoolQueryBuilder; import org.opensearch.index.query.QueryBuilder; import org.opensearch.search.SearchHit; diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/utils/JsonPrettyFormatter.java b/legacy/src/main/java/org/opensearch/sql/legacy/utils/JsonPrettyFormatter.java index 827f968bde..ecc86877ee 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/utils/JsonPrettyFormatter.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/utils/JsonPrettyFormatter.java @@ -8,7 +8,6 @@ import com.fasterxml.jackson.core.JsonFactory; import java.io.IOException; -import org.opensearch.common.Strings; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.json.JsonXContentParser; @@ -37,7 +36,7 @@ public static String format(String jsonString) throws IOException { ){ contentBuilder.copyCurrentStructure(contentParser); } - return Strings.toString(contentBuilder); + return contentBuilder.toString(); } private JsonPrettyFormatter() { diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/SemanticAnalyzerBasicTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/SemanticAnalyzerBasicTest.java index 1d594db2bc..6f6b09b737 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/SemanticAnalyzerBasicTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/SemanticAnalyzerBasicTest.java @@ -6,10 +6,10 @@ package org.opensearch.sql.legacy.antlr.semantic; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.aMapWithSize; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.hasEntry; -import static org.hamcrest.MatcherAssert.assertThat; import static org.opensearch.sql.legacy.antlr.semantic.types.base.OpenSearchDataType.BOOLEAN; import static org.opensearch.sql.legacy.antlr.semantic.types.base.OpenSearchDataType.DATE; import static org.opensearch.sql.legacy.antlr.semantic.types.base.OpenSearchDataType.DOUBLE; diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/scope/EnvironmentTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/scope/EnvironmentTest.java index d9e9271728..05d8b048e2 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/scope/EnvironmentTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/scope/EnvironmentTest.java @@ -6,10 +6,10 @@ package org.opensearch.sql.legacy.antlr.semantic.scope; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.aMapWithSize; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.hasEntry; -import static org.hamcrest.MatcherAssert.assertThat; import static org.opensearch.sql.legacy.antlr.semantic.types.base.OpenSearchDataType.BOOLEAN; import static org.opensearch.sql.legacy.antlr.semantic.types.base.OpenSearchDataType.DATE; import static org.opensearch.sql.legacy.antlr.semantic.types.base.OpenSearchDataType.KEYWORD; diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/scope/SymbolTableTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/scope/SymbolTableTest.java index 3ccc75da62..fcbc9bf7b6 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/scope/SymbolTableTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/scope/SymbolTableTest.java @@ -6,10 +6,10 @@ package org.opensearch.sql.legacy.antlr.semantic.scope; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.aMapWithSize; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.hasEntry; -import static org.hamcrest.MatcherAssert.assertThat; import static org.opensearch.sql.legacy.antlr.semantic.types.base.OpenSearchDataType.BOOLEAN; import static org.opensearch.sql.legacy.antlr.semantic.types.base.OpenSearchDataType.DATE; import static org.opensearch.sql.legacy.antlr.semantic.types.base.OpenSearchDataType.KEYWORD; diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMappingTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMappingTest.java index fe8b25ed1c..cca69d8af9 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMappingTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMappingTest.java @@ -7,8 +7,8 @@ package org.opensearch.sql.legacy.esdomain.mapping; import static java.util.Collections.emptyMap; -import static org.hamcrest.Matchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; import static org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata; import com.google.common.collect.ImmutableMap; diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/plugin/RestSQLQueryActionCursorFallbackTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/plugin/RestSQLQueryActionCursorFallbackTest.java index 2afcdc93f4..64e5d161b7 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/plugin/RestSQLQueryActionCursorFallbackTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/plugin/RestSQLQueryActionCursorFallbackTest.java @@ -20,7 +20,6 @@ import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.opensearch.client.node.NodeClient; -import org.opensearch.common.Strings; import org.opensearch.common.inject.Injector; import org.opensearch.common.inject.ModulesBuilder; import org.opensearch.common.util.concurrent.ThreadContext; @@ -93,7 +92,7 @@ private static SQLQueryRequest createSqlQueryRequest(String query, Optional source) { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); Settings.Builder settingsBuilder = Settings.builder() - .loadFromSource(Strings.toString(builder), builder.contentType()); + .loadFromSource(builder.toString(), builder.contentType()); settingsBuilder.keys().removeIf(key -> { for (String prefix : SETTINGS_PREFIX) { if (key.startsWith(prefix)) {