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-37121][docs] Fix syntax and examples in create table statement doc #25982

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions docs/content.zh/docs/dev/table/sql/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ Flink SQL> INSERT INTO RubberOrders SELECT product, amount FROM Orders WHERE pro
## CREATE TABLE

```text
CREATE TABLE [IF NOT EXISTS] [catalog_name.][db_name.]table_name
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] [catalog_name.][db_name.]table_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should include MATERIALIZED as well like this [TEMPORARY | MATERIALIZED ]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CREATE MATERIALIZED TABLE statement cannot have column definitions, and MATERIALIZED TABLE has a separate page for description, so I think this page is to create a normal table

Copy link
Contributor

@davidradl davidradl Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jiefei30 that makes sense - though it is strange to have 2 create table grammars described. I suggest some text to link to the materialized table grammar would be useful. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidradl I agree. I will add some text to link to the materialized table grammar and temporary table description

(
{ <physical_column_definition> | <metadata_column_definition> | <computed_column_definition> }[ , ...n]
[ <watermark_definition> ]
[ <table_constraint> ][ , ...n]
)
[COMMENT table_comment]
[PARTITIONED BY (partition_column_name1, partition_column_name2, ...)]
[ <distribution> ]
[PARTITIONED BY (partition_column_name1, partition_column_name2, ...)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why has this line been moved?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to parse a sql which DISTRIBUTION clause is after PARTITION clause will failed.And I checked create table in parserImpls.ftl. The DISTRIBUTION clause was defined before PARTITION clause.

WITH (key1=val1, key2=val2, ...)
[ LIKE source_table [( <like_options> )] | AS select_query ]

Expand Down Expand Up @@ -198,6 +198,18 @@ CREATE TABLE [IF NOT EXISTS] [catalog_name.][db_name.]table_name

根据指定的表名创建一个表,如果同名表已经在 catalog 中存在了,则无法注册。

有关 CREATE MATERIALIZED TABLE 语法请查看 [Materialized Table Statements]({{< ref "docs/dev/table/materialized-table/statements" >}}).

**TEMPORARY**

临时表通常保存于内存中并且仅在创建它们的 Flink 会话持续期间存在。

更多信息请查看 [Temporary vs Permanent tables]({{< ref "docs/dev/table/common" >}}#temporary-vs-permanent-tables).

**IF NOT EXISTS**

若该表已经存在,则不会进行任何操作。

### Columns

**Physical / Regular Columns**
Expand Down Expand Up @@ -288,7 +300,7 @@ CREATE TABLE MyTable (
`timestamp` BIGINT METADATA, -- part of the query-to-sink schema
`offset` BIGINT METADATA VIRTUAL, -- not part of the query-to-sink schema
`user_id` BIGINT,
`name` STRING,
`name` STRING
) WITH (
'connector' = 'kafka'
...
Expand Down Expand Up @@ -594,7 +606,7 @@ CREATE TABLE my_ctas_table (
desc STRING,
quantity DOUBLE,
cost AS price * quantity,
WATERMARK FOR order_time AS order_time - INTERVAL '5' SECOND,
WATERMARK FOR order_time AS order_time - INTERVAL '5' SECOND
) WITH (
'connector' = 'kafka',
...
Expand Down
21 changes: 17 additions & 4 deletions docs/content/docs/dev/table/sql/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ Flink SQL> INSERT INTO RubberOrders SELECT product, amount FROM Orders WHERE pro
The following grammar gives an overview about the available syntax:

```text
CREATE TABLE [IF NOT EXISTS] [catalog_name.][db_name.]table_name
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] [catalog_name.][db_name.]table_name
(
{ <physical_column_definition> | <metadata_column_definition> | <computed_column_definition> }[ , ...n]
[ <watermark_definition> ]
[ <table_constraint> ][ , ...n]
)
[COMMENT table_comment]
[PARTITIONED BY (partition_column_name1, partition_column_name2, ...)]
[ <distribution> ]
[PARTITIONED BY (partition_column_name1, partition_column_name2, ...)]
WITH (key1=val1, key2=val2, ...)
[ LIKE source_table [( <like_options> )] | AS select_query ]

Expand Down Expand Up @@ -197,6 +197,19 @@ CREATE TABLE [IF NOT EXISTS] [catalog_name.][db_name.]table_name
The statement above creates a table with the given name. If a table with the same name already exists
in the catalog, an exception is thrown.

For information about CREATE MATERIALIZED TABLE, please refer to [Materialized Table Statements]({{< ref "docs/dev/table/materialized-table/statements" >}}).

**TEMPORARY**

Temporary tables are always stored in memory and only exist for the duration of
the Flink session they are created within.

Check out more details at [Temporary vs Permanent tables]({{< ref "docs/dev/table/common" >}}#temporary-vs-permanent-tables).

**IF NOT EXISTS**

If the table already exists, nothing happens.

### Columns

**Physical / Regular Columns**
Expand Down Expand Up @@ -287,7 +300,7 @@ CREATE TABLE MyTable (
`timestamp` BIGINT METADATA, -- part of the query-to-sink schema
`offset` BIGINT METADATA VIRTUAL, -- not part of the query-to-sink schema
`user_id` BIGINT,
`name` STRING,
`name` STRING
) WITH (
'connector' = 'kafka'
...
Expand Down Expand Up @@ -594,7 +607,7 @@ CREATE TABLE my_ctas_table (
desc STRING,
quantity DOUBLE,
cost AS price * quantity,
WATERMARK FOR order_time AS order_time - INTERVAL '5' SECOND,
WATERMARK FOR order_time AS order_time - INTERVAL '5' SECOND
) WITH (
'connector' = 'kafka',
...
Expand Down