Flink SQL:CREATE Statements

CREATE Statements

CREATE statements are used to register a table/view/function into current or specified Catalog. A registered table/view/function can be used in SQL queries.
CREATE语句用于将表/视图/函数注册到当前或指定的目录中。注册的表/视图/函数可以用于SQL查询。

Flink SQL supports the following CREATE statements for now:
Flink SQL目前支持以下CREATE语句:

  • CREATE TABLE
  • CREATE CATALOG
  • CREATE DATABASE
  • CREATE VIEW
  • CREATE FUNCTION

Run a CREATE statement

Java
CREATE statements can be executed with the executeSql() method of the TableEnvironment. The executeSql() method returns ‘OK’ for a successful CREATE operation, otherwise will throw an exception.
CREATE语句可以使用TableEnvironment的executeSql()方法执行。executeSql()方法为成功的CREATE操作返回“OK”,否则将引发异常。

The following examples show how to run a CREATE statement in TableEnvironment.
以下示例演示如何在TableEnvironment中运行CREATE语句。

TableEnvironment tableEnv = TableEnvironment.create(...);

// SQL query with a registered table
// register a table named "Orders"
tableEnv.executeSql("CREATE TABLE Orders (`user` BIGINT, product STRING, amount INT) WITH (...)");
// run a SQL query on the Table and retrieve the result as a new Table
Table result = tableEnv.sqlQuery(
  "SELECT product, amount FROM Orders WHERE product LIKE '%Rubber%'");

// Execute insert SQL with a registered table
// register a TableSink
tableEnv.executeSql("CREATE TABLE RubberOrders(product STRING, amount INT) WITH (...)");
// run an insert SQL on the Table and emit the result to the TableSink
tableEnv.executeSql(
  "INSERT INTO RubberOrders SELECT product, amount FROM Orders WHERE product LIKE '%Rubber%'");

SQL CLI
CREATE statements can be executed in SQL CLI.
CREATE语句可以在SQL CLI中执行。

The following examples show how to run a CREATE statement in SQL CLI.
以下示例显示了如何在SQL CLI中运行CREATE语句。

Flink SQL> CREATE TABLE Orders (`user` BIGINT, product STRING, amount INT) WITH (...);
[INFO] Table has been created.

Flink SQL> CREATE TABLE RubberOrders (product STRING, amount INT) WITH (...);
[INFO] Table has been created.

Flink SQL> INSERT INTO RubberOrders SELECT product, amount FROM Orders WHERE product LIKE '%Rubber%';
[INFO] Submitting SQL update statement to the cluster...

CREATE TABLE

The following grammar gives an overview about the available syntax:
以下语法概述了可用语法:

CREATE 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, ...)]
  WITH (key1=val1, key2=val2, ...)
  [ LIKE source_table [( <like_options> )] ]
   
<physical_column_definition>:
  column_name column_type [ <column_constraint> ] [COMMENT column_comment]
  
<column_constraint>:
  [CONSTRAINT constraint_name] PRIMARY KEY NOT ENFORCED

<table_constraint>:
  [CONSTRAINT constraint_name] PRIMARY KEY (column_name, ...) NOT ENFORCED

<metadata_column_definition>:
  column_name column_type METADATA [ FROM metadata_key ] [ VIRTUAL ]

<computed_column_definition>:
  column_name AS computed_column_expression [COMMENT column_comment]

<watermark_definition>:
  WATERMARK FOR rowtime_column_name AS watermark_strategy_expression

<source_table>:
  [catalog_name.][db_name.]table_name

<like_options>:
{
   { INCLUDING | EXCLUDING } { ALL | CONSTRAINTS | PARTITIONS }
 | { INCLUDING | EXCLUDING | OVERWRITING } { GENERATED | OPTIONS | WATERMARKS } 
}[, ...]

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.
上面的语句创建了一个具有给定名称的表。如果目录中已存在同名表,则会引发异常。

Columns

Physical / Regular Columns
物理/常规列

