Create a logical model: Dimension table

更新时间:
复制 MD 格式

Dimensions are the foundation of dimensional modeling. In dimensional modeling, measurements are called 'facts', and the context that describes these facts is called 'dimensions'. A dimension table contains detailed information about specified attributes in a fact table. Common examples include date and city dimensions. This topic describes how to create a dimension table.

How it works

Based on your Data Domain plan, identify potential dimensions for data analysis within each business Data Domain. You then store these dimensions and their attributes in dimension tables. For example, when analyzing e-commerce data, you might identify dimensions and their attributes, such as an order dimension (with attributes like order ID, creation time, buyer ID, and seller ID), a user dimension (with attributes like gender and birthdate), and a product dimension (with attributes like product ID, name, and launch date). You can create corresponding order, user, and product dimension tables, where each attribute becomes a field in the table. You can then deploy these dimension tables to your data warehouse and use an ETL process to store the actual dimension data according to the table definitions, making it readily available for business analysis.

image

As shown in the preceding figure:

  • When you create a dimension table:

    • You can specify the data warehouse layer where the dimension table's data is stored for analysis. Typically, a dimension table resides in the Common Layer, but it can also be placed in the Application Layer. By default, the Application Layer only allows the creation of application tables. If you need to create a dimension table in the Application Layer, you must create a new application layer and set its model type to Dimension or Dimension Table, Dimension. For more information, see Custom layers.

    • This helps you manage the dimension table from either the Data Domain or Data Mart perspective.

  • After you create a dimension table, you can add dimensions as its attributes and configure its associations and partitions. Use a unified column standard or lookup table for field settings to ensure attribute consistency across your entire Data Domain.

  • After the dimension table is configured:

    • You can materialize it to a storage engine for data analysis in a compute engine.

    • When you design Derived Metrics and Aggregate Tables, you can directly reference and use the fields from the dimension table.

Prerequisites

The Common Layer processes and integrates shared data to build unified, enterprise-wide dimension tables. The Application Layer uses this integrated data to build business-specific dimension tables that support personalized data development and transformation. You can create dimension tables in either layer based on your needs. The following table describes the prerequisites for each layer.

Data warehouse layer

Prerequisites

References

Common Layer

You must create a data warehouse layer in the Common Layer to contain the dimension table.

Define data warehouse layers

You must create a Data Domain to define the business perspective for the dimension table.

Data Domain

Application Layer

You must create a data warehouse layer in the Application Layer to contain the dimension table.

Define data warehouse layers

You must create a Data Mart to categorize the data that the dimension table serves.

Data Mart

Create a dimension table

  1. Log on to the DataWorks console. In the target region, click Data Development and O&M > Data Modeling in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Data Modeling.

  2. On the Data Modeling page, click Dimensional Modeling in the top menu bar to go to the Dimensional Modeling page.

  3. Create the dimension table.

    1. On the Dimensional Modeling page, hover over the 加号 icon and choose Logical Model > Create Dimension Table.

    2. Configure the basic properties of the dimension table.

      You can specify properties such as the data warehouse layer, Data Domain, Business Category, and Data Mart for the dimension table. After the table is created, you can find it listed under these entities. This topic uses the creation of a Common Layer dimension table as an example. The key parameters are described below.

      Parameter

      Description

      Data Layer

      Select the data warehouse layer for the dimension table. Different layers serve different purposes:

      • Common Layer: Stores processed and integrated shared data to build unified, enterprise-level dimension tables. If you select this layer, you must also specify a Data Domain. For more information about how to create a Data Domain, see Data Domain.

      • Application Layer: Builds business-specific dimension tables based on application requirements. If you select this layer, you must also specify a Data Mart. For more information about how to create a Data Mart, see Data Mart.

      Note

      By default, the Application Layer only allows the creation of application tables. To create a dimension table in the Application Layer, you need to create a new application layer and set its model type to Dimension or Dimension Table, Dimension. For more information, see Custom layers.

      Business Category

      If the data warehouse layer is set to Common Layer, you can select the Business Category for the dimension table.

      Data Domain

      If you select Common Layer for the data warehouse layer, you can select the Data Domain for the dimension table.

      Category/Mart/Subject

      If you select Application Layer for the data warehouse layer, you must select a mart or theme under Business Category.

      Storage Policy

      The policy that defines how the dimension table stores data, including the retention period and data volume.

      Dimension

      The dimension to associate with the dimension table. This defines the perspective for data analysis.

      Note

      To create a dimension, see Create a conceptual model: Dimension.

      Naming Rule

      A checker that enforces naming conventions for the dimension table. If you select a checker, the Table Name must conform to its rules.

      Note

      To configure a checker, see Configure data warehouse layer checkers.

      Table Name

      The name of the dimension table. If you configured a naming rule, the name must comply with the rule.

      Table Display Name

      The display name of the dimension table.

      Lifecycle

      The retention period for the dimension table, in days. The maximum value is 36,000.

      Owner

      The owner of the dimension table. Defaults to the user who creates the table.

      Description

      A description of the dimension table.

  4. After you finish the configuration, click Save.

    You can find and manage the dimension table under its corresponding Data Domain or Business Category in the left-side navigation tree.

