Function library

We list here the most important functions supported by RumbleDB, and introduce them by means of examples. Highly detailed specifications can be found in the underlying W3C standardarrow-up-right, unless the function is marked as specific to JSON or RumbleDB, in which case it can be found herearrow-up-right. JSONiq and RumbleDB intentionally do not support builtin functions on XML nodes, NOTATION or QNames. RumbleDB supports almost all other W3C-standardized functions, please contact us if you are still missing one.

For the sake of ease of use, all W3C standard builtin functions and JSONiq builtin functions are in the RumbleDB namespace, which is the default function namespace and does not require any prefix in front of function names.

It is recommended that user-defined functions are put in the local namespace, i.e., their name should have the local: prefix (which is predefined). Otherwise, there is the risk that your code becomes incompatible with subsequent releases if new (unprefixed) builtin functions are introduced.

Errors and diagnostics

Diagnostic tracing

trace

W3C specificationarrow-up-right

Fully implemented

trace(1 to 3)

returns (1, 2, 3) and logs it in the log-path if specified

Functions and operators on numerics

Functions on numeric values

abs

W3C specificationarrow-up-right

Fully implemented

returns 2.0

ceiling

W3C specificationarrow-up-right

Fully implemented

returns 3.0

floor

W3C specificationarrow-up-right

Fully implemented

returns 2.0

round

W3C specificationarrow-up-right

Fully implemented

returns 2.0

returns 2.23

round-half-to-even

W3C specificationarrow-up-right

Fully implemented

Parsing numbers

number

W3C specificationarrow-up-right

Fully implemented

returns 15 as a double

returns NaN as a double

returns 15 as a double

Formatting integers

format-integer

W3C specificationarrow-up-right

Not implemented

##Formatting numbers

format-number

W3C specificationarrow-up-right

Not implemented

##Trigonometric and exponential functions

###pi W3C specificationarrow-up-right

Fully implemented

returns 3.141592653589793

###exp W3C specificationarrow-up-right

Fully implemented

###exp10 W3C specificationarrow-up-right

Fully implemented

log

W3C specificationarrow-up-right

Fully implemented

log10

W3C specificationarrow-up-right

Fully implemented

pow

W3C specificationarrow-up-right

Fully implemented

sqrt

W3C specificationarrow-up-right

Fully implemented

returns 2

sin

W3C specificationarrow-up-right

Fully implemented

cos

W3C specificationarrow-up-right

Fully implemented

cosh

JSONiq-specific. Fully implemented

sinh

JSONiq-specific. Fully implemented

tan

W3C specificationarrow-up-right

Fully implemented

asin

W3C specificationarrow-up-right

Fully implemented

acos

W3C specificationarrow-up-right

Fully implemented

atan

W3C specificationarrow-up-right

Fully implemented

atan2

W3C specificationarrow-up-right

Fully implemented

Random numbers

random-number-generator

W3C specificationarrow-up-right

Not implemented

Functions on strings

Functions to assemble and disassemble strings

string-to-codepoint

W3C specificationarrow-up-right

Fully implemented

returns (84, 104, 233, 114, 232, 115, 101)

returns ()

codepoints-to-string

W3C specificationarrow-up-right

Fully implemented

returns "अशॊक"

returns ""

Comparison of strings

compare

W3C specificationarrow-up-right

Fully implemented

returns -1

codepoint-equal

W3C specificationarrow-up-right

Fully implemented

returns true

returns ()

collation-key

W3C specificationarrow-up-right

Not implemented

contains-token

W3C specificationarrow-up-right

Not implemented

Functions on string values

concat

W3C specificationarrow-up-right

Fully implemented

returns "foobarfoobar"

string-join

W3C specificationarrow-up-right

Fully implemented

returns "foobarfoobar"

returns "foo-bar-foobar"

substring

W3C specificationarrow-up-right

Fully implemented

returns "bar"

returns "ba"

string-length

W3C specificationarrow-up-right

Fully implemented

Returns the length of the supplied string, or 0 if the empty sequence is supplied.

returns 3.

returns 0.

###normalize-space W3C specificationarrow-up-right

Fully implemented

Normalization of spaces in a string.

returns "The wealthy curled darlings of our nation."

normalize-unicode

W3C specificationarrow-up-right

