Search code examples
apache-kafkaapache-flinkflink-streaming

What is the difference between StreamExecutionEnvironment and StreamTableEnvironment in Flink


Well, I'm a newbie on Apache Flink and reading some source codes on the Internet.

Sometimes I saw StreamExecutionEnvironment but I have also seen StreamTableEnvironment.

I've read the official doc but I still can't figure out their difference.

Furthermore, I'm trying to code a Flink Stream Job, which receives the data from Kafka. In this case, which kind of environment should I use?


Solution

  • A StreamExecutionEnvironment is used with the DataStream API. You need a StreamTableEnvironment if you are going to use the higher level Table or SQL APIs.

    The section of the docs on creating a TableEnvironment covers this in more detail.

    Which you should use depends on whether you want to work with lower level data streams, or a higher level relational API. Both can be used to implement a streaming job that reads from Kafka.

    The documentation includes a pair of code walkthroughs introducing both APIs, which should help you figure out which API is better suited for your use case. See the DataStream walkthrough and the Table walkthrough.

    To learn the DataStream API, spend a day working through the self-paced training. There's also training for Flink SQL. Both are free.