map:
输入一个元素同时输出一个元素。下面是将输入流中元素数值加倍的 map function:
[root@master pyflink]# cat flik_3.py
# -*- coding: utf-8 -*-
from pyflink.datastream import StreamExecutionEnvironment
from pyflink.datastream.functions import MapFunction, RuntimeContext, KeyedProcessFunction
from pyflink.datastream.state import MapStateDescriptor
from pyflink.datastream.connectors.kafka import FlinkKafkaConsumer
from pyflink.common.typeinfo import Types, TypeInformation
from pyflink.datastream.connectors.elasticsearch import Elasticsearch7SinkBuilder, ElasticsearchEmitter, FlushBackoffType
from pyflink.datastream.connectors import DeliveryGuarantee
from pyflink.common.serialization import SimpleStringSchema
import json
import re
env = StreamExecutionEnvironment.get_execution_environment()
data_stream = env.from_collection(collection=[1, 2, 3, 4, 5])
data_stream=data_stream.map(lambda x: 2 * x, output_type=Types.INT())
# 输出到控制台
data_stream.print()
# 执行任务
env.execute('Add "aaaa" to each line')
[root@master pyflink]# python flik_3.py
1> 6
4> 4
3> 2
2> 8
3> 10