Create a logical model: dimension table

Updated at:

Dimensions form the basis of dimensional modeling. A measure is called a fact, while the context that describes it is called a dimension. A dimension table contains details about specified attributes of a fact table. Common examples include date and city dimensions. This topic describes how to create a dimension table.

Overview

Based on the planned business data domains, identify dimensions that may be needed for data analysis in each domain, and store each dimension and its attributes in a dimension table. For example, in e-commerce analysis, possible dimensions include orders (with attributes such as order ID, order creation time, buyer ID, and seller ID), users (gender and date of birth), and products (product ID, product name, and listing time). You can create order, user, and product dimension tables and use their fields to store the corresponding dimension attributes. Then deploy these dimension tables to the data warehouse and use ETL to store actual dimension data according to the table definitions, so business users can retrieve the data for subsequent analysis.

image

As shown in the figure above:

  • When creating a dimension table:

    • You can specify the data warehouse layer where the dimension table is stored for analysis. Dimension tables are usually stored in the public dimension layer (DIM), but can also be placed in an application layer. The default application data layer supports only application tables. To create a dimension in an application layer, create a new application layer and set its model type to Dimension or Dimension tables and dimensions. For more information, see:Custom layers.

    • Based on the selected warehouse layer, associate the dimension table with the business category, data domain, and business process, or with the data mart and subject area it analyzes. You can then manage dimension tables from either the data domain or data mart perspective.

  • After creating the table, add dimensions as table attributes, configure relationships and partitions, and apply consistent field standards or standard codes. This keeps dimension attributes consistent across the data domain.

  • After configuring the dimension table:

    • You can materialize it in a storage engine and use it for analysis in a compute engine.

    • You can directly reference fields from the dimension table when designing derived metrics and aggregate tables.

Prerequisites

The public layer processes and integrates shared data to build consistent dimension tables. The application layer uses processed data from the public layer to build business-specific dimension tables for application needs and ongoing customization. Choose the public or application layer according to your needs. The prerequisites for each layer are listed below.

Data warehouse layer

Prerequisite

Reference

Common Layer

A data warehouse layer has been created in the public layer to determine where the dimension table belongs.

Define data warehouse layers

A data domain has been created to define the business data perspective measured by the dimension table.

Data domain

Application Layer

A data warehouse layer has been created in the application layer to determine where the dimension table belongs.

Define data warehouse layers

A data mart has been created to define the data category for the application scenario or product measured by the dimension table.

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 open the Dimensional Modeling page.

  3. Create a dimension table.

    1. On the Dimensional Modeling page, hover over the Plus icon icon and click Logical Model > Create Dimension Table.

    2. Configure the basic information for the dimension table.

      Select the warehouse layer, data domain, business category, data mart, and other information for the table. You can later find the table in the corresponding object list. This example creates a public-layer dimension table. The main parameters are described below.

      Parameter

      Description

      Data Layer

      Select the warehouse layer for the dimension table. Different layers serve different business scenarios:

      • Common Layer: Stores results of shared data processing and integration to build enterprise-wide dimension tables. After selecting it, specify a data domain. For instructions on creating a data domain, see Data domain.

      • Application Layer: Builds business-specific dimension tables for application needs. After selecting it, specify a data mart. For instructions on creating a data mart, see Data mart.

      Note

      The default application data layer supports only application tables. To create a dimension table in an application layer, create a new application layer and set its model type to Dimension or Dimension tables and dimensions. For more information, see:Custom layers.

      Business Category

      If you select the public layer, you can select the business category of the dimension table here.

      Data Domain

      If you select the public layer, you can select the data domain of the dimension table here.

      Category/Mart/Subject

      If you select the application layer, select the data mart or subject area under the business category here.

      Storage Policy

      Specify the strategy for storing the dimension table's data, including its retention period and data volume range.

      Dimension

      Select the dimension associated with the table to define the perspective for analyzing its data.

      Note

      For information about creating a dimension, see Create a conceptual model: dimension.

      Naming Rule

      Use a configured checker to enforce naming rules for the dimension table. After selecting a checker, the table's Table Name must follow its rules.

      Note

      For information about configuring a checker, see Configure data warehouse layer checkers.

      Table Name

      Name of the dimension table. If a table naming rule is configured, the name must follow it.

      Table Display Name

      Display name of the dimension table.

      Lifecycle

      Retention period of the dimension table, up to 36,000 days.

      Owner

      Owner of the dimension table. The user who creates the table is selected by default.

      Description

      Description of the dimension table.

  4. When finished, click Save to create the dimension table.

    Find and manage the table under its data domain or business category in the left navigation tree of Dimensional Modeling.

