spark1.5 scala.collection.mutable.WrappedArray$ofRef cannot be cast to ...解決辦法


下面是我在spark user list的求助貼,很快就得到了正確回答,有遇到問題的同學解決不了也可以去上面提問。

I can use it under spark1.4.1,but error on spark1.5.1,how to deal with this problem?

//define Schema 
 val struct =StructType( 
      StructField("app_name", StringType, true):: StructField("apply_time",LongType ,true) :: StructField("final_decision" , StringType) :: StructField("final_score" ,IntegerType ) :: StructField("partner_code", StringType, true) :: StructField("person_info",MapType(StringType,StringType,true)) :: StructField("report_id",StringType, true) :: StructField("report_time",LongType ,true) :: StructField("risk_items",ArrayType(MapType(StringType,StringType,true))) :: Nil 
    ) 

val rdd2 = sqlContext.read.schema(struct).json(jsonData).map(r => { 
... 
      //Exception 
         val risk_items = r.getAs[List[Map[String, String]]]("risk_items") ... } 

報錯提示如下:

java.lang.ClassCastException: scala.collection.mutable.WrappedArray$ofRef cannot be cast to scala.collection.immutable.List

很快得到了一個正確的答案,只需要將List改為Seq就行了,回復如下:

這里寫圖片描述


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM