- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含 Strings
的数据流,它看起来像 JSONArrays
。我想解析这些字符串并使用 Apache Beam 写入 BigQuery 表,但在写入重复字符串时出现错误。
以下是我将字符串转换为 TableRow
的方法:
String dataString = "[{\"EMAIL\": [\"zog@yahoo.com\"]}]";
JSONArray jsonArray = new JSONArray(dataString);
TableRow tableRow = new TableRow();
for (int i = 0; i < jsonArray.length(); i++) {
JSONArray emailArray = new JSONArray(jsonArray.getJSONObject(i).get("EMAIL").toString());
tableRow.set("EMAIL", emailArray); //Results in error
}
这是我的 BigQuery 架构的样子:
[
{
"name": "EMAIL",
"type": "STRING",
"mode": "REPEATED"
}
]
我已经设法使用 Python 将类似的重复字符串写入 BigQuery 表,但无法使用 Apache Beam 完成。我想我没有在 TableRow
中保存正确的键值对。我现在得到的错误是:
java.io.IOException: Insert failed: [{"errors":[{"debugInfo":"","location":"email","message":"This field is not a record.","reason":"invalid"}],"index":0}]
我需要有关如何在不创建记录的情况下将类似的重复字符串保存到 BigQuery 的帮助,我将不胜感激任何意见或建议。提前致谢。
最佳答案
看来你要创建
请注意,您的 ValidFrom
字段似乎是 STRING
类型,不是 重复字段,除非它包含在重复字段中层次架构。
在您提供的示例代码中,您正在创建一个 JSONArray
并将其放入 STRING
字段,我认为这会导致问题,因为类型不兼容。如果您想将其保留为普通 STRING
字段,您可以使用下面的解决方案 1。
还要确保您在 BigQuery 中的列名称与代码中的名称相匹配,我看到您同时使用了 ValidFrom
和 EMAIL
(可能是您的错误虽然发布了代码)。
如果您想在 BigQuery 中添加带有concatenated String
字段的行,您可以使用以下方法:
// Initialize your final row
TableRow tableRow = new TableRow();
// Find email addresses
String [] emails = ... // your extraction logic
// Build a concatenated string of emails
String allEmails = String.join(";", emails);
// Add the string field to the row
tableRow.set('EMAILS', allEmails);
如果您想插入多行,您可以创建多个表格行:
// Find email addresses
String [] emails = ... // your extraction logic
// Build a row per email
for(String email: emails) {
// Initialize your final row
TableRow tableRow = new TableRow();
tableRow.set('EMAIL', email);
// TODO: do something with the row (add to list, or ...)
}
如果您想在 BigQuery 中添加带有 REPEATED STRING
字段的一行,您可以使用以下命令:
// Initialize your final row
TableRow tableRow = new TableRow();
// Find email addresses
String [] emails = ... // your extraction logic
// Build the repeated field
List<String> emailCells = new ArrayList<>();
for(String email: emails) {
emailCells.add(email);
}
// Add the repeated field to the row
tableRow.set('EMAILS', emailCells);
如果这不是您的目标,请提供更多详细信息。
关于java - 使用 Apache Beam 将重复的字符串写入 BigQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66495050/
我正在使用 Apache Beam 从 Kafka 读取数据。由于乱序写入 Kafka,我想使用有效负载中的事件时间戳而不是默认的 LogAppendTime。 我看到了一个解决方案 Apache B
我有一个通用输入请求,其中包含需要转换和保存的输入。如果需要转换生成的输出,我会为它实现一个新的处理器(转换器)。 class Request { Input input; Transform
我已经在 Apache Beam 上工作了几天。我想快速迭代我正在工作的应用程序,并确保我正在构建的管道没有错误。在 Spark 中我们可以使用 sc.parallelise当我们应用一些 Actio
我有一个简单的波束管道,它使用带有 tf 变换的通用句子编码器获取一些文本并获得嵌入。与使用 tf 1 制作的演示非常相似。 import tensorflow as tf import apache
使用Apache Beam丰富数据时,对每个数据项都进行一次API调用会不会出错? (我是 Apache Beam 的新手) 最佳答案 不,但您可以批处理 API 调用以获得更好的性能。查看 this
我的任务是为一款应用添加支持,以便通过 Android 上的“NFC”在设备之间传输大型数据文件(数十兆字节)。 我知道 Android 上真正的 NFC 非常慢,但我知道 ICS 支持将批量数据传输
NFC:S-beam 和 Android beam 有什么区别?有人可以解释 Wifi-Direct/Bluetooth 激活和传输数据的确切流程吗? 最佳答案 在 stackexchanged 上解
我正在使用 Beam 管道计算流式数据的电话号码频率。我使用的滑动窗口每 5 分钟重复一次,总周期为 15 分钟,因此正如预期的那样,对于某些输入,当输入落在多个窗口中时,我会得到多个输出。 计算出现
输入的PCollection是http requests,是一个有界数据集。我想在 ParDo 中进行异步 http 调用(Java),解析响应并将结果放入输出 PCollection 中。我的代码如
输入的PCollection是http requests,是一个有界数据集。我想在 ParDo 中进行异步 http 调用(Java),解析响应并将结果放入输出 PCollection 中。我的代码如
在使用 PAssert 为我的光束管道编写单元测试时,管道输出对象很好,但在与以下断言错误进行比较时测试失败: java.lang.AssertionError: Decode pubsub mess
我正在尝试从 here 运行 Wordcount 演示与 Samza Runner。这是我的build.gradle plugins { id 'eclipse' id 'java' id
我正在尝试使用 Beam 和 Flink runner 设置流处理管道。 Flink 是一个本地 session 部署,包含以下 docker-compose 文件: version: "3" ser
在尝试编译我的 Phoenix 项目的发行版时,出现以下错误: $ mix release .... ==> Generated .appup for myapp 0.0.1 -> 0.0.2 ===
我正在尝试使用 Apache beam-dataflow 连接到安装在云实例中的配置单元实例。当我运行它时,出现以下异常。当我使用 Apache Beam 访问此数据库时,就会发生这种情况。我见过很多
我正在使用 zsh,并且我已经安装了 gcloud,以便通过我的 Mac 上的本地终端与 GCP 进行交互。我遇到了这个错误“zsh:找不到匹配项:apache-beam[gcp]”。但是,当我在 G
主要记录两种不同的beam search版本 版本一 使用类似层次遍历的方式进行搜索,用队列进行维护,每次循环对当前层的所有节点进行搜索,这些节点每个分别对应topk个节点作为下一层候选节点,取
我的目标是创建一个每秒调用后端(云托管)服务最多次数的管道......我该如何实现? 背景故事:想象一下后端服务使用单个输入调用并返回单个输出。该服务具有与其关联的配额,允许每秒最大请求数(假设每秒
我想写入一个 gs 文件,但在编译时我不知道文件名。它的名称基于在运行时定义的行为。我该如何继续? 最佳答案 如果你使用 Beam Java,你可以使用 FileIO.writeDynamic()为此
我试图弄清楚如何使用Apache Beam读取大型CSV文件。 “大”是指几千兆字节(因此一次将整个CSV读取到内存中是不切实际的)。 到目前为止,我已经尝试了以下选项: 使用TextIO.read(
我是一名优秀的程序员,十分优秀!