From 8bb0f8797a12a5e2138a9794c0a3053faf90dcab Mon Sep 17 00:00:00 2001 From: currantw Date: Mon, 9 Dec 2024 14:55:46 -0800 Subject: [PATCH] More replacement of `Collections.singletonList`, `emptyList`, and `emptyMap` with `List.of`/`Map.of` in cases where `List`/`Map` is already imported. Signed-off-by: currantw --- .../cluster/ClusterManagerEventListener.java | 3 +- .../sql/analysis/ExpressionAnalyzer.java | 3 +- .../analysis/SelectExpressionAnalyzer.java | 7 +- .../sql/analysis/symbol/SymbolTable.java | 3 +- .../opensearch/sql/ast/expression/Cast.java | 3 +- .../sql/ast/expression/QualifiedName.java | 3 +- .../org/opensearch/sql/ast/tree/Relation.java | 4 +- .../sql/expression/function/FunctionDSL.java | 10 +- .../sql/planner/logical/LogicalNested.java | 3 +- .../sql/planner/logical/LogicalWrite.java | 3 +- .../planner/physical/AggregationOperator.java | 4 +- .../sql/planner/physical/DedupeOperator.java | 4 +- .../sql/planner/physical/EvalOperator.java | 3 +- .../sql/planner/physical/ProjectOperator.java | 4 +- .../planner/physical/RareTopNOperator.java | 4 +- .../sql/planner/physical/RemoveOperator.java | 3 +- .../sql/planner/physical/RenameOperator.java | 3 +- .../sql/planner/physical/SortOperator.java | 4 +- .../planner/physical/TakeOrderedOperator.java | 4 +- .../sql/planner/physical/WindowOperator.java | 4 +- .../physical/collector/MetricCollector.java | 4 +- .../assigner/TumblingWindowAssigner.java | 4 +- .../opensearch/sql/analysis/AnalyzerTest.java | 56 ++++---- .../sql/analysis/AnalyzerTestBase.java | 3 +- .../sql/analysis/ExpressionAnalyzerTest.java | 6 +- .../expression/ExpressionNodeVisitorTest.java | 3 +- .../BuiltinFunctionRepositoryTest.java | 19 ++- .../sql/planner/DefaultImplementorTest.java | 17 +-- .../physical/AggregationOperatorTest.java | 127 ++++++++---------- .../physical/PhysicalPlanNodeVisitorTest.java | 5 +- .../physical/RareTopNOperatorTest.java | 22 ++- .../planner/physical/RenameOperatorTest.java | 5 +- .../service/DataSourceServiceImplTest.java | 36 +++-- ...enSearchDataSourceMetadataStorageTest.java | 14 +- .../sql/correctness/tests/DBResultTest.java | 19 ++- .../sql/correctness/tests/TestConfigTest.java | 3 +- .../sql/legacy/PrettyFormatResponseIT.java | 11 +- .../antlr/semantic/scope/SymbolTable.java | 3 +- .../visitor/AntlrSqlParseTreeVisitor.java | 5 +- .../legacy/esdomain/mapping/FieldMapping.java | 3 +- .../esdomain/mapping/IndexMappings.java | 4 +- .../physical/node/join/JoinAlgorithm.java | 4 +- .../planner/physical/node/sort/QuickSort.java | 4 +- .../legacy/antlr/SymbolSimilarityTest.java | 7 +- .../esdomain/mapping/FieldMappingTest.java | 7 +- .../executor/AsyncRestExecutorTest.java | 3 +- .../unittest/planner/QueryPlannerTest.java | 3 +- .../sql/legacy/util/CheckScriptContents.java | 3 +- .../planner/physical/ADOperator.java | 3 +- .../planner/physical/MLCommonsOperator.java | 3 +- .../planner/physical/MLOperator.java | 4 +- .../agg/NoBucketAggregationParser.java | 4 +- .../aggregation/AggregationQueryBuilder.java | 4 +- .../script/filter/FilterQueryBuilder.java | 3 +- .../OpenSearchExecutionProtectorTest.java | 27 ++-- .../response/OpenSearchResponseTest.java | 3 +- .../OpenSearchIndexScanOptimizationTest.java | 10 +- .../AggregationQueryBuilderTest.java | 12 +- .../ExpressionAggregationScriptTest.java | 3 +- .../dsl/MetricAggregationBuilderTest.java | 19 ++- .../filter/ExpressionFilterScriptTest.java | 9 +- .../sql/opensearch/utils/Utils.java | 6 +- .../org/opensearch/sql/plugin/SQLPlugin.java | 3 +- .../sql/ppl/utils/ArgumentFactory.java | 7 +- .../ppl/parser/AstExpressionBuilderTest.java | 39 +++--- .../client/PrometheusClientImplTest.java | 6 +- .../PrometheusListMetricsRequestTest.java | 6 +- .../sql/sql/parser/AstAggregationBuilder.java | 6 +- .../sql/sql/parser/AstExpressionBuilder.java | 5 +- .../sql/parser/AstAggregationBuilderTest.java | 3 +- 70 files changed, 268 insertions(+), 396 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 69be1a3fc7..eb83afdf7b 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,7 +5,6 @@ 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; @@ -183,7 +182,7 @@ private void cancel(Cancellable cron) { @VisibleForTesting public List getFlintIndexRetentionCron() { - return singletonList(flintIndexRetentionCron); + return List.of(flintIndexRetentionCron); } private String executorName() { 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 370dd881c7..bef62fa408 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java @@ -5,7 +5,6 @@ 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; @@ -83,7 +82,7 @@ public Expression visitCast(Cast node, AnalysisContext context) { final Expression expression = node.getExpression().accept(this, context); return (Expression) repository.compile( - context.getFunctionProperties(), node.convertFunctionName(), singletonList(expression)); + context.getFunctionProperties(), node.convertFunctionName(), List.of(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 2abbb6d96f..d296ad6573 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,6 @@ package org.opensearch.sql.analysis; -import static java.util.Collections.singletonList; - import com.google.common.collect.ImmutableList; import java.util.List; import java.util.Map; @@ -55,7 +53,7 @@ public List analyze( @Override public List visitField(Field node, AnalysisContext context) { - return singletonList(DSL.named(node.accept(expressionAnalyzer, context))); + return List.of(DSL.named(node.accept(expressionAnalyzer, context))); } @Override @@ -66,8 +64,7 @@ public List visitAlias(Alias node, AnalysisContext context) { } Expression expr = referenceIfSymbolDefined(node, context); - return singletonList( - DSL.named(unqualifiedNameIfFieldOnly(node, context), expr, node.getAlias())); + return List.of(DSL.named(unqualifiedNameIfFieldOnly(node, context), expr, node.getAlias())); } /** diff --git a/core/src/main/java/org/opensearch/sql/analysis/symbol/SymbolTable.java b/core/src/main/java/org/opensearch/sql/analysis/symbol/SymbolTable.java index 64a4fc4e09..e2913a0e4e 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/symbol/SymbolTable.java +++ b/core/src/main/java/org/opensearch/sql/analysis/symbol/SymbolTable.java @@ -5,7 +5,6 @@ package org.opensearch.sql.analysis.symbol; -import static java.util.Collections.emptyMap; import static java.util.Collections.emptyNavigableMap; import java.util.EnumMap; @@ -88,7 +87,7 @@ public Map lookupByPrefix(Symbol prefix) { if (table != null) { return table.subMap(prefix.getName(), prefix.getName() + Character.MAX_VALUE); } - return emptyMap(); + return Map.of(); } /** 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 b922198028..77719b000b 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,7 +5,6 @@ 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; @@ -99,7 +98,7 @@ public FunctionName convertFunctionName() { @Override public List getChild() { - return singletonList(expression); + return List.of(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 09789d8ca2..c105dfb762 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,7 +5,6 @@ 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; @@ -25,7 +24,7 @@ public class QualifiedName extends UnresolvedExpression { private final List parts; public QualifiedName(String name) { - this.parts = singletonList(name); + this.parts = List.of(name); } /** QualifiedName Constructor. */ 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 09faca70fb..0256ae4124 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,6 @@ package org.opensearch.sql.ast.tree; -import static java.util.Collections.singletonList; - import com.google.common.collect.ImmutableList; import java.util.List; import java.util.stream.Collectors; @@ -33,7 +31,7 @@ public Relation(UnresolvedExpression tableName) { } public Relation(UnresolvedExpression tableName, String alias) { - this.tableName = singletonList(tableName); + this.tableName = List.of(tableName); this.alias = alias; } 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 f8a8d4773d..670a086f7e 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,9 +5,6 @@ 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.List; import java.util.function.Function; @@ -70,10 +67,10 @@ public static DefaultFunctionResolver define( implWithProperties( SerializableFunction function, ExprType returnType) { return functionName -> { - FunctionSignature functionSignature = new FunctionSignature(functionName, emptyList()); + FunctionSignature functionSignature = new FunctionSignature(functionName, List.of()); FunctionBuilder functionBuilder = (functionProperties, arguments) -> - new FunctionExpression(functionName, emptyList()) { + new FunctionExpression(functionName, List.of()) { @Override public ExprValue valueOf(Environment valueEnv) { return function.apply(functionProperties); @@ -109,8 +106,7 @@ public String toString() { ExprType argsType) { return functionName -> { - FunctionSignature functionSignature = - new FunctionSignature(functionName, singletonList(argsType)); + FunctionSignature functionSignature = new FunctionSignature(functionName, List.of(argsType)); FunctionBuilder functionBuilder = (functionProperties, arguments) -> new FunctionExpression(functionName, 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 91eae51599..089efe707e 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,6 +5,7 @@ package org.opensearch.sql.planner.logical; +import java.util.Collections; import java.util.List; import java.util.Map; import lombok.EqualsAndHashCode; @@ -26,7 +27,7 @@ public LogicalNested( LogicalPlan childPlan, List> fields, List projectList) { - super(List.of(childPlan)); + super(Collections.singletonList(childPlan)); this.fields = fields; this.projectList = projectList; } 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 76d75972d8..a253739a68 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,6 +5,7 @@ package org.opensearch.sql.planner.logical; +import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -25,7 +26,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(List.of(child)); + super(Collections.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 9103c3e4a6..c853788501 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,8 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; - import java.util.Iterator; import java.util.List; import lombok.EqualsAndHashCode; @@ -60,7 +58,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(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 816ada3b10..73a2fb5aa1 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,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; - import com.google.common.collect.ImmutableList; import java.util.List; import java.util.Map; @@ -79,7 +77,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(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 e458b20211..14c9e4e8a6 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,7 +5,6 @@ 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; @@ -50,7 +49,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(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 ccde753530..84e7c833eb 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,8 +5,6 @@ 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; @@ -43,7 +41,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(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 dac850ba3b..c1c6a122a2 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,8 +5,6 @@ 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; @@ -85,7 +83,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(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 23a562aca8..bd2b2c91fc 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,7 +5,6 @@ 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; @@ -49,7 +48,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(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 7195d15106..1039646563 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,7 +5,6 @@ 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; @@ -56,7 +55,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(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 1a5887374b..468ebf9b31 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,8 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; - import java.util.Comparator; import java.util.Iterator; import java.util.List; @@ -64,7 +62,7 @@ public void open() { @Override public List getChild() { - return singletonList(input); + return List.of(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 27813450b7..97d31cb4d4 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,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.singletonList; - import com.google.common.collect.Ordering; import java.util.Iterator; import java.util.List; @@ -74,7 +72,7 @@ public void open() { @Override public List getChild() { - return singletonList(input); + return List.of(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 eb962cb537..16f76b776f 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,8 +5,6 @@ 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; @@ -63,7 +61,7 @@ public R accept(PhysicalPlanNodeVisitor visitor, C context) { @Override public List getChild() { - return singletonList(input); + return List.of(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 36455bf32c..5307947df7 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,6 @@ package org.opensearch.sql.planner.physical.collector; -import static java.util.Collections.singletonList; - import java.util.AbstractMap; import java.util.LinkedHashMap; import java.util.List; @@ -58,6 +56,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 singletonList(ExprTupleValue.fromExprValueMap(map)); + return List.of(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 504fad9f30..9a003303a7 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,6 @@ package org.opensearch.sql.planner.streaming.windowing.assigner; -import static java.util.Collections.singletonList; - import com.google.common.base.Preconditions; import java.util.List; import org.opensearch.sql.planner.streaming.windowing.Window; @@ -32,6 +30,6 @@ public TumblingWindowAssigner(long windowSize) { @Override public List assign(long timestamp) { long startTime = DateTimeUtils.getWindowStartTime(timestamp, windowSize); - return singletonList(new Window(startTime, startTime + windowSize)); + return List.of(new Window(startTime, startTime + windowSize)); } } 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 53a5a28152..56e2f6f704 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java @@ -5,8 +5,6 @@ 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; @@ -408,9 +406,9 @@ public void analyze_filter_aggregation_relation() { ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value"))), alias("MIN(integer_value)", aggregate("MIN", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of(alias("string_value", qualifiedName("string_value"))), - emptyList()), + List.of()), compare(">", aggregate("MIN", qualifiedName("integer_value")), intLiteral(10)))); } @@ -491,7 +489,7 @@ public void rename_to_invalid_expression() { AstDSL.alias( "avg(integer_value)", AstDSL.aggregate("avg", field("integer_value")))), - emptyList(), + List.of(), ImmutableList.of(), AstDSL.defaultStatsArgs()), AstDSL.map( @@ -894,7 +892,7 @@ public void remove_source() { DSL.ref("double_value", DOUBLE)), AstDSL.projectWithArg( AstDSL.relation("schema"), - singletonList(argument("exclude", booleanLiteral(true))), + List.of(argument("exclude", booleanLiteral(true))), AstDSL.field("integer_value"), AstDSL.field("double_value"))); } @@ -956,9 +954,9 @@ public void sort_with_aggregator() { ImmutableList.of( AstDSL.alias( "avg(integer_value)", function("avg", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of(AstDSL.alias("string_value", qualifiedName("string_value"))), - emptyList()), + List.of()), field( function("avg", qualifiedName("integer_value")), argument("asc", booleanLiteral(true)))), @@ -1041,8 +1039,8 @@ public void window_function() { "window_function", AstDSL.window( AstDSL.function("row_number"), - singletonList(AstDSL.qualifiedName("string_value")), - singletonList( + List.of(AstDSL.qualifiedName("string_value")), + List.of( ImmutablePair.of(DEFAULT_ASC, AstDSL.qualifiedName("integer_value"))))))); } @@ -1098,13 +1096,13 @@ public void nested_group_by_clause_throws_syntax_exception() { AstDSL.project( AstDSL.agg( AstDSL.relation("schema"), - emptyList(), - emptyList(), + List.of(), + List.of(), ImmutableList.of( alias( "nested(message.info)", function("nested", qualifiedName("message", "info")))), - emptyList())))); + List.of())))); assertEquals( "Falling back to legacy engine. Nested function is not supported in WHERE," + " GROUP BY, and HAVING clauses.", @@ -1128,9 +1126,9 @@ public void sql_group_by_field() { AstDSL.relation("schema"), ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of(alias("string_value", qualifiedName("string_value"))), - emptyList()), + List.of()), AstDSL.alias("string_value", qualifiedName("string_value")), AstDSL.alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value"))))); } @@ -1153,10 +1151,10 @@ public void sql_group_by_function() { AstDSL.relation("schema"), ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of( alias("abs(long_value)", function("abs", qualifiedName("long_value")))), - emptyList()), + List.of()), AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))), AstDSL.alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value"))))); } @@ -1179,10 +1177,10 @@ public void sql_group_by_function_in_uppercase() { AstDSL.relation("schema"), ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of( alias("ABS(long_value)", function("ABS", qualifiedName("long_value")))), - emptyList()), + List.of()), AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))), AstDSL.alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value"))))); } @@ -1205,10 +1203,10 @@ public void sql_expression_over_one_aggregation() { AstDSL.relation("schema"), ImmutableList.of( alias("avg(integer_value)", aggregate("avg", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of( alias("abs(long_value)", function("abs", qualifiedName("long_value")))), - emptyList()), + List.of()), AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))), AstDSL.alias( "abs(avg(integer_value)", @@ -1239,10 +1237,10 @@ public void sql_expression_over_two_aggregation() { ImmutableList.of( alias("sum(integer_value)", aggregate("sum", qualifiedName("integer_value"))), alias("avg(integer_value)", aggregate("avg", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of( alias("abs(long_value)", function("abs", qualifiedName("long_value")))), - emptyList()), + List.of()), AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))), AstDSL.alias( "sum(integer_value)-avg(integer_value)", @@ -1280,7 +1278,7 @@ public void named_aggregator_with_condition() { DSL.count(DSL.ref("string_value", STRING)) .condition( DSL.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))))), - emptyList()), + List.of()), DSL.named( "count(string_value) filter(where integer_value > 1)", DSL.ref("count(string_value) filter(where integer_value > 1)", INTEGER))), @@ -1294,9 +1292,9 @@ public void named_aggregator_with_condition() { "count", qualifiedName("string_value"), function(">", qualifiedName("integer_value"), intLiteral(1))))), - emptyList(), - emptyList(), - emptyList()), + List.of(), + List.of(), + List.of()), AstDSL.alias( "count(string_value) filter(where integer_value > 1)", filteredAggregate( @@ -1320,10 +1318,10 @@ public void ppl_stats_by_fieldAndSpan() { AstDSL.relation("schema"), ImmutableList.of( alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))), - emptyList(), + List.of(), ImmutableList.of(alias("string_value", qualifiedName("string_value"))), alias("span", span(field("long_value"), intLiteral(10), SpanUnit.NONE)), - emptyList())); + List.of())); } @Test 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 c0ff667efc..3548cffef5 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTestBase.java @@ -5,7 +5,6 @@ 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; @@ -61,7 +60,7 @@ protected StorageEngine prometheusStorageEngine() { return new StorageEngine() { @Override public Collection getFunctions() { - return singletonList( + return List.of( new FunctionResolver() { @Override diff --git a/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java index b27b8348e2..8a7adff3fd 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.analysis; -import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -173,8 +172,7 @@ public void case_with_default_result_type_different() { @Test public void scalar_window_function() { - assertAnalyzeEqual( - DSL.rank(), AstDSL.window(AstDSL.function("rank"), emptyList(), emptyList())); + assertAnalyzeEqual(DSL.rank(), AstDSL.window(AstDSL.function("rank"), List.of(), List.of())); } @SuppressWarnings("unchecked") @@ -183,7 +181,7 @@ public void aggregate_window_function() { assertAnalyzeEqual( new AggregateWindowFunction(DSL.avg(DSL.ref("integer_value", INTEGER))), AstDSL.window( - AstDSL.aggregate("avg", qualifiedName("integer_value")), emptyList(), emptyList())); + AstDSL.aggregate("avg", qualifiedName("integer_value")), List.of(), List.of())); } @Test 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 3300ca374e..d77f484248 100644 --- a/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/ExpressionNodeVisitorTest.java @@ -5,7 +5,6 @@ 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; @@ -38,7 +37,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(singletonList(ref("age", INTEGER)), INTEGER)) + named("avg", new AvgAggregator(List.of(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 17f63d7215..1ddf53a8b9 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,8 +5,6 @@ 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; @@ -98,7 +96,7 @@ void compile_datasource_defined_function() { repo.compile( functionProperties, - singletonList(dataSourceFunctionResolver), + List.of(dataSourceFunctionResolver), mockFunctionName, List.of(mockExpression)); verify(functionExpressionBuilder, times(1)).apply(eq(functionProperties), any()); @@ -116,7 +114,7 @@ void resolve() { BuiltinFunctionRepository repo = new BuiltinFunctionRepository(mockMap); repo.register(mockfunctionResolver); - assertEquals(functionExpressionBuilder, repo.resolve(emptyList(), functionSignature)); + assertEquals(functionExpressionBuilder, repo.resolve(List.of(), functionSignature)); } @Test @@ -124,8 +122,7 @@ void resolve_should_not_cast_arguments_in_cast_function() { when(mockExpression.toString()).thenReturn("string"); FunctionImplementation function = repo.resolve( - emptyList(), - registerFunctionResolver(CAST_TO_BOOLEAN.getName(), TIMESTAMP, BOOLEAN)) + List.of(), registerFunctionResolver(CAST_TO_BOOLEAN.getName(), TIMESTAMP, BOOLEAN)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("cast_to_boolean(string)", function.toString()); } @@ -135,7 +132,7 @@ void resolve_should_not_cast_arguments_if_same_type() { when(mockFunctionName.getFunctionName()).thenReturn("mock"); when(mockExpression.toString()).thenReturn("string"); FunctionImplementation function = - repo.resolve(emptyList(), registerFunctionResolver(mockFunctionName, STRING, STRING)) + repo.resolve(List.of(), registerFunctionResolver(mockFunctionName, STRING, STRING)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(string)", function.toString()); } @@ -145,7 +142,7 @@ void resolve_should_not_cast_arguments_if_both_numbers() { when(mockFunctionName.getFunctionName()).thenReturn("mock"); when(mockExpression.toString()).thenReturn("byte"); FunctionImplementation function = - repo.resolve(emptyList(), registerFunctionResolver(mockFunctionName, BYTE, INTEGER)) + repo.resolve(List.of(), registerFunctionResolver(mockFunctionName, BYTE, INTEGER)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(byte)", function.toString()); } @@ -160,7 +157,7 @@ void resolve_should_cast_arguments() { registerFunctionResolver(CAST_TO_BOOLEAN.getName(), STRING, STRING); FunctionImplementation function = - repo.resolve(emptyList(), signature) + repo.resolve(List.of(), signature) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("mock(cast_to_boolean(string))", function.toString()); } @@ -171,7 +168,7 @@ void resolve_should_throw_exception_for_unsupported_conversion() { assertThrows( ExpressionEvaluationException.class, () -> - repo.resolve(emptyList(), registerFunctionResolver(mockFunctionName, BYTE, STRUCT)) + repo.resolve(List.of(), registerFunctionResolver(mockFunctionName, BYTE, STRUCT)) .apply(functionProperties, ImmutableList.of(mockExpression))); assertEquals(error.getMessage(), "Type conversion to type STRUCT is not supported"); } @@ -188,7 +185,7 @@ void resolve_unregistered() { ExpressionEvaluationException.class, () -> repo.resolve( - emptyList(), new FunctionSignature(FunctionName.of("unknown"), List.of()))); + List.of(), 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 a58773fae4..7174088152 100644 --- a/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/DefaultImplementorTest.java @@ -5,8 +5,6 @@ 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; @@ -127,7 +125,7 @@ public void visit_should_return_default_physical_operator() { remove( rename( aggregation( - filter(values(emptyList()), filterExpr), + filter(values(List.of()), filterExpr), aggregators, groupByExprs), mappings), @@ -158,8 +156,7 @@ public void visit_should_return_default_physical_operator() { PhysicalPlanDSL.rename( PhysicalPlanDSL.agg( PhysicalPlanDSL.filter( - PhysicalPlanDSL.values(emptyList()), - filterExpr), + PhysicalPlanDSL.values(List.of()), filterExpr), aggregators, groupByExprs), mappings), @@ -191,8 +188,8 @@ public void visitWindowOperator_should_return_PhysicalWindowOperator() { NamedExpression windowFunction = named(new RowNumberFunction()); WindowDefinition windowDefinition = new WindowDefinition( - singletonList(ref("state", STRING)), - singletonList(ImmutablePair.of(Sort.SortOption.DEFAULT_DESC, ref("age", INTEGER)))); + List.of(ref("state", STRING)), + List.of(ImmutablePair.of(Sort.SortOption.DEFAULT_DESC, ref("age", INTEGER)))); NamedExpression[] projectList = { named("state", ref("state", STRING)), named("row_number", ref("row_number", INTEGER)) @@ -282,11 +279,11 @@ public void visitLimit_support_return_takeOrdered() { // replace SortOperator + LimitOperator with TakeOrderedOperator Pair sort = ImmutablePair.of(Sort.SortOption.DEFAULT_ASC, ref("a", INTEGER)); - var logicalValues = values(emptyList()); + var logicalValues = values(List.of()); var logicalSort = sort(logicalValues, sort); var logicalLimit = limit(logicalSort, 10, 5); PhysicalPlan physicalPlanTree = - PhysicalPlanDSL.takeOrdered(PhysicalPlanDSL.values(emptyList()), 10, 5, sort); + PhysicalPlanDSL.takeOrdered(PhysicalPlanDSL.values(List.of()), 10, 5, sort); assertEquals(physicalPlanTree, logicalLimit.accept(implementor, null)); // don't replace if LimitOperator's child is not SortOperator @@ -297,7 +294,7 @@ public void visitLimit_support_return_takeOrdered() { physicalPlanTree = PhysicalPlanDSL.limit( PhysicalPlanDSL.eval( - PhysicalPlanDSL.sort(PhysicalPlanDSL.values(emptyList()), sort), newEvalField), + PhysicalPlanDSL.sort(PhysicalPlanDSL.values(List.of()), sort), newEvalField), 10, 5); assertEquals(physicalPlanTree, logicalLimit.accept(implementor, null)); 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 d454469ba2..faca949df0 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,8 +5,6 @@ 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; @@ -39,8 +37,8 @@ public void sum_without_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - singletonList(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), - emptyList()); + List.of(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), + List.of()); List result = execute(plan); assertEquals(1, result.size()); assertThat( @@ -53,8 +51,8 @@ public void avg_with_one_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), - singletonList(DSL.named("action", DSL.ref("action", STRING)))); + List.of(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + List.of(DSL.named("action", DSL.ref("action", STRING)))); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -69,7 +67,7 @@ public void avg_with_two_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + List.of(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)))); @@ -91,8 +89,8 @@ public void sum_with_one_groups() { PhysicalPlan plan = new AggregationOperator( new TestScan(), - singletonList(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), - singletonList(DSL.named("action", DSL.ref("action", STRING)))); + List.of(DSL.named("sum(response)", DSL.sum(DSL.ref("response", INTEGER)))), + List.of(DSL.named("action", DSL.ref("action", STRING)))); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -107,8 +105,8 @@ public void millisecond_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + List.of( DSL.named( "span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6 * 1000), "ms")))); List result = execute(plan); @@ -128,8 +126,8 @@ public void second_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + List.of( DSL.named("span", DSL.span(DSL.ref("second", TIMESTAMP), DSL.literal(6), "s")))); List result = execute(plan); assertEquals(2, result.size()); @@ -148,8 +146,8 @@ public void minute_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("minute", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("minute", TIMESTAMP)))), + List.of( DSL.named("span", DSL.span(DSL.ref("minute", TIMESTAMP), DSL.literal(5), "m")))); List result = execute(plan); assertEquals(3, result.size()); @@ -167,9 +165,8 @@ public void minute_span() { plan = new AggregationOperator( testScan(datetimeInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(30), "m")))); + List.of(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), + List.of(DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(30), "m")))); result = execute(plan); assertEquals(4, result.size()); assertThat( @@ -190,8 +187,8 @@ public void hour_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - 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.of(DSL.named("count", DSL.count(DSL.ref("hour", TIME)))), + List.of(DSL.named("span", DSL.span(DSL.ref("hour", TIME), DSL.literal(1), "h")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -210,8 +207,8 @@ public void day_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - 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.of(DSL.named("count(day)", DSL.count(DSL.ref("day", DATE)))), + List.of(DSL.named("span", DSL.span(DSL.ref("day", DATE), DSL.literal(1), "d")))); List result = execute(plan); assertEquals(4, result.size()); assertThat( @@ -229,9 +226,8 @@ public void day_span() { plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(30), "d")))); + List.of(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), + List.of(DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(30), "d")))); result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -250,9 +246,8 @@ public void week_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - 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.of(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), + List.of(DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(5), "w")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -271,9 +266,8 @@ public void month_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - 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.of(DSL.named("count", DSL.count(DSL.ref("month", DATE)))), + List.of(DSL.named("span", DSL.span(DSL.ref("month", DATE), DSL.literal(1), "M")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -289,8 +283,8 @@ public void month_span() { plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), + List.of( DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "M")))); result = execute(plan); assertEquals(4, result.size()); @@ -310,8 +304,8 @@ public void month_span() { plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), + List.of( DSL.named( "span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10 * 12), "M")))); result = execute(plan); @@ -333,8 +327,8 @@ public void quarter_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), + List.of( DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "q")))); List result = execute(plan); assertEquals(2, result.size()); @@ -350,8 +344,8 @@ public void quarter_span() { plan = new AggregationOperator( testScan(dateInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), + List.of( DSL.named("span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10 * 4), "q")))); result = execute(plan); assertEquals(3, result.size()); @@ -372,9 +366,8 @@ public void year_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - 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.of(DSL.named("count", DSL.count(DSL.ref("year", TIMESTAMP)))), + List.of(DSL.named("span", DSL.span(DSL.ref("year", TIMESTAMP), DSL.literal(10), "y")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -394,9 +387,8 @@ public void integer_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("integer", INTEGER), DSL.literal(1), "")))); + List.of(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), + List.of(DSL.named("span", DSL.span(DSL.ref("integer", INTEGER), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -409,8 +401,8 @@ public void integer_field() { plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("integer", INTEGER)))), + List.of( DSL.named("span", DSL.span(DSL.ref("integer", INTEGER), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); @@ -427,8 +419,8 @@ public void long_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), - singletonList(DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1), "")))); + List.of(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), + List.of(DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -441,9 +433,8 @@ public void long_field() { plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1.5), "")))); + List.of(DSL.named("count", DSL.count(DSL.ref("long", LONG)))), + List.of(DSL.named("span", DSL.span(DSL.ref("long", LONG), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -459,9 +450,8 @@ public void float_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1), "")))); + List.of(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), + List.of(DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -474,9 +464,8 @@ public void float_field() { plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1.5), "")))); + List.of(DSL.named("count", DSL.count(DSL.ref("float", FLOAT)))), + List.of(DSL.named("span", DSL.span(DSL.ref("float", FLOAT), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -492,9 +481,8 @@ public void double_field() { PhysicalPlan plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1), "")))); + List.of(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), + List.of(DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1), "")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -507,9 +495,8 @@ public void double_field() { plan = new AggregationOperator( testScan(numericInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), - singletonList( - DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1.5), "")))); + List.of(DSL.named("count", DSL.count(DSL.ref("double", DOUBLE)))), + List.of(DSL.named("span", DSL.span(DSL.ref("double", DOUBLE), DSL.literal(1.5), "")))); result = execute(plan); assertEquals(3, result.size()); assertThat( @@ -525,7 +512,7 @@ public void twoBucketsSpanAndLong() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), + List.of(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)))); @@ -550,7 +537,7 @@ public void twoBucketsSpanAndLong() { plan = new AggregationOperator( testScan(compoundInputs), - singletonList(DSL.named("max", DSL.max(DSL.ref("errors", INTEGER)))), + List.of(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)), @@ -637,7 +624,7 @@ public void aggregate_with_two_groups_with_windowing() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), + List.of(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")))); @@ -689,7 +676,7 @@ public void aggregate_with_three_groups_with_windowing() { PhysicalPlan plan = new AggregationOperator( testScan(compoundInputs), - singletonList(DSL.named("sum", DSL.sum(DSL.ref("errors", INTEGER)))), + List.of(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")), @@ -749,8 +736,8 @@ public void copyOfAggregationOperatorShouldSame() { AggregationOperator plan = new AggregationOperator( testScan(datetimeInputs), - singletonList(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), - singletonList( + List.of(DSL.named("count", DSL.count(DSL.ref("second", TIMESTAMP)))), + List.of( 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/PhysicalPlanNodeVisitorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitorTest.java index 17fb128ace..1b8cf7f560 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitorTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.planner.physical; -import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; @@ -110,7 +109,7 @@ public static Stream getPhysicalPlanForTest() { PhysicalPlan project = project(plan, named("ref", ref)); PhysicalPlan window = - window(plan, named(DSL.rowNumber()), new WindowDefinition(emptyList(), emptyList())); + window(plan, named(DSL.rowNumber()), new WindowDefinition(List.of(), List.of())); PhysicalPlan remove = remove(plan, ref); @@ -122,7 +121,7 @@ public static Stream getPhysicalPlanForTest() { PhysicalPlan dedupe = dedupe(plan, ref); - PhysicalPlan values = values(emptyList()); + PhysicalPlan values = values(List.of()); PhysicalPlan rareTopN = rareTopN(plan, CommandType.TOP, 5, ImmutableList.of(), ref); 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 70e2ba1866..e6b70fdbe3 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,8 +5,6 @@ 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; @@ -28,8 +26,8 @@ public void rare_without_group() { new RareTopNOperator( new TestScan(), CommandType.RARE, - singletonList(DSL.ref("action", ExprCoreType.STRING)), - emptyList()); + List.of(DSL.ref("action", ExprCoreType.STRING)), + List.of()); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -45,8 +43,8 @@ public void rare_with_group() { new RareTopNOperator( new TestScan(), CommandType.RARE, - singletonList(DSL.ref("response", ExprCoreType.INTEGER)), - singletonList(DSL.ref("action", ExprCoreType.STRING))); + List.of(DSL.ref("response", ExprCoreType.INTEGER)), + List.of(DSL.ref("action", ExprCoreType.STRING))); List result = execute(plan); assertEquals(4, result.size()); assertThat( @@ -64,8 +62,8 @@ public void top_without_group() { new RareTopNOperator( new TestScan(), CommandType.TOP, - singletonList(DSL.ref("action", ExprCoreType.STRING)), - emptyList()); + List.of(DSL.ref("action", ExprCoreType.STRING)), + List.of()); List result = execute(plan); assertEquals(2, result.size()); assertThat( @@ -82,8 +80,8 @@ public void top_n_without_group() { new TestScan(), CommandType.TOP, 1, - singletonList(DSL.ref("action", ExprCoreType.STRING)), - emptyList()); + List.of(DSL.ref("action", ExprCoreType.STRING)), + List.of()); List result = execute(plan); assertEquals(1, result.size()); assertThat( @@ -97,8 +95,8 @@ public void top_n_with_group() { new TestScan(), CommandType.TOP, 1, - singletonList(DSL.ref("response", ExprCoreType.INTEGER)), - singletonList(DSL.ref("action", ExprCoreType.STRING))); + List.of(DSL.ref("response", ExprCoreType.INTEGER)), + List.of(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 fe55275e3b..47d557acd6 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,7 +5,6 @@ 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; @@ -34,8 +33,8 @@ public void avg_aggregation_rename() { new RenameOperator( new AggregationOperator( new TestScan(), - singletonList(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), - singletonList(DSL.named("action", DSL.ref("action", STRING)))), + List.of(DSL.named("avg(response)", DSL.avg(DSL.ref("response", INTEGER)))), + List.of(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/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java index 84cb3d58a0..be866452b7 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,8 +5,6 @@ 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; @@ -105,7 +103,7 @@ void testGetDataSourceForNonExistingDataSource() { @Test void testGetDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("test", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); + metadata("test", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); doNothing().when(dataSourceUserAuthorizationHelper).authorizeDataSource(dataSourceMetadata); when(dataSourceMetadataStorage.getDataSourceMetadata("test")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -120,10 +118,7 @@ void testGetDataSourceSuccessCase() { void testGetDataSourceWithAuthorizationFailure() { DataSourceMetadata dataSourceMetadata = metadata( - "test", - DataSourceType.OPENSEARCH, - singletonList("prometheus_access"), - ImmutableMap.of()); + "test", DataSourceType.OPENSEARCH, List.of("prometheus_access"), ImmutableMap.of()); doThrow( new SecurityException( "User is not authorized to access datasource test. User should be mapped to any of" @@ -149,7 +144,7 @@ void testGetDataSourceWithAuthorizationFailure() { void testCreateDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); dataSourceService.createDataSource(dataSourceMetadata); verify(dataSourceMetadataStorage, times(1)).createDataSourceMetadata(dataSourceMetadata); verify(dataSourceFactory, times(1)).createDataSource(dataSourceMetadata); @@ -157,7 +152,7 @@ void testCreateDataSourceSuccessCase() { when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn( Optional.ofNullable( - metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()))); + metadata("testDS", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()))); DataSource dataSource = dataSourceService.getDataSource("testDS"); assertEquals("testDS", dataSource.getName()); assertEquals(storageEngine, dataSource.getStorageEngine()); @@ -175,7 +170,7 @@ void testGetDataSourceMetadataSet() { .thenReturn( new ArrayList<>() { { - add(metadata("testDS", DataSourceType.PROMETHEUS, emptyList(), properties)); + add(metadata("testDS", DataSourceType.PROMETHEUS, List.of(), properties)); } }); Set dataSourceMetadataSet = dataSourceService.getDataSourceMetadata(false); @@ -196,7 +191,7 @@ void testGetDataSourceMetadataSetWithDefaultDatasource() { .thenReturn( new ArrayList<>() { { - add(metadata("testDS", DataSourceType.PROMETHEUS, emptyList(), ImmutableMap.of())); + add(metadata("testDS", DataSourceType.PROMETHEUS, List.of(), ImmutableMap.of())); } }); Set dataSourceMetadataSet = dataSourceService.getDataSourceMetadata(true); @@ -209,7 +204,7 @@ void testGetDataSourceMetadataSetWithDefaultDatasource() { @Test void testUpdateDataSourceSuccessCase() { DataSourceMetadata dataSourceMetadata = - metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); dataSourceService.updateDataSource(dataSourceMetadata); verify(dataSourceMetadataStorage, times(1)).updateDataSourceMetadata(dataSourceMetadata); verify(dataSourceFactory, times(1)).createDataSource(dataSourceMetadata); @@ -218,8 +213,7 @@ void testUpdateDataSourceSuccessCase() { @Test void testUpdateDefaultDataSource() { DataSourceMetadata dataSourceMetadata = - metadata( - DEFAULT_DATASOURCE_NAME, DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); + metadata(DEFAULT_DATASOURCE_NAME, DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); UnsupportedOperationException unsupportedOperationException = assertThrows( UnsupportedOperationException.class, @@ -263,7 +257,7 @@ void testPatchDataSourceSuccessCase() { STATUS_FIELD, DataSourceStatus.DISABLED)); DataSourceMetadata getData = - metadata("testDS", DataSourceType.OPENSEARCH, emptyList(), ImmutableMap.of()); + metadata("testDS", DataSourceType.OPENSEARCH, List.of(), ImmutableMap.of()); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.ofNullable(getData)); @@ -326,7 +320,7 @@ void testRemovalOfAuthorizationInfo() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -351,7 +345,7 @@ void testRemovalOfAuthorizationInfoForAccessKeyAndSecretKye() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -378,7 +372,7 @@ void testRemovalOfAuthorizationInfoForGlueWithRoleARN() { .setName("testGlue") .setProperties(properties) .setConnector(DataSourceType.S3GLUE) - .setAllowedRoles(singletonList("glue_access")) + .setAllowedRoles(List.of("glue_access")) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testGlue")) .thenReturn(Optional.of(dataSourceMetadata)); @@ -420,7 +414,7 @@ void testGetDataSourceMetadataForSpecificDataSourceName() { when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) .thenReturn( Optional.ofNullable( - metadata("testDS", DataSourceType.PROMETHEUS, emptyList(), properties))); + metadata("testDS", DataSourceType.PROMETHEUS, List.of(), properties))); DataSourceMetadata dataSourceMetadata = this.dataSourceService.getDataSourceMetadata("testDS"); assertTrue(dataSourceMetadata.getProperties().containsKey("prometheus.uri")); assertTrue(dataSourceMetadata.getProperties().containsKey("prometheus.auth.type")); @@ -441,7 +435,7 @@ void testVerifyDataSourceAccessAndGetRawDataSourceMetadataWithDisabledData() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .setDataSourceStatus(DataSourceStatus.DISABLED) .build(); when(dataSourceMetadataStorage.getDataSourceMetadata("testDS")) @@ -468,7 +462,7 @@ void testVerifyDataSourceAccessAndGetRawDataSourceMetadata() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("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 0a363699cd..efc99e2455 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,8 +5,6 @@ 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; @@ -673,7 +671,7 @@ public void testWhenDataSourcesAreDisabled() { Optional.empty(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata("dummy")); Assertions.assertEquals( - emptyList(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata()); + List.of(), this.openSearchDataSourceMetadataStorage.getDataSourceMetadata()); Assertions.assertThrows( IllegalStateException.class, @@ -713,7 +711,7 @@ private String getBasicDataSourceMetadataString() throws JsonProcessingException .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -733,7 +731,7 @@ private String getAWSSigv4DataSourceMetadataString() throws JsonProcessingExcept .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -750,7 +748,7 @@ private String getDataSourceMetadataStringWithBasicAuthentication() .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -763,7 +761,7 @@ private String getDataSourceMetadataStringWithNoAuthentication() throws JsonProc .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); return serialize(dataSourceMetadata); } @@ -778,7 +776,7 @@ private DataSourceMetadata getDataSourceMetadata() { .setName("testDS") .setProperties(properties) .setConnector(DataSourceType.PROMETHEUS) - .setAllowedRoles(singletonList("prometheus_access")) + .setAllowedRoles(List.of("prometheus_access")) .build(); } diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/DBResultTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/DBResultTest.java index 2415ff486b..798d1c23e9 100644 --- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/DBResultTest.java +++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/DBResultTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.correctness.tests; -import static java.util.Collections.emptyList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -24,15 +23,15 @@ public class DBResultTest { @Test public void dbResultFromDifferentDbNameShouldEqual() { - DBResult result1 = new DBResult("DB 1", List.of(new Type("name", "VARCHAR")), emptyList()); - DBResult result2 = new DBResult("DB 2", List.of(new Type("name", "VARCHAR")), emptyList()); + DBResult result1 = new DBResult("DB 1", List.of(new Type("name", "VARCHAR")), List.of()); + DBResult result2 = new DBResult("DB 2", List.of(new Type("name", "VARCHAR")), List.of()); assertEquals(result1, result2); } @Test public void dbResultWithDifferentColumnShouldNotEqual() { - DBResult result1 = new DBResult("DB 1", List.of(new Type("name", "VARCHAR")), emptyList()); - DBResult result2 = new DBResult("DB 2", List.of(new Type("age", "INT")), emptyList()); + DBResult result1 = new DBResult("DB 1", List.of(new Type("name", "VARCHAR")), List.of()); + DBResult result2 = new DBResult("DB 2", List.of(new Type("age", "INT")), List.of()); assertNotEquals(result1, result2); } @@ -68,8 +67,8 @@ public void dbResultInOrderWithSameRowsInDifferentOrderShouldNotEqual() { @Test public void dbResultWithDifferentColumnTypeShouldNotEqual() { - DBResult result1 = new DBResult("DB 1", List.of(new Type("age", "FLOAT")), emptyList()); - DBResult result2 = new DBResult("DB 2", List.of(new Type("age", "INT")), emptyList()); + DBResult result1 = new DBResult("DB 1", List.of(new Type("age", "FLOAT")), List.of()); + DBResult result2 = new DBResult("DB 2", List.of(new Type("age", "INT")), List.of()); assertNotEquals(result1, result2); } @@ -79,12 +78,10 @@ public void shouldExplainColumnTypeDifference() { new DBResult( "DB 1", Arrays.asList(new Type("name", "VARCHAR"), new Type("age", "FLOAT")), - emptyList()); + List.of()); DBResult result2 = new DBResult( - "DB 2", - Arrays.asList(new Type("name", "VARCHAR"), new Type("age", "INT")), - emptyList()); + "DB 2", Arrays.asList(new Type("name", "VARCHAR"), new Type("age", "INT")), List.of()); assertEquals( "Schema type at [1] is different: " diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestConfigTest.java b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestConfigTest.java index daf084d371..962642a540 100644 --- a/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestConfigTest.java +++ b/integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestConfigTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.correctness.tests; -import static java.util.Collections.emptyMap; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.emptyString; @@ -22,7 +21,7 @@ public class TestConfigTest { @Test public void testDefaultConfig() { - TestConfig config = new TestConfig(emptyMap()); + TestConfig config = new TestConfig(Map.of()); assertThat(config.getOpenSearchHostUrl(), is(emptyString())); assertThat( config.getOtherDbConnectionNameAndUrls(), 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 f90b42cda2..03b6c3fb64 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,7 +5,6 @@ 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; @@ -157,7 +156,7 @@ public void selectScore() throws IOException { "SELECT _score FROM %s WHERE SCORE(match_phrase(phrase, 'brown fox'))", TestsConstants.TEST_INDEX_PHRASE)); - List fields = singletonList("_score"); + List fields = List.of("_score"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } @@ -277,7 +276,7 @@ public void groupBySingleField() throws IOException { String.format( Locale.ROOT, "SELECT * FROM %s GROUP BY age", TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = singletonList("age"); + List fields = List.of("age"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } @@ -398,7 +397,7 @@ public void aggregationFunctionInSelectNoGroupBy() throws IOException { Locale.ROOT, "SELECT SUM(age) FROM %s", TestsConstants.TEST_INDEX_ACCOUNT)); String ageSum = "SUM(age)"; - assertContainsColumns(getSchema(response), singletonList(ageSum)); + assertContainsColumns(getSchema(response), List.of(ageSum)); JSONArray dataRows = getDataRows(response); for (int i = 0; i < dataRows.length(); i++) { @@ -433,7 +432,7 @@ public void aggregationFunctionInHaving() throws IOException { TestsConstants.TEST_INDEX_ACCOUNT)); String ageSum = "gender"; - assertContainsColumns(getSchema(response), singletonList(ageSum)); + assertContainsColumns(getSchema(response), List.of(ageSum)); JSONArray dataRows = getDataRows(response); assertEquals(1, dataRows.length()); @@ -555,7 +554,7 @@ public void joinQuerySelectOnlyOnOneTable() throws Exception { TestsConstants.TEST_INDEX_ACCOUNT, TestsConstants.TEST_INDEX_ACCOUNT)); - List fields = singletonList("b1.age"); + List fields = List.of("b1.age"); assertContainsColumns(getSchema(response), fields); assertContainsData(getDataRows(response), fields); } diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/antlr/semantic/scope/SymbolTable.java b/legacy/src/main/java/org/opensearch/sql/legacy/antlr/semantic/scope/SymbolTable.java index 0f65ee1b99..2eb0f4009d 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/antlr/semantic/scope/SymbolTable.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/antlr/semantic/scope/SymbolTable.java @@ -5,7 +5,6 @@ package org.opensearch.sql.legacy.antlr.semantic.scope; -import static java.util.Collections.emptyMap; import static java.util.Collections.emptyNavigableMap; import java.util.EnumMap; @@ -67,7 +66,7 @@ public Map lookupByPrefix(Symbol prefix) { .filter(entry -> null != entry.getValue().get()) .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().get())); } - return emptyMap(); + return Map.of(); } /** diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/antlr/visitor/AntlrSqlParseTreeVisitor.java b/legacy/src/main/java/org/opensearch/sql/legacy/antlr/visitor/AntlrSqlParseTreeVisitor.java index 5e89b3b8ae..29a1bdebb9 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/antlr/visitor/AntlrSqlParseTreeVisitor.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/antlr/visitor/AntlrSqlParseTreeVisitor.java @@ -5,7 +5,6 @@ package org.opensearch.sql.legacy.antlr.visitor; -import static java.util.Collections.emptyList; import static java.util.Collections.singleton; import static org.opensearch.sql.legacy.antlr.parser.OpenSearchLegacySqlParser.AggregateWindowedFunctionContext; import static org.opensearch.sql.legacy.antlr.parser.OpenSearchLegacySqlParser.AtomTableItemContext; @@ -377,14 +376,14 @@ private T visitSelectItem(ParserRuleContext item, UidContext uid) { } private T reduce(T reducer, ParserRuleContext ctx) { - return reduce(reducer, (ctx == null) ? emptyList() : ctx.children); + return reduce(reducer, (ctx == null) ? List.of() : ctx.children); } /** Make constructor apply arguments and return result type */ private T reduce(T reducer, List nodes) { List args; if (nodes == null) { - args = emptyList(); + args = List.of(); } else { args = nodes.stream() diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMapping.java b/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMapping.java index 89f8f9ac89..01416f442a 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMapping.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMapping.java @@ -5,7 +5,6 @@ package org.opensearch.sql.legacy.esdomain.mapping; -import static java.util.Collections.emptyMap; import static org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata; import java.util.Map; @@ -31,7 +30,7 @@ public class FieldMapping { private final Map specifiedFieldsByName; public FieldMapping(String fieldName) { - this(fieldName, emptyMap(), emptyMap()); + this(fieldName, Map.of(), Map.of()); } public FieldMapping( diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/IndexMappings.java b/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/IndexMappings.java index 61e707e8ef..4292a95432 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/IndexMappings.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/IndexMappings.java @@ -5,8 +5,6 @@ package org.opensearch.sql.legacy.esdomain.mapping; -import static java.util.Collections.emptyMap; - import java.util.Map; import java.util.Objects; import org.opensearch.cluster.metadata.MappingMetadata; @@ -42,7 +40,7 @@ public class IndexMappings implements Mappings { private final Map indexMappings; public IndexMappings() { - this.indexMappings = emptyMap(); + this.indexMappings = Map.of(); } public IndexMappings(Metadata metaData) { diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/join/JoinAlgorithm.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/join/JoinAlgorithm.java index 0c0d50258d..bd248f3b7e 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/join/JoinAlgorithm.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/join/JoinAlgorithm.java @@ -5,8 +5,6 @@ package org.opensearch.sql.legacy.query.planner.physical.node.join; -import static java.util.Collections.emptyList; - import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource.JoinType; import com.google.common.collect.Sets; import java.util.ArrayList; @@ -130,7 +128,7 @@ protected Collection> prefetch() throws Exception { // 4.Clean up and close right cleanUpAndCloseRight(); } - return emptyList(); + return List.of(); } /** Probe right by hash table built from left. Handle matched and mismatched rows. */ diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/sort/QuickSort.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/sort/QuickSort.java index abfcf273ad..715cd61430 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/sort/QuickSort.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/sort/QuickSort.java @@ -5,8 +5,6 @@ package org.opensearch.sql.legacy.query.planner.physical.node.sort; -import static java.util.Collections.emptyList; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -67,7 +65,7 @@ public void open(ExecuteParams params) throws Exception { @Override protected Collection> prefetch() { if (isDone) { - return emptyList(); + return List.of(); } List> allRowsSorted = new ArrayList<>(); diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/SymbolSimilarityTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/SymbolSimilarityTest.java index fbdcca2bb0..8a47a25fa9 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/SymbolSimilarityTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/SymbolSimilarityTest.java @@ -5,9 +5,6 @@ package org.opensearch.sql.legacy.antlr; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; - import java.util.Arrays; import java.util.List; import org.junit.Assert; @@ -19,7 +16,7 @@ public class SymbolSimilarityTest { @Test public void noneCandidateShouldReturnTargetStringItself() { String target = "test"; - String mostSimilarSymbol = new SimilarSymbols(emptyList()).mostSimilarTo(target); + String mostSimilarSymbol = new SimilarSymbols(List.of()).mostSimilarTo(target); Assert.assertEquals(target, mostSimilarSymbol); } @@ -27,7 +24,7 @@ public void noneCandidateShouldReturnTargetStringItself() { public void singleCandidateShouldReturnTheOnlyCandidate() { String target = "test"; String candidate = "hello"; - String mostSimilarSymbol = new SimilarSymbols(singletonList(candidate)).mostSimilarTo(target); + String mostSimilarSymbol = new SimilarSymbols(List.of(candidate)).mostSimilarTo(target); Assert.assertEquals(candidate, mostSimilarSymbol); } diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMappingTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMappingTest.java index ed2611786a..05d91b2261 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMappingTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMappingTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.legacy.esdomain.mapping; -import static java.util.Collections.emptyMap; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata; @@ -29,14 +28,14 @@ public class FieldMappingTest { @Test public void testFieldMatchesWildcardPatternSpecifiedInQuery() { assertThat( - new FieldMapping("employee.first", emptyMap(), fieldsSpecifiedInQuery("employee.*")), + new FieldMapping("employee.first", Map.of(), fieldsSpecifiedInQuery("employee.*")), isWildcardSpecified(true)); } @Test public void testFieldMismatchesWildcardPatternSpecifiedInQuery() { assertThat( - new FieldMapping("employee.first", emptyMap(), fieldsSpecifiedInQuery("manager.*")), + new FieldMapping("employee.first", Map.of(), fieldsSpecifiedInQuery("manager.*")), isWildcardSpecified(false)); } @@ -76,7 +75,7 @@ public void testDeepNestedField() { "employee.location.city", new BytesArray( "{\n" + " \"city\" : {\n" + " \"type\" : \"text\"\n" + " }\n" + "}"))), - emptyMap()), + Map.of()), hasType("text")); } diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/executor/AsyncRestExecutorTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/executor/AsyncRestExecutorTest.java index eea1c9a87a..f34defca6b 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/executor/AsyncRestExecutorTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/executor/AsyncRestExecutorTest.java @@ -6,7 +6,6 @@ package org.opensearch.sql.legacy.executor; import static java.util.Collections.emptyList; -import static java.util.Collections.emptyMap; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -43,7 +42,7 @@ public class AsyncRestExecutorTest { @Mock private Client client; - private final Map params = emptyMap(); + private final Map params = Map.of(); @Mock private QueryAction action; diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/planner/QueryPlannerTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/planner/QueryPlannerTest.java index 6ff907ba30..42019a2bfb 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/planner/QueryPlannerTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/planner/QueryPlannerTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.legacy.unittest.planner; -import static java.util.Collections.emptyList; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; @@ -104,7 +103,7 @@ public void init() { // Force return empty list to avoid ClusterSettings be invoked which is a final class and hard // to mock. // In this case, default value in Setting will be returned all the time. - doReturn(emptyList()).when(settings).getSettings(); + doReturn(List.of()).when(settings).getSettings(); doReturn(false).when(settings).getSettingValue(Settings.Key.SQL_PAGINATION_API_SEARCH_AFTER); LocalClusterState.state().setPluginSettings(settings); diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/util/CheckScriptContents.java b/legacy/src/test/java/org/opensearch/sql/legacy/util/CheckScriptContents.java index 811d05c16a..474daab055 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/util/CheckScriptContents.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/util/CheckScriptContents.java @@ -5,7 +5,6 @@ package org.opensearch.sql.legacy.util; -import static java.util.Collections.emptyList; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyLong; @@ -242,7 +241,7 @@ public static OpenSearchSettings mockPluginSettings() { // Force return empty list to avoid ClusterSettings be invoked which is a final class and hard // to mock. // In this case, default value in Setting will be returned all the time. - doReturn(emptyList()).when(settings).getSettings(); + doReturn(List.of()).when(settings).getSettings(); return settings; } } 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 f274e35811..46f96f6e2d 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,7 +5,6 @@ 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; @@ -115,7 +114,7 @@ public ExprValue next() { @Override public List getChild() { - return singletonList(input); + return List.of(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 3ae0f43fce..10342f6d4d 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,7 +5,6 @@ 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; @@ -91,7 +90,7 @@ public ExprValue next() { @Override public List getChild() { - return singletonList(input); + return List.of(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 00a28342ef..ecb486f39f 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,6 @@ package org.opensearch.sql.opensearch.planner.physical; -import static java.util.Collections.singletonList; - import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -99,7 +97,7 @@ public ExprValue next() { @Override public List getChild() { - return singletonList(input); + return List.of(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 3a61915499..b3bdece816 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,6 @@ package org.opensearch.sql.opensearch.response.agg; -import static java.util.Collections.singletonList; - import java.util.Arrays; import java.util.List; import java.util.Map; @@ -35,6 +33,6 @@ public NoBucketAggregationParser(List metricParserList) { @Override public List> parse(Aggregations aggregations) { - return singletonList(metricsParser.parse(aggregations)); + return List.of(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 7f14cb1fe0..e46fdb0b81 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,8 +5,6 @@ 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; @@ -78,7 +76,7 @@ public AggregationQueryBuilder(ExpressionSerializer serializer) { } else { GroupSortOrder groupSortOrder = new GroupSortOrder(sortList); return Pair.of( - singletonList( + List.of( AggregationBuilders.composite( "composite_buckets", bucketBuilder.build( diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilder.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilder.java index fa0fe19105..9cf80f0cb4 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilder.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilder.java @@ -5,7 +5,6 @@ package org.opensearch.sql.opensearch.storage.script.filter; -import static java.util.Collections.emptyMap; import static org.opensearch.script.Script.DEFAULT_SCRIPT_TYPE; import static org.opensearch.sql.opensearch.storage.script.ExpressionScriptEngine.EXPRESSION_LANG_NAME; @@ -131,6 +130,6 @@ private BoolQueryBuilder buildBoolQuery( private ScriptQueryBuilder buildScriptQuery(FunctionExpression node) { return new ScriptQueryBuilder( new Script( - DEFAULT_SCRIPT_TYPE, EXPRESSION_LANG_NAME, serializer.serialize(node), emptyMap())); + DEFAULT_SCRIPT_TYPE, EXPRESSION_LANG_NAME, serializer.serialize(node), Map.of())); } } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/executor/protector/OpenSearchExecutionProtectorTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/executor/protector/OpenSearchExecutionProtectorTest.java index da06c1eb66..f69cce7f8b 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/executor/protector/OpenSearchExecutionProtectorTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/executor/protector/OpenSearchExecutionProtectorTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.opensearch.executor.protector; -import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.Mockito.*; @@ -184,13 +183,12 @@ void test_protect_sort_for_windowOperator() { NamedExpression rank = named(mock(RankFunction.class)); Pair sortItem = ImmutablePair.of(DEFAULT_ASC, DSL.ref("age", INTEGER)); - WindowDefinition windowDefinition = - new WindowDefinition(emptyList(), ImmutableList.of(sortItem)); + WindowDefinition windowDefinition = new WindowDefinition(List.of(), ImmutableList.of(sortItem)); assertEquals( - window(resourceMonitor(sort(values(emptyList()), sortItem)), rank, windowDefinition), + window(resourceMonitor(sort(values(List.of()), sortItem)), rank, windowDefinition), executionProtector.protect( - window(sort(values(emptyList()), sortItem), rank, windowDefinition))); + window(sort(values(List.of()), sortItem), rank, windowDefinition))); } @Test @@ -209,13 +207,12 @@ void test_not_protect_windowOperator_input_if_already_protected() { NamedExpression avg = named(mock(AggregateWindowFunction.class)); Pair sortItem = ImmutablePair.of(DEFAULT_ASC, DSL.ref("age", INTEGER)); - WindowDefinition windowDefinition = - new WindowDefinition(emptyList(), ImmutableList.of(sortItem)); + WindowDefinition windowDefinition = new WindowDefinition(List.of(), ImmutableList.of(sortItem)); assertEquals( - window(resourceMonitor(sort(values(emptyList()), sortItem)), avg, windowDefinition), + window(resourceMonitor(sort(values(List.of()), sortItem)), avg, windowDefinition), executionProtector.protect( - window(sort(values(emptyList()), sortItem), avg, windowDefinition))); + window(sort(values(List.of()), sortItem), avg, windowDefinition))); } @Test @@ -232,7 +229,7 @@ void test_visitMLcommons() { NodeClient nodeClient = mock(NodeClient.class); MLCommonsOperator mlCommonsOperator = new MLCommonsOperator( - values(emptyList()), + values(List.of()), "kmeans", new HashMap() { { @@ -253,7 +250,7 @@ void test_visitAD() { NodeClient nodeClient = mock(NodeClient.class); ADOperator adOperator = new ADOperator( - values(emptyList()), + values(List.of()), new HashMap() { { put("shingle_size", new Literal(8, DataType.INTEGER)); @@ -272,7 +269,7 @@ void test_visitML() { NodeClient nodeClient = mock(NodeClient.class); MLOperator mlOperator = new MLOperator( - values(emptyList()), + values(List.of()), new HashMap() { { put("action", new Literal("train", DataType.STRING)); @@ -293,11 +290,11 @@ void test_visitNested() { Set args = Set.of("message.info"); Map> groupedFieldsByPath = Map.of("message", List.of("message.info")); NestedOperator nestedOperator = - new NestedOperator(values(emptyList()), args, groupedFieldsByPath); + new NestedOperator(values(List.of()), args, groupedFieldsByPath); assertEquals( executionProtector.doProtect(nestedOperator), - executionProtector.visitNested(nestedOperator, values(emptyList()))); + executionProtector.visitNested(nestedOperator, values(List.of()))); } @Test @@ -313,7 +310,7 @@ public void test_visitTakeOrdered() { Pair sort = ImmutablePair.of(Sort.SortOption.DEFAULT_ASC, ref("a", INTEGER)); TakeOrderedOperator takeOrdered = - PhysicalPlanDSL.takeOrdered(PhysicalPlanDSL.values(emptyList()), 10, 5, sort); + PhysicalPlanDSL.takeOrdered(PhysicalPlanDSL.values(List.of()), 10, 5, sort); assertEquals( resourceMonitor(takeOrdered), executionProtector.visitTakeOrdered(takeOrdered, null)); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/response/OpenSearchResponseTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/response/OpenSearchResponseTest.java index 984c98f803..5597ca1213 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/response/OpenSearchResponseTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/response/OpenSearchResponseTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.opensearch.response; -import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -94,7 +93,7 @@ void isEmpty() { assertTrue(response.isEmpty()); when(searchResponse.getHits()).thenReturn(SearchHits.empty()); - when(searchResponse.getAggregations()).thenReturn(new Aggregations(emptyList())); + when(searchResponse.getAggregations()).thenReturn(new Aggregations(List.of())); response = new OpenSearchResponse(searchResponse, factory, includes); assertFalse(response.isEmpty()); 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 b0769b950c..98b7382b3b 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,8 +5,6 @@ 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; @@ -332,10 +330,10 @@ void test_limit_push_down() { void test_highlight_push_down() { assertEqualsAfterOptimization( project( - indexScanBuilder(withHighlightPushedDown("*", emptyMap())), + indexScanBuilder(withHighlightPushedDown("*", Map.of())), DSL.named("highlight(*)", new HighlightExpression(DSL.literal("*")))), project( - highlight(relation("schema", table), DSL.literal("*"), emptyMap()), + highlight(relation("schema", table), DSL.literal("*"), Map.of()), DSL.named("highlight(*)", new HighlightExpression(DSL.literal("*"))))); } @@ -642,7 +640,7 @@ private Runnable withAggregationPushedDown( CompositeAggregationBuilder aggBuilder = AggregationBuilders.composite( "composite_buckets", - singletonList( + List.of( new TermsValuesSourceBuilder(aggregation.groupBy) .field(aggregation.groupBy) .order(aggregation.sortBy.getSortOrder() == ASC ? "asc" : "desc") @@ -653,7 +651,7 @@ private Runnable withAggregationPushedDown( AggregationBuilders.avg(aggregation.aggregateName).field(aggregation.aggregateBy)) .size(AggregationQueryBuilder.AGGREGATION_BUCKET_SIZE); - List aggBuilders = singletonList(aggBuilder); + List aggBuilders = List.of(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 13769ef226..cb55fd3cfb 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,8 +5,6 @@ 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; @@ -281,7 +279,7 @@ void should_build_composite_aggregation_for_expression() { List.of( named( "avg(balance)", - new AvgAggregator(singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), + new AvgAggregator(List.of(DSL.abs(ref("balance", INTEGER))), INTEGER))), List.of(named("age", DSL.asin(ref("age", INTEGER)))))); } @@ -339,7 +337,7 @@ void should_build_type_mapping_for_expression() { List.of( named( "avg(balance)", - new AvgAggregator(singletonList(DSL.abs(ref("balance", INTEGER))), INTEGER))), + new AvgAggregator(List.of(DSL.abs(ref("balance", INTEGER))), INTEGER))), List.of(named("age", DSL.asin(ref("age", INTEGER))))), containsInAnyOrder( map("avg(balance)", OpenSearchDataType.of(INTEGER)), @@ -361,7 +359,7 @@ void should_build_aggregation_without_bucket() { List.of( named( "avg(balance)", new AvgAggregator(List.of(ref("balance", INTEGER)), INTEGER))), - emptyList())); + List.of())); } @Test @@ -396,7 +394,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))))), - emptyList())); + List.of())); } @Test @@ -458,7 +456,7 @@ void should_build_type_mapping_without_bucket() { List.of( named( "avg(balance)", new AvgAggregator(List.of(ref("balance", INTEGER)), INTEGER))), - emptyList()), + List.of()), containsInAnyOrder(map("avg(balance)", OpenSearchDataType.of(INTEGER)))); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java index 6d90cce704..d25c9dc11f 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java @@ -6,7 +6,6 @@ package org.opensearch.sql.opensearch.storage.script.aggregation; import static java.time.temporal.ChronoUnit.MILLIS; -import static java.util.Collections.emptyMap; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -174,7 +173,7 @@ ExprScriptAssertion docValues(String name1, Object value1, String name2, Object ExprScriptAssertion evaluate(Expression expr) { ExpressionAggregationScript script = - new ExpressionAggregationScript(expr, lookup, context, emptyMap()); + new ExpressionAggregationScript(expr, lookup, context, Map.of()); actual = script.execute(); return this; } 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 8c6ff07083..bfdc2392b2 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,7 +5,6 @@ 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; @@ -335,11 +334,10 @@ void should_build_cardinality_aggregation() { + " }%n" + "}"), buildQuery( - singletonList( + List.of( named( "count(distinct name)", - new CountAggregator(singletonList(ref("name", STRING)), INTEGER) - .distinct(true))))); + new CountAggregator(List.of(ref("name", STRING)), INTEGER).distinct(true))))); } @Test @@ -369,10 +367,10 @@ void should_build_filtered_cardinality_aggregation() { + " }%n" + "}"), buildQuery( - singletonList( + List.of( named( "count(distinct name) filter(where age > 30)", - new CountAggregator(singletonList(ref("name", STRING)), INTEGER) + new CountAggregator(List.of(ref("name", STRING)), INTEGER) .condition(DSL.greater(ref("age", INTEGER), literal(30))) .distinct(true))))); } @@ -397,7 +395,7 @@ void should_build_top_hits_aggregation() { + " }%n" + "}"), buildQuery( - singletonList( + List.of( named( "take(name, 10)", new TakeAggregator( @@ -439,7 +437,7 @@ void should_build_filtered_top_hits_aggregation() { + " }%n" + "}"), buildQuery( - singletonList( + List.of( named( "take(name, 10) filter(where age > 30)", new TakeAggregator(ImmutableList.of(ref("name", STRING), literal(10)), ARRAY) @@ -452,11 +450,10 @@ void should_throw_exception_for_unsupported_distinct_aggregator() { IllegalStateException.class, () -> buildQuery( - singletonList( + List.of( named( "avg(distinct age)", - new AvgAggregator(singletonList(ref("name", STRING)), STRING) - .distinct(true)))), + new AvgAggregator(List.of(ref("name", STRING)), STRING).distinct(true)))), "unsupported distinct aggregator avg"); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java index df754887cf..bb0bc9a129 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java @@ -5,9 +5,6 @@ package org.opensearch.sql.opensearch.storage.script.filter; -import static java.util.Collections.emptyList; -import static java.util.Collections.emptyMap; -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; @@ -140,7 +137,7 @@ void can_execute_expression_with_missing_field() { @Test void can_execute_expression_with_empty_doc_value() { - assertThat().docValues("name", emptyList()).filterBy(ref("name", STRING)).shouldNotMatch(); + assertThat().docValues("name", List.of()).filterBy(ref("name", STRING)).shouldNotMatch(); } @Test @@ -212,7 +209,7 @@ ExprScriptAssertion docValues(String name1, Object value1, String name2, Object } ExprScriptAssertion filterBy(Expression expr) { - ExpressionFilterScript script = new ExpressionFilterScript(expr, lookup, context, emptyMap()); + ExpressionFilterScript script = new ExpressionFilterScript(expr, lookup, context, Map.of()); isMatched = script.execute(); return this; } @@ -238,7 +235,7 @@ private static class FakeScriptDocValues extends ScriptDocValues { @SuppressWarnings("unchecked") public FakeScriptDocValues(T value) { - this.values = (value instanceof List) ? (List) value : singletonList(value); + this.values = (value instanceof List) ? (List) value : List.of(value); } @Override 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 75e27e58da..9a42cb089f 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,8 +5,6 @@ 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.List; @@ -25,7 +23,7 @@ public class Utils { public static AvgAggregator avg(Expression expr, ExprCoreType type) { - return new AvgAggregator(singletonList(expr), type); + return new AvgAggregator(List.of(expr), type); } public static List agg(NamedAggregator... exprs) { @@ -38,7 +36,7 @@ public static List group(NamedExpression... exprs) { public static List> sort( Expression expr1, Sort.SortOption option1) { - return singletonList(Pair.of(option1, expr1)); + return List.of(Pair.of(option1, expr1)); } public static List> sort( diff --git a/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java b/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java index 766edc42c0..db87e64430 100644 --- a/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java +++ b/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java @@ -5,7 +5,6 @@ package org.opensearch.sql.plugin; -import static java.util.Collections.singletonList; import static org.opensearch.sql.datasource.model.DataSourceMetadata.defaultOpenSearchDataSourceMetadata; import static org.opensearch.sql.spark.data.constants.SparkConstants.SPARK_REQUEST_BUFFER_INDEX_NAME; @@ -276,7 +275,7 @@ public ScheduledJobParser getJobParser() { @Override public List> getExecutorBuilders(Settings settings) { - return singletonList( + return List.of( new FixedExecutorBuilder( settings, AsyncRestExecutor.SQL_WORKER_THREAD_POOL_NAME, 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 6e20d19820..c7e77651a8 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,7 +5,6 @@ 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; @@ -33,7 +32,7 @@ public class ArgumentFactory { * @return the list of arguments fetched from the fields command */ public static List getArgumentList(FieldsCommandContext ctx) { - return singletonList( + return List.of( ctx.MINUS() != null ? new Argument("exclude", new Literal(true, DataType.BOOLEAN)) : new Argument("exclude", new Literal(false, DataType.BOOLEAN))); @@ -109,7 +108,7 @@ public static List getArgumentList(SortFieldContext ctx) { * @return the list of arguments fetched from the top command */ public static List getArgumentList(TopCommandContext ctx) { - return singletonList( + return List.of( ctx.number != null ? new Argument("noOfResults", getArgumentValue(ctx.number)) : new Argument("noOfResults", new Literal(10, DataType.INTEGER))); @@ -122,7 +121,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 singletonList(new Argument("noOfResults", new Literal(10, DataType.INTEGER))); + return List.of(new Argument("noOfResults", new Literal(10, DataType.INTEGER))); } /** diff --git a/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java b/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java index fbb25549ab..e10dca5229 100644 --- a/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java +++ b/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.ppl.parser; -import static java.util.Collections.emptyList; import static org.junit.Assert.assertFalse; import static org.opensearch.sql.ast.dsl.AstDSL.agg; import static org.opensearch.sql.ast.dsl.AstDSL.aggregate; @@ -394,7 +393,7 @@ public void testAggFuncCallExpr() { agg( relation("t"), exprList(alias("avg(a)", aggregate("avg", field("a")))), - emptyList(), + List.of(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -406,7 +405,7 @@ public void testVarAggregationShouldPass() { agg( relation("t"), exprList(alias("var_samp(a)", aggregate("var_samp", field("a")))), - emptyList(), + List.of(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -418,7 +417,7 @@ public void testVarpAggregationShouldPass() { agg( relation("t"), exprList(alias("var_pop(a)", aggregate("var_pop", field("a")))), - emptyList(), + List.of(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -430,7 +429,7 @@ public void testStdDevAggregationShouldPass() { agg( relation("t"), exprList(alias("stddev_samp(a)", aggregate("stddev_samp", field("a")))), - emptyList(), + List.of(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -442,7 +441,7 @@ public void testStdDevPAggregationShouldPass() { agg( relation("t"), exprList(alias("stddev_pop(a)", aggregate("stddev_pop", field("a")))), - emptyList(), + List.of(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -457,8 +456,8 @@ public void testPercentileAggFuncExpr() { alias( "percentile(a, 1)", aggregate("percentile", field("a"), unresolvedArg("percent", intLiteral(1))))), - emptyList(), - emptyList(), + List.of(), + List.of(), defaultStatsArgs())); assertEqual( "source=t | stats percentile(a, 1.0)", @@ -469,8 +468,8 @@ public void testPercentileAggFuncExpr() { "percentile(a, 1.0)", aggregate( "percentile", field("a"), unresolvedArg("percent", doubleLiteral(1D))))), - emptyList(), - emptyList(), + List.of(), + List.of(), defaultStatsArgs())); assertEqual( "source=t | stats percentile(a, 1.0, 100)", @@ -484,8 +483,8 @@ public void testPercentileAggFuncExpr() { field("a"), unresolvedArg("percent", doubleLiteral(1D)), unresolvedArg("compression", intLiteral(100))))), - emptyList(), - emptyList(), + List.of(), + List.of(), defaultStatsArgs())); } @@ -496,7 +495,7 @@ public void testCountFuncCallExpr() { agg( relation("t"), exprList(alias("count()", aggregate("count", AllFields.of()))), - emptyList(), + List.of(), exprList(alias("b", field("b"))), defaultStatsArgs())); } @@ -508,8 +507,8 @@ public void testDistinctCount() { agg( relation("t"), exprList(alias("distinct_count(a)", distinctAggregate("count", field("a")))), - emptyList(), - emptyList(), + List.of(), + List.of(), defaultStatsArgs())); } @@ -523,8 +522,8 @@ public void testTakeAggregationNoArgsShouldPass() { alias( "take(a)", aggregate("take", field("a"), unresolvedArg("size", intLiteral(10))))), - emptyList(), - emptyList(), + List.of(), + List.of(), defaultStatsArgs())); } @@ -538,8 +537,8 @@ public void testTakeAggregationWithArgsShouldPass() { alias( "take(a, 5)", aggregate("take", field("a"), unresolvedArg("size", intLiteral(5))))), - emptyList(), - emptyList(), + List.of(), + List.of(), defaultStatsArgs())); } @@ -762,7 +761,7 @@ public void indexCanBeId() { agg( relation("index"), exprList(alias("count()", aggregate("count", AllFields.of()))), - emptyList(), + List.of(), exprList(alias("index", field("index"))), defaultStatsArgs())); } 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 8709cecba3..6dc6e11f0e 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,7 +5,6 @@ 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; @@ -154,13 +153,12 @@ void testGetAllMetrics() { Map> expected = new HashMap<>(); expected.put( "go_gc_duration_seconds", - singletonList( + List.of( new MetricMetadata( "summary", "A summary of the pause duration of garbage collection cycles.", ""))); expected.put( "go_goroutines", - singletonList( - new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); + List.of(new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); assertEquals(expected, response); RecordedRequest recordedRequest = mockWebServer.takeRequest(); verifyGetAllMetricsCall(recordedRequest); 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 8fff1c36d0..17f405df4b 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,7 +7,6 @@ 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; @@ -43,13 +42,12 @@ void testSearch() { Map> metricsResult = new HashMap<>(); metricsResult.put( "go_gc_duration_seconds", - singletonList( + List.of( new MetricMetadata( "summary", "A summary of the pause duration of garbage collection cycles.", ""))); metricsResult.put( "go_goroutines", - singletonList( - new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); + List.of(new MetricMetadata("gauge", "Number of goroutines that currently exist.", ""))); when(prometheusClient.getAllMetrics()).thenReturn(metricsResult); PrometheusListMetricsRequest prometheusListMetricsRequest = new PrometheusListMetricsRequest( diff --git a/sql/src/main/java/org/opensearch/sql/sql/parser/AstAggregationBuilder.java b/sql/src/main/java/org/opensearch/sql/sql/parser/AstAggregationBuilder.java index e46147b7a3..6ee0159d6e 100644 --- a/sql/src/main/java/org/opensearch/sql/sql/parser/AstAggregationBuilder.java +++ b/sql/src/main/java/org/opensearch/sql/sql/parser/AstAggregationBuilder.java @@ -5,8 +5,6 @@ package org.opensearch.sql.sql.parser; -import static java.util.Collections.emptyList; - import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -77,7 +75,7 @@ public UnresolvedPlan visit(ParseTree groupByClause) { private UnresolvedPlan buildExplicitAggregation() { List groupByItems = replaceGroupByItemIfAliasOrOrdinal(); - return new Aggregation(new ArrayList<>(querySpec.getAggregators()), emptyList(), groupByItems); + return new Aggregation(new ArrayList<>(querySpec.getAggregators()), List.of(), groupByItems); } private UnresolvedPlan buildImplicitAggregation() { @@ -93,7 +91,7 @@ private UnresolvedPlan buildImplicitAggregation() { } return new Aggregation( - new ArrayList<>(querySpec.getAggregators()), emptyList(), querySpec.getGroupByItems()); + new ArrayList<>(querySpec.getAggregators()), List.of(), querySpec.getGroupByItems()); } private List replaceGroupByItemIfAliasOrOrdinal() { 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 eb76875f16..5e7687e409 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,7 +5,6 @@ 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; @@ -109,7 +108,7 @@ public UnresolvedExpression visitColumnName(ColumnNameContext ctx) { @Override public UnresolvedExpression visitIdent(IdentContext ctx) { - return visitIdentifiers(singletonList(ctx)); + return visitIdentifiers(List.of(ctx)); } @Override @@ -253,7 +252,7 @@ public UnresolvedExpression visitIsNullPredicate(IsNullPredicateContext ctx) { ctx.nullNotnull().NOT() == null ? IS_NULL.getName().getFunctionName() : IS_NOT_NULL.getName().getFunctionName(), - singletonList(visit(ctx.predicate()))); + List.of(visit(ctx.predicate()))); } @Override diff --git a/sql/src/test/java/org/opensearch/sql/sql/parser/AstAggregationBuilderTest.java b/sql/src/test/java/org/opensearch/sql/sql/parser/AstAggregationBuilderTest.java index 95188e20b6..461e9e7688 100644 --- a/sql/src/test/java/org/opensearch/sql/sql/parser/AstAggregationBuilderTest.java +++ b/sql/src/test/java/org/opensearch/sql/sql/parser/AstAggregationBuilderTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.sql.parser; -import static java.util.Collections.emptyList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.equalTo; @@ -270,7 +269,7 @@ private Matcher featureValueOf( Function> getter, UnresolvedExpression... exprs) { Matcher> subMatcher = - (exprs.length == 0) ? equalTo(emptyList()) : equalTo(Arrays.asList(exprs)); + (exprs.length == 0) ? equalTo(List.of()) : equalTo(Arrays.asList(exprs)); return new FeatureMatcher>(subMatcher, name, "") { @Override protected List featureValueOf(UnresolvedPlan agg) {