Maps

Attention

Map type currently not implemented.

Construction

Maps can be constructed with the following syntaxes:

{<expression>: <expression>, ...}

Example: {"key1": 1, "key2": 2.0}

Constructs a map of type map(string, double not null). Keys are strings. Value is double because 2.0 is a double.

map(<idn>=<expression>, ...)

Example: map(string, double null)

In this syntax identifiers are always keys of type string. Equivalent to {"key1": 1, "key 2": null}

Membership: IN / NOT IN

Check if a key is contained or not in the map.

Syntax:

<expression> IN <map>
<expression> NOT IN <map>

For example:

"x" in map(x="foo") // true
"foo" in map(x="foo") // false
null in map(x="foo") // null

INTERSECT

Returns the intersection of two maps based on their keys. Both maps must have compatible types.

Syntax:

<map> INTERSECT <map>

For example:

{"x": 1, "y": 2} INTERSECT {"x": 3} // {"x" :1}

Attention

INTERSECT not currently implemented.

EXCEPT

Returns the first map without the keys in the second map. Both maps must have compatible types.

Syntax:

<map> EXCEPT <collection>

For example:

{"x": 1, "y": 2} EXCEPT {"x": 3} // {"y": 2}

Attention

EXCEPT not currently implemented.

Merge: ++

Merge two maps. If keys overlap, the value from the first map is preserved.

Syntax:

<map> ++ <map>

For example:

{"a": 1.0, "b": 2.0"} ++ {"c": 3.0} // {"a": 1.0, "b": 2.0", "c": 3.0}
{"a": 1.0, "b": 2.0"} ++ null // {"a": 1.0, "b": 2.0"}
null ++ {"a": 1.0, "b": 2.0"} // {"a": 1.0, "b": 2.0"}
{"a": 1.0} ++ {"a": 2.0} // {"a": 1.0}

Index Operations

Index operations are used to extract the value from the map.

The variant with suffix ? returns null instead of a runtime error for keys not in the map.

Syntax:

<map>[<key>]
<map>[<key>]?

For example:

m["a"] // 1.0
m["c"] // Runtime error
m["c"]? // null

KEYS

Return collection of keys in the map. Order is not guaranteed.

Syntax:

KEYS(<map>)

For example:

keys({true: 1, false: 0, null: -1}) \\ [true, false, null]

VALUES

Return collection of values in the map. Order is not guaranteed.

Syntax:

VALUES(<map>)

For example:

keys({true: 1, false: 0, null: -1}) \\ [1, 0, -1]

Comparisons

Maps cannot be compared with equality operators (=, <>, etc). However, maps can be compared using IS DISTINCT FROM / IS NOT DISTINCT FROM as described in Comparisons.

Casts

Maps cannot be casted to other types.