From 823cffe3e592f0b9cdd84fdd4040d62580f20278 Mon Sep 17 00:00:00 2001 From: currantw Date: Fri, 6 Dec 2024 09:07:36 -0800 Subject: [PATCH] Use static imports for `Collections.singletonList` Signed-off-by: currantw --- .../cluster/ClusterManagerEventListener.java | 4 +- .../BasicAuthenticationInterceptorTest.java | 5 +- .../sql/analysis/ExpressionAnalyzer.java | 6 +- .../analysis/SelectExpressionAnalyzer.java | 7 +- .../sql/ast/expression/AggregateFunction.java | 10 +- .../sql/ast/expression/Argument.java | 5 +- .../opensearch/sql/ast/expression/Cast.java | 4 +- .../org/opensearch/sql/ast/expression/In.java | 5 +- .../sql/ast/expression/Interval.java | 5 +- .../opensearch/sql/ast/expression/Not.java | 5 +- .../sql/ast/expression/QualifiedName.java | 4 +- .../ast/expression/UnresolvedArgument.java | 5 +- .../org/opensearch/sql/ast/tree/RareTopN.java | 5 +- .../org/opensearch/sql/ast/tree/Relation.java | 5 +- .../aggregation/AggregatorFunctions.java | 61 +++++---- .../sql/expression/function/FunctionDSL.java | 11 +- .../sql/expression/text/TextFunctions.java | 4 +- .../sql/planner/logical/LogicalAD.java | 5 +- .../planner/logical/LogicalAggregation.java | 5 +- .../sql/planner/logical/LogicalDedupe.java | 5 +- .../sql/planner/logical/LogicalEval.java | 5 +- .../sql/planner/logical/LogicalFilter.java | 5 +- .../sql/planner/logical/LogicalHighlight.java | 5 +- .../sql/planner/logical/LogicalLimit.java | 5 +- .../sql/planner/logical/LogicalML.java | 5 +- .../sql/planner/logical/LogicalMLCommons.java | 5 +- .../sql/planner/logical/LogicalNested.java | 5 +- .../sql/planner/logical/LogicalProject.java | 5 +- .../sql/planner/logical/LogicalRareTopN.java | 5 +- .../sql/planner/logical/LogicalRemove.java | 5 +- .../sql/planner/logical/LogicalRename.java | 5 +- .../sql/planner/logical/LogicalSort.java | 5 +- .../sql/planner/logical/LogicalWindow.java | 5 +- .../sql/planner/logical/LogicalWrite.java | 5 +- .../planner/physical/AggregationOperator.java | 5 +- .../sql/planner/physical/DedupeOperator.java | 5 +- .../sql/planner/physical/EvalOperator.java | 4 +- .../sql/planner/physical/FilterOperator.java | 5 +- .../sql/planner/physical/NestedOperator.java | 4 +- .../sql/planner/physical/ProjectOperator.java | 5 +- .../planner/physical/RareTopNOperator.java | 5 +- .../sql/planner/physical/RemoveOperator.java | 4 +- .../sql/planner/physical/RenameOperator.java | 4 +- .../sql/planner/physical/SortOperator.java | 5 +- .../planner/physical/TakeOrderedOperator.java | 5 +- .../sql/planner/physical/WindowOperator.java | 5 +- .../physical/collector/MetricCollector.java | 5 +- .../assigner/TumblingWindowAssigner.java | 5 +- .../sql/storage/write/TableWriteBuilder.java | 5 +- .../sql/storage/write/TableWriteOperator.java | 5 +- .../opensearch/sql/analysis/AnalyzerTest.java | 10 +- .../sql/analysis/AnalyzerTestBase.java | 4 +- .../SelectExpressionAnalyzerTest.java | 6 +- .../expression/ExpressionNodeVisitorTest.java | 4 +- .../BuiltinFunctionRepositoryTest.java | 25 ++-- .../sql/planner/DefaultImplementorTest.java | 7 +- .../physical/AggregationOperatorTest.java | 124 +++++++++--------- .../physical/RareTopNOperatorTest.java | 23 ++-- .../planner/physical/RenameOperatorTest.java | 7 +- .../assigner/TumblingWindowAssignerTest.java | 8 +- .../storage/write/TableWriteOperatorTest.java | 4 +- .../service/DataSourceServiceImplTest.java | 48 +++---- ...enSearchDataSourceMetadataStorageTest.java | 15 ++- .../utils/DatasourceValidationUtilsTest.java | 12 +- .../sql/legacy/PrettyFormatResponseIT.java | 12 +- .../executor/format/DeleteResultSet.java | 10 +- .../core/builder/UnaryExpressionBuilder.java | 5 +- .../planner/physical/ADOperator.java | 4 +- .../planner/physical/MLCommonsOperator.java | 4 +- .../planner/physical/MLOperator.java | 5 +- .../agg/NoBucketAggregationParser.java | 5 +- .../aggregation/AggregationQueryBuilder.java | 5 +- .../physical/MLCommonsOperatorTest.java | 4 +- .../planner/physical/MLOperatorTest.java | 4 +- .../request/OpenSearchRequestBuilderTest.java | 6 +- .../OpenSearchIndexScanOptimizationTest.java | 11 +- .../AggregationQueryBuilderTest.java | 15 +-- .../dsl/MetricAggregationBuilderTest.java | 18 +-- .../system/OpenSearchSystemIndexScanTest.java | 4 +- .../sql/opensearch/utils/Utils.java | 7 +- .../sql/ppl/utils/ArgumentFactory.java | 9 +- .../ppl/utils/UnresolvedPlanHelperTest.java | 4 +- .../client/PrometheusClientImplTest.java | 6 +- ...eryRangeFunctionTableScanOperatorTest.java | 14 +- .../PrometheusListMetricsRequestTest.java | 6 +- .../storage/PrometheusMetricScanTest.java | 4 +- .../storage/PrometheusStorageFactoryTest.java | 17 +-- .../system/PrometheusSystemTableScanTest.java | 4 +- .../protocol/response/QueryResultTest.java | 11 +- .../sql/spark/storage/SparkStorageEngine.java | 5 +- .../opensearch/sql/sql/parser/AstBuilder.java | 8 +- .../sql/sql/parser/AstExpressionBuilder.java | 5 +- 92 files changed, 419 insertions(+), 402 deletions(-) diff --git a/async-query/src/main/java/org/opensearch/sql/spark/cluster/ClusterManagerEventListener.java b/async-query/src/main/java/org/opensearch/sql/spark/cluster/ClusterManagerEventListener.java index 0bcdc3a924..69be1a3fc7 100644 --- a/async-query/src/main/java/org/opensearch/sql/spark/cluster/ClusterManagerEventListener.java +++ b/async-query/src/main/java/org/opensearch/sql/spark/cluster/ClusterManagerEventListener.java @@ -5,12 +5,12 @@ package org.opensearch.sql.spark.cluster; +import static java.util.Collections.singletonList; import static org.opensearch.sql.spark.data.constants.SparkConstants.SPARK_REQUEST_BUFFER_INDEX_NAME; import com.google.common.annotations.VisibleForTesting; import java.time.Clock; import java.time.Duration; -import java.util.Collections; import java.util.List; import org.opensearch.client.Client; import org.opensearch.cluster.LocalNodeClusterManagerListener; @@ -183,7 +183,7 @@ private void cancel(Cancellable cron) { @VisibleForTesting public List getFlintIndexRetentionCron() { - return Collections.singletonList(flintIndexRetentionCron); + return singletonList(flintIndexRetentionCron); } private String executorName() { diff --git a/common/src/test/java/org/opensearch/sql/common/interceptors/BasicAuthenticationInterceptorTest.java b/common/src/test/java/org/opensearch/sql/common/interceptors/BasicAuthenticationInterceptorTest.java index af93060fab..165f9e63f7 100644 --- a/common/src/test/java/org/opensearch/sql/common/interceptors/BasicAuthenticationInterceptorTest.java +++ b/common/src/test/java/org/opensearch/sql/common/interceptors/BasicAuthenticationInterceptorTest.java @@ -7,7 +7,8 @@ package org.opensearch.sql.common.interceptors; -import java.util.Collections; +import static java.util.Collections.singletonList; + import lombok.SneakyThrows; import okhttp3.Credentials; import okhttp3.Interceptor; @@ -47,7 +48,7 @@ void testIntercept() { Mockito.verify(chain).proceed(requestArgumentCaptor.capture()); Request request = requestArgumentCaptor.getValue(); Assertions.assertEquals( - Collections.singletonList(Credentials.basic("testAdmin", "testPassword")), + singletonList(Credentials.basic("testAdmin", "testPassword")), request.headers("Authorization")); } } diff --git a/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java index 5a8d6fe976..370dd881c7 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java @@ -5,6 +5,7 @@ package org.opensearch.sql.analysis; +import static java.util.Collections.singletonList; import static org.opensearch.sql.ast.dsl.AstDSL.and; import static org.opensearch.sql.ast.dsl.AstDSL.compare; @@ -13,7 +14,6 @@ import com.google.common.collect.ImmutableSet; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -83,9 +83,7 @@ public Expression visitCast(Cast node, AnalysisContext context) { final Expression expression = node.getExpression().accept(this, context); return (Expression) repository.compile( - context.getFunctionProperties(), - node.convertFunctionName(), - Collections.singletonList(expression)); + context.getFunctionProperties(), node.convertFunctionName(), singletonList(expression)); } public ExpressionAnalyzer(BuiltinFunctionRepository repository) { diff --git a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java index 5e46cfa629..2abbb6d96f 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java @@ -5,8 +5,9 @@ package org.opensearch.sql.analysis; +import static java.util.Collections.singletonList; + import com.google.common.collect.ImmutableList; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.regex.Pattern; @@ -54,7 +55,7 @@ public List analyze( @Override public List visitField(Field node, AnalysisContext context) { - return Collections.singletonList(DSL.named(node.accept(expressionAnalyzer, context))); + return singletonList(DSL.named(node.accept(expressionAnalyzer, context))); } @Override @@ -65,7 +66,7 @@ public List visitAlias(Alias node, AnalysisContext context) { } Expression expr = referenceIfSymbolDefined(node, context); - return Collections.singletonList( + return singletonList( DSL.named(unqualifiedNameIfFieldOnly(node, context), expr, node.getAlias())); } diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/AggregateFunction.java b/core/src/main/java/org/opensearch/sql/ast/expression/AggregateFunction.java index 5208e39623..5335e3dfa2 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/AggregateFunction.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/AggregateFunction.java @@ -5,7 +5,9 @@ package org.opensearch.sql.ast.expression; -import java.util.Collections; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -42,7 +44,7 @@ public class AggregateFunction extends UnresolvedExpression { public AggregateFunction(String funcName, UnresolvedExpression field) { this.funcName = funcName; this.field = field; - this.argList = Collections.emptyList(); + this.argList = emptyList(); } /** @@ -55,13 +57,13 @@ public AggregateFunction(String funcName, UnresolvedExpression field) { public AggregateFunction(String funcName, UnresolvedExpression field, Boolean distinct) { this.funcName = funcName; this.field = field; - this.argList = Collections.emptyList(); + this.argList = emptyList(); this.distinct = distinct; } @Override public List getChild() { - return Collections.singletonList(field); + return singletonList(field); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Argument.java b/core/src/main/java/org/opensearch/sql/ast/expression/Argument.java index ca9ad795b8..f187dcd1d9 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Argument.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Argument.java @@ -5,7 +5,8 @@ package org.opensearch.sql.ast.expression; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -25,7 +26,7 @@ public class Argument extends UnresolvedExpression { // private final DataType valueType; @Override public List getChild() { - return Collections.singletonList(value); + return singletonList(value); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Cast.java b/core/src/main/java/org/opensearch/sql/ast/expression/Cast.java index 2019346fb5..b922198028 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Cast.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Cast.java @@ -5,6 +5,7 @@ package org.opensearch.sql.ast.expression; +import static java.util.Collections.singletonList; import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BOOLEAN; import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BYTE; import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_DATE; @@ -19,7 +20,6 @@ import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_TIMESTAMP; import com.google.common.collect.ImmutableMap; -import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Map; @@ -99,7 +99,7 @@ public FunctionName convertFunctionName() { @Override public List getChild() { - return Collections.singletonList(expression); + return singletonList(expression); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/In.java b/core/src/main/java/org/opensearch/sql/ast/expression/In.java index 781b73fca7..78c958a93e 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/In.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/In.java @@ -5,7 +5,8 @@ package org.opensearch.sql.ast.expression; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -28,7 +29,7 @@ public class In extends UnresolvedExpression { @Override public List getChild() { - return Collections.singletonList(field); + return singletonList(field); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Interval.java b/core/src/main/java/org/opensearch/sql/ast/expression/Interval.java index c26f829f48..82ff1b93cf 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Interval.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Interval.java @@ -5,7 +5,8 @@ package org.opensearch.sql.ast.expression; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -29,7 +30,7 @@ public Interval(UnresolvedExpression value, String unit) { @Override public List getChild() { - return Collections.singletonList(value); + return singletonList(value); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/Not.java b/core/src/main/java/org/opensearch/sql/ast/expression/Not.java index ad9c032f2e..1dcb59c4b8 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/Not.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/Not.java @@ -5,7 +5,8 @@ package org.opensearch.sql.ast.expression; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -23,7 +24,7 @@ public class Not extends UnresolvedExpression { @Override public List getChild() { - return Collections.singletonList(expression); + return singletonList(expression); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/QualifiedName.java b/core/src/main/java/org/opensearch/sql/ast/expression/QualifiedName.java index 852b61cfa8..09789d8ca2 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/QualifiedName.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/QualifiedName.java @@ -5,13 +5,13 @@ package org.opensearch.sql.ast.expression; +import static java.util.Collections.singletonList; import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toList; import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.StreamSupport; @@ -25,7 +25,7 @@ public class QualifiedName extends UnresolvedExpression { private final List parts; public QualifiedName(String name) { - this.parts = Collections.singletonList(name); + this.parts = singletonList(name); } /** QualifiedName Constructor. */ diff --git a/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedArgument.java b/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedArgument.java index 59ebc1d839..18fd13a4e7 100644 --- a/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedArgument.java +++ b/core/src/main/java/org/opensearch/sql/ast/expression/UnresolvedArgument.java @@ -5,7 +5,8 @@ package org.opensearch.sql.ast.expression; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -27,7 +28,7 @@ public UnresolvedArgument(String argName, UnresolvedExpression value) { @Override public List getChild() { - return Collections.singletonList(value); + return singletonList(value); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java b/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java index 2cbe170541..05f3a178a9 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java @@ -5,7 +5,8 @@ package org.opensearch.sql.ast.tree; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; @@ -41,7 +42,7 @@ public RareTopN attach(UnresolvedPlan child) { @Override public List getChild() { - return Collections.singletonList(this.child); + return singletonList(this.child); } @Override diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java b/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java index 9d22b42e75..09faca70fb 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Relation.java @@ -5,8 +5,9 @@ package org.opensearch.sql.ast.tree; +import static java.util.Collections.singletonList; + import com.google.common.collect.ImmutableList; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import lombok.AllArgsConstructor; @@ -32,7 +33,7 @@ public Relation(UnresolvedExpression tableName) { } public Relation(UnresolvedExpression tableName, String alias) { - this.tableName = Collections.singletonList(tableName); + this.tableName = singletonList(tableName); this.alias = alias; } diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java index 698fb20408..c54c1bcc9c 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java @@ -5,6 +5,7 @@ package org.opensearch.sql.expression.aggregation; +import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; import static org.opensearch.sql.data.type.ExprCoreType.DATE; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; @@ -21,7 +22,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import java.util.Collections; import java.util.stream.Collectors; import lombok.experimental.UtilityClass; import org.opensearch.sql.data.type.ExprCoreType; @@ -66,16 +66,16 @@ private static DefaultFunctionResolver avg() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> new AvgAggregator(arguments, DOUBLE)) .put( - new FunctionSignature(functionName, Collections.singletonList(DATE)), + new FunctionSignature(functionName, singletonList(DATE)), (functionProperties, arguments) -> new AvgAggregator(arguments, DATE)) .put( - new FunctionSignature(functionName, Collections.singletonList(TIME)), + new FunctionSignature(functionName, singletonList(TIME)), (functionProperties, arguments) -> new AvgAggregator(arguments, TIME)) .put( - new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), + new FunctionSignature(functionName, singletonList(TIMESTAMP)), (functionProperties, arguments) -> new AvgAggregator(arguments, TIMESTAMP)) .build()); } @@ -88,8 +88,7 @@ private static DefaultFunctionResolver count() { ExprCoreType.coreTypes().stream() .collect( Collectors.toMap( - type -> - new FunctionSignature(functionName, Collections.singletonList(type)), + type -> new FunctionSignature(functionName, singletonList(type)), type -> (functionProperties, arguments) -> new CountAggregator(arguments, INTEGER)))); @@ -102,16 +101,16 @@ private static DefaultFunctionResolver sum() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(INTEGER)), + new FunctionSignature(functionName, singletonList(INTEGER)), (functionProperties, arguments) -> new SumAggregator(arguments, INTEGER)) .put( - new FunctionSignature(functionName, Collections.singletonList(LONG)), + new FunctionSignature(functionName, singletonList(LONG)), (functionProperties, arguments) -> new SumAggregator(arguments, LONG)) .put( - new FunctionSignature(functionName, Collections.singletonList(FLOAT)), + new FunctionSignature(functionName, singletonList(FLOAT)), (functionProperties, arguments) -> new SumAggregator(arguments, FLOAT)) .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> new SumAggregator(arguments, DOUBLE)) .build()); } @@ -122,28 +121,28 @@ private static DefaultFunctionResolver min() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(INTEGER)), + new FunctionSignature(functionName, singletonList(INTEGER)), (functionProperties, arguments) -> new MinAggregator(arguments, INTEGER)) .put( - new FunctionSignature(functionName, Collections.singletonList(LONG)), + new FunctionSignature(functionName, singletonList(LONG)), (functionProperties, arguments) -> new MinAggregator(arguments, LONG)) .put( - new FunctionSignature(functionName, Collections.singletonList(FLOAT)), + new FunctionSignature(functionName, singletonList(FLOAT)), (functionProperties, arguments) -> new MinAggregator(arguments, FLOAT)) .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> new MinAggregator(arguments, DOUBLE)) .put( - new FunctionSignature(functionName, Collections.singletonList(STRING)), + new FunctionSignature(functionName, singletonList(STRING)), (functionProperties, arguments) -> new MinAggregator(arguments, STRING)) .put( - new FunctionSignature(functionName, Collections.singletonList(DATE)), + new FunctionSignature(functionName, singletonList(DATE)), (functionProperties, arguments) -> new MinAggregator(arguments, DATE)) .put( - new FunctionSignature(functionName, Collections.singletonList(TIME)), + new FunctionSignature(functionName, singletonList(TIME)), (functionProperties, arguments) -> new MinAggregator(arguments, TIME)) .put( - new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), + new FunctionSignature(functionName, singletonList(TIMESTAMP)), (functionProperties, arguments) -> new MinAggregator(arguments, TIMESTAMP)) .build()); } @@ -154,28 +153,28 @@ private static DefaultFunctionResolver max() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(INTEGER)), + new FunctionSignature(functionName, singletonList(INTEGER)), (functionProperties, arguments) -> new MaxAggregator(arguments, INTEGER)) .put( - new FunctionSignature(functionName, Collections.singletonList(LONG)), + new FunctionSignature(functionName, singletonList(LONG)), (functionProperties, arguments) -> new MaxAggregator(arguments, LONG)) .put( - new FunctionSignature(functionName, Collections.singletonList(FLOAT)), + new FunctionSignature(functionName, singletonList(FLOAT)), (functionProperties, arguments) -> new MaxAggregator(arguments, FLOAT)) .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> new MaxAggregator(arguments, DOUBLE)) .put( - new FunctionSignature(functionName, Collections.singletonList(STRING)), + new FunctionSignature(functionName, singletonList(STRING)), (functionProperties, arguments) -> new MaxAggregator(arguments, STRING)) .put( - new FunctionSignature(functionName, Collections.singletonList(DATE)), + new FunctionSignature(functionName, singletonList(DATE)), (functionProperties, arguments) -> new MaxAggregator(arguments, DATE)) .put( - new FunctionSignature(functionName, Collections.singletonList(TIME)), + new FunctionSignature(functionName, singletonList(TIME)), (functionProperties, arguments) -> new MaxAggregator(arguments, TIME)) .put( - new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), + new FunctionSignature(functionName, singletonList(TIMESTAMP)), (functionProperties, arguments) -> new MaxAggregator(arguments, TIMESTAMP)) .build()); } @@ -186,7 +185,7 @@ private static DefaultFunctionResolver varSamp() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> varianceSample(arguments, DOUBLE)) .build()); } @@ -197,7 +196,7 @@ private static DefaultFunctionResolver varPop() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> variancePopulation(arguments, DOUBLE)) .build()); } @@ -208,7 +207,7 @@ private static DefaultFunctionResolver stddevSamp() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> stddevSample(arguments, DOUBLE)) .build()); } @@ -219,7 +218,7 @@ private static DefaultFunctionResolver stddevPop() { functionName, new ImmutableMap.Builder() .put( - new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), + new FunctionSignature(functionName, singletonList(DOUBLE)), (functionProperties, arguments) -> stddevPopulation(arguments, DOUBLE)) .build()); } diff --git a/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java b/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java index 8ebbfd3a3c..f8a8d4773d 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java @@ -5,8 +5,10 @@ package org.opensearch.sql.expression.function; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; + import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; @@ -68,11 +70,10 @@ public static DefaultFunctionResolver define( implWithProperties( SerializableFunction function, ExprType returnType) { return functionName -> { - FunctionSignature functionSignature = - new FunctionSignature(functionName, Collections.emptyList()); + FunctionSignature functionSignature = new FunctionSignature(functionName, emptyList()); FunctionBuilder functionBuilder = (functionProperties, arguments) -> - new FunctionExpression(functionName, Collections.emptyList()) { + new FunctionExpression(functionName, emptyList()) { @Override public ExprValue valueOf(Environment valueEnv) { return function.apply(functionProperties); @@ -109,7 +110,7 @@ public String toString() { return functionName -> { FunctionSignature functionSignature = - new FunctionSignature(functionName, Collections.singletonList(argsType)); + new FunctionSignature(functionName, singletonList(argsType)); FunctionBuilder functionBuilder = (functionProperties, arguments) -> new FunctionExpression(functionName, arguments) { diff --git a/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java b/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java index 2c3bbf7efb..1c99af789a 100644 --- a/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java +++ b/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java @@ -5,6 +5,7 @@ package org.opensearch.sql.expression.text; +import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRING; @@ -12,7 +13,6 @@ import static org.opensearch.sql.expression.function.FunctionDSL.impl; import static org.opensearch.sql.expression.function.FunctionDSL.nullMissingHandling; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import lombok.experimental.UtilityClass; @@ -176,7 +176,7 @@ private DefaultFunctionResolver concat() { concatFuncName, funcName -> Pair.of( - new FunctionSignature(concatFuncName, Collections.singletonList(ARRAY)), + new FunctionSignature(concatFuncName, singletonList(ARRAY)), (funcProp, args) -> new FunctionExpression(funcName, args) { @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAD.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAD.java index 25dbd14f1a..40f70c422c 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAD.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAD.java @@ -1,6 +1,7 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -23,7 +24,7 @@ public class LogicalAD extends LogicalPlan { * @param arguments arguments of the algorithm */ public LogicalAD(LogicalPlan child, Map arguments) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.arguments = arguments; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java index ecbcece623..450a4fe415 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalAggregation.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -25,7 +26,7 @@ public class LogicalAggregation extends LogicalPlan { /** Constructor of LogicalAggregation. */ public LogicalAggregation( LogicalPlan child, List aggregatorList, List groupByList) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.aggregatorList = aggregatorList; this.groupByList = groupByList; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalDedupe.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalDedupe.java index 82a48fa87c..368dc3314f 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalDedupe.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalDedupe.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -30,7 +31,7 @@ public LogicalDedupe( Integer allowedDuplication, Boolean keepEmpty, Boolean consecutive) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.dedupeList = dedupeList; this.allowedDuplication = allowedDuplication; this.keepEmpty = keepEmpty; diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java index e7b8f353bc..2a79a0ad44 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalEval.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -27,7 +28,7 @@ public class LogicalEval extends LogicalPlan { /** Constructor of LogicalEval. */ public LogicalEval(LogicalPlan child, List> expressions) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.expressions = expressions; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalFilter.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalFilter.java index 49280e8709..7c2902c455 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalFilter.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalFilter.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -20,7 +21,7 @@ public class LogicalFilter extends LogicalPlan { /** Constructor of LogicalFilter. */ public LogicalFilter(LogicalPlan child, Expression condition) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.condition = condition; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalHighlight.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalHighlight.java index 41fcd48f81..1ad86fffd9 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalHighlight.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalHighlight.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -23,7 +24,7 @@ public class LogicalHighlight extends LogicalPlan { /** Constructor of LogicalHighlight. */ public LogicalHighlight( LogicalPlan childPlan, Expression highlightField, Map arguments) { - super(Collections.singletonList(childPlan)); + super(singletonList(childPlan)); this.highlightField = highlightField; this.arguments = arguments; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalLimit.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalLimit.java index bec77d9b6f..6933958976 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalLimit.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalLimit.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -19,7 +20,7 @@ public class LogicalLimit extends LogicalPlan { /** Constructor of LogicalLimit. */ public LogicalLimit(LogicalPlan input, Integer limit, Integer offset) { - super(Collections.singletonList(input)); + super(singletonList(input)); this.limit = limit; this.offset = offset; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalML.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalML.java index 780e0bba94..dd7a5ae460 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalML.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalML.java @@ -1,6 +1,7 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -21,7 +22,7 @@ public class LogicalML extends LogicalPlan { * @param arguments arguments of the algorithm */ public LogicalML(LogicalPlan child, Map arguments) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.arguments = arguments; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalMLCommons.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalMLCommons.java index cfc313a68d..bfb1b4261d 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalMLCommons.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalMLCommons.java @@ -1,6 +1,7 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -24,7 +25,7 @@ public class LogicalMLCommons extends LogicalPlan { * @param arguments arguments of the algorithm */ public LogicalMLCommons(LogicalPlan child, String algorithm, Map arguments) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.algorithm = algorithm; this.arguments = arguments; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java index 089efe707e..24d768865b 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalNested.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import java.util.Map; import lombok.EqualsAndHashCode; @@ -27,7 +28,7 @@ public LogicalNested( LogicalPlan childPlan, List> fields, List projectList) { - super(Collections.singletonList(childPlan)); + super(singletonList(childPlan)); this.fields = fields; this.projectList = projectList; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java index 5978620480..58576d2e59 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalProject.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -25,7 +26,7 @@ public LogicalProject( LogicalPlan child, List projectList, List namedParseExpressions) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.projectList = projectList; this.namedParseExpressions = namedParseExpressions; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java index 2c387eca9c..787350b5cb 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRareTopN.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -31,7 +32,7 @@ public LogicalRareTopN( Integer noOfResults, List fieldList, List groupByList) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.commandType = commandType; this.noOfResults = noOfResults; this.fieldList = fieldList; diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRemove.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRemove.java index c1aeda22c7..a32fe0a2ab 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRemove.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRemove.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Set; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -21,7 +22,7 @@ public class LogicalRemove extends LogicalPlan { /** Constructor of LogicalRemove. */ public LogicalRemove(LogicalPlan child, Set removeList) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.removeList = removeList; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRename.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRename.java index 25ee645932..7c117ce240 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRename.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalRename.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -21,7 +22,7 @@ public class LogicalRename extends LogicalPlan { /** Constructor of LogicalRename. */ public LogicalRename(LogicalPlan child, Map renameMap) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.renameMap = renameMap; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java index 569ca7e309..17f6ff0a97 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalSort.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -24,7 +25,7 @@ public class LogicalSort extends LogicalPlan { /** Constructor of LogicalSort. */ public LogicalSort(LogicalPlan child, List> sortList) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.sortList = sortList; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWindow.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWindow.java index 00c89410a7..37310be391 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWindow.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWindow.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -27,7 +28,7 @@ public class LogicalWindow extends LogicalPlan { /** Constructor of logical window. */ public LogicalWindow( LogicalPlan child, NamedExpression windowFunction, WindowDefinition windowDefinition) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.windowFunction = windowFunction; this.windowDefinition = windowDefinition; } diff --git a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java index a253739a68..1f4d0ff108 100644 --- a/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java +++ b/core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.logical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -26,7 +27,7 @@ public class LogicalWrite extends LogicalPlan { /** Construct a logical write with given child node, table and column name list. */ public LogicalWrite(LogicalPlan child, Table table, List columns) { - super(Collections.singletonList(child)); + super(singletonList(child)); this.table = table; this.columns = columns; } diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java index cc1c047c31..9103c3e4a6 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/AggregationOperator.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.physical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Iterator; import java.util.List; import lombok.EqualsAndHashCode; @@ -59,7 +60,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java index 7faec2154b..816ada3b10 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/DedupeOperator.java @@ -5,8 +5,9 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; + import com.google.common.collect.ImmutableList; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -78,7 +79,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java index ac62fe1b86..e458b20211 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/EvalOperator.java @@ -5,12 +5,12 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; import static org.opensearch.sql.expression.env.Environment.extendEnv; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -50,7 +50,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java index 192ea5cb4f..291b267484 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/FilterOperator.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.physical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -36,7 +37,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/NestedOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/NestedOperator.java index fb5ec276ac..92f463b742 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/NestedOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/NestedOperator.java @@ -5,11 +5,11 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; import static java.util.stream.Collectors.mapping; import static java.util.stream.Collectors.toList; import java.util.ArrayList; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.ListIterator; @@ -80,7 +80,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java index 55422dacd3..ccde753530 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/ProjectOperator.java @@ -5,12 +5,13 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -42,7 +43,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java index ecf997f7ae..dac850ba3b 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/RareTopNOperator.java @@ -5,11 +5,12 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; + import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.Streams; import java.util.AbstractMap; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; @@ -84,7 +85,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java index b4a724aa7a..23a562aca8 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/RemoveOperator.java @@ -5,11 +5,11 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -49,7 +49,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java index e6f97dab4a..7195d15106 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/RenameOperator.java @@ -5,11 +5,11 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -56,7 +56,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java index b635f01d18..1a5887374b 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/SortOperator.java @@ -5,7 +5,8 @@ package org.opensearch.sql.planner.physical; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.Comparator; import java.util.Iterator; import java.util.List; @@ -63,7 +64,7 @@ public void open() { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java index a6e0f968e6..27813450b7 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/TakeOrderedOperator.java @@ -5,8 +5,9 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; + import com.google.common.collect.Ordering; -import java.util.Collections; import java.util.Iterator; import java.util.List; import lombok.EqualsAndHashCode; @@ -73,7 +74,7 @@ public void open() { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java index 10377ce47a..eb962cb537 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/WindowOperator.java @@ -5,10 +5,11 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterators; import com.google.common.collect.PeekingIterator; -import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -62,7 +63,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } @Override diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java b/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java index 2cfa3c9457..36455bf32c 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/collector/MetricCollector.java @@ -5,8 +5,9 @@ package org.opensearch.sql.planner.physical.collector; +import static java.util.Collections.singletonList; + import java.util.AbstractMap; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -57,6 +58,6 @@ public void collect(BindingTuple input) { public List results() { LinkedHashMap map = new LinkedHashMap<>(); aggregators.forEach(agg -> map.put(agg.getKey().getName(), agg.getValue().result())); - return Collections.singletonList(ExprTupleValue.fromExprValueMap(map)); + return singletonList(ExprTupleValue.fromExprValueMap(map)); } } diff --git a/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java b/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java index 2591689a35..504fad9f30 100644 --- a/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java +++ b/core/src/main/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssigner.java @@ -5,8 +5,9 @@ package org.opensearch.sql.planner.streaming.windowing.assigner; +import static java.util.Collections.singletonList; + import com.google.common.base.Preconditions; -import java.util.Collections; import java.util.List; import org.opensearch.sql.planner.streaming.windowing.Window; import org.opensearch.sql.utils.DateTimeUtils; @@ -31,6 +32,6 @@ public TumblingWindowAssigner(long windowSize) { @Override public List assign(long timestamp) { long startTime = DateTimeUtils.getWindowStartTime(timestamp, windowSize); - return Collections.singletonList(new Window(startTime, startTime + windowSize)); + return singletonList(new Window(startTime, startTime + windowSize)); } } diff --git a/core/src/main/java/org/opensearch/sql/storage/write/TableWriteBuilder.java b/core/src/main/java/org/opensearch/sql/storage/write/TableWriteBuilder.java index af18916f71..1a430fc049 100644 --- a/core/src/main/java/org/opensearch/sql/storage/write/TableWriteBuilder.java +++ b/core/src/main/java/org/opensearch/sql/storage/write/TableWriteBuilder.java @@ -5,7 +5,8 @@ package org.opensearch.sql.storage.write; -import java.util.Collections; +import static java.util.Collections.singletonList; + import org.opensearch.sql.planner.logical.LogicalPlan; import org.opensearch.sql.planner.logical.LogicalPlanNodeVisitor; import org.opensearch.sql.planner.physical.PhysicalPlan; @@ -20,7 +21,7 @@ public abstract class TableWriteBuilder extends LogicalPlan { /** Construct table write builder with child node. */ public TableWriteBuilder(LogicalPlan child) { - super(Collections.singletonList(child)); + super(singletonList(child)); } /** diff --git a/core/src/main/java/org/opensearch/sql/storage/write/TableWriteOperator.java b/core/src/main/java/org/opensearch/sql/storage/write/TableWriteOperator.java index 92cdc6eb41..82607eaa65 100644 --- a/core/src/main/java/org/opensearch/sql/storage/write/TableWriteOperator.java +++ b/core/src/main/java/org/opensearch/sql/storage/write/TableWriteOperator.java @@ -5,7 +5,8 @@ package org.opensearch.sql.storage.write; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.RequiredArgsConstructor; import org.opensearch.sql.planner.physical.PhysicalPlan; @@ -29,7 +30,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } /** diff --git a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java index 4f06ce9d23..53a5a28152 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java @@ -6,6 +6,7 @@ package org.opensearch.sql.analysis; import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -62,7 +63,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -491,7 +491,7 @@ public void rename_to_invalid_expression() { AstDSL.alias( "avg(integer_value)", AstDSL.aggregate("avg", field("integer_value")))), - Collections.emptyList(), + emptyList(), ImmutableList.of(), AstDSL.defaultStatsArgs()), AstDSL.map( @@ -894,7 +894,7 @@ public void remove_source() { DSL.ref("double_value", DOUBLE)), AstDSL.projectWithArg( AstDSL.relation("schema"), - Collections.singletonList(argument("exclude", booleanLiteral(true))), + singletonList(argument("exclude", booleanLiteral(true))), AstDSL.field("integer_value"), AstDSL.field("double_value"))); } @@ -1041,8 +1041,8 @@ public void window_function() { "window_function", AstDSL.window( AstDSL.function("row_number"), - Collections.singletonList(AstDSL.qualifiedName("string_value")), - Collections.singletonList( + singletonList(AstDSL.qualifiedName("string_value")), + singletonList( ImmutablePair.of(DEFAULT_ASC, AstDSL.qualifiedName("integer_value"))))))); } diff --git a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java index 17f86cadba..c0ff667efc 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java @@ -5,6 +5,7 @@ package org.opensearch.sql.analysis; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; import static org.opensearch.sql.data.type.ExprCoreType.LONG; @@ -12,7 +13,6 @@ import com.google.common.collect.ImmutableMap; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -61,7 +61,7 @@ protected StorageEngine prometheusStorageEngine() { return new StorageEngine() { @Override public Collection getFunctions() { - return Collections.singletonList( + return singletonList( new FunctionResolver() { @Override diff --git a/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java index 461e1f8358..8898b0b7db 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/SelectExpressionAnalyzerTest.java @@ -5,13 +5,13 @@ package org.opensearch.sql.analysis; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; -import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -77,11 +77,11 @@ protected List analyze(UnresolvedExpression unresolvedExpressio .when(optimizer) .optimize(any(), any()); return new SelectExpressionAnalyzer(expressionAnalyzer) - .analyze(Collections.singletonList(unresolvedExpression), analysisContext, optimizer); + .analyze(singletonList(unresolvedExpression), analysisContext, optimizer); } protected void assertAnalyzeEqual( NamedExpression expected, UnresolvedExpression unresolvedExpression) { - assertEquals(Collections.singletonList(expected), analyze(unresolvedExpression)); + assertEquals(singletonList(expected), analyze(unresolvedExpression)); } } diff --git a/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java b/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java index 2f3e855430..3300ca374e 100644 --- a/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.expression; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -14,7 +15,6 @@ import static org.opensearch.sql.expression.DSL.ref; import com.google.common.collect.ImmutableList; -import java.util.Collections; import java.util.List; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -38,7 +38,7 @@ void should_return_null_by_default() { assertNull(DSL.abs(literal(-10)).accept(visitor, null)); assertNull(DSL.sum(literal(10)).accept(visitor, null)); assertNull( - named("avg", new AvgAggregator(Collections.singletonList(ref("age", INTEGER)), INTEGER)) + named("avg", new AvgAggregator(singletonList(ref("age", INTEGER)), INTEGER)) .accept(visitor, null)); assertNull(new CaseClause(ImmutableList.of(), null).accept(visitor, null)); assertNull(new WhenClause(literal("test"), literal(10)).accept(visitor, null)); diff --git a/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java b/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java index ae345fa989..17f63d7215 100644 --- a/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java @@ -5,6 +5,8 @@ package org.opensearch.sql.expression.function; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -24,7 +26,6 @@ import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BOOLEAN; import com.google.common.collect.ImmutableList; -import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; @@ -97,7 +98,7 @@ void compile_datasource_defined_function() { repo.compile( functionProperties, - Collections.singletonList(dataSourceFunctionResolver), + singletonList(dataSourceFunctionResolver), mockFunctionName, List.of(mockExpression)); verify(functionExpressionBuilder, times(1)).apply(eq(functionProperties), any()); @@ -115,8 +116,7 @@ void resolve() { BuiltinFunctionRepository repo = new BuiltinFunctionRepository(mockMap); repo.register(mockfunctionResolver); - assertEquals( - functionExpressionBuilder, repo.resolve(Collections.emptyList(), functionSignature)); + assertEquals(functionExpressionBuilder, repo.resolve(emptyList(), functionSignature)); } @Test @@ -124,7 +124,7 @@ void resolve_should_not_cast_arguments_in_cast_function() { when(mockExpression.toString()).thenReturn("string"); FunctionImplementation function = repo.resolve( - Collections.emptyList(), + emptyList(), registerFunctionResolver(CAST_TO_BOOLEAN.getName(), TIMESTAMP, BOOLEAN)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("cast_to_boolean(string)", function.toString()); @@ -135,8 +135,7 @@ void resolve_should_not_cast_arguments_if_same_type() { when(mockFunctionName.getFunctionName()).thenReturn("mock"); when(mockExpression.toString()).thenReturn("string"); FunctionImplementation function = - repo.resolve( - Collections.emptyList(), registerFunctionResolver(mockFunctionName, STRING, STRING)) + repo.resolve(emptyList(), registerFunctionResolver(mockFunctionName, STRING, STRING)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(string)", function.toString()); } @@ -146,8 +145,7 @@ void resolve_should_not_cast_arguments_if_both_numbers() { when(mockFunctionName.getFunctionName()).thenReturn("mock"); when(mockExpression.toString()).thenReturn("byte"); FunctionImplementation function = - repo.resolve( - Collections.emptyList(), registerFunctionResolver(mockFunctionName, BYTE, INTEGER)) + repo.resolve(emptyList(), registerFunctionResolver(mockFunctionName, BYTE, INTEGER)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(byte)", function.toString()); } @@ -162,7 +160,7 @@ void resolve_should_cast_arguments() { registerFunctionResolver(CAST_TO_BOOLEAN.getName(), STRING, STRING); FunctionImplementation function = - repo.resolve(Collections.emptyList(), signature) + repo.resolve(emptyList(), signature) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(cast_to_boolean(string))", function.toString()); } @@ -173,9 +171,7 @@ void resolve_should_throw_exception_for_unsupported_conversion() { assertThrows( ExpressionEvaluationException.class, () -> - repo.resolve( - Collections.emptyList(), - registerFunctionResolver(mockFunctionName, BYTE, STRUCT)) + repo.resolve(emptyList(), registerFunctionResolver(mockFunctionName, BYTE, STRUCT)) .apply(functionProperties, ImmutableList.of(mockExpression))); assertEquals(error.getMessage(), "Type conversion to type STRUCT is not supported"); } @@ -192,8 +188,7 @@ void resolve_unregistered() { ExpressionEvaluationException.class, () -> repo.resolve( - Collections.emptyList(), - new FunctionSignature(FunctionName.of("unknown"), List.of()))); + emptyList(), new FunctionSignature(FunctionName.of("unknown"), List.of()))); assertEquals("unsupported function name: unknown", exception.getMessage()); } diff --git a/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java b/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java index 9db1eaf565..a58773fae4 100644 --- a/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java @@ -6,6 +6,7 @@ package org.opensearch.sql.planner; import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -31,7 +32,6 @@ import static org.opensearch.sql.planner.logical.LogicalPlanDSL.window; import com.google.common.collect.ImmutableMap; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -191,9 +191,8 @@ public void visitWindowOperator_should_return_PhysicalWindowOperator() { NamedExpression windowFunction = named(new RowNumberFunction()); WindowDefinition windowDefinition = new WindowDefinition( - Collections.singletonList(ref("state", STRING)), - Collections.singletonList( - ImmutablePair.of(Sort.SortOption.DEFAULT_DESC, ref("age", INTEGER)))); + singletonList(ref("state", STRING)), + singletonList(ImmutablePair.of(Sort.SortOption.DEFAULT_DESC, ref("age", INTEGER)))); NamedExpression[] projectList = { named("state", ref("state", STRING)), named("row_number", ref("row_number", INTEGER)) diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java index ee784045d0..d454469ba2 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java @@ -5,6 +5,8 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInRelativeOrder; @@ -20,7 +22,6 @@ import com.google.common.collect.ImmutableMap; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; import org.opensearch.sql.data.model.ExprDateValue; @@ -38,9 +39,8 @@ public void sum_without_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - Collections.singletonList( - DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), - Collections.emptyList()); + singletonList(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), + emptyList()); List result = execute(plan); assertEquals(1, result.size()); assertThat( @@ -53,9 +53,8 @@ public void avg_with_one_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - Collections.singletonList( - DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), - Collections.singletonList(DSL.named("action", DSL.ref("action", STRING)))); + singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + singletonList(DSL.named("action", DSL.ref("action", STRING)))); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -70,8 +69,7 @@ public void avg_with_two_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - Collections.singletonList( - DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), Arrays.asList( DSL.named("action", DSL.ref("action", STRING)), DSL.named("ip", DSL.ref("ip", STRING)))); @@ -93,9 +91,8 @@ public void sum_with_one_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - Collections.singletonList( - DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), - Collections.singletonList(DSL.named("action", DSL.ref("action", STRING)))); + singletonList(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), + singletonList(DSL.named("action", DSL.ref("action", STRING)))); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -110,8 +107,8 @@ public void millisecond_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + singletonList( DSL.named( "span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6 * 1000), "ms")))); List result = execute(plan); @@ -131,8 +128,8 @@ public void second_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6), "s")))); List result = execute(plan); assertEquals(2, result.size()); @@ -151,8 +148,8 @@ public void minute_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("minute", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("minute", TIMESTAMP)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("minute", TIMESTAMP), DSL.literal(5), "m")))); List result = execute(plan); assertEquals(3, result.size()); @@ -170,8 +167,8 @@ public void minute_span() { plan = new AggregationOperator( testScan(datetimeInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(30), "m")))); result = execute(plan); assertEquals(4, result.size()); @@ -193,9 +190,8 @@ public void hour_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), - Collections.singletonList( - DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(1), "h")))); + singletonList(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), + singletonList(DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(1), "h")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -214,9 +210,8 @@ public void day_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count(day)", DSL.count(DSL.ref("day", DATE)))), - Collections.singletonList( - DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")))); + singletonList(DSL.named("count(day)", DSL.count(DSL.ref("day", DATE)))), + singletonList(DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")))); List result = execute(plan); assertEquals(4, result.size()); assertThat( @@ -234,8 +229,8 @@ public void day_span() { plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(30), "d")))); result = execute(plan); assertEquals(3, result.size()); @@ -255,8 +250,8 @@ public void week_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(5), "w")))); List result = execute(plan); assertEquals(3, result.size()); @@ -276,8 +271,8 @@ public void month_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(1), "M")))); List result = execute(plan); assertEquals(3, result.size()); @@ -294,8 +289,8 @@ public void month_span() { plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "M")))); result = execute(plan); assertEquals(4, result.size()); @@ -315,8 +310,8 @@ public void month_span() { plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), + singletonList( DSL.named( "span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10 * 12), "M")))); result = execute(plan); @@ -338,8 +333,8 @@ public void quarter_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "q")))); List result = execute(plan); assertEquals(2, result.size()); @@ -355,8 +350,8 @@ public void quarter_span() { plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10 * 4), "q")))); result = execute(plan); assertEquals(3, result.size()); @@ -377,8 +372,8 @@ public void year_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10), "y")))); List result = execute(plan); assertEquals(3, result.size()); @@ -399,8 +394,8 @@ public void integer_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("integer", INTEGER), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); @@ -414,8 +409,8 @@ public void integer_field() { plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("integer", INTEGER), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); @@ -432,9 +427,8 @@ public void long_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), - Collections.singletonList( - DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1), "")))); + singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), + singletonList(DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -447,8 +441,8 @@ public void long_field() { plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); @@ -465,8 +459,8 @@ public void float_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); @@ -480,8 +474,8 @@ public void float_field() { plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); @@ -498,8 +492,8 @@ public void double_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); @@ -513,8 +507,8 @@ public void double_field() { plan = new AggregationOperator( testScan(numericInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), + singletonList( DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); @@ -531,7 +525,7 @@ public void twoBucketsSpanAndLong() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - Collections.singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), + singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), Arrays.asList( DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")), DSL.named("region", DSL.ref("region", STRING)))); @@ -556,7 +550,7 @@ public void twoBucketsSpanAndLong() { plan = new AggregationOperator( testScan(compoundInputs), - Collections.singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), + singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), Arrays.asList( DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")), DSL.named("region", DSL.ref("region", STRING)), @@ -643,7 +637,7 @@ public void aggregate_with_two_groups_with_windowing() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - Collections.singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), + singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), Arrays.asList( DSL.named("host", DSL.ref("host", STRING)), DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")))); @@ -695,7 +689,7 @@ public void aggregate_with_three_groups_with_windowing() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - Collections.singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), + singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), Arrays.asList( DSL.named("host", DSL.ref("host", STRING)), DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")), @@ -755,8 +749,8 @@ public void copyOfAggregationOperatorShouldSame() { AggregationOperator plan = new AggregationOperator( testScan(datetimeInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - Collections.singletonList( + singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + singletonList( DSL.named( "span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6 * 1000), "ms")))); AggregationOperator copy = diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/RareTopNOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/RareTopNOperatorTest.java index e252c41d1f..70e2ba1866 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/RareTopNOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/RareTopNOperatorTest.java @@ -5,12 +5,13 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.common.collect.ImmutableMap; -import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; import org.opensearch.sql.ast.tree.RareTopN.CommandType; @@ -27,8 +28,8 @@ public void rare_without_group() { new RareTopNOperator( new TestScan(), CommandType.RARE, - Collections.singletonList(DSL.ref("action", ExprCoreType.STRING)), - Collections.emptyList()); + singletonList(DSL.ref("action", ExprCoreType.STRING)), + emptyList()); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -44,8 +45,8 @@ public void rare_with_group() { new RareTopNOperator( new TestScan(), CommandType.RARE, - Collections.singletonList(DSL.ref("response", ExprCoreType.INTEGER)), - Collections.singletonList(DSL.ref("action", ExprCoreType.STRING))); + singletonList(DSL.ref("response", ExprCoreType.INTEGER)), + singletonList(DSL.ref("action", ExprCoreType.STRING))); List result = execute(plan); assertEquals(4, result.size()); assertThat( @@ -63,8 +64,8 @@ public void top_without_group() { new RareTopNOperator( new TestScan(), CommandType.TOP, - Collections.singletonList(DSL.ref("action", ExprCoreType.STRING)), - Collections.emptyList()); + singletonList(DSL.ref("action", ExprCoreType.STRING)), + emptyList()); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -81,8 +82,8 @@ public void top_n_without_group() { new TestScan(), CommandType.TOP, 1, - Collections.singletonList(DSL.ref("action", ExprCoreType.STRING)), - Collections.emptyList()); + singletonList(DSL.ref("action", ExprCoreType.STRING)), + emptyList()); List result = execute(plan); assertEquals(1, result.size()); assertThat( @@ -96,8 +97,8 @@ public void top_n_with_group() { new TestScan(), CommandType.TOP, 1, - Collections.singletonList(DSL.ref("response", ExprCoreType.INTEGER)), - Collections.singletonList(DSL.ref("action", ExprCoreType.STRING))); + singletonList(DSL.ref("response", ExprCoreType.INTEGER)), + singletonList(DSL.ref("action", ExprCoreType.STRING))); List result = execute(plan); assertEquals(2, result.size()); assertThat( diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/RenameOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/RenameOperatorTest.java index 807d8b8836..fe55275e3b 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/RenameOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/RenameOperatorTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.planner.physical; +import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -14,7 +15,6 @@ import static org.opensearch.sql.data.type.ExprCoreType.STRING; import com.google.common.collect.ImmutableMap; -import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -34,9 +34,8 @@ public void avg_aggregation_rename() { new RenameOperator( new AggregationOperator( new TestScan(), - Collections.singletonList( - DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), - Collections.singletonList(DSL.named("action", DSL.ref("action", STRING)))), + singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + singletonList(DSL.named("action", DSL.ref("action", STRING)))), ImmutableMap.of(DSL.ref("avg(response)", DOUBLE), DSL.ref("avg", DOUBLE))); List result = execute(plan); assertEquals(2, result.size()); diff --git a/core/src/test/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssignerTest.java b/core/src/test/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssignerTest.java index a8ab048701..4869a4c8a8 100644 --- a/core/src/test/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssignerTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/streaming/windowing/assigner/TumblingWindowAssignerTest.java @@ -5,10 +5,10 @@ package org.opensearch.sql.planner.streaming.windowing.assigner; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.util.Collections; import org.junit.jupiter.api.Test; import org.opensearch.sql.planner.streaming.windowing.Window; @@ -19,9 +19,9 @@ void testAssignWindow() { long windowSize = 1000; TumblingWindowAssigner assigner = new TumblingWindowAssigner(windowSize); - assertEquals(Collections.singletonList(new Window(0, 1000)), assigner.assign(500)); - assertEquals(Collections.singletonList(new Window(1000, 2000)), assigner.assign(1999)); - assertEquals(Collections.singletonList(new Window(2000, 3000)), assigner.assign(2000)); + assertEquals(singletonList(new Window(0, 1000)), assigner.assign(500)); + assertEquals(singletonList(new Window(1000, 2000)), assigner.assign(1999)); + assertEquals(singletonList(new Window(2000, 3000)), assigner.assign(2000)); } @Test diff --git a/core/src/test/java/org/opensearch/sql/storage/write/TableWriteOperatorTest.java b/core/src/test/java/org/opensearch/sql/storage/write/TableWriteOperatorTest.java index e5b2c9f61a..3c28b14092 100644 --- a/core/src/test/java/org/opensearch/sql/storage/write/TableWriteOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/storage/write/TableWriteOperatorTest.java @@ -5,10 +5,10 @@ package org.opensearch.sql.storage.write; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.Collections; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -68,6 +68,6 @@ public Boolean visitTableWrite(TableWriteOperator node, Object context) { @Test void testGetChild() { - assertEquals(Collections.singletonList(child), tableWrite.getChild()); + assertEquals(singletonList(child), tableWrite.getChild()); } } diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java index 9a1022706f..84cb3d58a0 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java @@ -5,6 +5,8 @@ package org.opensearch.sql.datasources.service; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -22,7 +24,6 @@ import com.google.common.collect.ImmutableMap; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -104,7 +105,7 @@ void testGetDataSourceForNonExistingDataSource() { @Test void testGetDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("test", DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of()); + metadata("test", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); doNothing().when(dataSourceUserAuthorizationHelper).authorizeDataSource(dataSourceMetadata); when(dataSourceMetadataStorage.getDataSourceMetadata("test")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -121,7 +122,7 @@ void testGetDataSourceWithAuthorizationFailure() { metadata( "test", DataSourceType.OPENSEARCH, - Collections.singletonList("prometheus_access"), + singletonList("prometheus_access"), ImmutableMap.of()); doThrow( new SecurityException( @@ -148,7 +149,7 @@ void testGetDataSourceWithAuthorizationFailure() { void testCreateDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("testDS", DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); dataSourceService.createDataSource(dataSourceMetadata); verify(dataSourceMetadataStorage, times(1)).createDataSourceMetadata(dataSourceMetadata); verify(dataSourceFactory, times(1)).createDataSource(dataSourceMetadata); @@ -156,11 +157,7 @@ void testCreateDataSourceSuccessCase() { when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn( Optional.ofNullable( - metadata( - "testDS", - DataSourceType.OPENSEARCH, - Collections.emptyList(), - ImmutableMap.of()))); + metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()))); DataSource dataSource = dataSourceService.getDataSource("testDS"); assertEquals("testDS", dataSource.getName()); assertEquals(storageEngine, dataSource.getStorageEngine()); @@ -178,9 +175,7 @@ void testGetDataSourceMetadataSet() { .thenReturn( new ArrayList<>() { { - add( - metadata( - "testDS", DataSourceType.PROMETHEUS, Collections.emptyList(), properties)); + add(metadata("testDS", DataSourceType.PROMETHEUS, emptyList(), properties)); } }); Set dataSourceMetadataSet = dataSourceService.getDataSourceMetadata(false); @@ -201,12 +196,7 @@ void testGetDataSourceMetadataSetWithDefaultDatasource() { .thenReturn( new ArrayList<>() { { - add( - metadata( - "testDS", - DataSourceType.PROMETHEUS, - Collections.emptyList(), - ImmutableMap.of())); + add(metadata("testDS", DataSourceType.PROMETHEUS, emptyList(), ImmutableMap.of())); } }); Set dataSourceMetadataSet = dataSourceService.getDataSourceMetadata(true); @@ -219,7 +209,7 @@ void testGetDataSourceMetadataSetWithDefaultDatasource() { @Test void testUpdateDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("testDS", DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); dataSourceService.updateDataSource(dataSourceMetadata); verify(dataSourceMetadataStorage, times(1)).updateDataSourceMetadata(dataSourceMetadata); verify(dataSourceFactory, times(1)).createDataSource(dataSourceMetadata); @@ -229,10 +219,7 @@ void testUpdateDataSourceSuccessCase() { void testUpdateDefaultDataSource() { DataSourceMetadata dataSourceMetadata = metadata( - DEFAULT_DATASOURCE_NAME, - DataSourceType.OPENSEARCH, - Collections.emptyList(), - ImmutableMap.of()); + DEFAULT_DATASOURCE_NAME, DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); UnsupportedOperationException unsupportedOperationException = assertThrows( UnsupportedOperationException.class, @@ -276,7 +263,7 @@ void testPatchDataSourceSuccessCase() { STATUS_FIELD, DataSourceStatus.DISABLED)); DataSourceMetadata getData = - metadata("testDS", DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.ofNullable(getData)); @@ -339,7 +326,7 @@ void testRemovalOfAuthorizationInfo() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -364,7 +351,7 @@ void testRemovalOfAuthorizationInfoForAccessKeyAndSecretKye() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -391,7 +378,7 @@ void testRemovalOfAuthorizationInfoForGlueWithRoleARN() { .setName("testGlue") .setProperties(properties) .setConnector(DataSourceType.S3GLUE) - .setAllowedRoles(Collections.singletonList("glue_access")) + .setAllowedRoles(singletonList("glue_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testGlue")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -433,8 +420,7 @@ void testGetDataSourceMetadataForSpecificDataSourceName() { when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn( Optional.ofNullable( - metadata( - "testDS", DataSourceType.PROMETHEUS, Collections.emptyList(), properties))); + metadata("testDS", DataSourceType.PROMETHEUS, emptyList(), properties))); DataSourceMetadata dataSourceMetadata = this.dataSourceService.getDataSourceMetadata("testDS"); assertTrue(dataSourceMetadata.getProperties().containsKey("prometheus.uri")); assertTrue(dataSourceMetadata.getProperties().containsKey("prometheus.auth.type")); @@ -455,7 +441,7 @@ void testVerifyDataSourceAccessAndGetRawDataSourceMetadataWithDisabledData() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .setDataSourceStatus(DataSourceStatus.DISABLED) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) @@ -482,7 +468,7 @@ void testVerifyDataSourceAccessAndGetRawDataSourceMetadata() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .setDataSourceStatus(DataSourceStatus.ACTIVE) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java index 03abe73763..0a363699cd 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java @@ -5,6 +5,8 @@ package org.opensearch.sql.datasources.storage; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.opensearch.sql.datasource.model.DataSourceStatus.ACTIVE; import static org.opensearch.sql.datasources.storage.OpenSearchDataSourceMetadataStorage.DATASOURCE_INDEX_NAME; @@ -15,7 +17,6 @@ import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -672,7 +673,7 @@ public void testWhenDataSourcesAreDisabled() { Optional.empty(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata("dummy")); Assertions.assertEquals( - Collections.emptyList(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata()); + emptyList(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata()); Assertions.assertThrows( IllegalStateException.class, @@ -712,7 +713,7 @@ private String getBasicDataSourceMetadataString() throws JsonProcessingException .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -732,7 +733,7 @@ private String getAWSSigv4DataSourceMetadataString() throws JsonProcessingExcept .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -749,7 +750,7 @@ private String getDataSourceMetadataStringWithBasicAuthentication() .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -762,7 +763,7 @@ private String getDataSourceMetadataStringWithNoAuthentication() throws JsonProc .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -777,7 +778,7 @@ private DataSourceMetadata getDataSourceMetadata() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(Collections.singletonList("prometheus_access")) + .setAllowedRoles(singletonList("prometheus_access")) .build(); } diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtilsTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtilsTest.java index 2b77c1938a..e48ec0ffee 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtilsTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/utils/DatasourceValidationUtilsTest.java @@ -1,6 +1,8 @@ package org.opensearch.sql.datasources.utils; -import java.util.Collections; +import static java.util.Collections.emptySet; +import static java.util.Collections.singletonList; + import java.util.HashMap; import java.util.Set; import lombok.SneakyThrows; @@ -21,7 +23,7 @@ public void testValidateHost() { IllegalArgumentException.class, () -> DatasourceValidationUtils.validateHost( - "http://localhost:9090", Collections.singletonList("127.0.0.0/8"))); + "http://localhost:9090", singletonList("127.0.0.0/8"))); Assertions.assertEquals( "Disallowed hostname in the uri. Validate with plugins.query.datasources.uri.hosts.denylist" + " config", @@ -34,7 +36,7 @@ public void testValidateHostWithSuccess() { Assertions.assertDoesNotThrow( () -> DatasourceValidationUtils.validateHost( - "http://localhost:9090", Collections.singletonList("192.168.0.0/8"))); + "http://localhost:9090", singletonList("192.168.0.0/8"))); } @Test @@ -73,8 +75,6 @@ public void testValidateLengthAndRequiredFieldsWithSuccess() { HashMap config = new HashMap<>(); config.put("s3.uri", "test"); Assertions.assertDoesNotThrow( - () -> - DatasourceValidationUtils.validateLengthAndRequiredFields( - config, Collections.emptySet())); + () -> DatasourceValidationUtils.validateLengthAndRequiredFields(config, emptySet())); } } diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/PrettyFormatResponseIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/PrettyFormatResponseIT.java index 73ed6e359c..f90b42cda2 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/PrettyFormatResponseIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/PrettyFormatResponseIT.java @@ -5,6 +5,7 @@ package org.opensearch.sql.legacy; +import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toSet; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -15,7 +16,6 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -157,7 +157,7 @@ public void selectScore() throws IOException { "SELECT _score FROM %s WHERE SCORE(match_phrase(phrase, 'brown fox'))", TestsConstants.TEST_INDEX_PHRASE)); - List fields = Collections.singletonList("_score"); + List fields = singletonList("_score"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } @@ -277,7 +277,7 @@ public void groupBySingleField() throws IOException { String.format( Locale.ROOT, "SELECT * FROM %s GROUP BY age", TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = Collections.singletonList("age"); + List fields = singletonList("age"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } @@ -398,7 +398,7 @@ public void aggregationFunctionInSelectNoGroupBy() throws IOException { Locale.ROOT, "SELECT SUM(age) FROM %s", TestsConstants.TEST_INDEX_ACCOUNT)); String ageSum = "SUM(age)"; - assertContainsColumns(getSchema(response), Collections.singletonList(ageSum)); + assertContainsColumns(getSchema(response), singletonList(ageSum)); JSONArray dataRows = getDataRows(response); for (int i = 0; i < dataRows.length(); i++) { @@ -433,7 +433,7 @@ public void aggregationFunctionInHaving() throws IOException { TestsConstants.TEST_INDEX_ACCOUNT)); String ageSum = "gender"; - assertContainsColumns(getSchema(response), Collections.singletonList(ageSum)); + assertContainsColumns(getSchema(response), singletonList(ageSum)); JSONArray dataRows = getDataRows(response); assertEquals(1, dataRows.length()); @@ -555,7 +555,7 @@ public void joinQuerySelectOnlyOnOneTable() throws Exception { TestsConstants.TEST_INDEX_ACCOUNT, TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = Collections.singletonList("b1.age"); + List fields = singletonList("b1.age"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/format/DeleteResultSet.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/format/DeleteResultSet.java index 2e040d78fb..6d6b05a3e3 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/format/DeleteResultSet.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/format/DeleteResultSet.java @@ -5,7 +5,9 @@ package org.opensearch.sql.legacy.executor.format; -import java.util.Collections; +import static java.util.Collections.singletonList; +import static java.util.Collections.singletonMap; + import java.util.List; import java.util.Map; import org.opensearch.client.Client; @@ -27,14 +29,14 @@ public DeleteResultSet(Client client, Delete query, Object queryResult) { } private List loadColumns() { - return Collections.singletonList(new Schema.Column(DELETED, null, Schema.Type.LONG)); + return singletonList(new Schema.Column(DELETED, null, Schema.Type.LONG)); } private List loadRows() { - return Collections.singletonList(new DataRows.Row(loadDeletedData())); + return singletonList(new DataRows.Row(loadDeletedData())); } private Map loadDeletedData() { - return Collections.singletonMap(DELETED, ((BulkByScrollResponse) queryResult).getDeleted()); + return singletonMap(DELETED, ((BulkByScrollResponse) queryResult).getDeleted()); } } diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/expression/core/builder/UnaryExpressionBuilder.java b/legacy/src/main/java/org/opensearch/sql/legacy/expression/core/builder/UnaryExpressionBuilder.java index f66e744923..de726d7e19 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/expression/core/builder/UnaryExpressionBuilder.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/expression/core/builder/UnaryExpressionBuilder.java @@ -5,7 +5,8 @@ package org.opensearch.sql.legacy.expression.core.builder; -import java.util.Collections; +import static java.util.Collections.singletonList; + import java.util.List; import lombok.RequiredArgsConstructor; import org.opensearch.sql.legacy.expression.core.Expression; @@ -31,7 +32,7 @@ public Expression build(List expressionList) { return new Expression() { @Override public ExprValue valueOf(BindingTuple tuple) { - return op.apply(Collections.singletonList(expression.valueOf(tuple))); + return op.apply(singletonList(expression.valueOf(tuple))); } @Override diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/ADOperator.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/ADOperator.java index f9c32b7424..f274e35811 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/ADOperator.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/ADOperator.java @@ -5,6 +5,7 @@ package org.opensearch.sql.opensearch.planner.physical; +import static java.util.Collections.singletonList; import static org.opensearch.sql.utils.MLCommonsConstants.ANOMALY_RATE; import static org.opensearch.sql.utils.MLCommonsConstants.ANOMALY_SCORE_THRESHOLD; import static org.opensearch.sql.utils.MLCommonsConstants.CATEGORY_FIELD; @@ -18,7 +19,6 @@ import static org.opensearch.sql.utils.MLCommonsConstants.TIME_ZONE; import static org.opensearch.sql.utils.MLCommonsConstants.TRAINING_DATA_SIZE; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -115,7 +115,7 @@ public ExprValue next() { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } protected MLAlgoParams convertArgumentToMLParameter(Map arguments) { diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperator.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperator.java index ef60782a24..3ae0f43fce 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperator.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperator.java @@ -5,12 +5,12 @@ package org.opensearch.sql.opensearch.planner.physical; +import static java.util.Collections.singletonList; import static org.opensearch.ml.common.FunctionName.KMEANS; import static org.opensearch.sql.utils.MLCommonsConstants.CENTROIDS; import static org.opensearch.sql.utils.MLCommonsConstants.DISTANCE_TYPE; import static org.opensearch.sql.utils.MLCommonsConstants.ITERATIONS; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -91,7 +91,7 @@ public ExprValue next() { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } protected MLAlgoParams convertArgumentToMLParameter( diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLOperator.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLOperator.java index 6dc7078a0d..00a28342ef 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLOperator.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/MLOperator.java @@ -5,8 +5,9 @@ package org.opensearch.sql.opensearch.planner.physical; +import static java.util.Collections.singletonList; + import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -98,7 +99,7 @@ public ExprValue next() { @Override public List getChild() { - return Collections.singletonList(input); + return singletonList(input); } protected Map processArgs(Map arguments) { diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/response/agg/NoBucketAggregationParser.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/response/agg/NoBucketAggregationParser.java index de0ee5883c..3a61915499 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/response/agg/NoBucketAggregationParser.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/response/agg/NoBucketAggregationParser.java @@ -13,8 +13,9 @@ package org.opensearch.sql.opensearch.response.agg; +import static java.util.Collections.singletonList; + import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; import org.opensearch.search.aggregations.Aggregations; @@ -34,6 +35,6 @@ public NoBucketAggregationParser(List metricParserList) { @Override public List> parse(Aggregations aggregations) { - return Collections.singletonList(metricsParser.parse(aggregations)); + return singletonList(metricsParser.parse(aggregations)); } } diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilder.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilder.java index a218151b2e..7f14cb1fe0 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilder.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilder.java @@ -5,10 +5,11 @@ package org.opensearch.sql.opensearch.storage.script.aggregation; +import static java.util.Collections.singletonList; + import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -77,7 +78,7 @@ public AggregationQueryBuilder(ExpressionSerializer serializer) { } else { GroupSortOrder groupSortOrder = new GroupSortOrder(sortList); return Pair.of( - Collections.singletonList( + singletonList( AggregationBuilders.composite( "composite_buckets", bucketBuilder.build( diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperatorTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperatorTest.java index e6d2bac85b..6b76b37360 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperatorTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLCommonsOperatorTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.opensearch.planner.physical; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -16,7 +17,6 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableMap; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -81,7 +81,7 @@ void setUp() { DataFrame dataFrame = DataFrameBuilder.load( - Collections.singletonList( + singletonList( ImmutableMap.builder() .put("result-k1", 2D) .put("result-k2", 1) diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLOperatorTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLOperatorTest.java index fa328fd26c..f003de848d 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLOperatorTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/planner/physical/MLOperatorTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.opensearch.planner.physical; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -20,7 +21,6 @@ import static org.opensearch.sql.utils.MLCommonsConstants.TRAIN; import com.google.common.collect.ImmutableMap; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -87,7 +87,7 @@ void setUp(boolean isPredict) { DataFrame dataFrame = DataFrameBuilder.load( - Collections.singletonList( + singletonList( ImmutableMap.builder() .put("result-k1", 2D) .put("result-k2", 1) diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/request/OpenSearchRequestBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/request/OpenSearchRequestBuilderTest.java index a2430a671d..1e6bb6b171 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/request/OpenSearchRequestBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/request/OpenSearchRequestBuilderTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.opensearch.request; +import static java.util.Collections.singletonList; import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; @@ -14,7 +15,6 @@ import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRING; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -349,7 +349,7 @@ void test_push_down_query() { void test_push_down_aggregation() { AggregationBuilder aggBuilder = AggregationBuilders.composite( - "composite_buckets", Collections.singletonList(new TermsValuesSourceBuilder("longA"))); + "composite_buckets", singletonList(new TermsValuesSourceBuilder("longA"))); OpenSearchAggregationResponseParser responseParser = new CompositeAggregationParser(new SingleValueParser("AVG(intA)")); requestBuilder.pushDownAggregation(Pair.of(List.of(aggBuilder), responseParser)); @@ -368,7 +368,7 @@ void test_push_down_aggregation() { void test_push_down_percentile_aggregation() { AggregationBuilder aggBuilder = AggregationBuilders.composite( - "composite_buckets", Collections.singletonList(new TermsValuesSourceBuilder("longA"))); + "composite_buckets", singletonList(new TermsValuesSourceBuilder("longA"))); OpenSearchAggregationResponseParser responseParser = new CompositeAggregationParser(new SinglePercentileParser("PERCENTILE(intA, 50)")); requestBuilder.pushDownAggregation(Pair.of(List.of(aggBuilder), responseParser)); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/scan/OpenSearchIndexScanOptimizationTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/scan/OpenSearchIndexScanOptimizationTest.java index 6749f87c5b..b0769b950c 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/scan/OpenSearchIndexScanOptimizationTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/scan/OpenSearchIndexScanOptimizationTest.java @@ -5,6 +5,8 @@ package org.opensearch.sql.opensearch.storage.scan; +import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; @@ -39,7 +41,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Arrays; -import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -331,10 +332,10 @@ void test_limit_push_down() { void test_highlight_push_down() { assertEqualsAfterOptimization( project( - indexScanBuilder(withHighlightPushedDown("*", Collections.emptyMap())), + indexScanBuilder(withHighlightPushedDown("*", emptyMap())), DSL.named("highlight(*)", new HighlightExpression(DSL.literal("*")))), project( - highlight(relation("schema", table), DSL.literal("*"), Collections.emptyMap()), + highlight(relation("schema", table), DSL.literal("*"), emptyMap()), DSL.named("highlight(*)", new HighlightExpression(DSL.literal("*"))))); } @@ -641,7 +642,7 @@ private Runnable withAggregationPushedDown( CompositeAggregationBuilder aggBuilder = AggregationBuilders.composite( "composite_buckets", - Collections.singletonList( + singletonList( new TermsValuesSourceBuilder(aggregation.groupBy) .field(aggregation.groupBy) .order(aggregation.sortBy.getSortOrder() == ASC ? "asc" : "desc") @@ -652,7 +653,7 @@ private Runnable withAggregationPushedDown( AggregationBuilders.avg(aggregation.aggregateName).field(aggregation.aggregateBy)) .size(AggregationQueryBuilder.AGGREGATION_BUCKET_SIZE); - List aggBuilders = Collections.singletonList(aggBuilder); + List aggBuilders = singletonList(aggBuilder); OpenSearchAggregationResponseParser responseParser = new CompositeAggregationParser(new SingleValueParser(aggregation.aggregateName)); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java index 4c030ae001..13769ef226 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java @@ -5,6 +5,8 @@ package org.opensearch.sql.opensearch.storage.script.aggregation; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -30,7 +32,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.util.AbstractMap; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -280,8 +281,7 @@ void should_build_composite_aggregation_for_expression() { List.of( named( "avg(balance)", - new AvgAggregator( - Collections.singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), + new AvgAggregator(singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), List.of(named("age", DSL.asin(ref("age", INTEGER)))))); } @@ -339,8 +339,7 @@ void should_build_type_mapping_for_expression() { List.of( named( "avg(balance)", - new AvgAggregator( - Collections.singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), + new AvgAggregator(singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), List.of(named("age", DSL.asin(ref("age", INTEGER))))), containsInAnyOrder( map("avg(balance)", OpenSearchDataType.of(INTEGER)), @@ -362,7 +361,7 @@ void should_build_aggregation_without_bucket() { List.of( named( "avg(balance)", new AvgAggregator(List.of(ref("balance", INTEGER)), INTEGER))), - Collections.emptyList())); + emptyList())); } @Test @@ -397,7 +396,7 @@ void should_build_filter_aggregation() { "avg(age) filter(where age > 34)", new AvgAggregator(List.of(ref("age", INTEGER)), INTEGER) .condition(DSL.greater(ref("age", INTEGER), literal(20))))), - Collections.emptyList())); + emptyList())); } @Test @@ -459,7 +458,7 @@ void should_build_type_mapping_without_bucket() { List.of( named( "avg(balance)", new AvgAggregator(List.of(ref("balance", INTEGER)), INTEGER))), - Collections.emptyList()), + emptyList()), containsInAnyOrder(map("avg(balance)", OpenSearchDataType.of(INTEGER)))); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java index c3c24facb2..8c6ff07083 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.opensearch.storage.script.aggregation.dsl; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; @@ -24,7 +25,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import lombok.SneakyThrows; import org.junit.jupiter.api.BeforeEach; @@ -335,10 +335,10 @@ void should_build_cardinality_aggregation() { + " }%n" + "}"), buildQuery( - Collections.singletonList( + singletonList( named( "count(distinct name)", - new CountAggregator(Collections.singletonList(ref("name", STRING)), INTEGER) + new CountAggregator(singletonList(ref("name", STRING)), INTEGER) .distinct(true))))); } @@ -369,10 +369,10 @@ void should_build_filtered_cardinality_aggregation() { + " }%n" + "}"), buildQuery( - Collections.singletonList( + singletonList( named( "count(distinct name) filter(where age > 30)", - new CountAggregator(Collections.singletonList(ref("name", STRING)), INTEGER) + new CountAggregator(singletonList(ref("name", STRING)), INTEGER) .condition(DSL.greater(ref("age", INTEGER), literal(30))) .distinct(true))))); } @@ -397,7 +397,7 @@ void should_build_top_hits_aggregation() { + " }%n" + "}"), buildQuery( - Collections.singletonList( + singletonList( named( "take(name, 10)", new TakeAggregator( @@ -439,7 +439,7 @@ void should_build_filtered_top_hits_aggregation() { + " }%n" + "}"), buildQuery( - Collections.singletonList( + singletonList( named( "take(name, 10) filter(where age > 30)", new TakeAggregator(ImmutableList.of(ref("name", STRING), literal(10)), ARRAY) @@ -452,10 +452,10 @@ void should_throw_exception_for_unsupported_distinct_aggregator() { IllegalStateException.class, () -> buildQuery( - Collections.singletonList( + singletonList( named( "avg(distinct age)", - new AvgAggregator(Collections.singletonList(ref("name", STRING)), STRING) + new AvgAggregator(singletonList(ref("name", STRING)), STRING) .distinct(true)))), "unsupported distinct aggregator avg"); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/system/OpenSearchSystemIndexScanTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/system/OpenSearchSystemIndexScanTest.java index 00d1c9ecd1..afe2e0b172 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/system/OpenSearchSystemIndexScanTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/system/OpenSearchSystemIndexScanTest.java @@ -5,12 +5,12 @@ package org.opensearch.sql.opensearch.storage.system; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; import static org.opensearch.sql.data.model.ExprValueUtils.stringValue; -import java.util.Collections; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -24,7 +24,7 @@ class OpenSearchSystemIndexScanTest { @Test public void queryData() { - when(request.search()).thenReturn(Collections.singletonList(stringValue("text"))); + when(request.search()).thenReturn(singletonList(stringValue("text"))); final OpenSearchSystemIndexScan systemIndexScan = new OpenSearchSystemIndexScan(request); systemIndexScan.open(); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/utils/Utils.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/utils/Utils.java index b9e269d9ac..75e27e58da 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/utils/Utils.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/utils/Utils.java @@ -5,9 +5,10 @@ package org.opensearch.sql.opensearch.utils; +import static java.util.Collections.singletonList; + import com.google.common.collect.ImmutableSet; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Set; import lombok.experimental.UtilityClass; @@ -24,7 +25,7 @@ public class Utils { public static AvgAggregator avg(Expression expr, ExprCoreType type) { - return new AvgAggregator(Collections.singletonList(expr), type); + return new AvgAggregator(singletonList(expr), type); } public static List agg(NamedAggregator... exprs) { @@ -37,7 +38,7 @@ public static List group(NamedExpression... exprs) { public static List> sort( Expression expr1, Sort.SortOption option1) { - return Collections.singletonList(Pair.of(option1, expr1)); + return singletonList(Pair.of(option1, expr1)); } public static List> sort( diff --git a/ppl/src/main/java/org/opensearch/sql/ppl/utils/ArgumentFactory.java b/ppl/src/main/java/org/opensearch/sql/ppl/utils/ArgumentFactory.java index f89ecf9c6e..6e20d19820 100644 --- a/ppl/src/main/java/org/opensearch/sql/ppl/utils/ArgumentFactory.java +++ b/ppl/src/main/java/org/opensearch/sql/ppl/utils/ArgumentFactory.java @@ -5,6 +5,7 @@ package org.opensearch.sql.ppl.utils; +import static java.util.Collections.singletonList; import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.BooleanLiteralContext; import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.DedupCommandContext; import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.FieldsCommandContext; @@ -15,7 +16,6 @@ import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.TopCommandContext; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.antlr.v4.runtime.ParserRuleContext; import org.opensearch.sql.ast.expression.Argument; @@ -33,7 +33,7 @@ public class ArgumentFactory { * @return the list of arguments fetched from the fields command */ public static List getArgumentList(FieldsCommandContext ctx) { - return Collections.singletonList( + return singletonList( ctx.MINUS() != null ? new Argument("exclude", new Literal(true, DataType.BOOLEAN)) : new Argument("exclude", new Literal(false, DataType.BOOLEAN))); @@ -109,7 +109,7 @@ public static List getArgumentList(SortFieldContext ctx) { * @return the list of arguments fetched from the top command */ public static List getArgumentList(TopCommandContext ctx) { - return Collections.singletonList( + return singletonList( ctx.number != null ? new Argument("noOfResults", getArgumentValue(ctx.number)) : new Argument("noOfResults", new Literal(10, DataType.INTEGER))); @@ -122,8 +122,7 @@ public static List getArgumentList(TopCommandContext ctx) { * @return the list of argument with default number of results for the rare command */ public static List getArgumentList(RareCommandContext ctx) { - return Collections.singletonList( - new Argument("noOfResults", new Literal(10, DataType.INTEGER))); + return singletonList(new Argument("noOfResults", new Literal(10, DataType.INTEGER))); } /** diff --git a/ppl/src/test/java/org/opensearch/sql/ppl/utils/UnresolvedPlanHelperTest.java b/ppl/src/test/java/org/opensearch/sql/ppl/utils/UnresolvedPlanHelperTest.java index 43feabfd5f..887c655702 100644 --- a/ppl/src/test/java/org/opensearch/sql/ppl/utils/UnresolvedPlanHelperTest.java +++ b/ppl/src/test/java/org/opensearch/sql/ppl/utils/UnresolvedPlanHelperTest.java @@ -5,10 +5,10 @@ package org.opensearch.sql.ppl.utils; +import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; -import java.util.Collections; import junit.framework.TestCase; import org.hamcrest.Matchers; import org.junit.Test; @@ -47,7 +47,7 @@ public void dontAddProjectForProjectOperator() { Project project = Mockito.mock(Project.class); UnresolvedExpression expression = Mockito.mock(UnresolvedExpression.class); when(project.isExcluded()).thenReturn(false); - when(project.getProjectList()).thenReturn(Collections.singletonList(expression)); + when(project.getProjectList()).thenReturn(singletonList(expression)); UnresolvedPlan plan = UnresolvedPlanHelper.addSelectAll(project); assertTrue(plan instanceof Project); diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/client/PrometheusClientImplTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/client/PrometheusClientImplTest.java index d6ca25b206..8709cecba3 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/client/PrometheusClientImplTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/client/PrometheusClientImplTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.prometheus.client; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -18,7 +19,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -154,12 +154,12 @@ void testGetAllMetrics() { Map> expected = new HashMap<>(); expected.put( "go_gc_duration_seconds", - Collections.singletonList( + singletonList( new MetricMetadata( "summary", "A summary of the pause duration of garbage collection cycles.", ""))); expected.put( "go_goroutines", - Collections.singletonList( + singletonList( new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); assertEquals(expected, response); RecordedRequest recordedRequest = mockWebServer.takeRequest(); diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/functions/scan/QueryRangeFunctionTableScanOperatorTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/functions/scan/QueryRangeFunctionTableScanOperatorTest.java index e59a2bf7c4..6345dcb1de 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/functions/scan/QueryRangeFunctionTableScanOperatorTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/functions/scan/QueryRangeFunctionTableScanOperatorTest.java @@ -7,6 +7,7 @@ package org.opensearch.sql.prometheus.functions.scan; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -23,7 +24,6 @@ import java.io.IOException; import java.time.Instant; import java.util.ArrayList; -import java.util.Collections; import java.util.LinkedHashMap; import lombok.SneakyThrows; import org.json.JSONObject; @@ -80,11 +80,9 @@ void testQueryResponseIterator() { put( TIMESTAMP, new ExprCollectionValue( - Collections.singletonList( + singletonList( new ExprTimestampValue(Instant.ofEpochMilli(1435781430781L))))); - put( - VALUE, - new ExprCollectionValue(Collections.singletonList(new ExprDoubleValue(1)))); + put(VALUE, new ExprCollectionValue(singletonList(new ExprDoubleValue(1)))); } }); @@ -107,11 +105,9 @@ void testQueryResponseIterator() { put( TIMESTAMP, new ExprCollectionValue( - Collections.singletonList( + singletonList( new ExprTimestampValue(Instant.ofEpochMilli(1435781430781L))))); - put( - VALUE, - new ExprCollectionValue(Collections.singletonList(new ExprDoubleValue(0)))); + put(VALUE, new ExprCollectionValue(singletonList(new ExprDoubleValue(0)))); } }); assertEquals(secondRow, queryRangeFunctionTableScanOperator.next()); diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusListMetricsRequestTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusListMetricsRequestTest.java index 09f63463b5..8fff1c36d0 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusListMetricsRequestTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/request/PrometheusListMetricsRequestTest.java @@ -7,6 +7,7 @@ package org.opensearch.sql.prometheus.request; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.times; @@ -15,7 +16,6 @@ import static org.opensearch.sql.data.model.ExprValueUtils.stringValue; import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -43,12 +43,12 @@ void testSearch() { Map> metricsResult = new HashMap<>(); metricsResult.put( "go_gc_duration_seconds", - Collections.singletonList( + singletonList( new MetricMetadata( "summary", "A summary of the pause duration of garbage collection cycles.", ""))); metricsResult.put( "go_goroutines", - Collections.singletonList( + singletonList( new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); when(prometheusClient.getAllMetrics()).thenReturn(metricsResult); PrometheusListMetricsRequest prometheusListMetricsRequest = diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusMetricScanTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusMetricScanTest.java index 00ddc973bc..9b3c193250 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusMetricScanTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusMetricScanTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.prometheus.storage; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -22,7 +23,6 @@ import java.io.IOException; import java.time.Instant; -import java.util.Collections; import java.util.LinkedHashMap; import lombok.SneakyThrows; import org.json.JSONObject; @@ -187,7 +187,7 @@ void testQueryResponseIteratorWithGivenPrometheusResponseWithBackQuotedFieldName prometheusResponseFieldNames.setValueType(LONG); prometheusResponseFieldNames.setTimestampFieldName(TIMESTAMP); prometheusResponseFieldNames.setGroupByList( - Collections.singletonList(DSL.named("`instance`", DSL.ref("instance", STRING)))); + singletonList(DSL.named("`instance`", DSL.ref("instance", STRING)))); PrometheusMetricScan prometheusMetricScan = new PrometheusMetricScan(prometheusClient); prometheusMetricScan.setPrometheusResponseFieldNames(prometheusResponseFieldNames); prometheusMetricScan.getRequest().setPromQl(QUERY); diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java index 7b1e2dec0f..e41b0a321e 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/PrometheusStorageFactoryTest.java @@ -7,9 +7,10 @@ package org.opensearch.sql.prometheus.storage; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.mockito.Mockito.when; -import java.util.Collections; import java.util.HashMap; import lombok.SneakyThrows; import org.apache.commons.lang3.RandomStringUtils; @@ -40,7 +41,7 @@ void testGetConnectorType() { @SneakyThrows void testGetStorageEngineWithBasicAuth() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.emptyList()); + .thenReturn(emptyList()); PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); @@ -55,7 +56,7 @@ void testGetStorageEngineWithBasicAuth() { @SneakyThrows void testGetStorageEngineWithAWSSigV4Auth() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.emptyList()); + .thenReturn(emptyList()); PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); @@ -127,7 +128,7 @@ void testGetStorageEngineWithLongConfigProperties() { @SneakyThrows void testGetStorageEngineWithWrongAuthType() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.emptyList()); + .thenReturn(emptyList()); PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "https://test.com"); @@ -147,7 +148,7 @@ void testGetStorageEngineWithWrongAuthType() { @SneakyThrows void testGetStorageEngineWithNONEAuthType() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.emptyList()); + .thenReturn(emptyList()); PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory(settings); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "https://test.com"); @@ -174,7 +175,7 @@ void testGetStorageEngineWithInvalidURISyntax() { @Test void createDataSourceSuccess() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.emptyList()); + .thenReturn(emptyList()); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); properties.put("prometheus.auth.type", "basicauth"); @@ -195,7 +196,7 @@ void createDataSourceSuccess() { @Test void createDataSourceSuccessWithLocalhost() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.emptyList()); + .thenReturn(emptyList()); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); properties.put("prometheus.auth.type", "basicauth"); @@ -216,7 +217,7 @@ void createDataSourceSuccessWithLocalhost() { @Test void createDataSourceWithHostnameNotMatchingWithAllowHostsConfig() { when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) - .thenReturn(Collections.singletonList("127.0.0.0/8")); + .thenReturn(singletonList("127.0.0.0/8")); HashMap properties = new HashMap<>(); properties.put("prometheus.uri", "http://localhost:9090"); properties.put("prometheus.auth.type", "basicauth"); diff --git a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTableScanTest.java b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTableScanTest.java index ea299b87de..e988a481a0 100644 --- a/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTableScanTest.java +++ b/prometheus/src/test/java/org/opensearch/sql/prometheus/storage/system/PrometheusSystemTableScanTest.java @@ -7,12 +7,12 @@ package org.opensearch.sql.prometheus.storage.system; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; import static org.opensearch.sql.data.model.ExprValueUtils.stringValue; -import java.util.Collections; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -26,7 +26,7 @@ public class PrometheusSystemTableScanTest { @Test public void queryData() { - when(request.search()).thenReturn(Collections.singletonList(stringValue("text"))); + when(request.search()).thenReturn(singletonList(stringValue("text"))); final PrometheusSystemTableScan systemIndexScan = new PrometheusSystemTableScan(request); systemIndexScan.open(); diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java index fc3402e20a..af03429bac 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java @@ -5,6 +5,8 @@ package org.opensearch.sql.protocol.response; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -15,7 +17,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Arrays; -import java.util.Collections; import org.junit.jupiter.api.Test; import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.executor.pagination.Cursor; @@ -46,7 +47,7 @@ void columnNameTypes() { QueryResult response = new QueryResult( schema, - Collections.singletonList(tupleValue(ImmutableMap.of("name", "John", "age", 20))), + singletonList(tupleValue(ImmutableMap.of("name", "John", "age", 20))), Cursor.None); assertEquals(ImmutableMap.of("name", "string", "age", "integer"), response.columnNameTypes()); @@ -59,16 +60,14 @@ void columnNameTypesWithAlias() { ImmutableList.of(new ExecutionEngine.Schema.Column("name", "n", STRING))); QueryResult response = new QueryResult( - schema, - Collections.singletonList(tupleValue(ImmutableMap.of("n", "John"))), - Cursor.None); + schema, singletonList(tupleValue(ImmutableMap.of("n", "John"))), Cursor.None); assertEquals(ImmutableMap.of("n", "string"), response.columnNameTypes()); } @Test void columnNameTypesFromEmptyExprValues() { - QueryResult response = new QueryResult(schema, Collections.emptyList(), Cursor.None); + QueryResult response = new QueryResult(schema, emptyList(), Cursor.None); assertEquals(ImmutableMap.of("name", "string", "age", "integer"), response.columnNameTypes()); } diff --git a/spark/src/main/java/org/opensearch/sql/spark/storage/SparkStorageEngine.java b/spark/src/main/java/org/opensearch/sql/spark/storage/SparkStorageEngine.java index 84c9c05e79..11d638457c 100644 --- a/spark/src/main/java/org/opensearch/sql/spark/storage/SparkStorageEngine.java +++ b/spark/src/main/java/org/opensearch/sql/spark/storage/SparkStorageEngine.java @@ -5,8 +5,9 @@ package org.opensearch.sql.spark.storage; +import static java.util.Collections.singletonList; + import java.util.Collection; -import java.util.Collections; import lombok.RequiredArgsConstructor; import org.opensearch.sql.DataSourceSchemaName; import org.opensearch.sql.expression.function.FunctionResolver; @@ -22,7 +23,7 @@ public class SparkStorageEngine implements StorageEngine { @Override public Collection getFunctions() { - return Collections.singletonList(new SparkSqlTableFunctionResolver(sparkClient)); + return singletonList(new SparkSqlTableFunctionResolver(sparkClient)); } @Override diff --git a/sql/src/main/java/org/opensearch/sql/sql/parser/AstBuilder.java b/sql/src/main/java/org/opensearch/sql/sql/parser/AstBuilder.java index ab96f16263..8b4f331d77 100644 --- a/sql/src/main/java/org/opensearch/sql/sql/parser/AstBuilder.java +++ b/sql/src/main/java/org/opensearch/sql/sql/parser/AstBuilder.java @@ -6,6 +6,7 @@ package org.opensearch.sql.sql.parser; import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.opensearch.sql.ast.dsl.AstDSL.qualifiedName; import static org.opensearch.sql.sql.antlr.parser.OpenSearchSQLParser.FromClauseContext; import static org.opensearch.sql.sql.antlr.parser.OpenSearchSQLParser.HavingClauseContext; @@ -19,7 +20,6 @@ import static org.opensearch.sql.utils.SystemIndexUtils.mappingTable; import com.google.common.collect.ImmutableList; -import java.util.Collections; import java.util.Optional; import lombok.RequiredArgsConstructor; import org.antlr.v4.runtime.tree.ParseTree; @@ -60,7 +60,7 @@ public class AstBuilder extends OpenSearchSQLParserBaseVisitor { @Override public UnresolvedPlan visitShowStatement(OpenSearchSQLParser.ShowStatementContext ctx) { final UnresolvedExpression tableFilter = visitAstExpression(ctx.tableFilter()); - return new Project(Collections.singletonList(AllFields.of())) + return new Project(singletonList(AllFields.of())) .attach(new Filter(tableFilter).attach(new Relation(qualifiedName(TABLE_INFO)))); } @@ -70,9 +70,9 @@ public UnresolvedPlan visitDescribeStatement(OpenSearchSQLParser.DescribeStateme final String tableName = tableFilter.getFuncArgs().get(1).toString(); final Relation table = new Relation(qualifiedName(mappingTable(tableName.toString()))); if (ctx.columnFilter() == null) { - return new Project(Collections.singletonList(AllFields.of())).attach(table); + return new Project(singletonList(AllFields.of())).attach(table); } else { - return new Project(Collections.singletonList(AllFields.of())) + return new Project(singletonList(AllFields.of())) .attach(new Filter(visitAstExpression(ctx.columnFilter())).attach(table)); } } diff --git a/sql/src/main/java/org/opensearch/sql/sql/parser/AstExpressionBuilder.java b/sql/src/main/java/org/opensearch/sql/sql/parser/AstExpressionBuilder.java index 5bdbfb4e38..eb76875f16 100644 --- a/sql/src/main/java/org/opensearch/sql/sql/parser/AstExpressionBuilder.java +++ b/sql/src/main/java/org/opensearch/sql/sql/parser/AstExpressionBuilder.java @@ -5,6 +5,7 @@ package org.opensearch.sql.sql.parser; +import static java.util.Collections.singletonList; import static org.opensearch.sql.ast.dsl.AstDSL.between; import static org.opensearch.sql.ast.dsl.AstDSL.not; import static org.opensearch.sql.ast.dsl.AstDSL.qualifiedName; @@ -108,7 +109,7 @@ public UnresolvedExpression visitColumnName(ColumnNameContext ctx) { @Override public UnresolvedExpression visitIdent(IdentContext ctx) { - return visitIdentifiers(Collections.singletonList(ctx)); + return visitIdentifiers(singletonList(ctx)); } @Override @@ -252,7 +253,7 @@ public UnresolvedExpression visitIsNullPredicate(IsNullPredicateContext ctx) { ctx.nullNotnull().NOT() == null ? IS_NULL.getName().getFunctionName() : IS_NOT_NULL.getName().getFunctionName(), - Collections.singletonList(visit(ctx.predicate()))); + singletonList(visit(ctx.predicate()))); } @Override