【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战014--DateSet实用API详解014
来源:互联网 发布:c语言读写ini配置文件 编辑:程序博客网 时间:2024/06/05 01:33
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 classcase 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),Student("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 classcase 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.collectres126: Seq[Student] = Buffer(Student(lisi,shandong,2400.0), Student(zhangsan,hainan,2600.0))Scala-Flink> out2.collectres127: 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.collectres128: 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))
阅读全文
0 0
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战014--DateSet实用API详解014
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战001--DateSet实用API详解001
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战002--DateSet实用API详解002
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战003--DateSet实用API详解003
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战004--DateSet实用API详解004
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战005--DateSet实用API详解005
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战006--DateSet实用API详解006
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战007--DateSet实用API详解007
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战008--DateSet实用API详解008
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战009--DateSet实用API详解009
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战010--DateSet实用API详解010
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战011--DateSet实用API详解011
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战012--DateSet实用API详解012
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战013--DateSet实用API详解013
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战015--DateSet实用API详解015
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战016--DateSet实用API详解016
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战017--DateSet实用API详解017
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战018--DateSet实用API详解018
- 第十一周项目四
- android 硬件加速
- maven-管理父类pom
- Sever 2008,2012 如何添加计算机图标到桌面
- 什么是ble?
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战014--DateSet实用API详解014
- od拦截对话框的另类方法
- Celery-4.1 用户指南: Task
- vc++ 德卡(IC卡)D3-U设密与读写应用
- MySQL 安装在 Windows2008R2
- SpringBoot-MongoDB
- Linux 上安装Realtek瑞昱网卡驱动
- sqlite3类
- 第十一周项目4(2)-利用遍历思想求解图问题