typeof()

The typeof() function returns the data type name of the value passed as an argument as a string.

Syntax

typeof(EXPR)

Parameters

EXPR
A field name or expression whose type to check.

Description

The typeof() function returns one of the following strings based on the data type of the result of evaluating EXPR.

Return valueDescription
"string"String
"int"32-bit integer
"long"64-bit integer
"short"16-bit integer
"double"64-bit floating-point
"float"32-bit floating-point
"bool"Boolean
"ipv4"IPv4 address
"ipv6"IPv6 address
"date"Timestamp
"map"Map
"list"List
"byte[]"Byte array
"int[]"32-bit integer array
"long[]"64-bit integer array
"short[]"16-bit integer array
"double[]"64-bit floating-point array
"float[]"32-bit floating-point array
"bool[]"Boolean array
"object[]"Object array

If the result of evaluating EXPR is null, returns null.

Error codes

N/A

Usage examples

To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.

  1. Checking the type of the string-type method field

    table limit=5 WEB_APACHE_SAMPLE | eval result = typeof(method) | fields method, result
    | # result: "string"
    
  2. Checking the type of the integer-type status field

    table limit=5 WEB_APACHE_SAMPLE | eval result = typeof(status) | fields status, result
    | # result: "int"
    
  3. Checking the type of the IP address-type src_ip field

    table limit=5 WEB_APACHE_SAMPLE | eval result = typeof(src_ip) | fields src_ip, result
    | # result: "ipv4"
    
  4. Checking the type of the timestamp-type _time field

    table limit=5 WEB_APACHE_SAMPLE | eval result = typeof(_time) | fields _time, result
    | # result: "date"
    
  5. NULL input

    json "{'val': null}" | eval result = typeof(val)
    | # result: null
    

Compatibility

The typeof() function has been available since before Sonar 4.0.