Skip to content

Commit 6e6466e

Browse files
committed
Make timestamp optional
1 parent 586b109 commit 6e6466e

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/ChangePointLongAggregator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ Block toBlock(Function<SingleState, LongArray> getArray, BlockFactory blockFacto
249249
}
250250
}
251251

252-
void enableGroupIdTracking(SeenGroupIds seenGroupIds) {
253-
}
252+
void enableGroupIdTracking(SeenGroupIds seenGroupIds) {}
254253

255254
@Override
256255
public void close() {

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
change point
1+
change point with timestamp argument
22
# required_capability: change_point
33

44
FROM k8s
@@ -12,3 +12,18 @@ cp:keyword
1212
"{""type"":{""stationary"":{}}}" | qa
1313
"{""type"":{""indeterminable"":{""reason"":""not enough buckets to calculate change_point. Requires at least [22]; found [18]""}}}" | staging
1414
;
15+
16+
change point without timestamp argument
17+
# required_capability: change_point
18+
19+
FROM k8s
20+
| STATS count=COUNT() BY @timestamp=BUCKET(@timestamp, 1 minute), cluster
21+
| STATS cp=CHANGE_POINT(count) BY cluster
22+
| SORT cluster
23+
;
24+
25+
cp:keyword | cluster:keyword
26+
"{""type"":{""indeterminable"":{""reason"":""not enough buckets to calculate change_point. Requires at least [22]; found [21]""}}}" | prod
27+
"{""type"":{""stationary"":{}}}" | qa
28+
"{""type"":{""indeterminable"":{""reason"":""not enough buckets to calculate change_point. Requires at least [22]; found [18]""}}}" | staging
29+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/ChangePoint.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException;
1515
import org.elasticsearch.xpack.esql.core.expression.Expression;
1616
import org.elasticsearch.xpack.esql.core.expression.Literal;
17+
import org.elasticsearch.xpack.esql.core.expression.UnresolvedAttribute;
1718
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1819
import org.elasticsearch.xpack.esql.core.tree.Source;
1920
import org.elasticsearch.xpack.esql.core.type.DataType;
2021
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
22+
import org.elasticsearch.xpack.esql.expression.function.OptionalArgument;
2123
import org.elasticsearch.xpack.esql.expression.function.Param;
2224
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
2325
import org.elasticsearch.xpack.esql.planner.ToAggregator;
@@ -29,21 +31,20 @@
2931
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
3032
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
3133

32-
public class ChangePoint extends AggregateFunction implements ToAggregator {
34+
public class ChangePoint extends AggregateFunction implements OptionalArgument, ToAggregator {
3335
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(
3436
Expression.class,
3537
"ChangePoint",
3638
ChangePoint::new
3739
);
3840

39-
// TODO: make "timestamp" field optional
4041
@FunctionInfo(returnType = { "string" }, description = "...", isAggregation = true)
4142
public ChangePoint(
4243
Source source,
4344
@Param(name = "field", type = { "double", "integer", "long" }, description = "field") Expression field,
44-
@Param(name = "timestamp", type = { "date_nanos", "datetime", "double", "integer", "long" }) Expression timestamp
45+
@Param(optional = true, name = "timestamp", type = { "date_nanos", "datetime", "double", "integer", "long" }) Expression timestamp
4546
) {
46-
this(source, field, Literal.TRUE, timestamp);
47+
this(source, field, Literal.TRUE, timestamp != null ? timestamp : new UnresolvedAttribute(source, "@timestamp"));
4748
}
4849

4950
public ChangePoint(Source source, Expression field, Expression filter, Expression timestamp) {
@@ -98,10 +99,6 @@ public AggregateFunction withFilter(Expression filter) {
9899

99100
@Override
100101
public AggregatorFunctionSupplier supplier(List<Integer> inputChannels) {
101-
// if (inputChannels.size() != 2 && inputChannels.size() != 3) {
102-
// throw new IllegalArgumentException("change point requires two for raw input or three channels for partial input; got " +
103-
// inputChannels);
104-
// }
105102
final DataType type = field().dataType();
106103
return switch (type) {
107104
case LONG -> new ChangePointLongAggregatorFunctionSupplier(inputChannels);

0 commit comments

Comments
 (0)