简体   繁体   English

pubsub <-> 使用 protobuf 的 bigquery:bool 正在转换为 null 或 true,而不是 false 或 true

[英]pubsub <-> bigquery with protobuf: bool is getting converted to null or true, not false or true

I have a protobuf pubsub schema being published to bigquery (directly, no dataflow).我有一个 protobuf pubsub 模式被发布到 bigquery(直接,没有数据流)。

in the protobuf, i have a field like:在 protobuf 中,我有一个像这样的字段:

bool foo = 1;

In the bigquery schema this becomes:在 bigquery 模式中,这变为:

  "name": "foo",
  "type": "BOOLEAN",
  "mode": "NULLABLE"
 },

From my python code, I call publish on the topic w/ a dict (encoded to bytes) that has:从我的 python 代码中,我调用带有字典(编码为字节)的主题发布,它具有:

foo: false

this becomes foo: null in the output bigquery table.这变成了foo: null在 output bigquery 表中。

if I make if如果我让

foo: true

it becomes foo: true in the bigquery table.它在 bigquery 表中变为foo: true

this is happening for all of my bool.这发生在我所有的布尔人身上。 eg false becomes null, true remains true.例如 false 变成 null,true 仍然是 true。

Suggestion on where to look?关于在哪里看的建议?

This is a known bug with proto3 support that is being actively worked on.这是一个已知的 proto3 支持错误,目前正在积极处理。 You can track progress in the public issue tracker .您可以在公共问题跟踪器中跟踪进度。 For now, the workaround is to use proto2 instead of proto3.目前,解决方法是使用 proto2 而不是 proto3。

TheJSON Mapping section from the Protocol Buffer documentation says: Protocol Buffer 文档中的JSON 映射部分说:

. . . . . . If a field has the default value in the protocol buffer, it will be omitted in the JSON-encoded data by default to save space.如果某个字段在 protocol buffer 中有默认值,那么在 JSON 编码的数据中会默认省略它以节省空间。

As false is the default value for protocol Buffer's bools , the above seems to suggest that foo: false by default became foo: null to save space.由于false是 protocol Buffer 的bools的默认值,上面似乎暗示foo: false默认变成foo: null以节省空间。

I reckon this is a bug because float value 0.0 is also being converted to null in BigQuery .我认为这是一个错误,因为浮点值 0.0 在 BigQuery 中也被转换为 null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM