From cf8886973794bd692a88e3e0b50b71c0a0cf7bd0 Mon Sep 17 00:00:00 2001 From: currantw Date: Thu, 12 Dec 2024 12:50:29 -0800 Subject: [PATCH] Revert changes not specifically related to `Arrays.asList` Signed-off-by: currantw --- .../BasicAuthenticationInterceptorTest.java | 5 +- .../sql/analysis/ExpressionAnalyzer.java | 5 +- .../analysis/SelectExpressionAnalyzer.java | 6 +- .../sql/analysis/symbol/SymbolTable.java | 3 +- .../sql/ast/expression/AggregateFunction.java | 7 +- .../opensearch/sql/ast/expression/Cast.java | 3 +- .../sql/ast/expression/Interval.java | 3 +- .../sql/ast/expression/QualifiedName.java | 3 +- .../sql/storage/write/TableWriteBuilder.java | 5 +- .../sql/storage/write/TableWriteOperator.java | 3 +- .../opensearch/sql/analysis/AnalyzerTest.java | 56 ++++---- .../sql/analysis/AnalyzerTestBase.java | 3 +- .../sql/analysis/ExpressionAnalyzerTest.java | 6 +- .../opensearch/sql/executor/ExplainTest.java | 34 ++--- .../expression/ExpressionNodeVisitorTest.java | 3 +- .../physical/AggregationOperatorTest.java | 133 ++++++++++-------- .../physical/PhysicalPlanNodeVisitorTest.java | 5 +- .../physical/RareTopNOperatorTest.java | 21 +-- .../planner/physical/RenameOperatorTest.java | 6 +- .../assigner/TumblingWindowAssignerTest.java | 8 +- .../storage/write/TableWriteOperatorTest.java | 4 +- .../service/DataSourceServiceImplTest.java | 50 +++++-- ...enSearchDataSourceMetadataStorageTest.java | 13 +- .../utils/DatasourceValidationUtilsTest.java | 12 +- .../sql/correctness/tests/TestConfigTest.java | 3 +- .../antlr/semantic/scope/SymbolTable.java | 3 +- .../visitor/AntlrSqlParseTreeVisitor.java | 5 +- .../legacy/esdomain/mapping/FieldMapping.java | 3 +- .../esdomain/mapping/IndexMappings.java | 4 +- .../executor/format/DeleteResultSet.java | 7 +- .../physical/node/join/JoinAlgorithm.java | 4 +- .../planner/physical/node/sort/QuickSort.java | 4 +- .../legacy/antlr/SymbolSimilarityTest.java | 7 +- .../esdomain/mapping/FieldMappingTest.java | 7 +- .../executor/AsyncRestExecutorTest.java | 3 +- .../unittest/planner/QueryPlannerTest.java | 3 +- .../sql/legacy/util/CheckScriptContents.java | 3 +- .../planner/physical/ADOperator.java | 3 +- .../planner/physical/MLCommonsOperator.java | 3 +- .../planner/physical/MLOperator.java | 3 +- .../agg/NoBucketAggregationParser.java | 3 +- .../aggregation/AggregationQueryBuilder.java | 3 +- .../script/filter/FilterQueryBuilder.java | 3 +- .../OpenSearchExecutionProtectorTest.java | 27 ++-- .../physical/MLCommonsOperatorTest.java | 4 +- .../planner/physical/MLOperatorTest.java | 4 +- .../request/OpenSearchRequestBuilderTest.java | 5 +- .../response/OpenSearchResponseTest.java | 3 +- .../OpenSearchIndexScanOptimizationTest.java | 9 +- .../ExpressionAggregationScriptTest.java | 3 +- .../filter/ExpressionFilterScriptTest.java | 9 +- .../system/OpenSearchSystemIndexScanTest.java | 4 +- .../org/opensearch/sql/plugin/SQLPlugin.java | 3 +- .../sql/ppl/utils/ArgumentFactory.java | 8 +- .../ppl/parser/AstExpressionBuilderTest.java | 39 ++--- .../client/PrometheusClientImplTest.java | 6 +- ...eryRangeFunctionTableScanOperatorTest.java | 14 +- .../PrometheusListMetricsRequestTest.java | 6 +- .../storage/PrometheusMetricScanTest.java | 4 +- .../storage/PrometheusStorageFactoryTest.java | 17 ++- .../system/PrometheusSystemTableScanTest.java | 4 +- .../sql/spark/storage/SparkStorageEngine.java | 5 +- .../sql/sql/parser/AstAggregationBuilder.java | 6 +- .../opensearch/sql/sql/parser/AstBuilder.java | 8 +- .../sql/parser/AstAggregationBuilderTest.java | 3 +- 65 files changed, 385 insertions(+), 277 deletions(-) diff --git a/common/src/test/java/org/opensearch/sql/common/interceptors/BasicAuthenticationInterceptorTest.java b/common/src/test/java/org/opensearch/sql/common/interceptors/BasicAuthenticationInterceptorTest.java index 165f9e63f7..af93060fab 100644 --- a/common/src/test/java/org/opensearch/sql/common/interceptors/BasicAuthenticationInterceptorTest.java +++ b/common/src/test/java/org/opensearch/sql/common/interceptors/BasicAuthenticationInterceptorTest.java @@ -7,8 +7,7 @@ package org.opensearch.sql.common.interceptors; -import static java.util.Collections.singletonList; - +import java.util.Collections; import lombok.SneakyThrows; import okhttp3.Credentials; import okhttp3.Interceptor; @@ -48,7 +47,7 @@ void testIntercept() { Mockito.verify(chain).proceed(requestArgumentCaptor.capture()); Request request = requestArgumentCaptor.getValue(); Assertions.assertEquals( - singletonList(Credentials.basic("testAdmin", "testPassword")), + Collections.singletonList(Credentials.basic("testAdmin", "testPassword")), request.headers("Authorization")); } } 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 bef62fa408..5a8d6fe976 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java @@ -13,6 +13,7 @@ import com.google.common.collect.ImmutableSet; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -82,7 +83,9 @@ public Expression visitCast(Cast node, AnalysisContext context) { final Expression expression = node.getExpression().accept(this, context); return (Expression) repository.compile( - context.getFunctionProperties(), node.convertFunctionName(), List.of(expression)); + context.getFunctionProperties(), + node.convertFunctionName(), + Collections.singletonList(expression)); } public ExpressionAnalyzer(BuiltinFunctionRepository repository) { 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 d296ad6573..5e46cfa629 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java @@ -6,6 +6,7 @@ package org.opensearch.sql.analysis; import com.google.common.collect.ImmutableList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.regex.Pattern; @@ -53,7 +54,7 @@ public List analyze( @Override public List visitField(Field node, AnalysisContext context) { - return List.of(DSL.named(node.accept(expressionAnalyzer, context))); + return Collections.singletonList(DSL.named(node.accept(expressionAnalyzer, context))); } @Override @@ -64,7 +65,8 @@ public List visitAlias(Alias node, AnalysisContext context) { } Expression expr = referenceIfSymbolDefined(node, context); - return List.of(DSL.named(unqualifiedNameIfFieldOnly(node, context), expr, node.getAlias())); + return Collections.singletonList( + DSL.named(unqualifiedNameIfFieldOnly(node, context), expr, node.getAlias())); } /** 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 e2913a0e4e..64a4fc4e09 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 @@ -5,6 +5,7 @@ package org.opensearch.sql.analysis.symbol; +import static java.util.Collections.emptyMap; import static java.util.Collections.emptyNavigableMap; import java.util.EnumMap; @@ -87,7 +88,7 @@ public Map lookupByPrefix(Symbol prefix) { if (table != null) { return table.subMap(prefix.getName(), prefix.getName() + Character.MAX_VALUE); } - return Map.of(); + return emptyMap(); } /** 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 6e837e90cc..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 @@ -5,6 +5,7 @@ package org.opensearch.sql.ast.expression; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -41,7 +42,7 @@ public class AggregateFunction extends UnresolvedExpression { public AggregateFunction(String funcName, UnresolvedExpression field) { this.funcName = funcName; this.field = field; - this.argList = List.of(); + this.argList = Collections.emptyList(); } /** @@ -54,13 +55,13 @@ public AggregateFunction(String funcName, UnresolvedExpression field) { public AggregateFunction(String funcName, UnresolvedExpression field, Boolean distinct) { this.funcName = funcName; this.field = field; - this.argList = List.of(); + this.argList = Collections.emptyList(); this.distinct = distinct; } @Override public List getChild() { - return List.of(field); + return Collections.singletonList(field); } @Override 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 77719b000b..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 @@ -19,6 +19,7 @@ import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_TIMESTAMP; import com.google.common.collect.ImmutableMap; +import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Map; @@ -98,7 +99,7 @@ public FunctionName convertFunctionName() { @Override public List getChild() { - return List.of(expression); + return Collections.singletonList(expression); } @Override 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 6ffc86497d..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 @@ -5,6 +5,7 @@ package org.opensearch.sql.ast.expression; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -28,7 +29,7 @@ public Interval(UnresolvedExpression value, String unit) { @Override public List getChild() { - return List.of(value); + return Collections.singletonList(value); } @Override 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 c105dfb762..852b61cfa8 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 @@ -11,6 +11,7 @@ import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.StreamSupport; @@ -24,7 +25,7 @@ public class QualifiedName extends UnresolvedExpression { private final List parts; public QualifiedName(String name) { - this.parts = List.of(name); + this.parts = Collections.singletonList(name); } /** QualifiedName Constructor. */ diff --git a/core/src/main/java/org/opensearch/sql/storage/write/TableWriteBuilder.java b/core/src/main/java/org/opensearch/sql/storage/write/TableWriteBuilder.java index 1a430fc049..af18916f71 100644 --- a/core/src/main/java/org/opensearch/sql/storage/write/TableWriteBuilder.java +++ b/core/src/main/java/org/opensearch/sql/storage/write/TableWriteBuilder.java @@ -5,8 +5,7 @@ package org.opensearch.sql.storage.write; -import static java.util.Collections.singletonList; - +import java.util.Collections; import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.logical.LogicalPlanNodeVisitor; import org.opensearch.sql.planner.physical.PhysicalPlan; @@ -21,7 +20,7 @@ public abstract class TableWriteBuilder extends LogicalPlan { /** Construct table write builder with child node. */ public TableWriteBuilder(LogicalPlan child) { - super(singletonList(child)); + super(Collections.singletonList(child)); } /** diff --git a/core/src/main/java/org/opensearch/sql/storage/write/TableWriteOperator.java b/core/src/main/java/org/opensearch/sql/storage/write/TableWriteOperator.java index b11eb35f0e..92cdc6eb41 100644 --- a/core/src/main/java/org/opensearch/sql/storage/write/TableWriteOperator.java +++ b/core/src/main/java/org/opensearch/sql/storage/write/TableWriteOperator.java @@ -5,6 +5,7 @@ package org.opensearch.sql.storage.write; +import java.util.Collections; import java.util.List; import lombok.RequiredArgsConstructor; import org.opensearch.sql.planner.physical.PhysicalPlan; @@ -28,7 +29,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } /** diff --git a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java index 56e2f6f704..4f06ce9d23 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.analysis; +import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -61,6 +62,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -406,9 +408,9 @@ public void analyze_filter_aggregation_relation() { ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value"))), alias("MIN(integer_value)", aggregate("MIN", qualifiedName("integer_value")))), - List.of(), + emptyList(), ImmutableList.of(alias("string_value", qualifiedName("string_value"))), - List.of()), + emptyList()), compare(">", aggregate("MIN", qualifiedName("integer_value")), intLiteral(10)))); } @@ -489,7 +491,7 @@ public void rename_to_invalid_expression() { AstDSL.alias( "avg(integer_value)", AstDSL.aggregate("avg", field("integer_value")))), - List.of(), + Collections.emptyList(), ImmutableList.of(), AstDSL.defaultStatsArgs()), AstDSL.map( @@ -892,7 +894,7 @@ public void remove_source() { DSL.ref("double_value", DOUBLE)), AstDSL.projectWithArg( AstDSL.relation("schema"), - List.of(argument("exclude", booleanLiteral(true))), + Collections.singletonList(argument("exclude", booleanLiteral(true))), AstDSL.field("integer_value"), AstDSL.field("double_value"))); } @@ -954,9 +956,9 @@ public void sort_with_aggregator() { ImmutableList.of( AstDSL.alias( "avg(integer_value)", function("avg", qualifiedName("integer_value")))), - List.of(), + emptyList(), ImmutableList.of(AstDSL.alias("string_value", qualifiedName("string_value"))), - List.of()), + emptyList()), field( function("avg", qualifiedName("integer_value")), argument("asc", booleanLiteral(true)))), @@ -1039,8 +1041,8 @@ public void window_function() { "window_function", AstDSL.window( AstDSL.function("row_number"), - List.of(AstDSL.qualifiedName("string_value")), - List.of( + Collections.singletonList(AstDSL.qualifiedName("string_value")), + Collections.singletonList( ImmutablePair.of(DEFAULT_ASC, AstDSL.qualifiedName("integer_value"))))))); } @@ -1096,13 +1098,13 @@ public void nested_group_by_clause_throws_syntax_exception() { AstDSL.project( AstDSL.agg( AstDSL.relation("schema"), - List.of(), - List.of(), + emptyList(), + emptyList(), ImmutableList.of( alias( "nested(message.info)", function("nested", qualifiedName("message", "info")))), - List.of())))); + emptyList())))); assertEquals( "Falling back to legacy engine. Nested function is not supported in WHERE," + " GROUP BY, and HAVING clauses.", @@ -1126,9 +1128,9 @@ public void sql_group_by_field() { AstDSL.relation("schema"), ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))), - List.of(), + emptyList(), ImmutableList.of(alias("string_value", qualifiedName("string_value"))), - List.of()), + emptyList()), AstDSL.alias("string_value", qualifiedName("string_value")), AstDSL.alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value"))))); } @@ -1151,10 +1153,10 @@ public void sql_group_by_function() { AstDSL.relation("schema"), ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))), - List.of(), + emptyList(), ImmutableList.of( alias("abs(long_value)", function("abs", qualifiedName("long_value")))), - List.of()), + emptyList()), AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))), AstDSL.alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value"))))); } @@ -1177,10 +1179,10 @@ public void sql_group_by_function_in_uppercase() { AstDSL.relation("schema"), ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))), - List.of(), + emptyList(), ImmutableList.of( alias("ABS(long_value)", function("ABS", qualifiedName("long_value")))), - List.of()), + emptyList()), AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))), AstDSL.alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value"))))); } @@ -1203,10 +1205,10 @@ public void sql_expression_over_one_aggregation() { AstDSL.relation("schema"), ImmutableList.of( alias("avg(integer_value)", aggregate("avg", qualifiedName("integer_value")))), - List.of(), + emptyList(), ImmutableList.of( alias("abs(long_value)", function("abs", qualifiedName("long_value")))), - List.of()), + emptyList()), AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))), AstDSL.alias( "abs(avg(integer_value)", @@ -1237,10 +1239,10 @@ public void sql_expression_over_two_aggregation() { ImmutableList.of( alias("sum(integer_value)", aggregate("sum", qualifiedName("integer_value"))), alias("avg(integer_value)", aggregate("avg", qualifiedName("integer_value")))), - List.of(), + emptyList(), ImmutableList.of( alias("abs(long_value)", function("abs", qualifiedName("long_value")))), - List.of()), + emptyList()), AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))), AstDSL.alias( "sum(integer_value)-avg(integer_value)", @@ -1278,7 +1280,7 @@ public void named_aggregator_with_condition() { DSL.count(DSL.ref("string_value", STRING)) .condition( DSL.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))))), - List.of()), + emptyList()), DSL.named( "count(string_value) filter(where integer_value > 1)", DSL.ref("count(string_value) filter(where integer_value > 1)", INTEGER))), @@ -1292,9 +1294,9 @@ public void named_aggregator_with_condition() { "count", qualifiedName("string_value"), function(">", qualifiedName("integer_value"), intLiteral(1))))), - List.of(), - List.of(), - List.of()), + emptyList(), + emptyList(), + emptyList()), AstDSL.alias( "count(string_value) filter(where integer_value > 1)", filteredAggregate( @@ -1318,10 +1320,10 @@ public void ppl_stats_by_fieldAndSpan() { AstDSL.relation("schema"), ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))), - List.of(), + emptyList(), ImmutableList.of(alias("string_value", qualifiedName("string_value"))), alias("span", span(field("long_value"), intLiteral(10), SpanUnit.NONE)), - List.of())); + emptyList())); } @Test diff --git a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java index 3548cffef5..17f86cadba 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java @@ -12,6 +12,7 @@ import com.google.common.collect.ImmutableMap; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -60,7 +61,7 @@ protected StorageEngine prometheusStorageEngine() { return new StorageEngine() { @Override public Collection getFunctions() { - return List.of( + return Collections.singletonList( new FunctionResolver() { @Override diff --git a/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java index 8a7adff3fd..b27b8348e2 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.analysis; +import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -172,7 +173,8 @@ public void case_with_default_result_type_different() { @Test public void scalar_window_function() { - assertAnalyzeEqual(DSL.rank(), AstDSL.window(AstDSL.function("rank"), List.of(), List.of())); + assertAnalyzeEqual( + DSL.rank(), AstDSL.window(AstDSL.function("rank"), emptyList(), emptyList())); } @SuppressWarnings("unchecked") @@ -181,7 +183,7 @@ public void aggregate_window_function() { assertAnalyzeEqual( new AggregateWindowFunction(DSL.avg(DSL.ref("integer_value", INTEGER))), AstDSL.window( - AstDSL.aggregate("avg", qualifiedName("integer_value")), List.of(), List.of())); + AstDSL.aggregate("avg", qualifiedName("integer_value")), emptyList(), emptyList())); } @Test diff --git a/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java b/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java index bf6b1cca68..eaeae07242 100644 --- a/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java +++ b/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java @@ -5,6 +5,8 @@ package org.opensearch.sql.executor; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opensearch.sql.ast.tree.RareTopN.CommandType.TOP; import static org.opensearch.sql.ast.tree.Sort.SortOption.DEFAULT_ASC; @@ -76,11 +78,11 @@ void can_explain_project_filter_table_scan() { new ExplainResponseNode( "ProjectOperator", Map.of("fields", "[name, age]"), - List.of( + singletonList( new ExplainResponseNode( "FilterOperator", Map.of("conditions", "and(=(balance, 10000), >(age, 30))"), - List.of(tableScan.explainNode()))))), + singletonList(tableScan.explainNode()))))), explain.apply(plan)); } @@ -99,7 +101,7 @@ void can_explain_aggregations() { Map.of( "aggregators", "[avg(balance)]", "groupBy", "[state]"), - List.of(tableScan.explainNode()))), + singletonList(tableScan.explainNode()))), explain.apply(plan)); } @@ -107,13 +109,13 @@ void can_explain_aggregations() { void can_explain_rare_top_n() { Expression field = ref("state", STRING); - PhysicalPlan plan = rareTopN(tableScan, TOP, List.of(), field); + PhysicalPlan plan = rareTopN(tableScan, TOP, emptyList(), field); assertEquals( new ExplainResponse( new ExplainResponseNode( "RareTopNOperator", Map.of("commandType", TOP, "noOfResults", 10, "fields", "[state]", "groupBy", "[]"), - List.of(tableScan.explainNode()))), + singletonList(tableScan.explainNode()))), explain.apply(plan)); } @@ -143,7 +145,7 @@ void can_explain_window() { Map.of( "sortOrder", "ASC", "nullOrder", "NULL_FIRST")))), - List.of(tableScan.explainNode()))), + singletonList(tableScan.explainNode()))), explain.apply(plan)); } @@ -169,15 +171,15 @@ void can_explain_other_operators() { new ExplainResponseNode( "RemoveOperator", Map.of("removeList", "[state]"), - List.of( + singletonList( new ExplainResponseNode( "RenameOperator", Map.of("mapping", Map.of("state", "s")), - List.of( + singletonList( new ExplainResponseNode( "EvalOperator", Map.of("expressions", Map.of("age", "+(age, 2)")), - List.of( + singletonList( new ExplainResponseNode( "DedupeOperator", Map.of( @@ -189,7 +191,7 @@ void can_explain_other_operators() { false, "consecutive", false), - List.of( + singletonList( new ExplainResponseNode( "SortOperator", Map.of( @@ -199,11 +201,11 @@ void can_explain_other_operators() { Map.of( "sortOrder", "ASC", "nullOrder", "NULL_FIRST"))), - List.of( + singletonList( new ExplainResponseNode( "ValuesOperator", Map.of("values", List.of(values)), - List.of())))))))))))), + emptyList())))))))))))), explain.apply(plan)); } @@ -215,7 +217,7 @@ void can_explain_limit() { new ExplainResponseNode( "LimitOperator", Map.of("limit", 10, "offset", 5), - List.of(tableScan.explainNode()))), + singletonList(tableScan.explainNode()))), explain.apply(plan)); } @@ -235,7 +237,7 @@ void can_explain_takeOrdered() { 5, "sortList", Map.of("a", Map.of("sortOrder", "ASC", "nullOrder", "NULL_FIRST"))), - List.of(tableScan.explainNode()))), + singletonList(tableScan.explainNode()))), explain.apply(plan)); } @@ -250,7 +252,7 @@ void can_explain_nested() { new ExplainResponseNode( "NestedOperator", Map.of("nested", Set.of("message.info", "message")), - List.of(tableScan.explainNode()))), + singletonList(tableScan.explainNode()))), explain.apply(plan)); } @@ -273,7 +275,7 @@ public String toString() { /** Used to ignore table scan which is duplicate but required for each operator test. */ public ExplainResponseNode explainNode() { return new ExplainResponseNode( - "FakeTableScan", Map.of("request", "Fake DSL request"), List.of()); + "FakeTableScan", Map.of("request", "Fake DSL request"), emptyList()); } public String explain() { diff --git a/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java b/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java index d77f484248..2f3e855430 100644 --- a/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java @@ -14,6 +14,7 @@ import static org.opensearch.sql.expression.DSL.ref; import com.google.common.collect.ImmutableList; +import java.util.Collections; import java.util.List; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -37,7 +38,7 @@ void should_return_null_by_default() { assertNull(DSL.abs(literal(-10)).accept(visitor, null)); assertNull(DSL.sum(literal(10)).accept(visitor, null)); assertNull( - named("avg", new AvgAggregator(List.of(ref("age", INTEGER)), INTEGER)) + named("avg", new AvgAggregator(Collections.singletonList(ref("age", INTEGER)), INTEGER)) .accept(visitor, null)); assertNull(new CaseClause(ImmutableList.of(), null).accept(visitor, null)); assertNull(new WhenClause(literal("test"), literal(10)).accept(visitor, null)); diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java index faca949df0..ee784045d0 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java @@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableMap; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; import org.opensearch.sql.data.model.ExprDateValue; @@ -37,8 +38,9 @@ public void sum_without_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - List.of(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), - List.of()); + Collections.singletonList( + DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), + Collections.emptyList()); List result = execute(plan); assertEquals(1, result.size()); assertThat( @@ -51,8 +53,9 @@ public void avg_with_one_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - List.of(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), - List.of(DSL.named("action", DSL.ref("action", STRING)))); + Collections.singletonList( + DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + Collections.singletonList(DSL.named("action", DSL.ref("action", STRING)))); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -67,7 +70,8 @@ public void avg_with_two_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - List.of(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + Collections.singletonList( + DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), Arrays.asList( DSL.named("action", DSL.ref("action", STRING)), DSL.named("ip", DSL.ref("ip", STRING)))); @@ -89,8 +93,9 @@ public void sum_with_one_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - List.of(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), - List.of(DSL.named("action", DSL.ref("action", STRING)))); + Collections.singletonList( + DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), + Collections.singletonList(DSL.named("action", DSL.ref("action", STRING)))); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -105,8 +110,8 @@ public void millisecond_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - List.of( + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + Collections.singletonList( DSL.named( "span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6 * 1000), "ms")))); List result = execute(plan); @@ -126,8 +131,8 @@ public void second_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - List.of( + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + Collections.singletonList( DSL.named("span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6), "s")))); List result = execute(plan); assertEquals(2, result.size()); @@ -146,8 +151,8 @@ public void minute_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("minute", TIMESTAMP)))), - List.of( + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("minute", TIMESTAMP)))), + Collections.singletonList( DSL.named("span", DSL.span(DSL.ref("minute", TIMESTAMP), DSL.literal(5), "m")))); List result = execute(plan); assertEquals(3, result.size()); @@ -165,8 +170,9 @@ public void minute_span() { plan = new AggregationOperator( testScan(datetimeInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), - List.of(DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(30), "m")))); + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(30), "m")))); result = execute(plan); assertEquals(4, result.size()); assertThat( @@ -187,8 +193,9 @@ public void hour_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), - List.of(DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(1), "h")))); + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(1), "h")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -207,8 +214,9 @@ public void day_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - List.of(DSL.named("count(day)", DSL.count(DSL.ref("day", DATE)))), - List.of(DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")))); + Collections.singletonList(DSL.named("count(day)", DSL.count(DSL.ref("day", DATE)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")))); List result = execute(plan); assertEquals(4, result.size()); assertThat( @@ -226,8 +234,9 @@ public void day_span() { plan = new AggregationOperator( testScan(dateInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), - List.of(DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(30), "d")))); + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(30), "d")))); result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -246,8 +255,9 @@ public void week_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), - List.of(DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(5), "w")))); + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(5), "w")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -266,8 +276,9 @@ public void month_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), - List.of(DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(1), "M")))); + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(1), "M")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -283,8 +294,8 @@ public void month_span() { plan = new AggregationOperator( testScan(dateInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), - List.of( + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), + Collections.singletonList( DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "M")))); result = execute(plan); assertEquals(4, result.size()); @@ -304,8 +315,8 @@ public void month_span() { plan = new AggregationOperator( testScan(dateInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - List.of( + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), + Collections.singletonList( DSL.named( "span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10 * 12), "M")))); result = execute(plan); @@ -327,8 +338,8 @@ public void quarter_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), - List.of( + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), + Collections.singletonList( DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "q")))); List result = execute(plan); assertEquals(2, result.size()); @@ -344,8 +355,8 @@ public void quarter_span() { plan = new AggregationOperator( testScan(dateInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - List.of( + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), + Collections.singletonList( DSL.named("span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10 * 4), "q")))); result = execute(plan); assertEquals(3, result.size()); @@ -366,8 +377,9 @@ public void year_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - List.of(DSL.named("span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10), "y")))); + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10), "y")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -387,8 +399,9 @@ public void integer_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), - List.of(DSL.named("span", DSL.span(DSL.ref("integer", INTEGER), DSL.literal(1), "")))); + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("integer", INTEGER), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -401,8 +414,8 @@ public void integer_field() { plan = new AggregationOperator( testScan(numericInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), - List.of( + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), + Collections.singletonList( DSL.named("span", DSL.span(DSL.ref("integer", INTEGER), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); @@ -419,8 +432,9 @@ public void long_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), - List.of(DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1), "")))); + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -433,8 +447,9 @@ public void long_field() { plan = new AggregationOperator( testScan(numericInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), - List.of(DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1.5), "")))); + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -450,8 +465,9 @@ public void float_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), - List.of(DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1), "")))); + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -464,8 +480,9 @@ public void float_field() { plan = new AggregationOperator( testScan(numericInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), - List.of(DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1.5), "")))); + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -481,8 +498,9 @@ public void double_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), - List.of(DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1), "")))); + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -495,8 +513,9 @@ public void double_field() { plan = new AggregationOperator( testScan(numericInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), - List.of(DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1.5), "")))); + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), + Collections.singletonList( + DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -512,7 +531,7 @@ public void twoBucketsSpanAndLong() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - List.of(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), + Collections.singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), Arrays.asList( DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")), DSL.named("region", DSL.ref("region", STRING)))); @@ -537,7 +556,7 @@ public void twoBucketsSpanAndLong() { plan = new AggregationOperator( testScan(compoundInputs), - List.of(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), + Collections.singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), Arrays.asList( DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")), DSL.named("region", DSL.ref("region", STRING)), @@ -624,7 +643,7 @@ public void aggregate_with_two_groups_with_windowing() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - List.of(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), + Collections.singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), Arrays.asList( DSL.named("host", DSL.ref("host", STRING)), DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")))); @@ -676,7 +695,7 @@ public void aggregate_with_three_groups_with_windowing() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - List.of(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), + Collections.singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), Arrays.asList( DSL.named("host", DSL.ref("host", STRING)), DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")), @@ -736,8 +755,8 @@ public void copyOfAggregationOperatorShouldSame() { AggregationOperator plan = new AggregationOperator( testScan(datetimeInputs), - List.of(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - List.of( + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + Collections.singletonList( DSL.named( "span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6 * 1000), "ms")))); AggregationOperator copy = diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitorTest.java index 1b8cf7f560..17fb128ace 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitorTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; @@ -109,7 +110,7 @@ public static Stream getPhysicalPlanForTest() { PhysicalPlan project = project(plan, named("ref", ref)); PhysicalPlan window = - window(plan, named(DSL.rowNumber()), new WindowDefinition(List.of(), List.of())); + window(plan, named(DSL.rowNumber()), new WindowDefinition(emptyList(), emptyList())); PhysicalPlan remove = remove(plan, ref); @@ -121,7 +122,7 @@ public static Stream getPhysicalPlanForTest() { PhysicalPlan dedupe = dedupe(plan, ref); - PhysicalPlan values = values(List.of()); + PhysicalPlan values = values(emptyList()); PhysicalPlan rareTopN = rareTopN(plan, CommandType.TOP, 5, ImmutableList.of(), ref); diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/RareTopNOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/RareTopNOperatorTest.java index e6b70fdbe3..e252c41d1f 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/RareTopNOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/RareTopNOperatorTest.java @@ -10,6 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.common.collect.ImmutableMap; +import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; import org.opensearch.sql.ast.tree.RareTopN.CommandType; @@ -26,8 +27,8 @@ public void rare_without_group() { new RareTopNOperator( new TestScan(), CommandType.RARE, - List.of(DSL.ref("action", ExprCoreType.STRING)), - List.of()); + Collections.singletonList(DSL.ref("action", ExprCoreType.STRING)), + Collections.emptyList()); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -43,8 +44,8 @@ public void rare_with_group() { new RareTopNOperator( new TestScan(), CommandType.RARE, - List.of(DSL.ref("response", ExprCoreType.INTEGER)), - List.of(DSL.ref("action", ExprCoreType.STRING))); + Collections.singletonList(DSL.ref("response", ExprCoreType.INTEGER)), + Collections.singletonList(DSL.ref("action", ExprCoreType.STRING))); List result = execute(plan); assertEquals(4, result.size()); assertThat( @@ -62,8 +63,8 @@ public void top_without_group() { new RareTopNOperator( new TestScan(), CommandType.TOP, - List.of(DSL.ref("action", ExprCoreType.STRING)), - List.of()); + Collections.singletonList(DSL.ref("action", ExprCoreType.STRING)), + Collections.emptyList()); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -80,8 +81,8 @@ public void top_n_without_group() { new TestScan(), CommandType.TOP, 1, - List.of(DSL.ref("action", ExprCoreType.STRING)), - List.of()); + Collections.singletonList(DSL.ref("action", ExprCoreType.STRING)), + Collections.emptyList()); List result = execute(plan); assertEquals(1, result.size()); assertThat( @@ -95,8 +96,8 @@ public void top_n_with_group() { new TestScan(), CommandType.TOP, 1, - List.of(DSL.ref("response", ExprCoreType.INTEGER)), - List.of(DSL.ref("action", ExprCoreType.STRING))); + Collections.singletonList(DSL.ref("response", ExprCoreType.INTEGER)), + Collections.singletonList(DSL.ref("action", ExprCoreType.STRING))); List result = execute(plan); assertEquals(2, result.size()); assertThat( diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/RenameOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/RenameOperatorTest.java index 47d557acd6..807d8b8836 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/RenameOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/RenameOperatorTest.java @@ -14,6 +14,7 @@ import static org.opensearch.sql.data.type.ExprCoreType.STRING; import com.google.common.collect.ImmutableMap; +import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -33,8 +34,9 @@ public void avg_aggregation_rename() { new RenameOperator( new AggregationOperator( new TestScan(), - List.of(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), - List.of(DSL.named("action", DSL.ref("action", STRING)))), + Collections.singletonList( + DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + Collections.singletonList(DSL.named("action", DSL.ref("action", STRING)))), ImmutableMap.of(DSL.ref("avg(response)", DOUBLE), DSL.ref("avg", DOUBLE))); List result = execute(plan); assertEquals(2, result.size()); diff --git a/core/src/test/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssignerTest.java b/core/src/test/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssignerTest.java index 4869a4c8a8..a8ab048701 100644 --- a/core/src/test/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssignerTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssignerTest.java @@ -5,10 +5,10 @@ package org.opensearch.sql.planner.streaming.windowing.assigner; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.Collections; import org.junit.jupiter.api.Test; import org.opensearch.sql.planner.streaming.windowing.Window; @@ -19,9 +19,9 @@ void testAssignWindow() { long windowSize = 1000; TumblingWindowAssigner assigner = new TumblingWindowAssigner(windowSize); - assertEquals(singletonList(new Window(0, 1000)), assigner.assign(500)); - assertEquals(singletonList(new Window(1000, 2000)), assigner.assign(1999)); - assertEquals(singletonList(new Window(2000, 3000)), assigner.assign(2000)); + assertEquals(Collections.singletonList(new Window(0, 1000)), assigner.assign(500)); + assertEquals(Collections.singletonList(new Window(1000, 2000)), assigner.assign(1999)); + assertEquals(Collections.singletonList(new Window(2000, 3000)), assigner.assign(2000)); } @Test diff --git a/core/src/test/java/org/opensearch/sql/storage/write/TableWriteOperatorTest.java b/core/src/test/java/org/opensearch/sql/storage/write/TableWriteOperatorTest.java index 3c28b14092..e5b2c9f61a 100644 --- a/core/src/test/java/org/opensearch/sql/storage/write/TableWriteOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/storage/write/TableWriteOperatorTest.java @@ -5,10 +5,10 @@ package org.opensearch.sql.storage.write; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.Collections; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -68,6 +68,6 @@ public Boolean visitTableWrite(TableWriteOperator node, Object context) { @Test void testGetChild() { - assertEquals(singletonList(child), tableWrite.getChild()); + assertEquals(Collections.singletonList(child), tableWrite.getChild()); } } diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java index be866452b7..9a1022706f 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableMap; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -103,7 +104,7 @@ void testGetDataSourceForNonExistingDataSource() { @Test void testGetDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("test", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); + metadata("test", DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of()); doNothing().when(dataSourceUserAuthorizationHelper).authorizeDataSource(dataSourceMetadata); when(dataSourceMetadataStorage.getDataSourceMetadata("test")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -118,7 +119,10 @@ void testGetDataSourceSuccessCase() { void testGetDataSourceWithAuthorizationFailure() { DataSourceMetadata dataSourceMetadata = metadata( - "test", DataSourceType.OPENSEARCH, List.of("prometheus_access"), ImmutableMap.of()); + "test", + DataSourceType.OPENSEARCH, + Collections.singletonList("prometheus_access"), + ImmutableMap.of()); doThrow( new SecurityException( "User is not authorized to access datasource test. User should be mapped to any of" @@ -144,7 +148,7 @@ void testGetDataSourceWithAuthorizationFailure() { void testCreateDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("testDS", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of()); dataSourceService.createDataSource(dataSourceMetadata); verify(dataSourceMetadataStorage, times(1)).createDataSourceMetadata(dataSourceMetadata); verify(dataSourceFactory, times(1)).createDataSource(dataSourceMetadata); @@ -152,7 +156,11 @@ void testCreateDataSourceSuccessCase() { when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn( Optional.ofNullable( - metadata("testDS", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()))); + metadata( + "testDS", + DataSourceType.OPENSEARCH, + Collections.emptyList(), + ImmutableMap.of()))); DataSource dataSource = dataSourceService.getDataSource("testDS"); assertEquals("testDS", dataSource.getName()); assertEquals(storageEngine, dataSource.getStorageEngine()); @@ -170,7 +178,9 @@ void testGetDataSourceMetadataSet() { .thenReturn( new ArrayList<>() { { - add(metadata("testDS", DataSourceType.PROMETHEUS, List.of(), properties)); + add( + metadata( + "testDS", DataSourceType.PROMETHEUS, Collections.emptyList(), properties)); } }); Set dataSourceMetadataSet = dataSourceService.getDataSourceMetadata(false); @@ -191,7 +201,12 @@ void testGetDataSourceMetadataSetWithDefaultDatasource() { .thenReturn( new ArrayList<>() { { - add(metadata("testDS", DataSourceType.PROMETHEUS, List.of(), ImmutableMap.of())); + add( + metadata( + "testDS", + DataSourceType.PROMETHEUS, + Collections.emptyList(), + ImmutableMap.of())); } }); Set dataSourceMetadataSet = dataSourceService.getDataSourceMetadata(true); @@ -204,7 +219,7 @@ void testGetDataSourceMetadataSetWithDefaultDatasource() { @Test void testUpdateDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("testDS", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of()); dataSourceService.updateDataSource(dataSourceMetadata); verify(dataSourceMetadataStorage, times(1)).updateDataSourceMetadata(dataSourceMetadata); verify(dataSourceFactory, times(1)).createDataSource(dataSourceMetadata); @@ -213,7 +228,11 @@ void testUpdateDataSourceSuccessCase() { @Test void testUpdateDefaultDataSource() { DataSourceMetadata dataSourceMetadata = - metadata(DEFAULT_DATASOURCE_NAME, DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); + metadata( + DEFAULT_DATASOURCE_NAME, + DataSourceType.OPENSEARCH, + Collections.emptyList(), + ImmutableMap.of()); UnsupportedOperationException unsupportedOperationException = assertThrows( UnsupportedOperationException.class, @@ -257,7 +276,7 @@ void testPatchDataSourceSuccessCase() { STATUS_FIELD, DataSourceStatus.DISABLED)); DataSourceMetadata getData = - metadata("testDS", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of()); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.ofNullable(getData)); @@ -320,7 +339,7 @@ void testRemovalOfAuthorizationInfo() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(List.of("prometheus_access")) + .setAllowedRoles(Collections.singletonList("prometheus_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -345,7 +364,7 @@ void testRemovalOfAuthorizationInfoForAccessKeyAndSecretKye() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(List.of("prometheus_access")) + .setAllowedRoles(Collections.singletonList("prometheus_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -372,7 +391,7 @@ void testRemovalOfAuthorizationInfoForGlueWithRoleARN() { .setName("testGlue") .setProperties(properties) .setConnector(DataSourceType.S3GLUE) - .setAllowedRoles(List.of("glue_access")) + .setAllowedRoles(Collections.singletonList("glue_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testGlue")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -414,7 +433,8 @@ void testGetDataSourceMetadataForSpecificDataSourceName() { when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn( Optional.ofNullable( - metadata("testDS", DataSourceType.PROMETHEUS, List.of(), properties))); + metadata( + "testDS", DataSourceType.PROMETHEUS, Collections.emptyList(), properties))); DataSourceMetadata dataSourceMetadata = this.dataSourceService.getDataSourceMetadata("testDS"); assertTrue(dataSourceMetadata.getProperties().containsKey("prometheus.uri")); assertTrue(dataSourceMetadata.getProperties().containsKey("prometheus.auth.type")); @@ -435,7 +455,7 @@ void testVerifyDataSourceAccessAndGetRawDataSourceMetadataWithDisabledData() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(List.of("prometheus_access")) + .setAllowedRoles(Collections.singletonList("prometheus_access")) .setDataSourceStatus(DataSourceStatus.DISABLED) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) @@ -462,7 +482,7 @@ void testVerifyDataSourceAccessAndGetRawDataSourceMetadata() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(List.of("prometheus_access")) + .setAllowedRoles(Collections.singletonList("prometheus_access")) .setDataSourceStatus(DataSourceStatus.ACTIVE) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java index efc99e2455..03abe73763 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -671,7 +672,7 @@ public void testWhenDataSourcesAreDisabled() { Optional.empty(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata("dummy")); Assertions.assertEquals( - List.of(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata()); + Collections.emptyList(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata()); Assertions.assertThrows( IllegalStateException.class, @@ -711,7 +712,7 @@ private String getBasicDataSourceMetadataString() throws JsonProcessingException .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(List.of("prometheus_access")) + .setAllowedRoles(Collections.singletonList("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -731,7 +732,7 @@ private String getAWSSigv4DataSourceMetadataString() throws JsonProcessingExcept .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(List.of("prometheus_access")) + .setAllowedRoles(Collections.singletonList("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -748,7 +749,7 @@ private String getDataSourceMetadataStringWithBasicAuthentication() .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(List.of("prometheus_access")) + .setAllowedRoles(Collections.singletonList("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -761,7 +762,7 @@ private String getDataSourceMetadataStringWithNoAuthentication() throws JsonProc .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(List.of("prometheus_access")) + .setAllowedRoles(Collections.singletonList("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -776,7 +777,7 @@ private DataSourceMetadata getDataSourceMetadata() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(List.of("prometheus_access")) + .setAllowedRoles(Collections.singletonList("prometheus_access")) .build(); } diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtilsTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtilsTest.java index e48ec0ffee..2b77c1938a 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtilsTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtilsTest.java @@ -1,8 +1,6 @@ package org.opensearch.sql.datasources.utils; -import static java.util.Collections.emptySet; -import static java.util.Collections.singletonList; - +import java.util.Collections; import java.util.HashMap; import java.util.Set; import lombok.SneakyThrows; @@ -23,7 +21,7 @@ public void testValidateHost() { IllegalArgumentException.class, () -> DatasourceValidationUtils.validateHost( - "http://localhost:9090", singletonList("127.0.0.0/8"))); + "http://localhost:9090", Collections.singletonList("127.0.0.0/8"))); Assertions.assertEquals( "Disallowed hostname in the uri. Validate with plugins.query.datasources.uri.hosts.denylist" + " config", @@ -36,7 +34,7 @@ public void testValidateHostWithSuccess() { Assertions.assertDoesNotThrow( () -> DatasourceValidationUtils.validateHost( - "http://localhost:9090", singletonList("192.168.0.0/8"))); + "http://localhost:9090", Collections.singletonList("192.168.0.0/8"))); } @Test @@ -75,6 +73,8 @@ public void testValidateLengthAndRequiredFieldsWithSuccess() { HashMap config = new HashMap<>(); config.put("s3.uri", "test"); Assertions.assertDoesNotThrow( - () -> DatasourceValidationUtils.validateLengthAndRequiredFields(config, emptySet())); + () -> + DatasourceValidationUtils.validateLengthAndRequiredFields( + config, Collections.emptySet())); } } 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 962642a540..daf084d371 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 @@ -5,6 +5,7 @@ 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; @@ -21,7 +22,7 @@ public class TestConfigTest { @Test public void testDefaultConfig() { - TestConfig config = new TestConfig(Map.of()); + TestConfig config = new TestConfig(emptyMap()); assertThat(config.getOpenSearchHostUrl(), is(emptyString())); assertThat( config.getOtherDbConnectionNameAndUrls(), diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/antlr/semantic/scope/SymbolTable.java b/legacy/src/main/java/org/opensearch/sql/legacy/antlr/semantic/scope/SymbolTable.java index 2eb0f4009d..0f65ee1b99 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/antlr/semantic/scope/SymbolTable.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/antlr/semantic/scope/SymbolTable.java @@ -5,6 +5,7 @@ package org.opensearch.sql.legacy.antlr.semantic.scope; +import static java.util.Collections.emptyMap; import static java.util.Collections.emptyNavigableMap; import java.util.EnumMap; @@ -66,7 +67,7 @@ public Map lookupByPrefix(Symbol prefix) { .filter(entry -> null != entry.getValue().get()) .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().get())); } - return Map.of(); + return emptyMap(); } /** diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/antlr/visitor/AntlrSqlParseTreeVisitor.java b/legacy/src/main/java/org/opensearch/sql/legacy/antlr/visitor/AntlrSqlParseTreeVisitor.java index 29a1bdebb9..5e89b3b8ae 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/antlr/visitor/AntlrSqlParseTreeVisitor.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/antlr/visitor/AntlrSqlParseTreeVisitor.java @@ -5,6 +5,7 @@ package org.opensearch.sql.legacy.antlr.visitor; +import static java.util.Collections.emptyList; import static java.util.Collections.singleton; import static org.opensearch.sql.legacy.antlr.parser.OpenSearchLegacySqlParser.AggregateWindowedFunctionContext; import static org.opensearch.sql.legacy.antlr.parser.OpenSearchLegacySqlParser.AtomTableItemContext; @@ -376,14 +377,14 @@ private T visitSelectItem(ParserRuleContext item, UidContext uid) { } private T reduce(T reducer, ParserRuleContext ctx) { - return reduce(reducer, (ctx == null) ? List.of() : ctx.children); + return reduce(reducer, (ctx == null) ? emptyList() : ctx.children); } /** Make constructor apply arguments and return result type */ private T reduce(T reducer, List nodes) { List args; if (nodes == null) { - args = List.of(); + args = emptyList(); } else { args = nodes.stream() diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMapping.java b/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMapping.java index 01416f442a..89f8f9ac89 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMapping.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMapping.java @@ -5,6 +5,7 @@ package org.opensearch.sql.legacy.esdomain.mapping; +import static java.util.Collections.emptyMap; import static org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata; import java.util.Map; @@ -30,7 +31,7 @@ public class FieldMapping { private final Map specifiedFieldsByName; public FieldMapping(String fieldName) { - this(fieldName, Map.of(), Map.of()); + this(fieldName, emptyMap(), emptyMap()); } public FieldMapping( diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/IndexMappings.java b/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/IndexMappings.java index 4292a95432..61e707e8ef 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/IndexMappings.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/IndexMappings.java @@ -5,6 +5,8 @@ package org.opensearch.sql.legacy.esdomain.mapping; +import static java.util.Collections.emptyMap; + import java.util.Map; import java.util.Objects; import org.opensearch.cluster.metadata.MappingMetadata; @@ -40,7 +42,7 @@ public class IndexMappings implements Mappings { private final Map indexMappings; public IndexMappings() { - this.indexMappings = Map.of(); + this.indexMappings = emptyMap(); } public IndexMappings(Metadata metaData) { diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/format/DeleteResultSet.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/format/DeleteResultSet.java index 9cfe8c9ec7..2e040d78fb 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/format/DeleteResultSet.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/format/DeleteResultSet.java @@ -5,6 +5,7 @@ package org.opensearch.sql.legacy.executor.format; +import java.util.Collections; import java.util.List; import java.util.Map; import org.opensearch.client.Client; @@ -26,14 +27,14 @@ public DeleteResultSet(Client client, Delete query, Object queryResult) { } private List loadColumns() { - return List.of(new Schema.Column(DELETED, null, Schema.Type.LONG)); + return Collections.singletonList(new Schema.Column(DELETED, null, Schema.Type.LONG)); } private List loadRows() { - return List.of(new DataRows.Row(loadDeletedData())); + return Collections.singletonList(new DataRows.Row(loadDeletedData())); } private Map loadDeletedData() { - return Map.of(DELETED, ((BulkByScrollResponse) queryResult).getDeleted()); + return Collections.singletonMap(DELETED, ((BulkByScrollResponse) queryResult).getDeleted()); } } diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/join/JoinAlgorithm.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/join/JoinAlgorithm.java index bd248f3b7e..0c0d50258d 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/join/JoinAlgorithm.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/join/JoinAlgorithm.java @@ -5,6 +5,8 @@ package org.opensearch.sql.legacy.query.planner.physical.node.join; +import static java.util.Collections.emptyList; + import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource.JoinType; import com.google.common.collect.Sets; import java.util.ArrayList; @@ -128,7 +130,7 @@ protected Collection> prefetch() throws Exception { // 4.Clean up and close right cleanUpAndCloseRight(); } - return List.of(); + return emptyList(); } /** Probe right by hash table built from left. Handle matched and mismatched rows. */ diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/sort/QuickSort.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/sort/QuickSort.java index 715cd61430..abfcf273ad 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/sort/QuickSort.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/sort/QuickSort.java @@ -5,6 +5,8 @@ package org.opensearch.sql.legacy.query.planner.physical.node.sort; +import static java.util.Collections.emptyList; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -65,7 +67,7 @@ public void open(ExecuteParams params) throws Exception { @Override protected Collection> prefetch() { if (isDone) { - return List.of(); + return emptyList(); } List> allRowsSorted = new ArrayList<>(); diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/SymbolSimilarityTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/SymbolSimilarityTest.java index 8a47a25fa9..fbdcca2bb0 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/SymbolSimilarityTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/SymbolSimilarityTest.java @@ -5,6 +5,9 @@ package org.opensearch.sql.legacy.antlr; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; + import java.util.Arrays; import java.util.List; import org.junit.Assert; @@ -16,7 +19,7 @@ public class SymbolSimilarityTest { @Test public void noneCandidateShouldReturnTargetStringItself() { String target = "test"; - String mostSimilarSymbol = new SimilarSymbols(List.of()).mostSimilarTo(target); + String mostSimilarSymbol = new SimilarSymbols(emptyList()).mostSimilarTo(target); Assert.assertEquals(target, mostSimilarSymbol); } @@ -24,7 +27,7 @@ public void noneCandidateShouldReturnTargetStringItself() { public void singleCandidateShouldReturnTheOnlyCandidate() { String target = "test"; String candidate = "hello"; - String mostSimilarSymbol = new SimilarSymbols(List.of(candidate)).mostSimilarTo(target); + String mostSimilarSymbol = new SimilarSymbols(singletonList(candidate)).mostSimilarTo(target); Assert.assertEquals(candidate, mostSimilarSymbol); } 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 05d91b2261..ed2611786a 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 @@ -5,6 +5,7 @@ package org.opensearch.sql.legacy.esdomain.mapping; +import static java.util.Collections.emptyMap; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata; @@ -28,14 +29,14 @@ public class FieldMappingTest { @Test public void testFieldMatchesWildcardPatternSpecifiedInQuery() { assertThat( - new FieldMapping("employee.first", Map.of(), fieldsSpecifiedInQuery("employee.*")), + new FieldMapping("employee.first", emptyMap(), fieldsSpecifiedInQuery("employee.*")), isWildcardSpecified(true)); } @Test public void testFieldMismatchesWildcardPatternSpecifiedInQuery() { assertThat( - new FieldMapping("employee.first", Map.of(), fieldsSpecifiedInQuery("manager.*")), + new FieldMapping("employee.first", emptyMap(), fieldsSpecifiedInQuery("manager.*")), isWildcardSpecified(false)); } @@ -75,7 +76,7 @@ public void testDeepNestedField() { "employee.location.city", new BytesArray( "{\n" + " \"city\" : {\n" + " \"type\" : \"text\"\n" + " }\n" + "}"))), - Map.of()), + emptyMap()), hasType("text")); } diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/executor/AsyncRestExecutorTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/executor/AsyncRestExecutorTest.java index f34defca6b..eea1c9a87a 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/executor/AsyncRestExecutorTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/executor/AsyncRestExecutorTest.java @@ -6,6 +6,7 @@ package org.opensearch.sql.legacy.executor; import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -42,7 +43,7 @@ public class AsyncRestExecutorTest { @Mock private Client client; - private final Map params = Map.of(); + private final Map params = emptyMap(); @Mock private QueryAction action; diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/planner/QueryPlannerTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/planner/QueryPlannerTest.java index 42019a2bfb..6ff907ba30 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/planner/QueryPlannerTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/planner/QueryPlannerTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.legacy.unittest.planner; +import static java.util.Collections.emptyList; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; @@ -103,7 +104,7 @@ public void init() { // Force return empty list to avoid ClusterSettings be invoked which is a final class and hard // to mock. // In this case, default value in Setting will be returned all the time. - doReturn(List.of()).when(settings).getSettings(); + doReturn(emptyList()).when(settings).getSettings(); doReturn(false).when(settings).getSettingValue(Settings.Key.SQL_PAGINATION_API_SEARCH_AFTER); LocalClusterState.state().setPluginSettings(settings); diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/util/CheckScriptContents.java b/legacy/src/test/java/org/opensearch/sql/legacy/util/CheckScriptContents.java index 474daab055..811d05c16a 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/util/CheckScriptContents.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/util/CheckScriptContents.java @@ -5,6 +5,7 @@ package org.opensearch.sql.legacy.util; +import static java.util.Collections.emptyList; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyLong; @@ -241,7 +242,7 @@ public static OpenSearchSettings mockPluginSettings() { // Force return empty list to avoid ClusterSettings be invoked which is a final class and hard // to mock. // In this case, default value in Setting will be returned all the time. - doReturn(List.of()).when(settings).getSettings(); + doReturn(emptyList()).when(settings).getSettings(); return settings; } } diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/ADOperator.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/ADOperator.java index 46f96f6e2d..f9c32b7424 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/ADOperator.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/ADOperator.java @@ -18,6 +18,7 @@ import static org.opensearch.sql.utils.MLCommonsConstants.TIME_ZONE; import static org.opensearch.sql.utils.MLCommonsConstants.TRAINING_DATA_SIZE; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -114,7 +115,7 @@ public ExprValue next() { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } protected MLAlgoParams convertArgumentToMLParameter(Map arguments) { diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperator.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperator.java index 10342f6d4d..ef60782a24 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperator.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperator.java @@ -10,6 +10,7 @@ import static org.opensearch.sql.utils.MLCommonsConstants.DISTANCE_TYPE; import static org.opensearch.sql.utils.MLCommonsConstants.ITERATIONS; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -90,7 +91,7 @@ public ExprValue next() { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } protected MLAlgoParams convertArgumentToMLParameter( diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLOperator.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLOperator.java index ecb486f39f..6dc7078a0d 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLOperator.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLOperator.java @@ -6,6 +6,7 @@ package org.opensearch.sql.opensearch.planner.physical; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -97,7 +98,7 @@ public ExprValue next() { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } protected Map processArgs(Map arguments) { diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/response/agg/NoBucketAggregationParser.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/response/agg/NoBucketAggregationParser.java index b3bdece816..de0ee5883c 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/response/agg/NoBucketAggregationParser.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/response/agg/NoBucketAggregationParser.java @@ -14,6 +14,7 @@ package org.opensearch.sql.opensearch.response.agg; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import org.opensearch.search.aggregations.Aggregations; @@ -33,6 +34,6 @@ public NoBucketAggregationParser(List metricParserList) { @Override public List> parse(Aggregations aggregations) { - return List.of(metricsParser.parse(aggregations)); + return Collections.singletonList(metricsParser.parse(aggregations)); } } diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilder.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilder.java index e46fdb0b81..a218151b2e 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilder.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilder.java @@ -8,6 +8,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -76,7 +77,7 @@ public AggregationQueryBuilder(ExpressionSerializer serializer) { } else { GroupSortOrder groupSortOrder = new GroupSortOrder(sortList); return Pair.of( - List.of( + Collections.singletonList( AggregationBuilders.composite( "composite_buckets", bucketBuilder.build( diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilder.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilder.java index 9cf80f0cb4..fa0fe19105 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilder.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilder.java @@ -5,6 +5,7 @@ package org.opensearch.sql.opensearch.storage.script.filter; +import static java.util.Collections.emptyMap; import static org.opensearch.script.Script.DEFAULT_SCRIPT_TYPE; import static org.opensearch.sql.opensearch.storage.script.ExpressionScriptEngine.EXPRESSION_LANG_NAME; @@ -130,6 +131,6 @@ private BoolQueryBuilder buildBoolQuery( private ScriptQueryBuilder buildScriptQuery(FunctionExpression node) { return new ScriptQueryBuilder( new Script( - DEFAULT_SCRIPT_TYPE, EXPRESSION_LANG_NAME, serializer.serialize(node), Map.of())); + DEFAULT_SCRIPT_TYPE, EXPRESSION_LANG_NAME, serializer.serialize(node), emptyMap())); } } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/executor/protector/OpenSearchExecutionProtectorTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/executor/protector/OpenSearchExecutionProtectorTest.java index f69cce7f8b..da06c1eb66 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/executor/protector/OpenSearchExecutionProtectorTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/executor/protector/OpenSearchExecutionProtectorTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.opensearch.executor.protector; +import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.Mockito.*; @@ -183,12 +184,13 @@ void test_protect_sort_for_windowOperator() { NamedExpression rank = named(mock(RankFunction.class)); Pair sortItem = ImmutablePair.of(DEFAULT_ASC, DSL.ref("age", INTEGER)); - WindowDefinition windowDefinition = new WindowDefinition(List.of(), ImmutableList.of(sortItem)); + WindowDefinition windowDefinition = + new WindowDefinition(emptyList(), ImmutableList.of(sortItem)); assertEquals( - window(resourceMonitor(sort(values(List.of()), sortItem)), rank, windowDefinition), + window(resourceMonitor(sort(values(emptyList()), sortItem)), rank, windowDefinition), executionProtector.protect( - window(sort(values(List.of()), sortItem), rank, windowDefinition))); + window(sort(values(emptyList()), sortItem), rank, windowDefinition))); } @Test @@ -207,12 +209,13 @@ void test_not_protect_windowOperator_input_if_already_protected() { NamedExpression avg = named(mock(AggregateWindowFunction.class)); Pair sortItem = ImmutablePair.of(DEFAULT_ASC, DSL.ref("age", INTEGER)); - WindowDefinition windowDefinition = new WindowDefinition(List.of(), ImmutableList.of(sortItem)); + WindowDefinition windowDefinition = + new WindowDefinition(emptyList(), ImmutableList.of(sortItem)); assertEquals( - window(resourceMonitor(sort(values(List.of()), sortItem)), avg, windowDefinition), + window(resourceMonitor(sort(values(emptyList()), sortItem)), avg, windowDefinition), executionProtector.protect( - window(sort(values(List.of()), sortItem), avg, windowDefinition))); + window(sort(values(emptyList()), sortItem), avg, windowDefinition))); } @Test @@ -229,7 +232,7 @@ void test_visitMLcommons() { NodeClient nodeClient = mock(NodeClient.class); MLCommonsOperator mlCommonsOperator = new MLCommonsOperator( - values(List.of()), + values(emptyList()), "kmeans", new HashMap() { { @@ -250,7 +253,7 @@ void test_visitAD() { NodeClient nodeClient = mock(NodeClient.class); ADOperator adOperator = new ADOperator( - values(List.of()), + values(emptyList()), new HashMap() { { put("shingle_size", new Literal(8, DataType.INTEGER)); @@ -269,7 +272,7 @@ void test_visitML() { NodeClient nodeClient = mock(NodeClient.class); MLOperator mlOperator = new MLOperator( - values(List.of()), + values(emptyList()), new HashMap() { { put("action", new Literal("train", DataType.STRING)); @@ -290,11 +293,11 @@ void test_visitNested() { Set args = Set.of("message.info"); Map> groupedFieldsByPath = Map.of("message", List.of("message.info")); NestedOperator nestedOperator = - new NestedOperator(values(List.of()), args, groupedFieldsByPath); + new NestedOperator(values(emptyList()), args, groupedFieldsByPath); assertEquals( executionProtector.doProtect(nestedOperator), - executionProtector.visitNested(nestedOperator, values(List.of()))); + executionProtector.visitNested(nestedOperator, values(emptyList()))); } @Test @@ -310,7 +313,7 @@ public void test_visitTakeOrdered() { Pair sort = ImmutablePair.of(Sort.SortOption.DEFAULT_ASC, ref("a", INTEGER)); TakeOrderedOperator takeOrdered = - PhysicalPlanDSL.takeOrdered(PhysicalPlanDSL.values(List.of()), 10, 5, sort); + PhysicalPlanDSL.takeOrdered(PhysicalPlanDSL.values(emptyList()), 10, 5, sort); assertEquals( resourceMonitor(takeOrdered), executionProtector.visitTakeOrdered(takeOrdered, null)); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperatorTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperatorTest.java index 6b76b37360..e6d2bac85b 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperatorTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperatorTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.opensearch.planner.physical; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -17,6 +16,7 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableMap; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -81,7 +81,7 @@ void setUp() { DataFrame dataFrame = DataFrameBuilder.load( - singletonList( + Collections.singletonList( ImmutableMap.builder() .put("result-k1", 2D) .put("result-k2", 1) diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLOperatorTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLOperatorTest.java index f003de848d..fa328fd26c 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLOperatorTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLOperatorTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.opensearch.planner.physical; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -21,6 +20,7 @@ import static org.opensearch.sql.utils.MLCommonsConstants.TRAIN; import com.google.common.collect.ImmutableMap; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -87,7 +87,7 @@ void setUp(boolean isPredict) { DataFrame dataFrame = DataFrameBuilder.load( - singletonList( + Collections.singletonList( ImmutableMap.builder() .put("result-k1", 2D) .put("result-k2", 1) diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/request/OpenSearchRequestBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/request/OpenSearchRequestBuilderTest.java index 0d0b0c3e67..a2430a671d 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/request/OpenSearchRequestBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/request/OpenSearchRequestBuilderTest.java @@ -14,6 +14,7 @@ import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRING; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -348,7 +349,7 @@ void test_push_down_query() { void test_push_down_aggregation() { AggregationBuilder aggBuilder = AggregationBuilders.composite( - "composite_buckets", List.of(new TermsValuesSourceBuilder("longA"))); + "composite_buckets", Collections.singletonList(new TermsValuesSourceBuilder("longA"))); OpenSearchAggregationResponseParser responseParser = new CompositeAggregationParser(new SingleValueParser("AVG(intA)")); requestBuilder.pushDownAggregation(Pair.of(List.of(aggBuilder), responseParser)); @@ -367,7 +368,7 @@ void test_push_down_aggregation() { void test_push_down_percentile_aggregation() { AggregationBuilder aggBuilder = AggregationBuilders.composite( - "composite_buckets", List.of(new TermsValuesSourceBuilder("longA"))); + "composite_buckets", Collections.singletonList(new TermsValuesSourceBuilder("longA"))); OpenSearchAggregationResponseParser responseParser = new CompositeAggregationParser(new SinglePercentileParser("PERCENTILE(intA, 50)")); requestBuilder.pushDownAggregation(Pair.of(List.of(aggBuilder), responseParser)); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/response/OpenSearchResponseTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/response/OpenSearchResponseTest.java index 5597ca1213..984c98f803 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/response/OpenSearchResponseTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/response/OpenSearchResponseTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.opensearch.response; +import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -93,7 +94,7 @@ void isEmpty() { assertTrue(response.isEmpty()); when(searchResponse.getHits()).thenReturn(SearchHits.empty()); - when(searchResponse.getAggregations()).thenReturn(new Aggregations(List.of())); + when(searchResponse.getAggregations()).thenReturn(new Aggregations(emptyList())); response = new OpenSearchResponse(searchResponse, factory, includes); assertFalse(response.isEmpty()); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/scan/OpenSearchIndexScanOptimizationTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/scan/OpenSearchIndexScanOptimizationTest.java index 98b7382b3b..6749f87c5b 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/scan/OpenSearchIndexScanOptimizationTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/scan/OpenSearchIndexScanOptimizationTest.java @@ -39,6 +39,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -330,10 +331,10 @@ void test_limit_push_down() { void test_highlight_push_down() { assertEqualsAfterOptimization( project( - indexScanBuilder(withHighlightPushedDown("*", Map.of())), + indexScanBuilder(withHighlightPushedDown("*", Collections.emptyMap())), DSL.named("highlight(*)", new HighlightExpression(DSL.literal("*")))), project( - highlight(relation("schema", table), DSL.literal("*"), Map.of()), + highlight(relation("schema", table), DSL.literal("*"), Collections.emptyMap()), DSL.named("highlight(*)", new HighlightExpression(DSL.literal("*"))))); } @@ -640,7 +641,7 @@ private Runnable withAggregationPushedDown( CompositeAggregationBuilder aggBuilder = AggregationBuilders.composite( "composite_buckets", - List.of( + Collections.singletonList( new TermsValuesSourceBuilder(aggregation.groupBy) .field(aggregation.groupBy) .order(aggregation.sortBy.getSortOrder() == ASC ? "asc" : "desc") @@ -651,7 +652,7 @@ private Runnable withAggregationPushedDown( AggregationBuilders.avg(aggregation.aggregateName).field(aggregation.aggregateBy)) .size(AggregationQueryBuilder.AGGREGATION_BUCKET_SIZE); - List aggBuilders = List.of(aggBuilder); + List aggBuilders = Collections.singletonList(aggBuilder); OpenSearchAggregationResponseParser responseParser = new CompositeAggregationParser(new SingleValueParser(aggregation.aggregateName)); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java index d25c9dc11f..6d90cce704 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java @@ -6,6 +6,7 @@ package org.opensearch.sql.opensearch.storage.script.aggregation; import static java.time.temporal.ChronoUnit.MILLIS; +import static java.util.Collections.emptyMap; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -173,7 +174,7 @@ ExprScriptAssertion docValues(String name1, Object value1, String name2, Object ExprScriptAssertion evaluate(Expression expr) { ExpressionAggregationScript script = - new ExpressionAggregationScript(expr, lookup, context, Map.of()); + new ExpressionAggregationScript(expr, lookup, context, emptyMap()); actual = script.execute(); return this; } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java index bb0bc9a129..df754887cf 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java @@ -5,6 +5,9 @@ package org.opensearch.sql.opensearch.storage.script.filter; +import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -137,7 +140,7 @@ void can_execute_expression_with_missing_field() { @Test void can_execute_expression_with_empty_doc_value() { - assertThat().docValues("name", List.of()).filterBy(ref("name", STRING)).shouldNotMatch(); + assertThat().docValues("name", emptyList()).filterBy(ref("name", STRING)).shouldNotMatch(); } @Test @@ -209,7 +212,7 @@ ExprScriptAssertion docValues(String name1, Object value1, String name2, Object } ExprScriptAssertion filterBy(Expression expr) { - ExpressionFilterScript script = new ExpressionFilterScript(expr, lookup, context, Map.of()); + ExpressionFilterScript script = new ExpressionFilterScript(expr, lookup, context, emptyMap()); isMatched = script.execute(); return this; } @@ -235,7 +238,7 @@ private static class FakeScriptDocValues extends ScriptDocValues { @SuppressWarnings("unchecked") public FakeScriptDocValues(T value) { - this.values = (value instanceof List) ? (List) value : List.of(value); + this.values = (value instanceof List) ? (List) value : singletonList(value); } @Override diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/system/OpenSearchSystemIndexScanTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/system/OpenSearchSystemIndexScanTest.java index afe2e0b172..00d1c9ecd1 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/system/OpenSearchSystemIndexScanTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/system/OpenSearchSystemIndexScanTest.java @@ -5,12 +5,12 @@ package org.opensearch.sql.opensearch.storage.system; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; import static org.opensearch.sql.data.model.ExprValueUtils.stringValue; +import java.util.Collections; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -24,7 +24,7 @@ class OpenSearchSystemIndexScanTest { @Test public void queryData() { - when(request.search()).thenReturn(singletonList(stringValue("text"))); + when(request.search()).thenReturn(Collections.singletonList(stringValue("text"))); final OpenSearchSystemIndexScan systemIndexScan = new OpenSearchSystemIndexScan(request); systemIndexScan.open(); diff --git a/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java b/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java index db87e64430..766edc42c0 100644 --- a/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java +++ b/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java @@ -5,6 +5,7 @@ package org.opensearch.sql.plugin; +import static java.util.Collections.singletonList; import static org.opensearch.sql.datasource.model.DataSourceMetadata.defaultOpenSearchDataSourceMetadata; import static org.opensearch.sql.spark.data.constants.SparkConstants.SPARK_REQUEST_BUFFER_INDEX_NAME; @@ -275,7 +276,7 @@ public ScheduledJobParser getJobParser() { @Override public List> getExecutorBuilders(Settings settings) { - return List.of( + return singletonList( new FixedExecutorBuilder( settings, AsyncRestExecutor.SQL_WORKER_THREAD_POOL_NAME, diff --git a/ppl/src/main/java/org/opensearch/sql/ppl/utils/ArgumentFactory.java b/ppl/src/main/java/org/opensearch/sql/ppl/utils/ArgumentFactory.java index c7e77651a8..f89ecf9c6e 100644 --- a/ppl/src/main/java/org/opensearch/sql/ppl/utils/ArgumentFactory.java +++ b/ppl/src/main/java/org/opensearch/sql/ppl/utils/ArgumentFactory.java @@ -15,6 +15,7 @@ import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.TopCommandContext; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.antlr.v4.runtime.ParserRuleContext; import org.opensearch.sql.ast.expression.Argument; @@ -32,7 +33,7 @@ public class ArgumentFactory { * @return the list of arguments fetched from the fields command */ public static List getArgumentList(FieldsCommandContext ctx) { - return List.of( + return Collections.singletonList( ctx.MINUS() != null ? new Argument("exclude", new Literal(true, DataType.BOOLEAN)) : new Argument("exclude", new Literal(false, DataType.BOOLEAN))); @@ -108,7 +109,7 @@ public static List getArgumentList(SortFieldContext ctx) { * @return the list of arguments fetched from the top command */ public static List getArgumentList(TopCommandContext ctx) { - return List.of( + return Collections.singletonList( ctx.number != null ? new Argument("noOfResults", getArgumentValue(ctx.number)) : new Argument("noOfResults", new Literal(10, DataType.INTEGER))); @@ -121,7 +122,8 @@ public static List getArgumentList(TopCommandContext ctx) { * @return the list of argument with default number of results for the rare command */ public static List getArgumentList(RareCommandContext ctx) { - return List.of(new Argument("noOfResults", new Literal(10, DataType.INTEGER))); + return Collections.singletonList( + new Argument("noOfResults", new Literal(10, DataType.INTEGER))); } /** diff --git a/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java b/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java index e10dca5229..fbb25549ab 100644 --- a/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java +++ b/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.ppl.parser; +import static java.util.Collections.emptyList; import static org.junit.Assert.assertFalse; import static org.opensearch.sql.ast.dsl.AstDSL.agg; import static org.opensearch.sql.ast.dsl.AstDSL.aggregate; @@ -393,7 +394,7 @@ public void testAggFuncCallExpr() { agg( relation("t"), exprList(alias("avg(a)", aggregate("avg", field("a")))), - List.of(), + emptyList(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -405,7 +406,7 @@ public void testVarAggregationShouldPass() { agg( relation("t"), exprList(alias("var_samp(a)", aggregate("var_samp", field("a")))), - List.of(), + emptyList(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -417,7 +418,7 @@ public void testVarpAggregationShouldPass() { agg( relation("t"), exprList(alias("var_pop(a)", aggregate("var_pop", field("a")))), - List.of(), + emptyList(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -429,7 +430,7 @@ public void testStdDevAggregationShouldPass() { agg( relation("t"), exprList(alias("stddev_samp(a)", aggregate("stddev_samp", field("a")))), - List.of(), + emptyList(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -441,7 +442,7 @@ public void testStdDevPAggregationShouldPass() { agg( relation("t"), exprList(alias("stddev_pop(a)", aggregate("stddev_pop", field("a")))), - List.of(), + emptyList(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -456,8 +457,8 @@ public void testPercentileAggFuncExpr() { alias( "percentile(a, 1)", aggregate("percentile", field("a"), unresolvedArg("percent", intLiteral(1))))), - List.of(), - List.of(), + emptyList(), + emptyList(), defaultStatsArgs())); assertEqual( "source=t | stats percentile(a, 1.0)", @@ -468,8 +469,8 @@ public void testPercentileAggFuncExpr() { "percentile(a, 1.0)", aggregate( "percentile", field("a"), unresolvedArg("percent", doubleLiteral(1D))))), - List.of(), - List.of(), + emptyList(), + emptyList(), defaultStatsArgs())); assertEqual( "source=t | stats percentile(a, 1.0, 100)", @@ -483,8 +484,8 @@ public void testPercentileAggFuncExpr() { field("a"), unresolvedArg("percent", doubleLiteral(1D)), unresolvedArg("compression", intLiteral(100))))), - List.of(), - List.of(), + emptyList(), + emptyList(), defaultStatsArgs())); } @@ -495,7 +496,7 @@ public void testCountFuncCallExpr() { agg( relation("t"), exprList(alias("count()", aggregate("count", AllFields.of()))), - List.of(), + emptyList(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -507,8 +508,8 @@ public void testDistinctCount() { agg( relation("t"), exprList(alias("distinct_count(a)", distinctAggregate("count", field("a")))), - List.of(), - List.of(), + emptyList(), + emptyList(), defaultStatsArgs())); } @@ -522,8 +523,8 @@ public void testTakeAggregationNoArgsShouldPass() { alias( "take(a)", aggregate("take", field("a"), unresolvedArg("size", intLiteral(10))))), - List.of(), - List.of(), + emptyList(), + emptyList(), defaultStatsArgs())); } @@ -537,8 +538,8 @@ public void testTakeAggregationWithArgsShouldPass() { alias( "take(a, 5)", aggregate("take", field("a"), unresolvedArg("size", intLiteral(5))))), - List.of(), - List.of(), + emptyList(), + emptyList(), defaultStatsArgs())); } @@ -761,7 +762,7 @@ public void indexCanBeId() { agg( relation("index"), exprList(alias("count()", aggregate("count", AllFields.of()))), - List.of(), + emptyList(), exprList(alias("index", field("index"))), defaultStatsArgs())); } diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/client/PrometheusClientImplTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/client/PrometheusClientImplTest.java index 6dc6e11f0e..d6ca25b206 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/client/PrometheusClientImplTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/client/PrometheusClientImplTest.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -153,12 +154,13 @@ void testGetAllMetrics() { Map> expected = new HashMap<>(); expected.put( "go_gc_duration_seconds", - List.of( + Collections.singletonList( new MetricMetadata( "summary", "A summary of the pause duration of garbage collection cycles.", ""))); expected.put( "go_goroutines", - List.of(new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); + Collections.singletonList( + new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); assertEquals(expected, response); RecordedRequest recordedRequest = mockWebServer.takeRequest(); verifyGetAllMetricsCall(recordedRequest); diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/functions/scan/QueryRangeFunctionTableScanOperatorTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/functions/scan/QueryRangeFunctionTableScanOperatorTest.java index 6345dcb1de..e59a2bf7c4 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/functions/scan/QueryRangeFunctionTableScanOperatorTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/functions/scan/QueryRangeFunctionTableScanOperatorTest.java @@ -7,7 +7,6 @@ package org.opensearch.sql.prometheus.functions.scan; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -24,6 +23,7 @@ import java.io.IOException; import java.time.Instant; import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashMap; import lombok.SneakyThrows; import org.json.JSONObject; @@ -80,9 +80,11 @@ void testQueryResponseIterator() { put( TIMESTAMP, new ExprCollectionValue( - singletonList( + Collections.singletonList( new ExprTimestampValue(Instant.ofEpochMilli(1435781430781L))))); - put(VALUE, new ExprCollectionValue(singletonList(new ExprDoubleValue(1)))); + put( + VALUE, + new ExprCollectionValue(Collections.singletonList(new ExprDoubleValue(1)))); } }); @@ -105,9 +107,11 @@ void testQueryResponseIterator() { put( TIMESTAMP, new ExprCollectionValue( - singletonList( + Collections.singletonList( new ExprTimestampValue(Instant.ofEpochMilli(1435781430781L))))); - put(VALUE, new ExprCollectionValue(singletonList(new ExprDoubleValue(0)))); + put( + VALUE, + new ExprCollectionValue(Collections.singletonList(new ExprDoubleValue(0)))); } }); assertEquals(secondRow, queryRangeFunctionTableScanOperator.next()); diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusListMetricsRequestTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusListMetricsRequestTest.java index 17f405df4b..09f63463b5 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusListMetricsRequestTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusListMetricsRequestTest.java @@ -15,6 +15,7 @@ import static org.opensearch.sql.data.model.ExprValueUtils.stringValue; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -42,12 +43,13 @@ void testSearch() { Map> metricsResult = new HashMap<>(); metricsResult.put( "go_gc_duration_seconds", - List.of( + Collections.singletonList( new MetricMetadata( "summary", "A summary of the pause duration of garbage collection cycles.", ""))); metricsResult.put( "go_goroutines", - List.of(new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); + Collections.singletonList( + new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); when(prometheusClient.getAllMetrics()).thenReturn(metricsResult); PrometheusListMetricsRequest prometheusListMetricsRequest = new PrometheusListMetricsRequest( diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusMetricScanTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusMetricScanTest.java index 9b3c193250..00ddc973bc 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusMetricScanTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusMetricScanTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.prometheus.storage; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -23,6 +22,7 @@ import java.io.IOException; import java.time.Instant; +import java.util.Collections; import java.util.LinkedHashMap; import lombok.SneakyThrows; import org.json.JSONObject; @@ -187,7 +187,7 @@ void testQueryResponseIteratorWithGivenPrometheusResponseWithBackQuotedFieldName prometheusResponseFieldNames.setValueType(LONG); prometheusResponseFieldNames.setTimestampFieldName(TIMESTAMP); prometheusResponseFieldNames.setGroupByList( - singletonList(DSL.named("`instance`", DSL.ref("instance", STRING)))); + Collections.singletonList(DSL.named("`instance`", DSL.ref("instance", STRING)))); PrometheusMetricScan prometheusMetricScan = new PrometheusMetricScan(prometheusClient); prometheusMetricScan.setPrometheusResponseFieldNames(prometheusResponseFieldNames); prometheusMetricScan.getRequest().setPromQl(QUERY); diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java index e41b0a321e..7b1e2dec0f 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java @@ -7,10 +7,9 @@ package org.opensearch.sql.prometheus.storage; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.mockito.Mockito.when; +import java.util.Collections; import java.util.HashMap; import lombok.SneakyThrows; import org.apache.commons.lang3.RandomStringUtils; @@ -41,7 +40,7 @@ void testGetConnectorType() { @SneakyThrows void testGetStorageEngineWithBasicAuth() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(emptyList()); + .thenReturn(Collections.emptyList()); PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); @@ -56,7 +55,7 @@ void testGetStorageEngineWithBasicAuth() { @SneakyThrows void testGetStorageEngineWithAWSSigV4Auth() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(emptyList()); + .thenReturn(Collections.emptyList()); PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); @@ -128,7 +127,7 @@ void testGetStorageEngineWithLongConfigProperties() { @SneakyThrows void testGetStorageEngineWithWrongAuthType() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(emptyList()); + .thenReturn(Collections.emptyList()); PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "https://test.com"); @@ -148,7 +147,7 @@ void testGetStorageEngineWithWrongAuthType() { @SneakyThrows void testGetStorageEngineWithNONEAuthType() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(emptyList()); + .thenReturn(Collections.emptyList()); PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "https://test.com"); @@ -175,7 +174,7 @@ void testGetStorageEngineWithInvalidURISyntax() { @Test void createDataSourceSuccess() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(emptyList()); + .thenReturn(Collections.emptyList()); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); properties.put("prometheus.auth.type", "basicauth"); @@ -196,7 +195,7 @@ void createDataSourceSuccess() { @Test void createDataSourceSuccessWithLocalhost() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(emptyList()); + .thenReturn(Collections.emptyList()); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); properties.put("prometheus.auth.type", "basicauth"); @@ -217,7 +216,7 @@ void createDataSourceSuccessWithLocalhost() { @Test void createDataSourceWithHostnameNotMatchingWithAllowHostsConfig() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(singletonList("127.0.0.0/8")); + .thenReturn(Collections.singletonList("127.0.0.0/8")); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); properties.put("prometheus.auth.type", "basicauth"); diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTableScanTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTableScanTest.java index e988a481a0..ea299b87de 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTableScanTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTableScanTest.java @@ -7,12 +7,12 @@ package org.opensearch.sql.prometheus.storage.system; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; import static org.opensearch.sql.data.model.ExprValueUtils.stringValue; +import java.util.Collections; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -26,7 +26,7 @@ public class PrometheusSystemTableScanTest { @Test public void queryData() { - when(request.search()).thenReturn(singletonList(stringValue("text"))); + when(request.search()).thenReturn(Collections.singletonList(stringValue("text"))); final PrometheusSystemTableScan systemIndexScan = new PrometheusSystemTableScan(request); systemIndexScan.open(); diff --git a/spark/src/main/java/org/opensearch/sql/spark/storage/SparkStorageEngine.java b/spark/src/main/java/org/opensearch/sql/spark/storage/SparkStorageEngine.java index 11d638457c..84c9c05e79 100644 --- a/spark/src/main/java/org/opensearch/sql/spark/storage/SparkStorageEngine.java +++ b/spark/src/main/java/org/opensearch/sql/spark/storage/SparkStorageEngine.java @@ -5,9 +5,8 @@ package org.opensearch.sql.spark.storage; -import static java.util.Collections.singletonList; - import java.util.Collection; +import java.util.Collections; import lombok.RequiredArgsConstructor; import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.expression.function.FunctionResolver; @@ -23,7 +22,7 @@ public class SparkStorageEngine implements StorageEngine { @Override public Collection getFunctions() { - return singletonList(new SparkSqlTableFunctionResolver(sparkClient)); + return Collections.singletonList(new SparkSqlTableFunctionResolver(sparkClient)); } @Override diff --git a/sql/src/main/java/org/opensearch/sql/sql/parser/AstAggregationBuilder.java b/sql/src/main/java/org/opensearch/sql/sql/parser/AstAggregationBuilder.java index 6ee0159d6e..e46147b7a3 100644 --- a/sql/src/main/java/org/opensearch/sql/sql/parser/AstAggregationBuilder.java +++ b/sql/src/main/java/org/opensearch/sql/sql/parser/AstAggregationBuilder.java @@ -5,6 +5,8 @@ package org.opensearch.sql.sql.parser; +import static java.util.Collections.emptyList; + import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -75,7 +77,7 @@ public UnresolvedPlan visit(ParseTree groupByClause) { private UnresolvedPlan buildExplicitAggregation() { List groupByItems = replaceGroupByItemIfAliasOrOrdinal(); - return new Aggregation(new ArrayList<>(querySpec.getAggregators()), List.of(), groupByItems); + return new Aggregation(new ArrayList<>(querySpec.getAggregators()), emptyList(), groupByItems); } private UnresolvedPlan buildImplicitAggregation() { @@ -91,7 +93,7 @@ private UnresolvedPlan buildImplicitAggregation() { } return new Aggregation( - new ArrayList<>(querySpec.getAggregators()), List.of(), querySpec.getGroupByItems()); + new ArrayList<>(querySpec.getAggregators()), emptyList(), querySpec.getGroupByItems()); } private List replaceGroupByItemIfAliasOrOrdinal() { diff --git a/sql/src/main/java/org/opensearch/sql/sql/parser/AstBuilder.java b/sql/src/main/java/org/opensearch/sql/sql/parser/AstBuilder.java index 8b4f331d77..ab96f16263 100644 --- a/sql/src/main/java/org/opensearch/sql/sql/parser/AstBuilder.java +++ b/sql/src/main/java/org/opensearch/sql/sql/parser/AstBuilder.java @@ -6,7 +6,6 @@ package org.opensearch.sql.sql.parser; import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.opensearch.sql.ast.dsl.AstDSL.qualifiedName; import static org.opensearch.sql.sql.antlr.parser.OpenSearchSQLParser.FromClauseContext; import static org.opensearch.sql.sql.antlr.parser.OpenSearchSQLParser.HavingClauseContext; @@ -20,6 +19,7 @@ import static org.opensearch.sql.utils.SystemIndexUtils.mappingTable; import com.google.common.collect.ImmutableList; +import java.util.Collections; import java.util.Optional; import lombok.RequiredArgsConstructor; import org.antlr.v4.runtime.tree.ParseTree; @@ -60,7 +60,7 @@ public class AstBuilder extends OpenSearchSQLParserBaseVisitor { @Override public UnresolvedPlan visitShowStatement(OpenSearchSQLParser.ShowStatementContext ctx) { final UnresolvedExpression tableFilter = visitAstExpression(ctx.tableFilter()); - return new Project(singletonList(AllFields.of())) + return new Project(Collections.singletonList(AllFields.of())) .attach(new Filter(tableFilter).attach(new Relation(qualifiedName(TABLE_INFO)))); } @@ -70,9 +70,9 @@ public UnresolvedPlan visitDescribeStatement(OpenSearchSQLParser.DescribeStateme final String tableName = tableFilter.getFuncArgs().get(1).toString(); final Relation table = new Relation(qualifiedName(mappingTable(tableName.toString()))); if (ctx.columnFilter() == null) { - return new Project(singletonList(AllFields.of())).attach(table); + return new Project(Collections.singletonList(AllFields.of())).attach(table); } else { - return new Project(singletonList(AllFields.of())) + return new Project(Collections.singletonList(AllFields.of())) .attach(new Filter(visitAstExpression(ctx.columnFilter())).attach(table)); } } diff --git a/sql/src/test/java/org/opensearch/sql/sql/parser/AstAggregationBuilderTest.java b/sql/src/test/java/org/opensearch/sql/sql/parser/AstAggregationBuilderTest.java index 461e9e7688..95188e20b6 100644 --- a/sql/src/test/java/org/opensearch/sql/sql/parser/AstAggregationBuilderTest.java +++ b/sql/src/test/java/org/opensearch/sql/sql/parser/AstAggregationBuilderTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.sql.parser; +import static java.util.Collections.emptyList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.equalTo; @@ -269,7 +270,7 @@ private Matcher featureValueOf( Function> getter, UnresolvedExpression... exprs) { Matcher> subMatcher = - (exprs.length == 0) ? equalTo(List.of()) : equalTo(Arrays.asList(exprs)); + (exprs.length == 0) ? equalTo(emptyList()) : equalTo(Arrays.asList(exprs)); return new FeatureMatcher>(subMatcher, name, "") { @Override protected List featureValueOf(UnresolvedPlan agg) {