From 82567d3a458bc484dd19abb2f96fdd6239a78210 Mon Sep 17 00:00:00 2001 From: currantw Date: Thu, 12 Dec 2024 13:45:35 -0800 Subject: [PATCH] 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 1ddf53a8b9..ae345fa989 100644 --- a/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java @@ -24,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 7174088152..7aad75b204 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 9ced180ff0..965cf1edb4 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 8bf4cc2998..bbbfe6cb2a 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 03b6c3fb64..a0729e94ce 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 bfdc2392b2..0df0c8db75 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 9a42cb089f..e79a229d00 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 887c655702..b86ab0cd59 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 4b45c8d15b..f32aa6a628 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;