spark rdd 和 DF 转换
来源:互联网 发布:便利店软件商品录入 编辑:程序博客网 时间:2024/05/16 07:59
RDD -》 DF
有两种方式
一、
一、Inferring the Schema Using Reflection
将 RDD[t] 转为一个 object ,然后 to df
val peopleDF = spark.sparkContext .textFile("examples/src/main/resources/people.txt") .map(_.split(",")) .map(attributes => Person(attributes(0), attributes(1).trim.toInt)) .toDF()
rdd 也能直接装 DATASet 要 import 隐式装换 类 import spark.implicits._
如果 转换的对象为 tuple . 转换后 下标为 _1 _2 .....
二、Programmatically Specifying the Schema
把 columnt meta 和 rdd createDataFrame 在一起
val peopleRDD = spark.sparkContext.textFile("examples/src/main/resources/people.txt")// The schema is encoded in a stringval schemaString = "name age"// Generate the schema based on the string of schemaval fields = schemaString.split(" ") .map(fieldName => StructField(fieldName, StringType, nullable = true))val schema = StructType(fields)
val rowRDD = peopleRDD .map(_.split(",")) .map(attributes => Row(attributes(0), attributes(1).trim))// Apply the schema to the RDDval peopleDF = spark.createDataFrame(rowRDD, schema)// Creates a temporary view using the DataFramepeopleDF.createOrReplaceTempView("people")
DF to RDd
val tt = teenagersDF.rdd
0 0
- spark rdd 和 DF 转换
- spark rdd 和 DF 转换
- Spark RDD的转换
- spark rdd 转换过程
- Spark RDD的转换
- 【spark,rdd,2】RDD基本转换算子
- 使用java 将 Spark RDD和DataFrame转换
- Spark源码解读之RDD构建和转换过程
- spark下rdd和dataframe以及sqlcontext之间相互转换
- spark基础之RDD和DataFrame的转换方式
- rdd和DF数据存入MYSQL
- spark之RDD基本转换
- Spark之键值RDD转换
- Spark RDD的缓存 rdd.cache() 和 rdd.persist()
- Spark RDD的缓存 rdd.cache() 和 rdd.persist()
- RDD和DataFram转换
- Spark RDD和Dataset区别
- Spark RDD概念学习系列之RDD的转换图解
- 在多字节的目标代码页中,没有此 Unicode 字符可以映射到的字符。 (异常来自 HRESULT:0x80070459)
- samba安装配置
- C# 文件与二进制流间的转换
- c++作业5
- Tanks Unity Tutorial
- spark rdd 和 DF 转换
- Gson解析,Volley使用,Gson转成Bean 类 _____给你一个json文件的网址, 一秒解析出你想要的参数.
- 关于Mybatis的输入参数包装
- ThinkPHP 5.5版本以上”No input file specified“问题解决
- NYOJ42一笔画问题_欧拉图(记录节点度数+深搜)
- poj3101——Astronomy(大数数学&gcd)
- 欢迎使用CSDN-markdown编辑器
- 那些“不务正业”的IT培训公司
- @SuppressWarnings("serial")注解