Physical columns are regular columns known from databases. They define the names, the types, and the order of fields in the physical data. Thus, physical columns represent the payload that is read from and written to an external system. Connectors and formats use these columns (in the defined order) to configure themselves. Other kinds of columns can be declared between physical columns but will not influence the final physical schema.
物理列是数据库中已知的常规列。它们定义物理数据中字段的名称、类型和顺序。因此,物理列表示从外部系统读取和写入的有效载荷。Connectors和formats使用这些列(按定义的顺序)进行配置。其他类型的列可以在物理列之间声明,但不会影响最终的物理schema。

The following statement creates a table with only regular columns:
以下语句创建一个仅包含常规列的表:

CREATE TABLE MyTable (
  `user_id` BIGINT,
  `name` STRING
) WITH (
  ...
);

Metadata Columns

Metadata columns are an extension to the SQL standard and allow to access connector and/or format specific fields for every row of a table. A metadata column is indicated by the METADATA keyword. For example, a metadata column can be be used to read and write the timestamp from and to Kafka records for time-based operations. The connector and format documentation lists the available metadata fields for every component. However, declaring a metadata column in a table’s schema is optional.
元数据列是SQL标准的扩展,允许访问表中每一行的connector and/or format特定字段。元数据列由metadata关键字指示。例如,可以使用元数据列从Kafka记录中读取时间戳,并将时间戳写入Kafka,以进行基于时间的操作。connector and/or format文档列出了每个组件的可用元数据字段。但是,在表的schema中声明元数据列是可选的。

The following statement creates a table with an additional metadata column that references the metadata field timestamp:
以下语句创建了一个表,其中包含引用元数据字段时间戳的附加元数据列:

CREATE TABLE MyTable (
  `user_id` BIGINT,
  `name` STRING,
  `record_time` TIMESTAMP_LTZ(3) METADATA FROM 'timestamp'    -- reads and writes a Kafka record's timestamp
) WITH (
  'connector' = 'kafka'
  ...
);

Every metadata field is identified by a string-based key and has a documented data type. For example, the Kafka connector exposes a metadata field with key timestamp and data type TIMESTAMP_LTZ(3) that can be used for both reading and writing records.
每个元数据字段都由一个基于字符串的key标识,并具有一个记录的数据类型。例如,Kafka连接器公开了一个元数据字段,该字段的key是timestamp,数据类型是TIMESTAMP_LTZ(3),可以用于读取和写入记录。

In the example above, the metadata column record_time becomes part of the table’s schema and can be transformed and stored like a regular column:
在上面的示例中,元数据列record_time成为表schema的一部分,可以像常规列一样进行转换和存储:

INSERT INTO MyTable SELECT user_id, name, record_time + INTERVAL '1' SECOND FROM MyTable;

For convenience, the FROM clause can be omitted if the column name should be used as the identifying metadata key:
为方便起见,如果列名为标识元数据key,则可以省略FROM子句:

CREATE TABLE MyTable (
  `user_id` BIGINT,
  `name` STRING,
  `timestamp` TIMESTAMP_LTZ(3) METADATA    -- use column name as metadata key
) WITH (
  'connector' = 'kafka'
  ...
);

For convenience, the runtime will perform an explicit cast if the data type of the column differs from the data type of the metadata field. Of course, this requires that the two data types are compatible.
为了方便起见,如果列的数据类型与元数据字段的数据类型不同,运行时将执行显式转换。当然,这需要两种数据类型兼容。

CREATE TABLE MyTable (
  `user_id` BIGINT,
  `name` STRING,
  `timestamp` BIGINT METADATA    -- cast the timestamp as BIGINT
) WITH (
  'connector' = 'kafka'
  ...
);

By default, the planner assumes that a metadata column can be used for both reading and writing. However, in many cases an external system provides more read-only metadata fields than writable fields. Therefore, it is possible to exclude metadata columns from persisting using the VIRTUAL keyword.
默认情况下,planner假定元数据列可以用于读取和写入。然而,在许多情况下,外部系统提供的只读元数据字段多于可写字段。因此,可以使用VIRTUAL关键字排除元数据列的持久化。

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,
) WITH (
  'connector' = 'kafka'
  ...
);

