All Products
Search
Document Center

Simple Log Service:Unit conversion functions

Last Updated:Feb 22, 2024

Simple Log Service allows you to convert a measurement or a time interval from the current unit to a different unit by using unit conversion functions. This topic describes the syntax of unit conversion functions. This topic also provides examples on how to use unit conversion functions.

The following table describes the unit conversion functions that are supported by Simple Log Service.

Important If you want to use strings in analytic statements, you must enclose strings in single quotation marks (''). Strings that are not enclosed or 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.

Category

Function

Syntax

Description

Supported in SQL

Supported in SPL

Unit conversion for measurements

convert_data_size function

convert_data_size(x)

Converts a measurement from the current unit to the optimal unit. The system automatically determines the optimal unit and returns a measurement in the optimal unit. The returned result is of the string type. For example, you can convert 1,024 KB to 1 MB and 1,024 MB to 1 GB.

×

convert_data_size(x, unit)

Converts a measurement from the current unit to a specified unit. The returned result is of the string type.

×

format_data_size function

format_data_size(x, unit)

Converts a measurement in byte to a measurement in a specified unit. The returned result is of the string type.

×

parse_data_size function

parse_data_size(x)

Converts a measurement from the current unit to a measurement in byte. The returned result is of the decimal type.

×

to_data_size_B function

to_data_size_B(x)

Converts a measurement from the current unit to a measurement in byte. The returned result is of the double type.

×

to_data_size_KB function

to_data_size_KB(x)

Converts a measurement from the current unit to a measurement in KB. The returned result is of the double type.

×

to_data_size_MB function

to_data_size_MB(x)

Converts a measurement from the current unit to a measurement in MB. The returned result is of the double type.

×

to_data_size_GB function

to_data_size_GB(x)

Converts a measurement from the current unit to a measurement in GB. The returned result is of the double type.

×

to_data_size_TB function

to_data_size_TB(x)

Converts a measurement from the current unit to a measurement in TB. The returned result is of the double type.

×

to_data_size_PB function

to_data_size_PB(x)

Converts a measurement from the current unit to a measurement in PB. The returned result is of the double type.

×

Unit conversion for time intervals

format_duration function

format_duration(x)

Converts a time interval in seconds to a readable string.

×

parse_duration function

parse_duration(x)

Converts a time interval to a time interval in the 0 00:00:00.000 format.

×

to_days function

to_days(x)

Converts a time interval to a time interval in days.

×

to_hours function

to_hours(x)

Converts a time interval to a time interval in hours.

×

to_microseconds function

to_microseconds(x)

Converts a time interval to a time interval in microseconds.

×

to_milliseconds function

to_milliseconds(x)

Converts a time interval to a time interval in milliseconds.

×

to_minutes function

to_minutes(x)

Converts a time interval to a time interval in minutes.

×

to_most_succinct_time_unit function

to_most_succinct_time_unit(x)

Converts a time interval from the current unit to the optimal unit. The system automatically determines the optimal unit and returns a time interval in the optimal unit.

×

to_nanoseconds function

to_nanoseconds(x)

Converts a time interval to a time interval in nanoseconds.

×

to_seconds function

to_seconds(x)

Converts a time interval to a time interval in seconds.

×

convert_data_size function

The convert_data_size function converts a measurement from the current unit to a different unit.

Syntax

  • If you use the following syntax, the function converts a measurement from the current unit to the optimal unit. The system automatically determines the optimal unit and returns a measurement in the optimal unit.

    convert_data_size(x)
  • If you use the following syntax, the function converts a measurement from the current unit to a specified unit.

    convert_data_size(x, unit)

Parameters

Parameter

Description

x

The measurement. The value of this parameter is of the string type.

unit

The unit of stored data. Valid values: KB, MB, GB, PB, TB, EB, ZB, and YB.

Return value type

The string type.

Examples

  • Example 1: Convert 1,200 KB to a measurement in a different unit.

    • Query statement

      * | SELECT convert_data_size('1200KB')
    • Query and analysis resultsconvert_data_size

  • Example 2: Convert the value of the body_bytes_sent field in byte to a measurement in KB. The body_bytes_sent field indicates the number of bytes that are sent to the client.

    • Query statement

      * | select convert_data_size(format_data_size(body_bytes_sent, 'KB'))
    • Query and analysis resultsconvert_data_size

format_data_size function

The format_data_size function converts a measurement in byte to a measurement in a specified unit.

Syntax

format_data_size(x, unit)

Parameters

