如果你想在 Scalding 中从一个较小的字段创建一个包含超过 22 个字段的管道,你会受到 Scala 元组的限制,它不能包含超过 22 个项目。
有没有办法使用集合而不是元组?我想象像下面的例子,遗憾的是它不起作用:
input.read.mapTo('line -> aLotOfFields) { line: String =>
(1 to 24).map(_.toString)
}.write(output)
其实你可以。在常见问题解答中 -https://github.com/twitter/scalding/wiki/Frequently-asked-questions#what-if-i-have-more-than-22-fields-in-my-data-set https://github.com/twitter/scalding/wiki/Frequently-asked-questions#what-if-i-have-more-than-22-fields-in-my-data-set
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])看起来很难看,所以如果您找到更好的解决方案,请告诉我。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)