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