简体   繁体   English

使用 require_partition_filter 列出 BigQuery 分区表中的所有分区

[英]Listing all the partitions from BigQuery partitioned table with require_partition_filter

I am trying to find a way to list the partitions of a table created with require_partition_filter = true however I am not able to find the way yet.我正在尝试找到一种方法来列出使用require_partition_filter = true创建的表的分区,但是我还找不到方法。

This is table creation script这是建表脚本

CREATE TABLE mydataset.partitionedtable_partitiontime
(
x INT64 \
)
PARTITION BY DATE(_PARTITIONTIME)
OPTIONS(
require_partition_filter = true
);

Some test rows一些测试行

INSERT INTO mydataset.partitionedtable_partitiontime (_PARTITIONTIME, x) SELECT TIMESTAMP("2017-05-01"), 10;
INSERT INTO mydataset.partitionedtable_partitiontime (_PARTITIONTIME, x) SELECT TIMESTAMP("2017-04-01"), 20;
INSERT INTO mydataset.partitionedtable_partitiontime (_PARTITIONTIME, x) SELECT TIMESTAMP("2017-03-01"), 30;

As expected, If a try the following query to get the partitions, I am getting an error because I need to user a filter on top of the partitioning column正如预期的那样,如果尝试以下查询来获取分区,我会收到错误消息,因为我需要在分区列的顶部使用过滤器

SELECT _PARTITIONTIME as pt, FORMAT_TIMESTAMP("%Y%m%d", _PARTITIONTIME) as partition_id
FROM `mydataset.partitionedtable_partitiontime`
GROUP BY _PARTITIONTIME
ORDER BY _PARTITIONTIME

Error错误

Cannot query over table 'mydataset.partitionedtable_partitiontime' without a filter over column(s) '_PARTITION_LOAD_TIME', '_PARTITIONDATE', '_PARTITIONTIME' that can be used for partition elimination

any ideas how to list the partitions?任何想法如何列出分区?

EDIT: I know that it is possible to add the filter, but I am looking for a solution like "SHOW PARTITIONS TABLENAME" of Hive to list all the partitions (which are essentially metadata)编辑:我知道可以添加过滤器,但我正在寻找像 Hive 的“SHOW PARTITIONS TABLENAME”这样的解决方案来列出所有分区(本质上是元数据)

Thanks!谢谢!

Here is the way to do it:这是这样做的方法:

SELECT * FROM `mydataset.partitionedtable_partitiontime$__PARTITIONS_SUMMARY__`

The bigquery.jobs.create permission is required.需要bigquery.jobs.create权限。

EDIT: Now is possible to get this information using Standard SQL:编辑:现在可以使用标准 SQL 获取此信息:

SELECT * FROM `myproject.mydataset.INFORMATION_SCHEMA.PARTITIONS`
WHERE table_name = 'partitionedtable'

As mentioned by hlagos , you can get this data by querying the _PARTITIONTIME pseudo column, in case you are using Standard SQL , or the __PARTITIONS_SUMMARY__ meta table for Legacy SQL .正如hlagos所提到的,您可以通过查询_PARTITIONTIME伪列来获取此数据,如果您使用的是Standard SQL__PARTITIONS_SUMMARY__ meta table for Legacy SQL

You can take a look on this GCP documentation that contains detailed information about the usage of this partitioned tables metadata.您可以查看此 GCP 文档,其中包含有关使用此分区表元数据的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 BigQuery 分区表(当天)不分区 - python - BigQuery Partitioned Table (on DAY) it does not partition - python bigquery:从查询结果创建分区表不会分区旧时间戳 - bigquery: create partitioned table from query results does NOT partition old timestamps 将 CSV 个文件上传到分区的 bigquery 表中(根据文件名生成分区) - Upload CSV files into partitioned bigquery table (generate partition from file name) 使用字符串字段作为分区的 CSV 上传到 BigQuery 分区表 - CSV upload into BigQuery partitioned table using a string field as partition 是否可以从 BigQuery 表中删除 Partition filter=Required 设置? - Is it possible to remove the Partition filter=Required setting from BigQuery table? 如何通过指定分区将分区插入到 Python 中的 BigQuery 提取时间分区表中 - How to Insert a partition into BigQuery's fetch time partitioned table in Python by specifying a partition 将查询结果从表写入 BigQuery 中的分区聚簇表 - Write query results from a table to a partitioned - clustered table in BigQuery 从 SQL 查询向 BigQuery 表添加多个分区列 - Adding multiple partitioned columns to BigQuery table from SQL query 选择需要对分区列进行过滤的 Bigquery 表的最新分区 - choose latest partition of a Bigquery table where filter over partition column is required 无法删除分区的 bigquery 表 - Can not delete a partitioned bigquery table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM