Field Editing and Value Assignment

Updated at:

Field editing and value assignment is a data processing component for single-table real-time synchronization tasks in DataWorks Data Integration. Add the component to a task to add fields during synchronization, assign values to them, and write them to the destination.

Prerequisites

  1. Create a data source. For more information, see Data source management.

  2. Create a Data Integration task. For more information, see Configure a single-table real-time synchronization task.

    Note

    For single-table real-time Data Integration tasks, you can add a data processing component between the source and destination components. For more information, see Supported data sources and synchronization solutions.

Add a field during synchronization

  1. In a real-time synchronization task for a single table, turn on the Data Processing switch.

  2. Click +Add Node, and then add the Edit Field and Assign Value component.

  3. Configure the field editing and value assignment component. Select the ancestor fields to output to the downstream component, add the fields that you need, and assign a value to each new field. For a description of every column and value assignment method, see Field settings.

  4. After you configure Source and Field editing and value assignment, click Output Preview to view the output data of the current node and check whether it meets your requirements.

  5. In field mapping, configure the mapping between each new field and a field in the destination table.

    Important

    A newly added field can be written to the destination table only after you configure its mapping to a destination table field in field mapping.

Field settings

The field editing and value assignment component works on two groups of fields: the fields that the ancestor component outputs, and the fields that you add manually.

  • Ancestor fields: the fields that the ancestor component outputs to the field editing and value assignment component. The following columns describe these fields:

    • Field Name: The name of the field that the ancestor component outputs.

    • Type: The data type that the ancestor component outputs.

    • Value: For a field that already exists in the ancestor component, the value is the ancestor output. For a new field, three value assignment methods are available: constant, variable, and function.

    • Actions: For an ancestor output field, specify whether to output the field to the downstream component.

  • Custom Field: Click Add Field in the lower-left corner of the field editing and value assignment page to add a new field. Assign a value to the new field by using one of the following methods:

    • Constant: Converts the constant text that you enter manually to the specified data type and then assigns it to the new field.

    • Variable: Assigns the value of a built-in variable to the new field at synchronization runtime. For the variables that you can select, see Supported variables.

    • Function: Performs a function calculation at synchronization runtime and assigns the result to the new field. If an exception occurs while the function is processed, the record is treated as dirty data and counted in the dirty data statistics of the synchronization task. The dirty data tolerance configuration then determines whether the task exits abnormally. For the functions that you can select, see Supported functions.

Example

In this example, the ancestor Kafka component outputs the _key_ (STRING), _value_ (STRING), _partition_ (LONG), _offset_ (LONG), _timestamp_ (LONG), and _headers_ (STRING) fields. All of these fields are selected for output to the downstream component. In the custom fields, an add_col field is added, with the data type set to STRING, the value assignment method set to constant, and the value set to 1.

Supported variables

Select the variable value assignment method to fill a new field with a value that the synchronization task resolves at runtime. The following table lists the supported built-in variables.

Note

Because of differences in system characteristics, some sources and destinations may not support all of the variables in the following table.

Category

Variable

Description

Source

PROCESS_TIME

The time when the synchronization task processes the record. The value is a 13-digit millisecond timestamp.

Source

DATASOURCE_NAME_SRC

The name of the source data source.

Source

DB_NAME_SRC

The name of the source database.

Source

SCHEMA_NAME_SRC

The name of the source schema.

Source

TABLE_NAME_SRC

The name of the source table.

Source

TOPIC_NAME_SRC

The name of the source topic.

Destination

TABLE_NAME_DEST

The name of the destination table.

Destination

TOPIC_NAME_DEST

The name of the destination topic.

Destination

SCHEMA_NAME_DEST

The name of the destination schema.

Destination

DB_NAME_DEST

The name of the destination database.

Destination

DATASOURCE_NAME_DEST

The name of the destination data source.

Supported functions

Select the function value assignment method to calculate the value of a new field at synchronization runtime. The following functions are supported.

In the time formats that these functions use, such as yyyy-MM-dd HH:mm:ss:SSS ZZ, yyyy indicates the year, MM the month, dd the day, HH the hour in the 24-hour clock, mm the minute, ss the second, SSS the millisecond, and ZZ the time zone.

DATE_FORMAT

Converts a timestamp to a time string in a specific format.

Parameter

Description

Parameter 1

An ancestor field of a numeric type, either a 10-digit UNIX timestamp or a 13-digit millisecond timestamp.

Parameter 2

The timestamp type. unix indicates a 10-digit UNIX timestamp, and millis indicates a 13-digit millisecond timestamp.

Parameter 3

The time zone used for the conversion.

Parameter 4

The date string format to convert to, for example yyyy-MM-dd HH:mm:ss:SSS ZZ.

TO_TIMESTAMP

Converts a time string to a 10-digit or 13-digit timestamp.

Parameter

Description

Parameter 1

An ancestor field of a text type that contains a time string in a specific format.

Parameter 2

The timestamp type to convert to. unix indicates a 10-digit UNIX timestamp, and millis indicates a 13-digit millisecond timestamp.

Parameter 3

The time zone used for the conversion.

Parameter 4

The time string format, for example yyyy-MM-dd HH:mm:ss:SSS ZZ.

SUBSTRING

Gets a substring from a string.

Parameter

Description

Parameter 1

An ancestor field of a text type.

Parameter 2

The start position of the substring. The substring includes the character at the start position. The minimum start position is 0.

Parameter 3

The substring length. If the length is less than or equal to 0, the function returns the substring from the start position to the end of the string.