|
14 | 14 | import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException; |
15 | 15 | import org.elasticsearch.xpack.esql.core.expression.Expression; |
16 | 16 | import org.elasticsearch.xpack.esql.core.expression.Literal; |
| 17 | +import org.elasticsearch.xpack.esql.core.expression.UnresolvedAttribute; |
17 | 18 | import org.elasticsearch.xpack.esql.core.tree.NodeInfo; |
18 | 19 | import org.elasticsearch.xpack.esql.core.tree.Source; |
19 | 20 | import org.elasticsearch.xpack.esql.core.type.DataType; |
20 | 21 | import org.elasticsearch.xpack.esql.expression.function.FunctionInfo; |
| 22 | +import org.elasticsearch.xpack.esql.expression.function.OptionalArgument; |
21 | 23 | import org.elasticsearch.xpack.esql.expression.function.Param; |
22 | 24 | import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput; |
23 | 25 | import org.elasticsearch.xpack.esql.planner.ToAggregator; |
|
29 | 31 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND; |
30 | 32 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType; |
31 | 33 |
|
32 | | -public class ChangePoint extends AggregateFunction implements ToAggregator { |
| 34 | +public class ChangePoint extends AggregateFunction implements OptionalArgument, ToAggregator { |
33 | 35 | public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry( |
34 | 36 | Expression.class, |
35 | 37 | "ChangePoint", |
36 | 38 | ChangePoint::new |
37 | 39 | ); |
38 | 40 |
|
39 | | - // TODO: make "timestamp" field optional |
40 | 41 | @FunctionInfo(returnType = { "string" }, description = "...", isAggregation = true) |
41 | 42 | public ChangePoint( |
42 | 43 | Source source, |
43 | 44 | @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 |
45 | 46 | ) { |
46 | | - this(source, field, Literal.TRUE, timestamp); |
| 47 | + this(source, field, Literal.TRUE, timestamp != null ? timestamp : new UnresolvedAttribute(source, "@timestamp")); |
47 | 48 | } |
48 | 49 |
|
49 | 50 | public ChangePoint(Source source, Expression field, Expression filter, Expression timestamp) { |
@@ -98,10 +99,6 @@ public AggregateFunction withFilter(Expression filter) { |
98 | 99 |
|
99 | 100 | @Override |
100 | 101 | 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 | | - // } |
105 | 102 | final DataType type = field().dataType(); |
106 | 103 | return switch (type) { |
107 | 104 | case LONG -> new ChangePointLongAggregatorFunctionSupplier(inputChannels); |
|
0 commit comments