I would like to feed a ParDo on a PCollection with a single String as a SideInput. I tried the following:
我想在PCollection上提供一个ParDo,并使用一个String作为SideInput。我尝试了以下方法:
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. :(
有人可以告诉我我错过了什么吗?我在SDK javadoc中搜索了很多,但我找不到任何具体的东西来解决这个看似微不足道的问题。 :(
1 个解决方案
#1
2
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:
这是因为在存在泛型的情况下Java编译器中的类型推断并不完美,在这种情况下需要添加显式类型参数:
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.
实际上,Dataflow SDK示例中的View.asSingleton的用法指定了此参数:请参阅github搜索。
However, as of writing, our javadocs and public documentation fail to mention this. We'll fix that, thanks for the report!
但是,在写作时,我们的javadoc和公共文档没有提到这一点。我们将解决这个问题,感谢您的报告!
#1
2
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:
这是因为在存在泛型的情况下Java编译器中的类型推断并不完美,在这种情况下需要添加显式类型参数:
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.
实际上,Dataflow SDK示例中的View.asSingleton的用法指定了此参数:请参阅github搜索。
However, as of writing, our javadocs and public documentation fail to mention this. We'll fix that, thanks for the report!
但是,在写作时,我们的javadoc和公共文档没有提到这一点。我们将解决这个问题,感谢您的报告!