![](/img/trans.png)
[英]How to Insert a partition into BigQuery's fetch time partitioned table in Python by specifying a partition
[英]CSV upload into BigQuery partitioned table using a string field as partition
我需要将 csv 文件上传到 bigquery 表中。 我的问题是如果“datestamp_column”是 STRING 我如何将它用作分区字段?
来自“datestamp_column”的示例值:2022-11-25T12:56:48.926500Z
def upload_to_bq():
client = bigquery.Client())
job_config = bigquery.LoadJobConfig(
schema = client.schema_from_json("schemaa.json"),
skip_leading_rows=1,
time_partitioning=bigquery.TimePartitioning(
type_=bigquery.TimePartitioningType.DAY,
field="datestamp_column",
expiration_ms=7776000000, # 90 days.
),
)
这是失败的,因为它抱怨 datestamp_column 是 STRING,应该是 TIMESTAMP、DATE 或 DATETIME
为了能够在datestamp_column
字段上使用分区,您必须使用TIMESTAMP
、 DATE
或DATETIME
。
您为此字段指定的格式对应于时间戳datestamp_column: 2022-11-25T12:56:48.926500Z
在您的BigQuery
模式中,您必须将datestamp_column
字段的列类型从STRING
更改为TIMESTAMP
。
那么您的摄取应该可以正常工作,因为时间戳格式2022-11-25T12:56:48.926500Z
应该作为TIMESTAMP
在BigQuery
中摄取。
input -> STRING with value 2022-11-25T12:56:48.926500Z
result column in BigQuery is TIMESTAMP
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.