I am receiving messages via pub-sub and would like to upload to big-query using the message data for determining what table to upload the data to.
I tried doing the following:
Pipeline pipeline = Pipeline.create(options); String bigQueryTable;
PCollection<String> input = pipeline
.apply(PubsubIO.Read.subscription("projects/my-data-analysis/subscriptions/myDataflowSub"));
input.apply(ParDo.of(new DoFn<String, TableRow>() {
@Override
public void processElement(DoFn<String, TableRow>.ProcessContext c) throws Exception {
JSONObject firstJSONObject = new JSONObject(c.element());
bigQueryTable = firstJSONObject.get("tableName").toString();
TableRow tableRow = convertJsonToTableRow(firstJSONObject);
c.output(tableRow);
}
})).apply(BigQueryIO.Write.to("my-data-analysis:mydataset." + bigQueryTable).withSchema(tableSchema));
is there any way doing this without writing my own DOFN?
If I do need to implement my own doFn how do implement it to upload to big-query?