当前位置:网站首页>Flink: from introduction to Zhenxiang (3. Reading data from collection and file)
Flink: from introduction to Zhenxiang (3. Reading data from collection and file)
2020-11-08 12:06:00 【open_neocf7df】
You can refer to : https://blog.51cto.com/mapengfei/2546985
Reading data from a collection
New package ,com.mafei.apitest, Create a new one scala Object class ,
package com.mafei.apitest
import org.apache.flink.api.scala.createTypeInformation
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
// Get sensor data
case class SensorReading(id: String,timestamp: Long, temperature: Double)
object SourceTest {
def main(args: Array[String]): Unit = {
// Create an execution environment
val env = StreamExecutionEnvironment.getExecutionEnvironment
// 1、 Reading data from a collection
val dataList = List(
SensorReading("sensor1",1603766281,41),
SensorReading("sensor2",1603766282,42),
SensorReading("sensor3",1603766283,43),
SensorReading("sensor4",1603766284,44)
)
val stream1 = env.fromCollection(dataList)
stream1.print()
// perform
env.execute(" source test")
}
}
Code catalog diagram :
Running effect
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.
2> SensorReading(sensor3,1603766283,43.0)
4> SensorReading(sensor1,1603766281,41.0)
3> SensorReading(sensor4,1603766284,44.0)
1> SensorReading(sensor2,1603766282,42.0)
Read data from file
Just like the first step , New package ,com.mafei.apitest, Create a new one scala Object class ,
package com.mafei.apitest
import org.apache.flink.api.scala.createTypeInformation
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
// Get sensor data
case class SensorReading(id: String,timestamp: Long, temperature: Double)
object SourceTest {
def main(args: Array[String]): Unit = {
// Create an execution environment
val env = StreamExecutionEnvironment.getExecutionEnvironment
// Reading data from a file
val stream2= env.readTextFile("/opt/java2020_study/maven/flink1/src/main/resources/sensor.txt")
stream2.print()
// perform
env.execute(" source test")
}
}
stay resources New under the directory sensor.txt, Write the following
sensor1,1603766281,41
sensor2,1603766282,42
sensor3,1603766283,43
sensor4,1603766284,44
Code structure diagram :
Code running effect :
1> sensor1,1603766281,41
1> sensor2,1603766282,42
2> sensor3,1603766283,43
3> sensor4,1603766284,44
版权声明
本文为[open_neocf7df]所创,转载请带上原文链接,感谢
边栏推荐
- 【Python 1-6】Python教程之——数字
- 个人目前技术栈
- This paper analyzes the top ten Internet of things applications in 2020!
- A scheme to improve the memory utilization of flutter
- From a friend recently Ali, Tencent, meituan and other P7 Python development post interview questions
- C语言I博客作业03
- Ali tear off the e-commerce label
- 解析Istio访问控制
- 学习小结(关于深度学习、视觉和学习体会)
- How to write a resume and project
猜你喜欢

Mozi college SQL injection solution

【Python 1-6】Python教程之——数字

维图PDMS切图软件

YGC问题排查,又让我涨姿势了!

Second assignment

Ali tear off the e-commerce label

Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
![[data structure Python description] use hash table to manually implement a dictionary class based on Python interpreter](/img/3b/00bc81122d330c9d59909994e61027.jpg)
[data structure Python description] use hash table to manually implement a dictionary class based on Python interpreter

值得一看!EMR弹性低成本离线大数据分析最佳实践(附网盘链接)

Installing MacOS 11 Big Sur in virtual machine
随机推荐
When kubernetes encounters confidential computing, see how Alibaba protects the data in the container! (Internet disk link attached)
来自朋友最近阿里、腾讯、美团等P7级Python开发岗位面试题
The progress bar written in Python is so wonderful~
蘑菇街电商交易平台服务架构及改造优化历程(含PPT)
Written interview topic: looking for the lost pig
We interviewed the product manager of SQL server of Alibaba cloud database, and he said that it is enough to understand these four problems
应届生年薪35w+ !倒挂老员工,互联网大厂薪资为何越来越高?
TiDB 性能竞赛 11.02-11.06
Web novice problem of attacking and defending the world
Written interview questions: find the smallest positive integer missing
当Kubernetes遇到机密计算,看阿里巴巴如何保护容器内数据的安全!(附网盘链接)
Implementation of verification code recognition in Python opencv pytesseract
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
运维人员常用到的 11 款服务器监控工具
TCP协议如何确保可靠传输
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
如何将 PyTorch Lightning 模型部署到生产中
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
python基本语法 变量
Flink从入门到真香(7、Sink数据输出-文件)