After a data table is created, you can execute fast modeling language (FML) statements in the code editor of the table to configure fields and partitions for the table. This topic describes how to use FML statements to configure a data table.
Prerequisites
- For more information about how to create a dimension table, see Create a dimension table.
- For more information about how to create a fact table, see Create a fact table.
- For more information about how to create an aggregate table, see Create an aggregate table.
Background information
Limits
- In DataWorks, FML statements cannot be used to create data tables or change the names of data tables. You can use FML statements only to perform other configuration operations on data tables. For example, you can use FML statements to configure table fields, configure table associations, and configure table partitions.
- In DataWorks, you can use FML statements to materialize data tables only to MaxCompute, Hologres, or Hive.
- FML statements use SQL keywords as reserved words. If the name of your data table
or the name of a field in the data table contains the keywords, you must enclose the
name in a pair of grave accents (
`
) to escape the name. Otherwise, an error is reported when you configure the table.
Go to the Script Mode panel of a data table
Configure a data table
In DataWorks, FML statements cannot be used to create data tables. However, when you
configure a data table in FML, you must configure the related parameters in the
CREATE TABLE
statement. This helps you obtain all the configurations of the data table. When you
configure a data table, you need to refer only to the content that defines the table,
such as the constraints and partitions, in the CREATE TABLE syntax. The following
CREATE TABLE syntax shows how to configure a data table: -- Configure a table.
CREATE <table_type> TABLE
IF NOT EXISTS
-- Specify the table name.
<table_name> [ALIAS <alias>]
-- Define field attributes.
<col_name> [ALIAS <alias>] <datatype> [<category>] [COMMENT <comment>] [WITH (<key>=<value>,....)]
-- Define constraints.
PRIMARY KEY (<col_name>),
-- Dimension constraint
CONSTRAINT <constraint_name> DIM KEY (<col_name>) REFERENCES <ref_table_name> (<ref_table_col_name>),
-- Hierarchy constraint
CONSTRAINT <constraint_name> LEVEL <col_name:(<col_name>)>,
CONSTRAINT <constraint_name> COLUMN_GROUP(<col_name>,...),
-- Specify the comment for the table.
COMMENT 'comment'
-- Define partitions.
PARTITION BY (col DATATYPE COMMENT 'comment' WITH ('key'='value',...), ...)
-- Define other attributes.
WITH ('key'='value', 'key1'='value1', ...)
;
tableType
: dimDetailType? DIM
| factDetailType? FACT
| CODE
| DWS
;
dimDetailType
: NORMAL
| LEVEL
| ENUM
;
factDetailType
: TRANSACTION
| AGGREGATE
| PERIODIC_SNAPSHOT
| ACCUMULATING_SNAPSHOT
| CONSOLIDATED
;
comment
: COMMENT 'comment'
;
Parameter | Description |
---|---|
table_name | The name of the table. The name can be a maximum of 128 characters in length and can contain letters, digits, and underscores (_). |
IF NOT EXISTS | When you create a table, if you specify IF NOT EXISTS , the table can be created regardless of whether a table with the same name exists
in the big data engine that you select. If a table with the same name exists, this
table is replaced by the new table. If you do not specify IF NOT EXISTS , the table fails to be created when a table with the same name exists in the big
data engine that you select.
|
alias | The alias of the table or a field in the table. For a data table, this parameter specifies the display name of the table. This parameter is optional. |
table_type | The type of the table. The following types of tables are supported:
|
comment | The comment for the table. The value of this parameter can be a maximum of 1,024 characters in length. |
columnDefinition | The definitions of fields in the table. The following parameters can be contained:
Note FML statements allow you to materialize tables after the tables are designed. Therefore,
new tables can contain no fields.
|
constraint | The constraints of the table schema. You can define the following types of constraints:
|
PARTITION BY | The partitions of the table. |
WITH | The custom attributes of the table. Configure each attribute in the 'key'='value' format. Separate multiple attributes with commas (,). You must enclose each key and each value in a pair of single quotation marks (') to avoid conflicts between custom attributes
and FML keywords. The custom attributes that you configure in the WITH clause can be parsed and processed by the engine that is used to materialize FML
statements.
|