【发布时间】:2016-11-24 05:05:28
【问题描述】:
json_data = '["xxxxxx",65465464.0,2,-1,10.10]'
bigquery 表的架构:
id 字符串可以为空
时间戳 STRING NULLABLE
xid INTEGER NULLABLE
yid INTEGER NULLABLE
幅度 FLOAT NULLABLE
脚本.py:
data = json.loads(json_data)
table.reload()
rows = [data]
errors = table.insert_data(rows)
错误:
errors = table.insert_data(rows)
File "/usr/local/lib/python2.7/dist-
packages/google/cloud/bigquery/table.py", line 749, in insert_data
value = _microseconds_from_datetime(value) * 1e-6
File "/usr/local/lib/python2.7/dist-packages/google/cloud/_helpers.py", line
363, in _microseconds_from_datetime
if not value.tzinfo:
AttributeError: 'float' object has no attribute 'tzinfo'
有人知道这个错误吗?
赞赏!
【问题讨论】:
-
在没有看到您的数据的情况下,很难确定,但看起来 BigQuery 期望某些东西是
datetime.datetime对象,而您正在传递一个浮点数。 -
@fdsa 基本上,我在 UNIX 纪元中有一个时间戳数据,您可以在 json 记录中将其视为浮点类型。当我触发批处理作业以加载此数据的 json 文件时,它可以正常工作,无需将此浮点类型转换为 Datetime。但是对于相同的 json 记录,当我尝试一次使用大查询 API 插入时(如上所示),它会引发上述错误。任何指针都会有所帮助!
标签: python python-3.x google-bigquery