[英]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.