Skip to content

Commit c5fd3cb

Browse files
committed
Warning indeterminable
1 parent 14072dc commit c5fd3cb

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

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

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

2121
import java.util.ArrayList;
22+
import java.util.Arrays;
2223
import java.util.List;
2324

2425
public class ChangePointOperator implements Operator {
2526

2627
// TODO: close upon failure / interrupt
2728

28-
public record Factory(int inputChannel) implements OperatorFactory {
29+
public record Factory(int inputChannel, String sourceText, int sourceLine, int sourceColumn) implements OperatorFactory {
2930
@Override
3031
public Operator get(DriverContext driverContext) {
31-
return new ChangePointOperator(driverContext.blockFactory(), inputChannel);
32+
return new ChangePointOperator(driverContext, inputChannel, sourceText, sourceLine, sourceColumn);
3233
}
3334

3435
@Override
@@ -37,17 +38,23 @@ public String describe() {
3738
}
3839
}
3940

40-
private final BlockFactory blockFactory;
41+
private final DriverContext driverContext;
4142
private final int inputChannel;
43+
private final String sourceText;
44+
private final int sourceLine;
45+
private final int sourceColumn;
46+
4247
private final List<Page> inputPages;
4348
private final List<Page> outputPages;
44-
4549
private boolean finished;
4650
private int outputPageIndex;
4751

48-
public ChangePointOperator(BlockFactory blockFactory, int inputChannel) {
49-
this.blockFactory = blockFactory;
52+
public ChangePointOperator(DriverContext driverContext, int inputChannel, String sourceText, int sourceLine, int sourceColumn) {
53+
this.driverContext = driverContext;
5054
this.inputChannel = inputChannel;
55+
this.sourceText = sourceText;
56+
this.sourceLine = sourceLine;
57+
this.sourceColumn = sourceColumn;
5158

5259
finished = false;
5360
inputPages = new ArrayList<>();
@@ -109,8 +116,13 @@ private void createOutputPages() {
109116
ChangeType changeType = ChangePointDetector.getChangeType(new MlAggsHelper.DoubleBucketValues(null, values));
110117
int changePointIndex = changeType.changePoint();
111118

112-
// TODO: throw error when indeterminable, due to not enough data
119+
if (changeType instanceof ChangeType.Indeterminable indeterminable) {
120+
Warnings.createWarnings(driverContext.warningsMode(), sourceLine, sourceColumn, sourceText)
121+
.registerException(new IllegalArgumentException(indeterminable.getReason()));
122+
}
113123

124+
// TODO: throw error when indeterminable, due to not enough data
125+
BlockFactory blockFactory = driverContext.blockFactory();
114126
int pageStartIndex = 0;
115127
for (Page inputPage : inputPages) {
116128
Block changeTypeBlock;

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,21 @@ null | null
206206
null | null
207207
null | null
208208
;
209+
210+
211+
not enough data
212+
// TODO: 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+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ private PhysicalOperation planMvExpand(MvExpandExec mvExpandExec, LocalExecution
705705
private PhysicalOperation planChangePoint(ChangePointExec changePoint, LocalExecutionPlannerContext context) {
706706
PhysicalOperation source = plan(changePoint.child(), context);
707707
Layout layout = source.layout.builder().append(changePoint.targetType()).append(changePoint.targetPvalue()).build();
708-
return source.with(new ChangePointOperator.Factory(layout.get(changePoint.value().id()).channel()), layout);
708+
return source.with(new ChangePointOperator.Factory(layout.get(changePoint.value().id()).channel(), changePoint.sourceText(), changePoint.sourceLocation().getLineNumber(), changePoint.sourceLocation().getColumnNumber()), layout);
709709
}
710710

711711
/**

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/changepoint/ChangeType.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public String getName() {
121121
return NAME;
122122
}
123123

124+
public String getReason() {
125+
return reason;
126+
}
127+
124128
@Override
125129
public boolean equals(Object o) {
126130
if (this == o) return true;

0 commit comments

Comments
 (0)