pyflink filter

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,FilterFunction

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):

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):

raw_message = raw_message.upper()

dict1 = {}

dict1['value'] = raw_message +'!!!'

yield dict1

class myFilterFunction(FilterFunction):

def filter(self,raw_message):

if re.findall('AAA',raw_message):

return raw_message

data.filter(myFilterFunction()).print()

s_env.execute('data')

相关推荐
Lenyiin5 分钟前
《Python 修炼全景指南:一》从环境搭建到第一个程序
开发语言·python
涛声依旧3931624 分钟前
Python项目实战:学生信息管理系统
开发语言·python·数据挖掘
kcuwu.1 小时前
Python进阶:生成器与协程,高效并发编程的核心实践
windows·python·php
XiaoQiao6669991 小时前
python 简单题目练手【详解版】【1】
开发语言·python
ZC跨境爬虫1 小时前
极验滑动验证码自动化实战:背景提取、缺口定位与Playwright滑动模拟
前端·爬虫·python·自动化
智算菩萨1 小时前
【Python图像处理】2 数字图像基础与Python图像表示
开发语言·图像处理·python
xiaoshuaishuai82 小时前
Git二分法定位Bug
开发语言·python
2401_835792542 小时前
FastAPI 速通
windows·python·fastapi
YMWM_2 小时前
export MPLBACKEND=Agg命令使用
linux·python
派大星~课堂2 小时前
【力扣-148. 排序链表】Python笔记
python·leetcode·链表