From 0011927becca5dbd39d6bb65664f14927bc20d14 Mon Sep 17 00:00:00 2001 From: currantw Date: Thu, 5 Dec 2024 13:12:49 -0800 Subject: [PATCH 01/16] 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 52c829318ab..0bcdc3a9243 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 9511359f86a..84b3c33fd62 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 ef8f1428018..84c2bd427a1 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 4c2a485ea77..ca9ad795b86 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 38c1b91b43c..781b73fca76 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 423cb088efe..ad9c032f2e8 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 2c6eee46e9c..59ebc1d8392 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 ec5264a86b7..9d22b42e75d 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 58d6ee346ba..2732854a14e 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 92734440f75..82a48fa87c2 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 38d4704bcd2..461e1f83583 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 775984a528a..ae82a7d2056 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 9fe63471028..3d304ffb114 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 @@ -126,7 +126,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 237477050dc..ae345fa9890 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 8e71fc2bec8..9db1eaf5659 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 5cab5b31752..793d9aa03bc 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 793728a9e90..2415ff486b1 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 43f678f60ed..5ce7e3d4d87 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 07883d92f4c..73ed6e359c1 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 d4db502407a..ffbc1ed7a7c 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 3d40c3a527f..f66e744923b 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 55c184bcaaf..41b6cb57907 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 fa385fa14b1..96210c7d8ac 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 983f10023ee..2f3e34d43aa 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 8f954b68b2a..83bfbd5cd65 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 1bb988dacd7..4c030ae0014 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 08c4017f1d0..b4c747e30e0 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 6d792dec251..c3c24facb29 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 0db87f89d47..b9e269d9ace 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 98c41027ffa..875884b69ce 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 7c1264e0b63..43feabfd5f7 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 ef2f2e8da8e..971169f1027 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 ebdadcd50b5..f9915a5317f 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 e5eb0f1ac77..a88f93bd2d0 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 d1c0be98b2a..5bdbfb4e381 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 From 9dfc2c5e233b0759604d2f82d0e0184df0d28916 Mon Sep 17 00:00:00 2001 From: currantw Date: Fri, 6 Dec 2024 09:07:36 -0800 Subject: [PATCH 02/16] Use static imports for `Collections.singletonList` Signed-off-by: currantw --- .../cluster/ClusterManagerEventListener.java | 4 +- .../BasicAuthenticationInterceptorTest.java | 5 +- .../sql/analysis/ExpressionAnalyzer.java | 6 +- .../analysis/SelectExpressionAnalyzer.java | 7 +- .../sql/ast/expression/AggregateFunction.java | 10 +- .../sql/ast/expression/Argument.java | 5 +- .../opensearch/sql/ast/expression/Cast.java | 4 +- .../org/opensearch/sql/ast/expression/In.java | 5 +- .../sql/ast/expression/Interval.java | 5 +- .../opensearch/sql/ast/expression/Not.java | 5 +- .../sql/ast/expression/QualifiedName.java | 4 +- .../ast/expression/UnresolvedArgument.java | 5 +- .../org/opensearch/sql/ast/tree/RareTopN.java | 5 +- .../org/opensearch/sql/ast/tree/Relation.java | 5 +- .../aggregation/AggregatorFunctions.java | 61 +++++---- .../sql/expression/function/FunctionDSL.java | 11 +- .../sql/expression/text/TextFunctions.java | 4 +- .../sql/planner/logical/LogicalAD.java | 5 +- .../planner/logical/LogicalAggregation.java | 5 +- .../sql/planner/logical/LogicalDedupe.java | 5 +- .../sql/planner/logical/LogicalEval.java | 5 +- .../sql/planner/logical/LogicalFilter.java | 5 +- .../sql/planner/logical/LogicalHighlight.java | 5 +- .../sql/planner/logical/LogicalLimit.java | 5 +- .../sql/planner/logical/LogicalML.java | 5 +- .../sql/planner/logical/LogicalMLCommons.java | 5 +- .../sql/planner/logical/LogicalNested.java | 5 +- .../sql/planner/logical/LogicalProject.java | 5 +- .../sql/planner/logical/LogicalRareTopN.java | 5 +- .../sql/planner/logical/LogicalRemove.java | 5 +- .../sql/planner/logical/LogicalRename.java | 5 +- .../sql/planner/logical/LogicalSort.java | 5 +- .../sql/planner/logical/LogicalWindow.java | 5 +- .../sql/planner/logical/LogicalWrite.java | 5 +- .../planner/physical/AggregationOperator.java | 5 +- .../sql/planner/physical/DedupeOperator.java | 5 +- .../sql/planner/physical/EvalOperator.java | 4 +- .../sql/planner/physical/FilterOperator.java | 5 +- .../sql/planner/physical/NestedOperator.java | 4 +- .../sql/planner/physical/ProjectOperator.java | 5 +- .../planner/physical/RareTopNOperator.java | 5 +- .../sql/planner/physical/RemoveOperator.java | 4 +- .../sql/planner/physical/RenameOperator.java | 4 +- .../sql/planner/physical/SortOperator.java | 5 +- .../planner/physical/TakeOrderedOperator.java | 5 +- .../sql/planner/physical/WindowOperator.java | 5 +- .../physical/collector/MetricCollector.java | 5 +- .../assigner/TumblingWindowAssigner.java | 5 +- .../sql/storage/write/TableWriteBuilder.java | 5 +- .../sql/storage/write/TableWriteOperator.java | 5 +- .../opensearch/sql/analysis/AnalyzerTest.java | 10 +- .../sql/analysis/AnalyzerTestBase.java | 4 +- .../SelectExpressionAnalyzerTest.java | 6 +- .../expression/ExpressionNodeVisitorTest.java | 4 +- .../BuiltinFunctionRepositoryTest.java | 25 ++-- .../sql/planner/DefaultImplementorTest.java | 7 +- .../physical/AggregationOperatorTest.java | 124 +++++++++--------- .../physical/RareTopNOperatorTest.java | 23 ++-- .../planner/physical/RenameOperatorTest.java | 7 +- .../assigner/TumblingWindowAssignerTest.java | 8 +- .../storage/write/TableWriteOperatorTest.java | 4 +- .../service/DataSourceServiceImplTest.java | 48 +++---- ...enSearchDataSourceMetadataStorageTest.java | 15 ++- .../utils/DatasourceValidationUtilsTest.java | 12 +- .../sql/legacy/PrettyFormatResponseIT.java | 12 +- .../executor/format/DeleteResultSet.java | 10 +- .../core/builder/UnaryExpressionBuilder.java | 5 +- .../planner/physical/ADOperator.java | 4 +- .../planner/physical/MLCommonsOperator.java | 4 +- .../planner/physical/MLOperator.java | 5 +- .../agg/NoBucketAggregationParser.java | 5 +- .../aggregation/AggregationQueryBuilder.java | 5 +- .../physical/MLCommonsOperatorTest.java | 4 +- .../planner/physical/MLOperatorTest.java | 4 +- .../request/OpenSearchRequestBuilderTest.java | 6 +- .../OpenSearchIndexScanOptimizationTest.java | 11 +- .../AggregationQueryBuilderTest.java | 15 +-- .../dsl/MetricAggregationBuilderTest.java | 18 +-- .../system/OpenSearchSystemIndexScanTest.java | 4 +- .../sql/opensearch/utils/Utils.java | 7 +- .../sql/ppl/utils/ArgumentFactory.java | 9 +- .../ppl/utils/UnresolvedPlanHelperTest.java | 4 +- .../client/PrometheusClientImplTest.java | 6 +- ...eryRangeFunctionTableScanOperatorTest.java | 14 +- .../PrometheusListMetricsRequestTest.java | 6 +- .../storage/PrometheusMetricScanTest.java | 4 +- .../storage/PrometheusStorageFactoryTest.java | 17 +-- .../system/PrometheusSystemTableScanTest.java | 4 +- .../protocol/response/QueryResultTest.java | 11 +- .../sql/spark/storage/SparkStorageEngine.java | 5 +- .../opensearch/sql/sql/parser/AstBuilder.java | 8 +- .../sql/sql/parser/AstExpressionBuilder.java | 5 +- 92 files changed, 419 insertions(+), 402 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 0bcdc3a9243..69be1a3fc78 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 @@ -5,12 +5,12 @@ package org.opensearch.sql.spark.cluster; +import static java.util.Collections.singletonList; import static org.opensearch.sql.spark.data.constants.SparkConstants.SPARK_REQUEST_BUFFER_INDEX_NAME; import com.google.common.annotations.VisibleForTesting; import java.time.Clock; import java.time.Duration; -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 Collections.singletonList(flintIndexRetentionCron); + return singletonList(flintIndexRetentionCron); } private String executorName() { 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 af93060fab3..165f9e63f72 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,7 +7,8 @@ package org.opensearch.sql.common.interceptors; -import java.util.Collections; +import static java.util.Collections.singletonList; + import lombok.SneakyThrows; import okhttp3.Credentials; import okhttp3.Interceptor; @@ -47,7 +48,7 @@ void testIntercept() { Mockito.verify(chain).proceed(requestArgumentCaptor.capture()); Request request = requestArgumentCaptor.getValue(); Assertions.assertEquals( - Collections.singletonList(Credentials.basic("testAdmin", "testPassword")), + 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 5a8d6fe976e..370dd881c77 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java @@ -5,6 +5,7 @@ package org.opensearch.sql.analysis; +import static java.util.Collections.singletonList; import static org.opensearch.sql.ast.dsl.AstDSL.and; import static org.opensearch.sql.ast.dsl.AstDSL.compare; @@ -13,7 +14,6 @@ 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; @@ -83,9 +83,7 @@ public Expression visitCast(Cast node, AnalysisContext context) { final Expression expression = node.getExpression().accept(this, context); return (Expression) repository.compile( - context.getFunctionProperties(), - node.convertFunctionName(), - Collections.singletonList(expression)); + context.getFunctionProperties(), node.convertFunctionName(), 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 5e46cfa629d..2abbb6d96f4 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java @@ -5,8 +5,9 @@ package org.opensearch.sql.analysis; +import static java.util.Collections.singletonList; + import com.google.common.collect.ImmutableList; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.regex.Pattern; @@ -54,7 +55,7 @@ public List analyze( @Override public List visitField(Field node, AnalysisContext context) { - return Collections.singletonList(DSL.named(node.accept(expressionAnalyzer, context))); + return singletonList(DSL.named(node.accept(expressionAnalyzer, context))); } @Override @@ -65,7 +66,7 @@ public List visitAlias(Alias node, AnalysisContext context) { } Expression expr = referenceIfSymbolDefined(node, context); - return Collections.singletonList( + return singletonList( DSL.named(unqualifiedNameIfFieldOnly(node, context), expr, node.getAlias())); } 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 5208e39623d..5335e3dfa2d 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,7 +5,9 @@ package org.opensearch.sql.ast.expression; -import java.util.Collections; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -42,7 +44,7 @@ public class AggregateFunction extends UnresolvedExpression { public AggregateFunction(String funcName, UnresolvedExpression field) { this.funcName = funcName; this.field = field; - this.argList = Collections.emptyList(); + this.argList = emptyList(); } /** @@ -55,13 +57,13 @@ public AggregateFunction(String funcName, UnresolvedExpression field) { public AggregateFunction(String funcName, UnresolvedExpression field, Boolean distinct) { this.funcName = funcName; this.field = field; - this.argList = Collections.emptyList(); + this.argList = emptyList(); this.distinct = distinct; } @Override public List getChild() { - return Collections.singletonList(field); + return singletonList(field); } @Override 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 ca9ad795b86..f187dcd1d98 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,8 @@ package org.opensearch.sql.ast.expression; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -25,7 +26,7 @@ public class Argument extends UnresolvedExpression { // private final DataType valueType; @Override public List getChild() { - return Collections.singletonList(value); + return singletonList(value); } @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 2019346fb52..b9221980283 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 @@ -5,6 +5,7 @@ package org.opensearch.sql.ast.expression; +import static java.util.Collections.singletonList; import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BOOLEAN; import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BYTE; import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_DATE; @@ -19,7 +20,6 @@ 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; @@ -99,7 +99,7 @@ public FunctionName convertFunctionName() { @Override public List getChild() { - return Collections.singletonList(expression); + return singletonList(expression); } @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 781b73fca76..78c958a93ed 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,8 @@ package org.opensearch.sql.ast.expression; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -28,7 +29,7 @@ public class In extends UnresolvedExpression { @Override public List getChild() { - return Collections.singletonList(field); + return singletonList(field); } @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 c26f829f486..82ff1b93cf6 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,7 +5,8 @@ package org.opensearch.sql.ast.expression; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -29,7 +30,7 @@ public Interval(UnresolvedExpression value, String unit) { @Override public List getChild() { - return Collections.singletonList(value); + return singletonList(value); } @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 ad9c032f2e8..1dcb59c4b83 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,8 @@ package org.opensearch.sql.ast.expression; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -23,7 +24,7 @@ public class Not extends UnresolvedExpression { @Override public List getChild() { - return Collections.singletonList(expression); + return singletonList(expression); } @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 852b61cfa8a..09789d8ca27 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 @@ -5,13 +5,13 @@ package org.opensearch.sql.ast.expression; +import static java.util.Collections.singletonList; import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toList; 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; @@ -25,7 +25,7 @@ public class QualifiedName extends UnresolvedExpression { private final List parts; public QualifiedName(String name) { - this.parts = Collections.singletonList(name); + this.parts = singletonList(name); } /** QualifiedName Constructor. */ 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 59ebc1d8392..18fd13a4e7b 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,8 @@ package org.opensearch.sql.ast.expression; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -27,7 +28,7 @@ public UnresolvedArgument(String argName, UnresolvedExpression value) { @Override public List getChild() { - return Collections.singletonList(value); + return singletonList(value); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java b/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java index 2cbe170541e..05f3a178a9a 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java @@ -5,7 +5,8 @@ package org.opensearch.sql.ast.tree; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; @@ -41,7 +42,7 @@ public RareTopN attach(UnresolvedPlan child) { @Override public List getChild() { - return Collections.singletonList(this.child); + return singletonList(this.child); } @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 9d22b42e75d..09faca70fb3 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 @@ -5,8 +5,9 @@ package org.opensearch.sql.ast.tree; +import static java.util.Collections.singletonList; + import com.google.common.collect.ImmutableList; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import lombok.AllArgsConstructor; @@ -32,7 +33,7 @@ public Relation(UnresolvedExpression tableName) { } public Relation(UnresolvedExpression tableName, String alias) { - this.tableName = Collections.singletonList(tableName); + this.tableName = singletonList(tableName); this.alias = alias; } diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java index 698fb20408b..c54c1bcc9c8 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java @@ -5,6 +5,7 @@ package org.opensearch.sql.expression.aggregation; +import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; import static org.opensearch.sql.data.type.ExprCoreType.DATE; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; @@ -21,7 +22,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import java.util.Collections; import java.util.stream.Collectors; import lombok.experimental.UtilityClass; import org.opensearch.sql.data.type.ExprCoreType; @@ -66,16 +66,16 @@ private static DefaultFunctionResolver avg() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> new AvgAggregator(arguments, DOUBLE)) .put( - new FunctionSignature(functionName, Collections.singletonList(DATE)), + new FunctionSignature(functionName, singletonList(DATE)), (functionProperties, arguments) -> new AvgAggregator(arguments, DATE)) .put( - new FunctionSignature(functionName, Collections.singletonList(TIME)), + new FunctionSignature(functionName, singletonList(TIME)), (functionProperties, arguments) -> new AvgAggregator(arguments, TIME)) .put( - new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), + new FunctionSignature(functionName, singletonList(TIMESTAMP)), (functionProperties, arguments) -> new AvgAggregator(arguments, TIMESTAMP)) .build()); } @@ -88,8 +88,7 @@ private static DefaultFunctionResolver count() { ExprCoreType.coreTypes().stream() .collect( Collectors.toMap( - type -> - new FunctionSignature(functionName, Collections.singletonList(type)), + type -> new FunctionSignature(functionName, singletonList(type)), type -> (functionProperties, arguments) -> new CountAggregator(arguments, INTEGER)))); @@ -102,16 +101,16 @@ private static DefaultFunctionResolver sum() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(INTEGER)), + new FunctionSignature(functionName, singletonList(INTEGER)), (functionProperties, arguments) -> new SumAggregator(arguments, INTEGER)) .put( - new FunctionSignature(functionName, Collections.singletonList(LONG)), + new FunctionSignature(functionName, singletonList(LONG)), (functionProperties, arguments) -> new SumAggregator(arguments, LONG)) .put( - new FunctionSignature(functionName, Collections.singletonList(FLOAT)), + new FunctionSignature(functionName, singletonList(FLOAT)), (functionProperties, arguments) -> new SumAggregator(arguments, FLOAT)) .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> new SumAggregator(arguments, DOUBLE)) .build()); } @@ -122,28 +121,28 @@ private static DefaultFunctionResolver min() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(INTEGER)), + new FunctionSignature(functionName, singletonList(INTEGER)), (functionProperties, arguments) -> new MinAggregator(arguments, INTEGER)) .put( - new FunctionSignature(functionName, Collections.singletonList(LONG)), + new FunctionSignature(functionName, singletonList(LONG)), (functionProperties, arguments) -> new MinAggregator(arguments, LONG)) .put( - new FunctionSignature(functionName, Collections.singletonList(FLOAT)), + new FunctionSignature(functionName, singletonList(FLOAT)), (functionProperties, arguments) -> new MinAggregator(arguments, FLOAT)) .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> new MinAggregator(arguments, DOUBLE)) .put( - new FunctionSignature(functionName, Collections.singletonList(STRING)), + new FunctionSignature(functionName, singletonList(STRING)), (functionProperties, arguments) -> new MinAggregator(arguments, STRING)) .put( - new FunctionSignature(functionName, Collections.singletonList(DATE)), + new FunctionSignature(functionName, singletonList(DATE)), (functionProperties, arguments) -> new MinAggregator(arguments, DATE)) .put( - new FunctionSignature(functionName, Collections.singletonList(TIME)), + new FunctionSignature(functionName, singletonList(TIME)), (functionProperties, arguments) -> new MinAggregator(arguments, TIME)) .put( - new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), + new FunctionSignature(functionName, singletonList(TIMESTAMP)), (functionProperties, arguments) -> new MinAggregator(arguments, TIMESTAMP)) .build()); } @@ -154,28 +153,28 @@ private static DefaultFunctionResolver max() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(INTEGER)), + new FunctionSignature(functionName, singletonList(INTEGER)), (functionProperties, arguments) -> new MaxAggregator(arguments, INTEGER)) .put( - new FunctionSignature(functionName, Collections.singletonList(LONG)), + new FunctionSignature(functionName, singletonList(LONG)), (functionProperties, arguments) -> new MaxAggregator(arguments, LONG)) .put( - new FunctionSignature(functionName, Collections.singletonList(FLOAT)), + new FunctionSignature(functionName, singletonList(FLOAT)), (functionProperties, arguments) -> new MaxAggregator(arguments, FLOAT)) .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> new MaxAggregator(arguments, DOUBLE)) .put( - new FunctionSignature(functionName, Collections.singletonList(STRING)), + new FunctionSignature(functionName, singletonList(STRING)), (functionProperties, arguments) -> new MaxAggregator(arguments, STRING)) .put( - new FunctionSignature(functionName, Collections.singletonList(DATE)), + new FunctionSignature(functionName, singletonList(DATE)), (functionProperties, arguments) -> new MaxAggregator(arguments, DATE)) .put( - new FunctionSignature(functionName, Collections.singletonList(TIME)), + new FunctionSignature(functionName, singletonList(TIME)), (functionProperties, arguments) -> new MaxAggregator(arguments, TIME)) .put( - new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), + new FunctionSignature(functionName, singletonList(TIMESTAMP)), (functionProperties, arguments) -> new MaxAggregator(arguments, TIMESTAMP)) .build()); } @@ -186,7 +185,7 @@ private static DefaultFunctionResolver varSamp() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> varianceSample(arguments, DOUBLE)) .build()); } @@ -197,7 +196,7 @@ private static DefaultFunctionResolver varPop() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> variancePopulation(arguments, DOUBLE)) .build()); } @@ -208,7 +207,7 @@ private static DefaultFunctionResolver stddevSamp() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> stddevSample(arguments, DOUBLE)) .build()); } @@ -219,7 +218,7 @@ private static DefaultFunctionResolver stddevPop() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> stddevPopulation(arguments, DOUBLE)) .build()); } diff --git a/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java b/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java index 8ebbfd3a3c6..f8a8d4773d7 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java @@ -5,8 +5,10 @@ package org.opensearch.sql.expression.function; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; + import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; @@ -68,11 +70,10 @@ public static DefaultFunctionResolver define( implWithProperties( SerializableFunction function, ExprType returnType) { return functionName -> { - FunctionSignature functionSignature = - new FunctionSignature(functionName, Collections.emptyList()); + FunctionSignature functionSignature = new FunctionSignature(functionName, emptyList()); FunctionBuilder functionBuilder = (functionProperties, arguments) -> - new FunctionExpression(functionName, Collections.emptyList()) { + new FunctionExpression(functionName, emptyList()) { @Override public ExprValue valueOf(Environment valueEnv) { return function.apply(functionProperties); @@ -109,7 +110,7 @@ public String toString() { return functionName -> { FunctionSignature functionSignature = - new FunctionSignature(functionName, Collections.singletonList(argsType)); + new FunctionSignature(functionName, singletonList(argsType)); FunctionBuilder functionBuilder = (functionProperties, arguments) -> new FunctionExpression(functionName, arguments) { diff --git a/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java b/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java index 2c3bbf7efb5..1c99af789ab 100644 --- a/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java +++ b/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java @@ -5,6 +5,7 @@ package org.opensearch.sql.expression.text; +import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRING; @@ -12,7 +13,6 @@ import static org.opensearch.sql.expression.function.FunctionDSL.impl; import static org.opensearch.sql.expression.function.FunctionDSL.nullMissingHandling; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import lombok.experimental.UtilityClass; @@ -176,7 +176,7 @@ private DefaultFunctionResolver concat() { concatFuncName, funcName -> Pair.of( - new FunctionSignature(concatFuncName, Collections.singletonList(ARRAY)), + new FunctionSignature(concatFuncName, singletonList(ARRAY)), (funcProp, args) -> new FunctionExpression(funcName, args) { @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAD.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAD.java index 25dbd14f1af..40f70c422c0 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAD.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAD.java @@ -1,6 +1,7 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -23,7 +24,7 @@ public class LogicalAD extends LogicalPlan { * @param arguments arguments of the algorithm */ public LogicalAD(LogicalPlan child, Map arguments) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.arguments = arguments; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java index ecbcece6236..450a4fe415c 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -25,7 +26,7 @@ public class LogicalAggregation extends LogicalPlan { /** Constructor of LogicalAggregation. */ public LogicalAggregation( LogicalPlan child, List aggregatorList, List groupByList) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.aggregatorList = aggregatorList; this.groupByList = groupByList; } 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 82a48fa87c2..368dc3314fb 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,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -30,7 +31,7 @@ public LogicalDedupe( Integer allowedDuplication, Boolean keepEmpty, Boolean consecutive) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.dedupeList = dedupeList; this.allowedDuplication = allowedDuplication; this.keepEmpty = keepEmpty; diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java index e7b8f353bcb..2a79a0ad443 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -27,7 +28,7 @@ public class LogicalEval extends LogicalPlan { /** Constructor of LogicalEval. */ public LogicalEval(LogicalPlan child, List> expressions) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.expressions = expressions; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalFilter.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalFilter.java index 49280e8709d..7c2902c4550 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalFilter.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalFilter.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -20,7 +21,7 @@ public class LogicalFilter extends LogicalPlan { /** Constructor of LogicalFilter. */ public LogicalFilter(LogicalPlan child, Expression condition) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.condition = condition; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalHighlight.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalHighlight.java index 41fcd48f813..1ad86fffd96 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalHighlight.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalHighlight.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -23,7 +24,7 @@ public class LogicalHighlight extends LogicalPlan { /** Constructor of LogicalHighlight. */ public LogicalHighlight( LogicalPlan childPlan, Expression highlightField, Map arguments) { - super(Collections.singletonList(childPlan)); + super(singletonList(childPlan)); this.highlightField = highlightField; this.arguments = arguments; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalLimit.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalLimit.java index bec77d9b6f2..69339589765 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalLimit.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalLimit.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -19,7 +20,7 @@ public class LogicalLimit extends LogicalPlan { /** Constructor of LogicalLimit. */ public LogicalLimit(LogicalPlan input, Integer limit, Integer offset) { - super(Collections.singletonList(input)); + super(singletonList(input)); this.limit = limit; this.offset = offset; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalML.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalML.java index 780e0bba94a..dd7a5ae4604 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalML.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalML.java @@ -1,6 +1,7 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -21,7 +22,7 @@ public class LogicalML extends LogicalPlan { * @param arguments arguments of the algorithm */ public LogicalML(LogicalPlan child, Map arguments) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.arguments = arguments; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalMLCommons.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalMLCommons.java index cfc313a68d5..bfb1b4261de 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalMLCommons.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalMLCommons.java @@ -1,6 +1,7 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -24,7 +25,7 @@ public class LogicalMLCommons extends LogicalPlan { * @param arguments arguments of the algorithm */ public LogicalMLCommons(LogicalPlan child, String algorithm, Map arguments) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.algorithm = algorithm; this.arguments = arguments; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java index 089efe707eb..24d768865be 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import java.util.Map; import lombok.EqualsAndHashCode; @@ -27,7 +28,7 @@ public LogicalNested( LogicalPlan childPlan, List> fields, List projectList) { - super(Collections.singletonList(childPlan)); + super(singletonList(childPlan)); this.fields = fields; this.projectList = projectList; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java index 5978620480a..58576d2e595 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -25,7 +26,7 @@ public LogicalProject( LogicalPlan child, List projectList, List namedParseExpressions) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.projectList = projectList; this.namedParseExpressions = namedParseExpressions; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java index 2c387eca9c8..787350b5cba 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -31,7 +32,7 @@ public LogicalRareTopN( Integer noOfResults, List fieldList, List groupByList) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.commandType = commandType; this.noOfResults = noOfResults; this.fieldList = fieldList; diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRemove.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRemove.java index c1aeda22c7b..a32fe0a2abb 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRemove.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRemove.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Set; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -21,7 +22,7 @@ public class LogicalRemove extends LogicalPlan { /** Constructor of LogicalRemove. */ public LogicalRemove(LogicalPlan child, Set removeList) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.removeList = removeList; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRename.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRename.java index 25ee645932c..7c117ce2408 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRename.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRename.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -21,7 +22,7 @@ public class LogicalRename extends LogicalPlan { /** Constructor of LogicalRename. */ public LogicalRename(LogicalPlan child, Map renameMap) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.renameMap = renameMap; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java index 569ca7e3098..17f6ff0a975 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -24,7 +25,7 @@ public class LogicalSort extends LogicalPlan { /** Constructor of LogicalSort. */ public LogicalSort(LogicalPlan child, List> sortList) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.sortList = sortList; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWindow.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWindow.java index 00c89410a78..37310be3914 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWindow.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWindow.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -27,7 +28,7 @@ public class LogicalWindow extends LogicalPlan { /** Constructor of logical window. */ public LogicalWindow( LogicalPlan child, NamedExpression windowFunction, WindowDefinition windowDefinition) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.windowFunction = windowFunction; this.windowDefinition = windowDefinition; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java index a253739a689..1f4d0ff1082 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -26,7 +27,7 @@ public class LogicalWrite extends LogicalPlan { /** Construct a logical write with given child node, table and column name list. */ public LogicalWrite(LogicalPlan child, Table table, List columns) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.table = table; this.columns = columns; } diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java index cc1c047c311..9103c3e4a65 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.physical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Iterator; import java.util.List; import lombok.EqualsAndHashCode; @@ -59,7 +60,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java index 7faec2154b9..816ada3b10f 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java @@ -5,8 +5,9 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; + import com.google.common.collect.ImmutableList; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -78,7 +79,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java index ac62fe1b867..e458b202113 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java @@ -5,12 +5,12 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; import static org.opensearch.sql.expression.env.Environment.extendEnv; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -50,7 +50,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java index 088dd07f8d9..f3d2ab81f2d 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.physical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -37,7 +38,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/NestedOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/NestedOperator.java index fb5ec276ac1..92f463b742d 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/NestedOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/NestedOperator.java @@ -5,11 +5,11 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; import static java.util.stream.Collectors.mapping; import static java.util.stream.Collectors.toList; import java.util.ArrayList; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.ListIterator; @@ -80,7 +80,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java index 55422dacd36..ccde7535307 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java @@ -5,12 +5,13 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -42,7 +43,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java index ecf997f7ae2..dac850ba3bd 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java @@ -5,11 +5,12 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; + import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.Streams; import java.util.AbstractMap; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; @@ -84,7 +85,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java index b4a724aa7a4..23a562aca83 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java @@ -5,11 +5,11 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -49,7 +49,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java index e6f97dab4a3..7195d15106b 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java @@ -5,11 +5,11 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -56,7 +56,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java index b635f01d180..1a5887374b3 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.physical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Comparator; import java.util.Iterator; import java.util.List; @@ -63,7 +64,7 @@ public void open() { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java index a6e0f968e63..27813450b78 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java @@ -5,8 +5,9 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; + import com.google.common.collect.Ordering; -import java.util.Collections; import java.util.Iterator; import java.util.List; import lombok.EqualsAndHashCode; @@ -73,7 +74,7 @@ public void open() { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java index 10377ce47aa..eb962cb5378 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java @@ -5,10 +5,11 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterators; import com.google.common.collect.PeekingIterator; -import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -62,7 +63,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java b/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java index 2cfa3c94571..36455bf32c8 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java @@ -5,8 +5,9 @@ package org.opensearch.sql.planner.physical.collector; +import static java.util.Collections.singletonList; + import java.util.AbstractMap; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -57,6 +58,6 @@ public void collect(BindingTuple input) { public List results() { LinkedHashMap map = new LinkedHashMap<>(); aggregators.forEach(agg -> map.put(agg.getKey().getName(), agg.getValue().result())); - return Collections.singletonList(ExprTupleValue.fromExprValueMap(map)); + return singletonList(ExprTupleValue.fromExprValueMap(map)); } } diff --git a/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java b/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java index 2591689a353..504fad9f30f 100644 --- a/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java +++ b/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java @@ -5,8 +5,9 @@ package org.opensearch.sql.planner.streaming.windowing.assigner; +import static java.util.Collections.singletonList; + import com.google.common.base.Preconditions; -import java.util.Collections; import java.util.List; import org.opensearch.sql.planner.streaming.windowing.Window; import org.opensearch.sql.utils.DateTimeUtils; @@ -31,6 +32,6 @@ public TumblingWindowAssigner(long windowSize) { @Override public List assign(long timestamp) { long startTime = DateTimeUtils.getWindowStartTime(timestamp, windowSize); - return Collections.singletonList(new Window(startTime, startTime + windowSize)); + return singletonList(new Window(startTime, startTime + windowSize)); } } 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 af18916f716..1a430fc0493 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,7 +5,8 @@ package org.opensearch.sql.storage.write; -import java.util.Collections; +import static java.util.Collections.singletonList; + import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.logical.LogicalPlanNodeVisitor; import org.opensearch.sql.planner.physical.PhysicalPlan; @@ -20,7 +21,7 @@ public abstract class TableWriteBuilder extends LogicalPlan { /** Construct table write builder with child node. */ public TableWriteBuilder(LogicalPlan child) { - super(Collections.singletonList(child)); + super(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 92cdc6eb417..82607eaa656 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,7 +5,8 @@ package org.opensearch.sql.storage.write; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.RequiredArgsConstructor; import org.opensearch.sql.planner.physical.PhysicalPlan; @@ -29,7 +30,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return 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 4f06ce9d23a..53a5a281528 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java @@ -6,6 +6,7 @@ package org.opensearch.sql.analysis; import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -62,7 +63,6 @@ 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; @@ -491,7 +491,7 @@ public void rename_to_invalid_expression() { AstDSL.alias( "avg(integer_value)", AstDSL.aggregate("avg", field("integer_value")))), - Collections.emptyList(), + emptyList(), ImmutableList.of(), AstDSL.defaultStatsArgs()), AstDSL.map( @@ -894,7 +894,7 @@ public void remove_source() { DSL.ref("double_value", DOUBLE)), AstDSL.projectWithArg( AstDSL.relation("schema"), - Collections.singletonList(argument("exclude", booleanLiteral(true))), + singletonList(argument("exclude", booleanLiteral(true))), AstDSL.field("integer_value"), AstDSL.field("double_value"))); } @@ -1041,8 +1041,8 @@ public void window_function() { "window_function", AstDSL.window( AstDSL.function("row_number"), - Collections.singletonList(AstDSL.qualifiedName("string_value")), - Collections.singletonList( + singletonList(AstDSL.qualifiedName("string_value")), + singletonList( ImmutablePair.of(DEFAULT_ASC, AstDSL.qualifiedName("integer_value"))))))); } 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 17f86cadbae..c0ff667efc2 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java @@ -5,6 +5,7 @@ package org.opensearch.sql.analysis; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; import static org.opensearch.sql.data.type.ExprCoreType.LONG; @@ -12,7 +13,6 @@ 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; @@ -61,7 +61,7 @@ protected StorageEngine prometheusStorageEngine() { return new StorageEngine() { @Override public Collection getFunctions() { - return Collections.singletonList( + return singletonList( new FunctionResolver() { @Override 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 461e1f83583..8898b0b7dba 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java @@ -5,13 +5,13 @@ package org.opensearch.sql.analysis; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; -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(Collections.singletonList(unresolvedExpression), analysisContext, optimizer); + .analyze(singletonList(unresolvedExpression), analysisContext, optimizer); } protected void assertAnalyzeEqual( NamedExpression expected, UnresolvedExpression unresolvedExpression) { - assertEquals(Collections.singletonList(expected), analyze(unresolvedExpression)); + assertEquals(singletonList(expected), analyze(unresolvedExpression)); } } 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 2f3e855430a..3300ca374eb 100644 --- a/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.expression; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -14,7 +15,6 @@ 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; @@ -38,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(Collections.singletonList(ref("age", INTEGER)), INTEGER)) + named("avg", new AvgAggregator(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/expression/function/BuiltinFunctionRepositoryTest.java b/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java index ae345fa9890..17f63d7215c 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 @@ -5,6 +5,8 @@ package org.opensearch.sql.expression.function; +import static java.util.Collections.emptyList; +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,7 +26,6 @@ import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BOOLEAN; import com.google.common.collect.ImmutableList; -import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; @@ -97,7 +98,7 @@ void compile_datasource_defined_function() { repo.compile( functionProperties, - Collections.singletonList(dataSourceFunctionResolver), + singletonList(dataSourceFunctionResolver), mockFunctionName, List.of(mockExpression)); verify(functionExpressionBuilder, times(1)).apply(eq(functionProperties), any()); @@ -115,8 +116,7 @@ void resolve() { BuiltinFunctionRepository repo = new BuiltinFunctionRepository(mockMap); repo.register(mockfunctionResolver); - assertEquals( - functionExpressionBuilder, repo.resolve(Collections.emptyList(), functionSignature)); + assertEquals(functionExpressionBuilder, repo.resolve(emptyList(), functionSignature)); } @Test @@ -124,7 +124,7 @@ void resolve_should_not_cast_arguments_in_cast_function() { when(mockExpression.toString()).thenReturn("string"); FunctionImplementation function = repo.resolve( - Collections.emptyList(), + emptyList(), registerFunctionResolver(CAST_TO_BOOLEAN.getName(), TIMESTAMP, BOOLEAN)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("cast_to_boolean(string)", function.toString()); @@ -135,8 +135,7 @@ void resolve_should_not_cast_arguments_if_same_type() { when(mockFunctionName.getFunctionName()).thenReturn("mock"); when(mockExpression.toString()).thenReturn("string"); FunctionImplementation function = - repo.resolve( - Collections.emptyList(), registerFunctionResolver(mockFunctionName, STRING, STRING)) + repo.resolve(emptyList(), registerFunctionResolver(mockFunctionName, STRING, STRING)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(string)", function.toString()); } @@ -146,8 +145,7 @@ void resolve_should_not_cast_arguments_if_both_numbers() { when(mockFunctionName.getFunctionName()).thenReturn("mock"); when(mockExpression.toString()).thenReturn("byte"); FunctionImplementation function = - repo.resolve( - Collections.emptyList(), registerFunctionResolver(mockFunctionName, BYTE, INTEGER)) + repo.resolve(emptyList(), registerFunctionResolver(mockFunctionName, BYTE, INTEGER)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(byte)", function.toString()); } @@ -162,7 +160,7 @@ void resolve_should_cast_arguments() { registerFunctionResolver(CAST_TO_BOOLEAN.getName(), STRING, STRING); FunctionImplementation function = - repo.resolve(Collections.emptyList(), signature) + repo.resolve(emptyList(), signature) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(cast_to_boolean(string))", function.toString()); } @@ -173,9 +171,7 @@ void resolve_should_throw_exception_for_unsupported_conversion() { assertThrows( ExpressionEvaluationException.class, () -> - repo.resolve( - Collections.emptyList(), - registerFunctionResolver(mockFunctionName, BYTE, STRUCT)) + repo.resolve(emptyList(), registerFunctionResolver(mockFunctionName, BYTE, STRUCT)) .apply(functionProperties, ImmutableList.of(mockExpression))); assertEquals(error.getMessage(), "Type conversion to type STRUCT is not supported"); } @@ -192,8 +188,7 @@ void resolve_unregistered() { ExpressionEvaluationException.class, () -> repo.resolve( - Collections.emptyList(), - new FunctionSignature(FunctionName.of("unknown"), List.of()))); + emptyList(), new FunctionSignature(FunctionName.of("unknown"), List.of()))); assertEquals("unsupported function name: unknown", exception.getMessage()); } 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 9db1eaf5659..a58773fae46 100644 --- a/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java @@ -6,6 +6,7 @@ package org.opensearch.sql.planner; import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -31,7 +32,6 @@ import static org.opensearch.sql.planner.logical.LogicalPlanDSL.window; import com.google.common.collect.ImmutableMap; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -191,9 +191,8 @@ public void visitWindowOperator_should_return_PhysicalWindowOperator() { NamedExpression windowFunction = named(new RowNumberFunction()); WindowDefinition windowDefinition = new WindowDefinition( - Collections.singletonList(ref("state", STRING)), - Collections.singletonList( - ImmutablePair.of(Sort.SortOption.DEFAULT_DESC, ref("age", INTEGER)))); + singletonList(ref("state", STRING)), + singletonList(ImmutablePair.of(Sort.SortOption.DEFAULT_DESC, ref("age", INTEGER)))); NamedExpression[] projectList = { named("state", ref("state", STRING)), named("row_number", ref("row_number", INTEGER)) 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 ee784045d00..d454469ba2b 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 @@ -5,6 +5,8 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInRelativeOrder; @@ -20,7 +22,6 @@ 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; @@ -38,9 +39,8 @@ public void sum_without_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - Collections.singletonList( - DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), - Collections.emptyList()); + singletonList(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), + emptyList()); List result = execute(plan); assertEquals(1, result.size()); assertThat( @@ -53,9 +53,8 @@ public void avg_with_one_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - Collections.singletonList( - DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), - Collections.singletonList(DSL.named("action", DSL.ref("action", STRING)))); + singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + singletonList(DSL.named("action", DSL.ref("action", STRING)))); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -70,8 +69,7 @@ public void avg_with_two_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - Collections.singletonList( - DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + 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)))); @@ -93,9 +91,8 @@ public void sum_with_one_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - Collections.singletonList( - DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), - Collections.singletonList(DSL.named("action", DSL.ref("action", STRING)))); + singletonList(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), + singletonList(DSL.named("action", DSL.ref("action", STRING)))); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -110,8 +107,8 @@ public void millisecond_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + singletonList( DSL.named( "span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6 * 1000), "ms")))); List result = execute(plan); @@ -131,8 +128,8 @@ public void second_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6), "s")))); List result = execute(plan); assertEquals(2, result.size()); @@ -151,8 +148,8 @@ public void minute_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("minute", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("minute", TIMESTAMP)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("minute", TIMESTAMP), DSL.literal(5), "m")))); List result = execute(plan); assertEquals(3, result.size()); @@ -170,8 +167,8 @@ public void minute_span() { plan = new AggregationOperator( testScan(datetimeInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(30), "m")))); result = execute(plan); assertEquals(4, result.size()); @@ -193,9 +190,8 @@ public void hour_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - 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")))); + singletonList(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), + singletonList(DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(1), "h")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -214,9 +210,8 @@ public void day_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - 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")))); + singletonList(DSL.named("count(day)", DSL.count(DSL.ref("day", DATE)))), + singletonList(DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")))); List result = execute(plan); assertEquals(4, result.size()); assertThat( @@ -234,8 +229,8 @@ public void day_span() { plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(30), "d")))); result = execute(plan); assertEquals(3, result.size()); @@ -255,8 +250,8 @@ public void week_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(5), "w")))); List result = execute(plan); assertEquals(3, result.size()); @@ -276,8 +271,8 @@ public void month_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(1), "M")))); List result = execute(plan); assertEquals(3, result.size()); @@ -294,8 +289,8 @@ public void month_span() { plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "M")))); result = execute(plan); assertEquals(4, result.size()); @@ -315,8 +310,8 @@ public void month_span() { plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), + singletonList( DSL.named( "span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10 * 12), "M")))); result = execute(plan); @@ -338,8 +333,8 @@ public void quarter_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "q")))); List result = execute(plan); assertEquals(2, result.size()); @@ -355,8 +350,8 @@ public void quarter_span() { plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10 * 4), "q")))); result = execute(plan); assertEquals(3, result.size()); @@ -377,8 +372,8 @@ public void year_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10), "y")))); List result = execute(plan); assertEquals(3, result.size()); @@ -399,8 +394,8 @@ public void integer_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("integer", INTEGER), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); @@ -414,8 +409,8 @@ public void integer_field() { plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("integer", INTEGER), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); @@ -432,9 +427,8 @@ public void long_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - 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), "")))); + singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), + singletonList(DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -447,8 +441,8 @@ public void long_field() { plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); @@ -465,8 +459,8 @@ public void float_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); @@ -480,8 +474,8 @@ public void float_field() { plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); @@ -498,8 +492,8 @@ public void double_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); @@ -513,8 +507,8 @@ public void double_field() { plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); @@ -531,7 +525,7 @@ public void twoBucketsSpanAndLong() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - Collections.singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), + 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)))); @@ -556,7 +550,7 @@ public void twoBucketsSpanAndLong() { plan = new AggregationOperator( testScan(compoundInputs), - Collections.singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), + 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)), @@ -643,7 +637,7 @@ public void aggregate_with_two_groups_with_windowing() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - Collections.singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), + 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")))); @@ -695,7 +689,7 @@ public void aggregate_with_three_groups_with_windowing() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - Collections.singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), + 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")), @@ -755,8 +749,8 @@ public void copyOfAggregationOperatorShouldSame() { AggregationOperator plan = new AggregationOperator( testScan(datetimeInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + 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/RareTopNOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/RareTopNOperatorTest.java index e252c41d1fa..70e2ba18661 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 @@ -5,12 +5,13 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; 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; @@ -27,8 +28,8 @@ public void rare_without_group() { new RareTopNOperator( new TestScan(), CommandType.RARE, - Collections.singletonList(DSL.ref("action", ExprCoreType.STRING)), - Collections.emptyList()); + singletonList(DSL.ref("action", ExprCoreType.STRING)), + emptyList()); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -44,8 +45,8 @@ public void rare_with_group() { new RareTopNOperator( new TestScan(), CommandType.RARE, - Collections.singletonList(DSL.ref("response", ExprCoreType.INTEGER)), - Collections.singletonList(DSL.ref("action", ExprCoreType.STRING))); + singletonList(DSL.ref("response", ExprCoreType.INTEGER)), + singletonList(DSL.ref("action", ExprCoreType.STRING))); List result = execute(plan); assertEquals(4, result.size()); assertThat( @@ -63,8 +64,8 @@ public void top_without_group() { new RareTopNOperator( new TestScan(), CommandType.TOP, - Collections.singletonList(DSL.ref("action", ExprCoreType.STRING)), - Collections.emptyList()); + singletonList(DSL.ref("action", ExprCoreType.STRING)), + emptyList()); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -81,8 +82,8 @@ public void top_n_without_group() { new TestScan(), CommandType.TOP, 1, - Collections.singletonList(DSL.ref("action", ExprCoreType.STRING)), - Collections.emptyList()); + singletonList(DSL.ref("action", ExprCoreType.STRING)), + emptyList()); List result = execute(plan); assertEquals(1, result.size()); assertThat( @@ -96,8 +97,8 @@ public void top_n_with_group() { new TestScan(), CommandType.TOP, 1, - Collections.singletonList(DSL.ref("response", ExprCoreType.INTEGER)), - Collections.singletonList(DSL.ref("action", ExprCoreType.STRING))); + singletonList(DSL.ref("response", ExprCoreType.INTEGER)), + 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 807d8b8836b..fe55275e3b8 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 @@ -5,6 +5,7 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -14,7 +15,6 @@ 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; @@ -34,9 +34,8 @@ public void avg_aggregation_rename() { new RenameOperator( new AggregationOperator( new TestScan(), - Collections.singletonList( - DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), - Collections.singletonList(DSL.named("action", DSL.ref("action", STRING)))), + singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + 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 a8ab0487017..4869a4c8a89 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(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)); + 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)); } @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 e5b2c9f61a0..3c28b140920 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(Collections.singletonList(child), tableWrite.getChild()); + assertEquals(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 9a1022706fc..84cb3d58a03 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 @@ -5,6 +5,8 @@ package org.opensearch.sql.datasources.service; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -22,7 +24,6 @@ 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; @@ -104,7 +105,7 @@ void testGetDataSourceForNonExistingDataSource() { @Test void testGetDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("test", DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of()); + metadata("test", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); doNothing().when(dataSourceUserAuthorizationHelper).authorizeDataSource(dataSourceMetadata); when(dataSourceMetadataStorage.getDataSourceMetadata("test")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -121,7 +122,7 @@ void testGetDataSourceWithAuthorizationFailure() { metadata( "test", DataSourceType.OPENSEARCH, - Collections.singletonList("prometheus_access"), + singletonList("prometheus_access"), ImmutableMap.of()); doThrow( new SecurityException( @@ -148,7 +149,7 @@ void testGetDataSourceWithAuthorizationFailure() { void testCreateDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("testDS", DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); dataSourceService.createDataSource(dataSourceMetadata); verify(dataSourceMetadataStorage, times(1)).createDataSourceMetadata(dataSourceMetadata); verify(dataSourceFactory, times(1)).createDataSource(dataSourceMetadata); @@ -156,11 +157,7 @@ void testCreateDataSourceSuccessCase() { when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn( Optional.ofNullable( - metadata( - "testDS", - DataSourceType.OPENSEARCH, - Collections.emptyList(), - ImmutableMap.of()))); + metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()))); DataSource dataSource = dataSourceService.getDataSource("testDS"); assertEquals("testDS", dataSource.getName()); assertEquals(storageEngine, dataSource.getStorageEngine()); @@ -178,9 +175,7 @@ void testGetDataSourceMetadataSet() { .thenReturn( new ArrayList<>() { { - add( - metadata( - "testDS", DataSourceType.PROMETHEUS, Collections.emptyList(), properties)); + add(metadata("testDS", DataSourceType.PROMETHEUS, emptyList(), properties)); } }); Set dataSourceMetadataSet = dataSourceService.getDataSourceMetadata(false); @@ -201,12 +196,7 @@ void testGetDataSourceMetadataSetWithDefaultDatasource() { .thenReturn( new ArrayList<>() { { - add( - metadata( - "testDS", - DataSourceType.PROMETHEUS, - Collections.emptyList(), - ImmutableMap.of())); + add(metadata("testDS", DataSourceType.PROMETHEUS, emptyList(), ImmutableMap.of())); } }); Set dataSourceMetadataSet = dataSourceService.getDataSourceMetadata(true); @@ -219,7 +209,7 @@ void testGetDataSourceMetadataSetWithDefaultDatasource() { @Test void testUpdateDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("testDS", DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); dataSourceService.updateDataSource(dataSourceMetadata); verify(dataSourceMetadataStorage, times(1)).updateDataSourceMetadata(dataSourceMetadata); verify(dataSourceFactory, times(1)).createDataSource(dataSourceMetadata); @@ -229,10 +219,7 @@ void testUpdateDataSourceSuccessCase() { void testUpdateDefaultDataSource() { DataSourceMetadata dataSourceMetadata = metadata( - DEFAULT_DATASOURCE_NAME, - DataSourceType.OPENSEARCH, - Collections.emptyList(), - ImmutableMap.of()); + DEFAULT_DATASOURCE_NAME, DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); UnsupportedOperationException unsupportedOperationException = assertThrows( UnsupportedOperationException.class, @@ -276,7 +263,7 @@ void testPatchDataSourceSuccessCase() { STATUS_FIELD, DataSourceStatus.DISABLED)); DataSourceMetadata getData = - metadata("testDS", DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.ofNullable(getData)); @@ -339,7 +326,7 @@ void testRemovalOfAuthorizationInfo() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -364,7 +351,7 @@ void testRemovalOfAuthorizationInfoForAccessKeyAndSecretKye() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -391,7 +378,7 @@ void testRemovalOfAuthorizationInfoForGlueWithRoleARN() { .setName("testGlue") .setProperties(properties) .setConnector(DataSourceType.S3GLUE) - .setAllowedRoles(Collections.singletonList("glue_access")) + .setAllowedRoles(singletonList("glue_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testGlue")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -433,8 +420,7 @@ void testGetDataSourceMetadataForSpecificDataSourceName() { when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn( Optional.ofNullable( - metadata( - "testDS", DataSourceType.PROMETHEUS, Collections.emptyList(), properties))); + metadata("testDS", DataSourceType.PROMETHEUS, emptyList(), properties))); DataSourceMetadata dataSourceMetadata = this.dataSourceService.getDataSourceMetadata("testDS"); assertTrue(dataSourceMetadata.getProperties().containsKey("prometheus.uri")); assertTrue(dataSourceMetadata.getProperties().containsKey("prometheus.auth.type")); @@ -455,7 +441,7 @@ void testVerifyDataSourceAccessAndGetRawDataSourceMetadataWithDisabledData() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .setDataSourceStatus(DataSourceStatus.DISABLED) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) @@ -482,7 +468,7 @@ void testVerifyDataSourceAccessAndGetRawDataSourceMetadata() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(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 03abe737632..0a363699cd3 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 @@ -5,6 +5,8 @@ package org.opensearch.sql.datasources.storage; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.opensearch.sql.datasource.model.DataSourceStatus.ACTIVE; import static org.opensearch.sql.datasources.storage.OpenSearchDataSourceMetadataStorage.DATASOURCE_INDEX_NAME; @@ -15,7 +17,6 @@ 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; @@ -672,7 +673,7 @@ public void testWhenDataSourcesAreDisabled() { Optional.empty(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata("dummy")); Assertions.assertEquals( - Collections.emptyList(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata()); + emptyList(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata()); Assertions.assertThrows( IllegalStateException.class, @@ -712,7 +713,7 @@ private String getBasicDataSourceMetadataString() throws JsonProcessingException .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -732,7 +733,7 @@ private String getAWSSigv4DataSourceMetadataString() throws JsonProcessingExcept .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -749,7 +750,7 @@ private String getDataSourceMetadataStringWithBasicAuthentication() .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -762,7 +763,7 @@ private String getDataSourceMetadataStringWithNoAuthentication() throws JsonProc .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -777,7 +778,7 @@ private DataSourceMetadata getDataSourceMetadata() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(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 2b77c1938ae..e48ec0ffeed 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,6 +1,8 @@ package org.opensearch.sql.datasources.utils; -import java.util.Collections; +import static java.util.Collections.emptySet; +import static java.util.Collections.singletonList; + import java.util.HashMap; import java.util.Set; import lombok.SneakyThrows; @@ -21,7 +23,7 @@ public void testValidateHost() { IllegalArgumentException.class, () -> DatasourceValidationUtils.validateHost( - "http://localhost:9090", Collections.singletonList("127.0.0.0/8"))); + "http://localhost:9090", singletonList("127.0.0.0/8"))); Assertions.assertEquals( "Disallowed hostname in the uri. Validate with plugins.query.datasources.uri.hosts.denylist" + " config", @@ -34,7 +36,7 @@ public void testValidateHostWithSuccess() { Assertions.assertDoesNotThrow( () -> DatasourceValidationUtils.validateHost( - "http://localhost:9090", Collections.singletonList("192.168.0.0/8"))); + "http://localhost:9090", singletonList("192.168.0.0/8"))); } @Test @@ -73,8 +75,6 @@ public void testValidateLengthAndRequiredFieldsWithSuccess() { HashMap config = new HashMap<>(); config.put("s3.uri", "test"); Assertions.assertDoesNotThrow( - () -> - DatasourceValidationUtils.validateLengthAndRequiredFields( - config, Collections.emptySet())); + () -> DatasourceValidationUtils.validateLengthAndRequiredFields(config, emptySet())); } } 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 73ed6e359c1..f90b42cda27 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 @@ -5,6 +5,7 @@ package org.opensearch.sql.legacy; +import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toSet; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -15,7 +16,6 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -157,7 +157,7 @@ public void selectScore() throws IOException { "SELECT _score FROM %s WHERE SCORE(match_phrase(phrase, 'brown fox'))", TestsConstants.TEST_INDEX_PHRASE)); - List fields = Collections.singletonList("_score"); + List fields = singletonList("_score"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } @@ -277,7 +277,7 @@ public void groupBySingleField() throws IOException { String.format( Locale.ROOT, "SELECT * FROM %s GROUP BY age", TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = Collections.singletonList("age"); + List fields = singletonList("age"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } @@ -398,7 +398,7 @@ public void aggregationFunctionInSelectNoGroupBy() throws IOException { Locale.ROOT, "SELECT SUM(age) FROM %s", TestsConstants.TEST_INDEX_ACCOUNT)); String ageSum = "SUM(age)"; - assertContainsColumns(getSchema(response), Collections.singletonList(ageSum)); + assertContainsColumns(getSchema(response), singletonList(ageSum)); JSONArray dataRows = getDataRows(response); for (int i = 0; i < dataRows.length(); i++) { @@ -433,7 +433,7 @@ public void aggregationFunctionInHaving() throws IOException { TestsConstants.TEST_INDEX_ACCOUNT)); String ageSum = "gender"; - assertContainsColumns(getSchema(response), Collections.singletonList(ageSum)); + assertContainsColumns(getSchema(response), singletonList(ageSum)); JSONArray dataRows = getDataRows(response); assertEquals(1, dataRows.length()); @@ -555,7 +555,7 @@ public void joinQuerySelectOnlyOnOneTable() throws Exception { TestsConstants.TEST_INDEX_ACCOUNT, TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = Collections.singletonList("b1.age"); + List fields = singletonList("b1.age"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } 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 2e040d78fbb..6d6b05a3e39 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,7 +5,9 @@ package org.opensearch.sql.legacy.executor.format; -import java.util.Collections; +import static java.util.Collections.singletonList; +import static java.util.Collections.singletonMap; + import java.util.List; import java.util.Map; import org.opensearch.client.Client; @@ -27,14 +29,14 @@ public DeleteResultSet(Client client, Delete query, Object queryResult) { } private List loadColumns() { - return Collections.singletonList(new Schema.Column(DELETED, null, Schema.Type.LONG)); + return singletonList(new Schema.Column(DELETED, null, Schema.Type.LONG)); } private List loadRows() { - return Collections.singletonList(new DataRows.Row(loadDeletedData())); + return singletonList(new DataRows.Row(loadDeletedData())); } private Map loadDeletedData() { - return Collections.singletonMap(DELETED, ((BulkByScrollResponse) queryResult).getDeleted()); + return singletonMap(DELETED, ((BulkByScrollResponse) queryResult).getDeleted()); } } 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 f66e744923b..de726d7e196 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,8 @@ package org.opensearch.sql.legacy.expression.core.builder; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.RequiredArgsConstructor; import org.opensearch.sql.legacy.expression.core.Expression; @@ -31,7 +32,7 @@ public Expression build(List expressionList) { return new Expression() { @Override public ExprValue valueOf(BindingTuple tuple) { - return op.apply(Collections.singletonList(expression.valueOf(tuple))); + return op.apply(singletonList(expression.valueOf(tuple))); } @Override 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 f9c32b74243..f274e358114 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 @@ -5,6 +5,7 @@ package org.opensearch.sql.opensearch.planner.physical; +import static java.util.Collections.singletonList; import static org.opensearch.sql.utils.MLCommonsConstants.ANOMALY_RATE; import static org.opensearch.sql.utils.MLCommonsConstants.ANOMALY_SCORE_THRESHOLD; import static org.opensearch.sql.utils.MLCommonsConstants.CATEGORY_FIELD; @@ -18,7 +19,6 @@ 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; @@ -115,7 +115,7 @@ public ExprValue next() { @Override public List getChild() { - return Collections.singletonList(input); + return 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 ef60782a24c..3ae0f43fcef 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 @@ -5,12 +5,12 @@ package org.opensearch.sql.opensearch.planner.physical; +import static java.util.Collections.singletonList; import static org.opensearch.ml.common.FunctionName.KMEANS; import static org.opensearch.sql.utils.MLCommonsConstants.CENTROIDS; 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; @@ -91,7 +91,7 @@ public ExprValue next() { @Override public List getChild() { - return Collections.singletonList(input); + return 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 6dc7078a0d3..00a28342efd 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 @@ -5,8 +5,9 @@ package org.opensearch.sql.opensearch.planner.physical; +import static java.util.Collections.singletonList; + import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -98,7 +99,7 @@ public ExprValue next() { @Override public List getChild() { - return Collections.singletonList(input); + return 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 de0ee5883cf..3a619154999 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 @@ -13,8 +13,9 @@ package org.opensearch.sql.opensearch.response.agg; +import static java.util.Collections.singletonList; + import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; import org.opensearch.search.aggregations.Aggregations; @@ -34,6 +35,6 @@ public NoBucketAggregationParser(List metricParserList) { @Override public List> parse(Aggregations aggregations) { - return Collections.singletonList(metricsParser.parse(aggregations)); + return 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 a218151b2e3..7f14cb1fe05 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 @@ -5,10 +5,11 @@ package org.opensearch.sql.opensearch.storage.script.aggregation; +import static java.util.Collections.singletonList; + 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; @@ -77,7 +78,7 @@ public AggregationQueryBuilder(ExpressionSerializer serializer) { } else { GroupSortOrder groupSortOrder = new GroupSortOrder(sortList); return Pair.of( - Collections.singletonList( + singletonList( AggregationBuilders.composite( "composite_buckets", bucketBuilder.build( 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 e6d2bac85b5..6b76b373603 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,6 +5,7 @@ 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; @@ -16,7 +17,6 @@ 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( - Collections.singletonList( + 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 fa328fd26ce..f003de848d8 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,6 +5,7 @@ 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; @@ -20,7 +21,6 @@ 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( - Collections.singletonList( + 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 a2430a671d2..1e6bb6b1718 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 @@ -5,6 +5,7 @@ package org.opensearch.sql.opensearch.request; +import static java.util.Collections.singletonList; import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; @@ -14,7 +15,6 @@ 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; @@ -349,7 +349,7 @@ void test_push_down_query() { void test_push_down_aggregation() { AggregationBuilder aggBuilder = AggregationBuilders.composite( - "composite_buckets", Collections.singletonList(new TermsValuesSourceBuilder("longA"))); + "composite_buckets", singletonList(new TermsValuesSourceBuilder("longA"))); OpenSearchAggregationResponseParser responseParser = new CompositeAggregationParser(new SingleValueParser("AVG(intA)")); requestBuilder.pushDownAggregation(Pair.of(List.of(aggBuilder), responseParser)); @@ -368,7 +368,7 @@ void test_push_down_aggregation() { void test_push_down_percentile_aggregation() { AggregationBuilder aggBuilder = AggregationBuilders.composite( - "composite_buckets", Collections.singletonList(new TermsValuesSourceBuilder("longA"))); + "composite_buckets", 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/storage/scan/OpenSearchIndexScanOptimizationTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/scan/OpenSearchIndexScanOptimizationTest.java index 6749f87c5bb..b0769b950c7 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 @@ -5,6 +5,8 @@ package org.opensearch.sql.opensearch.storage.scan; +import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; @@ -39,7 +41,6 @@ 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; @@ -331,10 +332,10 @@ void test_limit_push_down() { void test_highlight_push_down() { assertEqualsAfterOptimization( project( - indexScanBuilder(withHighlightPushedDown("*", Collections.emptyMap())), + indexScanBuilder(withHighlightPushedDown("*", emptyMap())), DSL.named("highlight(*)", new HighlightExpression(DSL.literal("*")))), project( - highlight(relation("schema", table), DSL.literal("*"), Collections.emptyMap()), + highlight(relation("schema", table), DSL.literal("*"), emptyMap()), DSL.named("highlight(*)", new HighlightExpression(DSL.literal("*"))))); } @@ -641,7 +642,7 @@ private Runnable withAggregationPushedDown( CompositeAggregationBuilder aggBuilder = AggregationBuilders.composite( "composite_buckets", - Collections.singletonList( + singletonList( new TermsValuesSourceBuilder(aggregation.groupBy) .field(aggregation.groupBy) .order(aggregation.sortBy.getSortOrder() == ASC ? "asc" : "desc") @@ -652,7 +653,7 @@ private Runnable withAggregationPushedDown( AggregationBuilders.avg(aggregation.aggregateName).field(aggregation.aggregateBy)) .size(AggregationQueryBuilder.AGGREGATION_BUCKET_SIZE); - List aggBuilders = Collections.singletonList(aggBuilder); + List aggBuilders = singletonList(aggBuilder); OpenSearchAggregationResponseParser responseParser = new CompositeAggregationParser(new SingleValueParser(aggregation.aggregateName)); 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 4c030ae0014..13769ef2266 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 @@ -5,6 +5,8 @@ package org.opensearch.sql.opensearch.storage.script.aggregation; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -30,7 +32,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.util.AbstractMap; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -280,8 +281,7 @@ void should_build_composite_aggregation_for_expression() { List.of( named( "avg(balance)", - new AvgAggregator( - Collections.singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), + new AvgAggregator(singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), List.of(named("age", DSL.asin(ref("age", INTEGER)))))); } @@ -339,8 +339,7 @@ void should_build_type_mapping_for_expression() { List.of( named( "avg(balance)", - new AvgAggregator( - Collections.singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), + new AvgAggregator(singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), List.of(named("age", DSL.asin(ref("age", INTEGER))))), containsInAnyOrder( map("avg(balance)", OpenSearchDataType.of(INTEGER)), @@ -362,7 +361,7 @@ void should_build_aggregation_without_bucket() { List.of( named( "avg(balance)", new AvgAggregator(List.of(ref("balance", INTEGER)), INTEGER))), - Collections.emptyList())); + emptyList())); } @Test @@ -397,7 +396,7 @@ void should_build_filter_aggregation() { "avg(age) filter(where age > 34)", new AvgAggregator(List.of(ref("age", INTEGER)), INTEGER) .condition(DSL.greater(ref("age", INTEGER), literal(20))))), - Collections.emptyList())); + emptyList())); } @Test @@ -459,7 +458,7 @@ void should_build_type_mapping_without_bucket() { List.of( named( "avg(balance)", new AvgAggregator(List.of(ref("balance", INTEGER)), INTEGER))), - Collections.emptyList()), + emptyList()), containsInAnyOrder(map("avg(balance)", OpenSearchDataType.of(INTEGER)))); } 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 c3c24facb29..8c6ff070833 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 @@ -5,6 +5,7 @@ package org.opensearch.sql.opensearch.storage.script.aggregation.dsl; +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.Mockito.when; @@ -24,7 +25,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import lombok.SneakyThrows; import org.junit.jupiter.api.BeforeEach; @@ -335,10 +335,10 @@ void should_build_cardinality_aggregation() { + " }%n" + "}"), buildQuery( - Collections.singletonList( + singletonList( named( "count(distinct name)", - new CountAggregator(Collections.singletonList(ref("name", STRING)), INTEGER) + new CountAggregator(singletonList(ref("name", STRING)), INTEGER) .distinct(true))))); } @@ -369,10 +369,10 @@ void should_build_filtered_cardinality_aggregation() { + " }%n" + "}"), buildQuery( - Collections.singletonList( + singletonList( named( "count(distinct name) filter(where age > 30)", - new CountAggregator(Collections.singletonList(ref("name", STRING)), INTEGER) + new CountAggregator(singletonList(ref("name", STRING)), INTEGER) .condition(DSL.greater(ref("age", INTEGER), literal(30))) .distinct(true))))); } @@ -397,7 +397,7 @@ void should_build_top_hits_aggregation() { + " }%n" + "}"), buildQuery( - Collections.singletonList( + singletonList( named( "take(name, 10)", new TakeAggregator( @@ -439,7 +439,7 @@ void should_build_filtered_top_hits_aggregation() { + " }%n" + "}"), buildQuery( - Collections.singletonList( + singletonList( named( "take(name, 10) filter(where age > 30)", new TakeAggregator(ImmutableList.of(ref("name", STRING), literal(10)), ARRAY) @@ -452,10 +452,10 @@ void should_throw_exception_for_unsupported_distinct_aggregator() { IllegalStateException.class, () -> buildQuery( - Collections.singletonList( + singletonList( named( "avg(distinct age)", - new AvgAggregator(Collections.singletonList(ref("name", STRING)), STRING) + new AvgAggregator(singletonList(ref("name", STRING)), STRING) .distinct(true)))), "unsupported distinct aggregator avg"); } 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 00d1c9ecd10..afe2e0b1729 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(Collections.singletonList(stringValue("text"))); + when(request.search()).thenReturn(singletonList(stringValue("text"))); final OpenSearchSystemIndexScan systemIndexScan = new OpenSearchSystemIndexScan(request); systemIndexScan.open(); 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 b9e269d9ace..75e27e58da4 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 @@ -5,9 +5,10 @@ package org.opensearch.sql.opensearch.utils; +import static java.util.Collections.singletonList; + import com.google.common.collect.ImmutableSet; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Set; import lombok.experimental.UtilityClass; @@ -24,7 +25,7 @@ public class Utils { public static AvgAggregator avg(Expression expr, ExprCoreType type) { - return new AvgAggregator(Collections.singletonList(expr), type); + return new AvgAggregator(singletonList(expr), type); } public static List agg(NamedAggregator... exprs) { @@ -37,7 +38,7 @@ public static List group(NamedExpression... exprs) { public static List> sort( Expression expr1, Sort.SortOption option1) { - return Collections.singletonList(Pair.of(option1, expr1)); + return singletonList(Pair.of(option1, expr1)); } public static List> sort( 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 f89ecf9c6e4..6e20d198208 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 @@ -5,6 +5,7 @@ package org.opensearch.sql.ppl.utils; +import static java.util.Collections.singletonList; import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.BooleanLiteralContext; import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.DedupCommandContext; import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.FieldsCommandContext; @@ -15,7 +16,6 @@ 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; @@ -33,7 +33,7 @@ public class ArgumentFactory { * @return the list of arguments fetched from the fields command */ public static List getArgumentList(FieldsCommandContext ctx) { - return Collections.singletonList( + return singletonList( ctx.MINUS() != null ? new Argument("exclude", new Literal(true, DataType.BOOLEAN)) : new Argument("exclude", new Literal(false, DataType.BOOLEAN))); @@ -109,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 Collections.singletonList( + return singletonList( ctx.number != null ? new Argument("noOfResults", getArgumentValue(ctx.number)) : new Argument("noOfResults", new Literal(10, DataType.INTEGER))); @@ -122,8 +122,7 @@ 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 Collections.singletonList( - new Argument("noOfResults", new Literal(10, DataType.INTEGER))); + return singletonList(new Argument("noOfResults", new Literal(10, DataType.INTEGER))); } /** 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 43feabfd5f7..887c6557025 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 @@ -5,10 +5,10 @@ package org.opensearch.sql.ppl.utils; +import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; -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(Collections.singletonList(expression)); + when(project.getProjectList()).thenReturn(singletonList(expression)); UnresolvedPlan plan = UnresolvedPlanHelper.addSelectAll(project); assertTrue(plan instanceof Project); 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 d6ca25b206c..8709cecba30 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 @@ -5,6 +5,7 @@ package org.opensearch.sql.prometheus.client; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -18,7 +19,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -154,12 +154,12 @@ void testGetAllMetrics() { Map> expected = new HashMap<>(); expected.put( "go_gc_duration_seconds", - Collections.singletonList( + singletonList( new MetricMetadata( "summary", "A summary of the pause duration of garbage collection cycles.", ""))); expected.put( "go_goroutines", - Collections.singletonList( + singletonList( new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); assertEquals(expected, response); RecordedRequest recordedRequest = mockWebServer.takeRequest(); 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 e59a2bf7c4e..6345dcb1de7 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,6 +7,7 @@ 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; @@ -23,7 +24,6 @@ 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,11 +80,9 @@ void testQueryResponseIterator() { put( TIMESTAMP, new ExprCollectionValue( - Collections.singletonList( + singletonList( new ExprTimestampValue(Instant.ofEpochMilli(1435781430781L))))); - put( - VALUE, - new ExprCollectionValue(Collections.singletonList(new ExprDoubleValue(1)))); + put(VALUE, new ExprCollectionValue(singletonList(new ExprDoubleValue(1)))); } }); @@ -107,11 +105,9 @@ void testQueryResponseIterator() { put( TIMESTAMP, new ExprCollectionValue( - Collections.singletonList( + singletonList( new ExprTimestampValue(Instant.ofEpochMilli(1435781430781L))))); - put( - VALUE, - new ExprCollectionValue(Collections.singletonList(new ExprDoubleValue(0)))); + put(VALUE, new ExprCollectionValue(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 09f63463b54..8fff1c36d0c 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 @@ -7,6 +7,7 @@ package org.opensearch.sql.prometheus.request; +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.Mockito.times; @@ -15,7 +16,6 @@ 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; @@ -43,12 +43,12 @@ void testSearch() { Map> metricsResult = new HashMap<>(); metricsResult.put( "go_gc_duration_seconds", - Collections.singletonList( + singletonList( new MetricMetadata( "summary", "A summary of the pause duration of garbage collection cycles.", ""))); metricsResult.put( "go_goroutines", - Collections.singletonList( + singletonList( new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); when(prometheusClient.getAllMetrics()).thenReturn(metricsResult); PrometheusListMetricsRequest 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 00ddc973bca..9b3c1932505 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,6 +5,7 @@ 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; @@ -22,7 +23,6 @@ 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( - Collections.singletonList(DSL.named("`instance`", DSL.ref("instance", STRING)))); + 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 7b1e2dec0f7..e41b0a321ee 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,9 +7,10 @@ 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; @@ -40,7 +41,7 @@ void testGetConnectorType() { @SneakyThrows void testGetStorageEngineWithBasicAuth() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.emptyList()); + .thenReturn(emptyList()); PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); @@ -55,7 +56,7 @@ void testGetStorageEngineWithBasicAuth() { @SneakyThrows void testGetStorageEngineWithAWSSigV4Auth() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.emptyList()); + .thenReturn(emptyList()); PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); @@ -127,7 +128,7 @@ void testGetStorageEngineWithLongConfigProperties() { @SneakyThrows void testGetStorageEngineWithWrongAuthType() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.emptyList()); + .thenReturn(emptyList()); PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "https://test.com"); @@ -147,7 +148,7 @@ void testGetStorageEngineWithWrongAuthType() { @SneakyThrows void testGetStorageEngineWithNONEAuthType() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.emptyList()); + .thenReturn(emptyList()); PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "https://test.com"); @@ -174,7 +175,7 @@ void testGetStorageEngineWithInvalidURISyntax() { @Test void createDataSourceSuccess() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.emptyList()); + .thenReturn(emptyList()); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); properties.put("prometheus.auth.type", "basicauth"); @@ -195,7 +196,7 @@ void createDataSourceSuccess() { @Test void createDataSourceSuccessWithLocalhost() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.emptyList()); + .thenReturn(emptyList()); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); properties.put("prometheus.auth.type", "basicauth"); @@ -216,7 +217,7 @@ void createDataSourceSuccessWithLocalhost() { @Test void createDataSourceWithHostnameNotMatchingWithAllowHostsConfig() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.singletonList("127.0.0.0/8")); + .thenReturn(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 ea299b87dee..e988a481a08 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(Collections.singletonList(stringValue("text"))); + when(request.search()).thenReturn(singletonList(stringValue("text"))); final PrometheusSystemTableScan systemIndexScan = new PrometheusSystemTableScan(request); systemIndexScan.open(); diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java index fc3402e20a5..af03429bac1 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java @@ -5,6 +5,8 @@ package org.opensearch.sql.protocol.response; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -15,7 +17,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Arrays; -import java.util.Collections; import org.junit.jupiter.api.Test; import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.executor.pagination.Cursor; @@ -46,7 +47,7 @@ void columnNameTypes() { QueryResult response = new QueryResult( schema, - Collections.singletonList(tupleValue(ImmutableMap.of("name", "John", "age", 20))), + singletonList(tupleValue(ImmutableMap.of("name", "John", "age", 20))), Cursor.None); assertEquals(ImmutableMap.of("name", "string", "age", "integer"), response.columnNameTypes()); @@ -59,16 +60,14 @@ void columnNameTypesWithAlias() { ImmutableList.of(new ExecutionEngine.Schema.Column("name", "n", STRING))); QueryResult response = new QueryResult( - schema, - Collections.singletonList(tupleValue(ImmutableMap.of("n", "John"))), - Cursor.None); + schema, singletonList(tupleValue(ImmutableMap.of("n", "John"))), Cursor.None); assertEquals(ImmutableMap.of("n", "string"), response.columnNameTypes()); } @Test void columnNameTypesFromEmptyExprValues() { - QueryResult response = new QueryResult(schema, Collections.emptyList(), Cursor.None); + QueryResult response = new QueryResult(schema, emptyList(), Cursor.None); assertEquals(ImmutableMap.of("name", "string", "age", "integer"), response.columnNameTypes()); } 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 84c9c05e79f..11d638457c8 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,8 +5,9 @@ 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; @@ -22,7 +23,7 @@ public class SparkStorageEngine implements StorageEngine { @Override public Collection getFunctions() { - return Collections.singletonList(new SparkSqlTableFunctionResolver(sparkClient)); + return singletonList(new SparkSqlTableFunctionResolver(sparkClient)); } @Override 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 ab96f162633..8b4f331d772 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,6 +6,7 @@ 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; @@ -19,7 +20,6 @@ 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(Collections.singletonList(AllFields.of())) + return new Project(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(Collections.singletonList(AllFields.of())).attach(table); + return new Project(singletonList(AllFields.of())).attach(table); } else { - return new Project(Collections.singletonList(AllFields.of())) + return new Project(singletonList(AllFields.of())) .attach(new Filter(visitAstExpression(ctx.columnFilter())).attach(table)); } } 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 5bdbfb4e381..eb76875f169 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 @@ -5,6 +5,7 @@ package org.opensearch.sql.sql.parser; +import static java.util.Collections.singletonList; import static org.opensearch.sql.ast.dsl.AstDSL.between; import static org.opensearch.sql.ast.dsl.AstDSL.not; import static org.opensearch.sql.ast.dsl.AstDSL.qualifiedName; @@ -108,7 +109,7 @@ public UnresolvedExpression visitColumnName(ColumnNameContext ctx) { @Override public UnresolvedExpression visitIdent(IdentContext ctx) { - return visitIdentifiers(Collections.singletonList(ctx)); + return visitIdentifiers(singletonList(ctx)); } @Override @@ -252,7 +253,7 @@ public UnresolvedExpression visitIsNullPredicate(IsNullPredicateContext ctx) { ctx.nullNotnull().NOT() == null ? IS_NULL.getName().getFunctionName() : IS_NOT_NULL.getName().getFunctionName(), - Collections.singletonList(visit(ctx.predicate()))); + singletonList(visit(ctx.predicate()))); } @Override From eb175ec1615ef42c8cf133b9da1d06fde36e1db7 Mon Sep 17 00:00:00 2001 From: currantw Date: Mon, 9 Dec 2024 13:18:34 -0800 Subject: [PATCH 03/16] Replace `Collections.singletonList` and `emptyList` with `List.of` in cases where `List` is already imported. Signed-off-by: currantw --- .../sql/ast/expression/AggregateFunction.java | 9 ++--- .../sql/ast/expression/Argument.java | 4 +-- .../org/opensearch/sql/ast/expression/In.java | 4 +-- .../sql/ast/expression/Interval.java | 4 +-- .../opensearch/sql/ast/expression/Not.java | 4 +-- .../ast/expression/UnresolvedArgument.java | 4 +-- .../org/opensearch/sql/ast/tree/RareTopN.java | 4 +-- .../sql/expression/text/TextFunctions.java | 3 +- .../window/ranking/RankingWindowFunction.java | 4 +-- .../planner/logical/LogicalAggregation.java | 4 +-- .../sql/planner/logical/LogicalDedupe.java | 4 +-- .../sql/planner/logical/LogicalEval.java | 4 +-- .../sql/planner/logical/LogicalNested.java | 4 +-- .../sql/planner/logical/LogicalProject.java | 4 +-- .../sql/planner/logical/LogicalRareTopN.java | 4 +-- .../sql/planner/logical/LogicalSort.java | 4 +-- .../sql/planner/logical/LogicalWrite.java | 4 +-- .../sql/planner/physical/FilterOperator.java | 4 +-- .../sql/storage/write/TableWriteOperator.java | 4 +-- .../SelectExpressionAnalyzerTest.java | 5 ++- .../opensearch/sql/executor/ExplainTest.java | 34 +++++++++---------- .../executor/format/DeleteResultSet.java | 9 ++--- .../core/builder/UnaryExpressionBuilder.java | 4 +-- .../request/OpenSearchRequestBuilderTest.java | 5 ++- 24 files changed, 45 insertions(+), 92 deletions(-) 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 5335e3dfa2d..6e837e90ccc 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,9 +5,6 @@ package org.opensearch.sql.ast.expression; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -44,7 +41,7 @@ public class AggregateFunction extends UnresolvedExpression { public AggregateFunction(String funcName, UnresolvedExpression field) { this.funcName = funcName; this.field = field; - this.argList = emptyList(); + this.argList = List.of(); } /** @@ -57,13 +54,13 @@ public AggregateFunction(String funcName, UnresolvedExpression field) { public AggregateFunction(String funcName, UnresolvedExpression field, Boolean distinct) { this.funcName = funcName; this.field = field; - this.argList = emptyList(); + this.argList = List.of(); this.distinct = distinct; } @Override public List getChild() { - return singletonList(field); + return List.of(field); } @Override 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 f187dcd1d98..b4e860811f9 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,8 +5,6 @@ package org.opensearch.sql.ast.expression; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -26,7 +24,7 @@ public class Argument extends UnresolvedExpression { // private final DataType valueType; @Override public List getChild() { - return singletonList(value); + return List.of(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 78c958a93ed..00f4150242b 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,8 +5,6 @@ package org.opensearch.sql.ast.expression; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -29,7 +27,7 @@ public class In extends UnresolvedExpression { @Override public List getChild() { - return singletonList(field); + return List.of(field); } @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 82ff1b93cf6..6ffc86497de 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,8 +5,6 @@ package org.opensearch.sql.ast.expression; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -30,7 +28,7 @@ public Interval(UnresolvedExpression value, String unit) { @Override public List getChild() { - return singletonList(value); + return List.of(value); } @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 1dcb59c4b83..1794c75080e 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,8 +5,6 @@ package org.opensearch.sql.ast.expression; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -24,7 +22,7 @@ public class Not extends UnresolvedExpression { @Override public List getChild() { - return singletonList(expression); + return List.of(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 18fd13a4e7b..cd826e8d90f 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,8 +5,6 @@ package org.opensearch.sql.ast.expression; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -28,7 +26,7 @@ public UnresolvedArgument(String argName, UnresolvedExpression value) { @Override public List getChild() { - return singletonList(value); + return List.of(value); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java b/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java index 05f3a178a9a..6c0d203a007 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java @@ -5,8 +5,6 @@ package org.opensearch.sql.ast.tree; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; @@ -42,7 +40,7 @@ public RareTopN attach(UnresolvedPlan child) { @Override public List getChild() { - return singletonList(this.child); + return List.of(this.child); } @Override diff --git a/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java b/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java index 1c99af789ab..b555c8c05c8 100644 --- a/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java +++ b/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java @@ -5,7 +5,6 @@ package org.opensearch.sql.expression.text; -import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRING; @@ -176,7 +175,7 @@ private DefaultFunctionResolver concat() { concatFuncName, funcName -> Pair.of( - new FunctionSignature(concatFuncName, singletonList(ARRAY)), + new FunctionSignature(concatFuncName, List.of(ARRAY)), (funcProp, args) -> new FunctionExpression(funcName, args) { @Override diff --git a/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunction.java b/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunction.java index c119629cdad..87f4b7de159 100644 --- a/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunction.java @@ -5,8 +5,6 @@ package org.opensearch.sql.expression.window.ranking; -import static java.util.Collections.emptyList; - import java.util.List; import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.Pair; @@ -35,7 +33,7 @@ public abstract class RankingWindowFunction extends FunctionExpression protected int rank; public RankingWindowFunction(FunctionName functionName) { - super(functionName, emptyList()); + super(functionName, List.of()); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java index 450a4fe415c..d40feb7dff0 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -26,7 +24,7 @@ public class LogicalAggregation extends LogicalPlan { /** Constructor of LogicalAggregation. */ public LogicalAggregation( LogicalPlan child, List aggregatorList, List groupByList) { - super(singletonList(child)); + super(List.of(child)); this.aggregatorList = aggregatorList; this.groupByList = groupByList; } 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 368dc3314fb..33fbdfd00e1 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,8 +5,6 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -31,7 +29,7 @@ public LogicalDedupe( Integer allowedDuplication, Boolean keepEmpty, Boolean consecutive) { - super(singletonList(child)); + super(List.of(child)); this.dedupeList = dedupeList; this.allowedDuplication = allowedDuplication; this.keepEmpty = keepEmpty; diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java index 2a79a0ad443..b93b80202ee 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -28,7 +26,7 @@ public class LogicalEval extends LogicalPlan { /** Constructor of LogicalEval. */ public LogicalEval(LogicalPlan child, List> expressions) { - super(singletonList(child)); + super(List.of(child)); this.expressions = expressions; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java index 24d768865be..91eae515995 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - import java.util.List; import java.util.Map; import lombok.EqualsAndHashCode; @@ -28,7 +26,7 @@ public LogicalNested( LogicalPlan childPlan, List> fields, List projectList) { - super(singletonList(childPlan)); + super(List.of(childPlan)); this.fields = fields; this.projectList = projectList; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java index 58576d2e595..37320f84286 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -26,7 +24,7 @@ public LogicalProject( LogicalPlan child, List projectList, List namedParseExpressions) { - super(singletonList(child)); + super(List.of(child)); this.projectList = projectList; this.namedParseExpressions = namedParseExpressions; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java index 787350b5cba..17bb090f60a 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -32,7 +30,7 @@ public LogicalRareTopN( Integer noOfResults, List fieldList, List groupByList) { - super(singletonList(child)); + super(List.of(child)); this.commandType = commandType; this.noOfResults = noOfResults; this.fieldList = fieldList; diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java index 17f6ff0a975..f5b9164e59f 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -25,7 +23,7 @@ public class LogicalSort extends LogicalPlan { /** Constructor of LogicalSort. */ public LogicalSort(LogicalPlan child, List> sortList) { - super(singletonList(child)); + super(List.of(child)); this.sortList = sortList; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java index 1f4d0ff1082..76d75972d80 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -27,7 +25,7 @@ public class LogicalWrite extends LogicalPlan { /** Construct a logical write with given child node, table and column name list. */ public LogicalWrite(LogicalPlan child, Table table, List columns) { - super(singletonList(child)); + super(List.of(child)); this.table = table; this.columns = columns; } diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java index f3d2ab81f2d..e1eeb3adb3a 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -38,7 +36,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(input); } @Override 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 82607eaa656..b11eb35f0e5 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,8 +5,6 @@ package org.opensearch.sql.storage.write; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.RequiredArgsConstructor; import org.opensearch.sql.planner.physical.PhysicalPlan; @@ -30,7 +28,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(input); } /** 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 8898b0b7dba..590f18f96f6 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.analysis; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; @@ -77,11 +76,11 @@ protected List analyze(UnresolvedExpression unresolvedExpressio .when(optimizer) .optimize(any(), any()); return new SelectExpressionAnalyzer(expressionAnalyzer) - .analyze(singletonList(unresolvedExpression), analysisContext, optimizer); + .analyze(List.of(unresolvedExpression), analysisContext, optimizer); } protected void assertAnalyzeEqual( NamedExpression expected, UnresolvedExpression unresolvedExpression) { - assertEquals(singletonList(expected), analyze(unresolvedExpression)); + assertEquals(List.of(expected), analyze(unresolvedExpression)); } } 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 eaeae072428..bf6b1cca686 100644 --- a/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java +++ b/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java @@ -5,8 +5,6 @@ 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; @@ -78,11 +76,11 @@ void can_explain_project_filter_table_scan() { new ExplainResponseNode( "ProjectOperator", Map.of("fields", "[name, age]"), - singletonList( + List.of( new ExplainResponseNode( "FilterOperator", Map.of("conditions", "and(=(balance, 10000), >(age, 30))"), - singletonList(tableScan.explainNode()))))), + List.of(tableScan.explainNode()))))), explain.apply(plan)); } @@ -101,7 +99,7 @@ void can_explain_aggregations() { Map.of( "aggregators", "[avg(balance)]", "groupBy", "[state]"), - singletonList(tableScan.explainNode()))), + List.of(tableScan.explainNode()))), explain.apply(plan)); } @@ -109,13 +107,13 @@ void can_explain_aggregations() { void can_explain_rare_top_n() { Expression field = ref("state", STRING); - PhysicalPlan plan = rareTopN(tableScan, TOP, emptyList(), field); + PhysicalPlan plan = rareTopN(tableScan, TOP, List.of(), field); assertEquals( new ExplainResponse( new ExplainResponseNode( "RareTopNOperator", Map.of("commandType", TOP, "noOfResults", 10, "fields", "[state]", "groupBy", "[]"), - singletonList(tableScan.explainNode()))), + List.of(tableScan.explainNode()))), explain.apply(plan)); } @@ -145,7 +143,7 @@ void can_explain_window() { Map.of( "sortOrder", "ASC", "nullOrder", "NULL_FIRST")))), - singletonList(tableScan.explainNode()))), + List.of(tableScan.explainNode()))), explain.apply(plan)); } @@ -171,15 +169,15 @@ void can_explain_other_operators() { new ExplainResponseNode( "RemoveOperator", Map.of("removeList", "[state]"), - singletonList( + List.of( new ExplainResponseNode( "RenameOperator", Map.of("mapping", Map.of("state", "s")), - singletonList( + List.of( new ExplainResponseNode( "EvalOperator", Map.of("expressions", Map.of("age", "+(age, 2)")), - singletonList( + List.of( new ExplainResponseNode( "DedupeOperator", Map.of( @@ -191,7 +189,7 @@ void can_explain_other_operators() { false, "consecutive", false), - singletonList( + List.of( new ExplainResponseNode( "SortOperator", Map.of( @@ -201,11 +199,11 @@ void can_explain_other_operators() { Map.of( "sortOrder", "ASC", "nullOrder", "NULL_FIRST"))), - singletonList( + List.of( new ExplainResponseNode( "ValuesOperator", Map.of("values", List.of(values)), - emptyList())))))))))))), + List.of())))))))))))), explain.apply(plan)); } @@ -217,7 +215,7 @@ void can_explain_limit() { new ExplainResponseNode( "LimitOperator", Map.of("limit", 10, "offset", 5), - singletonList(tableScan.explainNode()))), + List.of(tableScan.explainNode()))), explain.apply(plan)); } @@ -237,7 +235,7 @@ void can_explain_takeOrdered() { 5, "sortList", Map.of("a", Map.of("sortOrder", "ASC", "nullOrder", "NULL_FIRST"))), - singletonList(tableScan.explainNode()))), + List.of(tableScan.explainNode()))), explain.apply(plan)); } @@ -252,7 +250,7 @@ void can_explain_nested() { new ExplainResponseNode( "NestedOperator", Map.of("nested", Set.of("message.info", "message")), - singletonList(tableScan.explainNode()))), + List.of(tableScan.explainNode()))), explain.apply(plan)); } @@ -275,7 +273,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"), emptyList()); + "FakeTableScan", Map.of("request", "Fake DSL request"), List.of()); } public String explain() { 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 6d6b05a3e39..9cfe8c9ec72 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,9 +5,6 @@ package org.opensearch.sql.legacy.executor.format; -import static java.util.Collections.singletonList; -import static java.util.Collections.singletonMap; - import java.util.List; import java.util.Map; import org.opensearch.client.Client; @@ -29,14 +26,14 @@ public DeleteResultSet(Client client, Delete query, Object queryResult) { } private List loadColumns() { - return singletonList(new Schema.Column(DELETED, null, Schema.Type.LONG)); + return List.of(new Schema.Column(DELETED, null, Schema.Type.LONG)); } private List loadRows() { - return singletonList(new DataRows.Row(loadDeletedData())); + return List.of(new DataRows.Row(loadDeletedData())); } private Map loadDeletedData() { - return singletonMap(DELETED, ((BulkByScrollResponse) queryResult).getDeleted()); + return Map.of(DELETED, ((BulkByScrollResponse) queryResult).getDeleted()); } } 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 de726d7e196..d7682d7bf34 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,8 +5,6 @@ package org.opensearch.sql.legacy.expression.core.builder; -import static java.util.Collections.singletonList; - import java.util.List; import lombok.RequiredArgsConstructor; import org.opensearch.sql.legacy.expression.core.Expression; @@ -32,7 +30,7 @@ public Expression build(List expressionList) { return new Expression() { @Override public ExprValue valueOf(BindingTuple tuple) { - return op.apply(singletonList(expression.valueOf(tuple))); + return op.apply(List.of(expression.valueOf(tuple))); } @Override 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 1e6bb6b1718..0d0b0c3e675 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 @@ -5,7 +5,6 @@ package org.opensearch.sql.opensearch.request; -import static java.util.Collections.singletonList; import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; @@ -349,7 +348,7 @@ void test_push_down_query() { void test_push_down_aggregation() { AggregationBuilder aggBuilder = AggregationBuilders.composite( - "composite_buckets", singletonList(new TermsValuesSourceBuilder("longA"))); + "composite_buckets", List.of(new TermsValuesSourceBuilder("longA"))); OpenSearchAggregationResponseParser responseParser = new CompositeAggregationParser(new SingleValueParser("AVG(intA)")); requestBuilder.pushDownAggregation(Pair.of(List.of(aggBuilder), responseParser)); @@ -368,7 +367,7 @@ void test_push_down_aggregation() { void test_push_down_percentile_aggregation() { AggregationBuilder aggBuilder = AggregationBuilders.composite( - "composite_buckets", singletonList(new TermsValuesSourceBuilder("longA"))); + "composite_buckets", List.of(new TermsValuesSourceBuilder("longA"))); OpenSearchAggregationResponseParser responseParser = new CompositeAggregationParser(new SinglePercentileParser("PERCENTILE(intA, 50)")); requestBuilder.pushDownAggregation(Pair.of(List.of(aggBuilder), responseParser)); From 0216c8db14953c2c174dbd7d0ca179ba288be651 Mon Sep 17 00:00:00 2001 From: currantw Date: Mon, 9 Dec 2024 14:55:46 -0800 Subject: [PATCH 04/16] More replacement of `Collections.singletonList`, `emptyList`, and `emptyMap` with `List.of`/`Map.of` in cases where `List`/`Map` is already imported. Signed-off-by: currantw --- .../cluster/ClusterManagerEventListener.java | 3 +- .../sql/analysis/ExpressionAnalyzer.java | 3 +- .../analysis/SelectExpressionAnalyzer.java | 7 +- .../sql/analysis/symbol/SymbolTable.java | 3 +- .../opensearch/sql/ast/expression/Cast.java | 3 +- .../sql/ast/expression/QualifiedName.java | 3 +- .../org/opensearch/sql/ast/tree/Relation.java | 4 +- .../sql/expression/function/FunctionDSL.java | 10 +- .../sql/planner/logical/LogicalNested.java | 3 +- .../sql/planner/logical/LogicalWrite.java | 3 +- .../planner/physical/AggregationOperator.java | 4 +- .../sql/planner/physical/DedupeOperator.java | 4 +- .../sql/planner/physical/EvalOperator.java | 3 +- .../sql/planner/physical/ProjectOperator.java | 4 +- .../planner/physical/RareTopNOperator.java | 4 +- .../sql/planner/physical/RemoveOperator.java | 3 +- .../sql/planner/physical/RenameOperator.java | 3 +- .../sql/planner/physical/SortOperator.java | 4 +- .../planner/physical/TakeOrderedOperator.java | 4 +- .../sql/planner/physical/WindowOperator.java | 4 +- .../physical/collector/MetricCollector.java | 4 +- .../assigner/TumblingWindowAssigner.java | 4 +- .../opensearch/sql/analysis/AnalyzerTest.java | 56 ++++---- .../sql/analysis/AnalyzerTestBase.java | 3 +- .../sql/analysis/ExpressionAnalyzerTest.java | 6 +- .../expression/ExpressionNodeVisitorTest.java | 3 +- .../BuiltinFunctionRepositoryTest.java | 19 ++- .../sql/planner/DefaultImplementorTest.java | 17 +-- .../physical/AggregationOperatorTest.java | 127 ++++++++---------- .../physical/PhysicalPlanNodeVisitorTest.java | 5 +- .../physical/RareTopNOperatorTest.java | 22 ++- .../planner/physical/RenameOperatorTest.java | 5 +- .../service/DataSourceServiceImplTest.java | 36 +++-- ...enSearchDataSourceMetadataStorageTest.java | 14 +- .../sql/correctness/tests/DBResultTest.java | 19 ++- .../sql/correctness/tests/TestConfigTest.java | 3 +- .../sql/legacy/PrettyFormatResponseIT.java | 11 +- .../antlr/semantic/scope/SymbolTable.java | 3 +- .../visitor/AntlrSqlParseTreeVisitor.java | 5 +- .../legacy/esdomain/mapping/FieldMapping.java | 3 +- .../esdomain/mapping/IndexMappings.java | 4 +- .../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 | 4 +- .../agg/NoBucketAggregationParser.java | 4 +- .../aggregation/AggregationQueryBuilder.java | 4 +- .../script/filter/FilterQueryBuilder.java | 3 +- .../OpenSearchExecutionProtectorTest.java | 27 ++-- .../response/OpenSearchResponseTest.java | 3 +- .../OpenSearchIndexScanOptimizationTest.java | 10 +- .../AggregationQueryBuilderTest.java | 12 +- .../ExpressionAggregationScriptTest.java | 3 +- .../dsl/MetricAggregationBuilderTest.java | 19 ++- .../filter/ExpressionFilterScriptTest.java | 9 +- .../sql/opensearch/utils/Utils.java | 6 +- .../org/opensearch/sql/plugin/SQLPlugin.java | 3 +- .../sql/ppl/utils/ArgumentFactory.java | 7 +- .../ppl/parser/AstExpressionBuilderTest.java | 39 +++--- .../client/PrometheusClientImplTest.java | 6 +- .../PrometheusListMetricsRequestTest.java | 6 +- .../sql/sql/parser/AstAggregationBuilder.java | 6 +- .../sql/sql/parser/AstExpressionBuilder.java | 5 +- .../sql/parser/AstAggregationBuilderTest.java | 3 +- 70 files changed, 268 insertions(+), 396 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 69be1a3fc78..eb83afdf7b2 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 @@ -5,7 +5,6 @@ package org.opensearch.sql.spark.cluster; -import static java.util.Collections.singletonList; import static org.opensearch.sql.spark.data.constants.SparkConstants.SPARK_REQUEST_BUFFER_INDEX_NAME; import com.google.common.annotations.VisibleForTesting; @@ -183,7 +182,7 @@ private void cancel(Cancellable cron) { @VisibleForTesting public List getFlintIndexRetentionCron() { - return singletonList(flintIndexRetentionCron); + return List.of(flintIndexRetentionCron); } private String executorName() { 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 370dd881c77..bef62fa4085 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java @@ -5,7 +5,6 @@ package org.opensearch.sql.analysis; -import static java.util.Collections.singletonList; import static org.opensearch.sql.ast.dsl.AstDSL.and; import static org.opensearch.sql.ast.dsl.AstDSL.compare; @@ -83,7 +82,7 @@ public Expression visitCast(Cast node, AnalysisContext context) { final Expression expression = node.getExpression().accept(this, context); return (Expression) repository.compile( - context.getFunctionProperties(), node.convertFunctionName(), singletonList(expression)); + context.getFunctionProperties(), node.convertFunctionName(), List.of(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 2abbb6d96f4..d296ad6573a 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java @@ -5,8 +5,6 @@ package org.opensearch.sql.analysis; -import static java.util.Collections.singletonList; - import com.google.common.collect.ImmutableList; import java.util.List; import java.util.Map; @@ -55,7 +53,7 @@ public List analyze( @Override public List visitField(Field node, AnalysisContext context) { - return singletonList(DSL.named(node.accept(expressionAnalyzer, context))); + return List.of(DSL.named(node.accept(expressionAnalyzer, context))); } @Override @@ -66,8 +64,7 @@ public List visitAlias(Alias node, AnalysisContext context) { } Expression expr = referenceIfSymbolDefined(node, context); - return singletonList( - DSL.named(unqualifiedNameIfFieldOnly(node, context), expr, node.getAlias())); + return List.of(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 64a4fc4e098..e2913a0e4ec 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,7 +5,6 @@ package org.opensearch.sql.analysis.symbol; -import static java.util.Collections.emptyMap; import static java.util.Collections.emptyNavigableMap; import java.util.EnumMap; @@ -88,7 +87,7 @@ public Map lookupByPrefix(Symbol prefix) { if (table != null) { return table.subMap(prefix.getName(), prefix.getName() + Character.MAX_VALUE); } - return emptyMap(); + return Map.of(); } /** 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 b9221980283..77719b000be 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 @@ -5,7 +5,6 @@ package org.opensearch.sql.ast.expression; -import static java.util.Collections.singletonList; import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BOOLEAN; import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BYTE; import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_DATE; @@ -99,7 +98,7 @@ public FunctionName convertFunctionName() { @Override public List getChild() { - return singletonList(expression); + return List.of(expression); } @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 09789d8ca27..c105dfb7628 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 @@ -5,7 +5,6 @@ package org.opensearch.sql.ast.expression; -import static java.util.Collections.singletonList; import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toList; @@ -25,7 +24,7 @@ public class QualifiedName extends UnresolvedExpression { private final List parts; public QualifiedName(String name) { - this.parts = singletonList(name); + this.parts = List.of(name); } /** QualifiedName Constructor. */ 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 09faca70fb3..0256ae41242 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 @@ -5,8 +5,6 @@ package org.opensearch.sql.ast.tree; -import static java.util.Collections.singletonList; - import com.google.common.collect.ImmutableList; import java.util.List; import java.util.stream.Collectors; @@ -33,7 +31,7 @@ public Relation(UnresolvedExpression tableName) { } public Relation(UnresolvedExpression tableName, String alias) { - this.tableName = singletonList(tableName); + this.tableName = List.of(tableName); this.alias = alias; } diff --git a/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java b/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java index f8a8d4773d7..670a086f7ec 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java @@ -5,9 +5,6 @@ package org.opensearch.sql.expression.function; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; - import java.util.Arrays; import java.util.List; import java.util.function.Function; @@ -70,10 +67,10 @@ public static DefaultFunctionResolver define( implWithProperties( SerializableFunction function, ExprType returnType) { return functionName -> { - FunctionSignature functionSignature = new FunctionSignature(functionName, emptyList()); + FunctionSignature functionSignature = new FunctionSignature(functionName, List.of()); FunctionBuilder functionBuilder = (functionProperties, arguments) -> - new FunctionExpression(functionName, emptyList()) { + new FunctionExpression(functionName, List.of()) { @Override public ExprValue valueOf(Environment valueEnv) { return function.apply(functionProperties); @@ -109,8 +106,7 @@ public String toString() { ExprType argsType) { return functionName -> { - FunctionSignature functionSignature = - new FunctionSignature(functionName, singletonList(argsType)); + FunctionSignature functionSignature = new FunctionSignature(functionName, List.of(argsType)); FunctionBuilder functionBuilder = (functionProperties, arguments) -> new FunctionExpression(functionName, arguments) { diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java index 91eae515995..089efe707eb 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java @@ -5,6 +5,7 @@ package org.opensearch.sql.planner.logical; +import java.util.Collections; import java.util.List; import java.util.Map; import lombok.EqualsAndHashCode; @@ -26,7 +27,7 @@ public LogicalNested( LogicalPlan childPlan, List> fields, List projectList) { - super(List.of(childPlan)); + super(Collections.singletonList(childPlan)); this.fields = fields; this.projectList = projectList; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java index 76d75972d80..a253739a689 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java @@ -5,6 +5,7 @@ package org.opensearch.sql.planner.logical; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -25,7 +26,7 @@ public class LogicalWrite extends LogicalPlan { /** Construct a logical write with given child node, table and column name list. */ public LogicalWrite(LogicalPlan child, Table table, List columns) { - super(List.of(child)); + super(Collections.singletonList(child)); this.table = table; this.columns = columns; } diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java index 9103c3e4a65..c8537885015 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; - import java.util.Iterator; import java.util.List; import lombok.EqualsAndHashCode; @@ -60,7 +58,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java index 816ada3b10f..73a2fb5aa1a 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; - import com.google.common.collect.ImmutableList; import java.util.List; import java.util.Map; @@ -79,7 +77,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java index e458b202113..14c9e4e8a6e 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java @@ -5,7 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; import static org.opensearch.sql.expression.env.Environment.extendEnv; @@ -50,7 +49,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java index ccde7535307..84e7c833ebe 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; - import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import java.io.IOException; @@ -43,7 +41,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java index dac850ba3bd..c1c6a122a22 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; - import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.Streams; @@ -85,7 +83,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java index 23a562aca83..bd2b2c91fc2 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java @@ -5,7 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; import com.google.common.collect.ImmutableMap; @@ -49,7 +48,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java index 7195d15106b..1039646563d 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java @@ -5,7 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; import com.google.common.collect.ImmutableMap; @@ -56,7 +55,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java index 1a5887374b3..468ebf9b31d 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; - import java.util.Comparator; import java.util.Iterator; import java.util.List; @@ -64,7 +62,7 @@ public void open() { @Override public List getChild() { - return singletonList(input); + return List.of(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java index 27813450b78..97d31cb4d4b 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; - import com.google.common.collect.Ordering; import java.util.Iterator; import java.util.List; @@ -74,7 +72,7 @@ public void open() { @Override public List getChild() { - return singletonList(input); + return List.of(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java index eb962cb5378..16f76b776f3 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; - import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterators; import com.google.common.collect.PeekingIterator; @@ -63,7 +61,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java b/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java index 36455bf32c8..5307947df71 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.physical.collector; -import static java.util.Collections.singletonList; - import java.util.AbstractMap; import java.util.LinkedHashMap; import java.util.List; @@ -58,6 +56,6 @@ public void collect(BindingTuple input) { public List results() { LinkedHashMap map = new LinkedHashMap<>(); aggregators.forEach(agg -> map.put(agg.getKey().getName(), agg.getValue().result())); - return singletonList(ExprTupleValue.fromExprValueMap(map)); + return List.of(ExprTupleValue.fromExprValueMap(map)); } } diff --git a/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java b/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java index 504fad9f30f..9a003303a77 100644 --- a/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java +++ b/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.streaming.windowing.assigner; -import static java.util.Collections.singletonList; - import com.google.common.base.Preconditions; import java.util.List; import org.opensearch.sql.planner.streaming.windowing.Window; @@ -32,6 +30,6 @@ public TumblingWindowAssigner(long windowSize) { @Override public List assign(long timestamp) { long startTime = DateTimeUtils.getWindowStartTime(timestamp, windowSize); - return singletonList(new Window(startTime, startTime + windowSize)); + return List.of(new Window(startTime, startTime + windowSize)); } } 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 53a5a281528..56e2f6f704b 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java @@ -5,8 +5,6 @@ package org.opensearch.sql.analysis; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -408,9 +406,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")))), - emptyList(), + List.of(), ImmutableList.of(alias("string_value", qualifiedName("string_value"))), - emptyList()), + List.of()), compare(">", aggregate("MIN", qualifiedName("integer_value")), intLiteral(10)))); } @@ -491,7 +489,7 @@ public void rename_to_invalid_expression() { AstDSL.alias( "avg(integer_value)", AstDSL.aggregate("avg", field("integer_value")))), - emptyList(), + List.of(), ImmutableList.of(), AstDSL.defaultStatsArgs()), AstDSL.map( @@ -894,7 +892,7 @@ public void remove_source() { DSL.ref("double_value", DOUBLE)), AstDSL.projectWithArg( AstDSL.relation("schema"), - singletonList(argument("exclude", booleanLiteral(true))), + List.of(argument("exclude", booleanLiteral(true))), AstDSL.field("integer_value"), AstDSL.field("double_value"))); } @@ -956,9 +954,9 @@ public void sort_with_aggregator() { ImmutableList.of( AstDSL.alias( "avg(integer_value)", function("avg", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of(AstDSL.alias("string_value", qualifiedName("string_value"))), - emptyList()), + List.of()), field( function("avg", qualifiedName("integer_value")), argument("asc", booleanLiteral(true)))), @@ -1041,8 +1039,8 @@ public void window_function() { "window_function", AstDSL.window( AstDSL.function("row_number"), - singletonList(AstDSL.qualifiedName("string_value")), - singletonList( + List.of(AstDSL.qualifiedName("string_value")), + List.of( ImmutablePair.of(DEFAULT_ASC, AstDSL.qualifiedName("integer_value"))))))); } @@ -1098,13 +1096,13 @@ public void nested_group_by_clause_throws_syntax_exception() { AstDSL.project( AstDSL.agg( AstDSL.relation("schema"), - emptyList(), - emptyList(), + List.of(), + List.of(), ImmutableList.of( alias( "nested(message.info)", function("nested", qualifiedName("message", "info")))), - emptyList())))); + List.of())))); assertEquals( "Falling back to legacy engine. Nested function is not supported in WHERE," + " GROUP BY, and HAVING clauses.", @@ -1128,9 +1126,9 @@ public void sql_group_by_field() { AstDSL.relation("schema"), ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of(alias("string_value", qualifiedName("string_value"))), - emptyList()), + List.of()), AstDSL.alias("string_value", qualifiedName("string_value")), AstDSL.alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value"))))); } @@ -1153,10 +1151,10 @@ public void sql_group_by_function() { AstDSL.relation("schema"), ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of( alias("abs(long_value)", function("abs", qualifiedName("long_value")))), - emptyList()), + List.of()), AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))), AstDSL.alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value"))))); } @@ -1179,10 +1177,10 @@ public void sql_group_by_function_in_uppercase() { AstDSL.relation("schema"), ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of( alias("ABS(long_value)", function("ABS", qualifiedName("long_value")))), - emptyList()), + List.of()), AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))), AstDSL.alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value"))))); } @@ -1205,10 +1203,10 @@ public void sql_expression_over_one_aggregation() { AstDSL.relation("schema"), ImmutableList.of( alias("avg(integer_value)", aggregate("avg", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of( alias("abs(long_value)", function("abs", qualifiedName("long_value")))), - emptyList()), + List.of()), AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))), AstDSL.alias( "abs(avg(integer_value)", @@ -1239,10 +1237,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")))), - emptyList(), + List.of(), ImmutableList.of( alias("abs(long_value)", function("abs", qualifiedName("long_value")))), - emptyList()), + List.of()), AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))), AstDSL.alias( "sum(integer_value)-avg(integer_value)", @@ -1280,7 +1278,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))))), - emptyList()), + List.of()), DSL.named( "count(string_value) filter(where integer_value > 1)", DSL.ref("count(string_value) filter(where integer_value > 1)", INTEGER))), @@ -1294,9 +1292,9 @@ public void named_aggregator_with_condition() { "count", qualifiedName("string_value"), function(">", qualifiedName("integer_value"), intLiteral(1))))), - emptyList(), - emptyList(), - emptyList()), + List.of(), + List.of(), + List.of()), AstDSL.alias( "count(string_value) filter(where integer_value > 1)", filteredAggregate( @@ -1320,10 +1318,10 @@ public void ppl_stats_by_fieldAndSpan() { AstDSL.relation("schema"), ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of(alias("string_value", qualifiedName("string_value"))), alias("span", span(field("long_value"), intLiteral(10), SpanUnit.NONE)), - emptyList())); + List.of())); } @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 c0ff667efc2..3548cffef57 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java @@ -5,7 +5,6 @@ package org.opensearch.sql.analysis; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; import static org.opensearch.sql.data.type.ExprCoreType.LONG; @@ -61,7 +60,7 @@ protected StorageEngine prometheusStorageEngine() { return new StorageEngine() { @Override public Collection getFunctions() { - return singletonList( + return List.of( 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 b27b8348e2f..8a7adff3fd4 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java @@ -5,7 +5,6 @@ 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; @@ -173,8 +172,7 @@ public void case_with_default_result_type_different() { @Test public void scalar_window_function() { - assertAnalyzeEqual( - DSL.rank(), AstDSL.window(AstDSL.function("rank"), emptyList(), emptyList())); + assertAnalyzeEqual(DSL.rank(), AstDSL.window(AstDSL.function("rank"), List.of(), List.of())); } @SuppressWarnings("unchecked") @@ -183,7 +181,7 @@ public void aggregate_window_function() { assertAnalyzeEqual( new AggregateWindowFunction(DSL.avg(DSL.ref("integer_value", INTEGER))), AstDSL.window( - AstDSL.aggregate("avg", qualifiedName("integer_value")), emptyList(), emptyList())); + AstDSL.aggregate("avg", qualifiedName("integer_value")), List.of(), List.of())); } @Test 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 3300ca374eb..d77f4842485 100644 --- a/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.expression; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -38,7 +37,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(singletonList(ref("age", INTEGER)), INTEGER)) + named("avg", new AvgAggregator(List.of(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/expression/function/BuiltinFunctionRepositoryTest.java b/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java index 17f63d7215c..1ddf53a8b9b 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 @@ -5,8 +5,6 @@ package org.opensearch.sql.expression.function; -import static java.util.Collections.emptyList; -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; @@ -98,7 +96,7 @@ void compile_datasource_defined_function() { repo.compile( functionProperties, - singletonList(dataSourceFunctionResolver), + List.of(dataSourceFunctionResolver), mockFunctionName, List.of(mockExpression)); verify(functionExpressionBuilder, times(1)).apply(eq(functionProperties), any()); @@ -116,7 +114,7 @@ void resolve() { BuiltinFunctionRepository repo = new BuiltinFunctionRepository(mockMap); repo.register(mockfunctionResolver); - assertEquals(functionExpressionBuilder, repo.resolve(emptyList(), functionSignature)); + assertEquals(functionExpressionBuilder, repo.resolve(List.of(), functionSignature)); } @Test @@ -124,8 +122,7 @@ void resolve_should_not_cast_arguments_in_cast_function() { when(mockExpression.toString()).thenReturn("string"); FunctionImplementation function = repo.resolve( - emptyList(), - registerFunctionResolver(CAST_TO_BOOLEAN.getName(), TIMESTAMP, BOOLEAN)) + List.of(), registerFunctionResolver(CAST_TO_BOOLEAN.getName(), TIMESTAMP, BOOLEAN)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("cast_to_boolean(string)", function.toString()); } @@ -135,7 +132,7 @@ void resolve_should_not_cast_arguments_if_same_type() { when(mockFunctionName.getFunctionName()).thenReturn("mock"); when(mockExpression.toString()).thenReturn("string"); FunctionImplementation function = - repo.resolve(emptyList(), registerFunctionResolver(mockFunctionName, STRING, STRING)) + repo.resolve(List.of(), registerFunctionResolver(mockFunctionName, STRING, STRING)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(string)", function.toString()); } @@ -145,7 +142,7 @@ void resolve_should_not_cast_arguments_if_both_numbers() { when(mockFunctionName.getFunctionName()).thenReturn("mock"); when(mockExpression.toString()).thenReturn("byte"); FunctionImplementation function = - repo.resolve(emptyList(), registerFunctionResolver(mockFunctionName, BYTE, INTEGER)) + repo.resolve(List.of(), registerFunctionResolver(mockFunctionName, BYTE, INTEGER)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(byte)", function.toString()); } @@ -160,7 +157,7 @@ void resolve_should_cast_arguments() { registerFunctionResolver(CAST_TO_BOOLEAN.getName(), STRING, STRING); FunctionImplementation function = - repo.resolve(emptyList(), signature) + repo.resolve(List.of(), signature) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(cast_to_boolean(string))", function.toString()); } @@ -171,7 +168,7 @@ void resolve_should_throw_exception_for_unsupported_conversion() { assertThrows( ExpressionEvaluationException.class, () -> - repo.resolve(emptyList(), registerFunctionResolver(mockFunctionName, BYTE, STRUCT)) + repo.resolve(List.of(), registerFunctionResolver(mockFunctionName, BYTE, STRUCT)) .apply(functionProperties, ImmutableList.of(mockExpression))); assertEquals(error.getMessage(), "Type conversion to type STRUCT is not supported"); } @@ -188,7 +185,7 @@ void resolve_unregistered() { ExpressionEvaluationException.class, () -> repo.resolve( - emptyList(), new FunctionSignature(FunctionName.of("unknown"), List.of()))); + List.of(), new FunctionSignature(FunctionName.of("unknown"), List.of()))); assertEquals("unsupported function name: unknown", exception.getMessage()); } 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 a58773fae46..71740881529 100644 --- a/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java @@ -5,8 +5,6 @@ package org.opensearch.sql.planner; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -127,7 +125,7 @@ public void visit_should_return_default_physical_operator() { remove( rename( aggregation( - filter(values(emptyList()), filterExpr), + filter(values(List.of()), filterExpr), aggregators, groupByExprs), mappings), @@ -158,8 +156,7 @@ public void visit_should_return_default_physical_operator() { PhysicalPlanDSL.rename( PhysicalPlanDSL.agg( PhysicalPlanDSL.filter( - PhysicalPlanDSL.values(emptyList()), - filterExpr), + PhysicalPlanDSL.values(List.of()), filterExpr), aggregators, groupByExprs), mappings), @@ -191,8 +188,8 @@ public void visitWindowOperator_should_return_PhysicalWindowOperator() { NamedExpression windowFunction = named(new RowNumberFunction()); WindowDefinition windowDefinition = new WindowDefinition( - singletonList(ref("state", STRING)), - singletonList(ImmutablePair.of(Sort.SortOption.DEFAULT_DESC, ref("age", INTEGER)))); + List.of(ref("state", STRING)), + List.of(ImmutablePair.of(Sort.SortOption.DEFAULT_DESC, ref("age", INTEGER)))); NamedExpression[] projectList = { named("state", ref("state", STRING)), named("row_number", ref("row_number", INTEGER)) @@ -282,11 +279,11 @@ public void visitLimit_support_return_takeOrdered() { // replace SortOperator + LimitOperator with TakeOrderedOperator Pair sort = ImmutablePair.of(Sort.SortOption.DEFAULT_ASC, ref("a", INTEGER)); - var logicalValues = values(emptyList()); + var logicalValues = values(List.of()); var logicalSort = sort(logicalValues, sort); var logicalLimit = limit(logicalSort, 10, 5); PhysicalPlan physicalPlanTree = - PhysicalPlanDSL.takeOrdered(PhysicalPlanDSL.values(emptyList()), 10, 5, sort); + PhysicalPlanDSL.takeOrdered(PhysicalPlanDSL.values(List.of()), 10, 5, sort); assertEquals(physicalPlanTree, logicalLimit.accept(implementor, null)); // don't replace if LimitOperator's child is not SortOperator @@ -297,7 +294,7 @@ public void visitLimit_support_return_takeOrdered() { physicalPlanTree = PhysicalPlanDSL.limit( PhysicalPlanDSL.eval( - PhysicalPlanDSL.sort(PhysicalPlanDSL.values(emptyList()), sort), newEvalField), + PhysicalPlanDSL.sort(PhysicalPlanDSL.values(List.of()), sort), newEvalField), 10, 5); assertEquals(physicalPlanTree, logicalLimit.accept(implementor, 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 d454469ba2b..faca949df05 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 @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInRelativeOrder; @@ -39,8 +37,8 @@ public void sum_without_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - singletonList(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), - emptyList()); + List.of(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), + List.of()); List result = execute(plan); assertEquals(1, result.size()); assertThat( @@ -53,8 +51,8 @@ public void avg_with_one_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), - singletonList(DSL.named("action", DSL.ref("action", STRING)))); + List.of(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + List.of(DSL.named("action", DSL.ref("action", STRING)))); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -69,7 +67,7 @@ public void avg_with_two_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + List.of(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)))); @@ -91,8 +89,8 @@ public void sum_with_one_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - singletonList(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), - singletonList(DSL.named("action", DSL.ref("action", STRING)))); + List.of(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), + List.of(DSL.named("action", DSL.ref("action", STRING)))); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -107,8 +105,8 @@ public void millisecond_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + List.of( DSL.named( "span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6 * 1000), "ms")))); List result = execute(plan); @@ -128,8 +126,8 @@ public void second_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + List.of( DSL.named("span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6), "s")))); List result = execute(plan); assertEquals(2, result.size()); @@ -148,8 +146,8 @@ public void minute_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("minute", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("minute", TIMESTAMP)))), + List.of( DSL.named("span", DSL.span(DSL.ref("minute", TIMESTAMP), DSL.literal(5), "m")))); List result = execute(plan); assertEquals(3, result.size()); @@ -167,9 +165,8 @@ public void minute_span() { plan = new AggregationOperator( testScan(datetimeInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(30), "m")))); + 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")))); result = execute(plan); assertEquals(4, result.size()); assertThat( @@ -190,8 +187,8 @@ public void hour_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), - singletonList(DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(1), "h")))); + 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")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -210,8 +207,8 @@ public void day_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count(day)", DSL.count(DSL.ref("day", DATE)))), - singletonList(DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")))); + 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")))); List result = execute(plan); assertEquals(4, result.size()); assertThat( @@ -229,9 +226,8 @@ public void day_span() { plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(30), "d")))); + 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")))); result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -250,9 +246,8 @@ public void week_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(5), "w")))); + 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")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -271,9 +266,8 @@ public void month_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(1), "M")))); + 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")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -289,8 +283,8 @@ public void month_span() { plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), + List.of( DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "M")))); result = execute(plan); assertEquals(4, result.size()); @@ -310,8 +304,8 @@ public void month_span() { plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - singletonList( + 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 * 12), "M")))); result = execute(plan); @@ -333,8 +327,8 @@ public void quarter_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), + List.of( DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "q")))); List result = execute(plan); assertEquals(2, result.size()); @@ -350,8 +344,8 @@ public void quarter_span() { plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - singletonList( + 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 * 4), "q")))); result = execute(plan); assertEquals(3, result.size()); @@ -372,9 +366,8 @@ public void year_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10), "y")))); + 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")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -394,9 +387,8 @@ public void integer_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("integer", INTEGER), DSL.literal(1), "")))); + 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), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -409,8 +401,8 @@ public void integer_field() { plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), - singletonList( + 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.5), "")))); result = execute(plan); assertEquals(3, result.size()); @@ -427,8 +419,8 @@ public void long_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), - singletonList(DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1), "")))); + 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), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -441,9 +433,8 @@ public void long_field() { plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1.5), "")))); + 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), "")))); result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -459,9 +450,8 @@ public void float_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1), "")))); + 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), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -474,9 +464,8 @@ public void float_field() { plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1.5), "")))); + 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), "")))); result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -492,9 +481,8 @@ public void double_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1), "")))); + 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), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -507,9 +495,8 @@ public void double_field() { plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1.5), "")))); + 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), "")))); result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -525,7 +512,7 @@ public void twoBucketsSpanAndLong() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), + List.of(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)))); @@ -550,7 +537,7 @@ public void twoBucketsSpanAndLong() { plan = new AggregationOperator( testScan(compoundInputs), - singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), + List.of(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)), @@ -637,7 +624,7 @@ public void aggregate_with_two_groups_with_windowing() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), + List.of(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")))); @@ -689,7 +676,7 @@ public void aggregate_with_three_groups_with_windowing() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), + List.of(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")), @@ -749,8 +736,8 @@ public void copyOfAggregationOperatorShouldSame() { AggregationOperator plan = new AggregationOperator( testScan(datetimeInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + List.of( 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 17fb128aced..1b8cf7f5603 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,7 +5,6 @@ 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; @@ -110,7 +109,7 @@ public static Stream getPhysicalPlanForTest() { PhysicalPlan project = project(plan, named("ref", ref)); PhysicalPlan window = - window(plan, named(DSL.rowNumber()), new WindowDefinition(emptyList(), emptyList())); + window(plan, named(DSL.rowNumber()), new WindowDefinition(List.of(), List.of())); PhysicalPlan remove = remove(plan, ref); @@ -122,7 +121,7 @@ public static Stream getPhysicalPlanForTest() { PhysicalPlan dedupe = dedupe(plan, ref); - PhysicalPlan values = values(emptyList()); + PhysicalPlan values = values(List.of()); 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 70e2ba18661..e6b70fdbe33 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 @@ -5,8 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -28,8 +26,8 @@ public void rare_without_group() { new RareTopNOperator( new TestScan(), CommandType.RARE, - singletonList(DSL.ref("action", ExprCoreType.STRING)), - emptyList()); + List.of(DSL.ref("action", ExprCoreType.STRING)), + List.of()); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -45,8 +43,8 @@ public void rare_with_group() { new RareTopNOperator( new TestScan(), CommandType.RARE, - singletonList(DSL.ref("response", ExprCoreType.INTEGER)), - singletonList(DSL.ref("action", ExprCoreType.STRING))); + List.of(DSL.ref("response", ExprCoreType.INTEGER)), + List.of(DSL.ref("action", ExprCoreType.STRING))); List result = execute(plan); assertEquals(4, result.size()); assertThat( @@ -64,8 +62,8 @@ public void top_without_group() { new RareTopNOperator( new TestScan(), CommandType.TOP, - singletonList(DSL.ref("action", ExprCoreType.STRING)), - emptyList()); + List.of(DSL.ref("action", ExprCoreType.STRING)), + List.of()); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -82,8 +80,8 @@ public void top_n_without_group() { new TestScan(), CommandType.TOP, 1, - singletonList(DSL.ref("action", ExprCoreType.STRING)), - emptyList()); + List.of(DSL.ref("action", ExprCoreType.STRING)), + List.of()); List result = execute(plan); assertEquals(1, result.size()); assertThat( @@ -97,8 +95,8 @@ public void top_n_with_group() { new TestScan(), CommandType.TOP, 1, - singletonList(DSL.ref("response", ExprCoreType.INTEGER)), - singletonList(DSL.ref("action", ExprCoreType.STRING))); + List.of(DSL.ref("response", ExprCoreType.INTEGER)), + List.of(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 fe55275e3b8..47d557acd6c 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 @@ -5,7 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -34,8 +33,8 @@ public void avg_aggregation_rename() { new RenameOperator( new AggregationOperator( new TestScan(), - singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), - singletonList(DSL.named("action", DSL.ref("action", STRING)))), + List.of(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + List.of(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/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java index 84cb3d58a03..be866452b73 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 @@ -5,8 +5,6 @@ package org.opensearch.sql.datasources.service; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -105,7 +103,7 @@ void testGetDataSourceForNonExistingDataSource() { @Test void testGetDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("test", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); + metadata("test", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); doNothing().when(dataSourceUserAuthorizationHelper).authorizeDataSource(dataSourceMetadata); when(dataSourceMetadataStorage.getDataSourceMetadata("test")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -120,10 +118,7 @@ void testGetDataSourceSuccessCase() { void testGetDataSourceWithAuthorizationFailure() { DataSourceMetadata dataSourceMetadata = metadata( - "test", - DataSourceType.OPENSEARCH, - singletonList("prometheus_access"), - ImmutableMap.of()); + "test", DataSourceType.OPENSEARCH, List.of("prometheus_access"), ImmutableMap.of()); doThrow( new SecurityException( "User is not authorized to access datasource test. User should be mapped to any of" @@ -149,7 +144,7 @@ void testGetDataSourceWithAuthorizationFailure() { void testCreateDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); dataSourceService.createDataSource(dataSourceMetadata); verify(dataSourceMetadataStorage, times(1)).createDataSourceMetadata(dataSourceMetadata); verify(dataSourceFactory, times(1)).createDataSource(dataSourceMetadata); @@ -157,7 +152,7 @@ void testCreateDataSourceSuccessCase() { when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn( Optional.ofNullable( - metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()))); + metadata("testDS", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()))); DataSource dataSource = dataSourceService.getDataSource("testDS"); assertEquals("testDS", dataSource.getName()); assertEquals(storageEngine, dataSource.getStorageEngine()); @@ -175,7 +170,7 @@ void testGetDataSourceMetadataSet() { .thenReturn( new ArrayList<>() { { - add(metadata("testDS", DataSourceType.PROMETHEUS, emptyList(), properties)); + add(metadata("testDS", DataSourceType.PROMETHEUS, List.of(), properties)); } }); Set dataSourceMetadataSet = dataSourceService.getDataSourceMetadata(false); @@ -196,7 +191,7 @@ void testGetDataSourceMetadataSetWithDefaultDatasource() { .thenReturn( new ArrayList<>() { { - add(metadata("testDS", DataSourceType.PROMETHEUS, emptyList(), ImmutableMap.of())); + add(metadata("testDS", DataSourceType.PROMETHEUS, List.of(), ImmutableMap.of())); } }); Set dataSourceMetadataSet = dataSourceService.getDataSourceMetadata(true); @@ -209,7 +204,7 @@ void testGetDataSourceMetadataSetWithDefaultDatasource() { @Test void testUpdateDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); dataSourceService.updateDataSource(dataSourceMetadata); verify(dataSourceMetadataStorage, times(1)).updateDataSourceMetadata(dataSourceMetadata); verify(dataSourceFactory, times(1)).createDataSource(dataSourceMetadata); @@ -218,8 +213,7 @@ void testUpdateDataSourceSuccessCase() { @Test void testUpdateDefaultDataSource() { DataSourceMetadata dataSourceMetadata = - metadata( - DEFAULT_DATASOURCE_NAME, DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); + metadata(DEFAULT_DATASOURCE_NAME, DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); UnsupportedOperationException unsupportedOperationException = assertThrows( UnsupportedOperationException.class, @@ -263,7 +257,7 @@ void testPatchDataSourceSuccessCase() { STATUS_FIELD, DataSourceStatus.DISABLED)); DataSourceMetadata getData = - metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.ofNullable(getData)); @@ -326,7 +320,7 @@ void testRemovalOfAuthorizationInfo() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -351,7 +345,7 @@ void testRemovalOfAuthorizationInfoForAccessKeyAndSecretKye() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -378,7 +372,7 @@ void testRemovalOfAuthorizationInfoForGlueWithRoleARN() { .setName("testGlue") .setProperties(properties) .setConnector(DataSourceType.S3GLUE) - .setAllowedRoles(singletonList("glue_access")) + .setAllowedRoles(List.of("glue_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testGlue")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -420,7 +414,7 @@ void testGetDataSourceMetadataForSpecificDataSourceName() { when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn( Optional.ofNullable( - metadata("testDS", DataSourceType.PROMETHEUS, emptyList(), properties))); + metadata("testDS", DataSourceType.PROMETHEUS, List.of(), properties))); DataSourceMetadata dataSourceMetadata = this.dataSourceService.getDataSourceMetadata("testDS"); assertTrue(dataSourceMetadata.getProperties().containsKey("prometheus.uri")); assertTrue(dataSourceMetadata.getProperties().containsKey("prometheus.auth.type")); @@ -441,7 +435,7 @@ void testVerifyDataSourceAccessAndGetRawDataSourceMetadataWithDisabledData() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .setDataSourceStatus(DataSourceStatus.DISABLED) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) @@ -468,7 +462,7 @@ void testVerifyDataSourceAccessAndGetRawDataSourceMetadata() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("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 0a363699cd3..efc99e24556 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 @@ -5,8 +5,6 @@ package org.opensearch.sql.datasources.storage; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.opensearch.sql.datasource.model.DataSourceStatus.ACTIVE; import static org.opensearch.sql.datasources.storage.OpenSearchDataSourceMetadataStorage.DATASOURCE_INDEX_NAME; @@ -673,7 +671,7 @@ public void testWhenDataSourcesAreDisabled() { Optional.empty(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata("dummy")); Assertions.assertEquals( - emptyList(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata()); + List.of(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata()); Assertions.assertThrows( IllegalStateException.class, @@ -713,7 +711,7 @@ private String getBasicDataSourceMetadataString() throws JsonProcessingException .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -733,7 +731,7 @@ private String getAWSSigv4DataSourceMetadataString() throws JsonProcessingExcept .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -750,7 +748,7 @@ private String getDataSourceMetadataStringWithBasicAuthentication() .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -763,7 +761,7 @@ private String getDataSourceMetadataStringWithNoAuthentication() throws JsonProc .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -778,7 +776,7 @@ private DataSourceMetadata getDataSourceMetadata() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); } 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 2415ff486b1..798d1c23e93 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 @@ -5,7 +5,6 @@ package org.opensearch.sql.correctness.tests; -import static java.util.Collections.emptyList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -24,15 +23,15 @@ public class DBResultTest { @Test public void dbResultFromDifferentDbNameShouldEqual() { - 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()); + DBResult result1 = new DBResult("DB 1", List.of(new Type("name", "VARCHAR")), List.of()); + DBResult result2 = new DBResult("DB 2", List.of(new Type("name", "VARCHAR")), List.of()); assertEquals(result1, result2); } @Test public void dbResultWithDifferentColumnShouldNotEqual() { - 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()); + DBResult result1 = new DBResult("DB 1", List.of(new Type("name", "VARCHAR")), List.of()); + DBResult result2 = new DBResult("DB 2", List.of(new Type("age", "INT")), List.of()); assertNotEquals(result1, result2); } @@ -68,8 +67,8 @@ public void dbResultInOrderWithSameRowsInDifferentOrderShouldNotEqual() { @Test public void dbResultWithDifferentColumnTypeShouldNotEqual() { - 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()); + DBResult result1 = new DBResult("DB 1", List.of(new Type("age", "FLOAT")), List.of()); + DBResult result2 = new DBResult("DB 2", List.of(new Type("age", "INT")), List.of()); assertNotEquals(result1, result2); } @@ -79,12 +78,10 @@ public void shouldExplainColumnTypeDifference() { new DBResult( "DB 1", Arrays.asList(new Type("name", "VARCHAR"), new Type("age", "FLOAT")), - emptyList()); + List.of()); DBResult result2 = new DBResult( - "DB 2", - Arrays.asList(new Type("name", "VARCHAR"), new Type("age", "INT")), - emptyList()); + "DB 2", Arrays.asList(new Type("name", "VARCHAR"), new Type("age", "INT")), List.of()); assertEquals( "Schema type at [1] is different: " 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 daf084d3711..962642a540c 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,7 +5,6 @@ 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; @@ -22,7 +21,7 @@ public class TestConfigTest { @Test public void testDefaultConfig() { - TestConfig config = new TestConfig(emptyMap()); + TestConfig config = new TestConfig(Map.of()); assertThat(config.getOpenSearchHostUrl(), is(emptyString())); assertThat( config.getOtherDbConnectionNameAndUrls(), 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 f90b42cda27..03b6c3fb64f 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 @@ -5,7 +5,6 @@ package org.opensearch.sql.legacy; -import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toSet; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -157,7 +156,7 @@ public void selectScore() throws IOException { "SELECT _score FROM %s WHERE SCORE(match_phrase(phrase, 'brown fox'))", TestsConstants.TEST_INDEX_PHRASE)); - List fields = singletonList("_score"); + List fields = List.of("_score"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } @@ -277,7 +276,7 @@ public void groupBySingleField() throws IOException { String.format( Locale.ROOT, "SELECT * FROM %s GROUP BY age", TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = singletonList("age"); + List fields = List.of("age"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } @@ -398,7 +397,7 @@ public void aggregationFunctionInSelectNoGroupBy() throws IOException { Locale.ROOT, "SELECT SUM(age) FROM %s", TestsConstants.TEST_INDEX_ACCOUNT)); String ageSum = "SUM(age)"; - assertContainsColumns(getSchema(response), singletonList(ageSum)); + assertContainsColumns(getSchema(response), List.of(ageSum)); JSONArray dataRows = getDataRows(response); for (int i = 0; i < dataRows.length(); i++) { @@ -433,7 +432,7 @@ public void aggregationFunctionInHaving() throws IOException { TestsConstants.TEST_INDEX_ACCOUNT)); String ageSum = "gender"; - assertContainsColumns(getSchema(response), singletonList(ageSum)); + assertContainsColumns(getSchema(response), List.of(ageSum)); JSONArray dataRows = getDataRows(response); assertEquals(1, dataRows.length()); @@ -555,7 +554,7 @@ public void joinQuerySelectOnlyOnOneTable() throws Exception { TestsConstants.TEST_INDEX_ACCOUNT, TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = singletonList("b1.age"); + List fields = List.of("b1.age"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } 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 0f65ee1b996..2eb0f4009dc 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,7 +5,6 @@ package org.opensearch.sql.legacy.antlr.semantic.scope; -import static java.util.Collections.emptyMap; import static java.util.Collections.emptyNavigableMap; import java.util.EnumMap; @@ -67,7 +66,7 @@ public Map lookupByPrefix(Symbol prefix) { .filter(entry -> null != entry.getValue().get()) .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().get())); } - return emptyMap(); + return Map.of(); } /** 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 5e89b3b8aef..29a1bdebb90 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,7 +5,6 @@ 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; @@ -377,14 +376,14 @@ private T visitSelectItem(ParserRuleContext item, UidContext uid) { } private T reduce(T reducer, ParserRuleContext ctx) { - return reduce(reducer, (ctx == null) ? emptyList() : ctx.children); + return reduce(reducer, (ctx == null) ? List.of() : ctx.children); } /** Make constructor apply arguments and return result type */ private T reduce(T reducer, List nodes) { List args; if (nodes == null) { - args = emptyList(); + args = List.of(); } 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 89f8f9ac89e..01416f442a2 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,7 +5,6 @@ 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; @@ -31,7 +30,7 @@ public class FieldMapping { private final Map specifiedFieldsByName; public FieldMapping(String fieldName) { - this(fieldName, emptyMap(), emptyMap()); + this(fieldName, Map.of(), Map.of()); } 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 61e707e8efd..4292a954328 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,8 +5,6 @@ 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; @@ -42,7 +40,7 @@ public class IndexMappings implements Mappings { private final Map indexMappings; public IndexMappings() { - this.indexMappings = emptyMap(); + this.indexMappings = Map.of(); } public IndexMappings(Metadata metaData) { 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 0c0d50258d9..bd248f3b7e0 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,8 +5,6 @@ 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; @@ -130,7 +128,7 @@ protected Collection> prefetch() throws Exception { // 4.Clean up and close right cleanUpAndCloseRight(); } - return emptyList(); + return List.of(); } /** 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 abfcf273ad5..715cd61430f 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,8 +5,6 @@ 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; @@ -67,7 +65,7 @@ public void open(ExecuteParams params) throws Exception { @Override protected Collection> prefetch() { if (isDone) { - return emptyList(); + return List.of(); } 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 fbdcca2bb0e..8a47a25fa9b 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,9 +5,6 @@ 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; @@ -19,7 +16,7 @@ public class SymbolSimilarityTest { @Test public void noneCandidateShouldReturnTargetStringItself() { String target = "test"; - String mostSimilarSymbol = new SimilarSymbols(emptyList()).mostSimilarTo(target); + String mostSimilarSymbol = new SimilarSymbols(List.of()).mostSimilarTo(target); Assert.assertEquals(target, mostSimilarSymbol); } @@ -27,7 +24,7 @@ public void noneCandidateShouldReturnTargetStringItself() { public void singleCandidateShouldReturnTheOnlyCandidate() { String target = "test"; String candidate = "hello"; - String mostSimilarSymbol = new SimilarSymbols(singletonList(candidate)).mostSimilarTo(target); + String mostSimilarSymbol = new SimilarSymbols(List.of(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 ed2611786a1..05d91b22615 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,7 +5,6 @@ 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; @@ -29,14 +28,14 @@ public class FieldMappingTest { @Test public void testFieldMatchesWildcardPatternSpecifiedInQuery() { assertThat( - new FieldMapping("employee.first", emptyMap(), fieldsSpecifiedInQuery("employee.*")), + new FieldMapping("employee.first", Map.of(), fieldsSpecifiedInQuery("employee.*")), isWildcardSpecified(true)); } @Test public void testFieldMismatchesWildcardPatternSpecifiedInQuery() { assertThat( - new FieldMapping("employee.first", emptyMap(), fieldsSpecifiedInQuery("manager.*")), + new FieldMapping("employee.first", Map.of(), fieldsSpecifiedInQuery("manager.*")), isWildcardSpecified(false)); } @@ -76,7 +75,7 @@ public void testDeepNestedField() { "employee.location.city", new BytesArray( "{\n" + " \"city\" : {\n" + " \"type\" : \"text\"\n" + " }\n" + "}"))), - emptyMap()), + Map.of()), 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 eea1c9a87a3..f34defca6b4 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,7 +6,6 @@ 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; @@ -43,7 +42,7 @@ public class AsyncRestExecutorTest { @Mock private Client client; - private final Map params = emptyMap(); + private final Map params = Map.of(); @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 6ff907ba30f..42019a2bfbe 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,7 +5,6 @@ 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; @@ -104,7 +103,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(emptyList()).when(settings).getSettings(); + doReturn(List.of()).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 811d05c16a9..474daab055e 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,7 +5,6 @@ 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; @@ -242,7 +241,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(emptyList()).when(settings).getSettings(); + doReturn(List.of()).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 f274e358114..46f96f6e2df 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 @@ -5,7 +5,6 @@ package org.opensearch.sql.opensearch.planner.physical; -import static java.util.Collections.singletonList; import static org.opensearch.sql.utils.MLCommonsConstants.ANOMALY_RATE; import static org.opensearch.sql.utils.MLCommonsConstants.ANOMALY_SCORE_THRESHOLD; import static org.opensearch.sql.utils.MLCommonsConstants.CATEGORY_FIELD; @@ -115,7 +114,7 @@ public ExprValue next() { @Override public List getChild() { - return singletonList(input); + return List.of(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 3ae0f43fcef..10342f6d4db 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 @@ -5,7 +5,6 @@ package org.opensearch.sql.opensearch.planner.physical; -import static java.util.Collections.singletonList; import static org.opensearch.ml.common.FunctionName.KMEANS; import static org.opensearch.sql.utils.MLCommonsConstants.CENTROIDS; import static org.opensearch.sql.utils.MLCommonsConstants.DISTANCE_TYPE; @@ -91,7 +90,7 @@ public ExprValue next() { @Override public List getChild() { - return singletonList(input); + return List.of(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 00a28342efd..ecb486f39f4 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 @@ -5,8 +5,6 @@ package org.opensearch.sql.opensearch.planner.physical; -import static java.util.Collections.singletonList; - import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -99,7 +97,7 @@ public ExprValue next() { @Override public List getChild() { - return singletonList(input); + return List.of(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 3a619154999..b3bdece8164 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 @@ -13,8 +13,6 @@ package org.opensearch.sql.opensearch.response.agg; -import static java.util.Collections.singletonList; - import java.util.Arrays; import java.util.List; import java.util.Map; @@ -35,6 +33,6 @@ public NoBucketAggregationParser(List metricParserList) { @Override public List> parse(Aggregations aggregations) { - return singletonList(metricsParser.parse(aggregations)); + return List.of(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 7f14cb1fe05..e46fdb0b81b 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 @@ -5,8 +5,6 @@ package org.opensearch.sql.opensearch.storage.script.aggregation; -import static java.util.Collections.singletonList; - import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -78,7 +76,7 @@ public AggregationQueryBuilder(ExpressionSerializer serializer) { } else { GroupSortOrder groupSortOrder = new GroupSortOrder(sortList); return Pair.of( - singletonList( + List.of( 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 fa0fe191051..9cf80f0cb44 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,7 +5,6 @@ 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; @@ -131,6 +130,6 @@ private BoolQueryBuilder buildBoolQuery( private ScriptQueryBuilder buildScriptQuery(FunctionExpression node) { return new ScriptQueryBuilder( new Script( - DEFAULT_SCRIPT_TYPE, EXPRESSION_LANG_NAME, serializer.serialize(node), emptyMap())); + DEFAULT_SCRIPT_TYPE, EXPRESSION_LANG_NAME, serializer.serialize(node), Map.of())); } } 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 da06c1eb669..f69cce7f8b2 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,7 +5,6 @@ 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.*; @@ -184,13 +183,12 @@ 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(emptyList(), ImmutableList.of(sortItem)); + WindowDefinition windowDefinition = new WindowDefinition(List.of(), ImmutableList.of(sortItem)); assertEquals( - window(resourceMonitor(sort(values(emptyList()), sortItem)), rank, windowDefinition), + window(resourceMonitor(sort(values(List.of()), sortItem)), rank, windowDefinition), executionProtector.protect( - window(sort(values(emptyList()), sortItem), rank, windowDefinition))); + window(sort(values(List.of()), sortItem), rank, windowDefinition))); } @Test @@ -209,13 +207,12 @@ 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(emptyList(), ImmutableList.of(sortItem)); + WindowDefinition windowDefinition = new WindowDefinition(List.of(), ImmutableList.of(sortItem)); assertEquals( - window(resourceMonitor(sort(values(emptyList()), sortItem)), avg, windowDefinition), + window(resourceMonitor(sort(values(List.of()), sortItem)), avg, windowDefinition), executionProtector.protect( - window(sort(values(emptyList()), sortItem), avg, windowDefinition))); + window(sort(values(List.of()), sortItem), avg, windowDefinition))); } @Test @@ -232,7 +229,7 @@ void test_visitMLcommons() { NodeClient nodeClient = mock(NodeClient.class); MLCommonsOperator mlCommonsOperator = new MLCommonsOperator( - values(emptyList()), + values(List.of()), "kmeans", new HashMap() { { @@ -253,7 +250,7 @@ void test_visitAD() { NodeClient nodeClient = mock(NodeClient.class); ADOperator adOperator = new ADOperator( - values(emptyList()), + values(List.of()), new HashMap() { { put("shingle_size", new Literal(8, DataType.INTEGER)); @@ -272,7 +269,7 @@ void test_visitML() { NodeClient nodeClient = mock(NodeClient.class); MLOperator mlOperator = new MLOperator( - values(emptyList()), + values(List.of()), new HashMap() { { put("action", new Literal("train", DataType.STRING)); @@ -293,11 +290,11 @@ void test_visitNested() { Set args = Set.of("message.info"); Map> groupedFieldsByPath = Map.of("message", List.of("message.info")); NestedOperator nestedOperator = - new NestedOperator(values(emptyList()), args, groupedFieldsByPath); + new NestedOperator(values(List.of()), args, groupedFieldsByPath); assertEquals( executionProtector.doProtect(nestedOperator), - executionProtector.visitNested(nestedOperator, values(emptyList()))); + executionProtector.visitNested(nestedOperator, values(List.of()))); } @Test @@ -313,7 +310,7 @@ public void test_visitTakeOrdered() { Pair sort = ImmutablePair.of(Sort.SortOption.DEFAULT_ASC, ref("a", INTEGER)); TakeOrderedOperator takeOrdered = - PhysicalPlanDSL.takeOrdered(PhysicalPlanDSL.values(emptyList()), 10, 5, sort); + PhysicalPlanDSL.takeOrdered(PhysicalPlanDSL.values(List.of()), 10, 5, sort); assertEquals( resourceMonitor(takeOrdered), executionProtector.visitTakeOrdered(takeOrdered, null)); } 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 984c98f8033..5597ca12130 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,7 +5,6 @@ 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; @@ -94,7 +93,7 @@ void isEmpty() { assertTrue(response.isEmpty()); when(searchResponse.getHits()).thenReturn(SearchHits.empty()); - when(searchResponse.getAggregations()).thenReturn(new Aggregations(emptyList())); + when(searchResponse.getAggregations()).thenReturn(new Aggregations(List.of())); 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 b0769b950c7..98b7382b3b0 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 @@ -5,8 +5,6 @@ package org.opensearch.sql.opensearch.storage.scan; -import static java.util.Collections.emptyMap; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; @@ -332,10 +330,10 @@ void test_limit_push_down() { void test_highlight_push_down() { assertEqualsAfterOptimization( project( - indexScanBuilder(withHighlightPushedDown("*", emptyMap())), + indexScanBuilder(withHighlightPushedDown("*", Map.of())), DSL.named("highlight(*)", new HighlightExpression(DSL.literal("*")))), project( - highlight(relation("schema", table), DSL.literal("*"), emptyMap()), + highlight(relation("schema", table), DSL.literal("*"), Map.of()), DSL.named("highlight(*)", new HighlightExpression(DSL.literal("*"))))); } @@ -642,7 +640,7 @@ private Runnable withAggregationPushedDown( CompositeAggregationBuilder aggBuilder = AggregationBuilders.composite( "composite_buckets", - singletonList( + List.of( new TermsValuesSourceBuilder(aggregation.groupBy) .field(aggregation.groupBy) .order(aggregation.sortBy.getSortOrder() == ASC ? "asc" : "desc") @@ -653,7 +651,7 @@ private Runnable withAggregationPushedDown( AggregationBuilders.avg(aggregation.aggregateName).field(aggregation.aggregateBy)) .size(AggregationQueryBuilder.AGGREGATION_BUCKET_SIZE); - List aggBuilders = singletonList(aggBuilder); + List aggBuilders = List.of(aggBuilder); OpenSearchAggregationResponseParser responseParser = new CompositeAggregationParser(new SingleValueParser(aggregation.aggregateName)); 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 13769ef2266..cb55fd3cfb2 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 @@ -5,8 +5,6 @@ package org.opensearch.sql.opensearch.storage.script.aggregation; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -281,7 +279,7 @@ void should_build_composite_aggregation_for_expression() { List.of( named( "avg(balance)", - new AvgAggregator(singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), + new AvgAggregator(List.of(DSL.abs(ref("balance", INTEGER))), INTEGER))), List.of(named("age", DSL.asin(ref("age", INTEGER)))))); } @@ -339,7 +337,7 @@ void should_build_type_mapping_for_expression() { List.of( named( "avg(balance)", - new AvgAggregator(singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), + new AvgAggregator(List.of(DSL.abs(ref("balance", INTEGER))), INTEGER))), List.of(named("age", DSL.asin(ref("age", INTEGER))))), containsInAnyOrder( map("avg(balance)", OpenSearchDataType.of(INTEGER)), @@ -361,7 +359,7 @@ void should_build_aggregation_without_bucket() { List.of( named( "avg(balance)", new AvgAggregator(List.of(ref("balance", INTEGER)), INTEGER))), - emptyList())); + List.of())); } @Test @@ -396,7 +394,7 @@ void should_build_filter_aggregation() { "avg(age) filter(where age > 34)", new AvgAggregator(List.of(ref("age", INTEGER)), INTEGER) .condition(DSL.greater(ref("age", INTEGER), literal(20))))), - emptyList())); + List.of())); } @Test @@ -458,7 +456,7 @@ void should_build_type_mapping_without_bucket() { List.of( named( "avg(balance)", new AvgAggregator(List.of(ref("balance", INTEGER)), INTEGER))), - emptyList()), + List.of()), containsInAnyOrder(map("avg(balance)", OpenSearchDataType.of(INTEGER)))); } 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 6d90cce7046..d25c9dc11fe 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,7 +6,6 @@ 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; @@ -174,7 +173,7 @@ ExprScriptAssertion docValues(String name1, Object value1, String name2, Object ExprScriptAssertion evaluate(Expression expr) { ExpressionAggregationScript script = - new ExpressionAggregationScript(expr, lookup, context, emptyMap()); + new ExpressionAggregationScript(expr, lookup, context, Map.of()); actual = script.execute(); return this; } 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 8c6ff070833..bfdc2392b2d 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 @@ -5,7 +5,6 @@ package org.opensearch.sql.opensearch.storage.script.aggregation.dsl; -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.Mockito.when; @@ -335,11 +334,10 @@ void should_build_cardinality_aggregation() { + " }%n" + "}"), buildQuery( - singletonList( + List.of( named( "count(distinct name)", - new CountAggregator(singletonList(ref("name", STRING)), INTEGER) - .distinct(true))))); + new CountAggregator(List.of(ref("name", STRING)), INTEGER).distinct(true))))); } @Test @@ -369,10 +367,10 @@ void should_build_filtered_cardinality_aggregation() { + " }%n" + "}"), buildQuery( - singletonList( + List.of( named( "count(distinct name) filter(where age > 30)", - new CountAggregator(singletonList(ref("name", STRING)), INTEGER) + new CountAggregator(List.of(ref("name", STRING)), INTEGER) .condition(DSL.greater(ref("age", INTEGER), literal(30))) .distinct(true))))); } @@ -397,7 +395,7 @@ void should_build_top_hits_aggregation() { + " }%n" + "}"), buildQuery( - singletonList( + List.of( named( "take(name, 10)", new TakeAggregator( @@ -439,7 +437,7 @@ void should_build_filtered_top_hits_aggregation() { + " }%n" + "}"), buildQuery( - singletonList( + List.of( named( "take(name, 10) filter(where age > 30)", new TakeAggregator(ImmutableList.of(ref("name", STRING), literal(10)), ARRAY) @@ -452,11 +450,10 @@ void should_throw_exception_for_unsupported_distinct_aggregator() { IllegalStateException.class, () -> buildQuery( - singletonList( + List.of( named( "avg(distinct age)", - new AvgAggregator(singletonList(ref("name", STRING)), STRING) - .distinct(true)))), + new AvgAggregator(List.of(ref("name", STRING)), STRING).distinct(true)))), "unsupported distinct aggregator avg"); } 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 df754887cfc..bb0bc9a1299 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,9 +5,6 @@ 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; @@ -140,7 +137,7 @@ void can_execute_expression_with_missing_field() { @Test void can_execute_expression_with_empty_doc_value() { - assertThat().docValues("name", emptyList()).filterBy(ref("name", STRING)).shouldNotMatch(); + assertThat().docValues("name", List.of()).filterBy(ref("name", STRING)).shouldNotMatch(); } @Test @@ -212,7 +209,7 @@ ExprScriptAssertion docValues(String name1, Object value1, String name2, Object } ExprScriptAssertion filterBy(Expression expr) { - ExpressionFilterScript script = new ExpressionFilterScript(expr, lookup, context, emptyMap()); + ExpressionFilterScript script = new ExpressionFilterScript(expr, lookup, context, Map.of()); isMatched = script.execute(); return this; } @@ -238,7 +235,7 @@ private static class FakeScriptDocValues extends ScriptDocValues { @SuppressWarnings("unchecked") public FakeScriptDocValues(T value) { - this.values = (value instanceof List) ? (List) value : singletonList(value); + this.values = (value instanceof List) ? (List) value : List.of(value); } @Override 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 75e27e58da4..9a42cb089f6 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 @@ -5,8 +5,6 @@ package org.opensearch.sql.opensearch.utils; -import static java.util.Collections.singletonList; - import com.google.common.collect.ImmutableSet; import java.util.Arrays; import java.util.List; @@ -25,7 +23,7 @@ public class Utils { public static AvgAggregator avg(Expression expr, ExprCoreType type) { - return new AvgAggregator(singletonList(expr), type); + return new AvgAggregator(List.of(expr), type); } public static List agg(NamedAggregator... exprs) { @@ -38,7 +36,7 @@ public static List group(NamedExpression... exprs) { public static List> sort( Expression expr1, Sort.SortOption option1) { - return singletonList(Pair.of(option1, expr1)); + return List.of(Pair.of(option1, expr1)); } public static List> sort( 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 766edc42c0f..db87e644306 100644 --- a/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java +++ b/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java @@ -5,7 +5,6 @@ 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; @@ -276,7 +275,7 @@ public ScheduledJobParser getJobParser() { @Override public List> getExecutorBuilders(Settings settings) { - return singletonList( + return List.of( 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 6e20d198208..c7e77651a81 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 @@ -5,7 +5,6 @@ package org.opensearch.sql.ppl.utils; -import static java.util.Collections.singletonList; import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.BooleanLiteralContext; import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.DedupCommandContext; import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.FieldsCommandContext; @@ -33,7 +32,7 @@ public class ArgumentFactory { * @return the list of arguments fetched from the fields command */ public static List getArgumentList(FieldsCommandContext ctx) { - return singletonList( + return List.of( ctx.MINUS() != null ? new Argument("exclude", new Literal(true, DataType.BOOLEAN)) : new Argument("exclude", new Literal(false, DataType.BOOLEAN))); @@ -109,7 +108,7 @@ public static List getArgumentList(SortFieldContext ctx) { * @return the list of arguments fetched from the top command */ public static List getArgumentList(TopCommandContext ctx) { - return singletonList( + return List.of( ctx.number != null ? new Argument("noOfResults", getArgumentValue(ctx.number)) : new Argument("noOfResults", new Literal(10, DataType.INTEGER))); @@ -122,7 +121,7 @@ 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 singletonList(new Argument("noOfResults", new Literal(10, DataType.INTEGER))); + return List.of(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 fbb25549ab8..e10dca52294 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,7 +5,6 @@ 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; @@ -394,7 +393,7 @@ public void testAggFuncCallExpr() { agg( relation("t"), exprList(alias("avg(a)", aggregate("avg", field("a")))), - emptyList(), + List.of(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -406,7 +405,7 @@ public void testVarAggregationShouldPass() { agg( relation("t"), exprList(alias("var_samp(a)", aggregate("var_samp", field("a")))), - emptyList(), + List.of(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -418,7 +417,7 @@ public void testVarpAggregationShouldPass() { agg( relation("t"), exprList(alias("var_pop(a)", aggregate("var_pop", field("a")))), - emptyList(), + List.of(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -430,7 +429,7 @@ public void testStdDevAggregationShouldPass() { agg( relation("t"), exprList(alias("stddev_samp(a)", aggregate("stddev_samp", field("a")))), - emptyList(), + List.of(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -442,7 +441,7 @@ public void testStdDevPAggregationShouldPass() { agg( relation("t"), exprList(alias("stddev_pop(a)", aggregate("stddev_pop", field("a")))), - emptyList(), + List.of(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -457,8 +456,8 @@ public void testPercentileAggFuncExpr() { alias( "percentile(a, 1)", aggregate("percentile", field("a"), unresolvedArg("percent", intLiteral(1))))), - emptyList(), - emptyList(), + List.of(), + List.of(), defaultStatsArgs())); assertEqual( "source=t | stats percentile(a, 1.0)", @@ -469,8 +468,8 @@ public void testPercentileAggFuncExpr() { "percentile(a, 1.0)", aggregate( "percentile", field("a"), unresolvedArg("percent", doubleLiteral(1D))))), - emptyList(), - emptyList(), + List.of(), + List.of(), defaultStatsArgs())); assertEqual( "source=t | stats percentile(a, 1.0, 100)", @@ -484,8 +483,8 @@ public void testPercentileAggFuncExpr() { field("a"), unresolvedArg("percent", doubleLiteral(1D)), unresolvedArg("compression", intLiteral(100))))), - emptyList(), - emptyList(), + List.of(), + List.of(), defaultStatsArgs())); } @@ -496,7 +495,7 @@ public void testCountFuncCallExpr() { agg( relation("t"), exprList(alias("count()", aggregate("count", AllFields.of()))), - emptyList(), + List.of(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -508,8 +507,8 @@ public void testDistinctCount() { agg( relation("t"), exprList(alias("distinct_count(a)", distinctAggregate("count", field("a")))), - emptyList(), - emptyList(), + List.of(), + List.of(), defaultStatsArgs())); } @@ -523,8 +522,8 @@ public void testTakeAggregationNoArgsShouldPass() { alias( "take(a)", aggregate("take", field("a"), unresolvedArg("size", intLiteral(10))))), - emptyList(), - emptyList(), + List.of(), + List.of(), defaultStatsArgs())); } @@ -538,8 +537,8 @@ public void testTakeAggregationWithArgsShouldPass() { alias( "take(a, 5)", aggregate("take", field("a"), unresolvedArg("size", intLiteral(5))))), - emptyList(), - emptyList(), + List.of(), + List.of(), defaultStatsArgs())); } @@ -762,7 +761,7 @@ public void indexCanBeId() { agg( relation("index"), exprList(alias("count()", aggregate("count", AllFields.of()))), - emptyList(), + List.of(), 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 8709cecba30..6dc6e11f0e2 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 @@ -5,7 +5,6 @@ package org.opensearch.sql.prometheus.client; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -154,13 +153,12 @@ void testGetAllMetrics() { Map> expected = new HashMap<>(); expected.put( "go_gc_duration_seconds", - singletonList( + List.of( new MetricMetadata( "summary", "A summary of the pause duration of garbage collection cycles.", ""))); expected.put( "go_goroutines", - singletonList( - new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); + List.of(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/request/PrometheusListMetricsRequestTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusListMetricsRequestTest.java index 8fff1c36d0c..17f405df4b9 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 @@ -7,7 +7,6 @@ package org.opensearch.sql.prometheus.request; -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.Mockito.times; @@ -43,13 +42,12 @@ void testSearch() { Map> metricsResult = new HashMap<>(); metricsResult.put( "go_gc_duration_seconds", - singletonList( + List.of( new MetricMetadata( "summary", "A summary of the pause duration of garbage collection cycles.", ""))); metricsResult.put( "go_goroutines", - singletonList( - new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); + List.of(new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); when(prometheusClient.getAllMetrics()).thenReturn(metricsResult); PrometheusListMetricsRequest prometheusListMetricsRequest = new PrometheusListMetricsRequest( 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 e46147b7a38..6ee0159d6eb 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,8 +5,6 @@ package org.opensearch.sql.sql.parser; -import static java.util.Collections.emptyList; - import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -77,7 +75,7 @@ public UnresolvedPlan visit(ParseTree groupByClause) { private UnresolvedPlan buildExplicitAggregation() { List groupByItems = replaceGroupByItemIfAliasOrOrdinal(); - return new Aggregation(new ArrayList<>(querySpec.getAggregators()), emptyList(), groupByItems); + return new Aggregation(new ArrayList<>(querySpec.getAggregators()), List.of(), groupByItems); } private UnresolvedPlan buildImplicitAggregation() { @@ -93,7 +91,7 @@ private UnresolvedPlan buildImplicitAggregation() { } return new Aggregation( - new ArrayList<>(querySpec.getAggregators()), emptyList(), querySpec.getGroupByItems()); + new ArrayList<>(querySpec.getAggregators()), List.of(), querySpec.getGroupByItems()); } private List replaceGroupByItemIfAliasOrOrdinal() { 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 eb76875f169..5e7687e409c 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 @@ -5,7 +5,6 @@ package org.opensearch.sql.sql.parser; -import static java.util.Collections.singletonList; import static org.opensearch.sql.ast.dsl.AstDSL.between; import static org.opensearch.sql.ast.dsl.AstDSL.not; import static org.opensearch.sql.ast.dsl.AstDSL.qualifiedName; @@ -109,7 +108,7 @@ public UnresolvedExpression visitColumnName(ColumnNameContext ctx) { @Override public UnresolvedExpression visitIdent(IdentContext ctx) { - return visitIdentifiers(singletonList(ctx)); + return visitIdentifiers(List.of(ctx)); } @Override @@ -253,7 +252,7 @@ public UnresolvedExpression visitIsNullPredicate(IsNullPredicateContext ctx) { ctx.nullNotnull().NOT() == null ? IS_NULL.getName().getFunctionName() : IS_NOT_NULL.getName().getFunctionName(), - singletonList(visit(ctx.predicate()))); + List.of(visit(ctx.predicate()))); } @Override 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 95188e20b65..461e9e7688c 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,7 +5,6 @@ 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; @@ -270,7 +269,7 @@ private Matcher featureValueOf( Function> getter, UnresolvedExpression... exprs) { Matcher> subMatcher = - (exprs.length == 0) ? equalTo(emptyList()) : equalTo(Arrays.asList(exprs)); + (exprs.length == 0) ? equalTo(List.of()) : equalTo(Arrays.asList(exprs)); return new FeatureMatcher>(subMatcher, name, "") { @Override protected List featureValueOf(UnresolvedPlan agg) { From c3006139f5fc7162c0b474756b977933cab8d26b Mon Sep 17 00:00:00 2001 From: currantw Date: Mon, 9 Dec 2024 15:04:19 -0800 Subject: [PATCH 05/16] Remove link to GitHub account that has been deleted and is causing linkchecker job to fail. Signed-off-by: currantw --- MAINTAINERS.md | 1 - 1 file changed, 1 deletion(-) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 1bc25b6b034..4fa850d1b58 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -16,7 +16,6 @@ This document contains a list of maintainers in this repo. See [opensearch-proje | Peter Fitzgibbons | [pjfitzgibbons](https://github.com/pjfitzgibbons) | Amazon | | Simeon Widdis | [swiddis](https://github.com/swiddis) | Amazon | | Chen Dai | [dai-chen](https://github.com/dai-chen) | Amazon | -| Vamsi Manohar | [vamsi-amazon](https://github.com/vamsi-amazon) | Amazon | | Peng Huo | [penghuo](https://github.com/penghuo) | Amazon | | Sean Kao | [seankao-az](https://github.com/seankao-az) | Amazon | | Anirudha Jadhav | [anirudha](https://github.com/anirudha) | Amazon | From ab6dddb42488b20993bb3415052490e35e571f5d Mon Sep 17 00:00:00 2001 From: currantw Date: Mon, 9 Dec 2024 15:05:28 -0800 Subject: [PATCH 06/16] Update link to correct name. Signed-off-by: currantw --- MAINTAINERS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 4fa850d1b58..62a3e1aef22 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -5,7 +5,7 @@ This document contains a list of maintainers in this repo. See [opensearch-proje ## Current Maintainers | Maintainer | GitHub ID | Affiliation | -| ----------------- | ------------------------------------------------- | ----------- | +| ----------------- |-----------------------------------------------------| ----------- | | Eric Wei | [mengweieric](https://github.com/mengweieric) | Amazon | | Joshua Li | [joshuali925](https://github.com/joshuali925) | Amazon | | Shenoy Pratik | [ps48](https://github.com/ps48) | Amazon | @@ -16,6 +16,7 @@ This document contains a list of maintainers in this repo. See [opensearch-proje | Peter Fitzgibbons | [pjfitzgibbons](https://github.com/pjfitzgibbons) | Amazon | | Simeon Widdis | [swiddis](https://github.com/swiddis) | Amazon | | Chen Dai | [dai-chen](https://github.com/dai-chen) | Amazon | +| Vamsi Manohar | [vmcircuit](https://github.com/vmcircuit) | Amazon | | Peng Huo | [penghuo](https://github.com/penghuo) | Amazon | | Sean Kao | [seankao-az](https://github.com/seankao-az) | Amazon | | Anirudha Jadhav | [anirudha](https://github.com/anirudha) | Amazon | From 3637c1c30182cbd6b2978c3bff7d8906f7756430 Mon Sep 17 00:00:00 2001 From: currantw Date: Mon, 9 Dec 2024 15:10:04 -0800 Subject: [PATCH 07/16] Revert unintended change. Signed-off-by: currantw --- MAINTAINERS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 62a3e1aef22..adac008905a 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -5,7 +5,7 @@ This document contains a list of maintainers in this repo. See [opensearch-proje ## Current Maintainers | Maintainer | GitHub ID | Affiliation | -| ----------------- |-----------------------------------------------------| ----------- | +| ----------------- | ------------------------------------------------- | ----------- | | Eric Wei | [mengweieric](https://github.com/mengweieric) | Amazon | | Joshua Li | [joshuali925](https://github.com/joshuali925) | Amazon | | Shenoy Pratik | [ps48](https://github.com/ps48) | Amazon | @@ -16,7 +16,7 @@ This document contains a list of maintainers in this repo. See [opensearch-proje | Peter Fitzgibbons | [pjfitzgibbons](https://github.com/pjfitzgibbons) | Amazon | | Simeon Widdis | [swiddis](https://github.com/swiddis) | Amazon | | Chen Dai | [dai-chen](https://github.com/dai-chen) | Amazon | -| Vamsi Manohar | [vmcircuit](https://github.com/vmcircuit) | Amazon | +| Vamsi Manohar | [vmcircuit](https://github.com/vmcircuit) | Amazon | | Peng Huo | [penghuo](https://github.com/penghuo) | Amazon | | Sean Kao | [seankao-az](https://github.com/seankao-az) | Amazon | | Anirudha Jadhav | [anirudha](https://github.com/anirudha) | Amazon | From 6f6868c960c08a3445471e4ec85573384efb5253 Mon Sep 17 00:00:00 2001 From: currantw Date: Mon, 9 Dec 2024 15:49:39 -0800 Subject: [PATCH 08/16] Cleanup previous changes. Signed-off-by: currantw --- .../correctness/tests/ComparisonTestTest.java | 11 +++----- .../sql/correctness/tests/DBResultTest.java | 7 ++--- .../sql/correctness/tests/TestReportTest.java | 12 ++++----- .../format/BindingTupleResultSetTest.java | 3 +-- .../format/CsvResponseFormatterTest.java | 11 ++++---- .../format/RawResponseFormatterTest.java | 15 +++++------ .../SimpleJsonResponseFormatterTest.java | 9 +++---- .../sql/sql/parser/AstExpressionBuilder.java | 27 +++++++++---------- 8 files changed, 40 insertions(+), 55 deletions(-) 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 793d9aa03bc..f3ca1f18382 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 @@ -5,13 +5,11 @@ package org.opensearch.sql.correctness.tests; -import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -83,7 +81,7 @@ public void testFailureDueToInconsistency() { TestReport expected = new TestReport(); expected.addTestCase( new FailedTestCase( - 1, "SELECT * FROM accounts", asList(openSearchResult, otherDbResult), "")); + 1, "SELECT * FROM accounts", List.of(openSearchResult, otherDbResult), "")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); } @@ -147,7 +145,7 @@ public void testFailureDueToEventualInconsistency() { new FailedTestCase( 1, "SELECT * FROM accounts", - asList(openSearchResult, otherDbResult, anotherDbResult), + List.of(openSearchResult, otherDbResult, anotherDbResult), "")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); @@ -226,8 +224,7 @@ public void testFailureDueToInconsistencyAndExceptionMixed() { "OpenSearch", List.of(new Type("firstname", "text")), List.of(new Row(List.of("John")))); - DBResult otherResult = - new DBResult("Other", List.of(new Type("firstname", "text")), Collections.emptyList()); + DBResult otherResult = new DBResult("Other", List.of(new Type("firstname", "text")), List.of()); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(otherDbConnection.select(anyString())).thenReturn(otherResult); @@ -239,7 +236,7 @@ public void testFailureDueToInconsistencyAndExceptionMixed() { new FailedTestCase( 1, "SELECT * FROM accounts", - asList(openSearchResult, otherResult), + List.of(openSearchResult, otherResult), "Unsupported feature;")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); 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 798d1c23e93..8bf4cc29989 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 @@ -11,7 +11,6 @@ import com.google.common.collect.ImmutableList; 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; @@ -76,12 +75,10 @@ public void dbResultWithDifferentColumnTypeShouldNotEqual() { public void shouldExplainColumnTypeDifference() { DBResult result1 = new DBResult( - "DB 1", - Arrays.asList(new Type("name", "VARCHAR"), new Type("age", "FLOAT")), - List.of()); + "DB 1", List.of(new Type("name", "VARCHAR"), new Type("age", "FLOAT")), List.of()); DBResult result2 = new DBResult( - "DB 2", Arrays.asList(new Type("name", "VARCHAR"), new Type("age", "INT")), List.of()); + "DB 2", List.of(new Type("name", "VARCHAR"), new Type("age", "INT")), List.of()); assertEquals( "Schema type at [1] is different: " 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 5ce7e3d4d87..8fa3f189ba3 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 @@ -5,8 +5,6 @@ package org.opensearch.sql.correctness.tests; -import static java.util.Arrays.asList; -import static java.util.Collections.singleton; import static org.junit.Assert.fail; import java.util.List; @@ -57,15 +55,15 @@ public void testFailedReport() { new FailedTestCase( 1, "SELECT * FROM accounts", - asList( + List.of( new DBResult( "OpenSearch", - singleton(new Type("firstName", "text")), - singleton(new Row(List.of("hello")))), + List.of(new Type("firstName", "text")), + List.of(new Row(List.of("hello")))), new DBResult( "H2", - singleton(new Type("firstName", "text")), - singleton(new Row(List.of("world"))))), + List.of(new Type("firstName", "text")), + List.of(new Row(List.of("world"))))), "[SQLITE_ERROR] SQL error or missing database;")); JSONObject actual = new JSONObject(report); JSONObject expected = 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 96210c7d8ac..3c0cc4fdaa0 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,7 +14,6 @@ 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; @@ -70,7 +69,7 @@ public void buildDataRowsFromBindingTupleIncludeDateShouldPass() { Arrays.asList( ColumnNode.builder().alias("dateValue").type(Schema.Type.DATE).build(), ColumnNode.builder().alias("gender").type(Schema.Type.TEXT).build()), - Collections.singletonList( + List.of( BindingTuple.from(ImmutableMap.of("dateValue", 1529712000000L, "gender", "m")))), containsInAnyOrder( rowContents( 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 971169f1027..0f211127282 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 @@ -17,7 +17,6 @@ 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; @@ -38,7 +37,7 @@ void formatResponse() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("name", "John", "age", 20)), tupleValue(ImmutableMap.of("name", "Smith", "age", 30)))); CsvResponseFormatter formatter = new CsvResponseFormatter(); @@ -81,7 +80,7 @@ void sanitizeData() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("city", "Seattle")), tupleValue(ImmutableMap.of("city", "=Seattle")), tupleValue(ImmutableMap.of("city", "+Seattle")), @@ -109,7 +108,7 @@ void quoteIfRequired() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("na,me", "John,Smith", ",,age", "30,,,")), tupleValue(ImmutableMap.of("na,me", "\"Janice Jones", ",,age", "26\"")))); String expected = @@ -134,7 +133,7 @@ void escapeSanitize() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("city", "=Seattle")), tupleValue(ImmutableMap.of("city", ",,Seattle")))); String expected = "city%n=Seattle%n\",,Seattle\""; @@ -151,7 +150,7 @@ void replaceNullValues() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("name", "John", "city", "Seattle")), ExprTupleValue.fromExprValueMap( ImmutableMap.of("firstname", LITERAL_NULL, "city", stringValue("Seattle"))), 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 f9915a5317f..04bf7401ceb 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 @@ -17,7 +17,6 @@ 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; @@ -37,7 +36,7 @@ void formatResponse() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("name", "John", "age", 20)), tupleValue(ImmutableMap.of("name", "Smith", "age", 30)))); String expected = "name|age%n" + "John|20%n" + "Smith|30"; @@ -84,7 +83,7 @@ void sanitizeData() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("city", "Seattle")), tupleValue(ImmutableMap.of("city", "=Seattle")), tupleValue(ImmutableMap.of("city", "+Seattle")), @@ -121,7 +120,7 @@ void quoteIfRequired() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("na|me", "John|Smith", "||age", "30|||")), tupleValue(ImmutableMap.of("na|me", "Ja\"ne J\"ones", "||age", "\"40\"")))); String expected = @@ -153,7 +152,7 @@ void escapeSanitize() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("city", "=Seattle")), tupleValue(ImmutableMap.of("city", "||Seattle")))); String expected = "city%n" + "=Seattle%n" + "\"||Seattle\""; @@ -170,7 +169,7 @@ void senstiveCharater() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("city", "@Seattle")), tupleValue(ImmutableMap.of("city", "++Seattle")))); String expected = "city%n" + "@Seattle%n" + "++Seattle"; @@ -187,7 +186,7 @@ void senstiveCharaterWithSanitize() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("city", "@Seattle")), tupleValue(ImmutableMap.of("city", "++Seattle|||")))); String expected = "city%n" + "@Seattle%n" + "\"++Seattle|||\""; @@ -206,7 +205,7 @@ void replaceNullValues() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("name", "John", "city", "Seattle")), ExprTupleValue.fromExprValueMap( ImmutableMap.of("firstname", LITERAL_NULL, "city", stringValue("Seattle"))), 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 a88f93bd2d0..35435ee704a 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 @@ -16,7 +16,6 @@ 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; @@ -36,7 +35,7 @@ void formatResponse() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("firstname", "John", "age", 20)), tupleValue(ImmutableMap.of("firstname", "Smith", "age", 30)))); SimpleJsonResponseFormatter formatter = new SimpleJsonResponseFormatter(COMPACT); @@ -52,7 +51,7 @@ void formatResponsePretty() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( tupleValue(ImmutableMap.of("firstname", "John", "age", 20)), tupleValue(ImmutableMap.of("firstname", "Smith", "age", 30)))); SimpleJsonResponseFormatter formatter = new SimpleJsonResponseFormatter(PRETTY); @@ -104,7 +103,7 @@ void formatResponseWithMissingValue() { QueryResult response = new QueryResult( schema, - Arrays.asList( + List.of( ExprTupleValue.fromExprValueMap( ImmutableMap.of("firstname", stringValue("John"), "age", LITERAL_MISSING)), tupleValue(ImmutableMap.of("firstname", "Smith", "age", 30)))); @@ -150,7 +149,7 @@ void formatResponseWithArrayValue() { "name", "Smith", "address", - Arrays.asList( + List.of( ImmutableMap.of("state", "WA"), ImmutableMap.of("state", "NYC")))))); SimpleJsonResponseFormatter formatter = new SimpleJsonResponseFormatter(COMPACT); assertEquals( 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 5e7687e409c..4b45c8d15b6 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 @@ -68,8 +68,6 @@ 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; @@ -118,8 +116,7 @@ public UnresolvedExpression visitQualifiedName(QualifiedNameContext ctx) { @Override public UnresolvedExpression visitMathExpressionAtom(MathExpressionAtomContext ctx) { - return new Function( - ctx.mathOperator.getText(), Arrays.asList(visit(ctx.left), visit(ctx.right))); + return new Function(ctx.mathOperator.getText(), List.of(visit(ctx.left), visit(ctx.right))); } @Override @@ -169,21 +166,21 @@ public UnresolvedExpression visitTimestampFunctionCall(TimestampFunctionCallCont public UnresolvedExpression visitPositionFunction(PositionFunctionContext ctx) { return new Function( POSITION.getName().getFunctionName(), - Arrays.asList(visitFunctionArg(ctx.functionArg(0)), visitFunctionArg(ctx.functionArg(1)))); + List.of(visitFunctionArg(ctx.functionArg(0)), visitFunctionArg(ctx.functionArg(1)))); } @Override public UnresolvedExpression visitTableFilter(TableFilterContext ctx) { return new Function( LIKE.getName().getFunctionName(), - Arrays.asList(qualifiedName("TABLE_NAME"), visit(ctx.showDescribePattern()))); + List.of(qualifiedName("TABLE_NAME"), visit(ctx.showDescribePattern()))); } @Override public UnresolvedExpression visitColumnFilter(ColumnFilterContext ctx) { return new Function( LIKE.getName().getFunctionName(), - Arrays.asList(qualifiedName("COLUMN_NAME"), visit(ctx.showDescribePattern()))); + List.of(qualifiedName("COLUMN_NAME"), visit(ctx.showDescribePattern()))); } @Override @@ -202,7 +199,7 @@ public UnresolvedExpression visitFilteredAggregationFunctionCall( public UnresolvedExpression visitWindowFunctionClause(WindowFunctionClauseContext ctx) { OverClauseContext overClause = ctx.overClause(); - List partitionByList = Collections.emptyList(); + List partitionByList = List.of(); if (overClause.partitionByClause() != null) { partitionByList = overClause.partitionByClause().expression().stream() @@ -210,7 +207,7 @@ public UnresolvedExpression visitWindowFunctionClause(WindowFunctionClauseContex .collect(Collectors.toList()); } - List> sortList = Collections.emptyList(); + List> sortList = List.of(); if (overClause.orderByClause() != null) { sortList = overClause.orderByClause().orderByElement().stream() @@ -270,13 +267,13 @@ public UnresolvedExpression visitBetweenPredicate(BetweenPredicateContext ctx) { public UnresolvedExpression visitLikePredicate(LikePredicateContext ctx) { return new Function( ctx.NOT() == null ? LIKE.getName().getFunctionName() : NOT_LIKE.getName().getFunctionName(), - Arrays.asList(visit(ctx.left), visit(ctx.right))); + List.of(visit(ctx.left), visit(ctx.right))); } @Override public UnresolvedExpression visitRegexpPredicate(RegexpPredicateContext ctx) { return new Function( - REGEXP.getName().getFunctionName(), Arrays.asList(visit(ctx.left), visit(ctx.right))); + REGEXP.getName().getFunctionName(), List.of(visit(ctx.left), visit(ctx.right))); } @Override @@ -362,7 +359,7 @@ public UnresolvedExpression visitBinaryComparisonPredicate(BinaryComparisonPredi String functionName = ctx.comparisonOperator().getText(); return new Function( functionName.equals("<>") ? "!=" : functionName, - Arrays.asList(visit(ctx.left), visit(ctx.right))); + List.of(visit(ctx.left), visit(ctx.right))); } @Override @@ -577,7 +574,7 @@ private List multiFieldRelevanceArguments( private List getFormatFunctionArguments(GetFormatFunctionCallContext ctx) { List args = - Arrays.asList( + List.of( new Literal(ctx.getFormatFunction().getFormatType().getText(), DataType.STRING), visitFunctionArg(ctx.getFormatFunction().functionArg())); return args; @@ -585,7 +582,7 @@ private List getFormatFunctionArguments(GetFormatFunctionC private List timestampFunctionArguments(TimestampFunctionCallContext ctx) { List args = - Arrays.asList( + List.of( new Literal(ctx.timestampFunction().simpleDateTimePart().getText(), DataType.STRING), visitFunctionArg(ctx.timestampFunction().firstArg), visitFunctionArg(ctx.timestampFunction().secondArg)); @@ -660,7 +657,7 @@ private List altMultiFieldRelevanceFunctionArguments( private List getExtractFunctionArguments(ExtractFunctionCallContext ctx) { List args = - Arrays.asList( + List.of( new Literal(ctx.extractFunction().datetimePart().getText(), DataType.STRING), visitFunctionArg(ctx.extractFunction().functionArg())); return args; From 1b761f04f15b973a4caab3120b927eef350cbd07 Mon Sep 17 00:00:00 2001 From: currantw Date: Mon, 9 Dec 2024 16:12:07 -0800 Subject: [PATCH 09/16] Fix failing unit tests due to immutability. Signed-off-by: currantw --- .../sql/correctness/tests/ComparisonTestTest.java | 7 ++++--- .../opensearch/sql/correctness/tests/TestReportTest.java | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) 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 f3ca1f18382..90006f47288 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 @@ -10,6 +10,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.util.Arrays; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -81,7 +82,7 @@ public void testFailureDueToInconsistency() { TestReport expected = new TestReport(); expected.addTestCase( new FailedTestCase( - 1, "SELECT * FROM accounts", List.of(openSearchResult, otherDbResult), "")); + 1, "SELECT * FROM accounts", Arrays.asList(openSearchResult, otherDbResult), "")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); } @@ -145,7 +146,7 @@ public void testFailureDueToEventualInconsistency() { new FailedTestCase( 1, "SELECT * FROM accounts", - List.of(openSearchResult, otherDbResult, anotherDbResult), + Arrays.asList(openSearchResult, otherDbResult, anotherDbResult), "")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); @@ -236,7 +237,7 @@ public void testFailureDueToInconsistencyAndExceptionMixed() { new FailedTestCase( 1, "SELECT * FROM accounts", - List.of(openSearchResult, otherResult), + Arrays.asList(openSearchResult, otherResult), "Unsupported feature;")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); 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 8fa3f189ba3..42b46a5086d 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 @@ -7,6 +7,7 @@ import static org.junit.Assert.fail; +import java.util.Arrays; import java.util.List; import org.json.JSONObject; import org.junit.Test; @@ -55,7 +56,7 @@ public void testFailedReport() { new FailedTestCase( 1, "SELECT * FROM accounts", - List.of( + Arrays.asList( new DBResult( "OpenSearch", List.of(new Type("firstName", "text")), From 5e7ebe8b243a7f07357732b4a3fffbdfaf855a52 Mon Sep 17 00:00:00 2001 From: currantw Date: Mon, 9 Dec 2024 16:34:46 -0800 Subject: [PATCH 10/16] A bit more cleanup of imports Signed-off-by: currantw --- .../correctness/tests/ComparisonTestTest.java | 70 +++++++++++-------- .../sql/correctness/tests/TestReportTest.java | 14 ++-- .../format/BindingTupleResultSetTest.java | 11 ++- 3 files changed, 52 insertions(+), 43 deletions(-) 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 90006f47288..9ced180ff00 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 @@ -5,13 +5,14 @@ package org.opensearch.sql.correctness.tests; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.util.Arrays; -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", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John"))))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John"))))); when(otherDbConnection.select(anyString())) .thenReturn( new DBResult( "Other DB", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John"))))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John"))))); TestReport expected = new TestReport(); expected.addTestCase(new SuccessTestCase(1, "SELECT * FROM accounts")); @@ -71,18 +72,20 @@ public void testFailureDueToInconsistency() { DBResult openSearchResult = new DBResult( "OpenSearch", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John")))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John")))); DBResult otherDbResult = new DBResult( - "Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN")))); + "Other DB", + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("JOHN")))); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(otherDbConnection.select(anyString())).thenReturn(otherDbResult); TestReport expected = new TestReport(); expected.addTestCase( new FailedTestCase( - 1, "SELECT * FROM accounts", Arrays.asList(openSearchResult, otherDbResult), "")); + 1, "SELECT * FROM accounts", asList(openSearchResult, otherDbResult), "")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); } @@ -98,16 +101,18 @@ public void testSuccessFinally() { DBResult openSearchResult = new DBResult( "OpenSearch", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John")))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John")))); DBResult otherDbResult = new DBResult( - "Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN")))); + "Other DB", + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("JOHN")))); DBResult anotherDbResult = new DBResult( "Another DB", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John")))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John")))); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(anotherDbConnection.select(anyString())).thenReturn(anotherDbResult); @@ -129,14 +134,18 @@ public void testFailureDueToEventualInconsistency() { DBResult openSearchResult = new DBResult( "OpenSearch", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John")))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John")))); DBResult otherDbResult = new DBResult( - "Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN")))); + "Other DB", + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("JOHN")))); DBResult anotherDbResult = new DBResult( - "ZZZ DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("Hank")))); + "ZZZ DB", + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("Hank")))); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(otherDbConnection.select(anyString())).thenReturn(otherDbResult); when(anotherDbConnection.select(anyString())).thenReturn(anotherDbResult); @@ -146,7 +155,7 @@ public void testFailureDueToEventualInconsistency() { new FailedTestCase( 1, "SELECT * FROM accounts", - Arrays.asList(openSearchResult, otherDbResult, anotherDbResult), + asList(openSearchResult, otherDbResult, anotherDbResult), "")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); @@ -170,8 +179,8 @@ public void testErrorDueToNoOtherDBSupportThisQuery() { .thenReturn( new DBResult( "OpenSearch", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John"))))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John"))))); when(otherDbConnection.select(anyString())) .thenThrow(new RuntimeException("Unsupported feature")); @@ -197,14 +206,14 @@ public void testSuccessWhenOneDBSupportThisQuery() { .thenReturn( new DBResult( "OpenSearch", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John"))))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John"))))); when(anotherDbConnection.select(anyString())) .thenReturn( new DBResult( "Another DB", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John"))))); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John"))))); TestReport expected = new TestReport(); expected.addTestCase(new SuccessTestCase(1, "SELECT * FROM accounts")); @@ -223,9 +232,10 @@ public void testFailureDueToInconsistencyAndExceptionMixed() { DBResult openSearchResult = new DBResult( "OpenSearch", - List.of(new Type("firstname", "text")), - List.of(new Row(List.of("John")))); - DBResult otherResult = new DBResult("Other", List.of(new Type("firstname", "text")), List.of()); + singletonList(new Type("firstname", "text")), + singletonList(new Row(singletonList("John")))); + DBResult otherResult = + new DBResult("Other", singletonList(new Type("firstname", "text")), emptyList()); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(otherDbConnection.select(anyString())).thenReturn(otherResult); @@ -237,7 +247,7 @@ public void testFailureDueToInconsistencyAndExceptionMixed() { new FailedTestCase( 1, "SELECT * FROM accounts", - Arrays.asList(openSearchResult, otherResult), + asList(openSearchResult, otherResult), "Unsupported feature;")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); 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 42b46a5086d..435c9f0e1ec 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 @@ -5,10 +5,10 @@ package org.opensearch.sql.correctness.tests; +import static java.util.Arrays.asList; +import static java.util.Collections.singleton; import static org.junit.Assert.fail; -import java.util.Arrays; -import java.util.List; import org.json.JSONObject; import org.junit.Test; import org.opensearch.sql.correctness.report.ErrorTestCase; @@ -56,15 +56,15 @@ public void testFailedReport() { new FailedTestCase( 1, "SELECT * FROM accounts", - Arrays.asList( + asList( new DBResult( "OpenSearch", - List.of(new Type("firstName", "text")), - List.of(new Row(List.of("hello")))), + singleton(new Type("firstName", "text")), + singleton(new Row(singleton("hello")))), new DBResult( "H2", - List.of(new Type("firstName", "text")), - List.of(new Row(List.of("world"))))), + singleton(new Type("firstName", "text")), + singleton(new Row(singleton("world"))))), "[SQLITE_ERROR] SQL error or missing database;")); JSONObject actual = new JSONObject(report); JSONObject expected = 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 3c0cc4fdaa0..8216a5fdbb6 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 @@ -13,7 +13,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import java.util.Arrays; import java.util.List; import java.util.Map; import org.hamcrest.Matcher; @@ -30,10 +29,10 @@ public class BindingTupleResultSetTest { public void buildDataRowsFromBindingTupleShouldPass() { assertThat( row( - Arrays.asList( + List.of( ColumnNode.builder().name("age").type(Schema.Type.INTEGER).build(), ColumnNode.builder().name("gender").type(Schema.Type.TEXT).build()), - Arrays.asList( + List.of( BindingTuple.from(ImmutableMap.of("age", 31, "gender", "m")), BindingTuple.from(ImmutableMap.of("age", 31, "gender", "f")), BindingTuple.from(ImmutableMap.of("age", 39, "gender", "m")), @@ -49,10 +48,10 @@ public void buildDataRowsFromBindingTupleShouldPass() { public void buildDataRowsFromBindingTupleIncludeLongValueShouldPass() { assertThat( row( - Arrays.asList( + List.of( ColumnNode.builder().name("longValue").type(Schema.Type.LONG).build(), ColumnNode.builder().name("gender").type(Schema.Type.TEXT).build()), - Arrays.asList( + List.of( BindingTuple.from(ImmutableMap.of("longValue", Long.MAX_VALUE, "gender", "m")), BindingTuple.from(ImmutableMap.of("longValue", Long.MIN_VALUE, "gender", "f")))), containsInAnyOrder( @@ -66,7 +65,7 @@ public void buildDataRowsFromBindingTupleIncludeLongValueShouldPass() { public void buildDataRowsFromBindingTupleIncludeDateShouldPass() { assertThat( row( - Arrays.asList( + List.of( ColumnNode.builder().alias("dateValue").type(Schema.Type.DATE).build(), ColumnNode.builder().alias("gender").type(Schema.Type.TEXT).build()), List.of( From beee9060b5d4c1715eea359928fcd3f09c76d460 Mon Sep 17 00:00:00 2001 From: currantw Date: Tue, 10 Dec 2024 10:48:56 -0800 Subject: [PATCH 11/16] Remove broken link Signed-off-by: currantw --- MAINTAINERS.md | 1 - 1 file changed, 1 deletion(-) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index adac008905a..d41cd9bee4b 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -16,7 +16,6 @@ This document contains a list of maintainers in this repo. See [opensearch-proje | Peter Fitzgibbons | [pjfitzgibbons](https://github.com/pjfitzgibbons) | Amazon | | Simeon Widdis | [swiddis](https://github.com/swiddis) | Amazon | | Chen Dai | [dai-chen](https://github.com/dai-chen) | Amazon | -| Vamsi Manohar | [vmcircuit](https://github.com/vmcircuit) | Amazon | | Peng Huo | [penghuo](https://github.com/penghuo) | Amazon | | Sean Kao | [seankao-az](https://github.com/seankao-az) | Amazon | | Anirudha Jadhav | [anirudha](https://github.com/anirudha) | Amazon | From dea7cc1ded7b9cceafbd7265449eb40b9c6d55c9 Mon Sep 17 00:00:00 2001 From: currantw Date: Tue, 10 Dec 2024 18:42:30 -0800 Subject: [PATCH 12/16] Update link for (hopefully) the last time, Signed-off-by: currantw --- MAINTAINERS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index d41cd9bee4b..3b48e25cfe4 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -5,7 +5,7 @@ This document contains a list of maintainers in this repo. See [opensearch-proje ## Current Maintainers | Maintainer | GitHub ID | Affiliation | -| ----------------- | ------------------------------------------------- | ----------- | +| ----------------- |-----------------------------------------------------| ----------- | | Eric Wei | [mengweieric](https://github.com/mengweieric) | Amazon | | Joshua Li | [joshuali925](https://github.com/joshuali925) | Amazon | | Shenoy Pratik | [ps48](https://github.com/ps48) | Amazon | @@ -16,6 +16,7 @@ This document contains a list of maintainers in this repo. See [opensearch-proje | Peter Fitzgibbons | [pjfitzgibbons](https://github.com/pjfitzgibbons) | Amazon | | Simeon Widdis | [swiddis](https://github.com/swiddis) | Amazon | | Chen Dai | [dai-chen](https://github.com/dai-chen) | Amazon | +| Vamsi Manohar | [vamsi-amazon](https://github.com/vmmusings) | Amazon | | Peng Huo | [penghuo](https://github.com/penghuo) | Amazon | | Sean Kao | [seankao-az](https://github.com/seankao-az) | Amazon | | Anirudha Jadhav | [anirudha](https://github.com/anirudha) | Amazon | From 9202868b67f4aea50e5fb85301521a1d68ae8c37 Mon Sep 17 00:00:00 2001 From: currantw Date: Thu, 12 Dec 2024 12:50:29 -0800 Subject: [PATCH 13/16] 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 165f9e63f72..af93060fab3 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 bef62fa4085..5a8d6fe976e 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 d296ad6573a..5e46cfa629d 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 e2913a0e4ec..64a4fc4e098 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 6e837e90ccc..5208e39623d 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 77719b000be..2019346fb52 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 6ffc86497de..c26f829f486 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 c105dfb7628..852b61cfa8a 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 1a430fc0493..af18916f716 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 b11eb35f0e5..92cdc6eb417 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 56e2f6f704b..4f06ce9d23a 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 3548cffef57..17f86cadbae 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 8a7adff3fd4..b27b8348e2f 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 bf6b1cca686..eaeae072428 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 d77f4842485..2f3e855430a 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 faca949df05..ee784045d00 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 1b8cf7f5603..17fb128aced 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 e6b70fdbe33..e252c41d1fa 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 47d557acd6c..807d8b8836b 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 4869a4c8a89..a8ab0487017 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 3c28b140920..e5b2c9f61a0 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 be866452b73..9a1022706fc 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 efc99e24556..03abe737632 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 e48ec0ffeed..2b77c1938ae 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 962642a540c..daf084d3711 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 2eb0f4009dc..0f65ee1b996 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 29a1bdebb90..5e89b3b8aef 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 01416f442a2..89f8f9ac89e 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 4292a954328..61e707e8efd 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 9cfe8c9ec72..2e040d78fbb 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 bd248f3b7e0..0c0d50258d9 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 715cd61430f..abfcf273ad5 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 8a47a25fa9b..fbdcca2bb0e 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 05d91b22615..ed2611786a1 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 f34defca6b4..eea1c9a87a3 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 42019a2bfbe..6ff907ba30f 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 474daab055e..811d05c16a9 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 46f96f6e2df..f9c32b74243 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 10342f6d4db..ef60782a24c 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 ecb486f39f4..6dc7078a0d3 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 b3bdece8164..de0ee5883cf 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 e46fdb0b81b..a218151b2e3 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 9cf80f0cb44..fa0fe191051 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 f69cce7f8b2..da06c1eb669 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 6b76b373603..e6d2bac85b5 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 f003de848d8..fa328fd26ce 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 0d0b0c3e675..a2430a671d2 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 5597ca12130..984c98f8033 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 98b7382b3b0..6749f87c5bb 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 d25c9dc11fe..6d90cce7046 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 bb0bc9a1299..df754887cfc 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 afe2e0b1729..00d1c9ecd10 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 db87e644306..766edc42c0f 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 c7e77651a81..f89ecf9c6e4 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 e10dca52294..fbb25549ab8 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 6dc6e11f0e2..d6ca25b206c 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 6345dcb1de7..e59a2bf7c4e 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 17f405df4b9..09f63463b54 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 9b3c1932505..00ddc973bca 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 e41b0a321ee..7b1e2dec0f7 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 e988a481a08..ea299b87dee 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 11d638457c8..84c9c05e79f 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 6ee0159d6eb..e46147b7a38 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 8b4f331d772..ab96f162633 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 461e9e7688c..95188e20b65 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) { From df81d5cfe6dc75ca81d2a43aa516f63bda475494 Mon Sep 17 00:00:00 2001 From: currantw Date: Thu, 12 Dec 2024 13:12:01 -0800 Subject: [PATCH 14/16] Revert more changes not specifically related to `Arrays.asList` Signed-off-by: currantw --- .../org/opensearch/sql/ast/tree/RareTopN.java | 3 +- .../aggregation/AggregatorFunctions.java | 61 ++++++++++--------- .../sql/expression/function/FunctionDSL.java | 9 ++- .../sql/expression/text/TextFunctions.java | 3 +- .../window/ranking/RankingWindowFunction.java | 4 +- .../sql/planner/logical/LogicalAD.java | 5 +- .../planner/logical/LogicalAggregation.java | 3 +- .../sql/planner/logical/LogicalEval.java | 3 +- .../sql/planner/logical/LogicalFilter.java | 5 +- .../sql/planner/logical/LogicalHighlight.java | 5 +- .../sql/planner/logical/LogicalLimit.java | 5 +- .../sql/planner/logical/LogicalML.java | 5 +- .../sql/planner/logical/LogicalMLCommons.java | 5 +- .../sql/planner/logical/LogicalProject.java | 3 +- .../sql/planner/logical/LogicalRareTopN.java | 3 +- .../sql/planner/logical/LogicalRemove.java | 5 +- .../sql/planner/logical/LogicalRename.java | 5 +- .../sql/planner/logical/LogicalSort.java | 3 +- .../sql/planner/logical/LogicalWindow.java | 5 +- .../planner/physical/AggregationOperator.java | 3 +- .../sql/planner/physical/DedupeOperator.java | 3 +- .../sql/planner/physical/EvalOperator.java | 3 +- .../sql/planner/physical/FilterOperator.java | 3 +- .../sql/planner/physical/NestedOperator.java | 4 +- .../sql/planner/physical/ProjectOperator.java | 3 +- .../planner/physical/RareTopNOperator.java | 3 +- .../sql/planner/physical/RemoveOperator.java | 3 +- .../sql/planner/physical/RenameOperator.java | 3 +- .../sql/planner/physical/SortOperator.java | 3 +- .../planner/physical/TakeOrderedOperator.java | 3 +- .../sql/planner/physical/WindowOperator.java | 3 +- .../physical/collector/MetricCollector.java | 3 +- .../assigner/TumblingWindowAssigner.java | 3 +- .../protocol/response/QueryResultTest.java | 11 ++-- 34 files changed, 106 insertions(+), 88 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java b/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java index 6c0d203a007..2cbe170541e 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java @@ -5,6 +5,7 @@ package org.opensearch.sql.ast.tree; +import java.util.Collections; import java.util.List; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; @@ -40,7 +41,7 @@ public RareTopN attach(UnresolvedPlan child) { @Override public List getChild() { - return List.of(this.child); + return Collections.singletonList(this.child); } @Override diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java index c54c1bcc9c8..698fb20408b 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java @@ -5,7 +5,6 @@ package org.opensearch.sql.expression.aggregation; -import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; import static org.opensearch.sql.data.type.ExprCoreType.DATE; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; @@ -22,6 +21,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import java.util.Collections; import java.util.stream.Collectors; import lombok.experimental.UtilityClass; import org.opensearch.sql.data.type.ExprCoreType; @@ -66,16 +66,16 @@ private static DefaultFunctionResolver avg() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, singletonList(DOUBLE)), + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> new AvgAggregator(arguments, DOUBLE)) .put( - new FunctionSignature(functionName, singletonList(DATE)), + new FunctionSignature(functionName, Collections.singletonList(DATE)), (functionProperties, arguments) -> new AvgAggregator(arguments, DATE)) .put( - new FunctionSignature(functionName, singletonList(TIME)), + new FunctionSignature(functionName, Collections.singletonList(TIME)), (functionProperties, arguments) -> new AvgAggregator(arguments, TIME)) .put( - new FunctionSignature(functionName, singletonList(TIMESTAMP)), + new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), (functionProperties, arguments) -> new AvgAggregator(arguments, TIMESTAMP)) .build()); } @@ -88,7 +88,8 @@ private static DefaultFunctionResolver count() { ExprCoreType.coreTypes().stream() .collect( Collectors.toMap( - type -> new FunctionSignature(functionName, singletonList(type)), + type -> + new FunctionSignature(functionName, Collections.singletonList(type)), type -> (functionProperties, arguments) -> new CountAggregator(arguments, INTEGER)))); @@ -101,16 +102,16 @@ private static DefaultFunctionResolver sum() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, singletonList(INTEGER)), + new FunctionSignature(functionName, Collections.singletonList(INTEGER)), (functionProperties, arguments) -> new SumAggregator(arguments, INTEGER)) .put( - new FunctionSignature(functionName, singletonList(LONG)), + new FunctionSignature(functionName, Collections.singletonList(LONG)), (functionProperties, arguments) -> new SumAggregator(arguments, LONG)) .put( - new FunctionSignature(functionName, singletonList(FLOAT)), + new FunctionSignature(functionName, Collections.singletonList(FLOAT)), (functionProperties, arguments) -> new SumAggregator(arguments, FLOAT)) .put( - new FunctionSignature(functionName, singletonList(DOUBLE)), + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> new SumAggregator(arguments, DOUBLE)) .build()); } @@ -121,28 +122,28 @@ private static DefaultFunctionResolver min() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, singletonList(INTEGER)), + new FunctionSignature(functionName, Collections.singletonList(INTEGER)), (functionProperties, arguments) -> new MinAggregator(arguments, INTEGER)) .put( - new FunctionSignature(functionName, singletonList(LONG)), + new FunctionSignature(functionName, Collections.singletonList(LONG)), (functionProperties, arguments) -> new MinAggregator(arguments, LONG)) .put( - new FunctionSignature(functionName, singletonList(FLOAT)), + new FunctionSignature(functionName, Collections.singletonList(FLOAT)), (functionProperties, arguments) -> new MinAggregator(arguments, FLOAT)) .put( - new FunctionSignature(functionName, singletonList(DOUBLE)), + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> new MinAggregator(arguments, DOUBLE)) .put( - new FunctionSignature(functionName, singletonList(STRING)), + new FunctionSignature(functionName, Collections.singletonList(STRING)), (functionProperties, arguments) -> new MinAggregator(arguments, STRING)) .put( - new FunctionSignature(functionName, singletonList(DATE)), + new FunctionSignature(functionName, Collections.singletonList(DATE)), (functionProperties, arguments) -> new MinAggregator(arguments, DATE)) .put( - new FunctionSignature(functionName, singletonList(TIME)), + new FunctionSignature(functionName, Collections.singletonList(TIME)), (functionProperties, arguments) -> new MinAggregator(arguments, TIME)) .put( - new FunctionSignature(functionName, singletonList(TIMESTAMP)), + new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), (functionProperties, arguments) -> new MinAggregator(arguments, TIMESTAMP)) .build()); } @@ -153,28 +154,28 @@ private static DefaultFunctionResolver max() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, singletonList(INTEGER)), + new FunctionSignature(functionName, Collections.singletonList(INTEGER)), (functionProperties, arguments) -> new MaxAggregator(arguments, INTEGER)) .put( - new FunctionSignature(functionName, singletonList(LONG)), + new FunctionSignature(functionName, Collections.singletonList(LONG)), (functionProperties, arguments) -> new MaxAggregator(arguments, LONG)) .put( - new FunctionSignature(functionName, singletonList(FLOAT)), + new FunctionSignature(functionName, Collections.singletonList(FLOAT)), (functionProperties, arguments) -> new MaxAggregator(arguments, FLOAT)) .put( - new FunctionSignature(functionName, singletonList(DOUBLE)), + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> new MaxAggregator(arguments, DOUBLE)) .put( - new FunctionSignature(functionName, singletonList(STRING)), + new FunctionSignature(functionName, Collections.singletonList(STRING)), (functionProperties, arguments) -> new MaxAggregator(arguments, STRING)) .put( - new FunctionSignature(functionName, singletonList(DATE)), + new FunctionSignature(functionName, Collections.singletonList(DATE)), (functionProperties, arguments) -> new MaxAggregator(arguments, DATE)) .put( - new FunctionSignature(functionName, singletonList(TIME)), + new FunctionSignature(functionName, Collections.singletonList(TIME)), (functionProperties, arguments) -> new MaxAggregator(arguments, TIME)) .put( - new FunctionSignature(functionName, singletonList(TIMESTAMP)), + new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), (functionProperties, arguments) -> new MaxAggregator(arguments, TIMESTAMP)) .build()); } @@ -185,7 +186,7 @@ private static DefaultFunctionResolver varSamp() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, singletonList(DOUBLE)), + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> varianceSample(arguments, DOUBLE)) .build()); } @@ -196,7 +197,7 @@ private static DefaultFunctionResolver varPop() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, singletonList(DOUBLE)), + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> variancePopulation(arguments, DOUBLE)) .build()); } @@ -207,7 +208,7 @@ private static DefaultFunctionResolver stddevSamp() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, singletonList(DOUBLE)), + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> stddevSample(arguments, DOUBLE)) .build()); } @@ -218,7 +219,7 @@ private static DefaultFunctionResolver stddevPop() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, singletonList(DOUBLE)), + new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), (functionProperties, arguments) -> stddevPopulation(arguments, DOUBLE)) .build()); } diff --git a/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java b/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java index 670a086f7ec..8ebbfd3a3c6 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java @@ -6,6 +6,7 @@ package org.opensearch.sql.expression.function; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; @@ -67,10 +68,11 @@ public static DefaultFunctionResolver define( implWithProperties( SerializableFunction function, ExprType returnType) { return functionName -> { - FunctionSignature functionSignature = new FunctionSignature(functionName, List.of()); + FunctionSignature functionSignature = + new FunctionSignature(functionName, Collections.emptyList()); FunctionBuilder functionBuilder = (functionProperties, arguments) -> - new FunctionExpression(functionName, List.of()) { + new FunctionExpression(functionName, Collections.emptyList()) { @Override public ExprValue valueOf(Environment valueEnv) { return function.apply(functionProperties); @@ -106,7 +108,8 @@ public String toString() { ExprType argsType) { return functionName -> { - FunctionSignature functionSignature = new FunctionSignature(functionName, List.of(argsType)); + FunctionSignature functionSignature = + new FunctionSignature(functionName, Collections.singletonList(argsType)); FunctionBuilder functionBuilder = (functionProperties, arguments) -> new FunctionExpression(functionName, arguments) { diff --git a/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java b/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java index b555c8c05c8..2c3bbf7efb5 100644 --- a/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java +++ b/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java @@ -12,6 +12,7 @@ import static org.opensearch.sql.expression.function.FunctionDSL.impl; import static org.opensearch.sql.expression.function.FunctionDSL.nullMissingHandling; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import lombok.experimental.UtilityClass; @@ -175,7 +176,7 @@ private DefaultFunctionResolver concat() { concatFuncName, funcName -> Pair.of( - new FunctionSignature(concatFuncName, List.of(ARRAY)), + new FunctionSignature(concatFuncName, Collections.singletonList(ARRAY)), (funcProp, args) -> new FunctionExpression(funcName, args) { @Override diff --git a/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunction.java b/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunction.java index 87f4b7de159..c119629cdad 100644 --- a/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/window/ranking/RankingWindowFunction.java @@ -5,6 +5,8 @@ package org.opensearch.sql.expression.window.ranking; +import static java.util.Collections.emptyList; + import java.util.List; import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.Pair; @@ -33,7 +35,7 @@ public abstract class RankingWindowFunction extends FunctionExpression protected int rank; public RankingWindowFunction(FunctionName functionName) { - super(functionName, List.of()); + super(functionName, emptyList()); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAD.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAD.java index 40f70c422c0..25dbd14f1af 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAD.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAD.java @@ -1,7 +1,6 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - +import java.util.Collections; import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -24,7 +23,7 @@ public class LogicalAD extends LogicalPlan { * @param arguments arguments of the algorithm */ public LogicalAD(LogicalPlan child, Map arguments) { - super(singletonList(child)); + super(Collections.singletonList(child)); this.arguments = arguments; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java index d40feb7dff0..ecbcece6236 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java @@ -5,6 +5,7 @@ package org.opensearch.sql.planner.logical; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -24,7 +25,7 @@ public class LogicalAggregation extends LogicalPlan { /** Constructor of LogicalAggregation. */ public LogicalAggregation( LogicalPlan child, List aggregatorList, List groupByList) { - super(List.of(child)); + super(Collections.singletonList(child)); this.aggregatorList = aggregatorList; this.groupByList = groupByList; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java index b93b80202ee..e7b8f353bcb 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java @@ -5,6 +5,7 @@ package org.opensearch.sql.planner.logical; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -26,7 +27,7 @@ public class LogicalEval extends LogicalPlan { /** Constructor of LogicalEval. */ public LogicalEval(LogicalPlan child, List> expressions) { - super(List.of(child)); + super(Collections.singletonList(child)); this.expressions = expressions; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalFilter.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalFilter.java index 7c2902c4550..49280e8709d 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalFilter.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalFilter.java @@ -5,8 +5,7 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - +import java.util.Collections; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -21,7 +20,7 @@ public class LogicalFilter extends LogicalPlan { /** Constructor of LogicalFilter. */ public LogicalFilter(LogicalPlan child, Expression condition) { - super(singletonList(child)); + super(Collections.singletonList(child)); this.condition = condition; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalHighlight.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalHighlight.java index 1ad86fffd96..41fcd48f813 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalHighlight.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalHighlight.java @@ -5,8 +5,7 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - +import java.util.Collections; import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -24,7 +23,7 @@ public class LogicalHighlight extends LogicalPlan { /** Constructor of LogicalHighlight. */ public LogicalHighlight( LogicalPlan childPlan, Expression highlightField, Map arguments) { - super(singletonList(childPlan)); + super(Collections.singletonList(childPlan)); this.highlightField = highlightField; this.arguments = arguments; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalLimit.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalLimit.java index 69339589765..bec77d9b6f2 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalLimit.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalLimit.java @@ -5,8 +5,7 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - +import java.util.Collections; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -20,7 +19,7 @@ public class LogicalLimit extends LogicalPlan { /** Constructor of LogicalLimit. */ public LogicalLimit(LogicalPlan input, Integer limit, Integer offset) { - super(singletonList(input)); + super(Collections.singletonList(input)); this.limit = limit; this.offset = offset; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalML.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalML.java index dd7a5ae4604..780e0bba94a 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalML.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalML.java @@ -1,7 +1,6 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - +import java.util.Collections; import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -22,7 +21,7 @@ public class LogicalML extends LogicalPlan { * @param arguments arguments of the algorithm */ public LogicalML(LogicalPlan child, Map arguments) { - super(singletonList(child)); + super(Collections.singletonList(child)); this.arguments = arguments; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalMLCommons.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalMLCommons.java index bfb1b4261de..cfc313a68d5 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalMLCommons.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalMLCommons.java @@ -1,7 +1,6 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - +import java.util.Collections; import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -25,7 +24,7 @@ public class LogicalMLCommons extends LogicalPlan { * @param arguments arguments of the algorithm */ public LogicalMLCommons(LogicalPlan child, String algorithm, Map arguments) { - super(singletonList(child)); + super(Collections.singletonList(child)); this.algorithm = algorithm; this.arguments = arguments; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java index 37320f84286..5978620480a 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java @@ -5,6 +5,7 @@ package org.opensearch.sql.planner.logical; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -24,7 +25,7 @@ public LogicalProject( LogicalPlan child, List projectList, List namedParseExpressions) { - super(List.of(child)); + super(Collections.singletonList(child)); this.projectList = projectList; this.namedParseExpressions = namedParseExpressions; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java index 17bb090f60a..2c387eca9c8 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java @@ -5,6 +5,7 @@ package org.opensearch.sql.planner.logical; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -30,7 +31,7 @@ public LogicalRareTopN( Integer noOfResults, List fieldList, List groupByList) { - super(List.of(child)); + super(Collections.singletonList(child)); this.commandType = commandType; this.noOfResults = noOfResults; this.fieldList = fieldList; diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRemove.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRemove.java index a32fe0a2abb..c1aeda22c7b 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRemove.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRemove.java @@ -5,8 +5,7 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - +import java.util.Collections; import java.util.Set; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -22,7 +21,7 @@ public class LogicalRemove extends LogicalPlan { /** Constructor of LogicalRemove. */ public LogicalRemove(LogicalPlan child, Set removeList) { - super(singletonList(child)); + super(Collections.singletonList(child)); this.removeList = removeList; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRename.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRename.java index 7c117ce2408..25ee645932c 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRename.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRename.java @@ -5,8 +5,7 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - +import java.util.Collections; import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -22,7 +21,7 @@ public class LogicalRename extends LogicalPlan { /** Constructor of LogicalRename. */ public LogicalRename(LogicalPlan child, Map renameMap) { - super(singletonList(child)); + super(Collections.singletonList(child)); this.renameMap = renameMap; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java index f5b9164e59f..569ca7e3098 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java @@ -5,6 +5,7 @@ package org.opensearch.sql.planner.logical; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -23,7 +24,7 @@ public class LogicalSort extends LogicalPlan { /** Constructor of LogicalSort. */ public LogicalSort(LogicalPlan child, List> sortList) { - super(List.of(child)); + super(Collections.singletonList(child)); this.sortList = sortList; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWindow.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWindow.java index 37310be3914..00c89410a78 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWindow.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWindow.java @@ -5,8 +5,7 @@ package org.opensearch.sql.planner.logical; -import static java.util.Collections.singletonList; - +import java.util.Collections; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -28,7 +27,7 @@ public class LogicalWindow extends LogicalPlan { /** Constructor of logical window. */ public LogicalWindow( LogicalPlan child, NamedExpression windowFunction, WindowDefinition windowDefinition) { - super(singletonList(child)); + super(Collections.singletonList(child)); this.windowFunction = windowFunction; this.windowDefinition = windowDefinition; } diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java index c8537885015..cc1c047c311 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java @@ -5,6 +5,7 @@ package org.opensearch.sql.planner.physical; +import java.util.Collections; import java.util.Iterator; import java.util.List; import lombok.EqualsAndHashCode; @@ -58,7 +59,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java index 73a2fb5aa1a..7faec2154b9 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java @@ -6,6 +6,7 @@ package org.opensearch.sql.planner.physical; import com.google.common.collect.ImmutableList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -77,7 +78,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java index 14c9e4e8a6e..ac62fe1b867 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java @@ -10,6 +10,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -49,7 +50,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java index e1eeb3adb3a..088dd07f8d9 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java @@ -5,6 +5,7 @@ package org.opensearch.sql.planner.physical; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -36,7 +37,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/NestedOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/NestedOperator.java index 92f463b742d..fb5ec276ac1 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/NestedOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/NestedOperator.java @@ -5,11 +5,11 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; import static java.util.stream.Collectors.mapping; import static java.util.stream.Collectors.toList; import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.ListIterator; @@ -80,7 +80,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return Collections.singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java index 84e7c833ebe..55422dacd36 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -41,7 +42,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java index c1c6a122a22..ecf997f7ae2 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java @@ -9,6 +9,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Streams; import java.util.AbstractMap; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; @@ -83,7 +84,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java index bd2b2c91fc2..b4a724aa7a4 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java @@ -9,6 +9,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -48,7 +49,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java index 1039646563d..e6f97dab4a3 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java @@ -9,6 +9,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -55,7 +56,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java index 468ebf9b31d..b635f01d180 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java @@ -5,6 +5,7 @@ package org.opensearch.sql.planner.physical; +import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; @@ -62,7 +63,7 @@ public void open() { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java index 97d31cb4d4b..a6e0f968e63 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java @@ -6,6 +6,7 @@ package org.opensearch.sql.planner.physical; import com.google.common.collect.Ordering; +import java.util.Collections; import java.util.Iterator; import java.util.List; import lombok.EqualsAndHashCode; @@ -72,7 +73,7 @@ public void open() { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java index 16f76b776f3..10377ce47aa 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java @@ -8,6 +8,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterators; import com.google.common.collect.PeekingIterator; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -61,7 +62,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return List.of(input); + return Collections.singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java b/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java index 5307947df71..2cfa3c94571 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java @@ -6,6 +6,7 @@ package org.opensearch.sql.planner.physical.collector; import java.util.AbstractMap; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -56,6 +57,6 @@ public void collect(BindingTuple input) { public List results() { LinkedHashMap map = new LinkedHashMap<>(); aggregators.forEach(agg -> map.put(agg.getKey().getName(), agg.getValue().result())); - return List.of(ExprTupleValue.fromExprValueMap(map)); + return Collections.singletonList(ExprTupleValue.fromExprValueMap(map)); } } diff --git a/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java b/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java index 9a003303a77..2591689a353 100644 --- a/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java +++ b/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java @@ -6,6 +6,7 @@ package org.opensearch.sql.planner.streaming.windowing.assigner; import com.google.common.base.Preconditions; +import java.util.Collections; import java.util.List; import org.opensearch.sql.planner.streaming.windowing.Window; import org.opensearch.sql.utils.DateTimeUtils; @@ -30,6 +31,6 @@ public TumblingWindowAssigner(long windowSize) { @Override public List assign(long timestamp) { long startTime = DateTimeUtils.getWindowStartTime(timestamp, windowSize); - return List.of(new Window(startTime, startTime + windowSize)); + return Collections.singletonList(new Window(startTime, startTime + windowSize)); } } diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java index af03429bac1..fc3402e20a5 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java @@ -5,8 +5,6 @@ package org.opensearch.sql.protocol.response; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -17,6 +15,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Arrays; +import java.util.Collections; import org.junit.jupiter.api.Test; import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.executor.pagination.Cursor; @@ -47,7 +46,7 @@ void columnNameTypes() { QueryResult response = new QueryResult( schema, - singletonList(tupleValue(ImmutableMap.of("name", "John", "age", 20))), + Collections.singletonList(tupleValue(ImmutableMap.of("name", "John", "age", 20))), Cursor.None); assertEquals(ImmutableMap.of("name", "string", "age", "integer"), response.columnNameTypes()); @@ -60,14 +59,16 @@ void columnNameTypesWithAlias() { ImmutableList.of(new ExecutionEngine.Schema.Column("name", "n", STRING))); QueryResult response = new QueryResult( - schema, singletonList(tupleValue(ImmutableMap.of("n", "John"))), Cursor.None); + schema, + Collections.singletonList(tupleValue(ImmutableMap.of("n", "John"))), + Cursor.None); assertEquals(ImmutableMap.of("n", "string"), response.columnNameTypes()); } @Test void columnNameTypesFromEmptyExprValues() { - QueryResult response = new QueryResult(schema, emptyList(), Cursor.None); + QueryResult response = new QueryResult(schema, Collections.emptyList(), Cursor.None); assertEquals(ImmutableMap.of("name", "string", "age", "integer"), response.columnNameTypes()); } From 82567d3a458bc484dd19abb2f96fdd6239a78210 Mon Sep 17 00:00:00 2001 From: currantw Date: Thu, 12 Dec 2024 13:45:35 -0800 Subject: [PATCH 15/16] Update remaining `asList` issues Signed-off-by: currantw --- .../BuiltinFunctionRepositoryTest.java | 24 ++++--- .../sql/planner/DefaultImplementorTest.java | 22 +++--- .../correctness/tests/ComparisonTestTest.java | 69 ++++++++----------- .../sql/correctness/tests/DBResultTest.java | 17 ++--- .../sql/legacy/PrettyFormatResponseIT.java | 26 +++---- .../dsl/MetricAggregationBuilderTest.java | 26 +++---- .../sql/opensearch/utils/Utils.java | 3 +- .../ppl/utils/UnresolvedPlanHelperTest.java | 4 +- .../sql/sql/parser/AstExpressionBuilder.java | 29 ++++---- 9 files changed, 115 insertions(+), 105 deletions(-) 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 1ddf53a8b9b..ae345fa9890 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,6 +24,7 @@ import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BOOLEAN; import com.google.common.collect.ImmutableList; +import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; @@ -96,7 +97,7 @@ void compile_datasource_defined_function() { repo.compile( functionProperties, - List.of(dataSourceFunctionResolver), + Collections.singletonList(dataSourceFunctionResolver), mockFunctionName, List.of(mockExpression)); verify(functionExpressionBuilder, times(1)).apply(eq(functionProperties), any()); @@ -114,7 +115,8 @@ void resolve() { BuiltinFunctionRepository repo = new BuiltinFunctionRepository(mockMap); repo.register(mockfunctionResolver); - assertEquals(functionExpressionBuilder, repo.resolve(List.of(), functionSignature)); + assertEquals( + functionExpressionBuilder, repo.resolve(Collections.emptyList(), functionSignature)); } @Test @@ -122,7 +124,8 @@ void resolve_should_not_cast_arguments_in_cast_function() { when(mockExpression.toString()).thenReturn("string"); FunctionImplementation function = repo.resolve( - List.of(), registerFunctionResolver(CAST_TO_BOOLEAN.getName(), TIMESTAMP, BOOLEAN)) + Collections.emptyList(), + registerFunctionResolver(CAST_TO_BOOLEAN.getName(), TIMESTAMP, BOOLEAN)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("cast_to_boolean(string)", function.toString()); } @@ -132,7 +135,8 @@ void resolve_should_not_cast_arguments_if_same_type() { when(mockFunctionName.getFunctionName()).thenReturn("mock"); when(mockExpression.toString()).thenReturn("string"); FunctionImplementation function = - repo.resolve(List.of(), registerFunctionResolver(mockFunctionName, STRING, STRING)) + repo.resolve( + Collections.emptyList(), registerFunctionResolver(mockFunctionName, STRING, STRING)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(string)", function.toString()); } @@ -142,7 +146,8 @@ void resolve_should_not_cast_arguments_if_both_numbers() { when(mockFunctionName.getFunctionName()).thenReturn("mock"); when(mockExpression.toString()).thenReturn("byte"); FunctionImplementation function = - repo.resolve(List.of(), registerFunctionResolver(mockFunctionName, BYTE, INTEGER)) + repo.resolve( + Collections.emptyList(), registerFunctionResolver(mockFunctionName, BYTE, INTEGER)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(byte)", function.toString()); } @@ -157,7 +162,7 @@ void resolve_should_cast_arguments() { registerFunctionResolver(CAST_TO_BOOLEAN.getName(), STRING, STRING); FunctionImplementation function = - repo.resolve(List.of(), signature) + repo.resolve(Collections.emptyList(), signature) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(cast_to_boolean(string))", function.toString()); } @@ -168,7 +173,9 @@ void resolve_should_throw_exception_for_unsupported_conversion() { assertThrows( ExpressionEvaluationException.class, () -> - repo.resolve(List.of(), registerFunctionResolver(mockFunctionName, BYTE, STRUCT)) + repo.resolve( + Collections.emptyList(), + registerFunctionResolver(mockFunctionName, BYTE, STRUCT)) .apply(functionProperties, ImmutableList.of(mockExpression))); assertEquals(error.getMessage(), "Type conversion to type STRUCT is not supported"); } @@ -185,7 +192,8 @@ void resolve_unregistered() { ExpressionEvaluationException.class, () -> repo.resolve( - List.of(), new FunctionSignature(FunctionName.of("unknown"), List.of()))); + Collections.emptyList(), + new FunctionSignature(FunctionName.of("unknown"), List.of()))); assertEquals("unsupported function name: unknown", exception.getMessage()); } 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 71740881529..7aad75b2043 100644 --- a/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.planner; +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.junit.jupiter.api.Assertions.assertThrows; @@ -30,6 +31,7 @@ import static org.opensearch.sql.planner.logical.LogicalPlanDSL.window; import com.google.common.collect.ImmutableMap; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -89,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 = List.of(named("age", ref("age", INTEGER))); + List groupByExprs = List.of(DSL.named("age", ref("age", INTEGER))); List aggExprs = List.of(ref("age", INTEGER)); ReferenceExpression rareTopNField = ref("age", INTEGER); List topByExprs = List.of(ref("age", INTEGER)); List aggregators = - List.of(named("avg(age)", new AvgAggregator(aggExprs, ExprCoreType.DOUBLE))); + List.of(DSL.named("avg(age)", new AvgAggregator(aggExprs, ExprCoreType.DOUBLE))); Map mappings = ImmutableMap.of(ref("name", STRING), ref("lastname", STRING)); Pair newEvalField = @@ -125,7 +127,7 @@ public void visit_should_return_default_physical_operator() { remove( rename( aggregation( - filter(values(List.of()), filterExpr), + filter(values(emptyList()), filterExpr), aggregators, groupByExprs), mappings), @@ -156,7 +158,8 @@ public void visit_should_return_default_physical_operator() { PhysicalPlanDSL.rename( PhysicalPlanDSL.agg( PhysicalPlanDSL.filter( - PhysicalPlanDSL.values(List.of()), filterExpr), + PhysicalPlanDSL.values(emptyList()), + filterExpr), aggregators, groupByExprs), mappings), @@ -188,8 +191,9 @@ public void visitWindowOperator_should_return_PhysicalWindowOperator() { NamedExpression windowFunction = named(new RowNumberFunction()); WindowDefinition windowDefinition = new WindowDefinition( - List.of(ref("state", STRING)), - List.of(ImmutablePair.of(Sort.SortOption.DEFAULT_DESC, ref("age", INTEGER)))); + Collections.singletonList(ref("state", STRING)), + Collections.singletonList( + ImmutablePair.of(Sort.SortOption.DEFAULT_DESC, ref("age", INTEGER)))); NamedExpression[] projectList = { named("state", ref("state", STRING)), named("row_number", ref("row_number", INTEGER)) @@ -279,11 +283,11 @@ public void visitLimit_support_return_takeOrdered() { // replace SortOperator + LimitOperator with TakeOrderedOperator Pair sort = ImmutablePair.of(Sort.SortOption.DEFAULT_ASC, ref("a", INTEGER)); - var logicalValues = values(List.of()); + var logicalValues = values(emptyList()); var logicalSort = sort(logicalValues, sort); var logicalLimit = limit(logicalSort, 10, 5); PhysicalPlan physicalPlanTree = - PhysicalPlanDSL.takeOrdered(PhysicalPlanDSL.values(List.of()), 10, 5, sort); + PhysicalPlanDSL.takeOrdered(PhysicalPlanDSL.values(emptyList()), 10, 5, sort); assertEquals(physicalPlanTree, logicalLimit.accept(implementor, null)); // don't replace if LimitOperator's child is not SortOperator @@ -294,7 +298,7 @@ public void visitLimit_support_return_takeOrdered() { physicalPlanTree = PhysicalPlanDSL.limit( PhysicalPlanDSL.eval( - PhysicalPlanDSL.sort(PhysicalPlanDSL.values(List.of()), sort), newEvalField), + PhysicalPlanDSL.sort(PhysicalPlanDSL.values(emptyList()), sort), newEvalField), 10, 5); assertEquals(physicalPlanTree, logicalLimit.accept(implementor, null)); 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 9ced180ff00..965cf1edb4b 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 @@ -5,14 +5,13 @@ package org.opensearch.sql.correctness.tests; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; 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; @@ -52,14 +51,14 @@ public void testSuccess() { .thenReturn( new DBResult( "OpenSearch", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("John"))))); + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John"))))); when(otherDbConnection.select(anyString())) .thenReturn( new DBResult( "Other DB", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("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")); @@ -72,20 +71,18 @@ public void testFailureDueToInconsistency() { DBResult openSearchResult = new DBResult( "OpenSearch", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("John")))); + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John")))); DBResult otherDbResult = new DBResult( - "Other DB", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("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); TestReport expected = new TestReport(); expected.addTestCase( new FailedTestCase( - 1, "SELECT * FROM accounts", asList(openSearchResult, otherDbResult), "")); + 1, "SELECT * FROM accounts", List.of(openSearchResult, otherDbResult), "")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); } @@ -101,18 +98,16 @@ public void testSuccessFinally() { DBResult openSearchResult = new DBResult( "OpenSearch", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("John")))); + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John")))); DBResult otherDbResult = new DBResult( - "Other DB", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("JOHN")))); + "Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN")))); DBResult anotherDbResult = new DBResult( "Another DB", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("John")))); + 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); @@ -134,18 +129,14 @@ public void testFailureDueToEventualInconsistency() { DBResult openSearchResult = new DBResult( "OpenSearch", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("John")))); + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John")))); DBResult otherDbResult = new DBResult( - "Other DB", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("JOHN")))); + "Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN")))); DBResult anotherDbResult = new DBResult( - "ZZZ DB", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("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); @@ -155,7 +146,7 @@ public void testFailureDueToEventualInconsistency() { new FailedTestCase( 1, "SELECT * FROM accounts", - asList(openSearchResult, otherDbResult, anotherDbResult), + List.of(openSearchResult, otherDbResult, anotherDbResult), "")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); @@ -179,8 +170,8 @@ public void testErrorDueToNoOtherDBSupportThisQuery() { .thenReturn( new DBResult( "OpenSearch", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("John"))))); + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John"))))); when(otherDbConnection.select(anyString())) .thenThrow(new RuntimeException("Unsupported feature")); @@ -206,14 +197,14 @@ public void testSuccessWhenOneDBSupportThisQuery() { .thenReturn( new DBResult( "OpenSearch", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("John"))))); + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John"))))); when(anotherDbConnection.select(anyString())) .thenReturn( new DBResult( "Another DB", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("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")); @@ -232,10 +223,10 @@ public void testFailureDueToInconsistencyAndExceptionMixed() { DBResult openSearchResult = new DBResult( "OpenSearch", - singletonList(new Type("firstname", "text")), - singletonList(new Row(singletonList("John")))); + List.of(new Type("firstname", "text")), + List.of(new Row(List.of("John")))); DBResult otherResult = - new DBResult("Other", singletonList(new Type("firstname", "text")), emptyList()); + new DBResult("Other", List.of(new Type("firstname", "text")), Collections.emptyList()); when(openSearchConnection.select(anyString())).thenReturn(openSearchResult); when(otherDbConnection.select(anyString())).thenReturn(otherResult); @@ -247,7 +238,7 @@ public void testFailureDueToInconsistencyAndExceptionMixed() { new FailedTestCase( 1, "SELECT * FROM accounts", - asList(openSearchResult, otherResult), + List.of(openSearchResult, otherResult), "Unsupported feature;")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); 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 8bf4cc29989..bbbfe6cb2ae 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 @@ -5,6 +5,7 @@ package org.opensearch.sql.correctness.tests; +import static java.util.Collections.emptyList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -22,15 +23,15 @@ public class DBResultTest { @Test public void dbResultFromDifferentDbNameShouldEqual() { - DBResult result1 = new DBResult("DB 1", List.of(new Type("name", "VARCHAR")), List.of()); - DBResult result2 = new DBResult("DB 2", List.of(new Type("name", "VARCHAR")), List.of()); + 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", List.of(new Type("name", "VARCHAR")), List.of()); - DBResult result2 = new DBResult("DB 2", List.of(new Type("age", "INT")), List.of()); + 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); } @@ -66,8 +67,8 @@ public void dbResultInOrderWithSameRowsInDifferentOrderShouldNotEqual() { @Test public void dbResultWithDifferentColumnTypeShouldNotEqual() { - DBResult result1 = new DBResult("DB 1", List.of(new Type("age", "FLOAT")), List.of()); - DBResult result2 = new DBResult("DB 2", List.of(new Type("age", "INT")), List.of()); + 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); } @@ -75,10 +76,10 @@ public void dbResultWithDifferentColumnTypeShouldNotEqual() { public void shouldExplainColumnTypeDifference() { DBResult result1 = new DBResult( - "DB 1", List.of(new Type("name", "VARCHAR"), new Type("age", "FLOAT")), List.of()); + "DB 1", List.of(new Type("name", "VARCHAR"), new Type("age", "FLOAT")), emptyList()); DBResult result2 = new DBResult( - "DB 2", List.of(new Type("name", "VARCHAR"), new Type("age", "INT")), List.of()); + "DB 2", List.of(new Type("name", "VARCHAR"), new Type("age", "INT")), emptyList()); assertEquals( "Schema type at [1] is different: " 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 03b6c3fb64f..a0729e94ce1 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 @@ -13,8 +13,8 @@ import com.google.common.collect.Sets; import java.io.IOException; -import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -70,7 +70,7 @@ public class PrettyFormatResponseIT extends SQLIntegTestCase { private static final Set commentFields = Sets.newHashSet("comment.data", "comment.likes"); - private static final List nameFields = Arrays.asList("firstname", "lastname"); + private static final List nameFields = List.of("firstname", "lastname"); private final int RESPONSE_DEFAULT_MAX_SIZE = 200; @@ -156,7 +156,7 @@ public void selectScore() throws IOException { "SELECT _score FROM %s WHERE SCORE(match_phrase(phrase, 'brown fox'))", TestsConstants.TEST_INDEX_PHRASE)); - List fields = List.of("_score"); + List fields = Collections.singletonList("_score"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } @@ -221,7 +221,7 @@ public void selectNestedFields() throws IOException { "SELECT nested(message.info), someField FROM %s", TestsConstants.TEST_INDEX_NESTED_TYPE)); - List fields = Arrays.asList("nested(message.info)", "someField"); + List fields = List.of("nested(message.info)", "someField"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); @@ -276,7 +276,7 @@ public void groupBySingleField() throws IOException { String.format( Locale.ROOT, "SELECT * FROM %s GROUP BY age", TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = List.of("age"); + List fields = Collections.singletonList("age"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } @@ -290,7 +290,7 @@ public void groupByMultipleFields() throws IOException { "SELECT * FROM %s GROUP BY age, balance", TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = Arrays.asList("age", "balance"); + List fields = List.of("age", "balance"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } @@ -397,7 +397,7 @@ public void aggregationFunctionInSelectNoGroupBy() throws IOException { Locale.ROOT, "SELECT SUM(age) FROM %s", TestsConstants.TEST_INDEX_ACCOUNT)); String ageSum = "SUM(age)"; - assertContainsColumns(getSchema(response), List.of(ageSum)); + assertContainsColumns(getSchema(response), Collections.singletonList(ageSum)); JSONArray dataRows = getDataRows(response); for (int i = 0; i < dataRows.length(); i++) { @@ -417,7 +417,7 @@ public void multipleAggregationFunctionsInSelect() throws IOException { "SELECT COUNT(*), AVG(age) FROM %s GROUP BY age", TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = Arrays.asList("COUNT(*)", "AVG(age)"); + List fields = List.of("COUNT(*)", "AVG(age)"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } @@ -432,7 +432,7 @@ public void aggregationFunctionInHaving() throws IOException { TestsConstants.TEST_INDEX_ACCOUNT)); String ageSum = "gender"; - assertContainsColumns(getSchema(response), List.of(ageSum)); + assertContainsColumns(getSchema(response), Collections.singletonList(ageSum)); JSONArray dataRows = getDataRows(response); assertEquals(1, dataRows.length()); @@ -495,7 +495,7 @@ public void joinQuery() throws IOException { TestsConstants.TEST_INDEX_ACCOUNT, TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = Arrays.asList("b1.balance", "b1.age", "b2.firstname"); + List fields = List.of("b1.balance", "b1.age", "b2.firstname"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } @@ -517,7 +517,7 @@ public void joinQueryWithAlias() throws IOException { aliases.put("b2.firstname", "name"); assertContainsAliases(getSchema(response), aliases); - assertContainsData(getDataRows(response), Arrays.asList("bal", "age", "name")); + assertContainsData(getDataRows(response), List.of("bal", "age", "name")); } @Test @@ -531,7 +531,7 @@ public void joinQueryWithObjectFieldInSelect() throws IOException { TestsConstants.TEST_INDEX_GAME_OF_THRONES, TestsConstants.TEST_INDEX_GAME_OF_THRONES)); - List fields = Arrays.asList("c.name.firstname", "d.name.lastname"); + List fields = List.of("c.name.firstname", "d.name.lastname"); assertContainsColumns(getSchema(response), fields); // d.name.lastname is null here since entries with hname don't have a name.lastname entry, so @@ -554,7 +554,7 @@ public void joinQuerySelectOnlyOnOneTable() throws Exception { TestsConstants.TEST_INDEX_ACCOUNT, TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = List.of("b1.age"); + List fields = Collections.singletonList("b1.age"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } 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 bfdc2392b2d..0df0c8db755 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 @@ -23,7 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import lombok.SneakyThrows; import org.junit.jupiter.api.BeforeEach; @@ -220,7 +220,7 @@ void should_build_percentile_aggregation() { named( "percentile(age, 50)", new PercentileApproximateAggregator( - Arrays.asList(ref("age", INTEGER), literal(50)), DOUBLE))))); + List.of(ref("age", INTEGER), literal(50)), DOUBLE))))); } @Test @@ -244,7 +244,7 @@ void should_build_percentile_with_compression_aggregation() { named( "percentile(age, 50)", new PercentileApproximateAggregator( - Arrays.asList(ref("age", INTEGER), literal(50), literal(0.1)), DOUBLE))))); + List.of(ref("age", INTEGER), literal(50), literal(0.1)), DOUBLE))))); } @Test @@ -283,7 +283,7 @@ void should_build_filtered_percentile_aggregation() { named( "percentile(age, 50)", new PercentileApproximateAggregator( - Arrays.asList(ref("age", INTEGER), literal(50)), DOUBLE) + List.of(ref("age", INTEGER), literal(50)), DOUBLE) .condition(DSL.greater(ref("age", INTEGER), literal(30))))))); } @@ -334,10 +334,11 @@ void should_build_cardinality_aggregation() { + " }%n" + "}"), buildQuery( - List.of( + Collections.singletonList( named( "count(distinct name)", - new CountAggregator(List.of(ref("name", STRING)), INTEGER).distinct(true))))); + new CountAggregator(Collections.singletonList(ref("name", STRING)), INTEGER) + .distinct(true))))); } @Test @@ -367,10 +368,10 @@ void should_build_filtered_cardinality_aggregation() { + " }%n" + "}"), buildQuery( - List.of( + Collections.singletonList( named( "count(distinct name) filter(where age > 30)", - new CountAggregator(List.of(ref("name", STRING)), INTEGER) + new CountAggregator(Collections.singletonList(ref("name", STRING)), INTEGER) .condition(DSL.greater(ref("age", INTEGER), literal(30))) .distinct(true))))); } @@ -395,7 +396,7 @@ void should_build_top_hits_aggregation() { + " }%n" + "}"), buildQuery( - List.of( + Collections.singletonList( named( "take(name, 10)", new TakeAggregator( @@ -437,7 +438,7 @@ void should_build_filtered_top_hits_aggregation() { + " }%n" + "}"), buildQuery( - List.of( + Collections.singletonList( named( "take(name, 10) filter(where age > 30)", new TakeAggregator(ImmutableList.of(ref("name", STRING), literal(10)), ARRAY) @@ -450,10 +451,11 @@ void should_throw_exception_for_unsupported_distinct_aggregator() { IllegalStateException.class, () -> buildQuery( - List.of( + Collections.singletonList( named( "avg(distinct age)", - new AvgAggregator(List.of(ref("name", STRING)), STRING).distinct(true)))), + new AvgAggregator(Collections.singletonList(ref("name", STRING)), STRING) + .distinct(true)))), "unsupported distinct aggregator avg"); } 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 9a42cb089f6..e79a229d00d 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 @@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableSet; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Set; import lombok.experimental.UtilityClass; @@ -36,7 +37,7 @@ public static List group(NamedExpression... exprs) { public static List> sort( Expression expr1, Sort.SortOption option1) { - return List.of(Pair.of(option1, expr1)); + return Collections.singletonList(Pair.of(option1, expr1)); } public static List> sort( 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 887c6557025..b86ab0cd59b 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 @@ -5,10 +5,10 @@ package org.opensearch.sql.ppl.utils; -import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; +import java.util.List; 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(singletonList(expression)); + when(project.getProjectList()).thenReturn(List.of(expression)); UnresolvedPlan plan = UnresolvedPlanHelper.addSelectAll(project); assertTrue(plan instanceof Project); 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 4b45c8d15b6..f32aa6a6283 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 @@ -68,6 +68,8 @@ 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; @@ -106,7 +108,7 @@ public UnresolvedExpression visitColumnName(ColumnNameContext ctx) { @Override public UnresolvedExpression visitIdent(IdentContext ctx) { - return visitIdentifiers(List.of(ctx)); + return visitIdentifiers(Collections.singletonList(ctx)); } @Override @@ -116,7 +118,8 @@ public UnresolvedExpression visitQualifiedName(QualifiedNameContext ctx) { @Override public UnresolvedExpression visitMathExpressionAtom(MathExpressionAtomContext ctx) { - return new Function(ctx.mathOperator.getText(), List.of(visit(ctx.left), visit(ctx.right))); + return new Function( + ctx.mathOperator.getText(), Arrays.asList(visit(ctx.left), visit(ctx.right))); } @Override @@ -166,21 +169,21 @@ public UnresolvedExpression visitTimestampFunctionCall(TimestampFunctionCallCont public UnresolvedExpression visitPositionFunction(PositionFunctionContext ctx) { return new Function( POSITION.getName().getFunctionName(), - List.of(visitFunctionArg(ctx.functionArg(0)), visitFunctionArg(ctx.functionArg(1)))); + Arrays.asList(visitFunctionArg(ctx.functionArg(0)), visitFunctionArg(ctx.functionArg(1)))); } @Override public UnresolvedExpression visitTableFilter(TableFilterContext ctx) { return new Function( LIKE.getName().getFunctionName(), - List.of(qualifiedName("TABLE_NAME"), visit(ctx.showDescribePattern()))); + Arrays.asList(qualifiedName("TABLE_NAME"), visit(ctx.showDescribePattern()))); } @Override public UnresolvedExpression visitColumnFilter(ColumnFilterContext ctx) { return new Function( LIKE.getName().getFunctionName(), - List.of(qualifiedName("COLUMN_NAME"), visit(ctx.showDescribePattern()))); + Arrays.asList(qualifiedName("COLUMN_NAME"), visit(ctx.showDescribePattern()))); } @Override @@ -199,7 +202,7 @@ public UnresolvedExpression visitFilteredAggregationFunctionCall( public UnresolvedExpression visitWindowFunctionClause(WindowFunctionClauseContext ctx) { OverClauseContext overClause = ctx.overClause(); - List partitionByList = List.of(); + List partitionByList = Collections.emptyList(); if (overClause.partitionByClause() != null) { partitionByList = overClause.partitionByClause().expression().stream() @@ -207,7 +210,7 @@ public UnresolvedExpression visitWindowFunctionClause(WindowFunctionClauseContex .collect(Collectors.toList()); } - List> sortList = List.of(); + List> sortList = Collections.emptyList(); if (overClause.orderByClause() != null) { sortList = overClause.orderByClause().orderByElement().stream() @@ -267,13 +270,13 @@ public UnresolvedExpression visitBetweenPredicate(BetweenPredicateContext ctx) { public UnresolvedExpression visitLikePredicate(LikePredicateContext ctx) { return new Function( ctx.NOT() == null ? LIKE.getName().getFunctionName() : NOT_LIKE.getName().getFunctionName(), - List.of(visit(ctx.left), visit(ctx.right))); + Arrays.asList(visit(ctx.left), visit(ctx.right))); } @Override public UnresolvedExpression visitRegexpPredicate(RegexpPredicateContext ctx) { return new Function( - REGEXP.getName().getFunctionName(), List.of(visit(ctx.left), visit(ctx.right))); + REGEXP.getName().getFunctionName(), Arrays.asList(visit(ctx.left), visit(ctx.right))); } @Override @@ -359,7 +362,7 @@ public UnresolvedExpression visitBinaryComparisonPredicate(BinaryComparisonPredi String functionName = ctx.comparisonOperator().getText(); return new Function( functionName.equals("<>") ? "!=" : functionName, - List.of(visit(ctx.left), visit(ctx.right))); + Arrays.asList(visit(ctx.left), visit(ctx.right))); } @Override @@ -574,7 +577,7 @@ private List multiFieldRelevanceArguments( private List getFormatFunctionArguments(GetFormatFunctionCallContext ctx) { List args = - List.of( + Arrays.asList( new Literal(ctx.getFormatFunction().getFormatType().getText(), DataType.STRING), visitFunctionArg(ctx.getFormatFunction().functionArg())); return args; @@ -582,7 +585,7 @@ private List getFormatFunctionArguments(GetFormatFunctionC private List timestampFunctionArguments(TimestampFunctionCallContext ctx) { List args = - List.of( + Arrays.asList( new Literal(ctx.timestampFunction().simpleDateTimePart().getText(), DataType.STRING), visitFunctionArg(ctx.timestampFunction().firstArg), visitFunctionArg(ctx.timestampFunction().secondArg)); @@ -657,7 +660,7 @@ private List altMultiFieldRelevanceFunctionArguments( private List getExtractFunctionArguments(ExtractFunctionCallContext ctx) { List args = - List.of( + Arrays.asList( new Literal(ctx.extractFunction().datetimePart().getText(), DataType.STRING), visitFunctionArg(ctx.extractFunction().functionArg())); return args; From 93fe7c31d56369837bb1ea64e32b4a572a93687a Mon Sep 17 00:00:00 2001 From: currantw Date: Thu, 12 Dec 2024 14:53:08 -0800 Subject: [PATCH 16/16] Fix failing integration test (due to null values in list) Signed-off-by: currantw --- .../sql/correctness/tests/ComparisonTestTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 965cf1edb4b..793d9aa03bc 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 @@ -5,6 +5,7 @@ package org.opensearch.sql.correctness.tests; +import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -82,7 +83,7 @@ public void testFailureDueToInconsistency() { TestReport expected = new TestReport(); expected.addTestCase( new FailedTestCase( - 1, "SELECT * FROM accounts", List.of(openSearchResult, otherDbResult), "")); + 1, "SELECT * FROM accounts", asList(openSearchResult, otherDbResult), "")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); } @@ -146,7 +147,7 @@ public void testFailureDueToEventualInconsistency() { new FailedTestCase( 1, "SELECT * FROM accounts", - List.of(openSearchResult, otherDbResult, anotherDbResult), + asList(openSearchResult, otherDbResult, anotherDbResult), "")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual); @@ -238,7 +239,7 @@ public void testFailureDueToInconsistencyAndExceptionMixed() { new FailedTestCase( 1, "SELECT * FROM accounts", - List.of(openSearchResult, otherResult), + asList(openSearchResult, otherResult), "Unsupported feature;")); TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts")); assertEquals(expected, actual);