烫伤:部分功能无法减轻

Scalding: Cannot reduce with partial function

我正在使用烫洗来进行简单的字数统计。使用部分函数扩展元组时出现错误。确切的错误信息是:

Error:(15, 14) missing parameter type for expanded function
The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: (?, ?) => ?
      .reduce{ case ((t1, v1), (t2, v2)) =>
             ^

向元组添加类型也无济于事。我做错了什么?

TypedPipe.from(PackedAvroSource[TrackPlay](args("input")))
  .map({ t => (t.getTrackId.toString, 1) })
  .groupBy(_._1)
  .reduce{ case ((t1, v1), (t2, v2)) =>
      (t1, v1 + v2)
  }
  .values
  .write(TypedTsv[(CharSequence, Int)](args("output")))

您需要指定类型,因为编译器无法推断出正确的类型:

.reduce[(String, Int)] { case ((t1, v1), (t2, v2)) => (t1, v1 + v2) }

类型指定为 [U >: Tuple2[String, Int]],因此编译器推断 Tuple2[Any, Any],因此无法计算预期的结果类型 Tuple2[String, Int]

第 8.5 节中的更多信息:http://www.scala-lang.org/files/archive/nightly/pdfs/ScalaReference.pdf


附带说明一下,整体逻辑的更简单实现是:

TypedPipe.from(PackedAvroSource[TrackPlay](args("input")))
  .map(t => (t.getTrackId.toString, 1))
  .group
  .sum
  .toTypedPipe
  .write(TypedTsv[(CharSequence, Int)](args("output")))