Skip to content

Commit

Permalink
support jsonb type
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <[email protected]>
  • Loading branch information
wangrunji0408 committed Jan 15, 2024
1 parent 677fe1a commit 3121e9a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ arrow-flight = "50"
arrow-select = "50"
arrow-ord = "50"
arrow-row = "50"
arrow-udf-js = { git = "https://github.com/risingwavelabs/arrow-udf.git", rev = "0cc8391" }
arrow-udf-js = { git = "https://github.com/risingwavelabs/arrow-udf.git", rev = "70fae28" }
arrow-udf-wasm = "0.1"
arrow-array-deltalake = { package = "arrow-array", version = "48.0.1" }
arrow-buffer-deltalake = { package = "arrow-buffer", version = "48.0.1" }
Expand Down
33 changes: 29 additions & 4 deletions e2e_test/udf/js_udf.slt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $$;

statement ok
create function gcd(a int, b int) returns int language javascript as $$
// required before we support `RETURNS NULL ON NULL INPUT`
if(a == null || b == null) {
return null;
}
Expand All @@ -17,8 +18,24 @@ create function gcd(a int, b int) returns int language javascript as $$
$$;

statement ok
create function to_string(a boolean, b smallint, c int, d bigint, e real, f float, g varchar) returns varchar language javascript as $$
return a.toString() + b.toString() + c.toString() + d.toString() + e.toString() + f.toString() + g.toString();
create function to_string(a boolean, b smallint, c int, d bigint, e real, f float, g varchar, h bytea, i jsonb) returns varchar language javascript as $$
return a.toString() + b.toString() + c.toString() + d.toString() + e.toString() + f.toString() + g.toString() + h.toString() + JSON.stringify(i);
$$;

# show data types in javascript
statement ok
create function js_typeof(a boolean, b smallint, c int, d bigint, e real, f float, g varchar, h bytea, i jsonb) returns jsonb language javascript as $$
return {
boolean: `${typeof a}`,
smallint: `${typeof b}`,
int: `${typeof c}`,
bigint: `${typeof d}`,
real: `${typeof e}`,
float: `${typeof f}`,
varchar: `${typeof g}`,
bytea: `${typeof h}`,
jsonb: `${typeof i}`,
};
$$;

statement ok
Expand All @@ -39,9 +56,14 @@ select gcd(25, 15);
5

query T
select to_string(false, 1::smallint, 2, 3, 4.5, 6.7, 'abc');
select to_string(false, 1::smallint, 2, 3, 4.5, 6.7, 'abc', '\x010203', '{"key": 1}');
----
false1234.56.7abc1,2,3{"key":1}

query T
select js_typeof(false, 1::smallint, 2, 3, 4.5, 6.7, 'abc', '\x010203', '{"key": 1}');
----
false1234.56.7abc
{"bigint": "number", "boolean": "boolean", "bytea": "object", "float": "number", "int": "number", "jsonb": "object", "real": "number", "smallint": "number", "varchar": "string"}

query I
select series(5);
Expand All @@ -63,3 +85,6 @@ drop function to_string;

statement ok
drop function series;

statement ok
drop function js_typeof;

0 comments on commit 3121e9a

Please sign in to comment.