【发布时间】:2021-04-09 02:17:07
【问题描述】:
在我的 Apache Beam 管道中,我有一个 Row 对象的 PCollection (org.apache.beam.sdk.values.Row)。我想写入 Avro 文件。这是我的代码的简化版本:
Pipeline p = Pipeline.create();
Schema inputSchema = Schema.of(
Schema.Field.of("MyField1", Schema.FieldType.INT32)
);
Row row = Row.withSchema(inputSchema).addValues(1).build();
PCollection<Row> myRow = p.apply(Create.of(row)).setCoder(RowCoder.of(inputSchema));
myRow.apply(
"WriteToAvro",
AvroIO.write(Row.class)
.to("src/tmp/my_files")
.withWindowedWrites()
.withNumShards(10));
p.run();
文件已创建,但看起来像这样(JSON 格式):
"schema" : {
"fieldIndices" : {
"MyField1" : 0
},
"encodingPositions" : {
"MyField1" : 0
},
"fields" : [
{
}
],
"hashCode" : 545134948,
"uuid" : {
},
"options" : {
"options" : {
}
}
}
所以只有模式存在一堆无用的元数据。从 Row 对象写入 Avro 的正确方法是什么,以便我拥有数据而不仅仅是架构。我可以摆脱元数据吗?
【问题讨论】:
-
你用什么来检查文件内容?
-
@OneCricketeer 我正在使用在线查看器; dataformat.net/avro/viewer-and-converter
-
我建议使用 avro-tools jar 文件,因为不清楚该站点实际在做什么
-
刚刚试了一下。获取完全相同的 JSON :/
标签: apache-beam avro apache-beam-io