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
A data table is created by using the codeless user interface (UI). In DataWorks, FML statements cannot be used to create data tables.
For more information about how to create a dimension table, see Create a logical model: dimension table.
For more information about how to create a fact table, see Create a logical model: fact table.
For more information about how to create an aggregate table, see Create a logical model: aggregate table.
Background information
FML is an SQL-like language that is used to design data tables for dimensional modeling. FML statements use the standard SQL-like syntax. The design and materialization of a DataWorks data model (logical table) are decoupled. During the design of a logical table, you do not need to consider the materialization of the logical table on each underlying big data engine. The modeling engine drives the operations of each underlying big data engine based on the table schema defined by FML. During the materialization of the logical table, the modeling engine converts the logical table into a physical table for the underlying big data engine that you specify. During the conversion, the modeling engine converts FML statements for the logical table into SQL statements that can be identified by the specified big data engine and commits and executes the SQL statements.
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
In the left-side navigation tree of the Dimensional Modeling page, double-click the name of a data table.
In the Field Management section of the configuration tab of the table, click Script Mode.
In the code editor of the Script Mode panel, you can view the FML CREATE TABLE statement for the table. You can also configure fields for the table or modify existing fields in the table. For more information, see Configure 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 |
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 |