Search code examples
sqlapache-flinkflink-streamingcreate-tableflink-sql

Flink Create View or Table as Select


I was reading the Flink SQL docs and in the section on Create, I could not find anything that resembles CREATE VIEW AS SELECT nor CTAS.

I looked a bit further and found the following:

  • Flink SQL allows you to Select
  • Flink SQL allows you to Create
  • Flink SQL allows you to Insert

As such, it seems like Flink SQL would allow you to imitate the capabilities of Create as Select, but without the convenience of automatically grabbing the schema of the source table.

In addition, I found that:

  • Flink (outside SQL) allows you to assign the output of an SQL Select statement to a new table (and presumably a view)

For example:

Table result = tableEnv.sqlQuery("SELECT product, amount FROM Orders WHERE product LIKE '%Rubber%'");

Now my question:

(How) Does Flink allow you to Create as Select without leaving the SQL context

And based on the examples that I have seen this can likely be rephrased as:

Can you create as select inside an executeSql statement.


Solution

  • In Flink SQL, there exist the known CREATE VIEW AS SELECT since 1.11. In older versions, you'd need to resort to the table API as pointed out by you.