Skip to content

Commit

Permalink
Spotless
Browse files Browse the repository at this point in the history
Signed-off-by: James Duong <[email protected]>
  • Loading branch information
jduo committed Oct 23, 2024
1 parent ef30957 commit e1d940c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
6 changes: 4 additions & 2 deletions core/src/main/java/org/opensearch/sql/analysis/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,10 @@ public LogicalPlan visitTrendline(Trendline node, AnalysisContext context) {
.map(expression -> (Trendline.TrendlineComputation) expression)
.toList();

computations.forEach(computation -> currEnv.define(
new Symbol(Namespace.FIELD_NAME, computation.getAlias()), ExprCoreType.DOUBLE));
computations.forEach(
computation ->
currEnv.define(
new Symbol(Namespace.FIELD_NAME, computation.getAlias()), ExprCoreType.DOUBLE));
return new LogicalTrendline(child, computations);
}

Expand Down
8 changes: 3 additions & 5 deletions core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,13 @@ public static Limit limit(UnresolvedPlan input, Integer limit, Integer offset) {
return new Limit(limit, offset).attach(input);
}

public static Trendline trendline(UnresolvedPlan input, Trendline.TrendlineComputation... computations) {
public static Trendline trendline(
UnresolvedPlan input, Trendline.TrendlineComputation... computations) {
return new Trendline(Arrays.asList(computations)).attach(input);
}

public static Trendline.TrendlineComputation computation(
Integer numDataPoints,
UnresolvedExpression dataField,
String alias,
String type) {
Integer numDataPoints, UnresolvedExpression dataField, String alias, String type) {
return new Trendline.TrendlineComputation(numDataPoints, dataField, alias, type);
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/opensearch/sql/ast/tree/Trendline.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Locale;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -58,7 +57,8 @@ public TrendlineComputation(
this.numberOfDataPoints = numberOfDataPoints;
this.dataField = dataField;
this.alias = alias;
this.computationType = Trendline.TrendlineType.valueOf(computationType.toUpperCase(Locale.ROOT));
this.computationType =
Trendline.TrendlineType.valueOf(computationType.toUpperCase(Locale.ROOT));
}

@Override
Expand Down
13 changes: 8 additions & 5 deletions core/src/main/java/org/opensearch/sql/executor/Explain.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,10 @@ public ExplainResponseNode visitTrendline(TrendlineOperator node, Object context
return explain(
node,
context,
explainNode -> explainNode.setDescription(
ImmutableMap.of("computations", describeTrendlineComputations(node.getComputations()))));
explainNode ->
explainNode.setDescription(
ImmutableMap.of(
"computations", describeTrendlineComputations(node.getComputations()))));
}

protected ExplainResponseNode explain(
Expand Down Expand Up @@ -261,13 +263,14 @@ private Map<String, Map<String, String>> describeSortList(
private List<Map<String, String>> describeTrendlineComputations(
List<Trendline.TrendlineComputation> computations) {
return computations.stream()
.map(computation ->
.map(
computation ->
ImmutableMap.of(
"computationType", computation.getComputationType().name().toLowerCase(Locale.ROOT),
"computationType",
computation.getComputationType().name().toLowerCase(Locale.ROOT),
"numberOfDataPoints", computation.getNumberOfDataPoints().toString(),
"dataField", computation.getDataField().getChild().get(0).toString(),
"alias", computation.getAlias() != null ? computation.getAlias() : ""))
.collect(Collectors.toList());
}

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

package org.opensearch.sql.planner.physical;

import org.opensearch.sql.ast.tree.Trendline;
import org.opensearch.sql.storage.TableScanOperator;
import org.opensearch.sql.storage.write.TableWriteOperator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public ExprValue next() {
if (null != computations.get(i).getAlias()) {
mapBuilder.put(computations.get(i).getAlias(), calculateResult);
} else {
mapBuilder.put(computations.get(i).getDataField().getChild().get(0).toString(), calculateResult);
mapBuilder.put(
computations.get(i).getDataField().getChild().get(0).toString(), calculateResult);
}
}
result = ExprTupleValue.fromExprValueMap(mapBuilder.buildKeepingLast());
Expand Down Expand Up @@ -180,9 +181,7 @@ public ExprValue calculate() {
private static class WeightedMovingAverageAccumulator implements TrendlineAccumulator {

@Override
public void accumulate(ExprValue value) {

}
public void accumulate(ExprValue value) {}

@Override
public ExprValue calculate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ public String visitTrendlineComputation(Trendline.TrendlineComputation node, Str
final String dataField = node.getDataField().accept(this, context);
final String aliasOrEmpty = node.getAlias() != null ? " as " + node.getAlias() : "";
final String computationType = node.getComputationType().name().toLowerCase(Locale.ROOT);
return StringUtils.format("%s(%d, %s)%s",
computationType, node.getNumberOfDataPoints(), dataField, aliasOrEmpty);
return StringUtils.format(
"%s(%d, %s)%s", computationType, node.getNumberOfDataPoints(), dataField, aliasOrEmpty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -665,12 +665,12 @@ public void testMLCommand() {
@Test
public void testTrendline() {
assertEqual(
"source=t | trendline sma(5, test_field) as test_field_alias sma(1, test_field_2) as test_field_alias_2",
"source=t | trendline sma(5, test_field) as test_field_alias sma(1, test_field_2) as"
+ " test_field_alias_2",
trendline(
relation("t"),
computation(5, field("test_field"), "test_field_alias", "sma"),
computation(1, field("test_field)2"), "test_field_alias_2", "sma")
));
computation(1, field("test_field)2"), "test_field_alias_2", "sma")));
}

@Test
Expand Down

0 comments on commit e1d940c

Please sign in to comment.