メインコンテンツまでスキップ

percentile_union

percentile_union

説明

PERCENTILEデータを集約します。

構文

percentile_union(expr);

パラメーター

expr: サポートされているデータタイプはPERCENTILEです。

返り値

PERCENTILEの値を返します。

例1: マテリアライズドビューでPERCENTILEデータを使用する。

テーブルを作成します。

CREATE TABLE sales_records(
record_id int,
seller_id int,
store_id int,
sale_date date,
sale_amt bigint
) distributed BY hash(record_id)
properties("replication_num" = "3");

テーブルのsale_amt列を基にしたマテリアライズドビューを作成します。

create materialized view mv as
select store_id, percentile_union(percentile_hash(sale_amt))
from sales_records
group by store_id;

例2: PERCENTILEデータのロード。

PERCENTILE列sale_amt_perを含む集計テーブルを作成します。

CREATE TABLE sales_records(
record_id int,
seller_id int,
store_id int,
sale_amt_per percentile percentile_union
) ENGINE=OLAP
AGGREGATE KEY(`record_id`, `seller_id`, `store_id`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`record_id`)
PROPERTIES (
"replication_num" = "3",
"storage_format" = "DEFAULT"
);

sale_amt_perからデータをクエリします。

select percentile_approx_raw(percentile_union(sale_amt_per), 0.99) from sales_records;

PERCENTILEデータを含むデータをsales_recordsテーブルにロードします。

curl --location-trusted -u root
-H "columns: record_id, seller_id, store_id,tmp, sale_amt_per =percentile_hash(tmp)"
-H "column_separator:,"
-T a http://<ip:port>/api/test/sales_records/_stream_load