SPARK dataframe 两个表操作
来源:互联网 发布:金山数据恢复 编辑:程序博客网 时间:2024/06/05 17:57
spark 如何操作两个文件呢?
看下面样例:
创建了两个临时表,而后在编写语句。
class vistorcount extends Serializable{
//the defination please put here,otherwise it will compile error.
case class person(name:String,age:Int)
case class personscore(name:String,score:Int)
//case class mobiledata(mobile:String,longtitude:String,latitude:String,status:Int,createtime:String)
case class mobiledata(mobile:String,longtitude:String,latitude:String)
case class mobilecity(mobilerange:String,city:String)
def getpeople(): Unit = {
val conf = new SparkConf().setAppName("traveldata").setMaster("local[*]")
val sc = new SparkContext(conf)
val sqlContext = new SQLContext(sc)
import sqlContext.implicits._
val df = sc.textFile("c://traveldata//people.txt", 1)
.map(_.split(","))
.map(p=>person(p(0),p(1).trim.toInt))
.toDF()
df.registerTempTable("people")
//cacheTable("people")
val ps = sc.textFile("c://traveldata//peoplescore.txt", 1).map(_.split(",")).map(p=>personscore(p(0),p(1).trim.toInt)).toDF()
ps.registerTempTable("personscore")
val resultDF = sqlContext.sql("select people.name,people.age,personscore.score from people,personscore where people.name=personscore.name");
//resultDF.show()
resultDF.collect().foreach(println)
sc.stop()
}
}
2 0
- SPARK dataframe 两个表操作
- spark sql DataFrame操作
- 【spark】DataFrame基本操作
- spark sql dataframe操作
- spark dataframe操作
- Spark DataFrame相关操作
- Spark Dataframe操作
- Spark-SQL DataFrame操作
- Spark DataFrame 操作命令
- Spark DataFrame创建与操作
- Spark dataframe创建&操作总结
- spark dataframe创建和操作
- Apache Spark DataFrames入门指南:操作DataFrame
- Apache Spark DataFrames入门指南:操作DataFrame
- Spark-SQL之DataFrame操作大全
- Spark-SQL之DataFrame操作大全
- Apache Spark DataFrames入门指南:操作DataFrame
- Spark-SQL 之DataFrame操作大全
- 启动另外一个app
- 例说Hausdorff距离
- 将数组转为List的方法,转换后不可执行List的哪些操作?
- windows或者linux下执行java程序(.jar)
- 两个链表的第一个公共节点
- SPARK dataframe 两个表操作
- 在Eclipse里面怎么读取当前包下1个txt文件的路径
- LeetCode 147 Insertion Sort List
- 蓝桥杯历届试题——国王的烦恼(并查集)
- 《ACM程序设计》书中题目 K
- 使用Chipscope时如何防止reg_wire型信号被优化掉
- 二叉树的遍历(篇4)判断从根到叶节点的和是否等于某个给定的值
- Android处理图片报OOM的问题解决
- Saprk数据倾斜七解决方案(一)