From be31f9b057434975709e31b1a5f9989a5ac8bac1 Mon Sep 17 00:00:00 2001 From: Bogdan Pintea Date: Thu, 4 Apr 2024 12:57:04 +0200 Subject: [PATCH 1/4] Rename AUTO_BUCKET to just BUCKET This renames the function AUTO_BUCKET to just BUCKET. --- docs/reference/esql/esql-get-started.asciidoc | 10 +- .../{auto_bucket.asciidoc => bucket.asciidoc} | 44 +++--- .../functions/date-time-functions.asciidoc | 4 +- .../{auto_bucket.asciidoc => bucket.asciidoc} | 0 .../functions/layout/auto_bucket.asciidoc | 14 -- .../esql/functions/layout/bucket.asciidoc | 14 ++ .../{auto_bucket.asciidoc => bucket.asciidoc} | 0 .../esql/functions/signature/auto_bucket.svg | 1 - .../esql/functions/signature/bucket.svg | 1 + .../{auto_bucket.asciidoc => bucket.asciidoc} | 0 .../src/main/resources/date.csv-spec | 134 +++++++++--------- .../src/main/resources/floats.csv-spec | 4 +- .../src/main/resources/ints.csv-spec | 24 ++-- .../src/main/resources/meta.csv-spec | 8 +- .../src/main/resources/unsigned_long.csv-spec | 4 +- .../function/EsqlFunctionRegistry.java | 4 +- .../math/{AutoBucket.java => Bucket.java} | 12 +- .../xpack/esql/io/stream/PlanNamedTypes.java | 10 +- ...{AutoBucketTests.java => BucketTests.java} | 6 +- .../optimizer/LogicalPlanOptimizerTests.java | 6 +- .../session/IndexResolverFieldNamesTests.java | 6 +- 21 files changed, 152 insertions(+), 154 deletions(-) rename docs/reference/esql/functions/{auto_bucket.asciidoc => bucket.asciidoc} (62%) rename docs/reference/esql/functions/description/{auto_bucket.asciidoc => bucket.asciidoc} (100%) delete mode 100644 docs/reference/esql/functions/layout/auto_bucket.asciidoc create mode 100644 docs/reference/esql/functions/layout/bucket.asciidoc rename docs/reference/esql/functions/parameters/{auto_bucket.asciidoc => bucket.asciidoc} (100%) delete mode 100644 docs/reference/esql/functions/signature/auto_bucket.svg create mode 100644 docs/reference/esql/functions/signature/bucket.svg rename docs/reference/esql/functions/types/{auto_bucket.asciidoc => bucket.asciidoc} (100%) rename x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/{AutoBucket.java => Bucket.java} (95%) rename x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/{AutoBucketTests.java => BucketTests.java} (95%) diff --git a/docs/reference/esql/esql-get-started.asciidoc b/docs/reference/esql/esql-get-started.asciidoc index 29f61299cec30..421272f741602 100644 --- a/docs/reference/esql/esql-get-started.asciidoc +++ b/docs/reference/esql/esql-get-started.asciidoc @@ -240,7 +240,7 @@ include::{esql-specs}/eval.csv-spec[tag=gs-eval-stats-backticks] === Create a histogram To track statistics over time, {esql} enables you to create histograms using the -<> function. `AUTO_BUCKET` creates human-friendly bucket sizes +<> function. `BUCKET` creates human-friendly bucket sizes and returns a value for each row that corresponds to the resulting bucket the row falls into. @@ -248,22 +248,22 @@ For example, to create hourly buckets for the data on October 23rd: [source,esql] ---- -include::{esql-specs}/date.csv-spec[tag=gs-auto_bucket] +include::{esql-specs}/date.csv-spec[tag=gs-bucket] ---- -Combine `AUTO_BUCKET` with <> to create a histogram. For example, +Combine `BUCKET` with <> to create a histogram. For example, to count the number of events per hour: [source,esql] ---- -include::{esql-specs}/date.csv-spec[tag=gs-auto_bucket-stats-by] +include::{esql-specs}/date.csv-spec[tag=gs-bucket-stats-by] ---- Or the median duration per hour: [source,esql] ---- -include::{esql-specs}/date.csv-spec[tag=gs-auto_bucket-stats-by-median] +include::{esql-specs}/date.csv-spec[tag=gs-bucket-stats-by-median] ---- [discrete] diff --git a/docs/reference/esql/functions/auto_bucket.asciidoc b/docs/reference/esql/functions/bucket.asciidoc similarity index 62% rename from docs/reference/esql/functions/auto_bucket.asciidoc rename to docs/reference/esql/functions/bucket.asciidoc index 651ac168aa83a..e436a79d0ec1e 100644 --- a/docs/reference/esql/functions/auto_bucket.asciidoc +++ b/docs/reference/esql/functions/bucket.asciidoc @@ -1,14 +1,12 @@ [discrete] -[[esql-auto_bucket]] -=== `AUTO_BUCKET` - -experimental::[] +[[esql-bucket]] +=== `BUCKET` *Syntax* [source,esql] ---- -AUTO_BUCKET(expression, buckets, from, to) +BUCKET(expression, buckets, from, to) ---- *Parameters* @@ -28,39 +26,39 @@ End of the range. Can be a number or a date expressed as a string. *Description* Creates human-friendly buckets and returns a value for each row that corresponds -to the resulting bucket the row falls into. +to the resulting bucket the row falls into. Using a target number of buckets, a start of a range, and an end of a range, -`AUTO_BUCKET` picks an appropriate bucket size to generate the target number of +`BUCKET` picks an appropriate bucket size to generate the target number of buckets or fewer. For example, asking for at most 20 buckets over a year results in monthly buckets: [source.merge.styled,esql] ---- -include::{esql-specs}/date.csv-spec[tag=docsAutoBucketMonth] +include::{esql-specs}/date.csv-spec[tag=docsBucketMonth] ---- [%header.monospaced.styled,format=dsv,separator=|] |=== -include::{esql-specs}/date.csv-spec[tag=docsAutoBucketMonth-result] +include::{esql-specs}/date.csv-spec[tag=docsBucketMonth-result] |=== The goal isn't to provide *exactly* the target number of buckets, it's to pick a range that people are comfortable with that provides at most the target number of buckets. -Combine `AUTO_BUCKET` with +Combine `BUCKET` with <> to create a histogram: [source.merge.styled,esql] ---- -include::{esql-specs}/date.csv-spec[tag=docsAutoBucketMonthlyHistogram] +include::{esql-specs}/date.csv-spec[tag=docsBucketMonthlyHistogram] ---- [%header.monospaced.styled,format=dsv,separator=|] |=== -include::{esql-specs}/date.csv-spec[tag=docsAutoBucketMonthlyHistogram-result] +include::{esql-specs}/date.csv-spec[tag=docsBucketMonthlyHistogram-result] |=== -NOTE: `AUTO_BUCKET` does not create buckets that don't match any documents. +NOTE: `BUCKET` does not create buckets that don't match any documents. That's why this example is missing `1985-03-01` and other dates. Asking for more buckets can result in a smaller range. For example, asking for @@ -68,28 +66,28 @@ at most 100 buckets in a year results in weekly buckets: [source.merge.styled,esql] ---- -include::{esql-specs}/date.csv-spec[tag=docsAutoBucketWeeklyHistogram] +include::{esql-specs}/date.csv-spec[tag=docsBucketWeeklyHistogram] ---- [%header.monospaced.styled,format=dsv,separator=|] |=== -include::{esql-specs}/date.csv-spec[tag=docsAutoBucketWeeklyHistogram-result] +include::{esql-specs}/date.csv-spec[tag=docsBucketWeeklyHistogram-result] |=== -NOTE: `AUTO_BUCKET` does not filter any rows. It only uses the provided range to +NOTE: `BUCKET` does not filter any rows. It only uses the provided range to pick a good bucket size. For rows with a value outside of the range, it returns a bucket value that corresponds to a bucket outside the range. Combine -`AUTO_BUCKET` with <> to filter rows. +`BUCKET` with <> to filter rows. -`AUTO_BUCKET` can also operate on numeric fields. For example, to create a +`BUCKET` can also operate on numeric fields. For example, to create a salary histogram: [source.merge.styled,esql] ---- -include::{esql-specs}/ints.csv-spec[tag=docsAutoBucketNumeric] +include::{esql-specs}/ints.csv-spec[tag=docsBucketNumeric] ---- [%header.monospaced.styled,format=dsv,separator=|] |=== -include::{esql-specs}/ints.csv-spec[tag=docsAutoBucketNumeric-result] +include::{esql-specs}/ints.csv-spec[tag=docsBucketNumeric-result] |=== Unlike the earlier example that intentionally filters on a date range, you @@ -104,7 +102,7 @@ per hour: [source.styled,esql] ---- -include::{esql-specs}/date.csv-spec[tag=docsAutoBucketLast24hr] +include::{esql-specs}/date.csv-spec[tag=docsBucketLast24hr] ---- Create monthly buckets for the year 1985, and calculate the average salary by @@ -112,9 +110,9 @@ hiring month: [source.merge.styled,esql] ---- -include::{esql-specs}/date.csv-spec[tag=auto_bucket_in_agg] +include::{esql-specs}/date.csv-spec[tag=bucket_in_agg] ---- [%header.monospaced.styled,format=dsv,separator=|] |=== -include::{esql-specs}/date.csv-spec[tag=auto_bucket_in_agg-result] +include::{esql-specs}/date.csv-spec[tag=bucket_in_agg-result] |=== diff --git a/docs/reference/esql/functions/date-time-functions.asciidoc b/docs/reference/esql/functions/date-time-functions.asciidoc index e9d6628c63894..64d5ef42d0011 100644 --- a/docs/reference/esql/functions/date-time-functions.asciidoc +++ b/docs/reference/esql/functions/date-time-functions.asciidoc @@ -8,7 +8,7 @@ {esql} supports these date-time functions: // tag::date_list[] -* experimental:[] <> +* <> * <> * <> * <> @@ -17,7 +17,7 @@ * <> // end::date_list[] -include::auto_bucket.asciidoc[] +include::bucket.asciidoc[] include::date_diff.asciidoc[] include::date_extract.asciidoc[] include::date_format.asciidoc[] diff --git a/docs/reference/esql/functions/description/auto_bucket.asciidoc b/docs/reference/esql/functions/description/bucket.asciidoc similarity index 100% rename from docs/reference/esql/functions/description/auto_bucket.asciidoc rename to docs/reference/esql/functions/description/bucket.asciidoc diff --git a/docs/reference/esql/functions/layout/auto_bucket.asciidoc b/docs/reference/esql/functions/layout/auto_bucket.asciidoc deleted file mode 100644 index 82e05ab5d215c..0000000000000 --- a/docs/reference/esql/functions/layout/auto_bucket.asciidoc +++ /dev/null @@ -1,14 +0,0 @@ -// This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it. - -[discrete] -[[esql-auto_bucket]] -=== `AUTO_BUCKET` - -*Syntax* - -[.text-center] -image::esql/functions/signature/auto_bucket.svg[Embedded,opts=inline] - -include::../parameters/auto_bucket.asciidoc[] -include::../description/auto_bucket.asciidoc[] -include::../types/auto_bucket.asciidoc[] diff --git a/docs/reference/esql/functions/layout/bucket.asciidoc b/docs/reference/esql/functions/layout/bucket.asciidoc new file mode 100644 index 0000000000000..0445007237c8c --- /dev/null +++ b/docs/reference/esql/functions/layout/bucket.asciidoc @@ -0,0 +1,14 @@ +// This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it. + +[discrete] +[[esql-bucket]] +=== `BUCKET` + +*Syntax* + +[.text-center] +image::esql/functions/signature/bucket.svg[Embedded,opts=inline] + +include::../parameters/bucket.asciidoc[] +include::../description/bucket.asciidoc[] +include::../types/bucket.asciidoc[] diff --git a/docs/reference/esql/functions/parameters/auto_bucket.asciidoc b/docs/reference/esql/functions/parameters/bucket.asciidoc similarity index 100% rename from docs/reference/esql/functions/parameters/auto_bucket.asciidoc rename to docs/reference/esql/functions/parameters/bucket.asciidoc diff --git a/docs/reference/esql/functions/signature/auto_bucket.svg b/docs/reference/esql/functions/signature/auto_bucket.svg deleted file mode 100644 index 7da9a053825f1..0000000000000 --- a/docs/reference/esql/functions/signature/auto_bucket.svg +++ /dev/null @@ -1 +0,0 @@ -AUTO_BUCKET(field,buckets,from,to) \ No newline at end of file diff --git a/docs/reference/esql/functions/signature/bucket.svg b/docs/reference/esql/functions/signature/bucket.svg new file mode 100644 index 0000000000000..f6662910c010d --- /dev/null +++ b/docs/reference/esql/functions/signature/bucket.svg @@ -0,0 +1 @@ +BUCKET(field,buckets,from,to) \ No newline at end of file diff --git a/docs/reference/esql/functions/types/auto_bucket.asciidoc b/docs/reference/esql/functions/types/bucket.asciidoc similarity index 100% rename from docs/reference/esql/functions/types/auto_bucket.asciidoc rename to docs/reference/esql/functions/types/bucket.asciidoc diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/date.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/date.csv-spec index 8f9ce9968d89d..88b126d515330 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/date.csv-spec +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/date.csv-spec @@ -261,36 +261,36 @@ int:integer |dt:date // end::to_datetime-int-result[] ; -autoBucketSimpleMonth -// tag::auto_bucket_month[] +bucketSimpleMonth +// tag::bucket_month[] ROW date=TO_DATETIME("1985-07-09T00:00:00.000Z") -| EVAL bucket=AUTO_BUCKET(date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") -// end::auto_bucket_month[] +| EVAL bucket=BUCKET(date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") +// end::bucket_month[] ; -// tag::auto_bucket_month-result[] +// tag::bucket_month-result[] date:datetime | bucket:datetime 1985-07-09T00:00:00.000Z | 1985-07-01T00:00:00.000Z -// end::auto_bucket_month-result[] +// end::bucket_month-result[] ; -autoBucketSimpleWeek -// tag::auto_bucket_week[] +bucketSimpleWeek +// tag::bucket_week[] ROW date=TO_DATETIME("1985-07-09T00:00:00.000Z") -| EVAL bucket=AUTO_BUCKET(date, 100, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") -// end::auto_bucket_week[] +| EVAL bucket=BUCKET(date, 100, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") +// end::bucket_week[] ; -// tag::auto_bucket_week-result[] +// tag::bucket_week-result[] date:datetime | bucket:datetime 1985-07-09T00:00:00.000Z | 1985-07-08T00:00:00.000Z -// end::auto_bucket_week-result[] +// end::bucket_week-result[] ; -autoBucketMonth +bucketMonth from employees | where hire_date >= "1985-01-01T00:00:00Z" and hire_date < "1986-01-01T00:00:00Z" -| eval hd = auto_bucket(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") +| eval hd = bucket(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") | sort hire_date | keep hire_date, hd; @@ -308,10 +308,10 @@ hire_date:date | hd:date 1985-11-21T00:00:00.000Z | 1985-11-01T00:00:00.000Z ; -autoBucketWeek +bucketWeek from employees | where hire_date >= "1985-01-01T00:00:00Z" and hire_date < "1986-01-01T00:00:00Z" -| eval hd = auto_bucket(hire_date, 55, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") +| eval hd = bucket(hire_date, 55, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") | sort hire_date | keep hire_date, hd; @@ -350,10 +350,10 @@ from employees | where birth_date > now() | sort emp_no asc | keep emp_no, birth emp_no:integer | birth_date:date ; -autoBucketYearInAgg#[skip:-8.12.99, reason:date type is supported in 8.13] +bucketYearInAgg#[skip:-8.12.99, reason:date type is supported in 8.13] FROM employees | WHERE hire_date >= "1999-01-01T00:00:00Z" -| EVAL bucket = AUTO_BUCKET(hire_date, 5, "1999-01-01T00:00:00Z", NOW()) +| EVAL bucket = BUCKET(hire_date, 5, "1999-01-01T00:00:00Z", NOW()) | STATS COUNT(*) by bucket | sort bucket; @@ -361,12 +361,12 @@ COUNT(*):long | bucket:date 1 | 1999-01-01T00:00:00.000Z ; -autoBucketYearInAggConstRefsString#[skip:-8.12.99, reason:date type is supported in 8.13] +bucketYearInAggConstRefsString#[skip:-8.12.99, reason:date type is supported in 8.13] FROM employees | WHERE hire_date >= "1999-01-01T00:00:00Z" | EVAL bucket_start = "1999-01-01T00:00:00Z" | EVAL bucket_end = NOW() -| EVAL bucket = AUTO_BUCKET(hire_date, 5, bucket_start, bucket_end) +| EVAL bucket = BUCKET(hire_date, 5, bucket_start, bucket_end) | STATS COUNT(*) by bucket | sort bucket; @@ -374,12 +374,12 @@ COUNT(*):long | bucket:date 1 | 1999-01-01T00:00:00.000Z ; -autoBucketYearInAggConstRefsConcat#[skip:-8.12.99, reason:date type is supported in 8.13] +bucketYearInAggConstRefsConcat#[skip:-8.12.99, reason:date type is supported in 8.13] FROM employees | WHERE hire_date >= "1999-01-01T00:00:00Z" | EVAL bucket_start = CONCAT("1999-01-01", "T", "00:00:00Z") | EVAL bucket_end = NOW() -| EVAL bucket = AUTO_BUCKET(hire_date, 5, bucket_start, bucket_end) +| EVAL bucket = BUCKET(hire_date, 5, bucket_start, bucket_end) | STATS COUNT(*) by bucket | sort bucket; @@ -387,12 +387,12 @@ COUNT(*):long | bucket:date 1 | 1999-01-01T00:00:00.000Z ; -autoBucketYearInAggConstRefsDate#[skip:-8.12.99, reason:date type is supported in 8.13] +bucketYearInAggConstRefsDate#[skip:-8.12.99, reason:date type is supported in 8.13] FROM employees | WHERE hire_date >= "1999-01-01T00:00:00Z" | EVAL bucket_start = TO_DATETIME("1999-01-01T00:00:00.000Z") | EVAL bucket_end = NOW() -| EVAL bucket = AUTO_BUCKET(hire_date, 5, bucket_start, bucket_end) +| EVAL bucket = BUCKET(hire_date, 5, bucket_start, bucket_end) | keep bucket_start, bucket_end, bucket | STATS COUNT(*) by bucket | sort bucket; @@ -401,31 +401,31 @@ COUNT(*):long | bucket:date 1 | 1999-01-01T00:00:00.000Z ; -autoBucketYearInAggConstRefsRename#[skip:-8.12.99, reason:date type is supported in 8.13] +bucketYearInAggConstRefsRename#[skip:-8.12.99, reason:date type is supported in 8.13] FROM employees | WHERE hire_date >= "1999-01-01T00:00:00Z" | EVAL bucket_start = "1999-01-01T00:00:00Z" | EVAL bucket_end = NOW() | RENAME bucket_end as be, bucket_start as bs -| STATS c = COUNT(*) by AUTO_BUCKET(hire_date, 5, bs, be) +| STATS c = COUNT(*) by BUCKET(hire_date, 5, bs, be) | SORT c ; -c:long | AUTO_BUCKET(hire_date, 5, bs, be):date +c:long | BUCKET(hire_date, 5, bs, be):date 1 | 1999-01-01T00:00:00.000Z ; -autoBucketMonthInAgg -// tag::auto_bucket_in_agg[] +bucketMonthInAgg +// tag::bucket_in_agg[] FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" -| EVAL bucket = AUTO_BUCKET(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") +| EVAL bucket = BUCKET(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") | STATS AVG(salary) BY bucket | SORT bucket -// end::auto_bucket_in_agg[] +// end::bucket_in_agg[] ; -// tag::auto_bucket_in_agg-result[] +// tag::bucket_in_agg-result[] AVG(salary):double | bucket:date 46305.0 | 1985-02-01T00:00:00.000Z 44817.0 | 1985-05-01T00:00:00.000Z @@ -433,7 +433,7 @@ AVG(salary):double | bucket:date 49095.0 | 1985-09-01T00:00:00.000Z 51532.0 | 1985-10-01T00:00:00.000Z 54539.75 | 1985-11-01T00:00:00.000Z -// end::auto_bucket_in_agg-result[] +// end::bucket_in_agg-result[] ; evalDateDiffInNanoAndMicroAndMilliSeconds#[skip:-8.12.99, reason:date_diff added in 8.13] @@ -950,17 +950,17 @@ birth_date:datetime 1953-04-21T00:00:00.000Z ; -docsAutoBucketMonth -//tag::docsAutoBucketMonth[] +docsBucketMonth +//tag::docsBucketMonth[] FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" -| EVAL month = AUTO_BUCKET(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") +| EVAL month = BUCKET(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") | KEEP hire_date, month | SORT hire_date -//end::docsAutoBucketMonth[] +//end::docsBucketMonth[] ; -//tag::docsAutoBucketMonth-result[] +//tag::docsBucketMonth-result[] hire_date:date | month:date 1985-02-18T00:00:00.000Z|1985-02-01T00:00:00.000Z 1985-02-24T00:00:00.000Z|1985-02-01T00:00:00.000Z @@ -973,20 +973,20 @@ FROM employees 1985-11-20T00:00:00.000Z|1985-11-01T00:00:00.000Z 1985-11-20T00:00:00.000Z|1985-11-01T00:00:00.000Z 1985-11-21T00:00:00.000Z|1985-11-01T00:00:00.000Z -//end::docsAutoBucketMonth-result[] +//end::docsBucketMonth-result[] ; -docsAutoBucketMonthlyHistogram -//tag::docsAutoBucketMonthlyHistogram[] +docsBucketMonthlyHistogram +//tag::docsBucketMonthlyHistogram[] FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" -| EVAL month = AUTO_BUCKET(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") +| EVAL month = BUCKET(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") | STATS hires_per_month = COUNT(*) BY month | SORT month -//end::docsAutoBucketMonthlyHistogram[] +//end::docsBucketMonthlyHistogram[] ; -//tag::docsAutoBucketMonthlyHistogram-result[] +//tag::docsBucketMonthlyHistogram-result[] hires_per_month:long | month:date 2 |1985-02-01T00:00:00.000Z 1 |1985-05-01T00:00:00.000Z @@ -994,20 +994,20 @@ FROM employees 1 |1985-09-01T00:00:00.000Z 2 |1985-10-01T00:00:00.000Z 4 |1985-11-01T00:00:00.000Z -//end::docsAutoBucketMonthlyHistogram-result[] +//end::docsBucketMonthlyHistogram-result[] ; -docsAutoBucketWeeklyHistogram -//tag::docsAutoBucketWeeklyHistogram[] +docsBucketWeeklyHistogram +//tag::docsBucketWeeklyHistogram[] FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" -| EVAL week = AUTO_BUCKET(hire_date, 100, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") +| EVAL week = BUCKET(hire_date, 100, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") | STATS hires_per_week = COUNT(*) BY week | SORT week -//end::docsAutoBucketWeeklyHistogram[] +//end::docsBucketWeeklyHistogram[] ; -//tag::docsAutoBucketWeeklyHistogram-result[] +//tag::docsBucketWeeklyHistogram-result[] hires_per_week:long | week:date 2 |1985-02-18T00:00:00.000Z 1 |1985-05-13T00:00:00.000Z @@ -1015,40 +1015,40 @@ FROM employees 1 |1985-09-16T00:00:00.000Z 2 |1985-10-14T00:00:00.000Z 4 |1985-11-18T00:00:00.000Z -//end::docsAutoBucketWeeklyHistogram-result[] +//end::docsBucketWeeklyHistogram-result[] ; -docsAutoBucketLast24hr#[skip:-8.12.99, reason:date type is supported in 8.13] -//tag::docsAutoBucketLast24hr[] +docsBucketLast24hr#[skip:-8.12.99, reason:date type is supported in 8.13] +//tag::docsBucketLast24hr[] FROM sample_data | WHERE @timestamp >= NOW() - 1 day and @timestamp < NOW() -| EVAL bucket = AUTO_BUCKET(@timestamp, 25, NOW() - 1 day, NOW()) +| EVAL bucket = BUCKET(@timestamp, 25, NOW() - 1 day, NOW()) | STATS COUNT(*) BY bucket -//end::docsAutoBucketLast24hr[] +//end::docsBucketLast24hr[] ; COUNT(*):long | bucket:date ; -docsGettingStartedAutoBucket#[skip:-8.12.99, reason:date type is supported in 8.13] -// tag::gs-auto_bucket[] +docsGettingStartedBucket#[skip:-8.12.99, reason:date type is supported in 8.13] +// tag::gs-bucket[] FROM sample_data | KEEP @timestamp -| EVAL bucket = AUTO_BUCKET(@timestamp, 24, "2023-10-23T00:00:00Z", NOW()) -// end::gs-auto_bucket[] +| EVAL bucket = BUCKET(@timestamp, 24, "2023-10-23T00:00:00Z", NOW()) +// end::gs-bucket[] | LIMIT 0 ; @timestamp:date | bucket:date ; -docsGettingStartedAutoBucketStatsBy -// tag::gs-auto_bucket-stats-by[] +docsGettingStartedBucketStatsBy +// tag::gs-bucket-stats-by[] FROM sample_data | KEEP @timestamp, event_duration -| EVAL bucket = AUTO_BUCKET(@timestamp, 24, "2023-10-23T00:00:00Z", "2023-10-23T23:59:59Z") +| EVAL bucket = BUCKET(@timestamp, 24, "2023-10-23T00:00:00Z", "2023-10-23T23:59:59Z") | STATS COUNT(*) BY bucket -// end::gs-auto_bucket-stats-by[] +// end::gs-bucket-stats-by[] | SORT bucket ; @@ -1057,13 +1057,13 @@ COUNT(*):long | bucket:date 5 |2023-10-23T13:00:00.000Z ; -docsGettingStartedAutoBucketStatsByMedian -// tag::gs-auto_bucket-stats-by-median[] +docsGettingStartedBucketStatsByMedian +// tag::gs-bucket-stats-by-median[] FROM sample_data | KEEP @timestamp, event_duration -| EVAL bucket = AUTO_BUCKET(@timestamp, 24, "2023-10-23T00:00:00Z", "2023-10-23T23:59:59Z") +| EVAL bucket = BUCKET(@timestamp, 24, "2023-10-23T00:00:00Z", "2023-10-23T23:59:59Z") | STATS median_duration = MEDIAN(event_duration) BY bucket -// end::gs-auto_bucket-stats-by-median[] +// end::gs-bucket-stats-by-median[] | SORT bucket ; diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/floats.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/floats.csv-spec index 9c343083275cd..cb5f9e7ab64ed 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/floats.csv-spec +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/floats.csv-spec @@ -257,10 +257,10 @@ emp_no:integer | salary_change:double | a1:double 10005 | [-2.14,13.07] | [-2.14,13.07] ; -autoBucket +bucket FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" -| EVAL bh = auto_bucket(height, 20, 1.41, 2.10) +| EVAL bh = bucket(height, 20, 1.41, 2.10) | SORT hire_date, height | KEEP hire_date, height, bh ; diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/ints.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/ints.csv-spec index 8657602e7b16f..25323dab2dd48 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/ints.csv-spec +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/ints.csv-spec @@ -642,17 +642,17 @@ emp_no:integer | salary_change.long:long | a1:long 10005 | [-2, 13] | [-2, 13] ; -autoBucket -// tag::auto_bucket[] +bucket +// tag::bucket[] FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" -| EVAL bs = AUTO_BUCKET(salary, 20, 25324, 74999) +| EVAL bs = BUCKET(salary, 20, 25324, 74999) | SORT hire_date, salary | KEEP hire_date, salary, bs -// end::auto_bucket[] +// end::bucket[] ; -// tag::auto_bucket-result[] +// tag::bucket-result[] hire_date:date | salary:integer | bs:double 1985-02-18T00:00:00.000Z | 66174 | 65000.0 1985-02-24T00:00:00.000Z | 26436 | 25000.0 @@ -665,19 +665,19 @@ hire_date:date | salary:integer | bs:double 1985-11-20T00:00:00.000Z | 33956 | 30000.0 1985-11-20T00:00:00.000Z | 74999 | 70000.0 1985-11-21T00:00:00.000Z | 56371 | 55000.0 -// end::auto_bucket-result[] +// end::bucket-result[] ; -docsAutoBucketNumeric -//tag::docsAutoBucketNumeric[] +docsBucketNumeric +//tag::docsBucketNumeric[] FROM employees -| EVAL bs = AUTO_BUCKET(salary, 20, 25324, 74999) +| EVAL bs = BUCKET(salary, 20, 25324, 74999) | STATS COUNT(*) by bs | SORT bs -//end::docsAutoBucketNumeric[] +//end::docsBucketNumeric[] ; -//tag::docsAutoBucketNumeric-result[] +//tag::docsBucketNumeric-result[] COUNT(*):long | bs:double 9 |25000.0 9 |30000.0 @@ -689,7 +689,7 @@ FROM employees 9 |60000.0 8 |65000.0 8 |70000.0 -//end::docsAutoBucketNumeric-result[] +//end::docsBucketNumeric-result[] ; cos diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/meta.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/meta.csv-spec index 524de7c2c3b67..655a50cbbee67 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/meta.csv-spec +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/meta.csv-spec @@ -7,8 +7,8 @@ synopsis:keyword "double asin(number:double|integer|long|unsigned_long)" "double atan(number:double|integer|long|unsigned_long)" "double atan2(y_coordinate:double|integer|long|unsigned_long, x_coordinate:double|integer|long|unsigned_long)" -"double|date auto_bucket(field:integer|long|double|date, buckets:integer, from:integer|long|double|date|string, to:integer|long|double|date|string)" "double avg(number:double|integer|long)" +"double|date bucket(field:integer|long|double|date, buckets:integer, from:integer|long|double|date|string, to:integer|long|double|date|string)" "boolean|cartesian_point|date|double|geo_point|integer|ip|keyword|long|text|unsigned_long|version case(condition:boolean, trueValue...:boolean|cartesian_point|date|double|geo_point|integer|ip|keyword|long|text|unsigned_long|version)" "double|integer|long|unsigned_long ceil(number:double|integer|long|unsigned_long)" "boolean cidr_match(ip:ip, blockX...:keyword|text)" @@ -114,8 +114,8 @@ acos |number |"double|integer|long|unsigne asin |number |"double|integer|long|unsigned_long" |Number between -1 and 1. If `null`, the function returns `null`. atan |number |"double|integer|long|unsigned_long" |Numeric expression. If `null`, the function returns `null`. atan2 |[y_coordinate, x_coordinate] |["double|integer|long|unsigned_long", "double|integer|long|unsigned_long"] |[y coordinate. If `null`\, the function returns `null`., x coordinate. If `null`\, the function returns `null`.] -auto_bucket |[field, buckets, from, to] |["integer|long|double|date", integer, "integer|long|double|date|string", "integer|long|double|date|string"] |["", "", "", ""] avg |number |"double|integer|long" |[""] +bucket |[field, buckets, from, to] |["integer|long|double|date", integer, "integer|long|double|date|string", "integer|long|double|date|string"] |["", "", "", ""] case |[condition, trueValue] |[boolean, "boolean|cartesian_point|date|double|geo_point|integer|ip|keyword|long|text|unsigned_long|version"] |["", ""] ceil |number |"double|integer|long|unsigned_long" |Numeric expression. If `null`, the function returns `null`. cidr_match |[ip, blockX] |[ip, "keyword|text"] |[, CIDR block to test the IP against.] @@ -222,8 +222,8 @@ acos |Returns the {wikipedia}/Inverse_trigonometric_functions[arccosine asin |Returns the {wikipedia}/Inverse_trigonometric_functions[arcsine] of the input numeric expression as an angle, expressed in radians. atan |Returns the {wikipedia}/Inverse_trigonometric_functions[arctangent] of the input numeric expression as an angle, expressed in radians. atan2 |The {wikipedia}/Atan2[angle] between the positive x-axis and the ray from the origin to the point (x , y) in the Cartesian plane, expressed in radians. -auto_bucket |Creates human-friendly buckets and returns a datetime value for each row that corresponds to the resulting bucket the row falls into. avg |The average of a numeric field. +bucket |Creates human-friendly buckets and returns a datetime value for each row that corresponds to the resulting bucket the row falls into. case |Accepts pairs of conditions and values. The function returns the value that belongs to the first condition that evaluates to true. ceil |Round a number up to the nearest integer. cidr_match |Returns true if the provided IP is contained in one of the provided CIDR blocks. @@ -331,8 +331,8 @@ acos |double asin |double |false |false |false atan |double |false |false |false atan2 |double |[false, false] |false |false -auto_bucket |"double|date" |[false, false, false, false]|false |false avg |double |false |false |true +bucket |"double|date" |[false, false, false, false]|false |false case |"boolean|cartesian_point|date|double|geo_point|integer|ip|keyword|long|text|unsigned_long|version" |[false, false] |true |false ceil |"double|integer|long|unsigned_long" |false |false |false cidr_match |boolean |[false, false] |true |false diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/unsigned_long.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/unsigned_long.csv-spec index c6f24d876240f..9e249facff55a 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/unsigned_long.csv-spec +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/unsigned_long.csv-spec @@ -150,10 +150,10 @@ warning:Line 1:27: java.lang.IllegalArgumentException: single-value function enc 2017-11-10T20:21:58.000Z|154551962150890564|9382204513185396493|63 |OK ; -autoBucket +bucket FROM ul_logs | WHERE @timestamp >= "2017-11-10T20:30:00Z" AND @timestamp < "2017-11-10T20:35:00Z" -| EVAL bh = auto_bucket(bytes_in, 20, 5480608687137202404, 17764691215469285192) +| EVAL bh = bucket(bytes_in, 20, 5480608687137202404, 17764691215469285192) | SORT @timestamp | KEEP @timestamp, bytes_in, bh ; diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java index 9f0976e0045d3..f3745cb3972b3 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java @@ -48,7 +48,7 @@ import org.elasticsearch.xpack.esql.expression.function.scalar.math.Asin; import org.elasticsearch.xpack.esql.expression.function.scalar.math.Atan; import org.elasticsearch.xpack.esql.expression.function.scalar.math.Atan2; -import org.elasticsearch.xpack.esql.expression.function.scalar.math.AutoBucket; +import org.elasticsearch.xpack.esql.expression.function.scalar.math.Bucket; import org.elasticsearch.xpack.esql.expression.function.scalar.math.Ceil; import org.elasticsearch.xpack.esql.expression.function.scalar.math.Cos; import org.elasticsearch.xpack.esql.expression.function.scalar.math.Cosh; @@ -139,7 +139,7 @@ private FunctionDefinition[][] functions() { def(Asin.class, Asin::new, "asin"), def(Atan.class, Atan::new, "atan"), def(Atan2.class, Atan2::new, "atan2"), - def(AutoBucket.class, AutoBucket::new, "auto_bucket"), + def(Bucket.class, Bucket::new, "bucket"), def(Ceil.class, Ceil::new, "ceil"), def(Cos.class, Cos::new, "cos"), def(Cosh.class, Cosh::new, "cosh"), diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/AutoBucket.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/Bucket.java similarity index 95% rename from x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/AutoBucket.java rename to x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/Bucket.java index b9aeff7f1d935..78427b63bea24 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/AutoBucket.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/Bucket.java @@ -48,13 +48,13 @@ *

