gpt4 book ai didi

python - Python 脚本中忽略 BigQuery use_avro_logic_types

转载 作者:行者123 更新时间:2023-12-01 01:16:59 27 4
gpt4 key购买 nike

我正在尝试使用 Python 脚本将 AVRO 文件加载到 BigQuery。此过程本身会成功,但我在让 BigQuery 在表创建期间使用 AVRO 的逻辑数据类型时遇到一些问题。

Google here 记录了这些逻辑类型的使用并被添加到 google-cloud-python 库 here .

我不是专业编码员,但我希望下面的代码片段是正确的...但是,use_avro_logic_types 属性似乎被忽略,并且时间戳被加载为 INT 而不是 TIMESTAMP。

...    
with open(full_name, 'rb') as source_file:
var_job_config = google.cloud.bigquery.job.LoadJobConfig()
var_job_config.source_format = 'AVRO'
var_job_config.use_avro_logical_types = True
job = client.load_table_from_file(
source_file, table_ref, job_config=var_job_config)
job.result() # Waits for job to complete
...

AVRO架构如下:

{
"type": "record",
"name": "table_test",
"fields": [{
"name": "id_",
"type": {
"type": "bytes",
"logicalType": "decimal",
"precision": 29,
"scale": 0
}
},
{
"name": "datetime_",
"type": ["null",
{
"type": "long",
"logicalType": "timestamp-micros"
}]
},
{
"name": "integer_",
"type": ["null",
{
"type": "bytes",
"logicalType": "decimal",
"precision": 29,
"scale": 0
}]
},
{
"name": "varchar_",
"type": ["null",
{
"type": "string",
"logicalType": "varchar",
"maxLength": 60
}]
},
{
"name": "capture_time",
"type": {
"type": "long",
"logicalType": "timestamp-millis"
}
},
{
"name": "op_type",
"type": "int"
},
{
"name": "seq_no",
"type": {
"type": "string",
"logicalType": "varchar",
"maxLength": 16
}
}]
}

谁能详细解释一下这个问题吗?谢谢!

最佳答案

显然我的 Python 库没有我想象的那么最新。更新我的 Google Cloud 库解决了这个问题。感谢您的输入shollyman

关于python - Python 脚本中忽略 BigQuery use_avro_logic_types,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54242116/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com