2

我想对我的 Pipe 的所有字段应用一个操作。我在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) }

?

4

3 回答 3

1

在 Scalding Fields API 中,为了映射 from '*to '*,我能想到的最好方法是 Cascading TupleEntrycascading.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-06-25T12:54:21.970 回答
0

'*运算符似乎仅适用于mapTo完整类型注释。

mySource
  .mapTo[(String,String,String),(String,String,String)]('* -> '*) { case (a: String, b: String, c: String) =>
    (a.trim, b.trim, c.trim)
  }
于 2014-04-15T13:06:48.550 回答
0

例如,这适用于 Scalding 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

于 2014-12-03T09:55:29.557 回答