All Products
Search
Document Center

Simple Log Service:Structured data SQL calculation instructions

Last Updated:Jun 04, 2026

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.

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.

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

Aggregation functions

Calculates a single statistical value from a set of data.

String functions

Finds, replaces, extracts, concatenates, and formats text data.

Date and time functions

Converts, groups, and aggregates dates and times in logs.

JSON functions

Extracts data from, converts, or calculates statistics on JSON objects.

Regular expression functions

Performs pattern matching and text processing.

Year-over-year and period-over-period functions

Calculates the relative change in time-series data.

Array functions and operators

Creates, manipulates, traverses, and transforms arrays.

Map functions and operators

Works with key-value pairs.

Mathematical functions

Performs numerical calculations, rounding, random number generation, and trigonometric calculations.

Statistical functions

Performs data distribution analysis and numerical calculations.

Type conversion functions

Converts between data types.

Window functions

Aggregates or sorts data over a window.

IP functions

Parses and calculates IP addresses.

URL functions

Parses URL structures.

Approximation functions

Performs approximate aggregations on large datasets, trading accuracy for performance.

Binary functions

Operates on binary data.

Bitwise functions

Directly manipulates binary bits.

Spatial functions

Operates on spatial geometry data.

Geographic functions

Performs geographic location analysis and map calculations.

Color functions

Represents and converts colors.

HyperLogLog functions

Performs statistical processing on large datasets, trading precision for memory efficiency.

Comparison operators

Compares values across comparable types: double, bigint, varchar, timestamp, and date.

Logical operators

Combines multiple boolean conditions to control logical flow.

Unit conversion functions

Converts units of data size or time intervals.

Window funnel functions

Analyzes data such as user behavior, app traffic, and product goal conversion.

Lambda expressions

Lets you define lambda expressions in SQL and SPL statements and pass them to other functions for greater flexibility.

Conditional expressions

Returns a value based on a specified condition.