当前位置:网站首页>[Flink] transform operator map
[Flink] transform operator map
2022-07-25 03:27:00 【No bug is the biggest bug】
One 、 Entity class
@Data
public class Event {
public String user;
public String url;
public Long timestamp;
public Event(String user, String url, Long timestamp) {
this.user = user;
this.url = url;
this.timestamp = timestamp;
}
}Two 、 Custom data sources simulate streaming data
public class ClickSource implements SourceFunction<Event> {
// Declare a flag class
private Boolean running = true;
@Override
public void run(SourceContext<Event> ctx) throws Exception {
// Randomly generated data
Random random = new Random();
// Define the data set selected by the field
String[] users = {"Mary","Alice","Bob","Cary"};
String[] urls = {"./home","./cart","./fav","./prod?id=100","./prod:id=10"};
// Loop data
while (running){
String user = users[random.nextInt(users.length)];
String url = urls[random.nextInt(user.length())];
Long time = System.currentTimeMillis();
ctx.collect(new Event(user,url,time));
Thread.sleep(2000);
}
}
@Override
public void cancel() {
running = false;
}
}3、 ... and 、 Task code
public static void main(String[] args) throws Exception {
// Create an execution environment
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
// Set parallelism
env.setParallelism(1);
// Read data source
DataStreamSource<Event> dataStream = env.addSource(new ClickSource());
// Perform a conversion operation mapping
SingleOutputStreamOperator<String> map = dataStream.map(new MapFunction<Event, String>() {
@Override
public String map(Event event){
if (event.user.equals("Bob")){
return " I'm Bob ";
}
return event.user;
}
});
// Print
map.print();
// Start
env.execute();
}边栏推荐
- Banana pie bpi-m5 toss record (3) -- compile BSP
- Li Kou 279 complete square - dynamic programming
- Color space (2) -- YUV
- How to use two queues to simulate the implementation of a stack
- JS password combination rule - 8-16 digit combination of numbers and characters, not pure numbers and pure English
- Flink1.15 source code reading - Flink annotations
- File permission management
- Canvas record
- Brief understanding of operational amplifier
- Network security - information hiding - use steganography to prevent sensitive data from being stolen
猜你喜欢

Force deduction brush question 14. Longest common prefix

B. Making Towers

Vscode configuration, eslint+prettier combined with detailed configuration steps, standardized development

Advantages and disadvantages of zero trust security

Force button brushing question 61. rotating linked list

File permission management

mysql_ Master slave synchronization_ Show slave status details

A code takes you to draw multi format sangjimei pictures such as interactive +pdf+png

Import and export using poi

Analysis of DNS domain name resolution process
随机推荐
Visio use
Secondary vocational network security skills competition P100 web penetration test
Machine learning notes - building a recommendation system (4) matrix decomposition for collaborative filtering
Function of each layer of data warehouse
ECMAScript new features
Implementation principle of virtual DOM
VMware installation
Force button brushing question 61. rotating linked list
mysql_ Create temporary table
Can bus baud rate setting of stm32cubemx
mysql_ Record the executed SQL
Handwriting promise
What is technical support| Daily anecdotes
Fiddler grabs packets and displays err_ TUNNEL_ CONNECTION_ FAILED
Use of CCleaner
Stm32cubemx quadrature encoder
Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading
Performance test indicators using JMeter
Innobackupex parameter description
Network security - information hiding - use steganography to prevent sensitive data from being stolen