Built-in query language functions

Like constants and variables, there are many built-in functions that can be called from the query language with no additional imports or setup. In most cases, users will prefer these built-in functions over user-defined functions in query strings because:

  • They are coded with an eye for performance and correctness.
  • Ease of use - built-in functions don't require any additional coding.

Built-in functions

Built-in functions range from simple mathematical functions to date-time arithmetic, string manipulation, and more.

The following query calculates the absolute value of a column using the built-in abs function:

source = emptyTable(10).update("X = -ii", "AbsX = abs(X)")

The following query parses a column of strings containing integers into Java primitive int values using parseInt:

source = emptyTable(10).update("StringColumn = Integer.toString(randomInt(0, 9))")
result = source.update("IntegerColumn = parseInt(StringColumn)")

The following query uses the built-in and function to evaluate whether or not three different columns are all true:

source = newTable(
    booleanCol("A", true, true, true),
    booleanCol("B", true, true, false),
    booleanCol("C", true, false, true),
)
result = source.update("IsOk = and(A, B, C)")

Built-in functions gracefully handle null values as input. For example, the following example calls the built-in sin function on a column that contains null values:

source = emptyTable(40).update(
    "X = (ii % 3 != 0) ? 0.1 * ii : NULL_DOUBLE", "SinX = sin(X)"
)

This page does not provide a comprehensive list of all built-ins. For the complete list of functions built into the query language, see Auto-imported functions.