Class WidthBucket


public class WidthBucket extends NumericArgumentFunction
WIDTH_BUCKET(value, min, max, count) — which of count equal buckets between min and max the value falls in, 0 below the range and count + 1 above it.

A REVERSED range is legal and buckets downwards: over (10, 0, 5) the buckets are (8,10], (6,8] … and the two out-of-range answers swap places, so a value above min is 0 and one at or below max is count + 1. Frostlake answered 0 for every reversed call, since it only ever compared the value against the arguments in the order they were written.

A bucket count that is not positive, and a range whose ends are EQUAL, are the same refusal, and it names all three numbers — with the two bounds printed as UNSCALED integers at the widest scale among the value and the bounds, which is how Snowflake holds them:

   WIDTH_BUCKET(<NUMBER(10,2)>, 0, 10, 0)   … 0 (min_value) != 1000 (max_value)
   WIDTH_BUCKET(<NUMBER(38,0)>, 0, 10, 0)   … 0 (min_value) != 10 (max_value)
   WIDTH_BUCKET(<NUMBER(10,2)>, 0.5, 10.5, 0)  … 50 (min_value) != 1050 (max_value)
 

Any NULL argument makes the answer NULL, the bucket count included.

  • Constructor Details

    • WidthBucket

      public WidthBucket()
  • Method Details

    • evaluate

      public Object evaluate(List<Object> args)
      Description copied from class: BuiltInFunction
      Computes the function's result over its already-evaluated argument values. A SQL NULL argument arrives as Java null, and returning null makes the SQL result NULL.
      Specified by:
      evaluate in class BuiltInFunction
      Parameters:
      args - the argument values, in call order
      Returns:
      the function's value for these arguments, or null for SQL NULL
    • getMinArgCount

      public int getMinArgCount()
      Description copied from class: BuiltInFunction
      The fewest arguments a call to this function may pass; fewer is an argument-count error.
      Specified by:
      getMinArgCount in class BuiltInFunction
      Returns:
      the minimum accepted argument count
    • getMaxArgCount

      public int getMaxArgCount()
      Description copied from class: BuiltInFunction
      The most arguments a call to this function may pass; Integer.MAX_VALUE marks a variadic function (see BuiltInFunction.isVariadic()).
      Specified by:
      getMaxArgCount in class BuiltInFunction
      Returns:
      the maximum accepted argument count