Paimon on Flink DDL Syntax
CREATE TABLE
Tables created within the Paimon Catalog are managed by the Catalog. When a table is deleted from the Catalog, its table files are also deleted.
Basic table creation statement (with the primary key):
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table (
user_id BIGINT,
item_id BIGINT,
behavior STRING,
dt STRING,
hh STRING,
PRIMARY KEY (dt, hh, user_id) NOT ENFORCED
); Partitioned table creation statement
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table (
user_id BIGINT,
item_id BIGINT,
behavior STRING,
dt STRING,
hh STRING,
PRIMARY KEY (dt, hh, user_id) NOT ENFORCED
) PARTITIONED BY (dt, hh); Statistics Mode
Paimon automatically collects statistics on data files to accelerate queries. It supports four modes:
- full: Collects complete metrics (null_count, min, and max).
- truncate(length): Collects null_count and truncated min/max values. The default value is truncate(16), which prevents excessive column size from bloating manifest files.
- counts: Collects only null_count.
- none: Disables metadata statistics collection.
The statistics collection mode is configured using metadata.stats-mode. The default value is truncate(16). You can configure it by field using fields.{field_name}.stats-mode.
In none mode, metadata.stats-dense-store defaults to true. This significantly reduces the manifest storage size but requires Paimon SDK 0.9.1 or later.
Field Default Value
Paimon supports setting default values for fields by configuring fields.{field_name}.default-value in the table properties. Note that default values cannot be set for partition fields and primary key fields.
CREATE TABLE AS SELECT (CTAS)
CTAS allows you to create and populate a table based on query results. For example, the statement CREATE TABLE table_b AS SELECT id, name FROM table_a is equivalent to creating a table and then inserting data into it.
/* Streaming mode requires checkpointing to be enabled. */
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table (
user_id BIGINT,
item_id BIGINT
);
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table_as AS SELECT * FROM lf_paimon_catalog.paimon_db.paimon_table; Partitioned table CTAS
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table (
user_id BIGINT,
item_id BIGINT,
behavior STRING,
dt STRING,
hh STRING
) PARTITIONED BY (dt, hh);
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table_as WITH ('partition' = 'dt') AS SELECT * FROM lf_paimon_catalog.paimon_db.paimon_table; CTAS with modified options
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table (
user_id BIGINT,
item_id BIGINT
) WITH ('file.format' = 'orc');
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table_as WITH ('file.format' = 'parquet') AS SELECT * FROM lf_paimon_catalog.paimon_db.paimon_table; Primary key CTAS
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table (
user_id BIGINT,
item_id BIGINT,
behavior STRING,
dt STRING,
hh STRING,
PRIMARY KEY (dt, hh, user_id) NOT ENFORCED
);
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table_as WITH ('primary-key' = 'dt,hh') AS SELECT * FROM lf_paimon_catalog.paimon_db.paimon_table; Primary key + partitioned CTAS
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table (
user_id BIGINT,
item_id BIGINT,
behavior STRING,
dt STRING,
hh STRING,
PRIMARY KEY (dt, hh, user_id) NOT ENFORCED
) PARTITIONED BY (dt, hh);
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table_as WITH ('primary-key' = 'dt,hh', 'partition' = 'dt') AS SELECT * FROM lf_paimon_catalog.paimon_db.paimon_table; CREATE TABLE LIKE
This statement creates a new table with the same schema, partitioning, and table properties as an existing table. Using EXCLUDING OPTIONS copies the schema but excludes the table properties.
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table (
user_id BIGINT,
item_id BIGINT,
behavior STRING,
dt STRING,
hh STRING,
PRIMARY KEY (dt, hh, user_id) NOT ENFORCED
);
CREATE TABLE lf_paimon_catalog.paimon_db.paimon_table_like LIKE lf_paimon_catalog.paimon_db.paimon_table (EXCLUDING OPTIONS); What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot