Object Functions
Object functions are used to manipulate objects/maps.
KEYS
keys(obj)
Return an array containing the keys of the map.
example:
keys({"a":1, "b":2})
result:
["a","b"]
VALUES
values(obj)
example:
values({"a":1, "b":2})
result:
[1,2]
Return an array containing the values of the map.
OBJECT
object(keys, values)
Construct an object from an array of keys and an array of values. Keys must be an array of strings. Values must be an arbitrary array of the same length as keys.
example:
object(["a","b"],[1,2])
result:
{"a":1, "b":2}
ZIP
zip(entries)
Construct an object from an array of entries. Each entry must itself be an array of size 2: the first element is the key (and must be a string), and the second element is the value.
example:
zip([["a",1],["b":2]])
result:
{"a":1, "b":2}
ITEMS
items(obj)
Return an array containing the entries of object. Each entry is a 2-element array; the first is the key, the second is the value.
example:
items({"a":1, "b":2})
result:
[["a",1],["b":2]]
OBJECT_CONSTRUCT
object_construct(key1, col1, key2, col2, ...)
Return a struct type object/map constructed by the arguments. The arguments are a series of key value pairs, thus the arguments count must be an odd number. The key must be a string, and the value can be of any type. If the value is null, the key/value pair will not present in the final object.
example:
object_construct("a", 1, "b", 2)
result:
{"a":1, "b":2}
OBJECT_CONCAT
object_concat(obj1, obj2, ...)
This function concatenates the input objects and returns a new object. It requires a minimum of two input objects. In cases where there are duplicate attribute names among the input objects, the attribute from the last relevant object in the input list is selected and copied to the output object. To illustrate, here's an example:
object_concat({"a": 1}, {"b": 2}, {"b": 3})
result:
{"a":1, "b":3}
ERASE
erase(obj, k)
If k is a string, return a new object where the key k is erased. If k is an array of strings, return a new object where the keys in k are erased.
erase({"baz": [1, 2, 3], "bar": 'hello world',"foo":'emq'}, 'foo')
result:
{"baz": [1, 2, 3], "bar": 'hello world'}
OBJECT_PICK
object_pick(obj, k)
If k is a string, return a new object where the key k is preserved. If k is an array of strings, return a new object where the keys in k are preserved.
object_pick({"baz": [1, 2, 3], "bar": 'hello world',"foo":'emq'}, 'foo')
result:
{"foo":'emq'}
OBJ_TO_KVPAIR_ARRAY
obj_to_kvpair_array(obj)
Return an array of key-value pairs converted from an object.
obj_to_kvpair_array({"key1":1, "key2":2})
result:
[{"key":"key1", "value":1},{"key":"key2", "value":2}]