[root@master pyflink]# cat flink_sum.py
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
from pyflink.common.typeinfo import Types
env = StreamExecutionEnvironment.get_execution_environment()
ds = env.from_collection([('a', 1), ('a', 2), ('b', 1), ('b', 5),('a',7),('b',10)])
ds1=ds.key_by(lambda x: x[0]).sum(1)
ds2=ds1.print()
env.execute('data')
[root@master pyflink]# python3 flink_sum.py
2> ('a', 1)
1> ('b', 1)
1> ('b', 6)
1> ('b', 16)
2> ('a', 3)
2> ('a', 10)