【发布时间】:2022-12-17 23:10:57
【问题描述】:
我正在使用云函数(python 3.10 运行时)在 protobuf 模式中接收和编码以下 JSON 有效负载,并发布到允许将数据处理到 BigQuery 的 PubSub 主题。
有效负载
{
"data": [
{
"user_id": "XY25999A",
"firstname": "John",
"lastname": "Doe",
"fee": 20.00,
"is_active": false
},
{
"user_id": "XY26999B",
"firstname": "Sam",
"lastname": "Foo",
"fee": 0.00,
"is_active": true
},
{
"user_id": "XY27999C",
"firstname": "Kay",
"lastname": "Bent",
"fee": 20.00,
"is_active": true
}
]
}
JSON模式
{
"type":"object",
"properties":{
"user_id":{
"type":"string"
},
"firstname":{
"type":"string"
},
"lastname":{
"type":"string"
},
"fee":{
"type":"number"
},
"is_active":{
"type":"boolean"
}
}
}
protobuf 模式
message ProtoSchema {
string user_id = 1;
string firstname = 2;
string lastname = 3;
double fee = 4;
bool is_active = 5;
}
当数据处理到 BigQuery 时,活跃为了约翰和费用为了山姆都分别显示null而不是false和0.0。
| user_id | firstname | lastname | fee | is_active |
|---|---|---|---|---|
| XY25999A | John | Doe | 20.00 | null |
| XY26999B | Sam | Foo | null | true |
| XY27999C | Kay | Bent | 20.00 | true |
这种行为有原因或解释吗?
【问题讨论】:
标签: python types google-bigquery protocol-buffers jsonschema