In the example above, the offset is a read-only metadata column and excluded from the query-to-sink schema. Thus, source-to-query schema (for SELECT) and query-to-sink (for INSERT INTO) schema differ:
在上面的示例中,偏移量是一个只读元数据列,并从query-to-sink schema中排除。因此,source-to-query schema(for SELECT) 和query-to-sink (for INSERT INTO) schema 不同:

source-to-query schema:
MyTable(`timestamp` BIGINT, `offset` BIGINT, `user_id` BIGINT, `name` STRING)

query-to-sink schema:
MyTable(`timestamp` BIGINT, `user_id` BIGINT, `name` STRING)

Computed Columns

Computed columns are virtual columns that are generated using the syntax column_name AS computed_column_expression.
计算列是使用语法column_name AS Computed_column_expression生成的虚拟列。

A computed column evaluates an expression that can reference other columns declared in the same table. Both physical columns and metadata columns can be accessed. The column itself is not physically stored within the table. The column’s data type is derived automatically from the given expression and does not have to be declared manually.
计算列计算表达式可以引用同一表中声明的其他列。可以访问物理列和元数据列。列本身并不物理存储在表中。列的数据类型是从给定表达式自动派生的,不必手动声明。

The planner will transform computed columns into a regular projection after the source. For optimization or watermark strategy push down, the evaluation might be spread across operators, performed multiple times, or skipped if not needed for the given query.
planner将计算列转换为source之后的常规投影。对于优化或水印策略下推,评估可以跨operators进行,多次执行,或者在给定查询不需要时跳过。

For example, a computed column could be defined as:
例如,计算列可以定义为:

CREATE TABLE MyTable (
  `user_id` BIGINT,
  `price` DOUBLE,
  `quantity` DOUBLE,
  `cost` AS price * quanitity,  -- evaluate expression and supply the result to queries
) WITH (
  'connector' = 'kafka'
  ...
);

The expression may contain any combination of columns, constants, or functions. The expression cannot contain a subquery.
表达式可以包含列、常量或函数的任意组合。表达式不能包含子查询。

Computed columns are commonly used in Flink for defining time attributes in CREATE TABLE statements.
Flink中通常使用计算列来定义CREATE TABLE语句中的时间属性。

  • A processing time attribute can be defined easily via proc AS PROCTIME() using the system’s PROCTIME() function.
    使用系统的PROCTIME()函数,可以通过proc AS PROCTIME()轻松定义处理时间属性。
  • An event time attribute timestamp can be pre-processed before the WATERMARK declaration. For example, the computed column can be used if the original field is not TIMESTAMP(3) type or is nested in a JSON string.
    可以在WATERMARK声明之前预处理事件时间属性时间戳。例如,如果原始字段不是TIMESTAMP()类型或嵌套在JSON字符串中,则可以使用计算列。

Similar to virtual metadata columns, computed columns are excluded from persisting. Therefore, a computed column cannot be the target of an INSERT INTO statement. Thus, source-to-query schema (for SELECT) and query-to-sink (for INSERT INTO) schema differ:
与虚拟元数据列类似,计算列被排除在持久化之外。因此,计算列不能是INSERT INTO语句的目标。因此,source-to-query schema (for SELECT)和query-to-sink (for INSERT INTO) schema不同:

source-to-query schema:
MyTable(`user_id` BIGINT, `price` DOUBLE, `quantity` DOUBLE, `cost` DOUBLE)

query-to-sink schema:
MyTable(`user_id` BIGINT, `price` DOUBLE, `quantity` DOUBLE)

WATERMARK

The WATERMARK clause defines the event time attributes of a table and takes the form WATERMARK FOR rowtime_column_name AS watermark_strategy_expression.
WATERMARK子句定义表的事件时间属性,并采用WATERMARK FOR rowtime_column_name AS watermark_strategy_expression的形式。

The rowtime_column_name defines an existing column that is marked as the event time attribute of the table. The column must be of type TIMESTAMP(3) and be a top-level column in the schema. It may be a computed column.
rowtime_column_name定义了一个标记为表的事件时间属性的现有列。该列必须是TIMESTAMP(3)类型,并且是schema中的顶级列。它可能是一个计算列。

