0

I want to concatenate the value of two ValueProvider<String> and assign it to a new ValueProvider<String> How I can achieve it?

ValueProvider<String> A; //if A = Nikhil;
ValueProvider<String> B; //if B = Suthar;
ValueProvider<String> C = A + B; //Then C = Nikhil Suthar;
Nikhil Suthar
  • 2,289
  • 1
  • 6
  • 24

4 Answers4

2

You can combine different providers into one, see this as an example: https://github.com/GoogleCloudPlatform/DataflowTemplates/blob/main/v1/src/main/java/com/google/cloud/teleport/util/DualInputNestedValueProvider.java.

Bruno Volpato
  • 1,382
  • 10
  • 18
0

The ValueProvider provides a get() method (see Apache Beam). So you can do sth like this:

ValueProvider<String> a; 
ValueProvider<String> b; 
String c = a.get() + b.get();
Roland J.
  • 76
  • 4
  • I can not use get() first of all and secondly I don't want data as String Type. – Nikhil Suthar Jan 09 '23 at 13:04
  • @NikhilSuthar - Can you add a bit more detail on why you need the combined value as a ValueProvider? I'm guessing that you need to pass it into a built-in transform that take a ValueProvider, but would be good to specify. Roland's solution would work in runtime contexts such as in the body of a DoFn. – Jeff Klukas Jan 09 '23 at 15:01
0

This question comes up from time to time (see Dataflow. ValueProvider. How to create from several options? for example) but there is not currently support for combining ValueProviders in the Beam Java SDK. NestedValueProvider is available for transforming a runtime parameter, but it doesn't support multiple inputs.

Jeff Klukas
  • 1,259
  • 11
  • 20
  • yes, I had asked this question because of this limitation of NestedValueProvider. I am working on GCP Provided Method do DualNestedProvider, it should work. – Nikhil Suthar Jan 10 '23 at 05:46
0

You could also look into using flex templates instead, which avoid having to worry about ValueProviders at all.

robertwb
  • 4,891
  • 18
  • 21