06-flink-1.10.1-flink source api
2021/9/5 23:09:30
本文主要是介绍06-flink-1.10.1-flink source api,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1 flink 从集合中读取数据
1.1 代码
package com.study.liucf.bounded.api.source import org.apache.flink.streaming.api.scala._ /** * @Author liucf * @Date 2021/9/5 */ case class SensorReding(id:String,timeStamp:Long,temperature:Double) object CollectionSource { def main(args: Array[String]): Unit = { //定义一个提供数据的List val dataList = List( SensorReding("sensor_1",1630851513,36.1), SensorReding("sensor_2",1630851512,36.2), SensorReding("sensor_3",1630851513,36.3), SensorReding("sensor_4",1630851514,36.4), SensorReding("sensor_5",1630851515,36.5), ) //定义执行环境 val env = StreamExecutionEnvironment.getExecutionEnvironment //读取集合数据源 val ds: DataStream[SensorReding] = env.fromCollection(dataList) //输出结果到标准控制台 ds.print() //启动执行器 env.execute("liucf collection source test") } }
1.2 执行结果
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 4> SensorReding(sensor_2,1630851512,36.2) 6> SensorReding(sensor_4,1630851514,36.4) 5> SensorReding(sensor_3,1630851513,36.3) 7> SensorReding(sensor_5,1630851515,36.5) 3> SensorReding(sensor_1,1630851513,36.1) Process finished with exit code 0
2 fink 从文件中读取数据
2.1 数据文件
2.2 代码
package com.study.liucf.bounded.api.source import org.apache.flink.streaming.api.scala._ /** * @Author liucf * @Date 2021/9/5 */ object FileSource { def main(args: Array[String]): Unit = { //创建flink执行环境 val env = StreamExecutionEnvironment.getExecutionEnvironment //从文件中读取数据 val ds = env.readTextFile("src\\main\\resources\\sensor.txt") //输出结果到标准控制台 ds.print() //启动flink执行 env.execute("liucf File source test") } }
2.3 输出结果
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 6> sensor_4,1630851514,36.4 5> sensor_3,1630851513,36.3 2> sensor_1,1630851513,36.1 3> sensor_2,1630851512,36.2 8> sensor_5,1630851515,36.5 Process finished with exit code 0
这篇关于06-flink-1.10.1-flink source api的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-10Rakuten 乐天积分系统从 Cassandra 到 TiDB 的选型与实战
- 2025-01-09CMS内容管理系统是什么?如何选择适合你的平台?
- 2025-01-08CCPM如何缩短项目周期并降低风险?
- 2025-01-08Omnivore 替代品 Readeck 安装与使用教程
- 2025-01-07Cursor 收费太贵?3分钟教你接入超低价 DeepSeek-V3,代码质量逼近 Claude 3.5
- 2025-01-06PingCAP 连续两年入选 Gartner 云数据库管理系统魔力象限“荣誉提及”
- 2025-01-05Easysearch 可搜索快照功能,看这篇就够了
- 2025-01-04BOT+EPC模式在基础设施项目中的应用与优势
- 2025-01-03用LangChain构建会检索和搜索的智能聊天机器人指南
- 2025-01-03图像文字理解,OCR、大模型还是多模态模型?PalliGema2在QLoRA技术上的微调与应用