diff --git a/build.gradle b/build.gradle
index 71f94636b5..0c58fccfeb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -84,21 +84,7 @@ repositories {
spotless {
java {
target fileTree('.') {
- include 'core/src/main/java/org/opensearch/sql/DataSourceSchemaName.java',
- 'core/src/test/java/org/opensearch/sql/data/**/*.java',
- 'core/src/test/java/org/opensearch/sql/config/**/*.java',
- 'core/src/test/java/org/opensearch/sql/analysis/**/*.java',
- 'core/src/main/java/org/opensearch/sql/planner/**/*.java',
- 'core/src/main/java/org/opensearch/sql/storage/**/*.java',
- 'core/src/main/java/org/opensearch/sql/utils/**/*.java',
- 'core/src/main/java/org/opensearch/sql/monitor/**/*.java',
- 'core/src/main/java/org/opensearch/sql/expression/**/*.java',
- 'core/src/main/java/org/opensearch/sql/executor/**/*.java',
- 'core/src/main/java/org/opensearch/sql/exception/**/*.java',
- 'core/src/main/java/org/opensearch/sql/analysis/**/*.java',
- 'core/src/test/java/org/opensearch/sql/data/**/*.java',
- 'core/src/test/java/org/opensearch/sql/datasource/**/*.java',
- 'core/src/test/java/org/opensearch/sql/ast/**/*.java'
+ include 'core/**/*.java'
exclude '**/build/**', '**/build-*/**'
}
importOrder()
diff --git a/core/build.gradle b/core/build.gradle
index cf7f0b7a1c..5d67740a28 100644
--- a/core/build.gradle
+++ b/core/build.gradle
@@ -66,6 +66,9 @@ dependencies {
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.12.4'
}
+checkstyleMain.ignoreFailures = true
+checkstyleTest.ignoreFailures = true
+
test {
useJUnitPlatform()
testLogging {
diff --git a/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java b/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java
index 4ceb387076..d1d779032a 100644
--- a/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java
+++ b/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java
@@ -255,7 +255,6 @@ public static Function function(String funcName, UnresolvedExpression... funcArg
* [WHEN search_condition THEN result_expr] ...
* [ELSE result_expr]
* END
- *
*/
public UnresolvedExpression caseWhen(UnresolvedExpression elseClause,
When... whenClauses) {
@@ -269,7 +268,6 @@ public UnresolvedExpression caseWhen(UnresolvedExpression elseClause,
* [WHEN compare_expr THEN result_expr] ...
* [ELSE result_expr]
* END
- *
*/
public UnresolvedExpression caseWhen(UnresolvedExpression caseValueExpr,
UnresolvedExpression elseClause,
diff --git a/core/src/main/java/org/opensearch/sql/data/model/AbstractExprValue.java b/core/src/main/java/org/opensearch/sql/data/model/AbstractExprValue.java
index f5ac4d493b..1076e32ec3 100644
--- a/core/src/main/java/org/opensearch/sql/data/model/AbstractExprValue.java
+++ b/core/src/main/java/org/opensearch/sql/data/model/AbstractExprValue.java
@@ -3,18 +3,23 @@
* SPDX-License-Identifier: Apache-2.0
*/
+
package org.opensearch.sql.data.model;
import org.opensearch.sql.exception.ExpressionEvaluationException;
-/** Abstract ExprValue. */
+/**
+ * Abstract ExprValue.
+ */
public abstract class AbstractExprValue implements ExprValue {
- /** The customize compareTo logic. */
+ /**
+ * The customize compareTo logic.
+ */
@Override
public int compareTo(ExprValue other) {
if (this.isNull() || this.isMissing() || other.isNull() || other.isMissing()) {
throw new IllegalStateException(
- "[BUG] Unreachable, Comparing with NULL or MISSING is undefined");
+ "[BUG] Unreachable, Comparing with NULL or MISSING is undefined");
}
if ((this.isNumber() && other.isNumber())
|| (this.isDateTime() && other.isDateTime())
@@ -29,7 +34,7 @@ public int compareTo(ExprValue other) {
}
/**
- * The customize equals logic.
+ * The customize equals logic.
* The table below list the NULL and MISSING handling logic.
*
*
@@ -76,9 +81,13 @@ public boolean equals(Object o) {
}
}
- /** The expression value compare. */
+ /**
+ * The expression value compare.
+ */
public abstract int compare(ExprValue other);
- /** The expression value equal. */
+ /**
+ * The expression value equal.
+ */
public abstract boolean equal(ExprValue other);
}
diff --git a/core/src/main/java/org/opensearch/sql/executor/pagination/CanPaginateVisitor.java b/core/src/main/java/org/opensearch/sql/executor/pagination/CanPaginateVisitor.java
index 9f14ba1e5d..e5f1ec49e4 100644
--- a/core/src/main/java/org/opensearch/sql/executor/pagination/CanPaginateVisitor.java
+++ b/core/src/main/java/org/opensearch/sql/executor/pagination/CanPaginateVisitor.java
@@ -88,8 +88,8 @@ protected Boolean canPaginate(Node node, Object context) {
// https://github.com/opensearch-project/sql/issues/1471
@Override
public Boolean visitSort(Sort node, Object context) {
- return node.getSortList().stream()
- .allMatch(f -> f.getField() instanceof QualifiedName && visitField(f, context))
+ return node.getSortList().stream().allMatch(f -> f.getField() instanceof QualifiedName
+ && visitField(f, context))
&& canPaginate(node, context);
}
@@ -124,8 +124,8 @@ public Boolean visitLiteral(Literal node, Object context) {
@Override
public Boolean visitField(Field node, Object context) {
- return canPaginate(node, context)
- && node.getFieldArgs().stream().allMatch(n -> n.accept(this, context));
+ return canPaginate(node, context) && node.getFieldArgs().stream()
+ .allMatch(n -> n.accept(this, context));
}
@Override
@@ -200,8 +200,8 @@ public Boolean visitFunction(Function node, Object context) {
@Override
public Boolean visitIn(In node, Object context) {
- return canPaginate(node, context)
- && node.getValueList().stream().allMatch(n -> n.accept(this, context));
+ return canPaginate(node, context) && node.getValueList().stream()
+ .allMatch(n -> n.accept(this, context));
}
@Override
diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java
index 4a1d4d309b..fed1535aa1 100644
--- a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java
+++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java
@@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
+
package org.opensearch.sql.expression.aggregation;
import static org.opensearch.sql.data.type.ExprCoreType.ARRAY;
@@ -65,37 +66,26 @@ private static DefaultFunctionResolver avg() {
return new DefaultFunctionResolver(
functionName,
new ImmutableMap.Builder()
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
(functionProperties, arguments) -> new AvgAggregator(arguments, DOUBLE))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DATE)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DATE)),
(functionProperties, arguments) -> new AvgAggregator(arguments, DATE))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DATETIME)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DATETIME)),
(functionProperties, arguments) -> new AvgAggregator(arguments, DATETIME))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(TIME)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(TIME)),
(functionProperties, arguments) -> new AvgAggregator(arguments, TIME))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)),
(functionProperties, arguments) -> new AvgAggregator(arguments, TIMESTAMP))
- .build());
+ .build()
+ );
}
private static DefaultFunctionResolver count() {
FunctionName functionName = BuiltinFunctionName.COUNT.getName();
- DefaultFunctionResolver functionResolver =
- new DefaultFunctionResolver(
- functionName,
- ExprCoreType.coreTypes().stream()
- .collect(
- Collectors.toMap(
- type ->
- new FunctionSignature(functionName, Collections.singletonList(type)),
- type ->
- (functionProperties, arguments) ->
- new CountAggregator(arguments, INTEGER))));
+ DefaultFunctionResolver functionResolver = new DefaultFunctionResolver(functionName,
+ ExprCoreType.coreTypes().stream().collect(Collectors.toMap(
+ type -> new FunctionSignature(functionName, Collections.singletonList(type)),
+ type -> (functionProperties, arguments) -> new CountAggregator(arguments, INTEGER))));
return functionResolver;
}
@@ -104,19 +94,16 @@ private static DefaultFunctionResolver sum() {
return new DefaultFunctionResolver(
functionName,
new ImmutableMap.Builder()
- .put(
- new FunctionSignature(functionName, Collections.singletonList(INTEGER)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(INTEGER)),
(functionProperties, arguments) -> new SumAggregator(arguments, INTEGER))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(LONG)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(LONG)),
(functionProperties, arguments) -> new SumAggregator(arguments, LONG))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(FLOAT)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(FLOAT)),
(functionProperties, arguments) -> new SumAggregator(arguments, FLOAT))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
(functionProperties, arguments) -> new SumAggregator(arguments, DOUBLE))
- .build());
+ .build()
+ );
}
private static DefaultFunctionResolver min() {
@@ -124,32 +111,23 @@ private static DefaultFunctionResolver min() {
return new DefaultFunctionResolver(
functionName,
new ImmutableMap.Builder()
- .put(
- new FunctionSignature(functionName, Collections.singletonList(INTEGER)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(INTEGER)),
(functionProperties, arguments) -> new MinAggregator(arguments, INTEGER))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(LONG)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(LONG)),
(functionProperties, arguments) -> new MinAggregator(arguments, LONG))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(FLOAT)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(FLOAT)),
(functionProperties, arguments) -> new MinAggregator(arguments, FLOAT))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
(functionProperties, arguments) -> new MinAggregator(arguments, DOUBLE))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(STRING)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(STRING)),
(functionProperties, arguments) -> new MinAggregator(arguments, STRING))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DATE)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DATE)),
(functionProperties, arguments) -> new MinAggregator(arguments, DATE))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DATETIME)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DATETIME)),
(functionProperties, arguments) -> new MinAggregator(arguments, DATETIME))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(TIME)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(TIME)),
(functionProperties, arguments) -> new MinAggregator(arguments, TIME))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)),
(functionProperties, arguments) -> new MinAggregator(arguments, TIMESTAMP))
.build());
}
@@ -159,34 +137,26 @@ private static DefaultFunctionResolver max() {
return new DefaultFunctionResolver(
functionName,
new ImmutableMap.Builder()
- .put(
- new FunctionSignature(functionName, Collections.singletonList(INTEGER)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(INTEGER)),
(functionProperties, arguments) -> new MaxAggregator(arguments, INTEGER))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(LONG)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(LONG)),
(functionProperties, arguments) -> new MaxAggregator(arguments, LONG))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(FLOAT)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(FLOAT)),
(functionProperties, arguments) -> new MaxAggregator(arguments, FLOAT))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
(functionProperties, arguments) -> new MaxAggregator(arguments, DOUBLE))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(STRING)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(STRING)),
(functionProperties, arguments) -> new MaxAggregator(arguments, STRING))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DATE)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DATE)),
(functionProperties, arguments) -> new MaxAggregator(arguments, DATE))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DATETIME)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DATETIME)),
(functionProperties, arguments) -> new MaxAggregator(arguments, DATETIME))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(TIME)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(TIME)),
(functionProperties, arguments) -> new MaxAggregator(arguments, TIME))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)),
(functionProperties, arguments) -> new MaxAggregator(arguments, TIMESTAMP))
- .build());
+ .build()
+ );
}
private static DefaultFunctionResolver varSamp() {
@@ -194,10 +164,10 @@ private static DefaultFunctionResolver varSamp() {
return new DefaultFunctionResolver(
functionName,
new ImmutableMap.Builder()
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
(functionProperties, arguments) -> varianceSample(arguments, DOUBLE))
- .build());
+ .build()
+ );
}
private static DefaultFunctionResolver varPop() {
@@ -205,10 +175,10 @@ private static DefaultFunctionResolver varPop() {
return new DefaultFunctionResolver(
functionName,
new ImmutableMap.Builder()
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
(functionProperties, arguments) -> variancePopulation(arguments, DOUBLE))
- .build());
+ .build()
+ );
}
private static DefaultFunctionResolver stddevSamp() {
@@ -216,10 +186,10 @@ private static DefaultFunctionResolver stddevSamp() {
return new DefaultFunctionResolver(
functionName,
new ImmutableMap.Builder()
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
(functionProperties, arguments) -> stddevSample(arguments, DOUBLE))
- .build());
+ .build()
+ );
}
private static DefaultFunctionResolver stddevPop() {
@@ -227,22 +197,20 @@ private static DefaultFunctionResolver stddevPop() {
return new DefaultFunctionResolver(
functionName,
new ImmutableMap.Builder()
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
+ .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
(functionProperties, arguments) -> stddevPopulation(arguments, DOUBLE))
- .build());
+ .build()
+ );
}
private static DefaultFunctionResolver take() {
FunctionName functionName = BuiltinFunctionName.TAKE.getName();
- DefaultFunctionResolver functionResolver =
- new DefaultFunctionResolver(
- functionName,
- new ImmutableMap.Builder()
- .put(
- new FunctionSignature(functionName, ImmutableList.of(STRING, INTEGER)),
- (functionProperties, arguments) -> new TakeAggregator(arguments, ARRAY))
- .build());
+ DefaultFunctionResolver functionResolver = new DefaultFunctionResolver(functionName,
+ new ImmutableMap.Builder()
+ .put(new FunctionSignature(functionName, ImmutableList.of(STRING, INTEGER)),
+ (functionProperties, arguments) -> new TakeAggregator(arguments, ARRAY))
+ .build());
return functionResolver;
}
+
}
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 7d438c870d..897347f22d 100644
--- a/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java
+++ b/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.executor;
import static java.util.Collections.emptyList;
@@ -68,36 +67,30 @@ void can_explain_project_filter_table_scan() {
DSL.equal(ref("balance", INTEGER), literal(10000)),
DSL.greater(ref("age", INTEGER), literal(30)));
NamedExpression[] projectList = {
- named("full_name", ref("full_name", STRING), "name"),
- named("age", ref("age", INTEGER))
+ named("full_name", ref("full_name", STRING), "name"), named("age", ref("age", INTEGER))
};
- PhysicalPlan plan =
- project(
- filter(
- tableScan,
- filterExpr),
- projectList);
+ PhysicalPlan plan = project(filter(tableScan, filterExpr), projectList);
assertEquals(
new ExplainResponse(
new ExplainResponseNode(
"ProjectOperator",
Map.of("fields", "[name, age]"),
- singletonList(new ExplainResponseNode(
- "FilterOperator",
- Map.of("conditions", "and(=(balance, 10000), >(age, 30))"),
- singletonList(tableScan.explainNode()))))),
+ singletonList(
+ new ExplainResponseNode(
+ "FilterOperator",
+ Map.of("conditions", "and(=(balance, 10000), >(age, 30))"),
+ singletonList(tableScan.explainNode()))))),
explain.apply(plan));
}
@Test
void can_explain_aggregations() {
List aggExprs = List.of(ref("balance", DOUBLE));
- List aggList = List.of(
- named("avg(balance)", DSL.avg(aggExprs.toArray(new Expression[0]))));
- List groupByList = List.of(
- named("state", ref("state", STRING)));
+ List aggList =
+ List.of(named("avg(balance)", DSL.avg(aggExprs.toArray(new Expression[0]))));
+ List groupByList = List.of(named("state", ref("state", STRING)));
PhysicalPlan plan = agg(new FakeTableScan(), aggList, groupByList);
assertEquals(
@@ -120,11 +113,7 @@ void can_explain_rare_top_n() {
new ExplainResponse(
new ExplainResponseNode(
"RareTopNOperator",
- Map.of(
- "commandType", TOP,
- "noOfResults", 10,
- "fields", "[state]",
- "groupBy", "[]"),
+ Map.of("commandType", TOP, "noOfResults", 10, "fields", "[state]", "groupBy", "[]"),
singletonList(tableScan.explainNode()))),
explain.apply(plan));
}
@@ -132,22 +121,27 @@ void can_explain_rare_top_n() {
@Test
void can_explain_window() {
List partitionByList = List.of(DSL.ref("state", STRING));
- List> sortList = List.of(
- ImmutablePair.of(DEFAULT_ASC, ref("age", INTEGER)));
+ List> sortList =
+ List.of(ImmutablePair.of(DEFAULT_ASC, ref("age", INTEGER)));
- PhysicalPlan plan = window(tableScan, named(DSL.rank()),
- new WindowDefinition(partitionByList, sortList));
+ PhysicalPlan plan =
+ window(tableScan, named(DSL.rank()), new WindowDefinition(partitionByList, sortList));
assertEquals(
new ExplainResponse(
new ExplainResponseNode(
"WindowOperator",
Map.of(
- "function", "rank()",
- "definition", Map.of(
- "partitionBy", "[state]",
- "sortList", Map.of(
- "age", Map.of(
+ "function",
+ "rank()",
+ "definition",
+ Map.of(
+ "partitionBy",
+ "[state]",
+ "sortList",
+ Map.of(
+ "age",
+ Map.of(
"sortOrder", "ASC",
"nullOrder", "NULL_FIRST")))),
singletonList(tableScan.explainNode()))),
@@ -157,60 +151,61 @@ void can_explain_window() {
@Test
void can_explain_other_operators() {
ReferenceExpression[] removeList = {ref("state", STRING)};
- Map renameMapping = Map.of(
- ref("state", STRING), ref("s", STRING));
- Pair evalExprs = ImmutablePair.of(
- ref("age", INTEGER), DSL.add(ref("age", INTEGER), literal(2)));
+ Map renameMapping =
+ Map.of(ref("state", STRING), ref("s", STRING));
+ Pair evalExprs =
+ ImmutablePair.of(ref("age", INTEGER), DSL.add(ref("age", INTEGER), literal(2)));
Expression[] dedupeList = {ref("age", INTEGER)};
- Pair sortList = ImmutablePair.of(
- DEFAULT_ASC, ref("age", INTEGER));
+ Pair sortList = ImmutablePair.of(DEFAULT_ASC, ref("age", INTEGER));
List values = List.of(literal("WA"), literal(30));
PhysicalPlan plan =
remove(
rename(
- eval(
- dedupe(
- sort(
- values(values),
- sortList),
- dedupeList),
- evalExprs),
- renameMapping),
- removeList);
+ eval(dedupe(sort(values(values), sortList), dedupeList), evalExprs), renameMapping),
+ removeList);
assertEquals(
new ExplainResponse(
new ExplainResponseNode(
"RemoveOperator",
Map.of("removeList", "[state]"),
- singletonList(new ExplainResponseNode(
- "RenameOperator",
- Map.of("mapping", Map.of("state", "s")),
- singletonList(new ExplainResponseNode(
- "EvalOperator",
- Map.of("expressions", Map.of("age", "+(age, 2)")),
- singletonList(new ExplainResponseNode(
- "DedupeOperator",
- Map.of(
- "dedupeList", "[age]",
- "allowedDuplication", 1,
- "keepEmpty", false,
- "consecutive", false),
- singletonList(new ExplainResponseNode(
- "SortOperator",
- Map.of(
- "sortList", Map.of(
- "age", Map.of(
- "sortOrder", "ASC",
- "nullOrder", "NULL_FIRST"))),
- singletonList(new ExplainResponseNode(
- "ValuesOperator",
- Map.of("values", List.of(values)),
- emptyList())))))))))))
- ),
- explain.apply(plan)
- );
+ singletonList(
+ new ExplainResponseNode(
+ "RenameOperator",
+ Map.of("mapping", Map.of("state", "s")),
+ singletonList(
+ new ExplainResponseNode(
+ "EvalOperator",
+ Map.of("expressions", Map.of("age", "+(age, 2)")),
+ singletonList(
+ new ExplainResponseNode(
+ "DedupeOperator",
+ Map.of(
+ "dedupeList",
+ "[age]",
+ "allowedDuplication",
+ 1,
+ "keepEmpty",
+ false,
+ "consecutive",
+ false),
+ singletonList(
+ new ExplainResponseNode(
+ "SortOperator",
+ Map.of(
+ "sortList",
+ Map.of(
+ "age",
+ Map.of(
+ "sortOrder", "ASC",
+ "nullOrder", "NULL_FIRST"))),
+ singletonList(
+ new ExplainResponseNode(
+ "ValuesOperator",
+ Map.of("values", List.of(values)),
+ emptyList())))))))))))),
+ explain.apply(plan));
}
@Test
@@ -222,15 +217,13 @@ void can_explain_limit() {
"LimitOperator",
Map.of("limit", 10, "offset", 5),
singletonList(tableScan.explainNode()))),
- explain.apply(plan)
- );
+ explain.apply(plan));
}
@Test
void can_explain_nested() {
Set nestedOperatorArgs = Set.of("message.info", "message");
- Map> groupedFieldsByPath =
- Map.of("message", List.of("message.info"));
+ Map> groupedFieldsByPath = Map.of("message", List.of("message.info"));
PhysicalPlan plan = nested(tableScan, nestedOperatorArgs, groupedFieldsByPath);
assertEquals(
@@ -239,8 +232,7 @@ void can_explain_nested() {
"NestedOperator",
Map.of("nested", Set.of("message.info", "message")),
singletonList(tableScan.explainNode()))),
- explain.apply(plan)
- );
+ explain.apply(plan));
}
private static class FakeTableScan extends TableScanOperator {
@@ -262,14 +254,11 @@ 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"), emptyList());
}
public String explain() {
return "explain";
}
}
-
}
diff --git a/core/src/test/java/org/opensearch/sql/executor/QueryServiceTest.java b/core/src/test/java/org/opensearch/sql/executor/QueryServiceTest.java
index 1510b304e6..f6b66b4e77 100644
--- a/core/src/test/java/org/opensearch/sql/executor/QueryServiceTest.java
+++ b/core/src/test/java/org/opensearch/sql/executor/QueryServiceTest.java
@@ -37,73 +37,52 @@ class QueryServiceTest {
private QueryService queryService;
- @Mock
- private ExecutionEngine executionEngine;
+ @Mock private ExecutionEngine executionEngine;
- @Mock
- private Analyzer analyzer;
+ @Mock private Analyzer analyzer;
- @Mock
- private Planner planner;
+ @Mock private Planner planner;
- @Mock
- private UnresolvedPlan ast;
+ @Mock private UnresolvedPlan ast;
- @Mock
- private LogicalPlan logicalPlan;
+ @Mock private LogicalPlan logicalPlan;
- @Mock
- private PhysicalPlan plan;
+ @Mock private PhysicalPlan plan;
- @Mock
- private ExecutionEngine.Schema schema;
+ @Mock private ExecutionEngine.Schema schema;
- @Mock
- private PlanContext planContext;
+ @Mock private PlanContext planContext;
- @Mock
- private Split split;
+ @Mock private Split split;
@Test
public void executeWithoutContext() {
- queryService()
- .executeSuccess()
- .handledByOnResponse();
+ queryService().executeSuccess().handledByOnResponse();
}
@Test
public void executeWithContext() {
- queryService()
- .executeSuccess(split)
- .handledByOnResponse();
+ queryService().executeSuccess(split).handledByOnResponse();
}
@Test
public void testExplainShouldPass() {
- queryService()
- .explainSuccess()
- .handledByExplainOnResponse();
+ queryService().explainSuccess().handledByExplainOnResponse();
}
@Test
public void testExecuteWithExceptionShouldBeCaughtByHandler() {
- queryService()
- .executeFail()
- .handledByOnFailure();
+ queryService().executeFail().handledByOnFailure();
}
@Test
public void explainWithIllegalQueryShouldBeCaughtByHandler() {
- queryService()
- .explainFail()
- .handledByExplainOnFailure();
+ queryService().explainFail().handledByExplainOnFailure();
}
@Test
public void analyzeExceptionShouldBeCached() {
- queryService()
- .analyzeFail()
- .handledByOnFailure();
+ queryService().analyzeFail().handledByOnFailure();
}
Helper queryService() {
@@ -130,13 +109,14 @@ Helper executeSuccess() {
Helper executeSuccess(Split split) {
this.split = Optional.ofNullable(split);
doAnswer(
- invocation -> {
- ResponseListener listener = invocation.getArgument(2);
- listener.onResponse(
- new ExecutionEngine.QueryResponse(schema, Collections.emptyList(),
- Cursor.None));
- return null;
- })
+ invocation -> {
+ ResponseListener listener =
+ invocation.getArgument(2);
+ listener.onResponse(
+ new ExecutionEngine.QueryResponse(
+ schema, Collections.emptyList(), Cursor.None));
+ return null;
+ })
.when(executionEngine)
.execute(any(), any(), any());
lenient().when(planContext.getSplit()).thenReturn(this.split);
@@ -145,9 +125,7 @@ Helper executeSuccess(Split split) {
}
Helper analyzeFail() {
- doThrow(new IllegalStateException("analyze exception"))
- .when(analyzer)
- .analyze(any(), any());
+ doThrow(new IllegalStateException("analyze exception")).when(analyzer).analyze(any(), any());
return this;
}
@@ -162,14 +140,14 @@ Helper executeFail() {
Helper explainSuccess() {
doAnswer(
- invocation -> {
- ResponseListener listener =
- invocation.getArgument(1);
- listener.onResponse(
- new ExecutionEngine.ExplainResponse(
- new ExecutionEngine.ExplainResponseNode("test")));
- return null;
- })
+ invocation -> {
+ ResponseListener listener =
+ invocation.getArgument(1);
+ listener.onResponse(
+ new ExecutionEngine.ExplainResponse(
+ new ExecutionEngine.ExplainResponseNode("test")));
+ return null;
+ })
.when(executionEngine)
.explain(any(), any());
@@ -184,36 +162,37 @@ Helper explainFail() {
return this;
}
-
void handledByOnResponse() {
- ResponseListener responseListener = new ResponseListener<>() {
- @Override
- public void onResponse(ExecutionEngine.QueryResponse pplQueryResponse) {
- assertNotNull(pplQueryResponse);
- }
-
- @Override
- public void onFailure(Exception e) {
- fail();
- }
- };
+ ResponseListener responseListener =
+ new ResponseListener<>() {
+ @Override
+ public void onResponse(ExecutionEngine.QueryResponse pplQueryResponse) {
+ assertNotNull(pplQueryResponse);
+ }
+
+ @Override
+ public void onFailure(Exception e) {
+ fail();
+ }
+ };
split.ifPresentOrElse(
split -> queryService.executePlan(logicalPlan, planContext, responseListener),
() -> queryService.execute(ast, responseListener));
}
void handledByOnFailure() {
- ResponseListener responseListener = new ResponseListener<>() {
- @Override
- public void onResponse(ExecutionEngine.QueryResponse pplQueryResponse) {
- fail();
- }
-
- @Override
- public void onFailure(Exception e) {
- assertTrue(e instanceof IllegalStateException);
- }
- };
+ ResponseListener responseListener =
+ new ResponseListener<>() {
+ @Override
+ public void onResponse(ExecutionEngine.QueryResponse pplQueryResponse) {
+ fail();
+ }
+
+ @Override
+ public void onFailure(Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+ };
split.ifPresentOrElse(
split -> queryService.executePlan(logicalPlan, planContext, responseListener),
() -> queryService.execute(ast, responseListener));
@@ -250,6 +229,5 @@ public void onFailure(Exception e) {
}
});
}
-
}
}
diff --git a/core/src/test/java/org/opensearch/sql/executor/execution/CommandPlanTest.java b/core/src/test/java/org/opensearch/sql/executor/execution/CommandPlanTest.java
index aa300cb0da..aff5a0d867 100644
--- a/core/src/test/java/org/opensearch/sql/executor/execution/CommandPlanTest.java
+++ b/core/src/test/java/org/opensearch/sql/executor/execution/CommandPlanTest.java
@@ -47,8 +47,7 @@ public void execute_without_error() {
public void execute_with_error() {
QueryService qs = mock(QueryService.class, withSettings().defaultAnswer(CALLS_REAL_METHODS));
ResponseListener listener = mock(ResponseListener.class);
- doThrow(new RuntimeException())
- .when(qs).executePlan(any(LogicalPlan.class), any(), any());
+ doThrow(new RuntimeException()).when(qs).executePlan(any(LogicalPlan.class), any(), any());
new CommandPlan(QueryId.queryId(), mock(UnresolvedPlan.class), qs, listener).execute();
@@ -62,9 +61,12 @@ public void explain_not_supported() {
ResponseListener listener = mock(ResponseListener.class);
ResponseListener explainListener = mock(ResponseListener.class);
- var exception = assertThrows(Throwable.class, () ->
- new CommandPlan(QueryId.queryId(), mock(UnresolvedPlan.class), qs, listener)
- .explain(explainListener));
+ var exception =
+ assertThrows(
+ Throwable.class,
+ () ->
+ new CommandPlan(QueryId.queryId(), mock(UnresolvedPlan.class), qs, listener)
+ .explain(explainListener));
assertEquals("CommandPlan does not support explain", exception.getMessage());
verify(listener, never()).onResponse(any());
diff --git a/core/src/test/java/org/opensearch/sql/executor/execution/ExplainPlanTest.java b/core/src/test/java/org/opensearch/sql/executor/execution/ExplainPlanTest.java
index 54b4f24db0..cdb7f9dcb8 100644
--- a/core/src/test/java/org/opensearch/sql/executor/execution/ExplainPlanTest.java
+++ b/core/src/test/java/org/opensearch/sql/executor/execution/ExplainPlanTest.java
@@ -25,14 +25,11 @@
@ExtendWith(MockitoExtension.class)
public class ExplainPlanTest {
- @Mock
- private QueryId queryId;
+ @Mock private QueryId queryId;
- @Mock
- private QueryPlan queryPlan;
+ @Mock private QueryPlan queryPlan;
- @Mock
- private ResponseListener explainListener;
+ @Mock private ResponseListener explainListener;
@Test
public void execute() {
diff --git a/core/src/test/java/org/opensearch/sql/executor/execution/IntervalTriggerExecutionTest.java b/core/src/test/java/org/opensearch/sql/executor/execution/IntervalTriggerExecutionTest.java
index e0638ba88f..9eb99d37e3 100644
--- a/core/src/test/java/org/opensearch/sql/executor/execution/IntervalTriggerExecutionTest.java
+++ b/core/src/test/java/org/opensearch/sql/executor/execution/IntervalTriggerExecutionTest.java
@@ -18,16 +18,12 @@ public class IntervalTriggerExecutionTest {
@Test
void executeTaskWithInterval() {
- triggerTask(2)
- .taskRun(1)
- .aroundInterval();
+ triggerTask(2).taskRun(1).aroundInterval();
}
@Test
void continueExecuteIfTaskRunningLongerThanInterval() {
- triggerTask(1)
- .taskRun(2)
- .aroundTaskRuntime();
+ triggerTask(1).taskRun(2).aroundTaskRuntime();
}
Helper triggerTask(long interval) {
diff --git a/core/src/test/java/org/opensearch/sql/executor/execution/QueryPlanFactoryTest.java b/core/src/test/java/org/opensearch/sql/executor/execution/QueryPlanFactoryTest.java
index 2d346e4c2a..5aed9acc63 100644
--- a/core/src/test/java/org/opensearch/sql/executor/execution/QueryPlanFactoryTest.java
+++ b/core/src/test/java/org/opensearch/sql/executor/execution/QueryPlanFactoryTest.java
@@ -41,20 +41,15 @@
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
class QueryPlanFactoryTest {
- @Mock
- private UnresolvedPlan plan;
+ @Mock private UnresolvedPlan plan;
- @Mock
- private QueryService queryService;
+ @Mock private QueryService queryService;
- @Mock
- private ResponseListener queryListener;
+ @Mock private ResponseListener queryListener;
- @Mock
- private ResponseListener explainListener;
+ @Mock private ResponseListener explainListener;
- @Mock
- private ExecutionEngine.QueryResponse queryResponse;
+ @Mock private ExecutionEngine.QueryResponse queryResponse;
private QueryPlanFactory factory;
@@ -81,14 +76,11 @@ public void create_from_explain_should_success() {
@Test
public void create_from_cursor_should_success() {
- AbstractPlan queryExecution = factory.create("", false,
- queryListener, explainListener);
- AbstractPlan explainExecution = factory.create("", true,
- queryListener, explainListener);
+ AbstractPlan queryExecution = factory.create("", false, queryListener, explainListener);
+ AbstractPlan explainExecution = factory.create("", true, queryListener, explainListener);
assertAll(
() -> assertTrue(queryExecution instanceof QueryPlan),
- () -> assertTrue(explainExecution instanceof ExplainPlan)
- );
+ () -> assertTrue(explainExecution instanceof ExplainPlan));
}
@Test
@@ -96,8 +88,9 @@ public void create_from_query_without_query_listener_should_throw_exception() {
Statement query = new Query(plan, 0);
IllegalArgumentException exception =
- assertThrows(IllegalArgumentException.class, () -> factory.create(
- query, Optional.empty(), Optional.empty()));
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> factory.create(query, Optional.empty(), Optional.empty()));
assertEquals("[BUG] query listener must be not null", exception.getMessage());
}
@@ -106,8 +99,9 @@ public void create_from_explain_without_explain_listener_should_throw_exception(
Statement query = new Explain(new Query(plan, 0));
IllegalArgumentException exception =
- assertThrows(IllegalArgumentException.class, () -> factory.create(
- query, Optional.empty(), Optional.empty()));
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> factory.create(query, Optional.empty(), Optional.empty()));
assertEquals("[BUG] explain listener must be not null", exception.getMessage());
}
@@ -143,9 +137,9 @@ public void create_query_with_fetch_size_which_cannot_be_paged() {
when(plan.accept(any(CanPaginateVisitor.class), any())).thenReturn(Boolean.FALSE);
factory = new QueryPlanFactory(queryService);
Statement query = new Query(plan, 10);
- assertThrows(UnsupportedCursorRequestException.class,
- () -> factory.create(query,
- Optional.of(queryListener), Optional.empty()));
+ assertThrows(
+ UnsupportedCursorRequestException.class,
+ () -> factory.create(query, Optional.of(queryListener), Optional.empty()));
}
@Test
diff --git a/core/src/test/java/org/opensearch/sql/executor/execution/QueryPlanTest.java b/core/src/test/java/org/opensearch/sql/executor/execution/QueryPlanTest.java
index a0a98e2be7..57ff5c70e9 100644
--- a/core/src/test/java/org/opensearch/sql/executor/execution/QueryPlanTest.java
+++ b/core/src/test/java/org/opensearch/sql/executor/execution/QueryPlanTest.java
@@ -34,20 +34,15 @@
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
class QueryPlanTest {
- @Mock
- private QueryId queryId;
+ @Mock private QueryId queryId;
- @Mock
- private UnresolvedPlan plan;
+ @Mock private UnresolvedPlan plan;
- @Mock
- private QueryService queryService;
+ @Mock private QueryService queryService;
- @Mock
- private ResponseListener explainListener;
+ @Mock private ResponseListener explainListener;
- @Mock
- private ResponseListener queryListener;
+ @Mock private ResponseListener queryListener;
@Test
public void execute_no_page_size() {
@@ -67,53 +62,62 @@ public void explain_no_page_size() {
@Test
public void can_execute_paginated_plan() {
- var listener = new ResponseListener() {
- @Override
- public void onResponse(ExecutionEngine.QueryResponse response) {
- assertNotNull(response);
- }
-
- @Override
- public void onFailure(Exception e) {
- fail();
- }
- };
- var plan = new QueryPlan(QueryId.queryId(), mock(UnresolvedPlan.class), 10,
- queryService, listener);
+ var listener =
+ new ResponseListener() {
+ @Override
+ public void onResponse(ExecutionEngine.QueryResponse response) {
+ assertNotNull(response);
+ }
+
+ @Override
+ public void onFailure(Exception e) {
+ fail();
+ }
+ };
+ var plan =
+ new QueryPlan(QueryId.queryId(), mock(UnresolvedPlan.class), 10, queryService, listener);
plan.execute();
}
@Test
// Same as previous test, but with incomplete QueryService
public void can_handle_error_while_executing_plan() {
- var listener = new ResponseListener() {
- @Override
- public void onResponse(ExecutionEngine.QueryResponse response) {
- fail();
- }
-
- @Override
- public void onFailure(Exception e) {
- assertNotNull(e);
- }
- };
- var plan = new QueryPlan(QueryId.queryId(), mock(UnresolvedPlan.class), 10,
- new QueryService(null, new DefaultExecutionEngine(), null), listener);
+ var listener =
+ new ResponseListener() {
+ @Override
+ public void onResponse(ExecutionEngine.QueryResponse response) {
+ fail();
+ }
+
+ @Override
+ public void onFailure(Exception e) {
+ assertNotNull(e);
+ }
+ };
+ var plan =
+ new QueryPlan(
+ QueryId.queryId(),
+ mock(UnresolvedPlan.class),
+ 10,
+ new QueryService(null, new DefaultExecutionEngine(), null),
+ listener);
plan.execute();
}
@Test
public void explain_is_not_supported_for_pagination() {
- new QueryPlan(null, null, 0, null, null).explain(new ResponseListener<>() {
- @Override
- public void onResponse(ExecutionEngine.ExplainResponse response) {
- fail();
- }
-
- @Override
- public void onFailure(Exception e) {
- assertTrue(e instanceof NotImplementedException);
- }
- });
+ new QueryPlan(null, null, 0, null, null)
+ .explain(
+ new ResponseListener<>() {
+ @Override
+ public void onResponse(ExecutionEngine.ExplainResponse response) {
+ fail();
+ }
+
+ @Override
+ public void onFailure(Exception e) {
+ assertTrue(e instanceof NotImplementedException);
+ }
+ });
}
}
diff --git a/core/src/test/java/org/opensearch/sql/executor/execution/StreamingQueryPlanTest.java b/core/src/test/java/org/opensearch/sql/executor/execution/StreamingQueryPlanTest.java
index 7357e99d18..2e8666aea4 100644
--- a/core/src/test/java/org/opensearch/sql/executor/execution/StreamingQueryPlanTest.java
+++ b/core/src/test/java/org/opensearch/sql/executor/execution/StreamingQueryPlanTest.java
@@ -49,9 +49,7 @@ class StreamingQueryPlanTest {
@Test
void executionSuccess() throws InterruptedException {
- streamingQuery()
- .streamingSource()
- .shouldSuccess();
+ streamingQuery().streamingSource().shouldSuccess();
}
@Test
@@ -70,9 +68,7 @@ void failIfNoStreamingSource() throws InterruptedException {
@Test
void taskExecutionShouldNotCallListener() throws InterruptedException {
- streamingQuery()
- .streamingSource()
- .taskExecutionShouldNotCallListener();
+ streamingQuery().streamingSource().taskExecutionShouldNotCallListener();
}
Helper streamingQuery() {
diff --git a/core/src/test/java/org/opensearch/sql/executor/pagination/CanPaginateVisitorTest.java b/core/src/test/java/org/opensearch/sql/executor/pagination/CanPaginateVisitorTest.java
index 003967d6aa..5f2ba86c2f 100644
--- a/core/src/test/java/org/opensearch/sql/executor/pagination/CanPaginateVisitorTest.java
+++ b/core/src/test/java/org/opensearch/sql/executor/pagination/CanPaginateVisitorTest.java
@@ -121,8 +121,7 @@ public void allow_query_with_select_fields_and_from() {
@Test
// select x
public void allow_query_without_from() {
- var plan = project(values(List.of(intLiteral(1))),
- alias("1", intLiteral(1)));
+ var plan = project(values(List.of(intLiteral(1))), alias("1", intLiteral(1)));
assertTrue(plan.accept(visitor, null));
}
@@ -130,106 +129,124 @@ public void allow_query_without_from() {
public void visitField() {
// test combinations of acceptable and not acceptable args for coverage
assertAll(
- () -> assertFalse(project(relation("dummy"),
- field(map("1", "2"), argument("name", intLiteral(0))))
- .accept(visitor, null)),
- () -> assertFalse(project(relation("dummy"),
- field("field", new Argument("", new Literal(1, DataType.INTEGER) {
- @Override
- public List getChild() {
- return List.of(map("1", "2"));
- }
- })))
- .accept(visitor, null))
- );
+ () ->
+ assertFalse(
+ project(relation("dummy"), field(map("1", "2"), argument("name", intLiteral(0))))
+ .accept(visitor, null)),
+ () ->
+ assertFalse(
+ project(
+ relation("dummy"),
+ field(
+ "field",
+ new Argument(
+ "",
+ new Literal(1, DataType.INTEGER) {
+ @Override
+ public List getChild() {
+ return List.of(map("1", "2"));
+ }
+ })))
+ .accept(visitor, null)));
}
@Test
public void visitAlias() {
// test combinations of acceptable and not acceptable args for coverage
assertAll(
- () -> assertFalse(project(relation("dummy"),
- alias("pew", map("1", "2"), "pew"))
- .accept(visitor, null)),
- () -> assertFalse(project(relation("dummy"), new Alias("pew", field("pew")) {
- @Override
- public List extends Node> getChild() {
- return List.of(map("1", "2"));
- }
- })
- .accept(visitor, null))
- );
+ () ->
+ assertFalse(
+ project(relation("dummy"), alias("pew", map("1", "2"), "pew"))
+ .accept(visitor, null)),
+ () ->
+ assertFalse(
+ project(
+ relation("dummy"),
+ new Alias("pew", field("pew")) {
+ @Override
+ public List extends Node> getChild() {
+ return List.of(map("1", "2"));
+ }
+ })
+ .accept(visitor, null)));
}
@Test
// select a = b
public void visitEqualTo() {
- var plan = project(values(List.of(intLiteral(1))),
- alias("1", equalTo(intLiteral(1), intLiteral(1))));
+ var plan =
+ project(values(List.of(intLiteral(1))), alias("1", equalTo(intLiteral(1), intLiteral(1))));
assertTrue(plan.accept(visitor, null));
}
@Test
// select interval
public void visitInterval() {
- var plan = project(values(List.of(intLiteral(1))),
- alias("1", intervalLiteral(intLiteral(1), DataType.INTEGER, "days")));
+ var plan =
+ project(
+ values(List.of(intLiteral(1))),
+ alias("1", intervalLiteral(intLiteral(1), DataType.INTEGER, "days")));
assertTrue(plan.accept(visitor, null));
}
@Test
// select a != b
public void visitCompare() {
- var plan = project(values(List.of(intLiteral(1))),
- alias("1", compare("!=", intLiteral(1), intLiteral(1))));
+ var plan =
+ project(
+ values(List.of(intLiteral(1))),
+ alias("1", compare("!=", intLiteral(1), intLiteral(1))));
assertTrue(plan.accept(visitor, null));
}
@Test
// select NOT a
public void visitNot() {
- var plan = project(values(List.of(intLiteral(1))),
- alias("1", not(booleanLiteral(true))));
+ var plan = project(values(List.of(intLiteral(1))), alias("1", not(booleanLiteral(true))));
assertTrue(plan.accept(visitor, null));
}
@Test
// select a OR b
public void visitOr() {
- var plan = project(values(List.of(intLiteral(1))),
- alias("1", or(booleanLiteral(true), booleanLiteral(false))));
+ var plan =
+ project(
+ values(List.of(intLiteral(1))),
+ alias("1", or(booleanLiteral(true), booleanLiteral(false))));
assertTrue(plan.accept(visitor, null));
}
@Test
// select a AND b
public void visitAnd() {
- var plan = project(values(List.of(intLiteral(1))),
- alias("1", and(booleanLiteral(true), booleanLiteral(false))));
+ var plan =
+ project(
+ values(List.of(intLiteral(1))),
+ alias("1", and(booleanLiteral(true), booleanLiteral(false))));
assertTrue(plan.accept(visitor, null));
}
@Test
// select a XOR b
public void visitXor() {
- var plan = project(values(List.of(intLiteral(1))),
- alias("1", xor(booleanLiteral(true), booleanLiteral(false))));
+ var plan =
+ project(
+ values(List.of(intLiteral(1))),
+ alias("1", xor(booleanLiteral(true), booleanLiteral(false))));
assertTrue(plan.accept(visitor, null));
}
@Test
// select f()
public void visitFunction() {
- var plan = project(values(List.of(intLiteral(1))),
- function("func"));
+ var plan = project(values(List.of(intLiteral(1))), function("func"));
assertTrue(plan.accept(visitor, null));
}
@Test
// select nested() ...
public void visitNested() {
- var plan = project(values(List.of(intLiteral(1))),
- function("nested"));
+ var plan = project(values(List.of(intLiteral(1))), function("nested"));
assertFalse(plan.accept(visitor, null));
}
@@ -238,30 +255,37 @@ public void visitNested() {
public void visitIn() {
// test combinations of acceptable and not acceptable args for coverage
assertAll(
- () -> assertTrue(project(values(List.of(intLiteral(1))), alias("1", in(field("a"))))
- .accept(visitor, null)),
- () -> assertFalse(project(values(List.of(intLiteral(1))),
- alias("1", in(field("a"), map("1", "2"))))
- .accept(visitor, null)),
- () -> assertFalse(project(values(List.of(intLiteral(1))),
- alias("1", in(map("1", "2"), field("a"))))
- .accept(visitor, null))
- );
+ () ->
+ assertTrue(
+ project(values(List.of(intLiteral(1))), alias("1", in(field("a"))))
+ .accept(visitor, null)),
+ () ->
+ assertFalse(
+ project(values(List.of(intLiteral(1))), alias("1", in(field("a"), map("1", "2"))))
+ .accept(visitor, null)),
+ () ->
+ assertFalse(
+ project(values(List.of(intLiteral(1))), alias("1", in(map("1", "2"), field("a"))))
+ .accept(visitor, null)));
}
@Test
// select a BETWEEN 1 AND 2
public void visitBetween() {
- var plan = project(values(List.of(intLiteral(1))),
- alias("1", between(field("a"), intLiteral(1), intLiteral(2))));
+ var plan =
+ project(
+ values(List.of(intLiteral(1))),
+ alias("1", between(field("a"), intLiteral(1), intLiteral(2))));
assertTrue(plan.accept(visitor, null));
}
@Test
// select a CASE 1 WHEN 2
public void visitCase() {
- var plan = project(values(List.of(intLiteral(1))),
- alias("1", caseWhen(intLiteral(1), when(intLiteral(3), intLiteral(4)))));
+ var plan =
+ project(
+ values(List.of(intLiteral(1))),
+ alias("1", caseWhen(intLiteral(1), when(intLiteral(3), intLiteral(4)))));
assertTrue(plan.accept(visitor, null));
}
@@ -270,21 +294,33 @@ public void visitCase() {
public void visitCast() {
// test combinations of acceptable and not acceptable args for coverage
assertAll(
- () -> assertTrue(project(values(List.of(intLiteral(1))),
- alias("1", cast(intLiteral(2), stringLiteral("int"))))
- .accept(visitor, null)),
- () -> assertFalse(project(values(List.of(intLiteral(1))),
- alias("1", cast(intLiteral(2), new Literal(1, DataType.INTEGER) {
- @Override
- public List getChild() {
- return List.of(map("1", "2"));
- }
- })))
- .accept(visitor, null)),
- () -> assertFalse(project(values(List.of(intLiteral(1))),
- alias("1", cast(map("1", "2"), stringLiteral("int"))))
- .accept(visitor, null))
- );
+ () ->
+ assertTrue(
+ project(
+ values(List.of(intLiteral(1))),
+ alias("1", cast(intLiteral(2), stringLiteral("int"))))
+ .accept(visitor, null)),
+ () ->
+ assertFalse(
+ project(
+ values(List.of(intLiteral(1))),
+ alias(
+ "1",
+ cast(
+ intLiteral(2),
+ new Literal(1, DataType.INTEGER) {
+ @Override
+ public List getChild() {
+ return List.of(map("1", "2"));
+ }
+ })))
+ .accept(visitor, null)),
+ () ->
+ assertFalse(
+ project(
+ values(List.of(intLiteral(1))),
+ alias("1", cast(map("1", "2"), stringLiteral("int"))))
+ .accept(visitor, null)));
}
@Test
@@ -305,20 +341,22 @@ public void reject_query_with_eval() {
// simple_query_string(["Tags" ^ 1.5, "Title", "Body" 4.2], "taste")
// and Tags like "% % %" and Title like "%";
public void accept_query_with_highlight_and_relevance_func() {
- var plan = project(
- filter(
- relation("beer.stackexchange"),
- and(
+ var plan =
+ project(
+ filter(
+ relation("beer.stackexchange"),
and(
- function("like", qualifiedName("Tags"), stringLiteral("% % %")),
- function("like", qualifiedName("Title"), stringLiteral("%"))),
- function("simple_query_string",
- unresolvedArg("fields",
- new RelevanceFieldList(Map.of("Title", 1.0F, "Body", 4.2F, "Tags", 1.5F))),
- unresolvedArg("query",
- stringLiteral("taste"))))),
- alias("highlight(\"Body\")",
- highlight(stringLiteral("Body"), Map.of())));
+ and(
+ function("like", qualifiedName("Tags"), stringLiteral("% % %")),
+ function("like", qualifiedName("Title"), stringLiteral("%"))),
+ function(
+ "simple_query_string",
+ unresolvedArg(
+ "fields",
+ new RelevanceFieldList(
+ Map.of("Title", 1.0F, "Body", 4.2F, "Tags", 1.5F))),
+ unresolvedArg("query", stringLiteral("taste"))))),
+ alias("highlight(\"Body\")", highlight(stringLiteral("Body"), Map.of())));
assertTrue(plan.accept(visitor, null));
}
@@ -339,12 +377,13 @@ public void reject_query_with_offset() {
// test added for coverage only
@Test
public void visitLimit() {
- var visitor = new CanPaginateVisitor() {
- @Override
- public Boolean visitRelation(Relation node, Object context) {
- return Boolean.FALSE;
- }
- };
+ var visitor =
+ new CanPaginateVisitor() {
+ @Override
+ public Boolean visitRelation(Relation node, Object context) {
+ return Boolean.FALSE;
+ }
+ };
var plan = project(limit(relation("dummy"), 0, 0), allFields());
assertFalse(plan.accept(visitor, null));
}
@@ -352,8 +391,7 @@ public Boolean visitRelation(Relation node, Object context) {
@Test
// select * from y where z
public void allow_query_with_where() {
- var plan = project(filter(relation("dummy"),
- booleanLiteral(true)), allFields());
+ var plan = project(filter(relation("dummy"), booleanLiteral(true)), allFields());
assertTrue(plan.accept(visitor, null));
}
@@ -367,28 +405,29 @@ public void allow_query_with_order_by_with_column_references_only() {
@Test
// select * from y order by func(z)
public void reject_query_with_order_by_with_an_expression() {
- var plan = project(sort(relation("dummy"), field(function("func"))),
- allFields());
+ var plan = project(sort(relation("dummy"), field(function("func"))), allFields());
assertFalse(plan.accept(visitor, null));
}
// test added for coverage only
@Test
public void visitSort() {
- CanPaginateVisitor visitor = new CanPaginateVisitor() {
- @Override
- public Boolean visitRelation(Relation node, Object context) {
- return Boolean.FALSE;
- }
- };
+ CanPaginateVisitor visitor =
+ new CanPaginateVisitor() {
+ @Override
+ public Boolean visitRelation(Relation node, Object context) {
+ return Boolean.FALSE;
+ }
+ };
var plan = project(sort(relation("dummy"), field("1")), allFields());
assertFalse(plan.accept(visitor, null));
- visitor = new CanPaginateVisitor() {
- @Override
- public Boolean visitField(Field node, Object context) {
- return Boolean.FALSE;
- }
- };
+ visitor =
+ new CanPaginateVisitor() {
+ @Override
+ public Boolean visitField(Field node, Object context) {
+ return Boolean.FALSE;
+ }
+ };
plan = project(sort(relation("dummy"), field("1")), allFields());
assertFalse(plan.accept(visitor, null));
}
@@ -396,31 +435,38 @@ public Boolean visitField(Field node, Object context) {
@Test
// select * from y group by z
public void reject_query_with_group_by() {
- var plan = project(agg(
- relation("dummy"), List.of(), List.of(), List.of(field("1")), List.of()),
- allFields());
+ var plan =
+ project(
+ agg(relation("dummy"), List.of(), List.of(), List.of(field("1")), List.of()),
+ allFields());
assertFalse(plan.accept(visitor, null));
}
@Test
// select agg(x) from y
public void reject_query_with_aggregation_function() {
- var plan = project(agg(
- relation("dummy"),
- List.of(alias("agg", aggregate("func", field("pewpew")))),
- List.of(), List.of(), List.of()),
- allFields());
+ var plan =
+ project(
+ agg(
+ relation("dummy"),
+ List.of(alias("agg", aggregate("func", field("pewpew")))),
+ List.of(),
+ List.of(),
+ List.of()),
+ allFields());
assertFalse(plan.accept(visitor, null));
}
@Test
// select window(x) from y
public void reject_query_with_window_function() {
- var plan = project(relation("dummy"),
- alias("pewpew",
- window(
- aggregate("func", field("pewpew")),
- List.of(qualifiedName("1")), List.of())));
+ var plan =
+ project(
+ relation("dummy"),
+ alias(
+ "pewpew",
+ window(
+ aggregate("func", field("pewpew")), List.of(qualifiedName("1")), List.of())));
assertFalse(plan.accept(visitor, null));
}
@@ -449,12 +495,13 @@ public void reject_project_when_relation_has_child() {
// test combinations of acceptable and not acceptable args for coverage
public void visitFilter() {
assertAll(
- () -> assertTrue(project(filter(relation("dummy"), booleanLiteral(true)))
- .accept(visitor, null)),
- () -> assertFalse(project(filter(relation("dummy"), map("1", "2")))
- .accept(visitor, null)),
- () -> assertFalse(project(filter(tableFunction(List.of("1", "2")), booleanLiteral(true)))
- .accept(visitor, null))
- );
+ () ->
+ assertTrue(
+ project(filter(relation("dummy"), booleanLiteral(true))).accept(visitor, null)),
+ () -> assertFalse(project(filter(relation("dummy"), map("1", "2"))).accept(visitor, null)),
+ () ->
+ assertFalse(
+ project(filter(tableFunction(List.of("1", "2")), booleanLiteral(true)))
+ .accept(visitor, null)));
}
}
diff --git a/core/src/test/java/org/opensearch/sql/executor/pagination/PlanSerializerTest.java b/core/src/test/java/org/opensearch/sql/executor/pagination/PlanSerializerTest.java
index 8211a3bc12..495a7db80c 100644
--- a/core/src/test/java/org/opensearch/sql/executor/pagination/PlanSerializerTest.java
+++ b/core/src/test/java/org/opensearch/sql/executor/pagination/PlanSerializerTest.java
@@ -44,9 +44,14 @@ void setUp() {
}
@ParameterizedTest
- @ValueSource(strings = {"pewpew", "asdkfhashdfjkgakgfwuigfaijkb", "ajdhfgajklghadfjkhgjkadhgad"
- + "kadfhgadhjgfjklahdgqheygvskjfbvgsdklgfuirehiluANUIfgauighbahfuasdlhfnhaughsdlfhaughaggf"
- + "and_some_other_funny_stuff_which_could_be_generated_while_sleeping_on_the_keyboard"})
+ @ValueSource(
+ strings = {
+ "pewpew",
+ "asdkfhashdfjkgakgfwuigfaijkb",
+ "ajdhfgajklghadfjkhgjkadhgad"
+ + "kadfhgadhjgfjklahdgqheygvskjfbvgsdklgfuirehiluANUIfgauighbahfuasdlhfnhaughsdlfhaughaggf"
+ + "and_some_other_funny_stuff_which_could_be_generated_while_sleeping_on_the_keyboard"
+ })
void serialize_deserialize_str(String input) {
var compressed = serialize(input);
assertEquals(input, deserialize(compressed));
@@ -98,8 +103,7 @@ void deserialize_throws() {
// from gzip - damaged header
() -> assertThrows(Throwable.class, () -> deserialize("00")),
// from HashCode::fromString
- () -> assertThrows(Throwable.class, () -> deserialize("000"))
- );
+ () -> assertThrows(Throwable.class, () -> deserialize("000")));
}
@Test
@@ -109,8 +113,7 @@ void convertToCursor_returns_no_cursor_if_cant_serialize() {
plan.setThrowNoCursorOnWrite(true);
assertAll(
() -> assertThrows(NoCursorException.class, () -> serialize(plan)),
- () -> assertEquals(Cursor.None, planCache.convertToCursor(plan))
- );
+ () -> assertEquals(Cursor.None, planCache.convertToCursor(plan)));
}
@Test
@@ -122,14 +125,14 @@ void convertToCursor_returns_no_cursor_if_plan_is_not_paginate() {
@Test
void convertToPlan_throws_cursor_has_no_prefix() {
- assertThrows(UnsupportedOperationException.class, () ->
- planCache.convertToPlan("abc"));
+ assertThrows(UnsupportedOperationException.class, () -> planCache.convertToPlan("abc"));
}
@Test
void convertToPlan_throws_if_failed_to_deserialize() {
- assertThrows(UnsupportedOperationException.class, () ->
- planCache.convertToPlan("n:" + serialize(mock(Serializable.class))));
+ assertThrows(
+ UnsupportedOperationException.class,
+ () -> planCache.convertToPlan("n:" + serialize(mock(Serializable.class))));
}
@Test
@@ -144,8 +147,8 @@ void serialize_and_deserialize() {
@Test
void convertToCursor_and_convertToPlan() {
var plan = new TestOperator(100500);
- var roundTripPlan = (SerializablePlan)
- planCache.convertToPlan(planCache.convertToCursor(plan).toString());
+ var roundTripPlan =
+ (SerializablePlan) planCache.convertToPlan(planCache.convertToCursor(plan).toString());
assertEquals(plan, roundTripPlan);
assertNotSame(plan, roundTripPlan);
}
@@ -158,8 +161,8 @@ void resolveObject() {
objectOutput.writeObject("Hello, world!");
objectOutput.flush();
- var cds = planCache.getCursorDeserializationStream(
- new ByteArrayInputStream(output.toByteArray()));
+ var cds =
+ planCache.getCursorDeserializationStream(new ByteArrayInputStream(output.toByteArray()));
assertEquals(storageEngine, cds.resolveObject("engine"));
var object = new Object();
assertSame(object, cds.resolveObject(object));
diff --git a/core/src/test/java/org/opensearch/sql/executor/streaming/DefaultMetadataLogTest.java b/core/src/test/java/org/opensearch/sql/executor/streaming/DefaultMetadataLogTest.java
index 4d8c4f3e93..17ea253e2a 100644
--- a/core/src/test/java/org/opensearch/sql/executor/streaming/DefaultMetadataLogTest.java
+++ b/core/src/test/java/org/opensearch/sql/executor/streaming/DefaultMetadataLogTest.java
@@ -8,7 +8,6 @@
package org.opensearch.sql.executor.streaming;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
diff --git a/core/src/test/java/org/opensearch/sql/executor/streaming/MicroBatchStreamingExecutionTest.java b/core/src/test/java/org/opensearch/sql/executor/streaming/MicroBatchStreamingExecutionTest.java
index 589b093c2f..bd0c8ed3e1 100644
--- a/core/src/test/java/org/opensearch/sql/executor/streaming/MicroBatchStreamingExecutionTest.java
+++ b/core/src/test/java/org/opensearch/sql/executor/streaming/MicroBatchStreamingExecutionTest.java
@@ -45,19 +45,12 @@ void executedSuccess() {
@Test
void executedFailed() {
- streamingQuery()
- .addData()
- .executeFailed()
- .latestOffsetLogShouldBe(0L)
- .noCommittedLog();
+ streamingQuery().addData().executeFailed().latestOffsetLogShouldBe(0L).noCommittedLog();
}
@Test
void noDataInSource() {
- streamingQuery()
- .neverProcess()
- .noOffsetLog()
- .noCommittedLog();
+ streamingQuery().neverProcess().noOffsetLog().noCommittedLog();
}
@Test
@@ -170,8 +163,7 @@ Helper executeSuccess(Long... offsets) {
ResponseListener listener =
invocation.getArgument(2);
listener.onResponse(
- new ExecutionEngine.QueryResponse(null, Collections.emptyList(),
- Cursor.None));
+ new ExecutionEngine.QueryResponse(null, Collections.emptyList(), Cursor.None));
PlanContext planContext = invocation.getArgument(1);
assertTrue(planContext.getSplit().isPresent());
@@ -257,8 +249,8 @@ public Optional getLatestOffset() {
public Batch getBatch(Optional start, Offset end) {
return new Batch(
new TestOffsetSplit(
- start.map(v -> v.getOffset() + 1).orElse(0L), Long.min(offset.get(),
- end.getOffset())));
+ start.map(v -> v.getOffset() + 1).orElse(0L),
+ Long.min(offset.get(), end.getOffset())));
}
}
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 47fe9dad0f..2f3e855430 100644
--- a/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-
package org.opensearch.sql.expression;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -31,70 +30,69 @@ class ExpressionNodeVisitorTest {
@Test
void should_return_null_by_default() {
- ExpressionNodeVisitor