Spark 2.0 DataFrame map操作中Unable to find encoder for type stored in a Dataset.问题的分析与解决
转载:http://blog.csdn.net/sparkexpert/article/details/52871000
随着新版本的spark已经逐渐稳定,最近拟将原有框架升级到spark 2.0。还是比较兴奋的,特别是SQL的速度真的快了许多。。
然而,在其中一个操作时却卡住了。主要是dataframe.map操作,这个之前在spark 1.X是可以运行的,然而在spark 2.0上却无法通过。。
看了提醒的问题,主要是:
error:
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. resDf_upd.map(row =>
{
针对这个问题,网上所得获取的资料还真不多。不过想着肯定是dataset统一了datframe与rdd之后就出现了新的要求。
经过查看spark官方文档,对spark有了一条这样的描述。
Dataset is Spark SQL’s strongly-typed API for working with structured data, i.e. records with a known schema.
Datasets are lazy and structured query expressions are only triggered when an action is invoked. Internally, aDataset represents a logical plan that describes the computation query required to produce the data (for a givenSpark SQL session).
A Dataset is a result of executing a query expression against data storage like files, Hive tables or JDBC databases. The structured query expression can be described by a SQL query, a Column-based SQL expression or a Scala/Java lambda function. And that is why Dataset operations are available in three variants.
从这可以看出,要想对dataset进行操作,需要进行相应的encode操作。特别是官网给的例子
// No pre-defined encoders for Dataset[Map[K,V]], define explicitly
implicit val mapEncoder = org.apache.spark.sql.Encoders.kryo[Map[String, Any]]
// Primitive types and case classes can be also defined as
// implicit val stringIntMapEncoder: Encoder[Map[String, Any]] = ExpressionEncoder()
// row.getValuesMap[T] retrieves multiple columns at once into a Map[String, T]
teenagersDF.map(teenager => teenager.getValuesMap[Any](List("name", "age"))).collect()
// Array(Map("name" -> "Justin", "age" -> 19))
从这看出,要进行map操作,要先定义一个Encoder。。
这就增加了系统升级繁重的工作量了。为了更简单一些,幸运的dataset也提供了转化RDD的操作。因此只需要将之前dataframe.map
在中间修改为:dataframe.rdd.map即可。
最新文章
- SQL ALTER TABLE 语句在项目中的使用
- 关于json的理解
- 前端插件Emmet
- Python的面向对象4
- ZEDBOARD启动自启配置(加载镜像) 分类: OpenCV ubuntu shell ZedBoard Eye_Detection 2014-11-08 18:53 167人阅读 评论(0) 收藏
- [Python]从豆瓣电影批量获取看过这部电影的用户列表
- C函数调用与栈--代码真相
- windows下npm scripts不能执行的问题
- Javascript数组与基本函数
- session和cookie的辨析[阅读]
- decode函数解决oracle报错";除数为0";的问题
- C 语言 字符串命令 strstr()的用法 实现将原字符串以分割串分割输出
- Spark-SQL之DataFrame操作
- PHPNow升级PHP版本
- MicroOrm.Dapper.Repositories 的使用
- ubuntu安装mysql遇到的问题
- springboot工程的添加方式
- PAT A1004 Counting Leaves (30 分)——树,DFS,BFS
- 【转】WCF扩展系列 - 行为扩展(Behaviors)
- 《Haskell趣学指南》
热门文章
- 刷题总结——Throw nails(hdu4393)
- [解决方案]NuGet打包报错: 'X' already has a dependency defined for 'Y'
- linu触摸屏幕
- Android 画笔Paint
- [HNOI2002] 公交车路线
- fmap为什么可以用function作为第二个参数
- Linux用户态定时器用法以及犯错总结【转】
- aiohttp/asyncio 多次请求
- Postman前端HTTP请求调试神器教程
- EXCEL匹配结果match并跳转链接hyperlink