跳到主要内容
版本: 最新版本-3.5

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 的 Aggregate 表。

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