-- approx_top_k_estimate
SELECT approx_top_k_estimate(approx_top_k_accumulate(expr)) FROM VALUES (0), (0), (1), (1), (2), (3), (4), (4) AS tab(expr);
+--------------------------------------------------------------+
|approx_top_k_estimate(approx_top_k_accumulate(expr, 10000), 5)|
+--------------------------------------------------------------+
|                                          [{0, 2}, {4, 2}, ...|
+--------------------------------------------------------------+

SELECT approx_top_k_estimate(approx_top_k_accumulate(expr), 2) FROM VALUES 'a', 'b', 'c', 'c', 'c', 'c', 'd', 'd' tab(expr);
+--------------------------------------------------------------+
|approx_top_k_estimate(approx_top_k_accumulate(expr, 10000), 2)|
+--------------------------------------------------------------+
|                                              [{c, 4}, {d, 2}]|
+--------------------------------------------------------------+

-- hll_sketch_estimate
SELECT hll_sketch_estimate(hll_sketch_agg(col)) FROM VALUES (1), (1), (2), (2), (3) tab(col);
+--------------------------------------------+
|hll_sketch_estimate(hll_sketch_agg(col, 12))|
+--------------------------------------------+
|                                           3|
+--------------------------------------------+

-- hll_union
SELECT hll_sketch_estimate(hll_union(hll_sketch_agg(col1), hll_sketch_agg(col2))) FROM VALUES (1, 4), (1, 4), (2, 5), (2, 5), (3, 6) tab(col1, col2);
+-----------------------------------------------------------------------------------------+
|hll_sketch_estimate(hll_union(hll_sketch_agg(col1, 12), hll_sketch_agg(col2, 12), false))|
+-----------------------------------------------------------------------------------------+
|                                                                                        6|
+-----------------------------------------------------------------------------------------+

-- kll_sketch_get_n_bigint
SELECT kll_sketch_get_n_bigint(kll_sketch_agg_bigint(col)) FROM VALUES (1), (2), (3), (4), (5) tab(col);
+---------------------------------------------------+
|kll_sketch_get_n_bigint(kll_sketch_agg_bigint(col))|
+---------------------------------------------------+
|                                                  5|
+---------------------------------------------------+

-- kll_sketch_get_n_double
SELECT kll_sketch_get_n_double(kll_sketch_agg_double(col)) FROM VALUES (CAST(1.0 AS DOUBLE)), (CAST(2.0 AS DOUBLE)), (CAST(3.0 AS DOUBLE)), (CAST(4.0 AS DOUBLE)), (CAST(5.0 AS DOUBLE)) tab(col);
+---------------------------------------------------+
|kll_sketch_get_n_double(kll_sketch_agg_double(col))|
+---------------------------------------------------+
|                                                  5|
+---------------------------------------------------+

-- kll_sketch_get_n_float
SELECT kll_sketch_get_n_float(kll_sketch_agg_float(col)) FROM VALUES (CAST(1.0 AS FLOAT)), (CAST(2.0 AS FLOAT)), (CAST(3.0 AS FLOAT)), (CAST(4.0 AS FLOAT)), (CAST(5.0 AS FLOAT)) tab(col);
+-------------------------------------------------+
|kll_sketch_get_n_float(kll_sketch_agg_float(col))|
+-------------------------------------------------+
|                                                5|
+-------------------------------------------------+

-- kll_sketch_get_quantile_bigint
SELECT kll_sketch_get_quantile_bigint(kll_sketch_agg_bigint(col), 0.5) > 1 FROM VALUES (1), (2), (3), (4), (5) tab(col);
+---------------------------------------------------------------------+
|(kll_sketch_get_quantile_bigint(kll_sketch_agg_bigint(col), 0.5) > 1)|
+---------------------------------------------------------------------+
|                                                                 true|
+---------------------------------------------------------------------+

-- kll_sketch_get_quantile_double
SELECT kll_sketch_get_quantile_double(kll_sketch_agg_double(col), 0.5) > 1 FROM VALUES (CAST(1.0 AS DOUBLE)), (CAST(2.0 AS DOUBLE)), (CAST(3.0 AS DOUBLE)), (CAST(4.0 AS DOUBLE)), (CAST(5.0 AS DOUBLE)) tab(col);
+---------------------------------------------------------------------+
|(kll_sketch_get_quantile_double(kll_sketch_agg_double(col), 0.5) > 1)|
+---------------------------------------------------------------------+
|                                                                 true|
+---------------------------------------------------------------------+

-- kll_sketch_get_quantile_float
SELECT kll_sketch_get_quantile_float(kll_sketch_agg_float(col), 0.5) > 1 FROM VALUES (CAST(1.0 AS FLOAT)), (CAST(2.0 AS FLOAT)), (CAST(3.0 AS FLOAT)), (CAST(4.0 AS FLOAT)), (CAST(5.0 AS FLOAT)) tab(col);
+-------------------------------------------------------------------+
|(kll_sketch_get_quantile_float(kll_sketch_agg_float(col), 0.5) > 1)|
+-------------------------------------------------------------------+
|                                                               true|
+-------------------------------------------------------------------+

-- kll_sketch_get_rank_bigint
SELECT kll_sketch_get_rank_bigint(kll_sketch_agg_bigint(col), 3) > 0.3 FROM VALUES (1), (2), (3), (4), (5) tab(col);
+-----------------------------------------------------------------+
|(kll_sketch_get_rank_bigint(kll_sketch_agg_bigint(col), 3) > 0.3)|
+-----------------------------------------------------------------+
|                                                             true|
+-----------------------------------------------------------------+

-- kll_sketch_get_rank_double
SELECT kll_sketch_get_rank_double(kll_sketch_agg_double(col), 3.0) > 0.3 FROM VALUES (CAST(1.0 AS DOUBLE)), (CAST(2.0 AS DOUBLE)), (CAST(3.0 AS DOUBLE)), (CAST(4.0 AS DOUBLE)), (CAST(5.0 AS DOUBLE)) tab(col);
+-------------------------------------------------------------------+
|(kll_sketch_get_rank_double(kll_sketch_agg_double(col), 3.0) > 0.3)|
+-------------------------------------------------------------------+
|                                                               true|
+-------------------------------------------------------------------+

-- kll_sketch_get_rank_float
SELECT kll_sketch_get_rank_float(kll_sketch_agg_float(col), 3.0) > 0.3 FROM VALUES (CAST(1.0 AS FLOAT)), (CAST(2.0 AS FLOAT)), (CAST(3.0 AS FLOAT)), (CAST(4.0 AS FLOAT)), (CAST(5.0 AS FLOAT)) tab(col);
+-----------------------------------------------------------------+
|(kll_sketch_get_rank_float(kll_sketch_agg_float(col), 3.0) > 0.3)|
+-----------------------------------------------------------------+
|                                                             true|
+-----------------------------------------------------------------+

-- kll_sketch_merge_bigint
SELECT LENGTH(kll_sketch_to_string_bigint(kll_sketch_merge_bigint(kll_sketch_agg_bigint(col), kll_sketch_agg_bigint(col)))) > 0 FROM VALUES (1), (2), (3), (4), (5) tab(col);
+--------------------------------------------------------------------------------------------------------------------------+
|(length(kll_sketch_to_string_bigint(kll_sketch_merge_bigint(kll_sketch_agg_bigint(col), kll_sketch_agg_bigint(col)))) > 0)|
+--------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                      true|
+--------------------------------------------------------------------------------------------------------------------------+

-- kll_sketch_merge_double
SELECT LENGTH(kll_sketch_to_string_double(kll_sketch_merge_double(kll_sketch_agg_double(col), kll_sketch_agg_double(col)))) > 0 FROM VALUES (CAST(1.0 AS DOUBLE)), (CAST(2.0 AS DOUBLE)), (CAST(3.0 AS DOUBLE)), (CAST(4.0 AS DOUBLE)), (CAST(5.0 AS DOUBLE)) tab(col);
+--------------------------------------------------------------------------------------------------------------------------+
|(length(kll_sketch_to_string_double(kll_sketch_merge_double(kll_sketch_agg_double(col), kll_sketch_agg_double(col)))) > 0)|
+--------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                      true|
+--------------------------------------------------------------------------------------------------------------------------+

-- kll_sketch_merge_float
SELECT LENGTH(kll_sketch_to_string_float(kll_sketch_merge_float(kll_sketch_agg_float(col), kll_sketch_agg_float(col)))) > 0 FROM VALUES (CAST(1.0 AS FLOAT)), (CAST(2.0 AS FLOAT)), (CAST(3.0 AS FLOAT)), (CAST(4.0 AS FLOAT)), (CAST(5.0 AS FLOAT)) tab(col);
+----------------------------------------------------------------------------------------------------------------------+
|(length(kll_sketch_to_string_float(kll_sketch_merge_float(kll_sketch_agg_float(col), kll_sketch_agg_float(col)))) > 0)|
+----------------------------------------------------------------------------------------------------------------------+
|                                                                                                                  true|
+----------------------------------------------------------------------------------------------------------------------+

-- kll_sketch_to_string_bigint
SELECT LENGTH(kll_sketch_to_string_bigint(kll_sketch_agg_bigint(col))) > 0 FROM VALUES (1), (2), (3), (4), (5) tab(col);
+---------------------------------------------------------------------+
|(length(kll_sketch_to_string_bigint(kll_sketch_agg_bigint(col))) > 0)|
+---------------------------------------------------------------------+
|                                                                 true|
+---------------------------------------------------------------------+

-- kll_sketch_to_string_double
SELECT LENGTH(kll_sketch_to_string_double(kll_sketch_agg_double(col))) > 0 FROM VALUES (CAST(1.0 AS DOUBLE)), (CAST(2.0 AS DOUBLE)), (CAST(3.0 AS DOUBLE)), (CAST(4.0 AS DOUBLE)), (CAST(5.0 AS DOUBLE)) tab(col);
+---------------------------------------------------------------------+
|(length(kll_sketch_to_string_double(kll_sketch_agg_double(col))) > 0)|
+---------------------------------------------------------------------+
|                                                                 true|
+---------------------------------------------------------------------+

-- kll_sketch_to_string_float
SELECT LENGTH(kll_sketch_to_string_float(kll_sketch_agg_float(col))) > 0 FROM VALUES (CAST(1.0 AS FLOAT)), (CAST(2.0 AS FLOAT)), (CAST(3.0 AS FLOAT)), (CAST(4.0 AS FLOAT)), (CAST(5.0 AS FLOAT)) tab(col);
+-------------------------------------------------------------------+
|(length(kll_sketch_to_string_float(kll_sketch_agg_float(col))) > 0)|
+-------------------------------------------------------------------+
|                                                               true|
+-------------------------------------------------------------------+

-- theta_difference
SELECT theta_sketch_estimate(theta_difference(theta_sketch_agg(col1), theta_sketch_agg(col2))) FROM VALUES (5, 4), (1, 4), (2, 5), (2, 5), (3, 1) tab(col1, col2);
+-----------------------------------------------------------------------------------------------+
|theta_sketch_estimate(theta_difference(theta_sketch_agg(col1, 12), theta_sketch_agg(col2, 12)))|
+-----------------------------------------------------------------------------------------------+
|                                                                                              2|
+-----------------------------------------------------------------------------------------------+

-- theta_intersection
SELECT theta_sketch_estimate(theta_intersection(theta_sketch_agg(col1), theta_sketch_agg(col2))) FROM VALUES (5, 4), (1, 4), (2, 5), (2, 5), (3, 1) tab(col1, col2);
+-------------------------------------------------------------------------------------------------+
|theta_sketch_estimate(theta_intersection(theta_sketch_agg(col1, 12), theta_sketch_agg(col2, 12)))|
+-------------------------------------------------------------------------------------------------+
|                                                                                                2|
+-------------------------------------------------------------------------------------------------+

-- theta_sketch_estimate
SELECT theta_sketch_estimate(theta_sketch_agg(col)) FROM VALUES (1), (1), (2), (2), (3) tab(col);
+------------------------------------------------+
|theta_sketch_estimate(theta_sketch_agg(col, 12))|
+------------------------------------------------+
|                                               3|
+------------------------------------------------+

-- theta_union
SELECT theta_sketch_estimate(theta_union(theta_sketch_agg(col1), theta_sketch_agg(col2))) FROM VALUES (1, 4), (1, 4), (2, 5), (2, 5), (3, 6) tab(col1, col2);
+----------------------------------------------------------------------------------------------+
|theta_sketch_estimate(theta_union(theta_sketch_agg(col1, 12), theta_sketch_agg(col2, 12), 12))|
+----------------------------------------------------------------------------------------------+
|                                                                                             6|
+----------------------------------------------------------------------------------------------+

-- tuple_difference_double
SELECT tuple_sketch_estimate_double(tuple_difference_double(tuple_sketch_agg_double(col1, val1), tuple_sketch_agg_double(col2, val2))) FROM VALUES (5, 5.0D, 4, 4.0D), (1, 1.0D, 4, 4.0D), (2, 2.0D, 5, 5.0D), (3, 3.0D, 1, 1.0D) tab(col1, val1, col2, val2);
+-------------------------------------------------------------------------------------------------------------------------------------------------+
|tuple_sketch_estimate_double(tuple_difference_double(tuple_sketch_agg_double(col1, val1, 12, sum), tuple_sketch_agg_double(col2, val2, 12, sum)))|
+-------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                              2.0|
+-------------------------------------------------------------------------------------------------------------------------------------------------+

-- tuple_difference_integer
SELECT tuple_sketch_estimate_integer(tuple_difference_integer(tuple_sketch_agg_integer(col1, val1), tuple_sketch_agg_integer(col2, val2))) FROM VALUES (5, 5, 4, 4), (1, 1, 4, 4), (2, 2, 5, 5), (3, 3, 1, 1) tab(col1, val1, col2, val2);
+-----------------------------------------------------------------------------------------------------------------------------------------------------+
|tuple_sketch_estimate_integer(tuple_difference_integer(tuple_sketch_agg_integer(col1, val1, 12, sum), tuple_sketch_agg_integer(col2, val2, 12, sum)))|
+-----------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                  2.0|
+-----------------------------------------------------------------------------------------------------------------------------------------------------+

-- tuple_intersection_double
SELECT tuple_sketch_estimate_double(tuple_intersection_double(tuple_sketch_agg_double(col1, val1), tuple_sketch_agg_double(col2, val2))) FROM VALUES (1, 1.0D, 1, 4.0D), (2, 2.0D, 2, 5.0D), (3, 3.0D, 4, 6.0D) tab(col1, val1, col2, val2);
+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|tuple_sketch_estimate_double(tuple_intersection_double(tuple_sketch_agg_double(col1, val1, 12, sum), tuple_sketch_agg_double(col2, val2, 12, sum), sum))|
+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                     2.0|
+--------------------------------------------------------------------------------------------------------------------------------------------------------+

-- tuple_intersection_integer
SELECT tuple_sketch_estimate_integer(tuple_intersection_integer(tuple_sketch_agg_integer(col1, val1), tuple_sketch_agg_integer(col2, val2))) FROM VALUES (1, 1, 1, 4), (2, 2, 2, 5), (3, 3, 4, 6) tab(col1, val1, col2, val2);
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
|tuple_sketch_estimate_integer(tuple_intersection_integer(tuple_sketch_agg_integer(col1, val1, 12, sum), tuple_sketch_agg_integer(col2, val2, 12, sum), sum))|
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                         2.0|
+------------------------------------------------------------------------------------------------------------------------------------------------------------+

-- tuple_sketch_estimate_double
SELECT tuple_sketch_estimate_double(tuple_sketch_agg_double(key, summary)) FROM VALUES (1, 1.0D), (1, 2.0D), (2, 3.0D) tab(key, summary);
+----------------------------------------------------------------------------+
|tuple_sketch_estimate_double(tuple_sketch_agg_double(key, summary, 12, sum))|
+----------------------------------------------------------------------------+
|                                                                         2.0|
+----------------------------------------------------------------------------+

-- tuple_sketch_estimate_integer
SELECT tuple_sketch_estimate_integer(tuple_sketch_agg_integer(key, summary)) FROM VALUES (1, 1), (1, 2), (2, 3) tab(key, summary);
+------------------------------------------------------------------------------+
|tuple_sketch_estimate_integer(tuple_sketch_agg_integer(key, summary, 12, sum))|
+------------------------------------------------------------------------------+
|                                                                           2.0|
+------------------------------------------------------------------------------+

-- tuple_sketch_summary_double
SELECT tuple_sketch_summary_double(tuple_sketch_agg_double(key, summary)) FROM VALUES (1, 1.0D), (1, 2.0D), (2, 3.0D) tab(key, summary);
+--------------------------------------------------------------------------------+
|tuple_sketch_summary_double(tuple_sketch_agg_double(key, summary, 12, sum), sum)|
+--------------------------------------------------------------------------------+
|                                                                             6.0|
+--------------------------------------------------------------------------------+

-- tuple_sketch_summary_integer
SELECT tuple_sketch_summary_integer(tuple_sketch_agg_integer(key, summary)) FROM VALUES (1, 1), (1, 2), (2, 3) tab(key, summary);
+----------------------------------------------------------------------------------+
|tuple_sketch_summary_integer(tuple_sketch_agg_integer(key, summary, 12, sum), sum)|
+----------------------------------------------------------------------------------+
|                                                                                 6|
+----------------------------------------------------------------------------------+

-- tuple_sketch_theta_double
SELECT tuple_sketch_theta_double(tuple_sketch_agg_double(key, summary)) FROM VALUES (1, 1.0D), (2, 2.0D), (3, 3.0D) tab(key, summary);
+-------------------------------------------------------------------------+
|tuple_sketch_theta_double(tuple_sketch_agg_double(key, summary, 12, sum))|
+-------------------------------------------------------------------------+
|                                                                      1.0|
+-------------------------------------------------------------------------+

-- tuple_sketch_theta_integer
SELECT tuple_sketch_theta_integer(tuple_sketch_agg_integer(key, summary)) FROM VALUES (1, 1), (2, 2), (3, 3) tab(key, summary);
+---------------------------------------------------------------------------+
|tuple_sketch_theta_integer(tuple_sketch_agg_integer(key, summary, 12, sum))|
+---------------------------------------------------------------------------+
|                                                                        1.0|
+---------------------------------------------------------------------------+

-- tuple_union_double
SELECT tuple_sketch_estimate_double(tuple_union_double(tuple_sketch_agg_double(col1, val1), tuple_sketch_agg_double(col2, val2))) FROM VALUES (1, 1.0D, 4, 4.0D), (2, 2.0D, 5, 5.0D), (3, 3.0D, 6, 6.0D) tab(col1, val1, col2, val2);
+-----------------------------------------------------------------------------------------------------------------------------------------------------+
|tuple_sketch_estimate_double(tuple_union_double(tuple_sketch_agg_double(col1, val1, 12, sum), tuple_sketch_agg_double(col2, val2, 12, sum), 12, sum))|
+-----------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                  6.0|
+-----------------------------------------------------------------------------------------------------------------------------------------------------+

-- tuple_union_integer
SELECT tuple_sketch_estimate_integer(tuple_union_integer(tuple_sketch_agg_integer(col1, val1), tuple_sketch_agg_integer(col2, val2))) FROM VALUES (1, 1, 4, 4), (2, 2, 5, 5), (3, 3, 6, 6) tab(col1, val1, col2, val2);
+---------------------------------------------------------------------------------------------------------------------------------------------------------+
|tuple_sketch_estimate_integer(tuple_union_integer(tuple_sketch_agg_integer(col1, val1, 12, sum), tuple_sketch_agg_integer(col2, val2, 12, sum), 12, sum))|
+---------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                      6.0|
+---------------------------------------------------------------------------------------------------------------------------------------------------------+