Skip to content

Commit 83fef41

Browse files
committed
initial wiring up
1 parent 4f030ef commit 83fef41

File tree

6 files changed

+395
-6
lines changed

6 files changed

+395
-6
lines changed

docs/reference/esql/functions/kibana/definition/bucket.json

Lines changed: 270 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/types/bucket.asciidoc

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,27 @@ yr:date_nanos | mo:date_nanos | mn:date_nanos
549549
2023-01-01T00:00:00.000000000Z | 2023-10-01T00:00:00.000000000Z | 2023-10-23T12:10:00.000000000Z | 2023-10-23T12:15:03.360000000Z
550550
;
551551

552+
Date trunc on date nanos
553+
required_capability: date_trunc_date_nanos
554+
required_capability: date_nanos_bucket
555+
556+
FROM date_nanos
557+
| WHERE millis > "2020-01-01"
558+
| EVAL yr = BUCKET(nanos, 1 year), mo = BUCKET(nanos, 1 month), mn = BUCKET(nanos, 10 minutes), ms = BUCKET(nanos, 1 millisecond)
559+
| SORT nanos DESC
560+
| KEEP yr, mo, mn, ms;
561+
562+
yr:date_nanos | mo:date_nanos | mn:date_nanos | ms:date_nanos
563+
2023-01-01T00:00:00.000000000Z | 2023-10-01T00:00:00.000000000Z | 2023-10-23T13:50:00.000000000Z | 2023-10-23T13:55:01.543000000Z
564+
2023-01-01T00:00:00.000000000Z | 2023-10-01T00:00:00.000000000Z | 2023-10-23T13:50:00.000000000Z | 2023-10-23T13:53:55.832000000Z
565+
2023-01-01T00:00:00.000000000Z | 2023-10-01T00:00:00.000000000Z | 2023-10-23T13:50:00.000000000Z | 2023-10-23T13:52:55.015000000Z
566+
2023-01-01T00:00:00.000000000Z | 2023-10-01T00:00:00.000000000Z | 2023-10-23T13:50:00.000000000Z | 2023-10-23T13:51:54.732000000Z
567+
2023-01-01T00:00:00.000000000Z | 2023-10-01T00:00:00.000000000Z | 2023-10-23T13:30:00.000000000Z | 2023-10-23T13:33:34.937000000Z
568+
2023-01-01T00:00:00.000000000Z | 2023-10-01T00:00:00.000000000Z | 2023-10-23T12:20:00.000000000Z | 2023-10-23T12:27:28.948000000Z
569+
2023-01-01T00:00:00.000000000Z | 2023-10-01T00:00:00.000000000Z | 2023-10-23T12:10:00.000000000Z | 2023-10-23T12:15:03.360000000Z
570+
2023-01-01T00:00:00.000000000Z | 2023-10-01T00:00:00.000000000Z | 2023-10-23T12:10:00.000000000Z | 2023-10-23T12:15:03.360000000Z
571+
;
572+
552573
Add date nanos
553574
required_capability: date_nanos_add_subtract
554575

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ public enum Cap {
364364
*/
365365
DATE_TRUNC_DATE_NANOS(),
366366

367+
/**
368+
* Support date nanos values as the field argument to bucket
369+
*/
370+
DATE_NANOS_BUCKET(),
371+
367372
/**
368373
* support aggregations on date nanos
369374
*/

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/grouping/Bucket.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class Bucket extends GroupingFunction implements Validatable, TwoOptional
9090
private final Expression to;
9191

9292
@FunctionInfo(
93-
returnType = { "double", "date" },
93+
returnType = { "double", "date", "date_nanos" },
9494
description = """
9595
Creates groups of values - buckets - out of a datetime or numeric input.
9696
The size of the buckets can either be provided directly, or chosen based on a recommended count and values range.""",
@@ -169,7 +169,7 @@ public Bucket(
169169
Source source,
170170
@Param(
171171
name = "field",
172-
type = { "integer", "long", "double", "date" },
172+
type = { "integer", "long", "double", "date", "date_nanos" },
173173
description = "Numeric or date expression from which to derive buckets."
174174
) Expression field,
175175
@Param(
@@ -241,7 +241,7 @@ public boolean foldable() {
241241

242242
@Override
243243
public ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
244-
if (field.dataType() == DataType.DATETIME) {
244+
if (field.dataType() == DataType.DATETIME || field.dataType() == DataType.DATE_NANOS) {
245245
Rounding.Prepared preparedRounding;
246246
if (buckets.dataType().isWholeNumber()) {
247247
int b = ((Number) buckets.fold()).intValue();
@@ -314,8 +314,8 @@ private double pickRounding(int buckets, double from, double to) {
314314
}
315315

316316
// supported parameter type combinations (1st, 2nd, 3rd, 4th):
317-
// datetime, integer, string/datetime, string/datetime
318-
// datetime, rounding/duration, -, -
317+
// datetime/date_nanos, integer, string/datetime, string/datetime
318+
// datetime/date_nanos, rounding/duration, -, -
319319
// numeric, integer, numeric, numeric
320320
// numeric, numeric, -, -
321321
@Override
@@ -329,7 +329,7 @@ protected TypeResolution resolveType() {
329329
return TypeResolution.TYPE_RESOLVED;
330330
}
331331

332-
if (fieldType == DataType.DATETIME) {
332+
if (fieldType == DataType.DATETIME || fieldType == DataType.DATE_NANOS) {
333333
TypeResolution resolution = isType(
334334
buckets,
335335
dt -> dt.isWholeNumber() || DataType.isTemporalAmount(dt),

0 commit comments

Comments
 (0)