当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- On the confirmation of original data assets
- Why is Schnorr Signature known as the biggest technology update after bitcoin segwit
- Win10 Terminal + WSL 2 安装配置指南,精致开发体验
- 应届生年薪35w+ !倒挂老员工,互联网大厂薪资为何越来越高?
- Learning summary (about deep learning, vision and learning experience)
- Istio traffic management -- progress gateway
- This year's salary is 35W +! Why is the salary of Internet companies getting higher and higher?
- VC + + specified directory file output by time
- 【Python 1-6】Python教程之——数字
- Adobe media encoder / me 2021 software installation package (with installation tutorial)
猜你喜欢

Improvement of rate limit for laravel8 update

Personal current technology stack

Analysis of istio access control

Powershell 使用.Net对象发送邮件

Ali teaches you how to use the Internet of things platform! (Internet disk link attached)

When kubernetes encounters confidential computing, see how Alibaba protects the data in the container! (Internet disk link attached)

墨者学院SQL注入解题

虚拟机中安装 macOS 11 big sur

笔试面试题目:求缺失的最小正整数

Flink从入门到真香(10、Sink数据输出-Elasticsearch)
随机推荐
IQKeyboardManager 源代码看看
Personal current technology stack
211 postgraduate entrance examination failed, stay up for two months, get the byte offer! [face to face sharing]
Tidb performance competition 11.02-11.06
Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)
Where is the new target market? What is the anchored product? |Ten questions 2021 Chinese enterprise service
Share the experience of passing the PMP examination
The most complete! Alibaba economy cloud original practice! (Internet disk link attached)
阿里出品!视觉计算开发者系列手册(附网盘链接)
The young generation of winner's programming life, the starting point of changing the world is hidden around
Learning summary (about deep learning, vision and learning experience)
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
YGC问题排查,又让我涨姿势了!
Why is Schnorr Signature known as the biggest technology update after bitcoin segwit
android基础-CheckBox(复选框)
一文剖析2020年最火十大物联网应用|IoT Analytics 年度重磅报告出炉!
如何将 PyTorch Lightning 模型部署到生产中
Close to the double 11, he made up for two months and successfully took the offer from a large factory and transferred to Alibaba
TiDB 性能竞赛 11.02-11.06
不多不少,大学里必做的五件事(从我的大一说起)