Skip to content

Commit cd223c3

Browse files
committed
too much data
1 parent 995baad commit cd223c3

File tree

4 files changed

+1047
-31
lines changed

4 files changed

+1047
-31
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
import org.elasticsearch.xpack.ml.aggs.changepoint.ChangeType;
2020

2121
import java.util.ArrayList;
22-
import java.util.Arrays;
2322
import java.util.List;
2423

2524
public class ChangePointOperator implements Operator {
2625

2726
// TODO: close upon failure / interrupt
2827

28+
public static final int INPUT_VALUE_COUNT_LIMIT = 1000;
29+
2930
public record Factory(int inputChannel, String sourceText, int sourceLine, int sourceColumn) implements OperatorFactory {
3031
@Override
3132
public Operator get(DriverContext driverContext) {
@@ -103,14 +104,18 @@ private void createOutputPages() {
103104
for (Page page : inputPages) {
104105
valuesCount += page.getPositionCount();
105106
}
107+
boolean tooManyValues = valuesCount > INPUT_VALUE_COUNT_LIMIT;
108+
if (tooManyValues) {
109+
valuesCount = INPUT_VALUE_COUNT_LIMIT;
110+
}
106111

107112
// TODO: account for this memory?
108113
double[] values = new double[valuesCount];
109114
int valuesIndex = 0;
110115
boolean hasNulls = false;
111116
for (Page inputPage : inputPages) {
112117
Block inputBlock = inputPage.getBlock(inputChannel);
113-
for (int i = 0; i < inputBlock.getPositionCount(); i++) {
118+
for (int i = 0; i < inputBlock.getPositionCount() && valuesIndex < valuesCount; i++) {
114119
Object value = BlockUtils.toJavaObject(inputBlock, i);
115120
if (value == null) {
116121
hasNulls = true;
@@ -124,13 +129,6 @@ private void createOutputPages() {
124129
ChangeType changeType = ChangePointDetector.getChangeType(new MlAggsHelper.DoubleBucketValues(null, values));
125130
int changePointIndex = changeType.changePoint();
126131

127-
if (changeType instanceof ChangeType.Indeterminable indeterminable) {
128-
warnings(false).registerException(new IllegalArgumentException(indeterminable.getReason()));
129-
}
130-
if (hasNulls) {
131-
warnings(true).registerException(new IllegalArgumentException("values contain nulls; treating them as zeroes"));
132-
}
133-
134132
BlockFactory blockFactory = driverContext.blockFactory();
135133
int pageStartIndex = 0;
136134
for (Page inputPage : inputPages) {
@@ -164,6 +162,16 @@ private void createOutputPages() {
164162
}
165163

166164
inputPages.clear();
165+
166+
if (changeType instanceof ChangeType.Indeterminable indeterminable) {
167+
warnings(false).registerException(new IllegalArgumentException(indeterminable.getReason()));
168+
}
169+
if (tooManyValues) {
170+
warnings(true).registerException(new IllegalArgumentException("too many values; keeping only first " + INPUT_VALUE_COUNT_LIMIT + " values"));
171+
}
172+
if (hasNulls) {
173+
warnings(true).registerException(new IllegalArgumentException("values contain nulls; treating them as zeroes"));
174+
}
167175
}
168176

169177
@Override

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -208,24 +208,6 @@ null | null
208208
;
209209

210210

211-
not enough data
212-
required_capability: change_point
213-
214-
FROM k8s
215-
| STATS count=COUNT() BY @timestamp=BUCKET(@timestamp, 10 MINUTES)
216-
| CHANGE_POINT count ON @timestamp AS type, pvalue
217-
;
218-
219-
warning:Line 3:3: evaluation of [CHANGE_POINT count ON @timestamp AS type, pvalue] failed, treating result as null. Only first 20 failures recorded.
220-
warning:Line 3:3: java.lang.IllegalArgumentException: not enough buckets to calculate change_point. Requires at least [22]; found [3]
221-
222-
count:long | @timestamp:datetime | type:text | pvalue:double
223-
84 | 2024-05-10T00:00:00.000Z | null | null
224-
93 | 2024-05-10T00:10:00.000Z | null | null
225-
23 | 2024-05-10T00:20:00.000Z | null | null
226-
;
227-
228-
229211
null values
230212
required_capability: change_point
231213

0 commit comments

Comments
 (0)