user1089464
user1089464

Reputation: 273

PCollection Sideinput: Feeding a single String as a SideInput to a PCollection

I would like to feed a ParDo on a PCollection with a single String as a SideInput. I tried the following:

PCollection<String> sideView = p.apply(Create.of(sideName).withCoder(StringUtf8Coder.of()));
final PCollectionView<String> filterObject = sideView.apply(View.asSingleton());

But I am running into a compilation error:

no suitable method found for apply(View.asSingleton())

Can someone please tell me what I am missing? I poked around the SDK javadoc a lot but I could not find anything specific to solve this problem which seems so trivial. :(

Upvotes: 1

Views: 1005

Answers (1)

jkff
jkff

Reputation: 17913

Seems like your error would be something like:

The method apply(PTransform<? super PCollection<String>,OutputT>)
in the type PCollection<String> is not applicable for the arguments
(View.AsSingleton<Object>)

This is because type inference in the Java compiler in the presence of generics is not perfect and in this case it is required to add an explicit type parameter:

final PCollectionView<String> filterObject =
    sideView.apply(View.<String>asSingleton());

Indeed, usages of View.asSingleton in the Dataflow SDK examples specify this parameter: see github search.

However, as of writing, our javadocs and public documentation fail to mention this. We'll fix that, thanks for the report!

Upvotes: 2

Related Questions