Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-35164][table] Support ALTER CATALOG RESET syntax #24763

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions docs/content.zh/docs/dev/table/sql/alter.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ under the License.



ALTER 语句用于修改一个已经在 [Catalog]({{< ref "docs/dev/table/catalogs" >}}) 中注册的表、视图或函数定义。
ALTER 语句用于修改一个已经在 [Catalog]({{< ref "docs/dev/table/catalogs" >}}) 中注册的表、视图或函数定义,或 catalog 本身的定义

Flink SQL 目前支持以下 ALTER 语句:

- ALTER TABLE
- ALTER VIEW
- ALTER DATABASE
- ALTER FUNCTION
- ALTER CATALOG

## 执行 ALTER 语句

Expand Down Expand Up @@ -538,10 +539,14 @@ ALTER [TEMPORARY|TEMPORARY SYSTEM] FUNCTION

Language tag 用于指定 Flink runtime 如何执行这个函数。目前,只支持 JAVA,SCALA 和 PYTHON,且函数的默认语言为 JAVA。

{{< top >}}

## ALTER CATALOG

```sql
ALTER CATALOG catalog_name SET (key1=val1, ...)
ALTER CATALOG catalog_name
SET (key1=val1, ...)
| RESET (key1, ...)
```

### SET
Expand All @@ -555,4 +560,15 @@ ALTER CATALOG catalog_name SET (key1=val1, ...)
ALTER CATALOG cat2 SET ('default-database'='db');
```

### RESET

为指定的 catalog 重置一个或多个属性。

`RESET` 语句示例如下。

```sql
-- reset 'default-database'
ALTER CATALOG cat2 RESET ('default-database');
```

{{< top >}}
20 changes: 18 additions & 2 deletions docs/content/docs/dev/table/sql/alter.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ under the License.



ALTER statements are used to modified a registered table/view/function definition in the [Catalog]({{< ref "docs/dev/table/catalogs" >}}).
ALTER statements are used to modify the definition of a table, view or function that has already been registered in the [Catalog]({{< ref "docs/dev/table/catalogs" >}}), or the definition of a catalog itself.

Flink SQL supports the following ALTER statements for now:

- ALTER TABLE
- ALTER VIEW
- ALTER DATABASE
- ALTER FUNCTION
- ALTER CATALOG

## Run an ALTER statement

Expand Down Expand Up @@ -540,10 +541,14 @@ If the function doesn't exist, nothing happens.

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.

{{< top >}}

## ALTER CATALOG

```sql
ALTER CATALOG catalog_name SET (key1=val1, ...)
ALTER CATALOG catalog_name
SET (key1=val1, ...)
| RESET (key1, ...)
```

### SET
Expand All @@ -557,4 +562,15 @@ The following examples illustrate the usage of the `SET` statements.
ALTER CATALOG cat2 SET ('default-database'='db');
```

### RESET

Reset one or more properties to its default value in the specified catalog.

The following examples illustrate the usage of the `RESET` statements.

```sql
-- reset 'default-database'
ALTER CATALOG cat2 RESET ('default-database');
```

{{< top >}}
187 changes: 104 additions & 83 deletions flink-table/flink-sql-client/src/test/resources/sql/catalog_database.q
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,110 @@ drop catalog c1;
org.apache.flink.table.catalog.exceptions.CatalogException: Cannot drop a catalog which is currently in use.
!error

create catalog cat2 WITH ('type'='generic_in_memory', 'default-database'='db');
[INFO] Execute statement succeeded.
!info

show create catalog cat2;
+---------------------------------------------------------------------------------------------+
| result |
+---------------------------------------------------------------------------------------------+
| CREATE CATALOG `cat2` WITH (
'default-database' = 'db',
'type' = 'generic_in_memory'
)
|
+---------------------------------------------------------------------------------------------+
1 row in set
!ok

describe catalog cat2;
+-----------+-------------------+
| info name | info value |
+-----------+-------------------+
| name | cat2 |
| type | generic_in_memory |
| comment | |
+-----------+-------------------+
3 rows in set
!ok

