跳到主要内容

PARTITIONS

描述

表函数,生成分区临时表,可以查看某个 TABLE 的分区列表。

语法

PARTITIONS(
"catalog"="<catalog>",
"database"="<database>",
"table"="<table>"
)

必填参数 (Required Parameters)

字段描述
<catalog>指定需要查询的集群 catalog 名。
<database>指定需要查询的集群数据库名。
<table>指定需要查询的集群表名。

返回值

字段名描述
PartitionId分区ID
PartitionName分区名称
VisibleVersion分区版本
VisibleVersionTime分区版本提交时间
State分区状态
PartitionKey分区键
Range分区范围
DistributionKey分布键
Buckets分桶数量
ReplicationNum副本数
StorageMedium存储介质
CooldownTime冷却时间
RemoteStoragePolicy远程存储策略
LastConsistencyCheckTime上次一致性检查时间
DataSize数据大小
IsInMemory是否存在内存
ReplicaAllocation分布策略
IsMutable是否可变
SyncWithBaseTables是否和基表数据同步(针对异步物化视图的分区)
UnsyncTables和哪个基表数据不同步(针对异步物化视图的分区)

示例

查看 internal CATALOG 下 test 的 example_table 的分区列表

select * from partitions("catalog"="internal","database"="test","table"="example_table");
+-------------+---------------+----------------+---------------------+--------+--------------+--------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
| PartitionId | PartitionName | VisibleVersion | VisibleVersionTime | State | PartitionKey | Range | DistributionKey | Buckets | ReplicationNum | StorageMedium | CooldownTime | RemoteStoragePolicy | LastConsistencyCheckTime | DataSize | IsInMemory | ReplicaAllocation | IsMutable | SyncWithBaseTables | UnsyncTables |
+-------------+---------------+----------------+---------------------+--------+--------------+--------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
| 43209 | p1 | 1 | 2025-01-17 12:35:22 | NORMAL | created_at | [types: [DATEV2]; keys: [0000-01-01]; ..types: [DATEV2]; keys: [2023-01-01]; ) | id | 10 | 1 | HDD | 9999-12-31 23:59:59 | | \N | 0.000 | 0 | tag.location.default: 1 | 1 | 1 | \N |
| 43210 | p2 | 1 | 2025-01-17 12:35:22 | NORMAL | created_at | [types: [DATEV2]; keys: [2023-01-01]; ..types: [DATEV2]; keys: [2024-01-01]; ) | id | 10 | 1 | HDD | 9999-12-31 23:59:59 | | \N | 0.000 | 0 | tag.location.default: 1 | 1 | 1 | \N |
| 43211 | p3 | 1 | 2025-01-17 12:35:22 | NORMAL | created_at | [types: [DATEV2]; keys: [2024-01-01]; ..types: [DATEV2]; keys: [2025-01-01]; ) | id | 10 | 1 | HDD | 9999-12-31 23:59:59 | | \N | 0.000 | 0 | tag.location.default: 1 | 1 | 1 | \N |
| 43212 | p4 | 1 | 2025-01-17 12:35:22 | NORMAL | created_at | [types: [DATEV2]; keys: [2025-01-01]; ..types: [DATEV2]; keys: [2026-01-01]; ) | id | 10 | 1 | HDD | 9999-12-31 23:59:59 | | \N | 0.000 | 0 | tag.location.default: 1 | 1 | 1 | \N |
+-------------+---------------+----------------+---------------------+--------+--------------+--------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+

查看 example_table 下的分区名称为 partition1 的分区信息

select * from partitions("catalog"="internal","database"="test","table"="example_table") where PartitionName = "p1";
+-------------+---------------+----------------+---------------------+--------+--------------+--------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
| PartitionId | PartitionName | VisibleVersion | VisibleVersionTime | State | PartitionKey | Range | DistributionKey | Buckets | ReplicationNum | StorageMedium | CooldownTime | RemoteStoragePolicy | LastConsistencyCheckTime | DataSize | IsInMemory | ReplicaAllocation | IsMutable | SyncWithBaseTables | UnsyncTables |
+-------------+---------------+----------------+---------------------+--------+--------------+--------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
| 43209 | p1 | 1 | 2025-01-17 12:35:22 | NORMAL | created_at | [types: [DATEV2]; keys: [0000-01-01]; ..types: [DATEV2]; keys: [2023-01-01]; ) | id | 10 | 1 | HDD | 9999-12-31 23:59:59 | | \N | 0.000 | 0 | tag.location.default: 1 | 1 | 1 | \N |
+-------------+---------------+----------------+---------------------+--------+--------------+--------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+

查看 user_tab 下的分区名称为 partition1 的分区 id

select PartitionId from partitions("catalog"="internal","database"="test","table"="example_table") where PartitionName = "p1";
+-------------+
| PartitionId |
+-------------+
| 43209 |
+-------------+