Use the extend and where SPL instructions to run SQL calculations on structured data.
extend
Creates a new field by evaluating an SQL expression. Supported functions are listed in SQL functions supported by SPL.
Syntax
| extend <output>=<sql-expr>, ...
Parameters
|
Parameter |
Type |
Required |
Description |
|
output |
Field |
Yes |
The destination field name. Multiple expressions cannot output to the same field. Important
If a field with this name already exists in the input data, it is overwritten. |
|
sql-expr |
SQLExpr |
Yes |
The data processing expression. Important
|
Examples
-
Example 1: Use a calculation expression.
* | extend Duration = EndTime - StartTime -
Example 2: Use a regular expression.
* | extend server_protocol_version=regexp_extract(server_protocol, '\d+') -
Example 3: Extract from a JSON path and cast a field type.
-
SPL statement
* | extend a=json_extract(content, '$.body.a'), b=json_extract(content, '$.body.b') | extend b=cast(b as BIGINT) -
Input data
content: '{"body": {"a": 1, "b": 2}}' -
Output result
content: '{"body": {"a": 1, "b": 2}}' a: '1' b: 2
-
where
Filters data based on a boolean SQL expression. Only entries that evaluate to true are retained. Supported functions are listed in SQL functions supported by SPL.
Syntax
| where <sql-expr>
Parameters
|
Parameter |
Type |
Required |
Description |
|
sql-expr |
SQLExp |
Yes |
The SQL expression. Matching entries are retained. Important
|
Examples
-
Example 1: Filter by field value.
* | where userId='123' -
Example 2: Filter with a regular expression.
* | where regexp_like(server_protocol, '\d+') -
Example 3: Cast a data type and filter server-side errors.
* | where cast(status as BIGINT) >= 500
SQL functions supported by SPL
|
Category |
Description |
Common functions |
|
Calculates a single statistical value from a set of data. |
||
|
Finds, replaces, extracts, concatenates, and formats text data. |
||
|
Converts, groups, and aggregates dates and times in logs. |
||
|
Extracts data from, converts, or calculates statistics on JSON objects. |
||
|
Performs pattern matching and text processing. |
||
|
Calculates the relative change in time-series data. |
||
|
Creates, manipulates, traverses, and transforms arrays. |
||
|
Works with key-value pairs. |
||
|
Performs numerical calculations, rounding, random number generation, and trigonometric calculations. |
||
|
Performs data distribution analysis and numerical calculations. |
||
|
Converts between data types. |
||
|
Aggregates or sorts data over a window. |
||
|
Parses and calculates IP addresses. |
||
|
Parses URL structures. |
||
|
Performs approximate aggregations on large datasets, trading accuracy for performance. |
||
|
Operates on binary data. |
||
|
Directly manipulates binary bits. |
||
|
Operates on spatial geometry data. |
||
|
Performs geographic location analysis and map calculations. |
||
|
Represents and converts colors. |
||
|
Performs statistical processing on large datasets, trading precision for memory efficiency. |
||
|
Compares values across comparable types: double, bigint, varchar, timestamp, and date. |
||
|
Combines multiple boolean conditions to control logical flow. |
||
|
Converts units of data size or time intervals. |
||
|
Analyzes data such as user behavior, app traffic, and product goal conversion. |
||
|
Lets you define lambda expressions in SQL and SPL statements and pass them to other functions for greater flexibility. |
||
|
Returns a value based on a specified condition. |