循环遍历 PCollection 以创建图形数据结构,然后将其作为 SideInput 传递给管道转换
Loop through a PCollection to make a Graph data structure and then passing it as SideInput to pipeline transform
我有一个用例,我必须将一个大查询 table 读入数据流管道,然后读取该 PCollection 中的每一行以构建图形数据结构。然后将图作为 SideInput
传递给需要此图和另一个大查询 table PCollection 作为参数的更多转换步骤。以下是我现在拥有的:
Pipeline pipeline = Pipeline.create(options);
//Read from big query
PCollection<TableRow> bqTable = pipeline.apply("ReadFooBQTable", BigQueryIO.Read.from("Table"));
//Loop over PCollection create "graph" still need to figure this out
//pass the graph as side input
pCol.apply("Process", ParDo.withSideInputs(graph).of(new BlueKai.ProcessBatch(graph))).apply("Write",
Write.to(new DecoratedFileSink<String>(standardBucket, "csv", TextIO.DEFAULT_TEXT_CODER, null, null, WriterOutputGzipDecoratorFactory.getInstance())).withNumShards(numChunks));
问题将是如何序列化图形以在机器之间传递它。如果您为如何序列化表示图形的元素定义了 Coder
,那么您可以将其用作您描述的辅助输入。
假设可以对图进行编码,那么您只需将其用作单例侧输入。这假定行数可以在一台机器上处理。您可能需要定义一个 CombineFn<TableRow, Graph, Graph>
来计算来自 table 行的图表。假设两个图可以组合(例如,它是结合和交换操作),那么您可以使用组合加 asSingletonView
.
另一种方法是使用 List<TableRow>
作为辅助输入并让每台机器构建图形。
我有一个用例,我必须将一个大查询 table 读入数据流管道,然后读取该 PCollection 中的每一行以构建图形数据结构。然后将图作为 SideInput
传递给需要此图和另一个大查询 table PCollection 作为参数的更多转换步骤。以下是我现在拥有的:
Pipeline pipeline = Pipeline.create(options);
//Read from big query
PCollection<TableRow> bqTable = pipeline.apply("ReadFooBQTable", BigQueryIO.Read.from("Table"));
//Loop over PCollection create "graph" still need to figure this out
//pass the graph as side input
pCol.apply("Process", ParDo.withSideInputs(graph).of(new BlueKai.ProcessBatch(graph))).apply("Write",
Write.to(new DecoratedFileSink<String>(standardBucket, "csv", TextIO.DEFAULT_TEXT_CODER, null, null, WriterOutputGzipDecoratorFactory.getInstance())).withNumShards(numChunks));
问题将是如何序列化图形以在机器之间传递它。如果您为如何序列化表示图形的元素定义了 Coder
,那么您可以将其用作您描述的辅助输入。
假设可以对图进行编码,那么您只需将其用作单例侧输入。这假定行数可以在一台机器上处理。您可能需要定义一个 CombineFn<TableRow, Graph, Graph>
来计算来自 table 行的图表。假设两个图可以组合(例如,它是结合和交换操作),那么您可以使用组合加 asSingletonView
.
另一种方法是使用 List<TableRow>
作为辅助输入并让每台机器构建图形。