【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战014--DateSet实用API详解014
2017-11-16 10:08
856 查看
DateSet的API详解十四
Union
def union(other: DataSet[T]): DataSet[T] Creates a new DataSet containing the elements from both this DataSet and the other DataSet. 合并多个DataSet。
执行程序:
//1.定义 case class case class Student(val name: String, addr: String, salary: Double) //2.定义三个DataSet[Student] val tuples1 = benv.fromElements( Student("lisi-1","shandong",2400.00),Student("zhangsan-1","henan",2600.00)) val tuples2 = benv.fromElements( Student("lisi-2","shandong",2400.00),Student("zhangsan-2","henan",2600.00)) val tuples3 = benv.fromElements( Student("lisi-3","shandong",2400.00),Stu cb78 dent("zhangsan-3","henan",2600.00)) //3.将三个DataSet合并起来 val unioned = tuples1.union(tuples2).union(tuples3) //4.显示结果 unioned.collect
执行结果:
res113: Seq[Student] = Buffer( Student(lisi-1,shandong,2400.0), Student(zhangsan-1,henan,2600.0), Student(lisi-2,shandong,2400.0), Student(zhangsan-2,henan,2600.0), Student(lisi-3,shandong,2400.0), Student(zhangsan-3,henan,2600.0))
web ui中的执行效果:
first
def first(n: Int): DataSet[T] Creates a new DataSet containing the first n elements of this DataSet 取前n个元素
执行程序:
//1.定义 case class case class Student(val name: String, addr: String, salary: Double) //2.定义DataSet[Student] val in: DataSet[Student] = benv.fromElements( Student("lisi","shandong",2400.00),Student("zhangsan","hainan",2600.00), Student("wangwu","shandong",2400.00),Student("zhaoliu","hainan",2600.00), Student("xiaoqi","guangdong",2400.00),Student("xiaoba","henan",2600.00)) //3.取前2个元素 val out1 = in.first(2) out1.collect //3.取前2个元素 ??? val out2 = in.groupBy(0).first(2) out2.collect //3.取前3个元素 ??? val out3 = in.groupBy(0).sortGroup(1, Order.ASCENDING).first(3) out3.collect
执行结果:
Scala-Flink> out1.collect res126: Seq[Student] = Buffer( Student(lisi,shandong,2400.0), Student(zhangsan,hainan,2600.0)) Scala-Flink> out2.collect res127: Seq[Student] = Buffer( Student(lisi,shandong,2400.0), Student(wangwu,shandong,2400.0), Student(xiaoba,henan,2600.0), Student(xiaoqi,guangdong,2400.0), Student(zhangsan,hainan,2600.0), Student(zhaoliu,hainan,2600.0)) Scala-Flink> out3.collect res128: Seq[Student] = Buffer( Student(lisi,shandong,2400.0), Student(wangwu,shandong,2400.0), Student(xiaoba,henan,2600.0), Student(xiaoqi,guangdong,2400.0), Student(zhangsan,hainan,2600.0), Student(zhaoliu,hainan,2600.0))
相关文章推荐
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战007--DateSet实用API详解007
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战023--DateSet实用API详解023
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战025--DateSet实用API详解025
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战006--DateSet实用API详解006
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战008--DateSet实用API详解008
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战018--DateSet实用API详解018
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战024--DateSet实用API详解024
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战005--DateSet实用API详解005
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战026--DateSet实用API详解026
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战001--DateSet实用API详解001
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战010--DateSet实用API详解010
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战019--DateSet实用API详解019
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战027--DateSet实用API详解027
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战012--DateSet实用API详解012
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战002--DateSet实用API详解002
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战016--DateSet实用API详解016
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战020--DateSet实用API详解020
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战013--DateSet实用API详解013
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战017--DateSet实用API详解017
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战004--DateSet实用API详解004