赞
踩
//yield
import json
import re
import logging
import sys
from collections import Counter
from pyflink.datastream import DataStream, StreamExecutionEnvironment
from pyflink.datastream.functions import RuntimeContext, FlatMapFunction, MapFunction,KeySelector
from pyflink.common.typeinfo import Types
s_env = StreamExecutionEnvironment.get_execution_environment()
data = DataStream(s_env._j_stream_execution_environment.socketTextStream('192.168.137.201', 8899))
#data.print()
def get_key():
return '999'
class LogEvent:
world=None
def __init__(self,world,count):
self.world = world
self.count = count
def to_dict(self):
return {
"world": str(self.world),
"count": str(self.count)
}
class MyMapFunction(FlatMapFunction):
def open(self, runtime_context: RuntimeContext):
pass
def flat_map(self, raw_message):
arr_message=raw_message.split('\s')
for x in arr_message:
return x
arr_message=[]
def get_key(raw_message):
arr_message = raw_message.split('\s+')
yield arr_message:
data.flat_map(MyMapFunction()).print()
s_env.execute('data')
[root@master pyflink]# python3 test_keyby.py
3> a b c a d f
//return
import json
import re
import logging
import sys
from collections import Counter
from pyflink.datastream import DataStream, StreamExecutionEnvironment
from pyflink.datastream.functions import RuntimeContext, FlatMapFunction, MapFunction,KeySelector
from pyflink.common.typeinfo import Types
s_env = StreamExecutionEnvironment.get_execution_environment()
data = DataStream(s_env._j_stream_execution_environment.socketTextStream('192.168.137.201', 8899))
#data.print()
def get_key():
return '999'
class LogEvent:
world=None
def __init__(self,world,count):
self.world = world
self.count = count
def to_dict(self):
return {
"world": str(self.world),
"count": str(self.count)
}
class MyMapFunction(FlatMapFunction):
def open(self, runtime_context: RuntimeContext):
pass
def flat_map(self, raw_message):
arr_message=raw_message.split('\s')
for x in arr_message:
return x
arr_message=[]
def get_key(raw_message):
arr_message = raw_message.split('\s+')
for x in arr_message:
yield x
data.flat_map(MyMapFunction()).print()
s_env.execute('data')
[root@master pyflink]# python3 test_keyby.py
4> a
4>
4> b
4>
4>
4> c
4>
4> d
4>
4> e
4>
4> f
4>
4> g
4>
4> h
4>
4> i
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。