diff --git a/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java b/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java index 549cec5c7f..c7fc9b4c50 100644 --- a/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java +++ b/core/src/test/java/org/opensearch/sql/executor/ExplainTest.java @@ -31,6 +31,7 @@ import static org.opensearch.sql.planner.physical.PhysicalPlanDSL.values; import static org.opensearch.sql.planner.physical.PhysicalPlanDSL.window; +import com.google.common.collect.ImmutableMap; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -57,8 +58,6 @@ import org.opensearch.sql.planner.physical.TrendlineOperator; import org.opensearch.sql.storage.TableScanOperator; -import com.google.common.collect.ImmutableMap; - @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class ExplainTest extends ExpressionTestBase { @@ -263,31 +262,41 @@ void can_explain_nested() { @Test void can_explain_trendline() { - PhysicalPlan plan = new TrendlineOperator(tableScan, Arrays.asList( - AstDSL.computation(2, AstDSL.field("distance"), "distance_alias", "sma"), - AstDSL.computation(3, AstDSL.field("time"), "time_alias", "sma"))); + PhysicalPlan plan = + new TrendlineOperator( + tableScan, + Arrays.asList( + AstDSL.computation(2, AstDSL.field("distance"), "distance_alias", "sma"), + AstDSL.computation(3, AstDSL.field("time"), "time_alias", "sma"))); assertEquals( new ExplainResponse( new ExplainResponseNode( "TrendlineOperator", - ImmutableMap.of("computations", List.of( - ImmutableMap.of( - "computationType", - "sma", - "numberOfDataPoints", 2, - "dataField", "distance", - "alias", "distance_alias"), - ImmutableMap.of( - "computationType", - "sma", - "numberOfDataPoints", 3, - "dataField", "time", - "alias", "time_alias"))), + ImmutableMap.of( + "computations", + List.of( + ImmutableMap.of( + "computationType", + "sma", + "numberOfDataPoints", + 2, + "dataField", + "distance", + "alias", + "distance_alias"), + ImmutableMap.of( + "computationType", + "sma", + "numberOfDataPoints", + 3, + "dataField", + "time", + "alias", + "time_alias"))), singletonList(tableScan.explainNode()))), explain.apply(plan)); } - private static class FakeTableScan extends TableScanOperator { @Override public boolean hasNext() { diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/TrendlineOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/TrendlineOperatorTest.java index 900a291e61..1a913fa31e 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/TrendlineOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/TrendlineOperatorTest.java @@ -10,9 +10,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; +import com.google.common.collect.ImmutableMap; import java.util.Arrays; import java.util.Collections; - import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -22,8 +22,6 @@ import org.opensearch.sql.ast.dsl.AstDSL; import org.opensearch.sql.data.model.ExprValueUtils; -import com.google.common.collect.ImmutableMap; - @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ExtendWith(MockitoExtension.class) public class TrendlineOperatorTest { @@ -35,12 +33,18 @@ public void calculates_simple_moving_average_one_field_one_sample() { when(inputPlan.next()) .thenReturn(ExprValueUtils.tupleValue(ImmutableMap.of("distance", 100, "time", 10))); - var plan = new TrendlineOperator(inputPlan, Collections.singletonList(AstDSL.computation( - 1, AstDSL.field("distance"), "distance_alias", "sma"))); + var plan = + new TrendlineOperator( + inputPlan, + Collections.singletonList( + AstDSL.computation(1, AstDSL.field("distance"), "distance_alias", "sma"))); plan.open(); assertTrue(plan.hasNext()); - assertEquals(ExprValueUtils.tupleValue(ImmutableMap.of("distance", 100, "time", 10, "distance_alias", 100)), plan.next()); + assertEquals( + ExprValueUtils.tupleValue( + ImmutableMap.of("distance", 100, "time", 10, "distance_alias", 100)), + plan.next()); } @Test @@ -51,15 +55,21 @@ public void calculates_simple_moving_average_one_field_two_samples() { ExprValueUtils.tupleValue(ImmutableMap.of("distance", 100, "time", 10)), ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 10))); - - var plan = new TrendlineOperator(inputPlan, Collections.singletonList(AstDSL.computation( - 2, AstDSL.field("distance"), "distance_alias", "sma"))); + var plan = + new TrendlineOperator( + inputPlan, + Collections.singletonList( + AstDSL.computation(2, AstDSL.field("distance"), "distance_alias", "sma"))); plan.open(); assertTrue(plan.hasNext()); - assertEquals(ExprValueUtils.tupleValue(ImmutableMap.of("distance", 100, "time", 10)), plan.next()); + assertEquals( + ExprValueUtils.tupleValue(ImmutableMap.of("distance", 100, "time", 10)), plan.next()); assertTrue(plan.hasNext()); - assertEquals(plan.next(), ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 10, "distance_alias", 150.0))); + assertEquals( + plan.next(), + ExprValueUtils.tupleValue( + ImmutableMap.of("distance", 200, "time", 10, "distance_alias", 150.0))); assertFalse(plan.hasNext()); } @@ -72,16 +82,26 @@ public void calculates_simple_moving_average_one_field_two_samples_three_rows() ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 10)), ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 10))); - var plan = new TrendlineOperator(inputPlan, Collections.singletonList(AstDSL.computation( - 2, AstDSL.field("distance"), "distance_alias", "sma"))); + var plan = + new TrendlineOperator( + inputPlan, + Collections.singletonList( + AstDSL.computation(2, AstDSL.field("distance"), "distance_alias", "sma"))); plan.open(); assertTrue(plan.hasNext()); - assertEquals(ExprValueUtils.tupleValue(ImmutableMap.of("distance", 100, "time", 10)), plan.next()); + assertEquals( + ExprValueUtils.tupleValue(ImmutableMap.of("distance", 100, "time", 10)), plan.next()); assertTrue(plan.hasNext()); - assertEquals(plan.next(), ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 10, "distance_alias", 150.0))); + assertEquals( + plan.next(), + ExprValueUtils.tupleValue( + ImmutableMap.of("distance", 200, "time", 10, "distance_alias", 150.0))); assertTrue(plan.hasNext()); - assertEquals(plan.next(), ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 10, "distance_alias", 200.0))); + assertEquals( + plan.next(), + ExprValueUtils.tupleValue( + ImmutableMap.of("distance", 200, "time", 10, "distance_alias", 200.0))); assertFalse(plan.hasNext()); } @@ -94,17 +114,29 @@ public void calculates_simple_moving_average_multiple_computations() { ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 20)), ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 20))); - var plan = new TrendlineOperator(inputPlan, Arrays.asList( - AstDSL.computation(2, AstDSL.field("distance"), "distance_alias", "sma"), - AstDSL.computation(2, AstDSL.field("time"), "time_alias", "sma"))); + var plan = + new TrendlineOperator( + inputPlan, + Arrays.asList( + AstDSL.computation(2, AstDSL.field("distance"), "distance_alias", "sma"), + AstDSL.computation(2, AstDSL.field("time"), "time_alias", "sma"))); plan.open(); assertTrue(plan.hasNext()); - assertEquals(ExprValueUtils.tupleValue(ImmutableMap.of("distance", 100, "time", 10)), plan.next()); + assertEquals( + ExprValueUtils.tupleValue(ImmutableMap.of("distance", 100, "time", 10)), plan.next()); assertTrue(plan.hasNext()); - assertEquals(plan.next(), ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 20, "distance_alias", 150.0, "time_alias", 15.0))); + assertEquals( + plan.next(), + ExprValueUtils.tupleValue( + ImmutableMap.of( + "distance", 200, "time", 20, "distance_alias", 150.0, "time_alias", 15.0))); assertTrue(plan.hasNext()); - assertEquals(plan.next(), ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 20, "distance_alias", 200.0, "time_alias", 20.0))); + assertEquals( + plan.next(), + ExprValueUtils.tupleValue( + ImmutableMap.of( + "distance", 200, "time", 20, "distance_alias", 200.0, "time_alias", 20.0))); assertFalse(plan.hasNext()); } @@ -116,16 +148,22 @@ public void alias_overwrites_input_field() { ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 10)), ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 10))); - var plan = new TrendlineOperator(inputPlan, Collections.singletonList(AstDSL.computation( - 2, AstDSL.field("distance"), "time", "sma"))); + var plan = + new TrendlineOperator( + inputPlan, + Collections.singletonList( + AstDSL.computation(2, AstDSL.field("distance"), "time", "sma"))); plan.open(); assertTrue(plan.hasNext()); - assertEquals(ExprValueUtils.tupleValue(ImmutableMap.of("distance", 100, "time", 100)), plan.next()); + assertEquals( + ExprValueUtils.tupleValue(ImmutableMap.of("distance", 100, "time", 100)), plan.next()); assertTrue(plan.hasNext()); - assertEquals(plan.next(), ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 150.0))); + assertEquals( + plan.next(), ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 150.0))); assertTrue(plan.hasNext()); - assertEquals(plan.next(), ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 200.0))); + assertEquals( + plan.next(), ExprValueUtils.tupleValue(ImmutableMap.of("distance", 200, "time", 200.0))); assertFalse(plan.hasNext()); } }