You need to enable JavaScript to run this app.
Torch Log Service

Torch Log Service

Copy page
Download PDF
SQL function
Type conversion functions
Copy page
Download PDF
Type conversion functions
This article introduces the syntax of type conversion functions supported by TLS and common usage scenarios.​
Function list​
tip​
In SQL statements for TLS analysis, use single quotes ('') to enclose string values. Characters without quotes or those enclosed in double quotes ("") are treated as field names or column names. For example, 'time' indicates a string, while time or "time" refers to a field or column name.​
​
Function name​
Syntax​
Description​
CAST(KEY AS type)​
Convert the data type of KEY​
TRY_CAST(KEY AS type)​
Convert the data type of KEY​
TYPEOF(KEY)​
Query the data type of KEY.​
​
CAST function​
The CAST function converts the data type of a KEY. If a value fails to convert its data type when using the CAST function, the system will terminate the entire query and analysis operation.​
Function syntax​
  • Syntax format​
  • ​
    CAST(KEY AS type)​
    ​
  • Parameters description​
  • ​
    Parameter​
    Description​
    KEY​
    Field or expression, the value can be of any data type.​
    type​
    SQL data types. Options include bigint, varchar, double, boolean, timestamp, decimal, array, or map. For example, CAST(JSON_PARSE(KEY) AS array(varchar)).​
    For the mapping between index data types and SQL data types, see Data Type Mapping.​
    ​
  • Description of return values​
  • The return value data type matches the type parameter.​
Function example​
  • Scenarios​
  • The child_type field is of varchar type. Use the CAST function to convert the child_type field value to MAP(varchar, varchar) type.​
tip​
In this example, the index data type of the child_type field is text. If the index data type is json, running the following statement will result in an error.​
  • Log example​
  • ​Image​​
  • Query and analysis statements​
  • ​
    * | SELECT CAST(JSON_PARSE(child_type) AS MAP(varchar, varchar))​
    ​
  • Query and analysis results​
  • ​Image​​
TRY_CAST function​
The TRY_CAST function is used to convert the data type of a KEY. When converting data types using the TRY_CAST function, if the type conversion of a value fails, the system returns NULL and continues processing by skipping that value.​
Function syntax​
  • Syntax format​
  • ​
    TRY_CAST(KEY AS type)​
    ​
  • Parameters description​
  • ​
    Parameter​
    Description​
    KEY​
    Field or expression; the value can be any data type.​
    type​
    SQL data types: supported values are bigint, varchar, double, boolean, timestamp, decimal, array, or map. For example, TRY_CAST(JSON_PARSE(KEY) AS array(varchar)).​
    For details on the mapping between index data types and SQL data types, see Data Type Mapping.​
    ​
  • Return value description​
  • The return value data type is consistent with the type parameter.​
Function examples​
  • Scenarios​
  • Convert the value of the ReqTime field to varchar and return this data type.​
  • Query and analysis statements​
  • ​
    * | SELECT ReqTime,TYPEOF(TRY_CAST(ReqTime AS varchar))​
    ​
  • Query and analysis results​
  • ​Image​​
TYPEOF function​
The TYPEOF function is used to query the data type of a KEY.​
Function syntax​
  • Syntax format​
  • ​
    TYPEOF(KEY)​
    ​
  • Parameters description​
  • ​
    Parameter​
    Description​
    KEY​
    Log fields and expressions can hold values of any data type​
    ​
  • Return value description​
  • The return value is of varchar type.​
Function example​
  • Scenarios​
  • View the data type of the Method field​
  • Log example​
  • ​Image​​
  • Query and analysis statements​
  • ​
    * | SELECT TYPEOF(Method)​
    ​
  • Query and analysis results​
  • ​Image​​
Data type mapping​
The correspondence between index data types and SQL data types is shown in the table below:​
​
Index data type​
SQL data type​
long​
bigint​
text​
varchar​
double​
double​
json​
varchar​
​
​
Last updated: 2025.10.29 15:17:17