1.Spark sql出现的 原因是什么?
答:Spark为结构化数据处理引入了一个称为Spark sql的编程模块。简而言之,sparksql是Spark的前身,是在Hadoop发展过程中,为了给熟悉RDBMS但又不理解MapReduce的技术人员提供快速上手的工具。
2.用spark.read 创建DataFrame
3.观察从不同类型文件创建DataFrame有什么异同?
4.观察Spark的DataFrame与Python pandas的DataFrame有什么异同?
Spark sql DataFrame的基本操作
创建:
spark.read.text()
>>>file='file:///usr/local/spark/examples/src/main/resources/people.txt' >>> df=spark.read.text(file)
spark.read.json()
>>>file='file:///usr/local/spark/examples/src/main/resources/people.json' >>> df=spark.read.json(file)
打印数据
df.show()默认打印前20条数据,df.show(n)
>>>file='file:///usr/local/spark/examples/src/main/resources/people.txt' >>> df=spark.read.text(file) >>> df.show()
>>>file='file:///usr/local/spark/examples/src/main/resources/people.json' >>> df=spark.read.json(file) >>> df.show()
打印概要
df.printSchema()
>>> df.printSchema()
查询总行数
df.count()
>>> df.count()
df.head(3) #list类型,list中每个元素是Row类
>>> df.head(2)
输出全部行
df.collect() #list类型,list中每个元素是Row类
>>> df.collect()
查询概况
df.describe().show()
>>> df.describe().show()
取列
df[‘name’]
df.name
df.select()
df.filter()
df.groupBy()
df.sort()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。