我使用PyFlink开发了一个单词计数程序。程序没有抛出任何错误,但没有提供所需的输出。根据代码,程序应该创建一个新的文本文件,但在执行时没有生成任何文件。请帮忙,我的代码附在下面。
from flink.plan.Constants import WriteMode
from flink.plan.Environment import get_environment
from flink.functions.FlatMapFunction import FlatMapFunction
from flink.functions.GroupReduceFunction import GroupReduceFunction
from pyflink import datastream
from pyflink.common import WatermarkStrategy, Encoder, Types
from pyflink.datastream import StreamExecutionEnvironment, RuntimeExecutionMode
from pyflink.datastream.connectors import (FileSource, StreamFormat, FileSink, OutputFileConfig, RollingPolicy)
class Tokenizer(FlatMapFunction):
def flat_map(self, value, collector):
super().__init__()
for word in value.lower().split(","):
if len(word)>1:
collector.collect((word, 1))
if __name__ == '__main__':
env = get_environment()
env.set_parallelism(2)
data = env.read_text("h.txt")
tokenized = data.flat_map(Tokenizer())
count = tokenized.group_by(0).sum(1)
count.write_text("D:/Cyber Security/Apache Flink")
在程序结束时尝试使用env.execute("Word Count Example...")
。它开始了你的处决。