Parameter

Description

x

The measurement in byte. The value of this parameter is of the bigint type.

unit

The unit of stored data. Valid values: KB, MB, GB, PB, TB, EB, ZB, and YB.

Return value type

The string type.

Examples

  • Example 1: Convert the value of the body_bytes_sent field in byte to a measurement in KB. The body_bytes_sent field indicates the number of bytes that are sent to the client.

    • Sample field

      body_bytes_sent:4619
    • Query statement

      * | select format_data_size(body_bytes_sent, 'KB')
    • Query and analysis results format_data_size

  • Example 2: Convert the total number of bytes to a measurement in GB. The total number of bytes is calculated by adding up all the values of the body_bytes_sent field by using the sum function. The body_bytes_sent field indicates the number of bytes that are sent to the client.

    • Sample field

      body_bytes_sent:4619
    • Query statement

      * | select format_data_size(sum(body_bytes_sent), 'GB')
    • Query and analysis resultsformat_data_size

parse_data_size function

The parse_data_size function converts the current measurement to a measurement in byte.

Syntax

parse_data_size(x)

Parameters

Parameter

Description

x

The measurement. The value of this parameter is of the string type.

Return value type

The decimal type.

Examples

Convert 1,024 KB to a measurement in byte.

  • Query statement

    *| SELECT parse_data_size('1024KB')
  • Query and analysis resultsparse_data_size

to_data_size_B function

The to_data_size_B function converts the current measurement to a measurement in byte.

Syntax

to_data_size_B(x)

Parameters

Parameter

Description

x

The measurement. The value of this parameter is of the string type.

Return value type

The double type.

Examples

Convert 1,024 KB to a measurement in byte.

  • Query statement

    * | select to_data_size_B('1024KB')
  • Query and analysis resultsto_data_size_B

to_data_size_KB function

The to_data_size_KB function converts the current measurement to a measurement in KB.

Syntax

to_data_size_KB(x)

Parameters

Parameter

Description

x

The measurement. The value of this parameter is of the string type.

Return value type

The double type.

Examples

Convert the value of the body_bytes_sent field to a measurement in KB. The body_bytes_sent field indicates the number of bytes that are sent to the client.

  • Query statement

    * | select to_data_size_KB(format_data_size(body_bytes_sent, 'KB'))
  • Query and analysis resultsto_data_size_KB

to_data_size_MB function

The to_data_size_MB function converts the current measurement to a measurement in MB.

Syntax

to_data_size_MB(x)

Parameters

Parameter

Description

x

The measurement. The value of this parameter is of the string type.

Return value type

The double type.

Examples

Convert the total number of bytes to a measurement in MB. The total number of bytes is calculated by adding up all the values of the body_bytes_sent field by using the sum function. The body_bytes_sent field indicates the number of bytes that are sent to the client.

  • Query statement

    * | select to_data_size_MB(format_data_size(sum(body_bytes_sent), 'KB'))
  • Query and analysis resultsto_data_size_MB

to_data_size_GB function

The to_data_size_GB function converts the current measurement to a measurement in GB.

Syntax

to_data_size_GB(x)

Parameters

Parameter

Description

x

The measurement. The value of this parameter is of the string type.

Return value type

The double type.

Examples

Convert the total number of bytes to a measurement in GB. The total number of bytes is calculated by adding up all the values of the body_bytes_sent field by using the sum function. The body_bytes_sent field indicates the number of bytes that are sent to the client.

  • Query statement

    * | select to_data_size_GB(format_data_size(sum(body_bytes_sent), 'KB'))
  • Query and analysis resultsto_data_size_GB

to_data_size_TB function

The to_data_size_TB function converts the current measurement to a measurement in TB.

Syntax

to_data_size_TB(x)

Parameters

Parameter

Description

x

The measurement. The value of this parameter is of the string type.

Return value type

The double type.

Examples

Convert the total number of bytes to a measurement in TB. The total number of bytes is calculated by adding up all the values of the body_bytes_sent field by using the sum function. The body_bytes_sent field indicates the number of bytes that are sent to the client.

  • Query statement

    * | select to_data_size_TB(format_data_size(sum(body_bytes_sent), 'KB'))
  • Query and analysis resultsto_data_size_TB

to_data_size_PB function

The to_data_size_PB function converts the current measurement to a measurement in PB.

Syntax

to_data_size_PB(x)

Parameters

Parameter

Description

x

The measurement. The value of this parameter is of the string type.

Return value type

The double type.

Examples

