This topic describes SPL instructions.
Parameter types
The following table describes the parameter types used in SPL instructions.
Parameter type | Description |
Bool | A Boolean parameter. When you use SPL, this parameter works as a switch. |
Char | An ASCII character parameter. It must be enclosed in single quotation marks (''). For example, |
Integer | An integer parameter. |
String | A string parameter. It must be enclosed in single quotation marks (''). For example, |
RegExp | An RE2 regular expression parameter. It must be enclosed in single quotation marks (''). For example, For more information about the syntax, see Syntax. |
JSONPath | A JSON path parameter. It must be enclosed in single quotation marks (''). For example, For more information about the syntax, see JsonPath. |
Field | A field name parameter. For example, If a field name contains special characters other than letters, digits, and underscores, enclose the field name in double quotation marks (""). For example, Note For more information about the case sensitivity of field names, see General reference. |
FieldPattern | A combination of a field name and a wildcard character, or a field name parameter. The wildcard character (*) is supported, which matches zero or more characters. It must be enclosed in double quotation marks (""). For example, Note For more information about the case sensitivity of field names, see General reference. |
SPLExp | An SPL expression parameter. |
SQLExp | An SQL expression parameter. |
SPL instruction list
Instruction category | Instruction name | Description | Data transformation | Write processor | Consume processor | Scan mode (SCAN) | Logtail collection |
Control instructions | .let | Defines a named dataset. For more information about SPL datasets, see General reference. | √ | × | × | √ | × |
Field operation instructions | project | Retains fields that match a specified pattern and renames specified fields. During execution, all field retention expressions are processed before renaming expressions. | √ | √ | √ | √ | √ |
project-away | Removes fields that match a specified pattern and retains all other fields. | √ | √ | √ | √ | √ | |
project-rename | Renames specified fields and retains all other fields. | √ | √ | √ | √ | √ | |
expand-values | Expands the first-layer JSON object of a specified field to generate multiple results. | √ | × | √ | × | × | |
SQL calculation instructions for structured data | extend | Creates new fields by calculating the results of SQL expressions. For a list of supported SQL functions, see List of SQL functions supported by SPL. | √ | √ | √ | √ | √ |
where | Filters data based on an SQL expression and retains data entries that meet the expression. For a list of SQL functions supported by the where instruction, see List of SQL functions supported by SPL. | √ | √ | √ | √ | √ | |
Semi-structured data extraction instructions | parse-regexp | Extracts information that matches regular expression groups from a specified field. | √ | √ | √ | √ | √ |
parse-csv | Extracts information in CSV format from a specified field. | √ | √ | √ | √ | √ | |
parse-json | Extracts first-layer JSON information from a specified field. | √ | √ | √ | √ | √ | |
parse-kv | Extracts key-value pair information from a specified field. | √ | √ | √ | √ | √ | |
New data transformation instructions | pack-fields | Packs log fields and outputs them to a new field through JSON serialization. This instruction is suitable for scenarios that require structured transmission, such as building an API request body. | √ | × | √ | √ | × |
log-to-metric | Converts the log format to the metric storage format. | √ | × | × | × | × | |
metric-to-metric | Further processes existing metric data, such as adding, modifying, or removing tags. | √ | × | × | × | × | |
Aggregation instructions | stats | An instruction for statistical analysis of logs, similar to SQL aggregate functions such as | × | × | × | √ | × |
sort | Sorts query results. It supports sorting field values or statistical results in ascending ( | × | × | × | √ | × | |
limit | Limits the number of log rows returned in query results. This is a core instruction for controlling data volume. Using the | × | × | × | √ | × |
Function overview
SPL instructions support most SQL functions. However, the availability and applicable scenarios for specific functions are described in the corresponding function documentation.
Classification | Description | Common functions |
Perform summary calculations on the target dataset to generate a single statistical result. | ||
Process text data, including search, replace, substring, concatenate, and format. | ||
Perform format conversion, grouping, and aggregation on dates and times in logs. | ||
Process JSON objects, including extraction, transformation, and statistics. | ||
Pattern matching and text processing. | ||
Calculate relative changes in time series data. | ||
Perform addition, deletion, modification, query, traversal, and transformation on arrays. | ||
Operate on key-value pairs. | ||
Numerical calculations, rounding, random numbers, trigonometric functions, and more. | ||
Data distribution analysis and numerical calculations. | ||
Handle conversions between data types. | ||
Aggregation or sorting based on data windows. | ||
Parse and calculate IP addresses. | ||
Parse URL structures. | ||
Predict data or fill in missing values. | ||
Process binary data types. | ||
Directly operate on binary bits. | ||
Process spatial geometries. | ||
Geographic location analysis and map calculations. | ||
Color representation and conversion. | ||
Perform statistical processing on large datasets, sacrificing accuracy to save memory. | ||
Determine the size relationship of parameters, applicable to any comparable data type (double, bigint, varchar, timestamp, and date). | ||
Combine multiple Boolean conditions to control logical flow. | ||
Convert units of data size or time intervals. | ||
Analyze user behavior, app traffic, product goal conversion, and other data. | ||
Define lambda expressions in SQL analytic statements and SPL statements, and pass them to specified functions to enrich the expression of functions. | ||
Return different values based on conditional branches. |