python - BigQuery 字段的类型已从 STRING 更改为 TIMESTAMP
问题描述
我正在使用 Python API 将数据导入 BigQuery:
import os
from google.cloud import bigquery
from google.cloud.exceptions import BadRequest
import json
from schema import schema
target_project_name = 'project_name'
target_dataset_name = 'dataset_name'
target_table_name = 'table_name'
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = './credentials.json'
dataset_ref = bigquery.dataset.DatasetReference(target_project_name, target_dataset_name)
table_ref = bigquery.table.TableReference(dataset_ref, target_table_name)
job_config = bigquery.LoadJobConfig()
job_config.schema = schema
client = bigquery.Client()
cnt = 0
with open('./data/transformed_v2.json', 'r') as f:
json_list = []
for line in f.readlines():
cnt += 1
if cnt >= 10:
break
json_contents = json.loads(line)
json_list.append(json_contents)
job = client.load_table_from_json(json_list, table_ref)
try:
result = job.result()
except BadRequest as ex:
for err in ex.errors:
print(err)
print(job.errors)
schema
上面代码中提到的包含一个有问题的字段,migration_datetime
定义为bigquery.SchemaField("migration_datetime", "STRING", mode="NULLABLE")
. 该字段包含存储在'%Y-%m-%dT%H:%M:%S' format. The schema in the target table has the
migration_datetime field specified as
STRING 中的值。
会job.result()
引发一个错误,即Field migration_datetime has changed type from STRING to TIMESTAMP
. 为了缓解这种情况,我_string
在列中的值中添加了后缀,migration_datetime
但错误仍然存在。请问您可能是什么原因?
解决方案
推荐阅读
- asp.net - 验证 1000 个外部 URL 的 ASP.Net 问题
- unity3d - LineRenderer 绘制的线即使在应用 Rigidbody2d 后也不会下降
- laravel-8 - Fontawesome 显示为不透明度 = 0
- ruby-on-rails - 伪造跨站请求伪造 (CSRF) 令牌
- swift - 使用 UICollectionViewCompositionalLayout 时如何修改特定组的项目形状
- python-3.x - 我可以使用没有图像字段的 Django truncatewords 过滤器吗?
- c - 逐位移位和旋转实际用例
- ios - 使用 openCV 构建 Bazel,错误:架构 x86_64 的未定义符号
- reinforcement-learning - 监督学习与离线(批量)强化学习
- c# - 使用方法类构造函数 C# 创建表单