I wanted to do something like:
PCollection<String> a = whatever;
PCollection<KV<String, User>> b = a.apply(
MapElements.into(TypeDescriptor.of(KV<String, User>.class))
.via(s -> KV.of(s, new User(s))));
Where User is a custom datatype with Arvo coder and a constructor that takes a string into account.
However, I get the following error:
Cannot select from parameterized type
I tried to change it to TypeDescriptor.of(KV.class)
instead, but then I get:
Incompatible types; Required PCollection> but 'apply' was inferred to OutputT: no instance(s) of type variable(s) exists so that PCollection conforms to PCollection>
So how am I suppose to use KV
with MapElements
?
I know that what I want to do is doable using ParDo
where I could explicitly specify how to do Type Erasure by declearing new DoFn<String, KV<String, User>>
but ParDo
does not support lambda function. As we are using Java 8, this seems less elegant....