* Takes a date field and three constants and picks a bucket size based on the * constants. The constants are "target bucket count", "from", and "to". It looks like: - * {@code auto_bucket(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z")}. + * {@code bucket(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z")}. * We have a list of "human" bucket sizes like "one month" and "four hours". We pick * the largest range that covers the range in fewer than the target bucket count. So * in the above case we'll pick month long buckets, yielding 12 buckets. *

*/ -public class AutoBucket extends EsqlScalarFunction implements Validatable { +public class Bucket extends EsqlScalarFunction implements Validatable { // TODO maybe we should just cover the whole of representable dates here - like ten years, 100 years, 1000 years, all the way up. // That way you never end up with more than the target number of buckets. private static final Rounding LARGEST_HUMAN_DATE_ROUNDING = Rounding.builder(Rounding.DateTimeUnit.YEAR_OF_CENTURY).build(); @@ -86,7 +86,7 @@ public class AutoBucket extends EsqlScalarFunction implements Validatable { @FunctionInfo(returnType = { "double", "date" }, description = """ Creates human-friendly buckets and returns a datetime value for each row that corresponds to the resulting bucket the row falls into.""") - public AutoBucket( + public Bucket( Source source, @Param(name = "field", type = { "integer", "long", "double", "date" }) Expression field, @Param(name = "buckets", type = { "integer" }) Expression buckets, @@ -226,12 +226,12 @@ public DataType dataType() { @Override public Expression replaceChildren(List newChildren) { - return new AutoBucket(source(), newChildren.get(0), newChildren.get(1), newChildren.get(2), newChildren.get(3)); + return new Bucket(source(), newChildren.get(0), newChildren.get(1), newChildren.get(2), newChildren.get(3)); } @Override protected NodeInfo info() { - return NodeInfo.create(this, AutoBucket::new, field, buckets, from, to); + return NodeInfo.create(this, Bucket::new, field, buckets, from, to); } public Expression field() { @@ -252,6 +252,6 @@ public Expression to() { @Override public String toString() { - return "AutoBucket{" + "field=" + field + ", buckets=" + buckets + ", from=" + from + ", to=" + to + '}'; + return "Bucket{" + "field=" + field + ", buckets=" + buckets + ", from=" + from + ", to=" + to + '}'; } } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/io/stream/PlanNamedTypes.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/io/stream/PlanNamedTypes.java index 21c17110ad4fe..a8ed75bc339a0 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/io/stream/PlanNamedTypes.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/io/stream/PlanNamedTypes.java @@ -69,7 +69,7 @@ import org.elasticsearch.xpack.esql.expression.function.scalar.math.Asin; import org.elasticsearch.xpack.esql.expression.function.scalar.math.Atan; import org.elasticsearch.xpack.esql.expression.function.scalar.math.Atan2; -import org.elasticsearch.xpack.esql.expression.function.scalar.math.AutoBucket; +import org.elasticsearch.xpack.esql.expression.function.scalar.math.Bucket; import org.elasticsearch.xpack.esql.expression.function.scalar.math.Ceil; import org.elasticsearch.xpack.esql.expression.function.scalar.math.Cos; import org.elasticsearch.xpack.esql.expression.function.scalar.math.Cosh; @@ -374,7 +374,7 @@ public static List namedTypeEntries() { of(ESQL_UNARY_SCLR_CLS, Trim.class, PlanNamedTypes::writeESQLUnaryScalar, PlanNamedTypes::readESQLUnaryScalar), // ScalarFunction of(ScalarFunction.class, Atan2.class, PlanNamedTypes::writeAtan2, PlanNamedTypes::readAtan2), - of(ScalarFunction.class, AutoBucket.class, PlanNamedTypes::writeAutoBucket, PlanNamedTypes::readAutoBucket), + of(ScalarFunction.class, Bucket.class, PlanNamedTypes::writeAutoBucket, PlanNamedTypes::readAutoBucket), of(ScalarFunction.class, Case.class, PlanNamedTypes::writeVararg, PlanNamedTypes::readVarag), of(ScalarFunction.class, CIDRMatch.class, PlanNamedTypes::writeCIDRMatch, PlanNamedTypes::readCIDRMatch), of(ScalarFunction.class, Coalesce.class, PlanNamedTypes::writeVararg, PlanNamedTypes::readVarag), @@ -1388,11 +1388,11 @@ static void writeAtan2(PlanStreamOutput out, Atan2 atan2) throws IOException { out.writeExpression(atan2.x()); } - static AutoBucket readAutoBucket(PlanStreamInput in) throws IOException { - return new AutoBucket(in.readSource(), in.readExpression(), in.readExpression(), in.readExpression(), in.readExpression()); + static Bucket readAutoBucket(PlanStreamInput in) throws IOException { + return new Bucket(in.readSource(), in.readExpression(), in.readExpression(), in.readExpression(), in.readExpression()); } - static void writeAutoBucket(PlanStreamOutput out, AutoBucket bucket) throws IOException { + static void writeAutoBucket(PlanStreamOutput out, Bucket bucket) throws IOException { out.writeSource(bucket.source()); out.writeExpression(bucket.field()); out.writeExpression(bucket.buckets()); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/AutoBucketTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/BucketTests.java similarity index 95% rename from x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/AutoBucketTests.java rename to x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/BucketTests.java index 013753c801c39..3de096dcb3c6f 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/AutoBucketTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/BucketTests.java @@ -27,8 +27,8 @@ import static org.hamcrest.Matchers.equalTo; -public class AutoBucketTests extends AbstractScalarFunctionTestCase { - public AutoBucketTests(@Name("TestCase") Supplier testCaseSupplier) { +public class BucketTests extends AbstractScalarFunctionTestCase { + public BucketTests(@Name("TestCase") Supplier testCaseSupplier) { this.testCase = testCaseSupplier.get(); } @@ -90,7 +90,7 @@ private Expression build(Source source, Expression arg) { from = new Literal(Source.EMPTY, 0, DataTypes.DOUBLE); to = new Literal(Source.EMPTY, 1000, DataTypes.DOUBLE); } - return new AutoBucket(source, arg, new Literal(Source.EMPTY, 50, DataTypes.INTEGER), from, to); + return new Bucket(source, arg, new Literal(Source.EMPTY, 50, DataTypes.INTEGER), from, to); } private Literal stringOrDateTime(String date) { diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java index 3f0b39603ef89..113ad17c39e98 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java @@ -3006,7 +3006,7 @@ public void testLogicalPlanOptimizerVerifier() { var plan = plan(""" from test | eval bucket_start = 1, bucket_end = 100000 - | eval auto_bucket(salary, 10, bucket_start, bucket_end) + | eval bucket(salary, 10, bucket_start, bucket_end) """); var ab = as(plan, Eval.class); assertTrue(ab.optimized()); @@ -3016,12 +3016,12 @@ public void testLogicalPlanOptimizerVerificationException() { VerificationException e = expectThrows(VerificationException.class, () -> plan(""" from test | eval bucket_end = 100000 - | eval auto_bucket(salary, 10, emp_no, bucket_end) + | eval bucket(salary, 10, emp_no, bucket_end) """)); assertTrue(e.getMessage().startsWith("Found ")); final String header = "Found 1 problem\nline "; assertEquals( - "3:32: third argument of [auto_bucket(salary, 10, emp_no, bucket_end)] must be a constant, received [emp_no]", + "3:27: third argument of [bucket(salary, 10, emp_no, bucket_end)] must be a constant, received [emp_no]", e.getMessage().substring(header.length()) ); } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/IndexResolverFieldNamesTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/IndexResolverFieldNamesTests.java index 17ad5eb8b9f3d..1618cb152e2d9 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/IndexResolverFieldNamesTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/IndexResolverFieldNamesTests.java @@ -216,7 +216,7 @@ public void testAutoBucketMonth() { assertFieldNames(""" from employees | where hire_date >= "1985-01-01T00:00:00Z" and hire_date < "1986-01-01T00:00:00Z" - | eval hd = auto_bucket(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") + | eval hd = bucket(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") | sort hire_date | keep hire_date, hd""", Set.of("hire_date", "hire_date.*")); } @@ -232,7 +232,7 @@ public void testAutoBucketMonthInAgg() { assertFieldNames(""" FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" - | EVAL bucket = AUTO_BUCKET(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") + | EVAL bucket = BUCKET(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") | STATS AVG(salary) BY bucket | SORT bucket""", Set.of("salary", "salary.*", "hire_date", "hire_date.*")); } @@ -558,7 +558,7 @@ public void testAutoBucket() { assertFieldNames(""" FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" - | EVAL bh = auto_bucket(height, 20, 1.41, 2.10) + | EVAL bh = bucket(height, 20, 1.41, 2.10) | SORT hire_date | KEEP hire_date, height, bh""", Set.of("hire_date", "hire_date.*", "height", "height.*")); } From cf419396fcb967599d6fde832cff6d6ffa5c300e Mon Sep 17 00:00:00 2001 From: Bogdan Pintea Date: Thu, 4 Apr 2024 16:32:59 +0200 Subject: [PATCH 2/4] more renamings --- .../elasticsearch/xpack/esql/io/stream/PlanNamedTypes.java | 6 +++--- .../xpack/esql/session/IndexResolverFieldNamesTests.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/io/stream/PlanNamedTypes.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/io/stream/PlanNamedTypes.java index a8ed75bc339a0..42d568498215b 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/io/stream/PlanNamedTypes.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/io/stream/PlanNamedTypes.java @@ -374,7 +374,7 @@ public static List namedTypeEntries() { of(ESQL_UNARY_SCLR_CLS, Trim.class, PlanNamedTypes::writeESQLUnaryScalar, PlanNamedTypes::readESQLUnaryScalar), // ScalarFunction of(ScalarFunction.class, Atan2.class, PlanNamedTypes::writeAtan2, PlanNamedTypes::readAtan2), - of(ScalarFunction.class, Bucket.class, PlanNamedTypes::writeAutoBucket, PlanNamedTypes::readAutoBucket), + of(ScalarFunction.class, Bucket.class, PlanNamedTypes::writeBucket, PlanNamedTypes::readBucket), of(ScalarFunction.class, Case.class, PlanNamedTypes::writeVararg, PlanNamedTypes::readVarag), of(ScalarFunction.class, CIDRMatch.class, PlanNamedTypes::writeCIDRMatch, PlanNamedTypes::readCIDRMatch), of(ScalarFunction.class, Coalesce.class, PlanNamedTypes::writeVararg, PlanNamedTypes::readVarag), @@ -1388,11 +1388,11 @@ static void writeAtan2(PlanStreamOutput out, Atan2 atan2) throws IOException { out.writeExpression(atan2.x()); } - static Bucket readAutoBucket(PlanStreamInput in) throws IOException { + static Bucket readBucket(PlanStreamInput in) throws IOException { return new Bucket(in.readSource(), in.readExpression(), in.readExpression(), in.readExpression(), in.readExpression()); } - static void writeAutoBucket(PlanStreamOutput out, Bucket bucket) throws IOException { + static void writeBucket(PlanStreamOutput out, Bucket bucket) throws IOException { out.writeSource(bucket.source()); out.writeExpression(bucket.field()); out.writeExpression(bucket.buckets()); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/IndexResolverFieldNamesTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/IndexResolverFieldNamesTests.java index 1618cb152e2d9..ff6c60310fd87 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/IndexResolverFieldNamesTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/IndexResolverFieldNamesTests.java @@ -212,7 +212,7 @@ public void testIn2() { | limit 4""", Set.of("hire_date", "hire_date.*", "birth_date", "birth_date.*")); } - public void testAutoBucketMonth() { + public void testBucketMonth() { assertFieldNames(""" from employees | where hire_date >= "1985-01-01T00:00:00Z" and hire_date < "1986-01-01T00:00:00Z" @@ -228,7 +228,7 @@ public void testBorn_before_today() { ); } - public void testAutoBucketMonthInAgg() { + public void testBucketMonthInAgg() { assertFieldNames(""" FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" @@ -554,7 +554,7 @@ public void testConvertFromDatetime() { ); } - public void testAutoBucket() { + public void testBucket() { assertFieldNames(""" FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" From 99b1b0462440bebde31bb4a154956be02e2f41f5 Mon Sep 17 00:00:00 2001 From: Bogdan Pintea Date: Fri, 5 Apr 2024 16:40:03 +0200 Subject: [PATCH 3/4] Further renamings --- .../esql/expression/function/scalar/math/BucketTests.java | 8 ++++---- .../xpack/esql/optimizer/LogicalPlanOptimizerTests.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/BucketTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/BucketTests.java index 3de096dcb3c6f..b4dd54bf0e8be 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/BucketTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/BucketTests.java @@ -34,7 +34,7 @@ public BucketTests(@Name("TestCase") Supplier testCas @ParametersFactory public static Iterable parameters() { - return parameterSuppliersFromTypedData(List.of(new TestCaseSupplier("Autobucket Single date", () -> { + return parameterSuppliersFromTypedData(List.of(new TestCaseSupplier("Bucket Single date", () -> { List args = List.of( new TestCaseSupplier.TypedData( DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parseMillis("2023-02-17T09:00:00.00Z"), @@ -48,7 +48,7 @@ public static Iterable parameters() { DataTypes.DATETIME, dateResultsMatcher(args) ); - }), new TestCaseSupplier("Autobucket Single long", () -> { + }), new TestCaseSupplier("Bucket Single long", () -> { List args = List.of(new TestCaseSupplier.TypedData(100L, DataTypes.LONG, "arg")); return new TestCaseSupplier.TestCase( args, @@ -58,7 +58,7 @@ public static Iterable parameters() { DataTypes.DOUBLE, numericResultsMatcher(args, 100.0) ); - }), new TestCaseSupplier("Autobucket Single int", () -> { + }), new TestCaseSupplier("Bucket Single int", () -> { List args = List.of(new TestCaseSupplier.TypedData(100, DataTypes.INTEGER, "arg")); return new TestCaseSupplier.TestCase( args, @@ -68,7 +68,7 @@ public static Iterable parameters() { DataTypes.DOUBLE, numericResultsMatcher(args, 100.0) ); - }), new TestCaseSupplier("Autobucket Single double", () -> { + }), new TestCaseSupplier("Bucket Single double", () -> { List args = List.of(new TestCaseSupplier.TypedData(100.0, DataTypes.DOUBLE, "arg")); return new TestCaseSupplier.TestCase( args, diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java index 113ad17c39e98..62b0e2fcb08ff 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java @@ -3002,7 +3002,7 @@ public void testNestedMultiExpressionsInGroupingAndAggs() { assertThat(Expressions.names(agg.output()), contains("count(salary + 1)", "max(salary + 23)", "languages + 1", "emp_no % 3")); } - public void testLogicalPlanOptimizerVerifier() { + public void testBucketAcceptsEvalLiteralReferences() { var plan = plan(""" from test | eval bucket_start = 1, bucket_end = 100000 @@ -3012,7 +3012,7 @@ public void testLogicalPlanOptimizerVerifier() { assertTrue(ab.optimized()); } - public void testLogicalPlanOptimizerVerificationException() { + public void testBucketFailsOnFieldArgument() { VerificationException e = expectThrows(VerificationException.class, () -> plan(""" from test | eval bucket_end = 100000 From 8c1ed8bea0218bc08b1168a4b1bff1e5e8f3a905 Mon Sep 17 00:00:00 2001 From: Bogdan Pintea Date: Fri, 5 Apr 2024 23:49:53 +0200 Subject: [PATCH 4/4] Disable some bwc tests --- .../src/main/resources/date.csv-spec | 34 +++++++++---------- .../src/main/resources/floats.csv-spec | 2 +- .../src/main/resources/ints.csv-spec | 4 +-- .../src/main/resources/unsigned_long.csv-spec | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/date.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/date.csv-spec index 88b126d515330..5b3b6235ccb8b 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/date.csv-spec +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/date.csv-spec @@ -261,7 +261,7 @@ int:integer |dt:date // end::to_datetime-int-result[] ; -bucketSimpleMonth +bucketSimpleMonth#[skip:-8.13.99, reason:BUCKET renamed in 8.14] // tag::bucket_month[] ROW date=TO_DATETIME("1985-07-09T00:00:00.000Z") | EVAL bucket=BUCKET(date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") @@ -274,7 +274,7 @@ ROW date=TO_DATETIME("1985-07-09T00:00:00.000Z") // end::bucket_month-result[] ; -bucketSimpleWeek +bucketSimpleWeek#[skip:-8.13.99, reason:BUCKET renamed in 8.14] // tag::bucket_week[] ROW date=TO_DATETIME("1985-07-09T00:00:00.000Z") | EVAL bucket=BUCKET(date, 100, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") @@ -287,7 +287,7 @@ ROW date=TO_DATETIME("1985-07-09T00:00:00.000Z") // end::bucket_week-result[] ; -bucketMonth +bucketMonth#[skip:-8.13.99, reason:BUCKET renamed in 8.14] from employees | where hire_date >= "1985-01-01T00:00:00Z" and hire_date < "1986-01-01T00:00:00Z" | eval hd = bucket(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") @@ -308,7 +308,7 @@ hire_date:date | hd:date 1985-11-21T00:00:00.000Z | 1985-11-01T00:00:00.000Z ; -bucketWeek +bucketWeek#[skip:-8.13.99, reason:BUCKET renamed in 8.14] from employees | where hire_date >= "1985-01-01T00:00:00Z" and hire_date < "1986-01-01T00:00:00Z" | eval hd = bucket(hire_date, 55, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z") @@ -350,7 +350,7 @@ from employees | where birth_date > now() | sort emp_no asc | keep emp_no, birth emp_no:integer | birth_date:date ; -bucketYearInAgg#[skip:-8.12.99, reason:date type is supported in 8.13] +bucketYearInAgg#[skip:-8.13.99, reason:BUCKET renamed in 8.14] FROM employees | WHERE hire_date >= "1999-01-01T00:00:00Z" | EVAL bucket = BUCKET(hire_date, 5, "1999-01-01T00:00:00Z", NOW()) @@ -361,7 +361,7 @@ COUNT(*):long | bucket:date 1 | 1999-01-01T00:00:00.000Z ; -bucketYearInAggConstRefsString#[skip:-8.12.99, reason:date type is supported in 8.13] +bucketYearInAggConstRefsString#[skip:-8.13.99, reason:BUCKET renamed in 8.14] FROM employees | WHERE hire_date >= "1999-01-01T00:00:00Z" | EVAL bucket_start = "1999-01-01T00:00:00Z" @@ -374,7 +374,7 @@ COUNT(*):long | bucket:date 1 | 1999-01-01T00:00:00.000Z ; -bucketYearInAggConstRefsConcat#[skip:-8.12.99, reason:date type is supported in 8.13] +bucketYearInAggConstRefsConcat#[skip:-8.13.99, reason:BUCKET renamed in 8.14] FROM employees | WHERE hire_date >= "1999-01-01T00:00:00Z" | EVAL bucket_start = CONCAT("1999-01-01", "T", "00:00:00Z") @@ -387,7 +387,7 @@ COUNT(*):long | bucket:date 1 | 1999-01-01T00:00:00.000Z ; -bucketYearInAggConstRefsDate#[skip:-8.12.99, reason:date type is supported in 8.13] +bucketYearInAggConstRefsDate#[skip:-8.13.99, reason:BUCKET renamed in 8.14] FROM employees | WHERE hire_date >= "1999-01-01T00:00:00Z" | EVAL bucket_start = TO_DATETIME("1999-01-01T00:00:00.000Z") @@ -401,7 +401,7 @@ COUNT(*):long | bucket:date 1 | 1999-01-01T00:00:00.000Z ; -bucketYearInAggConstRefsRename#[skip:-8.12.99, reason:date type is supported in 8.13] +bucketYearInAggConstRefsRename#[skip:-8.13.99, reason:BUCKET renamed in 8.14] FROM employees | WHERE hire_date >= "1999-01-01T00:00:00Z" | EVAL bucket_start = "1999-01-01T00:00:00Z" @@ -415,7 +415,7 @@ c:long | BUCKET(hire_date, 5, bs, be):date 1 | 1999-01-01T00:00:00.000Z ; -bucketMonthInAgg +bucketMonthInAgg#[skip:-8.13.99, reason:BUCKET renamed in 8.14] // tag::bucket_in_agg[] FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" @@ -950,7 +950,7 @@ birth_date:datetime 1953-04-21T00:00:00.000Z ; -docsBucketMonth +docsBucketMonth#[skip:-8.13.99, reason:BUCKET renamed in 8.14] //tag::docsBucketMonth[] FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" @@ -976,7 +976,7 @@ FROM employees //end::docsBucketMonth-result[] ; -docsBucketMonthlyHistogram +docsBucketMonthlyHistogram#[skip:-8.13.99, reason:BUCKET renamed in 8.14] //tag::docsBucketMonthlyHistogram[] FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" @@ -997,7 +997,7 @@ FROM employees //end::docsBucketMonthlyHistogram-result[] ; -docsBucketWeeklyHistogram +docsBucketWeeklyHistogram#[skip:-8.13.99, reason:BUCKET renamed in 8.14] //tag::docsBucketWeeklyHistogram[] FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" @@ -1018,7 +1018,7 @@ FROM employees //end::docsBucketWeeklyHistogram-result[] ; -docsBucketLast24hr#[skip:-8.12.99, reason:date type is supported in 8.13] +docsBucketLast24hr#[skip:-8.13.99, reason:BUCKET renamed in 8.14] //tag::docsBucketLast24hr[] FROM sample_data | WHERE @timestamp >= NOW() - 1 day and @timestamp < NOW() @@ -1030,7 +1030,7 @@ FROM sample_data COUNT(*):long | bucket:date ; -docsGettingStartedBucket#[skip:-8.12.99, reason:date type is supported in 8.13] +docsGettingStartedBucket#[skip:-8.13.99, reason:BUCKET renamed in 8.14] // tag::gs-bucket[] FROM sample_data | KEEP @timestamp @@ -1042,7 +1042,7 @@ FROM sample_data @timestamp:date | bucket:date ; -docsGettingStartedBucketStatsBy +docsGettingStartedBucketStatsBy#[skip:-8.13.99, reason:BUCKET renamed in 8.14] // tag::gs-bucket-stats-by[] FROM sample_data | KEEP @timestamp, event_duration @@ -1057,7 +1057,7 @@ COUNT(*):long | bucket:date 5 |2023-10-23T13:00:00.000Z ; -docsGettingStartedBucketStatsByMedian +docsGettingStartedBucketStatsByMedian#[skip:-8.13.99, reason:BUCKET renamed in 8.14] // tag::gs-bucket-stats-by-median[] FROM sample_data | KEEP @timestamp, event_duration diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/floats.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/floats.csv-spec index a187e980199b9..8f8f218fd9821 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/floats.csv-spec +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/floats.csv-spec @@ -257,7 +257,7 @@ emp_no:integer | salary_change:double | a1:double 10005 | [-2.14,13.07] | [-2.14,13.07] ; -bucket +bucket#[skip:-8.13.99, reason:BUCKET renamed in 8.14] FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" | EVAL bh = bucket(height, 20, 1.41, 2.10) diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/ints.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/ints.csv-spec index a4587d8cd2715..026e3d922d00d 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/ints.csv-spec +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/ints.csv-spec @@ -642,7 +642,7 @@ emp_no:integer | salary_change.long:long | a1:long 10005 | [-2, 13] | [-2, 13] ; -bucket +bucket#[skip:-8.13.99, reason:BUCKET renamed in 8.14] // tag::bucket[] FROM employees | WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z" @@ -668,7 +668,7 @@ hire_date:date | salary:integer | bs:double // end::bucket-result[] ; -docsBucketNumeric +docsBucketNumeric#[skip:-8.13.99, reason:BUCKET renamed in 8.14] //tag::docsBucketNumeric[] FROM employees | EVAL bs = BUCKET(salary, 20, 25324, 74999) diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/unsigned_long.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/unsigned_long.csv-spec index 9e40fd2cb1fd2..2bf9259478032 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/unsigned_long.csv-spec +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/unsigned_long.csv-spec @@ -150,7 +150,7 @@ warning:Line 1:27: java.lang.IllegalArgumentException: single-value function enc 2017-11-10T20:21:58.000Z|154551962150890564|9382204513185396493|63 |OK ; -bucket +bucket#[skip:-8.13.99, reason:BUCKET renamed in 8.14] FROM ul_logs | WHERE @timestamp >= "2017-11-10T20:30:00Z" AND @timestamp < "2017-11-10T20:35:00Z" | EVAL bh = bucket(bytes_in, 20, 5480608687137202404, 17764691215469285192)