加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

用于火花箱类的scala通用编码器

发布时间:2020-12-16 18:45:30 所属栏目:安全 来源:网络整理
导读:我怎样才能编译这个方法.奇怪的是,隐含的火花已经被导入了. def loadDsFromHive[T : Product](tableName: String,spark: SparkSession): Dataset[T] = { import spark.implicits._ spark.sql(s"SELECT * FROM $tableName").as[T] } 这是错误: Unable to fin
我怎样才能编译这个方法.奇怪的是,隐含的火花已经被导入了.

def loadDsFromHive[T <: Product](tableName: String,spark: SparkSession): Dataset[T] = {
    import spark.implicits._
    spark.sql(s"SELECT * FROM $tableName").as[T]
  }

这是错误:

Unable to find encoder for type stored in a Dataset.  Primitive types (Int,String,etc) and Product types (case classes) are supported by importing spark.implicits._  Support for serializing other types will be added in future releases.
[error]     spark.sql(s"SELECT * FROM $tableName").as[T]

解决方法

根据org.apache.spark.sql.SQLImplicits的源代码,您需要类型类型TypeTag,以便隐式编码器存在:

import scala.reflect.runtime.universe.TypeTag
def loadDsFromHive[T <: Product: TypeTag](tableName: String,spark: SparkSession): Dataset[T] = ...

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读