The watermark_strategy_expression defines the watermark generation strategy. It allows arbitrary non-query expression, including computed columns, to calculate the watermark. The expression return type must be TIMESTAMP(3), which represents the timestamp since the Epoch. The returned watermark will be emitted only if it is non-null and its value is larger than the previously emitted local watermark (to preserve the contract of ascending watermarks). The watermark generation expression is evaluated by the framework for every record. The framework will periodically emit the largest generated watermark. If the current watermark is still identical to the previous one, or is null, or the value of the returned watermark is smaller than that of the last emitted one, then no new watermark will be emitted. Watermark is emitted in an interval defined by pipeline.auto-watermark-interval configuration. If watermark interval is 0ms, the generated watermarks will be emitted per-record if it is not null and greater than the last emitted one.
watermark_strategy_expression定义了水印生成策略。它允许任意非查询表达式(包括计算列)计算水印。表达式返回类型必须是TIMESTAMP(3),它表示自Epoch以来的时间戳。只有当返回的水印为非空且其值大于先前发出的本地水印时,才会发出该水印(以保留升序水印的契约)。水印生成表达式由每个记录的框架评估。该框架将定期发出生成的最大水印。如果当前水印仍然与前一个水印相同,或为空,或者返回的水印的值小于上次发出的水印,则不会发出新的水印。水印以pipeline.auto-watermark-interval配置定义的间隔发出。如果水印间隔为0ms,且生成的水印不为空且大于上次发出的水印,则将按每条记录发出水印。

When using event time semantics, tables must contain an event time attribute and watermarking strategy.
使用事件时间语义时,表必须包含事件时间属性和水印策略。

Flink provides several commonly used watermark strategies.
Flink提供了几种常用的水印策略。

  • Strictly ascending timestamps: WATERMARK FOR rowtime_column AS rowtime_column.
    Emits a watermark of the maximum observed timestamp so far. Rows that have a timestamp bigger to the max timestamp are not late.
    严格升序时间戳:WATERMARK FOR rowtime_column AS rowtime_column。
    发出迄今为止观察到的最大时间戳的水印。时间戳大于最大时间戳的行不会延迟。
  • Ascending timestamps: WATERMARK FOR rowtime_column AS rowtime_column - INTERVAL ‘0.001’ SECOND.
    Emits a watermark of the maximum observed timestamp so far minus 1. Rows that have a timestamp bigger or equal to the max timestamp are not late.
    升序时间戳:WATERMARK FOR rowtime_column AS rowtime_column-INTERVAL“0.001”秒。
    发出迄今为止观察到的最大时间戳减去1的水印。时间戳大于或等于最大时间戳的行不会延迟。
  • Bounded out of orderness timestamps: WATERMARK FOR rowtime_column AS rowtime_column - INTERVAL ‘string’ timeUnit.
    Emits watermarks, which are the maximum observed timestamp minus the specified delay, e.g., WATERMARK FOR rowtime_column AS rowtime_column - INTERVAL ‘5’ SECOND is a 5 seconds delayed watermark strategy.
    有界的无序时间戳:WATERMARK FOR rowtime_column AS rowtime_column - INTERVAL ‘string’ timeUnit。
    发出水印,即观察到的最大时间戳减去指定的延迟,例如,WATERMARK FOR rowtime_column AS rowtime_column - INTERVAL ‘5’ SECOND是5秒延迟的水印策略。
CREATE TABLE Orders (
    `user` BIGINT,
    product STRING,
    order_time TIMESTAMP(3),
    WATERMARK FOR order_time AS order_time - INTERVAL '5' SECOND
) WITH ( . . . );

PRIMARY KEY

Primary key constraint is a hint for Flink to leverage for optimizations. It tells that a column or a set of columns of a table or a view are unique and they do not contain null. Neither of columns in a primary can be nullable. Primary key therefore uniquely identify a row in a table.
主键约束是Flink用于优化的提示。它表示表或视图的一列或一组列是唯一的,并且它们不包含null。主列中的任何列都不能为空。因此,主键唯一地标识表中的行。

