我想对我的管道的所有字段应用一个操作。我在https://github.com/twitter/scalding/wiki/Fields-based-API-Reference上看到“您可以使用'* (这里和其他地方)来表示所有字段。”但不知何故,我没有成功地使它发挥作用。有人能给我举个例子吗?
一开始我有一件事
mySource.map('field1 -> 'field1){ number: String => number.trim }我现在想把它应用到所有的领域
mySource.map('* -> '*){ numbers: List[String] => numbers.map(_.trim) }发布于 2014-06-25 12:54:21
在烫伤字段API中,为了从'*映射到'*,我能想到的最佳方法是级联TupleEntry,cascading.tuple.TupleEntry。
import com.twitter.scalding._
import cascading.tuple.TupleEntry
// Notice I do not specify the scheme when reading.
// I only know first column is 'user_id', the rest is some value and I want
// to double the values. You can use 'map' or 'mapTo'.
Tsv(args("input"))
.read
.map('* -> '*) {
fields: TupleEntry =>
val sz: Int = fields.size()
for (i <- from 1 until sz) fields.setDouble(i, fields.getDouble(i) * 2.0)
fields.getTuple()
}
.write(Tsv(args("output")))发布于 2014-04-15 13:06:48
'*操作符似乎只适用于mapTo和全类型注释。
mySource
.mapTo[(String,String,String),(String,String,String)]('* -> '*) { case (a: String, b: String, c: String) =>
(a.trim, b.trim, c.trim)
}发布于 2014-12-03 09:55:29
例如,这适用于烫伤0.11.0 (当前的答案都不起作用):
mySource
.mapTo('* -> '*) {
entry: TupleEntry =>
for (i <- 0 until entry.size) {
if (entry.getObject(i) == null) entry.setRaw(i, "\\N")
}
entry.getTuple
}所以本质上是mapTo('* -> '*) -> entry.getTuple。
https://stackoverflow.com/questions/22359955
复制相似问题