describe catalog extended cat2;
+-------------------------+-------------------+
| info name | info value |
+-------------------------+-------------------+
| name | cat2 |
| type | generic_in_memory |
| comment | |
| option:default-database | db |
+-------------------------+-------------------+
4 rows in set
!ok

desc catalog cat2;
+-----------+-------------------+
| info name | info value |
+-----------+-------------------+
| name | cat2 |
| type | generic_in_memory |
| comment | |
+-----------+-------------------+
3 rows in set
!ok

desc catalog extended cat2;
+-------------------------+-------------------+
| info name | info value |
+-------------------------+-------------------+
| name | cat2 |
| type | generic_in_memory |
| comment | |
| option:default-database | db |
+-------------------------+-------------------+
4 rows in set
!ok

alter catalog cat2 set ('default-database'='db_new');
[INFO] Execute statement succeeded.
!info

desc catalog extended cat2;
+-------------------------+-------------------+
| info name | info value |
+-------------------------+-------------------+
| name | cat2 |
| type | generic_in_memory |
| comment | |
| option:default-database | db_new |
+-------------------------+-------------------+
4 rows in set
!ok

alter catalog cat2 reset ('default-database', 'k1');
[INFO] Execute statement succeeded.
!info

desc catalog extended cat2;
+-----------+-------------------+
| info name | info value |
+-----------+-------------------+
| name | cat2 |
| type | generic_in_memory |
| comment | |
+-----------+-------------------+
3 rows in set
!ok

alter catalog cat2 reset ('type');
[ERROR] Could not execute SQL statement. Reason:
org.apache.flink.table.api.ValidationException: ALTER CATALOG RESET does not support changing 'type'
!error

alter catalog cat2 reset ();
[ERROR] Could not execute SQL statement. Reason:
org.apache.flink.table.api.ValidationException: ALTER CATALOG RESET does not support empty key
!error

# ==========================================================================
# test database
# ==========================================================================
Expand Down Expand Up @@ -686,86 +790,3 @@ show tables from db1 like 'p_r%';
+------------+
1 row in set
!ok

# ==========================================================================
# test catalog
# ==========================================================================

create catalog cat2 WITH ('type'='generic_in_memory', 'default-database'='db');
[INFO] Execute statement succeeded.
!info

show create catalog cat2;
+---------------------------------------------------------------------------------------------+
| result |
+---------------------------------------------------------------------------------------------+
| CREATE CATALOG `cat2` WITH (
'default-database' = 'db',
'type' = 'generic_in_memory'
)
|
+---------------------------------------------------------------------------------------------+
1 row in set
!ok

describe catalog cat2;
+-----------+-------------------+
| info name | info value |
+-----------+-------------------+
| name | cat2 |
| type | generic_in_memory |
| comment | |
+-----------+-------------------+
3 rows in set
!ok

describe catalog extended cat2;
+-------------------------+-------------------+
| info name | info value |
+-------------------------+-------------------+
| name | cat2 |
| type | generic_in_memory |
| comment | |
| option:default-database | db |
+-------------------------+-------------------+
4 rows in set
!ok

desc catalog cat2;
+-----------+-------------------+
| info name | info value |
+-----------+-------------------+
| name | cat2 |
| type | generic_in_memory |
| comment | |
+-----------+-------------------+
3 rows in set
!ok

desc catalog extended cat2;
+-------------------------+-------------------+
| info name | info value |
+-------------------------+-------------------+
| name | cat2 |
| type | generic_in_memory |
| comment | |
| option:default-database | db |
+-------------------------+-------------------+
4 rows in set
!ok

alter catalog cat2 set ('default-database'='db_new');
[INFO] Execute statement succeeded.
!info

desc catalog extended cat2;
+-------------------------+-------------------+
| info name | info value |
+-------------------------+-------------------+
| name | cat2 |
| type | generic_in_memory |
| comment | |
| option:default-database | db_new |
+-------------------------+-------------------+
4 rows in set
!ok