如果要在Scalding中创建一个包含超过22个字段的管道,则受Scala元组的限制,该元组的项目不能超过22个。
有没有办法使用集合而不是元组?我想象下面的例子,遗憾的是它不起作用:
input.read.mapTo('line -> aLotOfFields) { line: String =>
(1 to 24).map(_.toString)
}.write(output)
答案 0 :(得分:4)
val toFields = (1 to 24).map(f => Symbol("field_" + f)).toList
input
.read
.mapTo('line -> toFields) { line: String =>
new Tuple((1 to 24).map(_.toString).map(_.asInstanceOf[AnyRef]): _*)
}
最后一张地图(_。asInstanceOf [AnyRef])看起来很难看,所以如果你找到更好的解决方案,请告诉我。
答案 1 :(得分:3)
将您的元组包装到案例类中。它还将使您的代码比分别使用元组和集合更具可读性和类型安全性。