String() and Concat() now available in NRQL!

We have added the functions string( ) and concat( ) to the NRQL Language! Come take a look at these new additions.

String

The string function can be used to convert a numeric, boolean, tuple, or array value into a string:

  • string(attribute [, precision: ]))

Simply enter the attribute you would like to cast to a string, and if you like, add a precision value indicating the number of decimal places to include when converting to a string.

Examples:

  • string(duration) = ‘2.06596E-4’
  • string(duration, precision: 2) = ‘2.07’

This is particularly useful when wanting to FACET on a number with decimal places. When you FACET the number is truncated to a whole number, but now you can use string to solve this!:

  • FROM Transaction SELECT count(*) FACET string(duration, 2)

Concat

The concat function can be used to combine up to 20 values together into a single string. You can combine string, numeric, boolean, tuple, or array types to this function to combine data in new ways:

  • concat(attribute, [, attribute [, ...]] [, precision: ]))

The precision argument can again be used to limit the number of decimal places.

Examples:

  • concat(‘The duration is: ‘, duration) = ‘The duration is: 2.06596E-4’
  • concat(‘The duration is: ‘, duration, precision: 2) = ‘The duration is: 2.07’

Now you can combine your data in different ways! This can be useful when extracting data from Logs:

  • FROM Log SELECT count(*) FACET concat(capture(message, '.*statusCode":(?P<StatusCode>(.*?)),.*?'), '-', capture(message, '.*customerId":"(?P<CustomerID>(.*?))".*?'))

In this example you can extract the status code and customer ID from your log, then concat these values into a ‘statusCode-customerID’ format. With this format you can find the most common occurrences of a status code and customer combination.

Limitations

Note that the resulting string can have a maximum length of 4096 characters.
Also, aggregate functions cannot be used with concat. For example:

  • UNSUPPORTED: FROM Transaction SELECT concat(average(duration), ‘ seconds’)
2 Likes