Fully implemented

Returns the value of the input after applying Unicode normalization.

returns the unicode-normalized version of the input string. Normalization forms NFC, NFD, NFKC, and NFKD are supported. "FULLY-NORMALIZED" though supported, should be used with caution as only the composition exclusion characters supported FULLY-NORMALIZED are which are uncommented in the following filearrow-up-right.

upper-case

W3C specificationarrow-up-right

Fully implemented

returns "ABCD0"

lower-case

W3C specificationarrow-up-right

Fully implemented

returns "abc!d"

translate

W3C specificationarrow-up-right

Fully implemented

returns "BAr"

returns "AAA"

Functions based on substring matching

contains

W3C specificationarrow-up-right

Fully implemented

returns true.

starts-with

W3C specificationarrow-up-right

Fully implemented

returns true

ends-with

W3C specificationarrow-up-right

Fully implemented

returns true.

substring-before

W3C specificationarrow-up-right

Fully implemented

returns "foo"

returns "f"

substring-after

W3C specificationarrow-up-right

Fully implemented

returns "bar"

returns ""

String functions that use regular expressions

matches

W3C specificationarrow-up-right

Arity 2 implemented, arity 3 is not.

Regular expression matching. The semantics of regular expressions are those of Java's Pattern class.

returns true.

returns true.

replace

W3C specificationarrow-up-right

Arity 3 implemented, arity 4 is not.

Regular expression matching and replacing. The semantics of regular expressions are those of Java's Pattern class.

returns "a*cada*"

returns "abbraccaddabbra"

tokenize

W3C specificationarrow-up-right

Arity 2 implemented, arity 3 is not.

returns ("aa", "bb", "cc", "dd")

returns ("aa", "bb", "cc", "dd")

analyze-string

W3C specificationarrow-up-right

Not implemented

Functions that manipulate URIs

resolve-uri

W3C specificationarrow-up-right

Fully implemented

returns http://www.examples.com/examples

encode-for-uri

W3C specificationarrow-up-right

Fully implemented

returns 100%25%20organic

iri-to-uri

W3C specificationarrow-up-right

Not implemented

escape-html-uri

W3C specificationarrow-up-right

Not implemented

Functions and operators on Boolean values

Boolean constant functions

true

W3C specificationarrow-up-right

Fully implemented

returns true

false

W3C specificationarrow-up-right

Fully implemented

returns false

boolean

W3C specificationarrow-up-right

Fully implemented

returns true

returns false

not

W3C specificationarrow-up-right

Fully implemented

returns false

returns true

Functions and operators on durations

Component extraction functions on durations

years-from-duration

W3C specificationarrow-up-right

Fully implemented

returns 2021.

months-from-duration

W3C specificationarrow-up-right

Fully implemented

returns 6.

days-from-duration

W3C specificationarrow-up-right

Fully implemented

returns 17.

hours-from-duration

W3C specificationarrow-up-right

Fully implemented

returns 12.

minutes-from-duration

W3C specificationarrow-up-right

Fully implemented

returns 35.

seconds-from-duration

W3C specificationarrow-up-right

Fully implemented

returns 30.

Functions and operators on dates and times

Constructing a DateTime

dateTime

W3C specificationarrow-up-right

Fully implemented

returns 2004-04-12T13:20:00+14:00

Component extraction functions on dates and times

year-from-dateTime

W3C specificationarrow-up-right

Fully implemented

returns 2021.

month-from-dateTime

W3C specificationarrow-up-right

Fully implemented

returns 04.

day-from-dateTime

W3C specificationarrow-up-right

Fully implemented

returns 12.

hours-from-dateTime

W3C specificationarrow-up-right

Fully implemented

returns 13.

minutes-from-dateTime

W3C specificationarrow-up-right

Fully implemented

returns 20.

seconds-from-dateTime

W3C specificationarrow-up-right

Fully implemented

returns 32.

timezone-from-dateTime

W3C specificationarrow-up-right

Fully implemented

returns PT2H.

year-from-date

W3C specificationarrow-up-right

Fully implemented

returns 2021.

month-from-date

W3C specificationarrow-up-right

Fully implemented

returns 6.

day-from-date

W3C specificationarrow-up-right

Fully implemented

returns 4.

