【问题标题】:Error inserting nullable integers into bigquery using python API使用 python API 将可空整数插入 bigquery 时出错
【发布时间】:2018-10-12 08:14:24
【问题描述】:

我正在尝试使用 bigquery python API 将数据插入到 bigquery 表中。更具体的命令:

errors = client.insert_rows(table, rows[i*BATCH_SIZE:])

我的表中的列 gas_used 的数据类型为 INTEGER,并且为 NULLABLE。但是在 gas_used 中插入具有空值的行时出现以下错误。

[{'index': 0, 'errors': [{u'debugInfo': u'', u'reason': u'invalid', u'message': u'无法将值转换为整数(错误value):', u'location': u'gas_used'}]}]

这是我的表的架构:

block_number,transaction_hash,type,trace_address,subtraces,transaction_position,from,to,value_wei,start_gas,input,gas_used,contract_address,output,error

并且,这是引发错误的行:

[('5000001', '0x2cfd7194877466e6adb87222e5876c4babf8bd59de299698fdce7f0a9a232932', 'call', '[]', '0', '11', '0x77cb68e788aa79640b8a613431cdb10d83208d47', '0x4b3ee0ac445d954f8bca68f9538d54e9633890f6', '349950000000000', '0', '0x', '', '', '', 'Out of gas')]

gas_used 列是架构中的倒数第四列。

【问题讨论】:

  • 所以它对应的值是''?对我来说,这看起来不是一个有效的整数......
  • Elliott 是对的,'' 的值是一个空字符串,而不是整数。您必须将其替换为 None 值或特定的 0(零)。
  • @WillianFuks 我想保留整数的Null 特性,因此不能使用特定值0,但使用None 是个好主意。我已经用我找到的解决方案更新了答案。

标签: python python-2.7 google-bigquery


【解决方案1】:

正如William Fuks 提到的,我必须将 Null 整数提到为 None0。我更愿意保留整数的Null 性质,所以更喜欢使用`Nonè

我阅读了this 的帖子,现在正在上传字典列表,同时删除为空的键。

【讨论】:

    猜你喜欢
    • 2012-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 2022-08-11
    • 1970-01-01
    • 2022-10-18
    相关资源
    最近更新 更多