[ 
https://issues.apache.org/jira/browse/BEAM-247?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15267496#comment-15267496
 ] 

Pei He commented on BEAM-247:
-----------------------------

The bug report comes from the following code snippets, and the combine fn is 
not used in a correct way:
 """
when I do this:
PCollection<KV<String, Double>> salesRecords = p.apply(Create.of(KV.of("a", 
1.0), KV.of("b", 2.0)));
 PCollection<KV<String, Double>> totalSalesPerPerson =
     salesRecords.apply(Combine.<String, Double>perKey(
         new Sum.SumDoubleFn()));

I get this error (and only this error):
[ERROR] 
/Users/stephen/dev/dominion/AnalyzeGames/src/main/java/com/siskybiz/dominion/StarterPipeline.java:[138,10]
 incompatible types: com.google.cloud.dataflow.sdk.transforms.Sum.SumDoubleFn 
cannot be converted to 
com.google.cloud.dataflow.sdk.transforms.SerializableFunction<java.lang.Iterable<java.lang.Double>,java.lang.Double>
"""

The correct usage is:
     salesRecords.apply(Combine.<String, Double, Double>perKey(new 
Sum.SumDoubleFn()));
or
     salesRecords.apply(Combine.perKey(new 
Sum.SumDoubleFn().<String>asKeyedFn()));

> CombineFn's only definable/usable inside sdk.transforms package
> ---------------------------------------------------------------
>
>                 Key: BEAM-247
>                 URL: https://issues.apache.org/jira/browse/BEAM-247
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-java-core
>            Reporter: Ben Chambers
>            Assignee: Pei He
>            Priority: Critical
>
> {code:java}
> public abstract static class CombineFn<InputT, AccumT, OutputT>
>   extends AbstractGlobalCombineFn<InputT, AccumT, OutputT> { /* ... */ }
> abstract static class AbstractGlobalCombineFn<InputT, AccumT, OutputT>
>   implements GlobalCombineFn<InputT, AccumT, OutputT>, Serializable { /* ... 
> */ }
> {code}
> Since {{AbstractGlobalCombineFn}} is package protected (and therefore not 
> visible outside of the {{transform}} package, it is not possible to cast any 
> class that extends {{CombineFn}} to a {{GlobalCombineFn}} outside of this 
> package.
> This prevents applying existing {{CombineFns}} directly (such as 
> {{Combine.perKey(new Sum.SumIntegersFn())}}, as used in our documentation) 
> and also means that a user cannot define their own {{CombineFn}} unless they 
> put them in the {{transform}} package.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to