timezone-from-date

W3C specificationarrow-up-right

Fully implemented

returns -PT14H.

hours-from-time

W3C specificationarrow-up-right

Fully implemented

returns 13.

minutes-from-time

W3C specificationarrow-up-right

Fully implemented

returns 20.

seconds-from-time

W3C specificationarrow-up-right

Fully implemented

returns 32.123.

timezone-from-time

W3C specificationarrow-up-right

Fully implemented

returns PT2H.

Timezone adjustment functions on dates and time values

adjust-dateTime-to-timezone

W3C specificationarrow-up-right

Fully implemented

returns 2004-04-12T03:25:15+04:05.

adjust-date-to-timezone

W3C specificationarrow-up-right

Fully implemented

returns 2014-03-12+04:00.

adjust-time-to-timezone

W3C specificationarrow-up-right

Fully implemented

returns 04:20:00-14:00.

Formatting dates and times functions

The functions in this section accept a simplified version of the picture string, in which a variable marker accepts only:

  • One of the following component specifiers: Y, M, d, D, F, H, m, s, P

  • A first presentation modifier, for which the value can be:

    • Nn, for all supported component specifiers, besides P

    • N, if the component specifier is P

    • a format token that indicates a numbering sequence of the the following form: '0001'

  • A second presentation modifier, for which the value can be t or c, which are also the default values

  • A width modifier, both minimum and maximum values

format-dateTime

W3C specificationarrow-up-right

Fully implemented

returns 20-13-12-4-2004

format-date

W3C specificationarrow-up-right

Fully implemented

returns 12-4-2004

format-time

W3C specificationarrow-up-right

Fully implemented

returns 13-20-0

Not implemented

Functions and operators on sequences

General functions and operators on sequences

empty

W3C specificationarrow-up-right

Fully implemented

Returns a boolean whether the input sequence is empty or not.

returns false.

exists

W3C specificationarrow-up-right

Fully implemented

Returns a boolean whether the input sequence has at least one item or not.

returns true.

returns false.

This is pushed down to Spark and works on big sequences.

W3C specificationarrow-up-right

Fully implemented

Returns the first item of a sequence, or the empty sequence if it is empty.

returns 1.

returns ().

This is pushed down to Spark and works on big sequences.

tail

W3C specificationarrow-up-right

Fully implemented

Returns all but the last item of a sequence, or the empty sequence if it is empty.

returns (2, 3, 4, 5).

returns ().

This is pushed down to Spark and works on big sequences.

insert-before

W3C specificationarrow-up-right

Fully implemented

returns (1, 2, 3, 4, 5).

remove

W3C specificationarrow-up-right

Fully implemented

returns (1, 2).

reverse

W3C specificationarrow-up-right

Fully implemented

returns (3, 2, 1).

subsequence

W3C specificationarrow-up-right

Fully implemented

returns (2, 3).

unordered

W3C specificationarrow-up-right

Fully implemented

returns (1, 2, 3).

Functions that compare values in sequences

distinct-values

W3C specificationarrow-up-right

Fully implemented

Eliminates duplicates from a sequence of atomic items.

returns (1, 4, 3, "foo", true, 5).

This is pushed down to Spark and works on big sequences.

index-of

W3C specificationarrow-up-right

Fully implemented

returns 3.

returns "".

deep-equal

W3C specificationarrow-up-right

Fully implemented

returns true.

returns false.

Functions that test the cardinality of sequences

zero-or-one

W3C specificationarrow-up-right

Fully implemented

returns "a".

returns an error.

one-or-more

W3C specificationarrow-up-right

Fully implemented

returns "a".

returns an error.

exactly-one

W3C specificationarrow-up-right

Fully implemented

returns "a".

returns an error.

Aggregate functions

count

W3C specificationarrow-up-right

Fully implemented

returns 4.

Count calls are pushed down to Spark, so this works on billions of items as well:

avg

W3C specificationarrow-up-right

Fully implemented

returns 2.5.

Avg calls are pushed down to Spark, so this works on billions of items as well:

max

W3C specificationarrow-up-right

Fully implemented

returns 4.

returns (1, 2, 3).

Max calls are pushed down to Spark, so this works on billions of items as well:

min

W3C specificationarrow-up-right

Fully implemented

