Skip to content

Commit

Permalink
switch to javascript udf
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <[email protected]>
  • Loading branch information
wangrunji0408 committed Feb 8, 2024
1 parent d8c2c38 commit 0eec285
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
12 changes: 8 additions & 4 deletions ci/scripts/sql/nexmark/q14.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
-- noinspection SqlNoDataSourceInspectionForFile
-- noinspection SqlResolveForFile

CREATE FUNCTION count_char(s varchar, c varchar) RETURNS int LANGUAGE rust AS $$
fn count_char(s: &str, c: &str) -> i32 {
s.matches(c).count() as i32
}
CREATE FUNCTION count_char(s varchar, c varchar) RETURNS int LANGUAGE javascript AS $$
var count = 0;
for (var cc of s) {
if (cc === c) {
count++;
}
}
return count;
$$;

CREATE SINK nexmark_q14 AS
Expand Down
12 changes: 8 additions & 4 deletions e2e_test/streaming/nexmark/sinks/q14.slt.part
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
statement ok
CREATE FUNCTION count_char(s varchar, c varchar) RETURNS int LANGUAGE rust AS $$
fn count_char(s: &str, c: &str) -> i32 {
s.matches(c).count() as i32
}
CREATE FUNCTION count_char(s varchar, c varchar) RETURNS int LANGUAGE javascript AS $$
var count = 0;
for (var cc of s) {
if (cc === c) {
count++;
}
}
return count;
$$;

statement ok
Expand Down
12 changes: 8 additions & 4 deletions e2e_test/streaming/nexmark/views/q14.slt.part
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
statement ok
CREATE FUNCTION count_char(s varchar, c varchar) RETURNS int LANGUAGE rust AS $$
fn count_char(s: &str, c: &str) -> i32 {
s.matches(c).count() as i32
}
CREATE FUNCTION count_char(s varchar, c varchar) RETURNS int LANGUAGE javascript AS $$
var count = 0;
for (var cc of s) {
if (cc === c) {
count++;
}
}
return count;
$$;

statement ok
Expand Down

0 comments on commit 0eec285

Please sign in to comment.