Deli z drugimi prek


tuple_union_agg_integer aggregate function

Applies to: check marked yes Databricks Runtime 18.1 and above

Unions multiple TupleSketch binary representations with integer summaries into a single merged sketch. Use this function to combine pre-aggregated sketches from different partitions or data sources.

Syntax

tuple_union_agg_integer ( sketch [, lgNomEntries [, mode ]] )

Arguments

  • sketch: A TupleSketch in binary format with integer summaries (such as from tuple_sketch_agg_integer).
  • lgNomEntries: An optional INTEGER literal specifying the log-base-2 of nominal entries for the union. Must be between 4 and 26, inclusive. The default is 12.
  • mode: An optional STRING literal specifying the aggregation mode for combining duplicate key summaries. Valid values: 'sum', 'min', 'max', 'alwaysone'. The default is 'sum'.

Returns

A BINARY value containing the merged TupleSketch with integer summaries.

Notes

  • NULL input sketches are ignored during aggregation.
  • The union operation combines sketches even when they have different lgNomEntries values.
  • For merging exactly two sketches, use the scalar tuple_union_integer function.

Error messages

Examples

-- Union sketches from different partitions
> SELECT tuple_sketch_estimate_integer(tuple_union_agg_integer(sketch)) FROM (
    SELECT tuple_sketch_agg_integer(key, summary) as sketch FROM VALUES (1, 5), (2, 10) tab(key, summary)
    UNION ALL
    SELECT tuple_sketch_agg_integer(key, summary) as sketch FROM VALUES (2, 3), (3, 7) tab(key, summary)
  );
3.0