All Products
Search
Document Center

Simple Log Service:Type conversion functions

Last Updated:Jun 10, 2026

Use type conversion functions in query and analysis statements to convert data types.

SLS supports the following type conversion functions.

Important

If you want to use strings in analytic statements, you must enclose the strings in single quotation marks (''). Strings that are not enclosed or strings that are enclosed in double quotation marks ("") indicate field names or column names. For example, 'status' indicates the status string, and status or "status" indicates the status log field.

Function

Syntax

Description

SQL

SPL

cast function

cast(x as type)

Converts the data type of x.

If conversion fails, the entire query fails.

try_cast function

try_cast(x as type)

Converts the data type of x.

If conversion fails, returns NULL and continues processing.

Note

Use try_cast instead of cast to prevent dirty data from stopping the entire query.

×

typeof function

typeof(x)

Returns the data type of x.

×

Cast function

Converts the data type of x. If conversion fails, the entire query fails.

Syntax

cast(x as type)

Parameters

Parameter

Description

x

The expression to convert. Supports any data type.

type

The target SQL data type. Valid values: bigint, varchar, double, boolean, timestamp, decimal, array, and map.

Example: cast(json_parse(key) as array(varchar)).

Appendix: Data type mapping lists the index-to-SQL type mappings.

Return value type

The data type specified by the type parameter.

Examples

SQL

Convert 1 to boolean.

  • Query and analysis statement

    * | select cast(1 as boolean)
  • The query returns true.

SPL

Convert 1 to boolean.

  • Query and analysis statement

* | extend a = cast(1 as boolean)
  • The value of a is true.

Try_cast function

Converts the data type of x. If conversion fails, returns NULL and continues processing.

Syntax

try_cast(x as type)

Parameters

Parameter

Description

x

The expression to convert. Supports any data type.

type

The target SQL data type. Valid values: bigint, varchar, double, boolean, timestamp, decimal, array, and map.

Example: try_cast(json_parse(key) as map(varchar, varchar)).

Appendix: Data type mapping lists the index-to-SQL type mappings.

Return value type

The data type specified by the type parameter.

Examples

Convert the uid field to varchar.

  • Query and analysis statement

    * | select try_cast(uid as varchar)
  • The result contains a _col0 column. Both rows have the value owner-01.

Typeof function

Returns the data type of x.

Syntax

typeof(x)

Parameters

Parameter

Description

x

The expression to evaluate. Supports any data type.

Return value type

varchar

Examples

Check the data type of request_time.

  • Query and analysis statement

    * |SELECT typeof(request_time)
  • The data type of request_time is double.

Appendix: Data type mapping

Index-to-SQL data type mappings:

Index data type

SQL data type

long

bigint

text

varchar

double

double

json

varchar