BigQuery:如何通过 DML 创建整数分区 table?

BigQuery: How to create integer partitioned table via DML?

我试图了解整数分区表的工作原理。但是到目前为止,我无法创建一个。

这个查询有什么问题:

 #standardSQL
 CREATE or Replace TABLE temp.test_int_partition

 PARTITION BY RANGE_BUCKET(id, GENERATE_ARRAY(0,100))
 OPTIONS(
   description="test int partition"
 ) 
as 

WITH data as (
SELECT 12 as id, 'Alex' as name
UNION ALL 
SELECT 23 as id, 'Chimp' as name
)

SELECT *
from data

我收到此错误:

Error: PARTITION BY expression must be DATE(<timestamp_column>), a DATE column, or RANGE_BUCKET(<int64_column>, GENERATE_ARRAY(<int64_value>, <int64_value>, <int64_value>))

问题是,尽管 GENERATE_ARRAY 被记录为 GENERATE_ARRAY(start_expression, end_expression [, step_expression]),这意味着 step_expression 是可选的,因为 RANGE_BUCKET 强制性

因此以下内容将起作用:

 #standardSQL
 CREATE or Replace TABLE temp.test_int_partition

 PARTITION BY RANGE_BUCKET(id, GENERATE_ARRAY(0,100,1))
 OPTIONS(
   description="test int partition"
 ) 
as 

WITH data as (
SELECT 12 as id, 'Alex' as name
UNION ALL 
SELECT 23 as id, 'Chimp' as name
)

SELECT *
from data