Fungsi HLL_COUNT_EXTRACT menghitung estimasi kardinalitas dari struktur data HLL++ (sketch).
Catatan
Data BINARY yang digunakan oleh fungsi HLL_COUNT_EXTRACT, HLL_COUNT_MERGE, dan HLL_COUNT_MERGE_PARTIAL harus dihasilkan oleh fungsi HLL_COUNT_INIT. Data dari sistem atau metode lain tidak dapat digunakan.
Sintaksis
BIGINT HLL_COUNT_EXTRACT(BINARY <sketch>)Parameter
sketch: Wajib diisi. Nilai BINARY yang merepresentasikan sketch HLL++. Sketch ini harus dihasilkan oleh fungsi HLL_COUNT_INIT.
Nilai kembalian
Mengembalikan estimasi kardinalitas sebagai tipe BIGINT. Jika input sketch bernilai NULL, fungsi ini mengembalikan 0.
Contoh
Kueri jumlah pelanggan unik di setiap negara yang memiliki setidaknya satu invoice.
SELECT
country,
HLL_COUNT_EXTRACT(HLL_sketch) AS distinct_customers_with_open_invoice
FROM
(
SELECT
country,
HLL_COUNT_INIT(customer_id) AS hll_sketch
FROM values
('UA', 'customer_id_1', 'invoice_id_11'),
('BR', 'customer_id_3', 'invoice_id_31'),
('CZ', 'customer_id_2', 'invoice_id_22'),
('CZ', 'customer_id_2', 'invoice_id_23'),
('BR', 'customer_id_3', 'invoice_id_31'),
('UA', 'customer_id_2', 'invoice_id_24')
t(country, customer_id, invoice_id)
GROUP BY country
);Kueri tersebut mengembalikan hasil berikut:
+---------+--------------------------------------+
| country | distinct_customers_with_open_invoice |
+---------+--------------------------------------+
| BR | 1 |
| CZ | 1 |
| UA | 2 |
+---------+--------------------------------------+Fungsi terkait
HLL_COUNT_EXTRACT merupakan salah satu dari beberapa fungsi HyperLogLog++ yang disediakan MaxCompute untuk agregasi aproksimasi. Untuk informasi selengkapnya, lihat HyperLogLog++ functions.