get_field¶
Description¶
Given an object, and a computed string value as key (which can be a column value or some string concatenation, for example), look up whether that key exists in that object. If so, return the corresponding value. If the key doesn’t exist, return null.
This looks up a single key only. A period in the key value, for example as
in foo.element1
, is simply another character in the key. If you need to
look up foo[bar][baz]
, where both bar
and baz
are computed values or
column values, then chain multiple calls to get_field()
.
If you know the exact key name you want to look up, it is more efficient to use
regular dot-path syntax: myobj.field
is more efficient than get_field(myobj, 'field')
.
For more advanced extraction and filtering on object data, please refer to get_jmespath.
Return type¶
variant
Domain¶
This is a scalar function (calculates a single output value for a single input row.)
Categories¶
Usage¶
get_field(object, field)
Argument |
Type |
Optional |
Repeatable |
Restrictions |
---|---|---|---|---|
object |
object |
no |
no |
none |
field |
string |
no |
no |
none |
Examples¶
make_col somekey:strcat("bar")
make_col someobj:make_object("foo":1, "bar":2)
make_col final:int64(get_field(someobj, somekey))
drop_col somekey, someobj
Make a new column final
that contains the value 2. It does this by constructing
an object in a temporary column someobj
and a key in a temporary column somekey
and then looking up the value of that key in the object. Because object lookup
returns variant
, the value is cast to an int64
.
make_col final:object(get_field(get_field(data_obj, data_key), strcat(data_key, "_inner")))
Make a new column final
that contains the value of the field determined by the
column data_key, further indexed by that same key with the string "_inner"
added.
Given the following input value, and the value data
in the column named data_key
,
you will get the output value below.
Input:
data_key: "data",
data_obj:{
"some_key": 1234,
"data": {
"data_inner":{
"very": "recursive"
},
"score": 3.14
},
"value": "snrk"
}
Output:
{
"very": "recursive"
}