Primary key constraint can be either declared along with a column definition (a column constraint) or as a single line (a table constraint). For both cases, it should only be declared as a singleton. If you define multiple primary key constraints at the same time, an exception would be thrown.
主键约束可以与列定义(列约束)一起声明,也可以单独声明(表约束)。对于这两种情况,它只应声明为单例。如果同时定义多个主键约束,则会引发异常。

Validity Check 有效性检查

SQL standard specifies that a constraint can either be ENFORCED or NOT ENFORCED. This controls if the constraint checks are performed on the incoming/outgoing data. Flink does not own the data therefore the only mode we want to support is the NOT ENFORCED mode. It is up to the user to ensure that the query enforces key integrity.
SQL标准指定约束可以是强制的,也可以是非强制的。这控制是否对传入/传出数据执行约束检查。Flink不拥有数据,因此我们希望支持的唯一模式是非强制模式。由用户来确保查询强制执行key完整性。

Flink will assume correctness of the primary key by assuming that the columns nullability is aligned with the columns in primary key. Connectors should ensure those are aligned.
Flink将通过假设列可为空性与主键中的列对齐来假设主键的正确性。Connectors应确保对齐。

Notes: In a CREATE TABLE statement, creating a primary key constraint will alter the columns nullability, that means, a column with primary key constraint is not nullable.
注意:在CREATE TABLE语句中,创建主键约束将改变列的可为空性,也就是说,具有主键约束的列不可为空。

PARTITIONED BY

Partition the created table by the specified columns. A directory is created for each partition if this table is used as a filesystem sink.
按指定列对创建的表进行分区。如果此表用作文件系统接收器,则会为每个分区创建一个directory。

WITH Options

Table properties used to create a table source/sink. The properties are usually used to find and create the underlying connector.
用于创建表source/sink的表属性。属性通常用于查找和创建基础connector。

The key and value of expression key1=val1 should both be string literal. See details in Connect to External Systems for all the supported table properties of different connectors.
表达式key1=val1的key和value都应该是字符串文字。有关不同连接器所有支持的表属性,请参见Connect to External Systems中的详细信息。

Notes: The table name can be of three formats: 1. catalog_name.db_name.table_name 2. db_name.table_name 3. table_name. For catalog_name.db_name.table_name, the table would be registered into metastore with catalog named “catalog_name” and database named “db_name”; for db_name.table_name, the table would be registered into the current catalog of the execution table environment and database named “db_name”; for table_name, the table would be registered into the current catalog and database of the execution table environment.
注意:表名可以有三种格式:1.catalog_name.db_name.table_name 2.db_name.table_name 3.table_name。对于catalog_name.db_name.table_name,该表将注册到元存储中,目录名为“catalog_name”,数据库名为“db_name”;对于db_name.table_name,该表将注册到的执行表环境的当前目录和名为“db_name”数据库中;对于table_name,该表将注册到执行表环境的当前目录和数据库中。

Notes: The table registered with CREATE TABLE statement can be used as both table source and table sink, we can not decide if it is used as a source or sink until it is referenced in the DMLs.
注意:使用CREATE TABLE语句注册的表可以用作table source and table sink,我们无法确定它是用作source or sink,除非它在DML中被引用。

LIKE

The LIKE clause is a variant/combination of SQL features (Feature T171, “LIKE clause in table definition” and Feature T173, “Extended LIKE clause in table definition”). The clause can be used to create a table based on a definition of an existing table. Additionally, users can extend the original table or exclude certain parts of it. In contrast to the SQL standard the clause must be defined at the top-level of a CREATE statement. That is because the clause applies to multiple parts of the definition and not only to the schema part.
LIKE子句是SQL功能的变体/组合(功能T171,“表定义中的LIKE语句”和功能T173,“表中的扩展LIKE”)。该子句可用于基于现有表的定义创建表。此外,用户可以扩展原始表或排除其中的某些部分。与SQL标准不同,该子句必须在CREATE语句的顶层定义。这是因为该子句适用于定义的多个部分,而不仅仅适用于schema部分。

You can use the clause to reuse (and potentially overwrite) certain connector properties or add watermarks to tables defined externally. For example, you can add a watermark to a table defined in Apache Hive.
您可以使用该子句复用(并可能覆盖)某些connector属性,或者向外部定义的表添加水印。例如,您可以向Apache Hive中定义的表添加水印。

