From 0ca7f2b3d2a02e9330828bf2079681f8c68b8879 Mon Sep 17 00:00:00 2001 From: currantw Date: Mon, 9 Dec 2024 15:49:39 -0800 Subject: [PATCH] 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 793d9aa03b..f3ca1f1838 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 798d1c23e9..8bf4cc2998 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 5ce7e3d4d8..8fa3f189ba 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 96210c7d8a..3c0cc4fdaa 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 971169f102..0f21112728 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 f9915a5317..04bf7401ce 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 a88f93bd2d..35435ee704 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 5e7687e409..4b45c8d15b 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;