SparkSql 隱式轉換異常


 一、Sparksql隱式轉換時異常描述

Cannot  create encoder for Option of Product type, because Product type is represented as a row, and the entire row can not be null in Spark SQL like normal databases.
You can wrap your type with Tuple1 if you do want top level null Product objects, e.g. instead of creating `Dataset[Option[MyClass]]`,
you can do something like `val ds: Dataset[Tuple1[MyClass]] = Seq(Tuple1(MyClass(...)), Tuple1(null)).toDS`

二、原因和解決方法

此問題主要是由於將data[Row]轉換成對應的的dataSet類型時,找不到對應的類型轉換導致的,需要為對應的類型添加隱式轉換,一般添加代碼:

implicit val registerKryoEncoder = Encoders.kryo[MyClass]


免責聲明!

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



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