Table API also allows us to write free form SQL queries using the sql()
method. The method internally also uses Apache Calcite for SQL syntax verification and optimization. It executes the query and returns results in the table format. Later the table can be again transformed into either a dataset or datastream or TableSink
for further processing.
One thing to note here is that, for the SQL method to access the tables, they must be registered with TableEnvironment
.
More support is being added to the SQL method continuously so if any syntax is not supported, it will error out with TableException
.
Now let's look at how to use the SQL method on a dataset and datastream.
SQL queries can be executed on datastreams registered with TableEnvironment
using the SELECT STREAM
keyword. Most of the SQL syntax is common between datasets and datastreams. To know more about stream syntax, the Apache Calcite's Streams documentation would be helpful. It can be found at: https://calcite.apache...