returns 1.

returns (1, 2, 3).

Min calls are pushed down to Spark, so this works on billions of items as well:

sum

W3C specificationarrow-up-right

Fully implemented

returns 10.

Sum calls are pushed down to Spark, so this works on billions of items as well:

Functions giving access to external information

doc

W3C specificationarrow-up-right

Fully implemented

Returns the corresponding document node

collection

W3C specificationarrow-up-right

Not implemented

Parsing and serializing

serialize

W3C specificationarrow-up-right

Fully implemented

Serializes the supplied input sequence, returning the serialized representation of the sequence as a string

returns { "hello" : "world" }

Context Functions

position

W3C specificationarrow-up-right

Fully implemented

returns 5

last

W3C specificationarrow-up-right

Fully implemented

returns 10

returns 10

current-dateTime

W3C specificationarrow-up-right

Fully implemented

returns 2020-02-26T11:22:48.423+01:00

current-date

W3C specificationarrow-up-right

Fully implemented

returns 2020-02-26Europe/Zurich

current-time

W3C specificationarrow-up-right

Fully implemented

returns 11:24:10.064+01:00

implicit-timezone

W3C specificationarrow-up-right

Fully implemented

returns PT1H.

default-collation

W3C specificationarrow-up-right

Fully implemented

returns http://www.w3.org/2005/xpath-functions/collation/codepoint.

High order functions

Functions on functions

function-lookup

W3C specificationarrow-up-right

Not implemented

function-name

W3C specificationarrow-up-right

Not implemented

function-arity

W3C specificationarrow-up-right

Not implemented

Basic higher-order functions

for-each

W3C specificationarrow-up-right

Not implemented

filter

W3C specificationarrow-up-right

Not implemented

fold-left

W3C specificationarrow-up-right

Not implemented

fold-right

W3C specificationarrow-up-right

Not implemented

for-each-pair

W3C specificationarrow-up-right

Not implemented

JSONiq functions

keys

JSONiq specificationarrow-up-right

Fully implemented

returns ("foo", "bar"). Also works on an input sequence, eliminating duplicates

Keys calls are pushed down to Spark, so this works on billions of items as well:

members

JSONiq specificationarrow-up-right

Fully implemented

This function returns the members as an array, but not recursively, i.e., nested arrays are not unboxed.

Returns the first 100 integers as a sequence. Also works on an input sequence, in a distributive way.

null

JSONiq specificationarrow-up-right

Fully implemented

Returns a JSON null (also available as the literal null).

parse-json

JSONiq specificationarrow-up-right

Fully implemented

size

JSONiq specificationarrow-up-right

Fully implemented

returns 100. Also works if the empty sequence is supplied, in which case it returns the empty sequence.

accumulate

JSONiq specificationarrow-up-right

Fully implemented

returns

descendant-arrays

JSONiq specificationarrow-up-right

Fully implemented

returns

descendant-objects

JSONiq specificationarrow-up-right

Fully implemented

returns

descendant-pairs

JSONiq specificationarrow-up-right

Fully implemented

returns

flatten

JSONiq specificationarrow-up-right

Fully implemented

Unboxes arrays recursively, stopping the recursion when any other item is reached (object or atomic). Also works on an input sequence, in a distributive way.

Returns (1, 2, 3, 4, 5, 6, 7, 8, 9).

intersect

JSONiq specificationarrow-up-right

Fully implemented

returns

project

JSONiq specificationarrow-up-right

Fully implemented

returns the object {"foo" : "bar", "bar" : "foobar"}. Also works on an input sequence, in a distributive way.

remove-keys

JSONiq specificationarrow-up-right

Fully implemented

returns the object {"foobar" : "foo"}. Also works on an input sequence, in a distributive way.

values

JSONiq specificationarrow-up-right

Fully implemented

returns ("bar", "foobar"). Also works on an input sequence, in a distributive way.

Values calls are pushed down to Spark, so this works on billions of items as well:

encode-for-roundtrip

JSONiq specificationarrow-up-right

Not implemented

decode-from-roundtrip

JSONiq specificationarrow-up-right

Not implemented

json-doc

returns the (unique) JSON value parsed from a local JSON (but not necessarily JSON Lines) file where this value may be spread over multiple lines.

Last updated