Data structures
Data transformation uses several data structures for processing log data, including basic types, event types, fixed identifiers, and JSON objects.
Basic data structures
The following table lists the basic data structure types.
|
Type |
Description |
|
Integer |
Sets field values or passes parameters to functions. Example: |
|
Float |
Sets field values or passes parameters to functions. Example: |
|
String |
Strings support the following conventions:
Note
Use single quotation marks for the outer string and double quotation marks for the inner search value. |
|
Bytes |
Differs from string memory encoding. |
|
empty |
Note
An empty string has a different data type than None or null. |
|
List |
An array, such as
|
|
Tuple |
Functions the same as a list. Example: |
|
Dictionary (Dict) |
A collection of key-value pairs in the format
|
|
Boolean (Bool) |
For example, |
|
Table |
A multi-column table structure. Build tables by loading multi-row CSV content from external resources or retrieving multi-column data from ApsaraDB RDS or a Logstore. Tables are mainly used for data enrichment mappings or other advanced configuration scenarios. |
|
Datetime object |
Represents a date and time in memory. Can be converted to a Unix timestamp string or a formatted time string, or passed to |
Event types
Data transformation supports the following event types.
-
Primitive type
Data transformation processes log data as a dictionary, such as
{"__topic__": "access_log", "content": "....."}.Dictionary keys and values correspond to log fields and values.
NoteEvent keys and values are both strings, and keys must be unique.
-
Meta-fields
Meta-fields include:
-
Time field
__time__: the Unix timestamp (seconds since 00:00:00 UTC, January 1, 1970) when the log was written. Stored as an integer string. -
Topic
__topic__: organizes logs in a Logstore by topic. You can specify a topic when writing or querying logs. -
Source
__source__: the log source, such as the IP address of the machine that generated the log.
-
-
Time field modification
Modify the time field value to change the event time. You can also use datetime functions for other operations on this field.
NoteIf the time field is deleted, the system uses the processing time as the event time when sending the log to the destination.
-
Tags
A tag is a log label used for classification, in the format
__tag__:name.-
If public IP address recording is enabled for the source Logstore, logs include the
tag:__tag__:__receive_time__tag. -
Container Service logs contain multiple container-related tags, such as
__tag__:__container_name__. -
You can add or modify tags. To add a tag named type, use
e_set("__tag__:type", "access_log").
-
-
Automatic conversion on assignment
Event keys and values are strings. When you assign a value or set a new field, keys and values are automatically converted to strings. Example:
e_set("v1", 12.3) e_set("v2", True)This sets
v1to string "12.3" andv2to string "true".The following table shows how different data types convert to strings.
Type
Example
Converted type
Converted example
Integer
1String
"1"Float
1.2String
"1.2"Boolean
TrueString
"true"Bytes
b"123"Decoded to a string using UTF-8
"123"Tuple
-
Example 1:
(1, 2, 3) -
Example 2:
("a", 1)
String of a list
-
Example 1:
"[1, 2, 3]" -
Example 2:
"[\"a\", 1]"
List
-
Example 1:
[1,2,3] -
Example 2:
["a", 1]
String
-
Example 1:
"[1, 2, 3]" -
Example 2:
"[\"a\", 1]"
Dictionary
{"1":2, "3":4}String
"{\"1\": 2, \"3\": 4}"Datetime
datetime(2018, 10, 10, 10, 10, 10)ISO format string
2018-10-10 10:10:10 -
Fixed identifiers
Data transformation provides fixed identifiers to simplify code and improve readability.
|
Identifier |
Type |
Description |
|
true |
Boolean |
Equivalent to |
|
false |
Boolean |
Equivalent to |
|
null |
None |
Equivalent to |
|
F_TAGS |
String |
Regex for |
|
F_META |
String |
Regex for |
|
F_TIME |
String |
The |
|
F_PACK_META |
String |
Regex for |
|
F_RECEIVE_TIME |
String |
The |
|
C_JOB_REGION |
String |
The region ID of the data transformation task, such as |
|
C_JOB_PROJECT |
String |
The project name of the data transformation task, such as |
|
C_JOB_NAME |
String |
The data transformation job configuration name, such as |
|
C_JOB_ID |
String |
The run ID of the data transformation task, such as |
JSON objects
A JSON object is parsed from a string using json_select or json_parse. It is composed of basic data structures. The following table shows how input strings convert to JSON objects.
|
String |
JSON object |
Actual type |
|
|
|
Integer |
|
|
|
Float |
|
|
|
Boolean |
|
|
|
Boolean |
|
|
|
String |
|
|
|
None |
|
|
|
List |
|
|
|
List |
|
|
|
Dictionary |
|
|
|
Dictionary |