'Extending Snowflake with Javascript UDFs
I'm trying to extend Snowflake's functionality with generic javascript functions - especially for array processing - i.e. map, filter, reduce.
I've written this simple function which works fine
create function map(A array)
returns array
language javascript
as
$$
return A.map(x => x.balance)
$$
This works fine
select map(myarray) from mytable;
Now I want to pass my map requirement (x => x.balance) as a parameter to the function i.e.
create or replace function map(A array, MAP string)
returns array
language javascript
as
$$
return A.map(MAP)
$$
So I can execute
select map(myarray,'x => x.balance') from mytable;
but this doesn't work - how can I achieve this, and even better if I could create a completely generic snowflake function that give me all JS functions e.g.
create function JS (func string)
returns array
language javascript
as
$$
return func
$$
so I could then just run
select js(myarray.map(x => x.balance)) from mytable;
or then any javascript array function
Many thanks everyone for your suggestions :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
