对于timestamp数据类型,bigquery insert失败

时间:2016-11-24 05:05:28

标签: python python-3.x google-bigquery

json_data ='[“xxxxxx”,65465464.0,2,-1,10.10]'

bigquery表的架构:

id STRING NULLABLE
时间戳STRING无效
xid INTEGER NULLABLE
yid INTEGER NULLABLE
幅度FLOAT NULLABLE

script.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'

有没有人对这个错误有任何想法?

赞赏!

1 个答案:

答案 0 :(得分:0)

@fdsa是对的。上传批处理文件时,它将接受浮点数和字符串,因为您无法在文件中存储日期时间。但是要使用insert_data命令,BQ期望时间戳是datetime.datetime对象,因此在插入之前将UNIX时间戳加载到日期时间:

 datetime.datetime.fromtimestamp(your_unix_timestamp)