All Products
Search
Document Center

DataWorks:Sensors Data

Last Updated:Mar 26, 2026

DataWorks Data Integration supports writing data to Sensors Data using Sensors Data Writer. Sensors Data Writer supports three data types — events, users, and items — and optional field-level data type conversion before writing.

Limits

  • You can add a Sensors Data source only in the China (Shenzhen) region. Support for other regions is coming soon.

  • You cannot read data directly from Sensors Data. Use a plugin such as Hive or HDFS to read data, based on the storage type of your Sensors Data instance.

Add a Sensors Data source

Before configuring a synchronization task, add Sensors Data as a data source in DataWorks. Follow the steps in Data source management. Parameter descriptions are available in the DataWorks console when you add the data source.

Configure a synchronization task

Sensors Data Writer supports three data types, each mapping to a Sensors Data entity:

type valueSensors Data entity
trackEvent
userUser
itemItem (property)

The type value determines which sub-parameters are required in the writer step. Configure the writer using the code editor, then map source columns to destination fields using the column parameter.

For the task configuration procedure, see Configure a task in the code editor.

Script example and parameter reference

Writer script example

The following example writes item data (a course catalog) from a MySQL source to Sensors Data. Field mappings use 0-based column indexes from the source table.

{
    "type": "job",
    "steps": [
        {
            "stepType": "mysql",
            "parameter": {},
            "name": "Reader",
            "category": "reader"
        },
        {
            "stepType": "sahistory",
            "parameter": {
                "type": "item",
                "item": {
                    "itemType": "course",
                    "typeIsColumn": false,
                    "itemIdColumn": "course_id"
                },
                "column": [
                    {
                        "name": "course_id",
                        "index": 0
                    },
                    {
                        "name": "course_name",
                        "index": 1
                    },
                    {
                        "name": "course_schedule",
                        "index": 2,
                        "dataConverters": [
                            {
                                "type": "Long2Date"
                            }
                        ]
                    }
                ],
                "sdkDataAddress": "http://bigdata-project.datasink.sensorsdata.cn/sa?project=default&token=1111111111111111"
            },
            "name": "Writer",
            "category": "writer"
        }
    ],
    "setting": {
        "errorLimit": {
            "record": "0"
        },
        "speed": {
            "throttle": true,
            "concurrent": 2,
            "mbps": "12"
        }
    }
}

Top-level writer parameters

ParameterDescriptionRequiredDefault
typeThe type of data to write to Sensors Data. Valid values: track, user, item. The value determines which sub-parameters apply under the writer step.YesNone
columnField mappings between source and destination tables. Each entry requires name (destination field name) and index (0-based source column index).YesNone
sdkDataAddressThe URL that Sensors Data uses to receive data. Format: http://localhost:8106/sa?project=default. To get this URL, go to Sensors Analytics > Basic Settings > Data Ingestion > Server Tracking > Copy HTTP Data Receiving Address.YesNone

Sub-parameters when type is track

Use these parameters to configure event data.

ParameterDescriptionRequiredDefault
distinctIdColumnThe source field name to use as the event's Distinct ID in Sensors Data. Must also appear in the column list. The field value cannot be empty.OptionalNone
eventNameThe event name in Sensors Data.OptionalNone
isLoginIdSpecifies whether the Distinct ID field is a logon ID (unique user identifier). Valid values: true, false.Optionaltrue

Example:

"track": {
    "distinctIdColumn": "track_id",
    "eventName": "testEventName",
    "isLoginId": true
}

Sub-parameters when type is user

Use these parameters to configure user data.

ParameterDescriptionRequiredDefault
distinctIdColumnThe source field name to use as the user's Distinct ID in Sensors Data. Must also appear in the column list. The field value cannot be empty.OptionalNone
isLoginIdSpecifies whether the Distinct ID field is a logon ID (unique user identifier). Valid values: true, false.Optionaltrue

Example:

"user": {
    "distinctIdColumn": "user_id",
    "isLoginId": true
}

