我正在尝试使用 Apache Beam Pardo 访问 Avro Generic Record 中的嵌套字段。
我可以进入第一层,但我不知道如何访问更进一步的字段。
如果您考虑这样的
Generic Record
值:
{
"eventTargetType": "GROUP",
"id": "1234",
"group":
{
"details":
{
"triggers":
[],
"attributes":
[]
},
"groupRole":
{
"algorithmResults":
[]
},
"activeTests":
[]
}
}
我可以通过这样做进入小组级别:
@ProcessElement
fun processElement(input: ProcessContext, output: OutputReceiver<GenericRecord>) {
input.element().getAsGenericRecord("event").get("group")
}
这返回的值是(org.apache.avro.generic.GenericData$Record)的数据类型:
{
"event": "RENDER",
"details":
{
"owner": null,
"type": null,
"name": null,
"attributes":[],
},
"locationLabel": null,
"position": null
}
现在我想获取
attributes
内部的字段details
。我不能再做一次get()
,因为它不允许。关于如何解决这个问题有什么想法吗?
不太熟悉 Pardo,但我很确定你必须手动将返回类型转换为 Map 或 GenericRecord
((Map)((Map) input.element().getAsGenericRecord("event").get("group")).get("details")).get("owner")