From c2fe00ee593ad4aa5a4bb3464944ee6a3fc2b159 Mon Sep 17 00:00:00 2001 From: currantw Date: Thu, 5 Dec 2024 13:12:49 -0800 Subject: [PATCH] Replace calls to `Arrays.asList` with too few arguments. Signed-off-by: currantw --- .../cluster/ClusterManagerEventListener.java | 4 +- .../AsyncQueryExecutorServiceSpec.java | 3 +- .../sql/analysis/NestedAnalyzer.java | 3 +- .../sql/ast/expression/Argument.java | 4 +- .../org/opensearch/sql/ast/expression/In.java | 4 +- .../opensearch/sql/ast/expression/Not.java | 4 +- .../ast/expression/UnresolvedArgument.java | 4 +- .../org/opensearch/sql/ast/tree/Relation.java | 4 +- .../opensearch/sql/data/type/ExprType.java | 3 +- .../sql/planner/logical/LogicalDedupe.java | 4 +- .../SelectExpressionAnalyzerTest.java | 6 +- ...ourceSchemaIdentifierNameResolverTest.java | 2 +- .../sql/data/model/ExprValueUtilsTest.java | 2 +- .../BuiltinFunctionRepositoryTest.java | 9 +- .../sql/planner/DefaultImplementorTest.java | 9 +- .../correctness/tests/ComparisonTestTest.java | 51 ++++---- .../sql/correctness/tests/DBResultTest.java | 28 +++-- .../sql/correctness/tests/TestReportTest.java | 5 +- .../sql/legacy/PrettyFormatResponseIT.java | 6 +- .../org/opensearch/sql/util/MatcherUtils.java | 2 +- .../core/builder/UnaryExpressionBuilder.java | 4 +- .../semantic/types/TypeExpressionTest.java | 7 +- .../format/BindingTupleResultSetTest.java | 3 +- .../unittest/utils/SQLFunctionsTest.java | 3 +- .../OpenSearchCatIndicesRequestTest.java | 3 +- .../AggregationQueryBuilderTest.java | 109 ++++++++---------- .../dsl/BucketAggregationBuilderTest.java | 15 ++- .../dsl/MetricAggregationBuilderTest.java | 66 ++++------- .../sql/opensearch/utils/Utils.java | 2 +- .../sql/ppl/parser/AstExpressionBuilder.java | 2 +- .../ppl/utils/UnresolvedPlanHelperTest.java | 4 +- .../format/CsvResponseFormatterTest.java | 3 +- .../format/RawResponseFormatterTest.java | 3 +- .../SimpleJsonResponseFormatterTest.java | 5 +- .../sql/sql/parser/AstExpressionBuilder.java | 2 +- 35 files changed, 181 insertions(+), 207 deletions(-) diff --git a/async-query/src/main/java/org/opensearch/sql/spark/cluster/ClusterManagerEventListener.java b/async-query/src/main/java/org/opensearch/sql/spark/cluster/ClusterManagerEventListener.java index 6c660f073c..8dba33163c 100644 --- a/async-query/src/main/java/org/opensearch/sql/spark/cluster/ClusterManagerEventListener.java +++ b/async-query/src/main/java/org/opensearch/sql/spark/cluster/ClusterManagerEventListener.java @@ -10,7 +10,7 @@ import com.google.common.annotations.VisibleForTesting; import java.time.Clock; import java.time.Duration; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.opensearch.client.Client; import org.opensearch.cluster.LocalNodeClusterManagerListener; @@ -183,7 +183,7 @@ private void cancel(Cancellable cron) { @VisibleForTesting public List getFlintIndexRetentionCron() { - return Arrays.asList(flintIndexRetentionCron); + return Collections.singletonList(flintIndexRetentionCron); } private String executorName() { diff --git a/async-query/src/test/java/org/opensearch/sql/spark/asyncquery/AsyncQueryExecutorServiceSpec.java b/async-query/src/test/java/org/opensearch/sql/spark/asyncquery/AsyncQueryExecutorServiceSpec.java index 53b465aa6d..c828f4e90c 100644 --- a/async-query/src/test/java/org/opensearch/sql/spark/asyncquery/AsyncQueryExecutorServiceSpec.java +++ b/async-query/src/test/java/org/opensearch/sql/spark/asyncquery/AsyncQueryExecutorServiceSpec.java @@ -21,7 +21,6 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import java.net.URL; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -137,7 +136,7 @@ public class AsyncQueryExecutorServiceSpec extends OpenSearchIntegTestCase { @Override protected Collection> nodePlugins() { - return Arrays.asList(TestSettingPlugin.class); + return List.of(TestSettingPlugin.class); } public static class TestSettingPlugin extends Plugin { diff --git a/core/src/main/java/org/opensearch/sql/analysis/NestedAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/NestedAnalyzer.java index ef8f142801..84c2bd427a 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/NestedAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/NestedAnalyzer.java @@ -8,7 +8,6 @@ import static org.opensearch.sql.data.type.ExprCoreType.STRING; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; import lombok.RequiredArgsConstructor; @@ -94,7 +93,7 @@ public LogicalPlan visitFunction(Function node, AnalysisContext context) { generatePath(nestedField.toString())); } - return mergeChildIfLogicalNested(new ArrayList<>(Arrays.asList(args))); + return mergeChildIfLogicalNested(new ArrayList<>(List.of(args))); } return null; } diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Argument.java b/core/src/main/java/org/opensearch/sql/ast/expression/Argument.java index 4c2a485ea7..ca9ad795b8 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Argument.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Argument.java @@ -5,7 +5,7 @@ package org.opensearch.sql.ast.expression; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -25,7 +25,7 @@ public class Argument extends UnresolvedExpression { // private final DataType valueType; @Override public List getChild() { - return Arrays.asList(value); + return Collections.singletonList(value); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/In.java b/core/src/main/java/org/opensearch/sql/ast/expression/In.java index 38c1b91b43..781b73fca7 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/In.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/In.java @@ -5,7 +5,7 @@ package org.opensearch.sql.ast.expression; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -28,7 +28,7 @@ public class In extends UnresolvedExpression { @Override public List getChild() { - return Arrays.asList(field); + return Collections.singletonList(field); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Not.java b/core/src/main/java/org/opensearch/sql/ast/expression/Not.java index 423cb088ef..ad9c032f2e 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Not.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Not.java @@ -5,7 +5,7 @@ package org.opensearch.sql.ast.expression; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -23,7 +23,7 @@ public class Not extends UnresolvedExpression { @Override public List getChild() { - return Arrays.asList(expression); + return Collections.singletonList(expression); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedArgument.java b/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedArgument.java index 2c6eee46e9..59ebc1d839 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedArgument.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedArgument.java @@ -5,7 +5,7 @@ package org.opensearch.sql.ast.expression; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -27,7 +27,7 @@ public UnresolvedArgument(String argName, UnresolvedExpression value) { @Override public List getChild() { - return Arrays.asList(value); + return Collections.singletonList(value); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java b/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java index ec5264a86b..9d22b42e75 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java @@ -6,7 +6,7 @@ package org.opensearch.sql.ast.tree; import com.google.common.collect.ImmutableList; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import lombok.AllArgsConstructor; @@ -32,7 +32,7 @@ public Relation(UnresolvedExpression tableName) { } public Relation(UnresolvedExpression tableName, String alias) { - this.tableName = Arrays.asList(tableName); + this.tableName = Collections.singletonList(tableName); this.alias = alias; } diff --git a/core/src/main/java/org/opensearch/sql/data/type/ExprType.java b/core/src/main/java/org/opensearch/sql/data/type/ExprType.java index 58d6ee346b..2732854a14 100644 --- a/core/src/main/java/org/opensearch/sql/data/type/ExprType.java +++ b/core/src/main/java/org/opensearch/sql/data/type/ExprType.java @@ -7,7 +7,6 @@ import static org.opensearch.sql.data.type.ExprCoreType.UNKNOWN; -import java.util.Arrays; import java.util.List; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.expression.Expression; @@ -44,7 +43,7 @@ default boolean shouldCast(ExprType other) { /** Get the parent type. */ default List getParent() { - return Arrays.asList(UNKNOWN); + return List.of(UNKNOWN); } /** Get the type name. */ diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalDedupe.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalDedupe.java index 92734440f7..82a48fa87c 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalDedupe.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalDedupe.java @@ -5,7 +5,7 @@ package org.opensearch.sql.planner.logical; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -30,7 +30,7 @@ public LogicalDedupe( Integer allowedDuplication, Boolean keepEmpty, Boolean consecutive) { - super(Arrays.asList(child)); + super(Collections.singletonList(child)); this.dedupeList = dedupeList; this.allowedDuplication = allowedDuplication; this.keepEmpty = keepEmpty; diff --git a/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java index 38d4704bcd..461e1f8358 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java @@ -11,7 +11,7 @@ import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -77,11 +77,11 @@ protected List analyze(UnresolvedExpression unresolvedExpressio .when(optimizer) .optimize(any(), any()); return new SelectExpressionAnalyzer(expressionAnalyzer) - .analyze(Arrays.asList(unresolvedExpression), analysisContext, optimizer); + .analyze(Collections.singletonList(unresolvedExpression), analysisContext, optimizer); } protected void assertAnalyzeEqual( NamedExpression expected, UnresolvedExpression unresolvedExpression) { - assertEquals(Arrays.asList(expected), analyze(unresolvedExpression)); + assertEquals(Collections.singletonList(expected), analyze(unresolvedExpression)); } } diff --git a/core/src/test/java/org/opensearch/sql/analysis/model/DataSourceSchemaIdentifierNameResolverTest.java b/core/src/test/java/org/opensearch/sql/analysis/model/DataSourceSchemaIdentifierNameResolverTest.java index 775984a528..ae82a7d205 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/model/DataSourceSchemaIdentifierNameResolverTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/model/DataSourceSchemaIdentifierNameResolverTest.java @@ -40,7 +40,7 @@ void testFullyQualifiedName() { @Test void defaultDataSourceNameResolve() { when(dataSourceService.dataSourceExists(any())).thenReturn(Boolean.FALSE); - identifierOf(Arrays.asList("tables"), dataSourceService) + identifierOf(List.of("tables"), dataSourceService) .datasource(DEFAULT_DATASOURCE_NAME) .schema(DEFAULT_SCHEMA_NAME) .name("tables"); diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java index 0baf5052e4..ee46746b02 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java @@ -125,7 +125,7 @@ private static Stream getValueTestArgumentStream() { 1D, "1", true, - Arrays.asList(integerValue(1)), + List.of(integerValue(1)), ImmutableMap.of("1", integerValue(1)), LocalDate.parse("2012-08-07"), LocalTime.parse("18:00:00"), diff --git a/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java b/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java index 237477050d..ae345fa989 100644 --- a/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java @@ -24,7 +24,6 @@ import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BOOLEAN; import com.google.common.collect.ImmutableList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -73,7 +72,7 @@ void register() { @Test void compile() { when(mockExpression.type()).thenReturn(UNDEFINED); - when(functionSignature.getParamTypeList()).thenReturn(Arrays.asList(UNDEFINED)); + when(functionSignature.getParamTypeList()).thenReturn(List.of(UNDEFINED)); when(mockfunctionResolver.getFunctionName()).thenReturn(mockFunctionName); when(mockfunctionResolver.resolve(any())) .thenReturn(Pair.of(functionSignature, functionExpressionBuilder)); @@ -82,7 +81,7 @@ void compile() { BuiltinFunctionRepository repo = new BuiltinFunctionRepository(mockMap); repo.register(mockfunctionResolver); - repo.compile(functionProperties, mockFunctionName, Arrays.asList(mockExpression)); + repo.compile(functionProperties, mockFunctionName, List.of(mockExpression)); verify(functionExpressionBuilder, times(1)).apply(eq(functionProperties), any()); } @@ -90,7 +89,7 @@ void compile() { void compile_datasource_defined_function() { DefaultFunctionResolver dataSourceFunctionResolver = mock(DefaultFunctionResolver.class); when(mockExpression.type()).thenReturn(UNDEFINED); - when(functionSignature.getParamTypeList()).thenReturn(Arrays.asList(UNDEFINED)); + when(functionSignature.getParamTypeList()).thenReturn(List.of(UNDEFINED)); when(dataSourceFunctionResolver.getFunctionName()).thenReturn(mockFunctionName); when(dataSourceFunctionResolver.resolve(any())) .thenReturn(Pair.of(functionSignature, functionExpressionBuilder)); @@ -100,7 +99,7 @@ void compile_datasource_defined_function() { functionProperties, Collections.singletonList(dataSourceFunctionResolver), mockFunctionName, - Arrays.asList(mockExpression)); + List.of(mockExpression)); verify(functionExpressionBuilder, times(1)).apply(eq(functionProperties), any()); } diff --git a/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java b/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java index 8e71fc2bec..9db1eaf565 100644 --- a/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java @@ -31,7 +31,6 @@ import static org.opensearch.sql.planner.logical.LogicalPlanDSL.window; import com.google.common.collect.ImmutableMap; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -92,12 +91,12 @@ public void visit_should_return_default_physical_operator() { ReferenceExpression exclude = ref("name", STRING); ReferenceExpression dedupeField = ref("name", STRING); Expression filterExpr = literal(ExprBooleanValue.of(true)); - List groupByExprs = Arrays.asList(DSL.named("age", ref("age", INTEGER))); - List aggExprs = Arrays.asList(ref("age", INTEGER)); + List groupByExprs = List.of(named("age", ref("age", INTEGER))); + List aggExprs = List.of(ref("age", INTEGER)); ReferenceExpression rareTopNField = ref("age", INTEGER); - List topByExprs = Arrays.asList(ref("age", INTEGER)); + List topByExprs = List.of(ref("age", INTEGER)); List aggregators = - Arrays.asList(DSL.named("avg(age)", new AvgAggregator(aggExprs, ExprCoreType.DOUBLE))); + List.of(named("avg(age)", new AvgAggregator(aggExprs, ExprCoreType.DOUBLE))); Map mappings = ImmutableMap.of(ref("name", STRING), ref("lastname", STRING)); Pair newEvalField = diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/ComparisonTestTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/ComparisonTestTest.java index 5cab5b3175..793d9aa03b 100644 --- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/ComparisonTestTest.java +++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/ComparisonTestTest.java @@ -12,6 +12,7 @@ import static org.mockito.Mockito.when; import java.util.Collections; +import java.util.List; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -51,14 +52,14 @@ public void testSuccess() { .thenReturn( new DBResult( "OpenSearch", - asList(new Type("firstname", "text")), - asList(new Row(asList("John"))))); + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John"))))); when(otherDbConnection.select(anyString())) .thenReturn( new DBResult( "Other DB", - asList(new Type("firstname", "text")), - asList(new Row(asList("John"))))); + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John"))))); TestReport expected = new TestReport(); expected.addTestCase(new SuccessTestCase(1, "SELECT * FROM accounts")); @@ -70,10 +71,12 @@ public void testSuccess() { public void testFailureDueToInconsistency() { DBResult openSearchResult = new DBResult( - "OpenSearch", asList(new Type("firstname", "text")), asList(new Row(asList("John")))); + "OpenSearch", + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John")))); DBResult otherDbResult = new DBResult( - "Other DB", asList(new Type("firstname", "text")), asList(new Row(asList("JOHN")))); + "Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN")))); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(otherDbConnection.select(anyString())).thenReturn(otherDbResult); @@ -95,13 +98,17 @@ public void testSuccessFinally() { DBResult openSearchResult = new DBResult( - "OpenSearch", asList(new Type("firstname", "text")), asList(new Row(asList("John")))); + "OpenSearch", + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John")))); DBResult otherDbResult = new DBResult( - "Other DB", asList(new Type("firstname", "text")), asList(new Row(asList("JOHN")))); + "Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN")))); DBResult anotherDbResult = new DBResult( - "Another DB", asList(new Type("firstname", "text")), asList(new Row(asList("John")))); + "Another DB", + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John")))); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(anotherDbConnection.select(anyString())).thenReturn(anotherDbResult); @@ -122,13 +129,15 @@ public void testFailureDueToEventualInconsistency() { DBResult openSearchResult = new DBResult( - "OpenSearch", asList(new Type("firstname", "text")), asList(new Row(asList("John")))); + "OpenSearch", + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John")))); DBResult otherDbResult = new DBResult( - "Other DB", asList(new Type("firstname", "text")), asList(new Row(asList("JOHN")))); + "Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN")))); DBResult anotherDbResult = new DBResult( - "ZZZ DB", asList(new Type("firstname", "text")), asList(new Row(asList("Hank")))); + "ZZZ DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("Hank")))); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(otherDbConnection.select(anyString())).thenReturn(otherDbResult); when(anotherDbConnection.select(anyString())).thenReturn(anotherDbResult); @@ -162,8 +171,8 @@ public void testErrorDueToNoOtherDBSupportThisQuery() { .thenReturn( new DBResult( "OpenSearch", - asList(new Type("firstname", "text")), - asList(new Row(asList("John"))))); + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John"))))); when(otherDbConnection.select(anyString())) .thenThrow(new RuntimeException("Unsupported feature")); @@ -189,14 +198,14 @@ public void testSuccessWhenOneDBSupportThisQuery() { .thenReturn( new DBResult( "OpenSearch", - asList(new Type("firstname", "text")), - asList(new Row(asList("John"))))); + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John"))))); when(anotherDbConnection.select(anyString())) .thenReturn( new DBResult( "Another DB", - asList(new Type("firstname", "text")), - asList(new Row(asList("John"))))); + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John"))))); TestReport expected = new TestReport(); expected.addTestCase(new SuccessTestCase(1, "SELECT * FROM accounts")); @@ -214,9 +223,11 @@ public void testFailureDueToInconsistencyAndExceptionMixed() { DBResult openSearchResult = new DBResult( - "OpenSearch", asList(new Type("firstname", "text")), asList(new Row(asList("John")))); + "OpenSearch", + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John")))); DBResult otherResult = - new DBResult("Other", asList(new Type("firstname", "text")), Collections.emptyList()); + new DBResult("Other", List.of(new Type("firstname", "text")), Collections.emptyList()); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(otherDbConnection.select(anyString())).thenReturn(otherResult); diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/DBResultTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/DBResultTest.java index 793728a9e9..2415ff486b 100644 --- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/DBResultTest.java +++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/DBResultTest.java @@ -13,6 +13,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import java.util.Arrays; +import java.util.List; import org.junit.Test; import org.opensearch.sql.correctness.runner.resultset.DBResult; import org.opensearch.sql.correctness.runner.resultset.Row; @@ -23,18 +24,15 @@ public class DBResultTest { @Test public void dbResultFromDifferentDbNameShouldEqual() { - DBResult result1 = - new DBResult("DB 1", Arrays.asList(new Type("name", "VARCHAR")), emptyList()); - DBResult result2 = - new DBResult("DB 2", Arrays.asList(new Type("name", "VARCHAR")), emptyList()); + DBResult result1 = new DBResult("DB 1", List.of(new Type("name", "VARCHAR")), emptyList()); + DBResult result2 = new DBResult("DB 2", List.of(new Type("name", "VARCHAR")), emptyList()); assertEquals(result1, result2); } @Test public void dbResultWithDifferentColumnShouldNotEqual() { - DBResult result1 = - new DBResult("DB 1", Arrays.asList(new Type("name", "VARCHAR")), emptyList()); - DBResult result2 = new DBResult("DB 2", Arrays.asList(new Type("age", "INT")), emptyList()); + DBResult result1 = new DBResult("DB 1", List.of(new Type("name", "VARCHAR")), emptyList()); + DBResult result2 = new DBResult("DB 2", List.of(new Type("age", "INT")), emptyList()); assertNotEquals(result1, result2); } @@ -70,8 +68,8 @@ public void dbResultInOrderWithSameRowsInDifferentOrderShouldNotEqual() { @Test public void dbResultWithDifferentColumnTypeShouldNotEqual() { - DBResult result1 = new DBResult("DB 1", Arrays.asList(new Type("age", "FLOAT")), emptyList()); - DBResult result2 = new DBResult("DB 2", Arrays.asList(new Type("age", "INT")), emptyList()); + DBResult result1 = new DBResult("DB 1", List.of(new Type("age", "FLOAT")), emptyList()); + DBResult result2 = new DBResult("DB 2", List.of(new Type("age", "INT")), emptyList()); assertNotEquals(result1, result2); } @@ -99,19 +97,19 @@ public void shouldExplainDataRowsDifference() { DBResult result1 = new DBResult( "DB 1", - Arrays.asList(new Type("name", "VARCHAR")), + List.of(new Type("name", "VARCHAR")), Sets.newHashSet( - new Row(Arrays.asList("hello")), - new Row(Arrays.asList("world")), + new Row(List.of("hello")), + new Row(List.of("world")), new Row(Lists.newArrayList((Object) null)))); DBResult result2 = new DBResult( "DB 2", - Arrays.asList(new Type("name", "VARCHAR")), + List.of(new Type("name", "VARCHAR")), Sets.newHashSet( new Row(Lists.newArrayList((Object) null)), - new Row(Arrays.asList("hello")), - new Row(Arrays.asList("world123")))); + new Row(List.of("hello")), + new Row(List.of("world123")))); assertEquals( "Data row at [1] is different: this=[Row(values=[world])], other=[Row(values=[world123])]", diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestReportTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestReportTest.java index 9ac5151b21..2c663be52d 100644 --- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestReportTest.java +++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestReportTest.java @@ -9,6 +9,7 @@ import static java.util.Collections.singleton; import static org.junit.Assert.fail; +import java.util.List; import org.json.JSONObject; import org.junit.Test; import org.opensearch.sql.correctness.report.ErrorTestCase; @@ -60,11 +61,11 @@ public void testFailedReport() { new DBResult( "OpenSearch", singleton(new Type("firstName", "text")), - singleton(new Row(asList("hello")))), + singleton(new Row(List.of("hello")))), new DBResult( "H2", singleton(new Type("firstName", "text")), - singleton(new Row(asList("world"))))), + singleton(new Row(List.of("world"))))), "[SQLITE_ERROR] SQL error or missing database;")); JSONObject actual = new JSONObject(report); JSONObject expected = diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/PrettyFormatResponseIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/PrettyFormatResponseIT.java index 07883d92f4..73ed6e359c 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/PrettyFormatResponseIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/PrettyFormatResponseIT.java @@ -335,7 +335,7 @@ public void aggregationFunctionInSelect() throws IOException { "SELECT COUNT(*) FROM %s GROUP BY age", TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = Arrays.asList("COUNT(*)"); + List fields = List.of("COUNT(*)"); assertContainsColumns(getSchema(response), fields); JSONArray dataRows = getDataRows(response); @@ -357,7 +357,7 @@ public void aggregationFunctionInSelectCaseCheck() throws IOException { "SELECT count(*) FROM %s GROUP BY age", TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = Arrays.asList("COUNT(*)"); + List fields = List.of("COUNT(*)"); assertContainsColumns(getSchema(response), fields); JSONArray dataRows = getDataRows(response); @@ -378,7 +378,7 @@ public void aggregationFunctionInSelectWithAlias() throws IOException { "SELECT COUNT(*) AS total FROM %s GROUP BY age", TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = Arrays.asList("total"); + List fields = List.of("total"); assertContainsColumns(getSchema(response), fields); JSONArray dataRows = getDataRows(response); diff --git a/integ-test/src/test/java/org/opensearch/sql/util/MatcherUtils.java b/integ-test/src/test/java/org/opensearch/sql/util/MatcherUtils.java index d4db502407..ffbc1ed7a7 100644 --- a/integ-test/src/test/java/org/opensearch/sql/util/MatcherUtils.java +++ b/integ-test/src/test/java/org/opensearch/sql/util/MatcherUtils.java @@ -296,7 +296,7 @@ protected boolean matchesSafely(JSONArray item) { @Override public void describeTo(Description description) { - description.appendText(String.join(",", Arrays.asList().toString())); + description.appendText(String.join(",", List.of().toString())); } private boolean valuesAreClose(Number v1, Number v2) { diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/expression/core/builder/UnaryExpressionBuilder.java b/legacy/src/main/java/org/opensearch/sql/legacy/expression/core/builder/UnaryExpressionBuilder.java index 3d40c3a527..f66e744923 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/expression/core/builder/UnaryExpressionBuilder.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/expression/core/builder/UnaryExpressionBuilder.java @@ -5,7 +5,7 @@ package org.opensearch.sql.legacy.expression.core.builder; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import lombok.RequiredArgsConstructor; import org.opensearch.sql.legacy.expression.core.Expression; @@ -31,7 +31,7 @@ public Expression build(List expressionList) { return new Expression() { @Override public ExprValue valueOf(BindingTuple tuple) { - return op.apply(Arrays.asList(expression.valueOf(tuple))); + return op.apply(Collections.singletonList(expression.valueOf(tuple))); } @Override diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/types/TypeExpressionTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/types/TypeExpressionTest.java index 55c184bcaa..41b6cb5790 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/types/TypeExpressionTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/types/TypeExpressionTest.java @@ -18,6 +18,7 @@ import static org.opensearch.sql.legacy.antlr.semantic.types.special.Generic.T; import java.util.Arrays; +import java.util.List; import org.junit.Test; /** Test cases for default implementation methods in interface TypeExpression */ @@ -54,20 +55,20 @@ public String getName() { return "Temp type expression with empty specification"; } }; - assertEquals(UNKNOWN, expr.construct(Arrays.asList(NUMBER))); + assertEquals(UNKNOWN, expr.construct(List.of(NUMBER))); assertEquals(UNKNOWN, expr.construct(Arrays.asList(STRING, BOOLEAN))); assertEquals(UNKNOWN, expr.construct(Arrays.asList(INTEGER, DOUBLE, GEO_POINT))); } @Test public void compatibilityCheckShouldPassIfAnySpecificationCompatible() { - assertEquals(DOUBLE, test123.construct(Arrays.asList(DOUBLE))); + assertEquals(DOUBLE, test123.construct(List.of(DOUBLE))); assertEquals(DATE, test123.construct(Arrays.asList(STRING, BOOLEAN))); } @Test public void compatibilityCheckShouldFailIfNoSpecificationCompatible() { - assertEquals(TYPE_ERROR, test123.construct(Arrays.asList(BOOLEAN))); + assertEquals(TYPE_ERROR, test123.construct(List.of(BOOLEAN))); } @Test diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/executor/format/BindingTupleResultSetTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/executor/format/BindingTupleResultSetTest.java index fa385fa14b..96210c7d8a 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/executor/format/BindingTupleResultSetTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/executor/format/BindingTupleResultSetTest.java @@ -14,6 +14,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import org.hamcrest.Matcher; @@ -69,7 +70,7 @@ public void buildDataRowsFromBindingTupleIncludeDateShouldPass() { Arrays.asList( ColumnNode.builder().alias("dateValue").type(Schema.Type.DATE).build(), ColumnNode.builder().alias("gender").type(Schema.Type.TEXT).build()), - Arrays.asList( + Collections.singletonList( BindingTuple.from(ImmutableMap.of("dateValue", 1529712000000L, "gender", "m")))), containsInAnyOrder( rowContents( diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/utils/SQLFunctionsTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/utils/SQLFunctionsTest.java index 9fc2b6012d..cd5d6fd82b 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/utils/SQLFunctionsTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/utils/SQLFunctionsTest.java @@ -16,7 +16,6 @@ import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr; import com.google.common.collect.ImmutableList; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.junit.Assert; import org.junit.Rule; @@ -92,6 +91,6 @@ public void testCastIntStatementScript() throws SqlParseException { "def result = (doc['age'].value instanceof boolean) " + "? (doc['age'].value ? 1 : 0) " + ": Double.parseDouble(doc['age'].value.toString()).intValue()", - sqlFunctions.getCastScriptStatement("result", "int", Arrays.asList(new KVValue("age")))); + sqlFunctions.getCastScriptStatement("result", "int", List.of(new KVValue("age")))); } } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/request/system/OpenSearchCatIndicesRequestTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/request/system/OpenSearchCatIndicesRequestTest.java index 8f954b68b2..83bfbd5cd6 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/request/system/OpenSearchCatIndicesRequestTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/request/system/OpenSearchCatIndicesRequestTest.java @@ -12,7 +12,6 @@ import static org.mockito.Mockito.when; import static org.opensearch.sql.data.model.ExprValueUtils.stringValue; -import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -28,7 +27,7 @@ class OpenSearchCatIndicesRequestTest { @Test void testSearch() { - when(client.indices()).thenReturn(Arrays.asList("index")); + when(client.indices()).thenReturn(List.of("index")); final List results = new OpenSearchCatIndicesRequest(client).search(); assertEquals(1, results.size()); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java index 1bb988dacd..4c030ae001 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java @@ -97,9 +97,8 @@ void should_build_composite_aggregation_for_field_reference() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named("avg(age)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER))), - Arrays.asList(named("name", ref("name", STRING))))); + List.of(named("avg(age)", new AvgAggregator(List.of(ref("age", INTEGER)), INTEGER))), + List.of(named("name", ref("name", STRING))))); } @Test @@ -131,9 +130,8 @@ void should_build_composite_aggregation_for_field_reference_with_order() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named("avg(age)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER))), - Arrays.asList(named("name", ref("name", STRING))), + List.of(named("avg(age)", new AvgAggregator(List.of(ref("age", INTEGER)), INTEGER))), + List.of(named("name", ref("name", STRING))), sort(ref("name", STRING), Sort.SortOption.DEFAULT_DESC))); } @@ -141,9 +139,8 @@ void should_build_composite_aggregation_for_field_reference_with_order() { void should_build_type_mapping_for_field_reference() { assertThat( buildTypeMapping( - Arrays.asList( - named("avg(age)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER))), - Arrays.asList(named("name", ref("name", STRING)))), + List.of(named("avg(age)", new AvgAggregator(List.of(ref("age", INTEGER)), INTEGER))), + List.of(named("name", ref("name", STRING)))), containsInAnyOrder( map("avg(age)", OpenSearchDataType.of(INTEGER)), map("name", OpenSearchDataType.of(STRING)))); @@ -153,11 +150,11 @@ void should_build_type_mapping_for_field_reference() { void should_build_type_mapping_for_timestamp_type() { assertThat( buildTypeMapping( - Arrays.asList( + List.of( named( "avg(timestamp)", - new AvgAggregator(Arrays.asList(ref("timestamp", TIMESTAMP)), TIMESTAMP))), - Arrays.asList(named("timestamp", ref("timestamp", TIMESTAMP)))), + new AvgAggregator(List.of(ref("timestamp", TIMESTAMP)), TIMESTAMP))), + List.of(named("timestamp", ref("timestamp", TIMESTAMP)))), containsInAnyOrder( map("avg(timestamp)", OpenSearchDateType.of()), map("timestamp", OpenSearchDateType.of()))); @@ -167,9 +164,8 @@ void should_build_type_mapping_for_timestamp_type() { void should_build_type_mapping_for_date_type() { assertThat( buildTypeMapping( - Arrays.asList( - named("avg(date)", new AvgAggregator(Arrays.asList(ref("date", DATE)), DATE))), - Arrays.asList(named("date", ref("date", DATE)))), + List.of(named("avg(date)", new AvgAggregator(List.of(ref("date", DATE)), DATE))), + List.of(named("date", ref("date", DATE)))), containsInAnyOrder( map("avg(date)", OpenSearchDateType.of(DATE)), map("date", OpenSearchDateType.of(DATE)))); @@ -179,9 +175,8 @@ void should_build_type_mapping_for_date_type() { void should_build_type_mapping_for_time_type() { assertThat( buildTypeMapping( - Arrays.asList( - named("avg(time)", new AvgAggregator(Arrays.asList(ref("time", TIME)), TIME))), - Arrays.asList(named("time", ref("time", TIME)))), + List.of(named("avg(time)", new AvgAggregator(List.of(ref("time", TIME)), TIME))), + List.of(named("time", ref("time", TIME)))), containsInAnyOrder( map("avg(time)", OpenSearchDateType.of(TIME)), map("time", OpenSearchDateType.of(TIME)))); @@ -216,9 +211,8 @@ void should_build_composite_aggregation_for_field_reference_of_keyword() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named("avg(age)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER))), - Arrays.asList( + List.of(named("avg(age)", new AvgAggregator(List.of(ref("age", INTEGER)), INTEGER))), + List.of( named( "name", ref( @@ -234,9 +228,8 @@ void should_build_composite_aggregation_for_field_reference_of_keyword() { void should_build_type_mapping_for_field_reference_of_keyword() { assertThat( buildTypeMapping( - Arrays.asList( - named("avg(age)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER))), - Arrays.asList(named("name", ref("name", STRING)))), + List.of(named("avg(age)", new AvgAggregator(List.of(ref("age", INTEGER)), INTEGER))), + List.of(named("name", ref("name", STRING)))), containsInAnyOrder( map("avg(age)", OpenSearchDataType.of(INTEGER)), map("name", OpenSearchDataType.of(STRING)))); @@ -284,11 +277,12 @@ void should_build_composite_aggregation_for_expression() { + " }%n" + "}"), buildQuery( - Arrays.asList( + List.of( named( "avg(balance)", - new AvgAggregator(Arrays.asList(DSL.abs(ref("balance", INTEGER))), INTEGER))), - Arrays.asList(named("age", DSL.asin(ref("age", INTEGER)))))); + new AvgAggregator( + Collections.singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), + List.of(named("age", DSL.asin(ref("age", INTEGER)))))); } @Test @@ -342,11 +336,12 @@ void should_build_composite_aggregation_follow_with_order_by_position() { void should_build_type_mapping_for_expression() { assertThat( buildTypeMapping( - Arrays.asList( + List.of( named( "avg(balance)", - new AvgAggregator(Arrays.asList(DSL.abs(ref("balance", INTEGER))), INTEGER))), - Arrays.asList(named("age", DSL.asin(ref("age", INTEGER))))), + new AvgAggregator( + Collections.singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), + List.of(named("age", DSL.asin(ref("age", INTEGER))))), containsInAnyOrder( map("avg(balance)", OpenSearchDataType.of(INTEGER)), map("age", OpenSearchDataType.of(DOUBLE)))); @@ -364,10 +359,9 @@ void should_build_aggregation_without_bucket() { + " }%n" + "}"), buildQuery( - Arrays.asList( + List.of( named( - "avg(balance)", - new AvgAggregator(Arrays.asList(ref("balance", INTEGER)), INTEGER))), + "avg(balance)", new AvgAggregator(List.of(ref("balance", INTEGER)), INTEGER))), Collections.emptyList())); } @@ -398,10 +392,10 @@ void should_build_filter_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( + List.of( named( "avg(age) filter(where age > 34)", - new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER) + new AvgAggregator(List.of(ref("age", INTEGER)), INTEGER) .condition(DSL.greater(ref("age", INTEGER), literal(20))))), Collections.emptyList())); } @@ -450,22 +444,21 @@ void should_build_filter_aggregation_group_by() { + " }%n" + "}"), buildQuery( - Arrays.asList( + List.of( named( "avg(age) filter(where age > 34)", - new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER) + new AvgAggregator(List.of(ref("age", INTEGER)), INTEGER) .condition(DSL.greater(ref("age", INTEGER), literal(20))))), - Arrays.asList(named(ref("gender", OpenSearchDataType.of(STRING)))))); + List.of(named(ref("gender", OpenSearchDataType.of(STRING)))))); } @Test void should_build_type_mapping_without_bucket() { assertThat( buildTypeMapping( - Arrays.asList( + List.of( named( - "avg(balance)", - new AvgAggregator(Arrays.asList(ref("balance", INTEGER)), INTEGER))), + "avg(balance)", new AvgAggregator(List.of(ref("balance", INTEGER)), INTEGER))), Collections.emptyList()), containsInAnyOrder(map("avg(balance)", OpenSearchDataType.of(INTEGER)))); } @@ -500,9 +493,8 @@ void should_build_histogram() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named("count(a)", new CountAggregator(Arrays.asList(ref("a", INTEGER)), INTEGER))), - Arrays.asList(named(span(ref("age", INTEGER), literal(10), ""))))); + List.of(named("count(a)", new CountAggregator(List.of(ref("a", INTEGER)), INTEGER))), + List.of(named(span(ref("age", INTEGER), literal(10), ""))))); } @Test @@ -541,9 +533,9 @@ void should_build_histogram_two_metrics() { + "}"), buildQuery( Arrays.asList( - named("count(a)", new CountAggregator(Arrays.asList(ref("a", INTEGER)), INTEGER)), - named("avg(b)", new AvgAggregator(Arrays.asList(ref("b", INTEGER)), INTEGER))), - Arrays.asList(named(span(ref("age", INTEGER), literal(10), ""))))); + named("count(a)", new CountAggregator(List.of(ref("a", INTEGER)), INTEGER)), + named("avg(b)", new AvgAggregator(List.of(ref("b", INTEGER)), INTEGER))), + List.of(named(span(ref("age", INTEGER), literal(10), ""))))); } @Test @@ -576,9 +568,8 @@ void fixed_interval_time_span() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named("count(a)", new CountAggregator(Arrays.asList(ref("a", INTEGER)), INTEGER))), - Arrays.asList(named(span(ref("timestamp", TIMESTAMP), literal(1), "h"))))); + List.of(named("count(a)", new CountAggregator(List.of(ref("a", INTEGER)), INTEGER))), + List.of(named(span(ref("timestamp", TIMESTAMP), literal(1), "h"))))); } @Test @@ -611,9 +602,8 @@ void calendar_interval_time_span() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named("count(a)", new CountAggregator(Arrays.asList(ref("a", INTEGER)), INTEGER))), - Arrays.asList(named(span(ref("date", DATE), literal(1), "w"))))); + List.of(named("count(a)", new CountAggregator(List.of(ref("a", INTEGER)), INTEGER))), + List.of(named(span(ref("date", DATE), literal(1), "w"))))); } @Test @@ -646,9 +636,8 @@ void general_span() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named("count(a)", new CountAggregator(Arrays.asList(ref("a", INTEGER)), INTEGER))), - Arrays.asList(named(span(ref("age", INTEGER), literal(1), ""))))); + List.of(named("count(a)", new CountAggregator(List.of(ref("a", INTEGER)), INTEGER))), + List.of(named(span(ref("age", INTEGER), literal(1), ""))))); } @Test @@ -657,11 +646,9 @@ void invalid_unit() { IllegalStateException.class, () -> buildQuery( - Arrays.asList( - named( - "count(a)", - new CountAggregator(Arrays.asList(ref("a", INTEGER)), INTEGER))), - Arrays.asList(named(span(ref("age", INTEGER), literal(1), "invalid_unit"))))); + List.of( + named("count(a)", new CountAggregator(List.of(ref("a", INTEGER)), INTEGER))), + List.of(named(span(ref("age", INTEGER), literal(1), "invalid_unit"))))); } @SneakyThrows diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java index 08c4017f1d..b4c747e30e 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java @@ -14,7 +14,6 @@ import static org.opensearch.sql.expression.DSL.named; import static org.opensearch.sql.expression.DSL.ref; -import java.util.Arrays; import java.util.List; import java.util.Map; import lombok.SneakyThrows; @@ -68,7 +67,7 @@ void should_build_bucket_with_field() { + " \"order\" : \"asc\"\n" + " }\n" + "}", - buildQuery(Arrays.asList(asc(named("age", ref("age", INTEGER)))))); + buildQuery(List.of(asc(named("age", ref("age", INTEGER)))))); } @Test @@ -87,7 +86,7 @@ void should_build_bucket_with_literal() { + " \"order\" : \"asc\"\n" + " }\n" + "}", - buildQuery(Arrays.asList(asc(named(literal))))); + buildQuery(List.of(asc(named(literal))))); } @Test @@ -102,7 +101,7 @@ void should_build_bucket_with_keyword_field() { + " }\n" + "}", buildQuery( - Arrays.asList( + List.of( asc( named( "name", @@ -132,7 +131,7 @@ void should_build_bucket_with_parse_expression() { + " \"order\" : \"asc\"\n" + " }\n" + "}", - buildQuery(Arrays.asList(asc(named("name", parseExpression))))); + buildQuery(List.of(asc(named("name", parseExpression))))); } @Test @@ -149,7 +148,7 @@ void terms_bucket_for_opensearchdate_type_uses_long() { + " \"order\" : \"asc\"\n" + " }\n" + "}", - buildQuery(Arrays.asList(asc(named("date", ref("date", dataType)))))); + buildQuery(List.of(asc(named("date", ref("date", dataType)))))); } @Test @@ -165,7 +164,7 @@ void terms_bucket_for_opensearchdate_type_uses_long_false() { + " \"order\" : \"asc\"\n" + " }\n" + "}", - buildQuery(Arrays.asList(asc(named("date", ref("date", dataType)))))); + buildQuery(List.of(asc(named("date", ref("date", dataType)))))); } @ParameterizedTest(name = "{0}") @@ -183,7 +182,7 @@ void terms_bucket_for_datetime_types_uses_long(ExprType dataType) { + " \"order\" : \"asc\"\n" + " }\n" + "}", - buildQuery(Arrays.asList(asc(named("date", ref("date", dataType)))))); + buildQuery(List.of(asc(named("date", ref("date", dataType)))))); } @SneakyThrows diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java index 6d792dec25..c3c24facb2 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java @@ -73,9 +73,7 @@ void should_build_avg_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named( - "avg(age)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER))))); + List.of(named("avg(age)", new AvgAggregator(List.of(ref("age", INTEGER)), INTEGER))))); } @Test @@ -90,9 +88,7 @@ void should_build_sum_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named( - "sum(age)", new SumAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER))))); + List.of(named("sum(age)", new SumAggregator(List.of(ref("age", INTEGER)), INTEGER))))); } @Test @@ -107,10 +103,8 @@ void should_build_count_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named( - "count(age)", - new CountAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER))))); + List.of( + named("count(age)", new CountAggregator(List.of(ref("age", INTEGER)), INTEGER))))); } @Test @@ -125,8 +119,7 @@ void should_build_count_star_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named("count(*)", new CountAggregator(Arrays.asList(literal("*")), INTEGER))))); + List.of(named("count(*)", new CountAggregator(List.of(literal("*")), INTEGER))))); } @Test @@ -140,9 +133,7 @@ void should_build_count_other_literal_aggregation() { + " }%n" + " }%n" + "}"), - buildQuery( - Arrays.asList( - named("count(1)", new CountAggregator(Arrays.asList(literal(1)), INTEGER))))); + buildQuery(List.of(named("count(1)", new CountAggregator(List.of(literal(1)), INTEGER))))); } @Test @@ -157,9 +148,7 @@ void should_build_min_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named( - "min(age)", new MinAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER))))); + List.of(named("min(age)", new MinAggregator(List.of(ref("age", INTEGER)), INTEGER))))); } @Test @@ -174,9 +163,7 @@ void should_build_max_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named( - "max(age)", new MaxAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER))))); + List.of(named("max(age)", new MaxAggregator(List.of(ref("age", INTEGER)), INTEGER))))); } @Test @@ -192,10 +179,8 @@ void should_build_varPop_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named( - "var_pop(age)", - variancePopulation(Arrays.asList(ref("age", INTEGER)), INTEGER))))); + List.of( + named("var_pop(age)", variancePopulation(List.of(ref("age", INTEGER)), INTEGER))))); } @Test @@ -211,10 +196,8 @@ void should_build_varSamp_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named( - "var_samp(age)", - varianceSample(Arrays.asList(ref("age", INTEGER)), INTEGER))))); + List.of( + named("var_samp(age)", varianceSample(List.of(ref("age", INTEGER)), INTEGER))))); } @Test @@ -234,7 +217,7 @@ void should_build_percentile_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( + List.of( named( "percentile(age, 50)", new PercentileApproximateAggregator( @@ -258,7 +241,7 @@ void should_build_percentile_with_compression_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( + List.of( named( "percentile(age, 50)", new PercentileApproximateAggregator( @@ -297,7 +280,7 @@ void should_build_filtered_percentile_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( + List.of( named( "percentile(age, 50)", new PercentileApproximateAggregator( @@ -318,10 +301,9 @@ void should_build_stddevPop_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( + List.of( named( - "stddev_pop(age)", - stddevPopulation(Arrays.asList(ref("age", INTEGER)), INTEGER))))); + "stddev_pop(age)", stddevPopulation(List.of(ref("age", INTEGER)), INTEGER))))); } @Test @@ -337,10 +319,8 @@ void should_build_stddevSamp_aggregation() { + " }%n" + "}"), buildQuery( - Arrays.asList( - named( - "stddev_samp(age)", - stddevSample(Arrays.asList(ref("age", INTEGER)), INTEGER))))); + List.of( + named("stddev_samp(age)", stddevSample(List.of(ref("age", INTEGER)), INTEGER))))); } @Test @@ -483,12 +463,12 @@ void should_throw_exception_for_unsupported_distinct_aggregator() { @Test void should_throw_exception_for_unsupported_aggregator() { when(aggregator.getFunctionName()).thenReturn(new FunctionName("unsupported_agg")); - when(aggregator.getArguments()).thenReturn(Arrays.asList(ref("age", INTEGER))); + when(aggregator.getArguments()).thenReturn(List.of(ref("age", INTEGER))); IllegalStateException exception = assertThrows( IllegalStateException.class, - () -> buildQuery(Arrays.asList(named("unsupported_agg(age)", aggregator)))); + () -> buildQuery(List.of(named("unsupported_agg(age)", aggregator)))); assertEquals("unsupported aggregator unsupported_agg", exception.getMessage()); } @@ -499,11 +479,11 @@ void should_throw_exception_for_unsupported_exception() { IllegalStateException.class, () -> buildQuery( - Arrays.asList( + List.of( named( "count(age)", new CountAggregator( - Arrays.asList(named("age", ref("age", INTEGER))), INTEGER))))); + List.of(named("age", ref("age", INTEGER))), INTEGER))))); assertEquals("metric aggregation doesn't support expression age", exception.getMessage()); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/utils/Utils.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/utils/Utils.java index 0db87f89d4..b9e269d9ac 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/utils/Utils.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/utils/Utils.java @@ -24,7 +24,7 @@ public class Utils { public static AvgAggregator avg(Expression expr, ExprCoreType type) { - return new AvgAggregator(Arrays.asList(expr), type); + return new AvgAggregator(Collections.singletonList(expr), type); } public static List agg(NamedAggregator... exprs) { diff --git a/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java b/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java index aec22ac231..a6f83c22c8 100644 --- a/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java +++ b/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java @@ -237,7 +237,7 @@ public UnresolvedExpression visitTableSource(TableSourceContext ctx) { if (ctx.getChild(0) instanceof IdentsAsTableQualifiedNameContext) { return visitIdentsAsTableQualifiedName((IdentsAsTableQualifiedNameContext) ctx.getChild(0)); } else { - return visitIdentifiers(Arrays.asList(ctx)); + return visitIdentifiers(List.of(ctx)); } } diff --git a/ppl/src/test/java/org/opensearch/sql/ppl/utils/UnresolvedPlanHelperTest.java b/ppl/src/test/java/org/opensearch/sql/ppl/utils/UnresolvedPlanHelperTest.java index 7c1264e0b6..43feabfd5f 100644 --- a/ppl/src/test/java/org/opensearch/sql/ppl/utils/UnresolvedPlanHelperTest.java +++ b/ppl/src/test/java/org/opensearch/sql/ppl/utils/UnresolvedPlanHelperTest.java @@ -8,7 +8,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; -import java.util.Arrays; +import java.util.Collections; import junit.framework.TestCase; import org.hamcrest.Matchers; import org.junit.Test; @@ -47,7 +47,7 @@ public void dontAddProjectForProjectOperator() { Project project = Mockito.mock(Project.class); UnresolvedExpression expression = Mockito.mock(UnresolvedExpression.class); when(project.isExcluded()).thenReturn(false); - when(project.getProjectList()).thenReturn(Arrays.asList(expression)); + when(project.getProjectList()).thenReturn(Collections.singletonList(expression)); UnresolvedPlan plan = UnresolvedPlanHelper.addSelectAll(project); assertTrue(plan instanceof Project); diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java index ef2f2e8da8..971169f102 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Arrays; +import java.util.List; import org.junit.jupiter.api.Test; import org.opensearch.sql.data.model.ExprTupleValue; import org.opensearch.sql.executor.ExecutionEngine; @@ -57,7 +58,7 @@ void sanitizeHeaders() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue( ImmutableMap.of( "=firstname", diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java index ebdadcd50b..f9915a5317 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Arrays; +import java.util.List; import org.junit.jupiter.api.Test; import org.opensearch.sql.data.model.ExprTupleValue; import org.opensearch.sql.executor.ExecutionEngine; @@ -57,7 +58,7 @@ void sanitizeHeaders() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue( ImmutableMap.of( "=firstname", diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java index e5eb0f1ac7..a88f93bd2d 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java @@ -17,6 +17,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Arrays; +import java.util.List; import org.junit.jupiter.api.Test; import org.opensearch.sql.data.model.ExprTupleValue; import org.opensearch.sql.executor.ExecutionEngine; @@ -120,7 +121,7 @@ void formatResponseWithTupleValue() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue( ImmutableMap.of( "name", @@ -143,7 +144,7 @@ void formatResponseWithArrayValue() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue( ImmutableMap.of( "name", diff --git a/sql/src/main/java/org/opensearch/sql/sql/parser/AstExpressionBuilder.java b/sql/src/main/java/org/opensearch/sql/sql/parser/AstExpressionBuilder.java index d1c0be98b2..5bdbfb4e38 100644 --- a/sql/src/main/java/org/opensearch/sql/sql/parser/AstExpressionBuilder.java +++ b/sql/src/main/java/org/opensearch/sql/sql/parser/AstExpressionBuilder.java @@ -252,7 +252,7 @@ public UnresolvedExpression visitIsNullPredicate(IsNullPredicateContext ctx) { ctx.nullNotnull().NOT() == null ? IS_NULL.getName().getFunctionName() : IS_NOT_NULL.getName().getFunctionName(), - Arrays.asList(visit(ctx.predicate()))); + Collections.singletonList(visit(ctx.predicate()))); } @Override