如何从Google BigQuery将数据加载到Google Cloud Bigtable

3
我需要将数据填充到Google Cloud Bigtable中,数据来源是Google BigQuery。
作为一种练习,我能够从BigQuery读取数据,并且作为另一个练习,我也能够将数据写入Bigtable
现在我必须将这两个操作合并为一个Google Cloud Dataflow作业。任何示例都将非常有帮助。
2个回答

3
您可以像这些示例中展示的那样使用转换,在其中添加您需要的任何逻辑,例如:
Pipeline p = Pipeline.create(options);
 .apply(BigQueryIO.Read.from("some_table"))
 .apply(ParDo.of(new DoFn<TableRow, Row>() {
   public void processElement(ProcessContext c) {
     Row output = somehowConvertYourDataToARow(c.element());
     c.output(output);
   }
   })
 .apply(BigtableIO.Write.withTableId("some_other_table");

我尝试执行以下代码: <code>CloudBigtableIO.initializeForWrite(p); p.apply(BigQueryIO.Read.fromQuery(getQuery())) .apply(ParDo.of(new DoFn<TableRow, Mutation>() { public void processElement(ProcessContext c) { Mutation output = convertDataToRow(c.element()); c.output(output); } })) .apply(CloudBigtableIO.writeToTable(config)); - Amandeep
但是我得到了以下异常:java.lang.IllegalArgumentException: 无法使用编码器'HBaseMutationCoder'对元素'null'进行编码。 - Amandeep
看起来你的代码中产生了空值,而Bigtable写入器不接受空值。尝试记录变异以查看它或其组件是否为空,并确保你的convertDataToRow函数不能产生空值。 - danielm
当我使用Dataflow作业执行包含记录类型列(展开)的BigQuery查询时,TableRow对象不会返回记录类型列,但其他列会被返回。不确定原因是什么。 - Amandeep
你能把这个问题作为一个单独的问题来问吗?并提供有关您查询和获得结果的额外信息吗? - danielm
请检查以下网址的详细信息:http://stackoverflow.com/questions/39047686/tablerow-object-not-returning-record-type-columns-in-dataflow-job - Amandeep

0

你能给一个使用一些样本数据的例子吗?例如,以someID为行键(rowkey),name,age为值(values)的情况。 例如- 1,John Doe,30 - Regressor

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接