合法代码不能在Scalding中编译

时间:2014-07-17 16:05:51

标签: scala hadoop scalding

我正在Scalding编写MapReduce作业,并且难以编译看起来完全合法的代码。

val persistenceBins = List[Int](1000 * 60 * 60, 2 * 1000 * 60 * 60, 4 * 1000 * 60 * 60)
val persistenceValues = persistenceBins.map(bin: Int => (bin, getPersistenceValues(connections, bin)) )

连接是RichPipe。 getPersistenceValues与上面的代码在同一个类中定义,如:

def getPersistenceValues(connections: RichPipe, binSize: Int): RichPipe = { ... }

我不断收到这类错误:

Error:(45, 87) ')' expected but '(' found.
val persistenceValues = persistenceBins.map(bin: Int => (bin, getPersistenceValues(connections, bin)) )
                                                                                  ^
Error:(45, 107) ';' expected but ')' found.
val persistenceValues = persistenceBins.map(bin: Int => (bin, getPersistenceValues(connections, bin)) )
                                                                                                      ^

我无法弄清楚发生了什么。这些错误对我来说毫无意义。我做错了什么?

1 个答案:

答案 0 :(得分:4)

在您的情况下,您不能跳过括号。此代码应该可以帮助您了解错误。

scala> val persistenceBins = List[Int](1000 * 60 * 60, 2 * 1000 * 60 * 60, 4 * 1000 * 60 * 60)
persistenceBins: List[Int] = List(3600000, 7200000, 14400000)

scala> val persistenceValues = persistenceBins.map((bin: Int) => (bin, 0))
persistenceValues: List[(Int, Int)] = List((3600000,0), (7200000,0), (14400000,0))