Consider the example statement below:
考虑下面的示例语句:

CREATE TABLE Orders (
    `user` BIGINT,
    product STRING,
    order_time TIMESTAMP(3)
) WITH ( 
    'connector' = 'kafka',
    'scan.startup.mode' = 'earliest-offset'
);

CREATE TABLE Orders_with_watermark (
    -- Add watermark definition
    WATERMARK FOR order_time AS order_time - INTERVAL '5' SECOND 
) WITH (
    -- Overwrite the startup-mode
    'scan.startup.mode' = 'latest-offset'
)
LIKE Orders;

The resulting table Orders_with_watermark will be equivalent to a table created with a following statement:
生成的表Orders_with_watermark将等同于使用以下语句创建的表:

CREATE TABLE Orders_with_watermark (
    `user` BIGINT,
    product STRING,
    order_time TIMESTAMP(3),
    WATERMARK FOR order_time AS order_time - INTERVAL '5' SECOND 
) WITH (
    'connector' = 'kafka',
    'scan.startup.mode' = 'latest-offset'
);

The merging logic of table features can be controlled with like options.
表特征的合并逻辑可以用类似的选项控制。

You can control the merging behavior of:
您可以控制以下对象的合并行为:

  • CONSTRAINTS - constraints such as primary and unique keys
    CONSTRAINTS - 约束,如主键和唯一键
  • GENERATED - computed columns
    GENERATED - 计算列
  • METADATA - metadata columns
    METADATA - 元数据列
  • OPTIONS - connector options that describe connector and format properties
    OPTIONS - 描述connector and format属性的连接器选项
  • PARTITIONS - partition of the tables
    PARTITIONS - 表的分区
  • WATERMARKS - watermark declarations
    WATERMARKS - 水印声明

with three different merging strategies:
有三种不同的合并策略:

  • INCLUDING - Includes the feature of the source table, fails on duplicate entries, e.g. if an option with the same key exists in both tables.
    INCLUDING - 包括source表的功能,在重复条目时失败,例如,如果两个表中都存在具有相同key的选项。
  • EXCLUDING - Does not include the given feature of the source table.
    EXCLUDING - 不包括source表的给定功能。
  • OVERWRITING - Includes the feature of the source table, overwrites duplicate entries of the source table with properties of the new table, e.g. if an option with the same key exists in both tables, the one from the current statement will be used.
    OVERWRITING - 包括source表的功能,用新表的属性覆盖源表的重复条目,例如,如果两个表中都存在具有相同key的选项,则将使用当前语句中的选项。

Additionally, you can use the INCLUDING/EXCLUDING ALL option to specify what should be the strategy if there was no specific strategy defined, i.e. if you use EXCLUDING ALL INCLUDING WATERMARKS only the watermarks will be included from the source table.
此外,如果没有定义特定的策略,则可以使用INCLUDING/EXCLUDINNG ALL选项来指定应该是什么策略,例如,如果使用EXCLUDING ALL INCLUDING WATERMARKS,只有水印定义才会来自source表中。

Example:

-- A source table stored in a filesystem
CREATE TABLE Orders_in_file (
    `user` BIGINT,
    product STRING,
    order_time_string STRING,
    order_time AS to_timestamp(order_time)
    
)
PARTITIONED BY (`user`) 
WITH ( 
    'connector' = 'filesystem',
    'path' = '...'
);

-- A corresponding table we want to store in kafka
CREATE TABLE Orders_in_kafka (
    -- Add watermark definition
    WATERMARK FOR order_time AS order_time - INTERVAL '5' SECOND 
) WITH (
    'connector' = 'kafka',
    ...
)
LIKE Orders_in_file (
    -- Exclude everything besides the computed columns which we need to generate the watermark for.
    -- We do not want to have the partitions or filesystem options as those do not apply to kafka. 
    EXCLUDING ALL
    INCLUDING GENERATED
);

If you provide no like options, INCLUDING ALL OVERWRITING OPTIONS will be used as a default.
如果您没有提供类似的选项,将使用 INCLUDING ALL OVERWRITING OPTIONS作为默认选项。

