Reputation: 2431
I want to pass the Query dynamically while running the Dataflow job. I am using SQLTransform which works fine when I pass Query within code.
My use case requires passing the Query at Runtime, is it possible with SqlTransform
in Apache Beam?
This works if I hard-code it in code.
String PQuery = "SELECT col1, max(col2) as max_watermark FROM PCOLLECTION GROUP BY col1";
PCollection<Row> rows1 = rows.apply(SqlTransform.query(PQuery));
But with valueProvider
input, it gives compile time error.
PCollection<Row> rows1 = rows.apply(SqlTransform.query(options.getQuery()))
Error
The method query(String) in the type SqlTransform is not applicable for the arguments (ValueProvider<String>)
Upvotes: 1
Views: 214
Reputation: 5104
You should use FlexTemplates which allow dynamic graph construction (such as SqlTransform) uses based on template parameters.
Upvotes: 1
Reputation: 6572
To solve your issue, you need to get the value inside the ValueProvider :
PCollection<Row> rows1 = rows.apply(SqlTransform.query(options.getQuery().get()))
The query
method takes a String
as parameter, that's why you need to get the String
value of the ValueProvider
option.
Upvotes: 1