gpt4 book ai didi

google-bigquery - 通过 Google Cloud Dataflow 将 PubSub 消息插入 BigQuery

转载 作者:行者123 更新时间:2023-12-04 11:03:55 26 4
gpt4 key购买 nike

我想使用 Google Cloud Dataflow 将来自主题的 PubSub 消息数据插入到 BigQuery 表中。
一切都很好,但在 BigQuery 表中,我可以看到不可读的字符串,例如“ㄧㄧㄆ”。
这是我的管道:

p.apply(PubsubIO.Read.named("ReadFromPubsub").topic("projects/project-name/topics/topic-name"))
.apply(ParDo.named("Transformation").of(new StringToRowConverter()))
.apply(BigQueryIO.Write.named("Write into BigQuery").to("project-name:dataset-name.table")
.withSchema(schema)
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED))

我的简单 StringToRowConverter 函数是:
class StringToRowConverter extends DoFn<String, TableRow> {
private static final long serialVersionUID = 0;

@Override
public void processElement(ProcessContext c) {
for (String word : c.element().split(",")) {
if (!word.isEmpty()) {
System.out.println(word);
c.output(new TableRow().set("data", word));
}
}
}
}

这是我通过 POST 请求发送的消息:
POST https://pubsub.googleapis.com/v1/projects/project-name/topics/topic-name:publish
{
"messages": [
{
"attributes":{
"key": "tablet, smartphone, desktop",
"value": "eng"
},
"data": "34gf5ert"
}
]
}

我错过了什么?
谢谢!

最佳答案

根据 https://cloud.google.com/pubsub/reference/rest/v1/PubsubMessage ,pubsub 消息的 JSON 有效负载是 base64 编码的。默认情况下,Dataflow 中的 PubsubIO 使用字符串 UTF8 编码器。您提供的示例字符串“34gf5ert”,当 base64 解码然后解释为 UTF-8 字符串时,准确地给出了“���”。

关于google-bigquery - 通过 Google Cloud Dataflow 将 PubSub 消息插入 BigQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32632602/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com