10
10
import static org .junit .jupiter .api .Assertions .assertTrue ;
11
11
import static org .mockito .Mockito .when ;
12
12
13
+ import com .google .common .collect .ImmutableMap ;
13
14
import java .util .Arrays ;
14
15
import java .util .Collections ;
15
-
16
16
import org .junit .jupiter .api .DisplayNameGeneration ;
17
17
import org .junit .jupiter .api .DisplayNameGenerator ;
18
18
import org .junit .jupiter .api .Test ;
22
22
import org .opensearch .sql .ast .dsl .AstDSL ;
23
23
import org .opensearch .sql .data .model .ExprValueUtils ;
24
24
25
- import com .google .common .collect .ImmutableMap ;
26
-
27
25
@ DisplayNameGeneration (DisplayNameGenerator .ReplaceUnderscores .class )
28
26
@ ExtendWith (MockitoExtension .class )
29
27
public class TrendlineOperatorTest {
@@ -35,12 +33,18 @@ public void calculates_simple_moving_average_one_field_one_sample() {
35
33
when (inputPlan .next ())
36
34
.thenReturn (ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 100 , "time" , 10 )));
37
35
38
- var plan = new TrendlineOperator (inputPlan , Collections .singletonList (AstDSL .computation (
39
- 1 , AstDSL .field ("distance" ), "distance_alias" , "sma" )));
36
+ var plan =
37
+ new TrendlineOperator (
38
+ inputPlan ,
39
+ Collections .singletonList (
40
+ AstDSL .computation (1 , AstDSL .field ("distance" ), "distance_alias" , "sma" )));
40
41
41
42
plan .open ();
42
43
assertTrue (plan .hasNext ());
43
- assertEquals (ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 100 , "time" , 10 , "distance_alias" , 100 )), plan .next ());
44
+ assertEquals (
45
+ ExprValueUtils .tupleValue (
46
+ ImmutableMap .of ("distance" , 100 , "time" , 10 , "distance_alias" , 100 )),
47
+ plan .next ());
44
48
}
45
49
46
50
@ Test
@@ -51,15 +55,21 @@ public void calculates_simple_moving_average_one_field_two_samples() {
51
55
ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 100 , "time" , 10 )),
52
56
ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 10 )));
53
57
54
-
55
- var plan = new TrendlineOperator (inputPlan , Collections .singletonList (AstDSL .computation (
56
- 2 , AstDSL .field ("distance" ), "distance_alias" , "sma" )));
58
+ var plan =
59
+ new TrendlineOperator (
60
+ inputPlan ,
61
+ Collections .singletonList (
62
+ AstDSL .computation (2 , AstDSL .field ("distance" ), "distance_alias" , "sma" )));
57
63
58
64
plan .open ();
59
65
assertTrue (plan .hasNext ());
60
- assertEquals (ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 100 , "time" , 10 )), plan .next ());
66
+ assertEquals (
67
+ ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 100 , "time" , 10 )), plan .next ());
61
68
assertTrue (plan .hasNext ());
62
- assertEquals (plan .next (), ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 10 , "distance_alias" , 150.0 )));
69
+ assertEquals (
70
+ plan .next (),
71
+ ExprValueUtils .tupleValue (
72
+ ImmutableMap .of ("distance" , 200 , "time" , 10 , "distance_alias" , 150.0 )));
63
73
assertFalse (plan .hasNext ());
64
74
}
65
75
@@ -72,16 +82,26 @@ public void calculates_simple_moving_average_one_field_two_samples_three_rows()
72
82
ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 10 )),
73
83
ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 10 )));
74
84
75
- var plan = new TrendlineOperator (inputPlan , Collections .singletonList (AstDSL .computation (
76
- 2 , AstDSL .field ("distance" ), "distance_alias" , "sma" )));
85
+ var plan =
86
+ new TrendlineOperator (
87
+ inputPlan ,
88
+ Collections .singletonList (
89
+ AstDSL .computation (2 , AstDSL .field ("distance" ), "distance_alias" , "sma" )));
77
90
78
91
plan .open ();
79
92
assertTrue (plan .hasNext ());
80
- assertEquals (ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 100 , "time" , 10 )), plan .next ());
93
+ assertEquals (
94
+ ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 100 , "time" , 10 )), plan .next ());
81
95
assertTrue (plan .hasNext ());
82
- assertEquals (plan .next (), ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 10 , "distance_alias" , 150.0 )));
96
+ assertEquals (
97
+ plan .next (),
98
+ ExprValueUtils .tupleValue (
99
+ ImmutableMap .of ("distance" , 200 , "time" , 10 , "distance_alias" , 150.0 )));
83
100
assertTrue (plan .hasNext ());
84
- assertEquals (plan .next (), ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 10 , "distance_alias" , 200.0 )));
101
+ assertEquals (
102
+ plan .next (),
103
+ ExprValueUtils .tupleValue (
104
+ ImmutableMap .of ("distance" , 200 , "time" , 10 , "distance_alias" , 200.0 )));
85
105
assertFalse (plan .hasNext ());
86
106
}
87
107
@@ -94,17 +114,29 @@ public void calculates_simple_moving_average_multiple_computations() {
94
114
ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 20 )),
95
115
ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 20 )));
96
116
97
- var plan = new TrendlineOperator (inputPlan , Arrays .asList (
98
- AstDSL .computation (2 , AstDSL .field ("distance" ), "distance_alias" , "sma" ),
99
- AstDSL .computation (2 , AstDSL .field ("time" ), "time_alias" , "sma" )));
117
+ var plan =
118
+ new TrendlineOperator (
119
+ inputPlan ,
120
+ Arrays .asList (
121
+ AstDSL .computation (2 , AstDSL .field ("distance" ), "distance_alias" , "sma" ),
122
+ AstDSL .computation (2 , AstDSL .field ("time" ), "time_alias" , "sma" )));
100
123
101
124
plan .open ();
102
125
assertTrue (plan .hasNext ());
103
- assertEquals (ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 100 , "time" , 10 )), plan .next ());
126
+ assertEquals (
127
+ ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 100 , "time" , 10 )), plan .next ());
104
128
assertTrue (plan .hasNext ());
105
- assertEquals (plan .next (), ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 20 , "distance_alias" , 150.0 , "time_alias" , 15.0 )));
129
+ assertEquals (
130
+ plan .next (),
131
+ ExprValueUtils .tupleValue (
132
+ ImmutableMap .of (
133
+ "distance" , 200 , "time" , 20 , "distance_alias" , 150.0 , "time_alias" , 15.0 )));
106
134
assertTrue (plan .hasNext ());
107
- assertEquals (plan .next (), ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 20 , "distance_alias" , 200.0 , "time_alias" , 20.0 )));
135
+ assertEquals (
136
+ plan .next (),
137
+ ExprValueUtils .tupleValue (
138
+ ImmutableMap .of (
139
+ "distance" , 200 , "time" , 20 , "distance_alias" , 200.0 , "time_alias" , 20.0 )));
108
140
assertFalse (plan .hasNext ());
109
141
}
110
142
@@ -116,16 +148,22 @@ public void alias_overwrites_input_field() {
116
148
ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 10 )),
117
149
ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 10 )));
118
150
119
- var plan = new TrendlineOperator (inputPlan , Collections .singletonList (AstDSL .computation (
120
- 2 , AstDSL .field ("distance" ), "time" , "sma" )));
151
+ var plan =
152
+ new TrendlineOperator (
153
+ inputPlan ,
154
+ Collections .singletonList (
155
+ AstDSL .computation (2 , AstDSL .field ("distance" ), "time" , "sma" )));
121
156
122
157
plan .open ();
123
158
assertTrue (plan .hasNext ());
124
- assertEquals (ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 100 , "time" , 100 )), plan .next ());
159
+ assertEquals (
160
+ ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 100 , "time" , 100 )), plan .next ());
125
161
assertTrue (plan .hasNext ());
126
- assertEquals (plan .next (), ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 150.0 )));
162
+ assertEquals (
163
+ plan .next (), ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 150.0 )));
127
164
assertTrue (plan .hasNext ());
128
- assertEquals (plan .next (), ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 200.0 )));
165
+ assertEquals (
166
+ plan .next (), ExprValueUtils .tupleValue (ImmutableMap .of ("distance" , 200 , "time" , 200.0 )));
129
167
assertFalse (plan .hasNext ());
130
168
}
131
169
}
0 commit comments