在Dataflow中自动检测BigQuery架构?

Max*_*ian 3 google-bigquery google-cloud-dataflow apache-beam

是否可以使用--autodetectDataFlow中的等价物?

即我们可以将数据加载到BQ表而不指定架构,相当于我们如何从CSV加载数据--autodetect

(可能相关的问题)

Mat*_*ens 7

如果您使用协议缓冲区作为PCollections中的对象(应该在Dataflow后端上执行得非常好),您可能可以使用我以前编写的工具.它将在运行时根据对protobuffer描述符的检查将protobuffer的模式解析为BigQuery模式.

我很快将它上传到GitHub,这是WIP,但是你可以使用它或者受到启发,使用Java Reflection编写类似的东西(我可能会在某些时候自己做).

您可以按如下方式使用util:

TableSchema schema = ProtobufUtils.makeTableSchema(ProtobufClass.getDescriptor());
enhanced_events.apply(BigQueryIO.Write.to(tableToWrite).withSchema(schema)
            .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
            .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE));
Run Code Online (Sandbox Code Playgroud)

其中create disposition将使用指定的模式创建表,ProtobufClass是使用Protobuf模式和proto编译器生成的类.