Skip to content

Commit

Permalink
More replacement of Collections.singletonList, emptyList, and `em…
Browse files Browse the repository at this point in the history
…ptyMap` with `List.of`/`Map.of` in cases where `List`/`Map` is already imported.

Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Dec 9, 2024
1 parent c603113 commit 8bb0f87
Show file tree
Hide file tree
Showing 70 changed files with 268 additions and 396 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -183,7 +182,7 @@ private void cancel(Cancellable cron) {

@VisibleForTesting
public List<Cancellable> getFlintIndexRetentionCron() {
return singletonList(flintIndexRetentionCron);
return List.of(flintIndexRetentionCron);
}

private String executorName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,7 +53,7 @@ public List<NamedExpression> analyze(

@Override
public List<NamedExpression> visitField(Field node, AnalysisContext context) {
return singletonList(DSL.named(node.accept(expressionAnalyzer, context)));
return List.of(DSL.named(node.accept(expressionAnalyzer, context)));
}

@Override
Expand All @@ -66,8 +64,7 @@ public List<NamedExpression> 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()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,7 +87,7 @@ public Map<String, ExprType> lookupByPrefix(Symbol prefix) {
if (table != null) {
return table.subMap(prefix.getName(), prefix.getName() + Character.MAX_VALUE);
}
return emptyMap();
return Map.of();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,7 +98,7 @@ public FunctionName convertFunctionName() {

@Override
public List<? extends Node> getChild() {
return singletonList(expression);
return List.of(expression);
}

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

Expand All @@ -25,7 +24,7 @@ public class QualifiedName extends UnresolvedExpression {
private final List<String> parts;

public QualifiedName(String name) {
this.parts = singletonList(name);
this.parts = List.of(name);
}

/** QualifiedName Constructor. */
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/java/org/opensearch/sql/ast/tree/Relation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,10 +67,10 @@ public static DefaultFunctionResolver define(
implWithProperties(
SerializableFunction<FunctionProperties, ExprValue> 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<Expression, ExprValue> valueEnv) {
return function.apply(functionProperties);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +27,7 @@ public LogicalNested(
LogicalPlan childPlan,
List<Map<String, ReferenceExpression>> fields,
List<NamedExpression> projectList) {
super(List.of(childPlan));
super(Collections.singletonList(childPlan));
this.fields = fields;
this.projectList = projectList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.opensearch.sql.planner.logical;

import java.util.Collections;
import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -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<String> columns) {
super(List.of(child));
super(Collections.singletonList(child));
this.table = table;
this.columns = columns;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,7 +58,7 @@ public <R, C> R accept(PhysicalPlanNodeVisitor<R, C> visitor, C context) {

@Override
public List<PhysicalPlan> getChild() {
return singletonList(input);
return List.of(input);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,7 +77,7 @@ public <R, C> R accept(PhysicalPlanNodeVisitor<R, C> visitor, C context) {

@Override
public List<PhysicalPlan> getChild() {
return singletonList(input);
return List.of(input);
}

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

Expand Down Expand Up @@ -50,7 +49,7 @@ public <R, C> R accept(PhysicalPlanNodeVisitor<R, C> visitor, C context) {

@Override
public List<PhysicalPlan> getChild() {
return singletonList(input);
return List.of(input);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,7 +41,7 @@ public <R, C> R accept(PhysicalPlanNodeVisitor<R, C> visitor, C context) {

@Override
public List<PhysicalPlan> getChild() {
return singletonList(input);
return List.of(input);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,7 +83,7 @@ public <R, C> R accept(PhysicalPlanNodeVisitor<R, C> visitor, C context) {

@Override
public List<PhysicalPlan> getChild() {
return singletonList(input);
return List.of(input);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,7 +48,7 @@ public <R, C> R accept(PhysicalPlanNodeVisitor<R, C> visitor, C context) {

@Override
public List<PhysicalPlan> getChild() {
return singletonList(input);
return List.of(input);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +55,7 @@ public <R, C> R accept(PhysicalPlanNodeVisitor<R, C> visitor, C context) {

@Override
public List<PhysicalPlan> getChild() {
return singletonList(input);
return List.of(input);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,7 +62,7 @@ public void open() {

@Override
public List<PhysicalPlan> getChild() {
return singletonList(input);
return List.of(input);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,7 +72,7 @@ public void open() {

@Override
public List<PhysicalPlan> getChild() {
return singletonList(input);
return List.of(input);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,7 +61,7 @@ public <R, C> R accept(PhysicalPlanNodeVisitor<R, C> visitor, C context) {

@Override
public List<PhysicalPlan> getChild() {
return singletonList(input);
return List.of(input);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,6 +56,6 @@ public void collect(BindingTuple input) {
public List<ExprValue> results() {
LinkedHashMap<String, ExprValue> 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));
}
}
Loading

0 comments on commit 8bb0f87

Please sign in to comment.