Skip to content

Commit 96e6d6a

Browse files
committed
error on MV
1 parent 2b137ca commit 96e6d6a

File tree

2 files changed

+92
-15
lines changed

2 files changed

+92
-15
lines changed

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,28 @@ private void createOutputPages() {
126126
if (value == null) {
127127
hasNulls = true;
128128
valuesIndex++;
129-
} else if (value instanceof List<?> list) {
129+
} else if (value instanceof List<?>) {
130130
hasMultivalued = true;
131-
values.add(((Number) list.getFirst()).doubleValue());
132131
} else {
133132
values.add(((Number) value).doubleValue());
134133
bucketIndexes.add(valuesIndex++);
135134
}
136135
}
137136
}
138-
MlAggsHelper.DoubleBucketValues bucketValues = new MlAggsHelper.DoubleBucketValues(
139-
null,
140-
values.stream().mapToDouble(Double::doubleValue).toArray(),
141-
bucketIndexes.stream().mapToInt(Integer::intValue).toArray()
142-
);
143-
ChangeType changeType = ChangePointDetector.getChangeType(bucketValues);
144-
int changePointIndex = changeType.changePoint();
137+
ChangeType changeType;
138+
int changePointIndex;
139+
if (hasMultivalued == false) {
140+
MlAggsHelper.DoubleBucketValues bucketValues = new MlAggsHelper.DoubleBucketValues(
141+
null,
142+
values.stream().mapToDouble(Double::doubleValue).toArray(),
143+
bucketIndexes.stream().mapToInt(Integer::intValue).toArray()
144+
);
145+
changeType = ChangePointDetector.getChangeType(bucketValues);
146+
changePointIndex = changeType.changePoint();
147+
} else {
148+
changeType = null;
149+
changePointIndex = -1;
150+
}
145151

