All Products
Search
Document Center

Dataphin:Create a mirror table

Last Updated:Jan 21, 2025

Mirror tables facilitate the management of streaming and offline tables in Flink computing tasks. This topic explains the process of creating a mirror table.

Background information

In scenarios where a Flink task requires both real-time and offline processing, developers must handle both streaming and offline tables. Dataphin simplifies this by allowing the creation of mirror tables, which serve as a single reference point for both streaming and offline tables. This streamlines the development of computing tasks by automatically generating real-time and offline instances, thereby enhancing development efficiency.

Step 1: Create a mirror table

  1. Navigate to the Dataphin home page and select Development from the top menu bar.

  2. Use the operation guide shown below to access the Streaming Table dialog box.

    image

  3. In the Create Table dialog box, set the parameters as follows:

    Parameter

    Description

    Table Type

    Choose Mirror Table as the type.

    Table Name

    Ensure the name adheres to the following criteria:

    • Use English letters, digits, and underscores (_).

    • The name must not begin with a digit.

    • Limit the name to a maximum of 64 characters.

    Storage Directory

    The default directory is Table Management. Alternatively, create and select a target folder on the Tables page as the directory for the mirror table. image

    Description

    Provide a concise description within 1000 characters.

  4. Once configured, click OK.

  5. Proceed to the primary table development page and add fields.

    The system offers several methods for adding new primary table fields:

    • SQL statement import fields:

      1. Select SQL Import Fields.

      2. Within the SQL Import dialog box, select Reference Example to access code samples that will guide you in writing the import code for fields. An example of the code is provided below.

        create table dwi_pub_hbd_cate_mtr (
          rowkey VARCHAR comment 'rowkey',
          stat_date VARCHAR comment 'stat_date',
          keymin VARCHAR comment 'keymin',
          PRIMARY KEY(rowkey)
        )
      3. Confirm by clicking OK.

    • Batch import fields:

      1. Choose Batch Import.

      2. In the Batch Import dialog box, use the example as a guide to write the batch import code.

        rowkey||VARCHAR||rowkey
        rowkey1||VARCHAR||rowkey1
        rowkey2||VARCHAR||rowkey2
        stat_date||VARCHAR||stat_date
        keymin||VARCHAR||keymin
      3. Click OK to confirm.

    • Single-row add fields:

      1. Click Single-row Add.

      2. In the Single-row Add dialog box, enter the Field Name and Description, and select the Field Type.

      3. To finalize, click OK.

    To add more fields to an existing table, click the gege icon at the top right of the primary table display box and choose the preferred method for adding fields.

Step 2: Associate streaming tables and offline tables

  1. On the primary table development page, select Select Associated Table.

    image

  2. In the Create Association dialog box, specify the associated streaming and offline tables.

    Associated Table

    Parameter

    Description

    Associated Streaming Table

    Select Project

    Choose the project for the associated streaming table.

    Select Streaming Table

    Choose the streaming table to associate.

    Associated Offline Table

    Select Project

    Select the project for the associated offline table.

    Select Offline Table

    Choose the offline table to associate.

  3. Confirm the association by clicking OK.

  4. On the mirror table development page, click the 1 icon on the connection line. In the Replace Association dialog box, update the associated streaming and offline tables.

    Note

    After creating the file, click the 1 icon on the connection line. In the Replace Association dialog box, click OK to remove the associated replacement association.

    Associated Table

    Parameter

    Description

    Associated Streaming Table

    Select Project

    Select the project for the associated streaming table.

    Select Streaming Table

    Select the streaming table

    Associated Offline Table

    Select Project

    Select the project for the associated offline table.

    Select Offline Table

    Select the offline table

  5. To finalize, click OK.

  6. Next, associate fields.

    Fields can be associated using the following methods:

    • Manual association:

      Select the corresponding fields in the streaming and offline tables, then click the related fields in the primary table to create associations, indicated by connecting lines. image.png

      To delete an association, click the gag on the connection line and in the Delete Field Association dialog box, select OK.

    • Automatic association:

      Select Automatic Association at the top of the page to have the system automatically link fields with the same names across the mirror, streaming, and offline tables, creating the necessary connections.

      Existing associations will be overwritten by the automatic process.

    • Batch association:

      1. Click Batch Association at the top of the page.

      2. In the Batch Association dialog box, refer to the Reference Example and compose the code for field association accordingly.

        Mirror Table Field, Streaming Table Field, Offline Table Field
        Mirror Table Field, Streaming Table Field, Offline Table Field
        Mirror Table Field, Streaming Table Field, Offline Table Field
      3. Confirm by clicking OK.

Step 3: Preview mirror relationships

On the mirror table development page, the Mirror Relationship Preview panel is displayed on the right side of the page. In the Mirror Relationship Preview panel, view the mapping relationships between streaming tables, offline tables, and mirror tables.

If the Mirror Relationship Preview panel is closed, reopen it by clicking the gegeg icon at the top right of the page.

Step 4: Submit or publish the mirror table

  1. Save the mirror table by clicking the 1 icon at the top of the mirror table development page.

  2. To proceed, click the 1 icon at the top of the page.

  3. In the Submit Remarks dialog box, enter the necessary remarks.

  4. Complete the submission by clicking OK And Submit.

  5. (Optional)

    Publish the mirror table to the production environment if required.

    Depending on the development pattern of the current project, determine if the mirror table needs to be published:

    • For projects in Basic mode, publishing is not necessary as a successfully submitted mirror table automatically moves to the production environment.

    • For projects in Dev-Prod mode, the mirror table must be published to transition to the production environment.