2016-09-16 57 views
3

在星火1.6.2(斯卡拉2.10.5)下面的代碼在殼工作只是罰款:星火2.0 Scala的import語句

import org.apache.spark.mllib.linalg.Vector 
case class DataPoint(vid: String, label: Double, features: Vector) 

的mllib矢量正確蓋過了Scala的載體。

然而,星火2.0(斯卡拉2.11.8)相同的代碼拋出在shell以下錯誤:

<console>:11: error: type Vector takes type parameters 
    case class DataPoint(vid: String, label: Double, features: Vector) 

爲了使其工作,我現在必須明確命名類:

case class DataPoint(vid: String, label: Double, 
    features: org.apache.spark.mllib.linalg.Vector) 

有人可以告訴我什麼改變了,是Spark還是Scala有過錯?謝謝!

+2

他們改變了火花殼做進口,有它突出的錯誤。你在談論從shell運行嗎? –

+0

@ som-snytt是我從shell運行 - 謝謝 - 更新了問題。好吧,那麼它最有可能是一個錯誤。 – Roman

回答

3

最簡單的辦法就是對這個問題是一個簡單的paste

Welcome to 
     ____    __ 
    /__/__ ___ _____/ /__ 
    _\ \/ _ \/ _ `/ __/ '_/ 
    /___/ .__/\_,_/_/ /_/\_\ version 2.1.0-SNAPSHOT 
     /_/ 

Using Scala version 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_102) 
Type in expressions to have them evaluated. 
Type :help for more information. 

scala> import org.apache.spark.mllib.linalg.Vector 
import org.apache.spark.mllib.linalg.Vector 

scala> case class DataPoint(vid: String, label: Double, features: Vector) 
<console>:11: error: type Vector takes type parameters 
     case class DataPoint(vid: String, label: Double, features: Vector) 
                   ^

scala> :paste 
// Entering paste mode (ctrl-D to finish) 

import org.apache.spark.mllib.linalg.Vector 
case class DataPoint(vid: String, label: Double, features: Vector) 

// Exiting paste mode, now interpreting. 

import org.apache.spark.mllib.linalg.Vector 
defined class DataPoint 
+0

謝謝@ zero323 - 你的解決方案確實有效!你能不能詳細說明是什麼使它工作? – Roman

+1

與逐行工作相比,差異在於整個模塊一起編譯。通過將所有內容放在同一個塊中,例如'{import ....; case class DataPoint(...)}'(我知道,沒用)或者包裝一個對象。但如果你問如何解決這個上游,我不知道。外殼嚴重閃爍,並且存在許多醜陋的bug,包括[case class monster](http://stackoverflow.com/q/35301998/1560062)。 – zero323

+0

非常感謝你! – Roman