Add table fields

After the logical model is created, you must add fields to the table.

You can add fields in either Shortcut Mode or Script Mode. In Shortcut Mode, you can use the Import from Table/View feature to import fields from existing physical tables or views in a compute engine. Search for and select a table or view from the Find Existing Table/View drop-down list.

Quick mode

Note

Currently, you can only import from tables or views in MaxCompute, Hologres, and EMR Hive compute engines.

  1. In Shortcut Mode, click Expand next to Import from Table/View.

  2. In the Find Existing Table/View input box, enter a name to search for the table or view. After you select a table, you can choose to import all or some of its fields.

    Note
    • Fuzzy matching is supported. You can enter a keyword to search for all tables or views that contain the keyword in their names.

    • You can search for tables only in the production environment, not the development environment.

    • The 导入全部字段 icon indicates that all fields will be imported.

    • The 部分字段 icon indicates that only selected fields will be imported.

  3. If you choose to import only some fields, a dialog box appears displaying all fields from the selected table. Select the fields you want to add to the model, and then click Import.

  4. If an imported field has an empty Field Display Name, you are prompted to populate it with the field's description.

Code mode

Note

You can also use FML statements to create fields, associations, and partitions. For more information, see Modeling in Code Mode.

Code Mode allows you to create a dimension table by writing code. After you fill in the basic information and save the table, click Script Mode. A dialog box appears with auto-generated modeling code based on your configuration. You can modify the model in the code, and then click OK.

-- After the model is published, the table name cannot be modified, regardless of its publishing status (pre-approval, in progress, or successful).
CREATE DIM TABLE dim_ec_pub_department_df ALIAS 'Department dimension table'
(
    id            ALIAS 'id' STRING COMMENT 'id',
    gmt_create    ALIAS 'Creation time' TIMESTAMP COMMENT 'Creation time',
    gmt_modified ALIAS 'Modification time' TIMESTAMP COMMENT 'Modification time',
    name          ALIAS 'Department name' STRING COMMENT 'Department name',
    parent_id     ALIAS 'Parent department ID' STRING COMMENT 'Parent department ID',
    `level`       ALIAS 'Level' BIGINT COMMENT 'The department level. 0: Group, 1: Subsidiary, 2: Business Unit, 3: Department.',
    ds            ALIAS 'Business date, yyyymmdd' STRING COMMENT 'Business date, yyyymmdd'
)
COMMENT 'Department dimension table'
WITH('life_cycle'='1000');

Configure field information

After you add fields to the model, you can configure the Associated Field, Redundant Field, and Associated Granularity/Metric for each field based on your business requirements.

  1. Set field properties.

    By default, the field properties list displays basic attributes such as Field Name, Type, Field Display Name, Description, Primary Key, Not Null, Measurement Unit, and Actions. In the upper-right corner of the field list, click Field Display Settings to select which properties to display and modify them.

  2. Set the Field Standard to Associate and Lookup Table to Associate for the fields. This allows you to associate the added fields with a column standard and a lookup table, which standardizes their content and value ranges.

    Alternatively, after configuring the fields, you can click Associate in the upper-right corner of the field list to uniformly set the associated Atomic Metric, Lookup Table, and Field Standard.

    • Field Standard to Associate: Governs fields that have the same meaning but different names. It defines properties such as value range and unit of measurement.

    • Lookup Table to Associate: Defines the valid content and range of values for a specific column standard.

  3. Set the Redundant Field for the fields.

    In a traditional star schema, dimensions are stored in dimension tables and accessed through foreign keys in the fact table to reduce storage. In contrast, DataWorks' intelligent dimensional modeling encourages adding frequently used fields, such as a user ID or common analytical dimensions, as redundant fields. This practice improves downstream query performance, simplifies data retrieval, and reduces the number of table joins.

    Example 1: An "order creation detail table" can include the "shipping address" dimension from a "shipping address dimension table" as a redundant field, which contains attributes such as the recipient's address and phone number.

    Example 2: A "product dimension table" can include attributes such as "procurement information" and "brand information" from a "product information table" as redundant fields.

    In the Actions column for a specific field, click Redundant Field to configure its associated fields.

    In the Redundant field configuration dialog box, select the Associated table/view name, including the data source type and the specific table name. The field list below shows the available fields for association, with properties such as name, type, primary key, and partition. Select the associated field and click Save.

  4. After you finish the configuration, click Save in the upper-left corner.

Next steps

After you create the dimension table, you must also configure field management, associations, and partition settings. You must also publish the table to the target environment. For more information, see the following topics: