Skip to content

Commit 906ca1a

Browse files
committed
handle multivalued columns
1 parent ac48a09 commit 906ca1a

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/ChangePointOperator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.util.Deque;
2323
import java.util.LinkedList;
24+
import java.util.List;
2425

2526
/**
2627
* Find spikes, dips and change point in a list of values.
@@ -115,13 +116,17 @@ private void createOutputPages() {
115116
double[] values = new double[valuesCount];
116117
int valuesIndex = 0;
117118
boolean hasNulls = false;
119+
boolean hasMultivalued = false;
118120
for (Page inputPage : inputPages) {
119121
Block inputBlock = inputPage.getBlock(channel);
120122
for (int i = 0; i < inputBlock.getPositionCount() && valuesIndex < valuesCount; i++) {
121123
Object value = BlockUtils.toJavaObject(inputBlock, i);
122124
if (value == null) {
123125
hasNulls = true;
124126
values[valuesIndex++] = 0;
127+
} else if (value instanceof List<?> list) {
128+
hasMultivalued = true;
129+
values[valuesIndex++] = ((Number) list.getFirst()).doubleValue();
125130
} else {
126131
values[valuesIndex++] = ((Number) value).doubleValue();
127132
}
@@ -186,6 +191,9 @@ private void createOutputPages() {
186191
if (hasNulls) {
187192
warnings(true).registerException(new IllegalArgumentException("values contain nulls; treating them as zeroes"));
188193
}
194+
if (hasMultivalued) {
195+
warnings(true).registerException(new IllegalArgumentException("values is multivalued; keeping only first elements"));
196+
}
189197
}
190198

191199
@Override

x-pack/plugin/esql/qa/testFixtures/src/main/resources/change_point.csv-spec

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,74 @@ warning:Line 6:3: java.lang.IllegalArgumentException: values contain nulls; trea
247247
2024-05-10T00:21:00.000Z | 104 | null | null
248248
2024-05-10T00:22:00.000Z | 109 | null | null
249249
;
250+
251+
252+
multivalued
253+
required_capability: change_point
254+
255+
FROM employees
256+
| STATS salary=VALUES(salary) BY height
257+
| EVAL salary = CASE(height == 1.5, [1, 22222, 33333], salary)
258+
| EVAL salary = CASE(height == 1.63, [43210, -10000, 999999999], salary)
259+
| CHANGE_POINT salary ON height
260+
;
261+
262+
warning:Line 5:3: warnings during evaluation of [CHANGE_POINT salary ON height]. Only first 20 failures recorded.
263+
warning:Line 5:3: java.lang.IllegalArgumentException: values is multivalued; keeping only first elements
264+
265+
height:double | salary:integer | type:keyword | pvalue:double
266+
1.41 | 40031 | null | null
267+
1.42 | [29175, 39110] | null | null
268+
1.44 | [30404, 50128] | null | null
269+
1.45 | 49095 | null | null
270+
1.46 | 39878 | null | null
271+
1.47 | 60408 | null | null
272+
1.48 | 44307 | null | null
273+
1.5 | [1, 22222, 33333] | dip | 6.483898939160238E-4
274+
1.51 | 28035 | null | null
275+
1.52 | [34341, 50064, 42716, 37853] | null | null
276+
1.53 | [73851, 35222, 71165] | null | null
277+
1.54 | 61358 | null | null
278+
1.55 | [36051, 37702] | null | null
279+
1.56 | 60335 | null | null
280+
1.57 | [33370, 43602] | null | null
281+
1.58 | [54462, 28941] | null | null
282+
1.59 | [27215, 50249, 32263] | null | null
283+
1.61 | [60781, 49818] | null | null
284+
1.63 | [43210, -10000, 999999999] | null | null
285+
1.64 | 38992 | null | null
286+
1.66 | [25324, 32568] | null | null
287+
1.68 | [37716, 46595] | null | null
288+
1.69 | 45656 | null | null
289+
1.7 | [74572, 45797, 74970, 65030] | null | null
290+
1.74 | [58715, 68547, 32272] | null | null
291+
1.75 | [47896, 56415, 25976] | null | null
292+
1.77 | [52044, 41933, 54329, 68431] | null | null
293+
1.78 | [36174, 52121] | null | null
294+
1.79 | 55360 | null | null
295+
1.8 | 52833 | null | null
296+
1.81 | [25945, 69904, 73578] | null | null
297+
1.82 | [48233, 65367, 54518] | null | null
298+
1.83 | [61805, 38376, 62405] | null | null
299+
1.85 | 66174 | null | null
300+
1.87 | 47411 | null | null
301+
1.89 | 58121 | null | null
302+
1.9 | 37112 | null | null
303+
1.91 | 39638 | null | null
304+
1.92 | 67492 | null | null
305+
1.93 | 33956 | null | null
306+
1.94 | [48735, 51956, 43889] | null | null
307+
1.96 | 43026 | null | null
308+
1.97 | [48942, 56760] | null | null
309+
1.99 | [37137, 74999] | null | null
310+
2.0 | [37691, 26436, 44817] | null | null
311+
2.01 | 35742 | null | null
312+
2.03 | [57305, 44956] | null | null
313+
2.04 | 49281 | null | null
314+
2.05 | 63528 | null | null
315+
2.06 | [73717, 39728] | null | null
316+
2.07 | [39356, 40612] | null | null
317+
2.08 | [56371, 64675] | null | null
318+
2.09 | 38645 | null | null
319+
2.1 | [43906, 28336, 62233, 31897, 66817] | null | null
320+
;

0 commit comments

Comments
 (0)