Skip to content

Commit

Permalink
ESQL: Rename AUTO_BUCKET to just BUCKET (#107197)
Browse files Browse the repository at this point in the history
This renames the function AUTO_BUCKET to just BUCKET.
It also removes the experimental tagging of the function in the docs, making it generally available.
  • Loading branch information
bpintea authored Apr 10, 2024
1 parent 62729c9 commit d6f9d1e
Show file tree
Hide file tree
Showing 21 changed files with 157 additions and 159 deletions.
10 changes: 5 additions & 5 deletions docs/reference/esql/esql-get-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -240,30 +240,30 @@ 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
<<esql-auto_bucket>> function. `AUTO_BUCKET` creates human-friendly bucket sizes
<<esql-bucket>> function. `BUCKET` creates human-friendly bucket sizes
and returns a value for each row that corresponds to the resulting bucket the
row falls into.

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 <<esql-stats-by>> to create a histogram. For example,
Combine `BUCKET` with <<esql-stats-by>> 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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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*
Expand All @@ -28,68 +26,68 @@ 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
<<esql-stats-by>> 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
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 <<esql-where>> to filter rows.
`BUCKET` with <<esql-where>> 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
Expand All @@ -104,17 +102,17 @@ 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
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]
|===
4 changes: 2 additions & 2 deletions docs/reference/esql/functions/date-time-functions.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{esql} supports these date-time functions:

// tag::date_list[]
* experimental:[] <<esql-auto_bucket>>
* <<esql-bucket>>
* <<esql-date_diff>>
* <<esql-date_extract>>
* <<esql-date_format>>
Expand All @@ -17,7 +17,7 @@
* <<esql-now>>
// end::date_list[]

include::auto_bucket.asciidoc[]
include::bucket.asciidoc[]
include::date_diff.asciidoc[]
include::date_extract.asciidoc[]
include::date_format.asciidoc[]
Expand Down
14 changes: 0 additions & 14 deletions docs/reference/esql/functions/layout/auto_bucket.asciidoc

This file was deleted.

14 changes: 14 additions & 0 deletions docs/reference/esql/functions/layout/bucket.asciidoc
Original file line number Diff line number Diff line change
@@ -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[]
1 change: 0 additions & 1 deletion docs/reference/esql/functions/signature/auto_bucket.svg

This file was deleted.

1 change: 1 addition & 0 deletions docs/reference/esql/functions/signature/bucket.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d6f9d1e

Please sign in to comment.