Skip to content

Commit

Permalink
Update remaining asList issues
Browse files Browse the repository at this point in the history
Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Dec 12, 2024
1 parent dd0ac2b commit d8f31e0
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -114,15 +115,17 @@ 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
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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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");
}
Expand All @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<NamedExpression> groupByExprs = List.of(named("age", ref("age", INTEGER)));
List<NamedExpression> groupByExprs = List.of(DSL.named("age", ref("age", INTEGER)));
List<Expression> aggExprs = List.of(ref("age", INTEGER));
ReferenceExpression rareTopNField = ref("age", INTEGER);
List<Expression> topByExprs = List.of(ref("age", INTEGER));
List<NamedAggregator> aggregators =
List.of(named("avg(age)", new AvgAggregator(aggExprs, ExprCoreType.DOUBLE)));
List.of(DSL.named("avg(age)", new AvgAggregator(aggExprs, ExprCoreType.DOUBLE)));
Map<ReferenceExpression, ReferenceExpression> mappings =
ImmutableMap.of(ref("name", STRING), ref("lastname", STRING));
Pair<ReferenceExpression, Expression> newEvalField =
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -279,11 +283,11 @@ public void visitLimit_support_return_takeOrdered() {
// replace SortOperator + LimitOperator with TakeOrderedOperator
Pair<Sort.SortOption, Expression> 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
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand All @@ -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);
}
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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"));

Expand All @@ -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"));
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand Down Expand Up @@ -66,19 +67,19 @@ 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);
}

@Test
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: "
Expand Down
Loading

0 comments on commit d8f31e0

Please sign in to comment.