Currently streaming Change Data Capture events from MongoDB into snowflake, would like to apply them to the raw data that is already there.
Let's say I have a table like this:
+---------------------+-----------------+-----------+
| key | value | document |
+---------------------+-----------------+-----------+
| foo.bar | "changed value" | <variant> |
| foo.stuff.anArray.1 | 1000 | <variant> |
| ... | ... | ... |
+---------------------+-----------------+-----------+
Where variant contains a very heavily nested JSON ex:
{
"foo": {
"bar": "Some info",
"baz": "Other info",
"stuff": {
"anArray": [1, 2, 3],
"things": "More nested info"
}
}
}
I would like to use OBJECT_DELETE
and OBJECT_INSERT
functions to update this nested variant data in snowflake.
Tried making a js UDF but eval()
is not supported.
Other approaches like writing a UDF that does key.split(".")
and then recursively walking the structure and updating the field seem to take a long time and fail with JavaScript out of memory error: UDF thread memory limit exceeded
in some cases.
Looking for a bit more efficient way to solve this issue.
[1, 1000, 3]
. I the Idea was for it to function the same asOBJECT_INSERT
but with the ability to go deeper into json. – ElvisElvisvariant
is the existing data and thekey, value
is the parsed information coming from mongodb CDC. – ElvisElvis