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 25, 2024
1 parent 8c8cb3e commit 78b8127
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 46 deletions.
47 changes: 28 additions & 19 deletions core/src/test/java/org/opensearch/sql/executor/ExplainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

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

Expand All @@ -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());
}

Expand All @@ -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());
}

Expand All @@ -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());
}
}

0 comments on commit 78b8127

Please sign in to comment.