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

Stephan Ewen commented on FLINK-1255:
-------------------------------------

I talked with [~aljoscha] about that and he mentioned, that the trick is to ask 
Scala to pass the implicit parameter into the utility function, rather that 
have it generated in the utility function.

Try this:
{code}
def groupCount[T : TypeInformation, K : TypeInformation](data: DataSet[T], 
extractKey: (T) => K): DataSet[(K, Long)] = {

    data.groupBy { extractKey }
        .reduceGroup { group => countBy(extractKey, group) }
  }
{code}


> Problems with generic types in Scala API
> ----------------------------------------
>
>                 Key: FLINK-1255
>                 URL: https://issues.apache.org/jira/browse/FLINK-1255
>             Project: Flink
>          Issue Type: Bug
>          Components: Scala API
>    Affects Versions: 0.7.0-incubating
>            Reporter: Sebastian Schelter
>
> the code below produces the following exception:
> {noformat}
> Error:(47, 18) could not find implicit value for evidence parameter of type 
> org.apache.flink.api.common.typeinfo.TypeInformation[K]
>     data.groupBy { extractKey }
> {noformat}
> Fixing K to Long made the code run though
> {noformat}
>   def groupCount[T, K](data: DataSet[T], extractKey: (T) => K): DataSet[(K, 
> Long)] = {
>     data.groupBy { extractKey }
>         .reduceGroup { group => countBy(extractKey, group) }
>   }
>   private[this] def countBy[T, K](extractKey: T => K,
>                                   group: Iterator[T]): (K, Long) = {
>     val key = extractKey(group.next())
>     var count = 1L
>     while (group.hasNext) {
>       group.next()
>       count += 1
>     }
>     key -> count
>   }
> {noformat}



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

Reply via email to