NOTE You cannot control the behavior of merging physical columns. Those will be merged as if you applied the INCLUDING strategy.
注意:您无法控制合并物理列的行为。这些将被合并,就像您应用了INCLUDING策略一样。

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.
注:source_table可以是复合标识符。因此,它可以是来自不同目录或数据库的表:例如my_catalog.my_db.MyTable从目录MyCatalog和数据库my_db指定表MyTable;my_db.MyTable从当前目录和数据库my_db指定表MyTable。

CREATE CATALOG

CREATE CATALOG catalog_name
  WITH (key1=val1, key2=val2, ...)

Create a catalog with the given catalog properties. If a catalog with the same name already exists, an exception is thrown.
使用给定的目录特性创建目录。如果已存在同名目录,则会引发异常。

WITH OPTIONS

Catalog properties used to store extra information related to this catalog. The key and value of expression key1=val1 should both be string literal.
用于存储与此目录相关的额外信息的目录属性。表达式key1=val1的key和value都应该是字符串文字。

Check out more details at Catalogs.
查看目录中的更多详细信息。

CREATE DATABASE

CREATE DATABASE [IF NOT EXISTS] [catalog_name.]db_name
  [COMMENT database_comment]
  WITH (key1=val1, key2=val2, ...)

Create a database with the given database properties. If a database with the same name already exists in the catalog, an exception is thrown.
使用给定的数据库属性创建数据库。如果目录中已存在同名数据库,则会引发异常。

IF NOT EXISTS

If the database already exists, nothing happens.
如果数据库已经存在,则不会发生任何事情。

WITH OPTIONS

Database properties used to store extra information related to this database. The key and value of expression key1=val1 should both be string literal.
用于存储与此数据库相关的额外信息的数据库属性。表达式key1=val1的key和value都应该是字符串文字。

CREATE VIEW

CREATE [TEMPORARY] VIEW [IF NOT EXISTS] [catalog_name.][db_name.]view_name
  [( columnName [, columnName ]* )] [COMMENT view_comment]
  AS query_expression

Create a view with the given query expression. If a view with the same name already exists in the catalog, an exception is thrown.
使用给定的查询表达式创建视图。如果目录中已存在同名视图,则会引发异常。

TEMPORARY

Create temporary view that has catalog and database namespaces and overrides views.
创建具有目录和数据库名称空间并覆盖视图的临时视图。

IF NOT EXISTS

If the view already exists, nothing happens.
如果视图已经存在,则不会发生任何事情。

CREATE FUNCTION

CREATE [TEMPORARY|TEMPORARY SYSTEM] FUNCTION 
  [IF NOT EXISTS] [catalog_name.][db_name.]function_name 
  AS identifier [LANGUAGE JAVA|SCALA|PYTHON]

Create a catalog function that has catalog and database namespaces with the identifier and optional language tag. If a function with the same name already exists 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.
如果语言标记是JAVA/SCALA,则标识符是UDF的完整类路径。有关Java/Scala UDF的实现,请参阅用户定义函数以了解更多详细信息。

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.
如果语言标记是PYTHON,则标识符是UDF的完全限定名,例如pyflink.table.tests.test_udf.add。有关Python UDF的实现,请参阅PythonUDF以了解更多详细信息。

If the language tag is PYTHON, however the current program is written in Java/Scala or pure SQL, then you need to configure the Python dependencies.
如果语言标记是PYTHON,但是当前的程序是用Java/Scala或纯SQL编写的,那么您需要配置PYTHON依赖项。

TEMPORARY

Create temporary catalog function that has catalog and database namespaces and overrides catalog functions.
创建具有目录和数据库名称空间并覆盖目录函数的临时目录函数。

TEMPORARY SYSTEM

Create temporary system function that has no namespace and overrides built-in functions
创建没有名称空间并覆盖内置函数的临时系统函数

IF NOT EXISTS

If the function already exists, 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.
指示Flinkruntime如何执行函数的语言标记。目前只支持JAVA、SCALA和PYTHON,函数的默认语言是JAVA。

你可能感兴趣的:(flink官方文档翻译-SQL,sql,flink,数据库)