Convert 1,048,576 GB to a measurement in PB.

  • Query statement

    *| SELECT to_data_size_PB('1048576GB')
  • Query and analysis resultsto_data_size_PB

format_duration function

The format_duration function converts a time interval in seconds to a readable string.

Syntax

format_duration(x)

Parameters

Parameter

Description

x

The time interval. The value of this parameter is of the double type.

Return value type

The string type.

Examples

Convert 235 seconds to a string in the 3 minutes, 55 seconds format.

  • Query statement

    * | SELECT format_duration(235)
  • Query and analysis resultsformat_duration

parse_duration function

The parse_duration function converts a time interval to a time interval in the 0 00:00:00.000 format.

Syntax

parse_duration(x)

Parameters

Parameter

Description

x

The time interval. The value of this parameter is of the string type.

Return value type

The interval type.

Examples

Convert 1,340 milliseconds to a time interval in the 0 00:00:01.340 format.

  • Query statement

    * | SELECT parse_duration('1340ms')
  • Query and analysis resultsparse_duration

to_days function

The to_days function converts a time interval to a time interval in days.

Syntax

to_days(x)

Parameters

Parameter

Description

x

The time interval. The value of this parameter is of the varchar type.

Return value type

The double type.

Examples

Convert 192,848 seconds to a time interval in days.

  • Query statement

    *| SELECT to_days('192848s')
  • Query and analysis resultsto_day

to_hours function

The to_hours function converts a time interval to a time interval in hours.

Syntax

to_hours(x)

Parameters

Parameter

Description

x

The time interval. The value of this parameter is of the varchar type.

Return value type

The double type.

Examples

Convert 1.2 days to a time interval in hours.

  • Query statement

    * | SELECT to_hours('1.2d')
  • Query and analysis resultsto_hours

to_microseconds function

The to_microseconds function converts a time interval to a time interval in microseconds.

Syntax

to_microseconds(x)

Parameters

Parameter

Description

x

The time interval. The value of this parameter is of the varchar type.

Return value type

The double type.

Examples

Convert 3,600 nanoseconds to a time interval in microseconds.

  • Query statement

    * | SELECT to_microseconds('3600ns')
  • Query and analysis resultsto_microseconds

to_milliseconds function

The to_milliseconds function converts a time interval to a time interval in milliseconds.

Syntax

to_milliseconds(x)

Parameters

Parameter

Description

x

The time interval. The value of this parameter is of the varchar type.

Return value type

The double type.

Examples

Convert 1.2 seconds to a time interval in milliseconds.

  • Query statement

    * | SELECT to_milliseconds('1.2s')
  • Query and analysis resultsto_milliseconds

to_minutes function

The to_minutes function converts a time interval to a time interval in minutes.

Syntax

to_minutes(x)

Parameters

Parameter

Description

x

The time interval. The value of this parameter is of the varchar type.

Return value type

The double type.

Examples

Convert 1.2 hours to a time interval in minutes.

  • Query statement

    * | SELECT to_minutes('1.2h')
  • Query and analysis resultsto_minutes

to_most_succinct_time_unit function

The to_most_succinct_time_unit function converts a time interval from the current unit to the optimal unit. The system automatically determines the optimal unit and returns a time interval in the optimal unit.

Syntax

to_most_succinct_time_unit(x)

Parameters

Parameter

Description

x

The time interval. The value of this parameter is of the varchar type.

Return value type

The varchar type.

Examples

Convert 1,340 milliseconds to a time interval in seconds.

  • Query statement

    * | SELECT to_most_succinct_time_unit('1340ms')
  • Query and analysis resultsto_most_succinct_time_unit

to_nanoseconds function

The to_nanoseconds function converts a time interval to a time interval in nanoseconds.

Syntax

to_nanoseconds(x)

Parameters

Parameter

Description

x

The time interval. The value of this parameter is of the varchar type.

Return value type

The double type.

Examples

Convert 125 milliseconds to a time interval in nanoseconds.

  • Query statement

    * | SELECT to_nanoseconds('125ms')
  • Query and analysis resultsto_nanoseconds

to_seconds function

The to_seconds function converts a time interval to a time interval in seconds.

Syntax

to_seconds(x)

Parameters

Parameter

Description

x

The time interval. The value of this parameter is of the varchar type.

Return value type

The double type.

Examples

Convert 1,340 milliseconds to a time interval in seconds.

  • Query statement

    * | SELECT to_seconds('1340ms')
  • Query and analysis resultsto_seconds