Width bucket

Supported in: Batch, Faster, Streaming

Splits the range from the minimum to the maximum value into a number of equal-width buckets and returns the 1-based bucket a value falls in. Returns 0 for a value before the range and the number of buckets plus one for a value after it. If the minimum is greater than the maximum, the buckets are numbered from the minimum down. Returns null if the number of buckets is not positive or is the maximum long, if the bounds are equal or not finite, or if the value is not a number.

Expression categories: Numeric

Declared arguments

  • Expression: Number to find the bucket of.
    Expression<Numeric>
  • Maximum value: End of the bucketed range.
    Expression<Numeric>
  • Minimum value: Start of the bucketed range.
    Expression<Numeric>
  • Number of buckets: Number of buckets to split the range into.
    Expression<Byte | Integer | Long | Short>

Output type: Long

Examples

Example 1: Base case

Description: The second value is before the range and the third after it. The fourth range runs down from its minimum.

Argument values:

  • Expression: value
  • Maximum value: max
  • Minimum value: min
  • Number of buckets: buckets
valueminmaxbucketsOutput
5.30.210.653
-2.11.33.430
8.10.05.745
4.010.00.054

Example 2: Null case

Argument values:

  • Expression: value
  • Maximum value: max
  • Minimum value: min
  • Number of buckets: buckets
valueminmaxbucketsOutput
null0.010.05null
5.0null10.05null
5.00.0null5null
5.00.010.0nullnull