我希望使用Python API将以下file附加到具有以下定义架构的BigQuery表中:
[
{
"name": "batsman",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "batting_team",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "bowler",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "city",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "date",
"type": "DATE",
"mode": "NULLABLE"
},
{
"name": "delivery",
"type": "FLOAT",
"mode": "NULLABLE"
},
{
"name": "extras",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "extras_type",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "inning",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "match_code",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "non_striker",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "player_out",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "runs",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "team1",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "team2",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "toss_decision",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "toss_winner",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "total",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "venue",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "wicket_fielders",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "wicket_kind",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "win_margin",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "win_type",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "winner",
"type": "STRING",
"mode": "NULLABLE"
}
]
我用于附加到BigQuery的代码如下:
^{pr2}$但是,每当我加载该文件时,我会收到一个错误消息:
BadRequest: 400 Invalid schema update. Field win_margin has changed type from INTEGER to STRING
普通文件看起来像this。在
我应该怎么做才能使win_margin
列保持为INTEGER
并且仍然能够加载包含列的所有空行的文件?在
您需要指定表模式,其中显式指定
win_margin
列的类型。您可以通过设置job_config.schema
字段并将job_config.autodetect
设置为False
来完成。在以下是可用于从文件中读取架构的函数:
如您所见,BigQuery不允许向整数字段添加空值,因此您需要在创建文件或上载期间填充此字段,例如:
win_margin
不是空的put 0或 空相关问题 更多 >
编程相关推荐