Skip to content

Commit

Permalink
Revert changes not specifically related to Arrays.asList
Browse files Browse the repository at this point in the history
Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Dec 12, 2024
1 parent 5ce52a7 commit cf88869
Show file tree
Hide file tree
Showing 65 changed files with 385 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

package org.opensearch.sql.common.interceptors;

import static java.util.Collections.singletonList;

import java.util.Collections;
import lombok.SneakyThrows;
import okhttp3.Credentials;
import okhttp3.Interceptor;
Expand Down Expand Up @@ -48,7 +47,7 @@ void testIntercept() {
Mockito.verify(chain).proceed(requestArgumentCaptor.capture());
Request request = requestArgumentCaptor.getValue();
Assertions.assertEquals(
singletonList(Credentials.basic("testAdmin", "testPassword")),
Collections.singletonList(Credentials.basic("testAdmin", "testPassword")),
request.headers("Authorization"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -82,7 +83,9 @@ public Expression visitCast(Cast node, AnalysisContext context) {
final Expression expression = node.getExpression().accept(this, context);
return (Expression)
repository.compile(
context.getFunctionProperties(), node.convertFunctionName(), List.of(expression));
context.getFunctionProperties(),
node.convertFunctionName(),
Collections.singletonList(expression));
}

public ExpressionAnalyzer(BuiltinFunctionRepository repository) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.opensearch.sql.analysis;

import com.google.common.collect.ImmutableList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -53,7 +54,7 @@ public List<NamedExpression> analyze(

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

@Override
Expand All @@ -64,7 +65,8 @@ public List<NamedExpression> visitAlias(Alias node, AnalysisContext context) {
}

Expression expr = referenceIfSymbolDefined(node, context);
return List.of(DSL.named(unqualifiedNameIfFieldOnly(node, context), expr, node.getAlias()));
return Collections.singletonList(
DSL.named(unqualifiedNameIfFieldOnly(node, context), expr, node.getAlias()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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 @@ -87,7 +88,7 @@ public Map<String, ExprType> lookupByPrefix(Symbol prefix) {
if (table != null) {
return table.subMap(prefix.getName(), prefix.getName() + Character.MAX_VALUE);
}
return Map.of();
return emptyMap();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.opensearch.sql.ast.expression;

import java.util.Collections;
import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand Down Expand Up @@ -41,7 +42,7 @@ public class AggregateFunction extends UnresolvedExpression {
public AggregateFunction(String funcName, UnresolvedExpression field) {
this.funcName = funcName;
this.field = field;
this.argList = List.of();
this.argList = Collections.emptyList();
}

/**
Expand All @@ -54,13 +55,13 @@ public AggregateFunction(String funcName, UnresolvedExpression field) {
public AggregateFunction(String funcName, UnresolvedExpression field, Boolean distinct) {
this.funcName = funcName;
this.field = field;
this.argList = List.of();
this.argList = Collections.emptyList();
this.distinct = distinct;
}

@Override
public List<UnresolvedExpression> getChild() {
return List.of(field);
return Collections.singletonList(field);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_TIMESTAMP;

import com.google.common.collect.ImmutableMap;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -98,7 +99,7 @@ public FunctionName convertFunctionName() {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.opensearch.sql.ast.expression;

import java.util.Collections;
import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -28,7 +29,7 @@ public Interval(UnresolvedExpression value, String unit) {

@Override
public List<UnresolvedExpression> getChild() {
return List.of(value);
return Collections.singletonList(value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.StreamSupport;
Expand All @@ -24,7 +25,7 @@ public class QualifiedName extends UnresolvedExpression {
private final List<String> parts;

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

/** QualifiedName Constructor. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

package org.opensearch.sql.storage.write;

import static java.util.Collections.singletonList;

import java.util.Collections;
import org.opensearch.sql.planner.logical.LogicalPlan;
import org.opensearch.sql.planner.logical.LogicalPlanNodeVisitor;
import org.opensearch.sql.planner.physical.PhysicalPlan;
Expand All @@ -21,7 +20,7 @@ public abstract class TableWriteBuilder extends LogicalPlan {

/** Construct table write builder with child node. */
public TableWriteBuilder(LogicalPlan child) {
super(singletonList(child));
super(Collections.singletonList(child));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.opensearch.sql.storage.write;

import java.util.Collections;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.opensearch.sql.planner.physical.PhysicalPlan;
Expand All @@ -28,7 +29,7 @@ public <R, C> R accept(PhysicalPlanNodeVisitor<R, C> visitor, C context) {

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

/**
Expand Down
56 changes: 29 additions & 27 deletions core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.opensearch.sql.analysis;

import static java.util.Collections.emptyList;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -61,6 +62,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -406,9 +408,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")))),
List.of(),
emptyList(),
ImmutableList.of(alias("string_value", qualifiedName("string_value"))),
List.of()),
emptyList()),
compare(">", aggregate("MIN", qualifiedName("integer_value")), intLiteral(10))));
}

Expand Down Expand Up @@ -489,7 +491,7 @@ public void rename_to_invalid_expression() {
AstDSL.alias(
"avg(integer_value)",
AstDSL.aggregate("avg", field("integer_value")))),
List.of(),
Collections.emptyList(),
ImmutableList.of(),
AstDSL.defaultStatsArgs()),
AstDSL.map(
Expand Down Expand Up @@ -892,7 +894,7 @@ public void remove_source() {
DSL.ref("double_value", DOUBLE)),
AstDSL.projectWithArg(
AstDSL.relation("schema"),
List.of(argument("exclude", booleanLiteral(true))),
Collections.singletonList(argument("exclude", booleanLiteral(true))),
AstDSL.field("integer_value"),
AstDSL.field("double_value")));
}
Expand Down Expand Up @@ -954,9 +956,9 @@ public void sort_with_aggregator() {
ImmutableList.of(
AstDSL.alias(
"avg(integer_value)", function("avg", qualifiedName("integer_value")))),
List.of(),
emptyList(),
ImmutableList.of(AstDSL.alias("string_value", qualifiedName("string_value"))),
List.of()),
emptyList()),
field(
function("avg", qualifiedName("integer_value")),
argument("asc", booleanLiteral(true)))),
Expand Down Expand Up @@ -1039,8 +1041,8 @@ public void window_function() {
"window_function",
AstDSL.window(
AstDSL.function("row_number"),
List.of(AstDSL.qualifiedName("string_value")),
List.of(
Collections.singletonList(AstDSL.qualifiedName("string_value")),
Collections.singletonList(
ImmutablePair.of(DEFAULT_ASC, AstDSL.qualifiedName("integer_value")))))));
}

Expand Down Expand Up @@ -1096,13 +1098,13 @@ public void nested_group_by_clause_throws_syntax_exception() {
AstDSL.project(
AstDSL.agg(
AstDSL.relation("schema"),
List.of(),
List.of(),
emptyList(),
emptyList(),
ImmutableList.of(
alias(
"nested(message.info)",
function("nested", qualifiedName("message", "info")))),
List.of()))));
emptyList()))));
assertEquals(
"Falling back to legacy engine. Nested function is not supported in WHERE,"
+ " GROUP BY, and HAVING clauses.",
Expand All @@ -1126,9 +1128,9 @@ public void sql_group_by_field() {
AstDSL.relation("schema"),
ImmutableList.of(
alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))),
List.of(),
emptyList(),
ImmutableList.of(alias("string_value", qualifiedName("string_value"))),
List.of()),
emptyList()),
AstDSL.alias("string_value", qualifiedName("string_value")),
AstDSL.alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))));
}
Expand All @@ -1151,10 +1153,10 @@ public void sql_group_by_function() {
AstDSL.relation("schema"),
ImmutableList.of(
alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))),
List.of(),
emptyList(),
ImmutableList.of(
alias("abs(long_value)", function("abs", qualifiedName("long_value")))),
List.of()),
emptyList()),
AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))),
AstDSL.alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))));
}
Expand All @@ -1177,10 +1179,10 @@ public void sql_group_by_function_in_uppercase() {
AstDSL.relation("schema"),
ImmutableList.of(
alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))),
List.of(),
emptyList(),
ImmutableList.of(
alias("ABS(long_value)", function("ABS", qualifiedName("long_value")))),
List.of()),
emptyList()),
AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))),
AstDSL.alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))));
}
Expand All @@ -1203,10 +1205,10 @@ public void sql_expression_over_one_aggregation() {
AstDSL.relation("schema"),
ImmutableList.of(
alias("avg(integer_value)", aggregate("avg", qualifiedName("integer_value")))),
List.of(),
emptyList(),
ImmutableList.of(
alias("abs(long_value)", function("abs", qualifiedName("long_value")))),
List.of()),
emptyList()),
AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))),
AstDSL.alias(
"abs(avg(integer_value)",
Expand Down Expand Up @@ -1237,10 +1239,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")))),
List.of(),
emptyList(),
ImmutableList.of(
alias("abs(long_value)", function("abs", qualifiedName("long_value")))),
List.of()),
emptyList()),
AstDSL.alias("abs(long_value)", function("abs", qualifiedName("long_value"))),
AstDSL.alias(
"sum(integer_value)-avg(integer_value)",
Expand Down Expand Up @@ -1278,7 +1280,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))))),
List.of()),
emptyList()),
DSL.named(
"count(string_value) filter(where integer_value > 1)",
DSL.ref("count(string_value) filter(where integer_value > 1)", INTEGER))),
Expand All @@ -1292,9 +1294,9 @@ public void named_aggregator_with_condition() {
"count",
qualifiedName("string_value"),
function(">", qualifiedName("integer_value"), intLiteral(1))))),
List.of(),
List.of(),
List.of()),
emptyList(),
emptyList(),
emptyList()),
AstDSL.alias(
"count(string_value) filter(where integer_value > 1)",
filteredAggregate(
Expand All @@ -1318,10 +1320,10 @@ public void ppl_stats_by_fieldAndSpan() {
AstDSL.relation("schema"),
ImmutableList.of(
alias("AVG(integer_value)", aggregate("AVG", qualifiedName("integer_value")))),
List.of(),
emptyList(),
ImmutableList.of(alias("string_value", qualifiedName("string_value"))),
alias("span", span(field("long_value"), intLiteral(10), SpanUnit.NONE)),
List.of()));
emptyList()));
}

@Test
Expand Down
Loading

0 comments on commit cf88869

Please sign in to comment.