ALTER Statements

ALTER statements are used to modified a registered table/view/function definition in the Catalog.

Flink SQL supports the following ALTER statements for now:

  • ALTER TABLE
  • ALTER VIEW
  • ALTER DATABASE
  • ALTER FUNCTION

Run an ALTER statement

Java

ALTER statements can be executed with the executeSql() method of the TableEnvironment. The executeSql() method returns ‘OK’ for a successful ALTER operation, otherwise will throw an exception.

The following examples show how to run an ALTER statement in TableEnvironment.

Scala

ALTER statements can be executed with the executeSql() method of the TableEnvironment. The executeSql() method returns ‘OK’ for a successful ALTER operation, otherwise will throw an exception.

The following examples show how to run an ALTER statement in TableEnvironment.

Python

ALTER statements can be executed with the execute_sql() method of the TableEnvironment. The execute_sql() method returns ‘OK’ for a successful ALTER operation, otherwise will throw an exception.

The following examples show how to run an ALTER statement in TableEnvironment.

SQL CLI

ALTER statements can be executed in SQL CLI.

The following examples show how to run an ALTER statement in SQL CLI.

Java

  1. EnvironmentSettings settings = EnvironmentSettings.newInstance()...
  2. TableEnvironment tableEnv = TableEnvironment.create(settings);
  3. // register a table named "Orders"
  4. tableEnv.executeSql("CREATE TABLE Orders (`user` BIGINT, product STRING, amount INT) WITH (...)");
  5. // a string array: ["Orders"]
  6. String[] tables = tableEnv.listTables();
  7. // or tableEnv.executeSql("SHOW TABLES").print();
  8. // rename "Orders" to "NewOrders"
  9. tableEnv.executeSql("ALTER TABLE Orders RENAME TO NewOrders;");
  10. // a string array: ["NewOrders"]
  11. String[] tables = tableEnv.listTables();
  12. // or tableEnv.executeSql("SHOW TABLES").print();

Scala

  1. val tableEnv = TableEnvironment.create(...)
  2. // register a table named "Orders"
  3. tableEnv.executeSql("CREATE TABLE Orders (`user` BIGINT, product STRING, amount INT) WITH (...)")
  4. // a string array: ["Orders"]
  5. val tables = tableEnv.listTables()
  6. // or tableEnv.executeSql("SHOW TABLES").print()
  7. // rename "Orders" to "NewOrders"
  8. tableEnv.executeSql("ALTER TABLE Orders RENAME TO NewOrders;")
  9. // a string array: ["NewOrders"]
  10. val tables = tableEnv.listTables()
  11. // or tableEnv.executeSql("SHOW TABLES").print()

Python

  1. table_env = TableEnvironment.create(...)
  2. # a string array: ["Orders"]
  3. tables = table_env.list_tables()
  4. # or table_env.execute_sql("SHOW TABLES").print()
  5. # rename "Orders" to "NewOrders"
  6. table_env.execute_sql("ALTER TABLE Orders RENAME TO NewOrders;")
  7. # a string array: ["NewOrders"]
  8. tables = table_env.list_tables()
  9. # or table_env.execute_sql("SHOW TABLES").print()

SQL CLI

  1. Flink SQL> CREATE TABLE Orders (`user` BIGINT, product STRING, amount INT) WITH (...);
  2. [INFO] Table has been created.
  3. Flink SQL> SHOW TABLES;
  4. Orders
  5. Flink SQL> ALTER TABLE Orders RENAME TO NewOrders;
  6. [INFO] Table has been removed.
  7. Flink SQL> SHOW TABLES;
  8. NewOrders

ALTER TABLE

  • Rename Table
  1. ALTER TABLE [catalog_name.][db_name.]table_name RENAME TO new_table_name

Rename the given table name to another new table name.

  • Set or Alter Table Properties
  1. ALTER TABLE [catalog_name.][db_name.]table_name SET (key1=val1, key2=val2, ...)

Set one or more properties in the specified table. If a particular property is already set in the table, override the old value with the new one.

ALTER VIEW

  1. ALTER VIEW [catalog_name.][db_name.]view_name RENAME TO new_view_name

Renames a given view to a new name within the same catalog and database.

  1. ALTER VIEW [catalog_name.][db_name.]view_name AS new_query_expression

Changes the underlying query defining the given view to a new query.

ALTER DATABASE

  1. ALTER DATABASE [catalog_name.]db_name SET (key1=val1, key2=val2, ...)

Set one or more properties in the specified database. If a particular property is already set in the database, override the old value with the new one.

ALTER FUNCTION

  1. ALTER [TEMPORARY|TEMPORARY SYSTEM] FUNCTION
  2. [IF EXISTS] [catalog_name.][db_name.]function_name
  3. AS identifier [LANGUAGE JAVA|SCALA|PYTHON]

Alter a catalog function with the new identifier and optional language tag. If a function doesn’t exist in the catalog, an exception is thrown.

If the language tag is JAVA/SCALA, the identifier is the full classpath of the UDF. For the implementation of Java/Scala UDF, please refer to User-defined Functions for more details.

If the language tag is PYTHON, the identifier is the fully qualified name of the UDF, e.g. pyflink.table.tests.test_udf.add. For the implementation of Python UDF, please refer to Python UDFs for more details.

TEMPORARY

Alter temporary catalog function that has catalog and database namespaces and overrides catalog functions.

TEMPORARY SYSTEM

Alter temporary system function that has no namespace and overrides built-in functions

IF EXISTS

If the function doesn’t exist, nothing happens.

LANGUAGE JAVA|SCALA|PYTHON

Language tag to instruct flink runtime how to execute the function. Currently only JAVA, SCALA and PYTHON are supported, the default language for a function is JAVA.