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'
有没有人对这个错误有任何想法?
赞赏!
答案 0 :(得分:0)
@fdsa是对的。上传批处理文件时,它将接受浮点数和字符串,因为您无法在文件中存储日期时间。但是要使用insert_data命令,BQ期望时间戳是datetime.datetime对象,因此在插入之前将UNIX时间戳加载到日期时间:
datetime.datetime.fromtimestamp(your_unix_timestamp)