lsyldliu commented on code in PR #20653: URL: https://github.com/apache/flink/pull/20653#discussion_r962589785
########## docs/content/docs/dev/table/sql/create.md: ########## @@ -155,7 +155,7 @@ CREATE TABLE [IF NOT EXISTS] [catalog_name.][db_name.]table_name [COMMENT table_comment] [PARTITIONED BY (partition_column_name1, partition_column_name2, ...)] WITH (key1=val1, key2=val2, ...) - [ LIKE source_table [( <like_options> )] ] + [ LIKE source_table [( <like_options> )] | AS query_expression ] Review Comment: Referring to https://nightlies.apache.org/flink/flink-docs-master/docs/dev/table/sql/queries/with/, I think we should unify the term in docs, using `select_query`. ########## docs/content/docs/dev/table/sql/create.md: ########## @@ -513,6 +513,46 @@ If you provide no like options, `INCLUDING ALL OVERWRITING OPTIONS` will be used **NOTE** The `source_table` can be a compound identifier. Thus, it can be a table from a different catalog or database: e.g. `my_catalog.my_db.MyTable` specifies table `MyTable` from catalog `MyCatalog` and database `my_db`; `my_db.MyTable` specifies table `MyTable` from current catalog and database `my_db`. +### `AS` + +The AS clause is a variation of SQL features (Feature T172, “AS subquery clause in table definition”). +The clause can be used to create a table based on the given query expression. It will be more user-friendly and reduce the cost for user to manually spell complex table creation statements. Review Comment: Reference: 1. https://docs.microsoft.com/en-us/azure/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-ctas#create-table-as-select 2. https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTableAsSelect(CTAS) Tables can also be created and populated by the results of a query in one create-table-as-select (CTAS) statement. CTAS is the simplest and fastest way to create and insert data into a table with a single command. There are two parts in CTAS, the SELECT part can be any [SELECT statement](https://nightlies.apache.org/flink/flink-docs-master/docs/dev/table/sql/queries/overview/) supported by Flink SQL. The CREATE part of the CTAS takes the resulting schema from the SELECT part and creates the target table with other table properties such as the connector and URL. Similar to CREATE TABLE, CTAS requires the required options of the corresponding connector must be specified in WITH clause. ########## docs/content/docs/dev/table/sql/create.md: ########## @@ -513,6 +513,46 @@ If you provide no like options, `INCLUDING ALL OVERWRITING OPTIONS` will be used **NOTE** The `source_table` can be a compound identifier. Thus, it can be a table from a different catalog or database: e.g. `my_catalog.my_db.MyTable` specifies table `MyTable` from catalog `MyCatalog` and database `my_db`; `my_db.MyTable` specifies table `MyTable` from current catalog and database `my_db`. +### `AS` + +The AS clause is a variation of SQL features (Feature T172, “AS subquery clause in table definition”). +The clause can be used to create a table based on the given query expression. It will be more user-friendly and reduce the cost for user to manually spell complex table creation statements. +You can use this clause in stream and batch mode. + +Consider the example statement below: + +```sql +CREATE TABLE ctas_hudi +WITH ( + 'connector' = 'hudi' +) +AS +SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +The resulting table `ctas_hudi` will be equivalent to create the table and insert the data with the following statement: +```sql +CREATE TABLE ctas_hudi ( + id BIGINT, + name STRING, + age INT +) WITH ( + 'connector' = 'hudi' +); + +INSERT INTO ctas_hudi SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +**Notes:** +* does not support to create temporary table yet. +* does not support to specify explicit columns yet. +* does not support to specify explicit watermark yet. Review Comment: ```suggestion * Does not support specifying explicit watermark yet. ``` ########## docs/content/docs/dev/table/sql/create.md: ########## @@ -513,6 +513,46 @@ If you provide no like options, `INCLUDING ALL OVERWRITING OPTIONS` will be used **NOTE** The `source_table` can be a compound identifier. Thus, it can be a table from a different catalog or database: e.g. `my_catalog.my_db.MyTable` specifies table `MyTable` from catalog `MyCatalog` and database `my_db`; `my_db.MyTable` specifies table `MyTable` from current catalog and database `my_db`. +### `AS` + +The AS clause is a variation of SQL features (Feature T172, “AS subquery clause in table definition”). +The clause can be used to create a table based on the given query expression. It will be more user-friendly and reduce the cost for user to manually spell complex table creation statements. +You can use this clause in stream and batch mode. + +Consider the example statement below: + +```sql +CREATE TABLE ctas_hudi +WITH ( + 'connector' = 'hudi' +) +AS +SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +The resulting table `ctas_hudi` will be equivalent to create the table and insert the data with the following statement: +```sql +CREATE TABLE ctas_hudi ( + id BIGINT, + name STRING, + age INT +) WITH ( + 'connector' = 'hudi' +); + +INSERT INTO ctas_hudi SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +**Notes:** +* does not support to create temporary table yet. +* does not support to specify explicit columns yet. +* does not support to specify explicit watermark yet. +* does not support to create partitioned table yet. +* does not support primary key constraints yet. + +**Notes:** Review Comment: ```suggestion **Note** The CTAS clause is currently non-atomicity and does not drop the target table when the job's final status is FAILED/CANCELED. ``` ########## docs/content/docs/dev/table/sql/create.md: ########## @@ -513,6 +513,46 @@ If you provide no like options, `INCLUDING ALL OVERWRITING OPTIONS` will be used **NOTE** The `source_table` can be a compound identifier. Thus, it can be a table from a different catalog or database: e.g. `my_catalog.my_db.MyTable` specifies table `MyTable` from catalog `MyCatalog` and database `my_db`; `my_db.MyTable` specifies table `MyTable` from current catalog and database `my_db`. +### `AS` + +The AS clause is a variation of SQL features (Feature T172, “AS subquery clause in table definition”). +The clause can be used to create a table based on the given query expression. It will be more user-friendly and reduce the cost for user to manually spell complex table creation statements. +You can use this clause in stream and batch mode. Review Comment: This is no need. ########## docs/content/docs/dev/table/sql/create.md: ########## @@ -513,6 +513,46 @@ If you provide no like options, `INCLUDING ALL OVERWRITING OPTIONS` will be used **NOTE** The `source_table` can be a compound identifier. Thus, it can be a table from a different catalog or database: e.g. `my_catalog.my_db.MyTable` specifies table `MyTable` from catalog `MyCatalog` and database `my_db`; `my_db.MyTable` specifies table `MyTable` from current catalog and database `my_db`. +### `AS` + +The AS clause is a variation of SQL features (Feature T172, “AS subquery clause in table definition”). +The clause can be used to create a table based on the given query expression. It will be more user-friendly and reduce the cost for user to manually spell complex table creation statements. +You can use this clause in stream and batch mode. + +Consider the example statement below: + +```sql +CREATE TABLE ctas_hudi +WITH ( + 'connector' = 'hudi' +) +AS +SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +The resulting table `ctas_hudi` will be equivalent to create the table and insert the data with the following statement: +```sql +CREATE TABLE ctas_hudi ( + id BIGINT, + name STRING, + age INT +) WITH ( + 'connector' = 'hudi' +); + +INSERT INTO ctas_hudi SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +**Notes:** Review Comment: ```suggestion **Note** CTAS has these restrictions: ``` ########## docs/content/docs/dev/table/sql/create.md: ########## @@ -513,6 +513,46 @@ If you provide no like options, `INCLUDING ALL OVERWRITING OPTIONS` will be used **NOTE** The `source_table` can be a compound identifier. Thus, it can be a table from a different catalog or database: e.g. `my_catalog.my_db.MyTable` specifies table `MyTable` from catalog `MyCatalog` and database `my_db`; `my_db.MyTable` specifies table `MyTable` from current catalog and database `my_db`. +### `AS` + +The AS clause is a variation of SQL features (Feature T172, “AS subquery clause in table definition”). +The clause can be used to create a table based on the given query expression. It will be more user-friendly and reduce the cost for user to manually spell complex table creation statements. +You can use this clause in stream and batch mode. + +Consider the example statement below: + +```sql +CREATE TABLE ctas_hudi +WITH ( + 'connector' = 'hudi' Review Comment: Please use the built-in jdbc connector and fill in the required options as examples, such as: ```sql WITH ( 'connector' = 'jdbc', 'url' = 'jdbc:mysql://mysqlhost:3306/customerdb', 'table-name' = 'customers' ) ``` ########## docs/content/docs/dev/table/sql/create.md: ########## @@ -513,6 +513,46 @@ If you provide no like options, `INCLUDING ALL OVERWRITING OPTIONS` will be used **NOTE** The `source_table` can be a compound identifier. Thus, it can be a table from a different catalog or database: e.g. `my_catalog.my_db.MyTable` specifies table `MyTable` from catalog `MyCatalog` and database `my_db`; `my_db.MyTable` specifies table `MyTable` from current catalog and database `my_db`. +### `AS` + +The AS clause is a variation of SQL features (Feature T172, “AS subquery clause in table definition”). +The clause can be used to create a table based on the given query expression. It will be more user-friendly and reduce the cost for user to manually spell complex table creation statements. +You can use this clause in stream and batch mode. + +Consider the example statement below: + +```sql +CREATE TABLE ctas_hudi +WITH ( + 'connector' = 'hudi' +) +AS +SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +The resulting table `ctas_hudi` will be equivalent to create the table and insert the data with the following statement: +```sql +CREATE TABLE ctas_hudi ( + id BIGINT, + name STRING, + age INT +) WITH ( + 'connector' = 'hudi' +); + +INSERT INTO ctas_hudi SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +**Notes:** +* does not support to create temporary table yet. Review Comment: ```suggestion * Does not support creating a temporary table yet. ``` ########## docs/content/docs/dev/table/sql/create.md: ########## @@ -513,6 +513,46 @@ If you provide no like options, `INCLUDING ALL OVERWRITING OPTIONS` will be used **NOTE** The `source_table` can be a compound identifier. Thus, it can be a table from a different catalog or database: e.g. `my_catalog.my_db.MyTable` specifies table `MyTable` from catalog `MyCatalog` and database `my_db`; `my_db.MyTable` specifies table `MyTable` from current catalog and database `my_db`. +### `AS` + +The AS clause is a variation of SQL features (Feature T172, “AS subquery clause in table definition”). +The clause can be used to create a table based on the given query expression. It will be more user-friendly and reduce the cost for user to manually spell complex table creation statements. +You can use this clause in stream and batch mode. + +Consider the example statement below: + +```sql +CREATE TABLE ctas_hudi +WITH ( + 'connector' = 'hudi' +) +AS +SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +The resulting table `ctas_hudi` will be equivalent to create the table and insert the data with the following statement: +```sql +CREATE TABLE ctas_hudi ( + id BIGINT, + name STRING, + age INT +) WITH ( + 'connector' = 'hudi' +); + +INSERT INTO ctas_hudi SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +**Notes:** +* does not support to create temporary table yet. +* does not support to specify explicit columns yet. +* does not support to specify explicit watermark yet. +* does not support to create partitioned table yet. Review Comment: ```suggestion * Does not support creating partitioned table yet. ``` ########## docs/content/docs/dev/table/sql/create.md: ########## @@ -513,6 +513,46 @@ If you provide no like options, `INCLUDING ALL OVERWRITING OPTIONS` will be used **NOTE** The `source_table` can be a compound identifier. Thus, it can be a table from a different catalog or database: e.g. `my_catalog.my_db.MyTable` specifies table `MyTable` from catalog `MyCatalog` and database `my_db`; `my_db.MyTable` specifies table `MyTable` from current catalog and database `my_db`. +### `AS` + +The AS clause is a variation of SQL features (Feature T172, “AS subquery clause in table definition”). +The clause can be used to create a table based on the given query expression. It will be more user-friendly and reduce the cost for user to manually spell complex table creation statements. +You can use this clause in stream and batch mode. + +Consider the example statement below: + +```sql +CREATE TABLE ctas_hudi +WITH ( + 'connector' = 'hudi' +) +AS +SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +The resulting table `ctas_hudi` will be equivalent to create the table and insert the data with the following statement: +```sql +CREATE TABLE ctas_hudi ( + id BIGINT, + name STRING, + age INT +) WITH ( + 'connector' = 'hudi' +); + +INSERT INTO ctas_hudi SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +**Notes:** +* does not support to create temporary table yet. +* does not support to specify explicit columns yet. Review Comment: ```suggestion * Does not support specifying explicit columns yet. ``` ########## docs/content/docs/dev/table/sql/create.md: ########## @@ -513,6 +513,46 @@ If you provide no like options, `INCLUDING ALL OVERWRITING OPTIONS` will be used **NOTE** The `source_table` can be a compound identifier. Thus, it can be a table from a different catalog or database: e.g. `my_catalog.my_db.MyTable` specifies table `MyTable` from catalog `MyCatalog` and database `my_db`; `my_db.MyTable` specifies table `MyTable` from current catalog and database `my_db`. +### `AS` + +The AS clause is a variation of SQL features (Feature T172, “AS subquery clause in table definition”). +The clause can be used to create a table based on the given query expression. It will be more user-friendly and reduce the cost for user to manually spell complex table creation statements. +You can use this clause in stream and batch mode. + +Consider the example statement below: + +```sql +CREATE TABLE ctas_hudi +WITH ( + 'connector' = 'hudi' +) +AS +SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +The resulting table `ctas_hudi` will be equivalent to create the table and insert the data with the following statement: +```sql +CREATE TABLE ctas_hudi ( + id BIGINT, + name STRING, + age INT +) WITH ( + 'connector' = 'hudi' +); + +INSERT INTO ctas_hudi SELECT id, name, age FROM test WHERE mod(id, 10) = 0; +``` + +**Notes:** +* does not support to create temporary table yet. +* does not support to specify explicit columns yet. +* does not support to specify explicit watermark yet. +* does not support to create partitioned table yet. +* does not support primary key constraints yet. Review Comment: ```suggestion * Does not support specifying primary key constraints yet. ``` ########## docs/content/docs/dev/table/sql/create.md: ########## @@ -155,7 +155,7 @@ CREATE TABLE [IF NOT EXISTS] [catalog_name.][db_name.]table_name [COMMENT table_comment] [PARTITIONED BY (partition_column_name1, partition_column_name2, ...)] WITH (key1=val1, key2=val2, ...) - [ LIKE source_table [( <like_options> )] ] + [ LIKE source_table [( <like_options> )] | AS query_expression ] Review Comment: Please also add some explanation about `select_query` after `like_options`: <select_query>: The table is populated using the data from the select statement. ########## docs/content.zh/docs/dev/table/sql/create.md: ########## @@ -513,6 +513,44 @@ LIKE Orders_in_file ( **注意:** 源表 `source_table` 可以是一个组合 ID。您可以指定不同 catalog 或者 DB 的表作为源表: 例如,`my_catalog.my_db.MyTable` 指定了源表 `MyTable` 来源于名为 `MyCatalog` 的 catalog 和名为 `my_db` 的 DB ,`my_db.MyTable` 指定了源表 `MyTable` 来源于当前 catalog 和名为 `my_db` 的 DB。 +### `AS` Review Comment: Ditto, same change with English docs -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org