我正在使用烫伤来做一个简单的字数统计类型的事情。使用部分函数扩展元组时出错。确切的错误消息是:
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")))
答案 0 :(得分:0)
您需要指定类型,因为编译器无法推断出正确的类型:
.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")))