Introduced in: v21.10.0
Like quantileBFloat16 but takes into account the weight of each sequence member.
Computes an approximate quantile of a sample consisting of bfloat16 numbers.
bfloat16 is a floating-point data type with 1 sign bit, 8 exponent bits and 7 fraction bits.
The function converts input values to 32-bit floats and takes the most significant 16 bits.
Then it calculates bfloat16 quantile value and converts the result to a 64-bit float by appending zero bits.
The function is a fast quantile estimator with a maximum relative error of 0.78125% (and an average relative error of approximately 0.27%), corresponding to the 7-bit mantissa precision of bfloat16.
Syntax
quantileBFloat16Weighted(level)(expr, weight)Arguments
expr— Expression over the column values resulting in numeric data types,DateorDateTime.(U)Int*orFloat*orDateorDateTimeweight— Column with weights of sequence members. Weight is a number of value occurrences.UInt*
Returned value
Approximate quantile of the specified level. For Date and DateTime inputs the output format matches the input format. Float64 or Date or DateTime
Examples
Computing weighted quantile with bfloat16
CREATE TABLE example_table (a UInt32, b Float32, w UInt32) ENGINE = Memory;
INSERT INTO example_table VALUES (1, 1.001, 1), (2, 1.002, 2), (3, 1.003, 3), (4, 1.004, 4);
SELECT quantileBFloat16Weighted(0.75)(a, w), quantileBFloat16Weighted(0.75)(b, w) FROM example_table;┌─quantileBFloat16Weighted(0.75)(a, w)─┬─quantileBFloat16Weighted(0.75)(b, w)─┐
│ 4 │ 1 │
└──────────────────────────────────────┴──────────────────────────────────────┘