syedteck
syedteck

Reputation: 1

Apache Flink - WordCount - NoResult - PyFlink

I have developed a Word Count program using PyFlink. The program is not throwing any error yet not providing a desired output. According to the code, the program should create a new text file but no file is generating at the the time of execution. Kindly help, my code is attached below.

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

Upvotes: 0

Views: 308

Answers (1)

whatsinthename
whatsinthename

Reputation: 2157

Try using env.execute("Word Count Example...") at the end of the program. It kicks off your execution.

Upvotes: 3

Related Questions