【发布时间】:2020-03-24 05:19:16
【问题描述】:
我有一个将 avro 文件上传到 bigquery 的管道,配置的架构似乎没问题,但 BigQuery 将其理解为整数值而不是日期字段。在这种情况下我该怎么办?
Schema 的 avro - 日期字段:
{
"name": "date",
"type": {
"type": "long",
"logicalType": "timestamp-millis"
},
"doc": "the date where the transaction happend"
}
大查询表:
我尝试使用下面的代码,但它只是忽略了它。你知道原因吗?
import gcloud
from gcloud import storage
from google.cloud import bigquery
def insert_bigquery_avro(target_uri, dataset_id, table_id):
bigquery_client = bigquery.Client()
dataset_ref = bigquery_client.dataset(dataset_id)
job_config = bigquery.LoadJobConfig()
job_config.autodetect = True
job_config.source_format = bigquery.SourceFormat.AVRO
job_config.use_avro_logical_types = True
time_partitioning = bigquery.table.TimePartitioning()
# time_partitioning = bigquery.table.TimePartitioning(type_=bigquery.TimePartitioningType.DAY, field="date")
job_config.time_partitioning = time_partitioning
uri = target_uri
load_job = bigquery_client.load_table_from_uri(
uri,
dataset_ref.table(table_id),
job_config=job_config
)
print('Starting job {}'.format(load_job.job_id))
load_job.result()
print('Job finished.')
【问题讨论】:
标签: python google-bigquery schema avro