146152
BlockFactory blockFactory = driverContext.blockFactory();
147153
int pageStartIndex = 0;
@@ -190,6 +196,11 @@ private void createOutputPages() {
190196
if (changeType instanceof ChangeType.Indeterminable indeterminable) {
191197
warnings(false).registerException(new IllegalArgumentException(indeterminable.getReason()));
192198
}
199+
if (hasMultivalued) {
200+
warnings(false).registerException(
201+
new IllegalArgumentException("values is multivalued; please reduce them with e.g. MV_AVG or MV_SUM")
202+
);
203+
}
193204
if (tooManyValues) {
194205
warnings(true).registerException(
195206
new IllegalArgumentException("too many values; keeping only first " + INPUT_VALUE_COUNT_LIMIT + " values")
@@ -198,9 +209,6 @@ private void createOutputPages() {
198209
if (hasNulls) {
199210
warnings(true).registerException(new IllegalArgumentException("values contain nulls; skipping them"));
200211
}
201-
if (hasMultivalued) {
202-
warnings(true).registerException(new IllegalArgumentException("values is multivalued; keeping only first elements"));
203-
}
204212
}
205213

206214
@Override

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

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,8 @@ FROM employees
737737
| CHANGE_POINT salary ON height
738738
;
739739

740-
warning:Line 5:3: warnings during evaluation of [CHANGE_POINT salary ON height]. Only first 20 failures recorded.
741-
warning:Line 5:3: java.lang.IllegalArgumentException: values is multivalued; keeping only first elements
740+
warning:Line 5:3: evaluation of [CHANGE_POINT salary ON height] failed, treating result as null. Only first 20 failures recorded.
741+
warning:Line 5:3: java.lang.IllegalArgumentException: values is multivalued; please reduce them with e.g. MV_AVG or MV_SUM
742742

743743
height:double | salary:integer | type:keyword | pvalue:double
744744
1.41 | 40031 | null | null
@@ -748,7 +748,7 @@ height:double | salary:integer | type:keyword | pvalue:doub
748748
1.46 | 39878 | null | null
749749
1.47 | 60408 | null | null
750750
1.48 | 44307 | null | null
751-
1.5 | [1, 22222, 33333] | dip | 9.140913464378286E-5
751+
1.5 | [1, 22222, 33333] | null | null
752752
1.51 | 28035 | null | null
753753
1.52 | [34341, 37853, 42716, 50064] | null | null
754754
1.53 | [35222, 71165, 73851] | null | null
@@ -798,6 +798,75 @@ height:double | salary:integer | type:keyword | pvalue:doub
798798
;
799799

800800

801+
multivalued with MV_AVG
802+
required_capability: change_point
803+
804+
FROM employees
805+
| STATS salary=MV_SORT(VALUES(salary)) BY height
806+
| EVAL salary = CASE(height == 1.5, [1, 22222, 33333], salary)
807+
| EVAL salary = CASE(height == 1.63, [43210, -10000, 999999999], salary)
808+
| EVAL salary = MV_AVG(salary)
809+
| CHANGE_POINT salary ON height
810+
;
811+
812+
height:double | salary:double | type:keyword | pvalue:double
813+
1.41 | 40031.0 | null | null
814+
1.42 | 34142.5 | null | null
815+
1.44 | 40266.0 | null | null
816+
1.45 | 49095.0 | null | null
817+
1.46 | 39878.0 | null | null
818+
1.47 | 60408.0 | null | null
819+
1.48 | 44307.0 | null | null
820+
1.5 | 18518.666666666668 | null | null
821+
1.51 | 28035.0 | null | null
822+
1.52 | 41243.5 | null | null
823+
1.53 | 60079.333333333336 | null | null
824+
1.54 | 61358.0 | null | null
825+
1.55 | 36876.5 | null | null
826+
1.56 | 60335.0 | null | null
827+
1.57 | 38486.0 | null | null
828+
1.58 | 41701.5 | null | null
829+
1.59 | 36575.666666666664 | null | null
830+
1.61 | 55299.5 | null | null
831+
1.63 | 3.33344403E8 | spike | 0.0
832+
1.64 | 38992.0 | null | null
833+
1.66 | 28946.0 | null | null
834+
1.68 | 42155.5 | null | null
835+
1.69 | 45656.0 | null | null
836+
1.7 | 65092.25 | null | null
837+
1.74 | 53178.0 | null | null
838+
1.75 | 43429.0 | null | null
839+
1.77 | 54184.25 | null | null
840+
1.78 | 44147.5 | null | null
841+
1.79 | 55360.0 | null | null
842+
1.8 | 52833.0 | null | null
843+
1.81 | 56475.666666666664 | null | null
844+
1.82 | 56039.333333333336 | null | null
845+
1.83 | 54195.333333333336 | null | null
846+
1.85 | 66174.0 | null | null
847+
1.87 | 47411.0 | null | null
848+
1.89 | 58121.0 | null | null
849+
1.9 | 37112.0 | null | null
850+
1.91 | 39638.0 | null | null
851+
1.92 | 67492.0 | null | null
852+
1.93 | 33956.0 | null | null
853+
1.94 | 48193.333333333336 | null | null
854+
1.96 | 43026.0 | null | null
855+
1.97 | 52851.0 | null | null
856+
1.99 | 56068.0 | null | null
857+
2.0 | 36314.666666666664 | null | null
858+
2.01 | 35742.0 | null | null
859+
2.03 | 51130.5 | null | null
860+
2.04 | 49281.0 | null | null
861+
2.05 | 63528.0 | null | null
862+
2.06 | 56722.5 | null | null
863+
2.07 | 39984.0 | null | null
864+
2.08 | 60523.0 | null | null
865+
2.09 | 38645.0 | null | null
866+
2.1 | 46637.8 | null | null
867+
;
868+
869+
801870
too much data (change point inside limit)
802871
required_capability: change_point
803872

0 commit comments

Comments
 (0)