Sub-parameters when type is item

Use these parameters to configure item (property) data.

ParameterDescriptionRequiredDefault
itemIdColumnThe source field name to use as the item's Distinct ID in Sensors Data. Must also appear in the column list. The field value cannot be empty.OptionalNone
itemTypeThe item type name in Sensors Data. If this field appears in column, its value cannot be empty and typeIsColumn must be true. Otherwise, use a constant as the item type.OptionalNone
typeIsColumnSpecifies whether itemType is read from the column list. Set to false to use a constant value. Valid values: true, false.Optionaltrue

Example:

"item": {
    "itemIdColumn": "item_id",
    "itemType": "testItem",
    "typeIsColumn": false
}

Data converters

Sensors Data Writer supports data type conversion before writing to the destination. Add a dataConverters array to a field entry in column and specify the converter type.

Converter typeConverts fromConverts toParameters
Date2StrDateStringpattern (Optional): Output time format, e.g., yyyy-MM-dd.
Date2LongDateLongNone
Number2StrNumericStringNone
Str2LongStringLongNone
Str2DateStringDatepattern (Optional): Output date format. Built-in formats: yyyy-MM-dd, yyyy-MM-dd HH:mm:ss, yyyy-MM-dd HH:mm:ss.SSS, yyyy-MM, yyyyMM, yyyyMMddHHmmss, yyyyMMddHHmmssSSS. formats (Optional): Array of additional input string formats for source data with mixed time formats.
BigInt2DateBigIntDateNone
Str2IntStringIntNone
Str2DoubleStringDoubleNone
Str2BigDecimalStringBigDecimalNone
IfNull2Defaultdefault: The constant to set when the field value is null. dataConverters (Optional): Nested converters to further transform the default value.
NotNull2NullNone. Converts any non-null field value to null.
IfElseSee IfElse parameters.
IfNull2ColumntargetColumnName: The name of the column whose value is used when the current field is null. The referenced column must be configured before the column using this converter.

IfElse parameters

IfElse evaluates a JavaScript conditional expression and returns one of two values based on the result.

ParameterDescription
ifA JavaScript expression that must return a Boolean. Has access to targetColumnName, value, param, and resolvedValues.
valueThe value returned when if evaluates to true. Parsed as JavaScript. Has access to the same variables as if.
elseThe value returned when if evaluates to false. Parsed as JavaScript. Has access to the same variables as if.
sharedPoolA shared JavaScript scope. Variables and constants defined here are accessible in if, value, and else.

Example — validate an ID number format and set the field to null if the check fails:

"dataConverters": [
    {
        "type": "IfElse",
        "param": {
            "if": "return true;",
            "value": "if(resolvedValues.get(\"check_card_type\") == 'NAN' && value == null ){return true;} if(resolvedValues.get(\"check_card_type\") == 'ID_Card'){ if(java.util.regex.Pattern.compile(regEx).matcher(value).find() && java.lang.Integer.parseInt(value.substring(6, 10)) >=1900 && java.lang.Integer.parseInt(value.substring(6, 10)) <= nowYear){return true;}} return null;",
            "sharedPool": "var nowYear = java.time.LocalDate.now().getYear(); var regEx = \"(110|120|310|510|150|650|540|640|450|230|220|210|120|140|630|370|410|320|340|320|340|330|350|360|430|420|440|460|620|610|520|530)\\d{7}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\\d{3}(\\d|X)\";"
        }
    }
]

IfNull2Default example

The following example handles a null timestamp field: it sets the value to "2021-07-01", converts the string to a Date, then converts the Date to a Long (milliseconds).

"dataConverters": [
    {
        "type": "IfNull2Default",
        "param": {
            "default": "2021-07-01",
            "dataConverters": [
                {
                    "type": "Str2Date",
                    "param": {
                        "pattern": "yyyy-MM-dd"
                    }
                },
                {
                    "type": "Date2Long"
                }
            ]
        }
    }
]