我试图根据TIMESTAMP列对表进行分区。我运行了以下查询
CREATE OR REPLACE TABLE `stackoverflow.questions_2018_partitioned` PARTITION BY DATE(creation_date) AS SELECT * FROM `bigquery-public-data.stackoverflow.posts_questions` WHERE creation_date BETWEEN '2018-01-01' AND '2018-07-01';
但是分区表是空的。我从这里复制了这个查询。你能帮我找出我的错误吗?
也许您的环境中默认的分区过期时间是60 days
。过期可以通过OPTION (partition_expiration_days = NULL)
设置为never
。完整的命令是
CREATE OR REPLACE TABLE `stackoverflow.questions_2018_partitioned`
PARTITION BY DATE(creation_date)
OPTIONS (partition_expiration_days = NULL)
AS SELECT * FROM `bigquery-public-data.stackoverflow.posts_questions` WHERE creation_date BETWEEN '2018-01-01' AND '2018-07-01';
您的个人Google Cloud帐户启用了计费功能,可以让您拥有未过期的分区表。但是,这在qwiklab
中不起作用。
我在填充分区表时遇到了同样的问题,之所以能够找到它,是因为默认分区过期设置为60天,删除分区过期有帮助!!!。
因此,删除目标表stackoverflow.questions_2018_partitioned
的分区过期时间。
请为您的SQL语句尝试以下步骤,并更新您的反馈。
1. Create empty partitioned table
CREATE OR REPLACE TABLE `stackoverflow.questions_2018_partitioned`
PARTITION BY DATE(creation_date);
2. Remove partition expiration
ALTER TABLE `stackoverflow.questions_2018_partitioned`
SET OPTIONS (
-- removes partition expiration
partition_expiration_days = NULL);
3. Populate the partitioned table
INSERT INTO `stackoverflow.questions_2018_partitioned`
SELECT * FROM `bigquery-public-data.stackoverflow.posts_questions`
WHERE creation_date BETWEEN '2018-01-01' AND '2018-07-01';