Add table fields

After creating the model, add table fields.

You can use Shortcut Mode or Script Mode to add fields to the table. The Shortcut Mode option supports Import from Table/View: importing fields from an existing physical table or view in a compute engine. In the Find existing table/view drop-down list, search for and select a physical table or view to import fields.

Quick mode

Note

Currently, fields can be imported only from tables or views in MaxCompute, Hologres, or EMR Hive.

  1. Click Shortcut Mode. Under Import from Table/View, enter a name in the input box after Expand.

  2. On the Find existing table/view to select a table or view. You can then import all or some fields from the referenced table or view.

    Note
    • Fuzzy matching is supported: enter a keyword to find tables or views whose names contain it.

    • Only production tables can be searched; development tables cannot be searched.

    • Import all fieldsThe icon indicates importing all fields.

    • Some fieldsThe icon indicates importing some fields.

  3. If you choose to import some fields, select the fields to add to the model in the dialog box, then click Import.

  4. If any imported field has an empty Field Display Name field, follow the prompt to populate its description with its display name.

Code mode

Note

You can also create fields, relationships, and partitions with FML statements. For instructions, see Modeling in Script Mode.

Code ModeYou can create a dimension table by writing code. After entering and saving its basic information, click Script Mode. The dialog box generates modeling language from the configured model information. Modify it as needed, then click OK.

-- After publication of the physical table starts (approval before publication, publication in progress, or publication succeeded), the table name cannot be changed.
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: 0 group; 1 subsidiary; 2 business unit; 3 department.' BIGINT COMMENT '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');

Set table field information

The fields required by the model have now been added. Set their Associated Field, Redundant Field, Associated Granularity/Metric.

  1. Set field attributes.

    By default, basic attributes such as Field Name, Type, Field Display Name, Description, Primary Key, Not Null, Measurement Unit, Actions are displayed. Click Field Display Settings in the upper-right corner of the added fields to choose which field attributes to display and modify them as needed.

  2. Set the field's Field Standard to Associate, Lookup Table to Associate. Associate an added field with a field standard and standard code to standardize its allowed values and range.

    After configuring fields, you can also click Association in the upper-right corner of the field list to set the associated Atomic Metric, Lookup Table and Field Standard.

    • Field Standard to Associate: Standardize data with the same meaning but different field names, including its allowed values and units of measurement.

    • Lookup Table to Associate: Specify the content and range of values allowed for a field standard.

  3. Set the field's Redundant Field.

    In a traditional star schema, dimensions are stored in dimension tables and accessed through foreign keys in fact tables to reduce storage. In DataWorks Intelligent Data Modeling, frequently used fields, such as user IDs and common analysis dimensions, can instead be stored redundantly to improve downstream query efficiency, simplify data access, and reduce joins.

    Example 1: The Order Creation Detail Table can redundantly include the Delivery Address dimension from the Delivery Address Dimension Table, such as recipient address and phone number.

    Example 2: The Product Dimension Table can redundantly include procurement and brand information from the Product Information Table.

    In the Actions column of an added field, click Redundant Field to set its associated field.

    In the Redundant Fields dialog box, select the Associated table/view name (including the data source type and specific table name). Review available fields below, including names, types, primary keys, and partitions. Select the Associated field and click Save to finish.

  4. After configuring the settings, click Save.

Next steps

After creating the dimension table, configure field management, relationships, partitions, and other settings, then publish the table to the appropriate environment. For more information, see: