From e1d940c65c403051333a8051c158c7639268711f Mon Sep 17 00:00:00 2001 From: James Duong Date: Wed, 23 Oct 2024 13:30:58 -0700 Subject: [PATCH] Spotless Signed-off-by: James Duong --- .../java/org/opensearch/sql/analysis/Analyzer.java | 6 ++++-- .../java/org/opensearch/sql/ast/dsl/AstDSL.java | 8 +++----- .../java/org/opensearch/sql/ast/tree/Trendline.java | 4 ++-- .../java/org/opensearch/sql/executor/Explain.java | 13 ++++++++----- .../planner/physical/PhysicalPlanNodeVisitor.java | 1 - .../sql/planner/physical/TrendlineOperator.java | 7 +++---- .../sql/ppl/utils/PPLQueryDataAnonymizer.java | 4 ++-- .../opensearch/sql/ppl/parser/AstBuilderTest.java | 6 +++--- 8 files changed, 25 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java b/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java index 02c9ed067d..2b70f84158 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/Analyzer.java @@ -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); } diff --git a/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java b/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java index ec93a915a8..f3acd70fce 100644 --- a/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java +++ b/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java @@ -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); } diff --git a/core/src/main/java/org/opensearch/sql/ast/tree/Trendline.java b/core/src/main/java/org/opensearch/sql/ast/tree/Trendline.java index 8858353b6b..f58527621d 100644 --- a/core/src/main/java/org/opensearch/sql/ast/tree/Trendline.java +++ b/core/src/main/java/org/opensearch/sql/ast/tree/Trendline.java @@ -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; @@ -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 diff --git a/core/src/main/java/org/opensearch/sql/executor/Explain.java b/core/src/main/java/org/opensearch/sql/executor/Explain.java index baedea0fa4..096fb240dd 100644 --- a/core/src/main/java/org/opensearch/sql/executor/Explain.java +++ b/core/src/main/java/org/opensearch/sql/executor/Explain.java @@ -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( @@ -261,13 +263,14 @@ private Map> describeSortList( private List> describeTrendlineComputations( List 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()); } - } diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitor.java b/core/src/main/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitor.java index ac2740b76d..66c7219e39 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitor.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/PhysicalPlanNodeVisitor.java @@ -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; diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/TrendlineOperator.java b/core/src/main/java/org/opensearch/sql/planner/physical/TrendlineOperator.java index 8a0bfa87c9..ad6cc32158 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/TrendlineOperator.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/TrendlineOperator.java @@ -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()); @@ -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() { diff --git a/ppl/src/main/java/org/opensearch/sql/ppl/utils/PPLQueryDataAnonymizer.java b/ppl/src/main/java/org/opensearch/sql/ppl/utils/PPLQueryDataAnonymizer.java index 7e622489ba..701989ba70 100644 --- a/ppl/src/main/java/org/opensearch/sql/ppl/utils/PPLQueryDataAnonymizer.java +++ b/ppl/src/main/java/org/opensearch/sql/ppl/utils/PPLQueryDataAnonymizer.java @@ -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); } } } diff --git a/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest.java b/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest.java index 14912591d0..4931689cfb 100644 --- a/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest.java +++ b/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest.java @@ -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