Skip to content

Commit

Permalink
enable udf in nexmark q14
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <[email protected]>
  • Loading branch information
wangrunji0408 committed Feb 4, 2024
1 parent f5386ca commit 7b640e2
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 31 deletions.
1 change: 1 addition & 0 deletions ci/scripts/sql/nexmark/q14.drop.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- noinspection SqlNoDataSourceInspectionForFile
-- noinspection SqlResolveForFile
DROP SINK nexmark_q14;
DROP FUNCTION count_char;
14 changes: 9 additions & 5 deletions ci/scripts/sql/nexmark/q14.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
-- 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 SINK nexmark_q14 AS
SELECT auction,
bidder,
Expand All @@ -15,11 +22,8 @@ SELECT auction,
THEN 'nightTime'
ELSE 'otherTime'
END AS bidTimeType,
date_time
-- extra
-- TODO: count_char is an UDF, add it back when we support similar functionality.
-- https://github.com/nexmark/nexmark/blob/master/nexmark-flink/src/main/java/com/github/nexmark/flink/udf/CountChar.java
-- count_char(extra, 'c') AS c_counts
date_time,
count_char(extra, 'c') AS c_counts
FROM bid
WHERE 0.908 * price > 1000000
AND 0.908 * price < 50000000
Expand Down
14 changes: 9 additions & 5 deletions e2e_test/streaming/nexmark/sinks/q14.slt.part
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
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
}
$$;

statement ok
CREATE SINK nexmark_q14 AS
SELECT
Expand All @@ -15,11 +22,8 @@ SELECT
THEN 'nightTime'
ELSE 'otherTime'
END AS bidTimeType,
date_time
-- extra
-- TODO: count_char is an UDF, add it back when we support similar functionality.
-- https://github.com/nexmark/nexmark/blob/master/nexmark-flink/src/main/java/com/github/nexmark/flink/udf/CountChar.java
-- count_char(extra, 'c') AS c_counts
date_time,
count_char(extra, 'c') AS c_counts
FROM bid
WHERE 0.908 * price > 1000000 AND 0.908 * price < 50000000
WITH ( connector = 'blackhole', type = 'append-only', force_append_only = 'true');
14 changes: 9 additions & 5 deletions e2e_test/streaming/nexmark/views/q14.slt.part
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
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
}
$$;

statement ok
CREATE MATERIALIZED VIEW nexmark_q14 AS
SELECT
Expand All @@ -15,10 +22,7 @@ SELECT
THEN 'nightTime'
ELSE 'otherTime'
END AS bidTimeType,
date_time
-- extra
-- TODO: count_char is an UDF, add it back when we support similar functionality.
-- https://github.com/nexmark/nexmark/blob/master/nexmark-flink/src/main/java/com/github/nexmark/flink/udf/CountChar.java
-- count_char(extra, 'c') AS c_counts
date_time,
count_char(extra, 'c') AS c_counts
FROM bid
WHERE 0.908 * price > 1000000 AND 0.908 * price < 50000000;
5 changes: 5 additions & 0 deletions e2e_test/udf/wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use arrow_udf::function;
use rust_decimal::Decimal;

#[function("count_char(varchar, varchar) -> int")]
fn count_char(s: &str, c: &str) -> i32 {
s.matches(c).count() as i32
}

#[function("int_42() -> int")]
fn int_42() -> i32 {
42
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/planner_test/tests/testdata/input/nexmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@
END AS bidTimeType,
date_time,
extra
-- TODO: count_char is an UDF, add it back when we support similar functionality.
-- https://github.com/nexmark/nexmark/blob/master/nexmark-flink/src/main/java/com/github/nexmark/flink/udf/CountChar.java
-- ignore UDF in planner test
-- count_char(extra, 'c') AS c_counts
FROM bid
WHERE 0.908 * price > 1000000 AND 0.908 * price < 50000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@
END AS bidTimeType,
date_time,
extra
-- TODO: count_char is an UDF, add it back when we support similar functionality.
-- https://github.com/nexmark/nexmark/blob/master/nexmark-flink/src/main/java/com/github/nexmark/flink/udf/CountChar.java
-- ignore UDF in planner test
-- count_char(extra, 'c') AS c_counts
FROM bid
WHERE 0.908 * price > 1000000 AND 0.908 * price < 50000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@
END AS bidTimeType,
date_time,
extra
-- TODO: count_char is an UDF, add it back when we support similar functionality.
-- https://github.com/nexmark/nexmark/blob/master/nexmark-flink/src/main/java/com/github/nexmark/flink/udf/CountChar.java
-- ignore UDF in planner test
-- count_char(extra, 'c') AS c_counts
FROM bid
WHERE 0.908 * price > 1000000 AND 0.908 * price < 50000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@
END AS bidTimeType,
date_time,
extra
-- TODO: count_char is an UDF, add it back when we support similar functionality.
-- https://github.com/nexmark/nexmark/blob/master/nexmark-flink/src/main/java/com/github/nexmark/flink/udf/CountChar.java
-- ignore UDF in planner test
-- count_char(extra, 'c') AS c_counts
FROM bid
WHERE 0.908 * price > 1000000 AND 0.908 * price < 50000000;
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/planner_test/tests/testdata/output/nexmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,7 @@
END AS bidTimeType,
date_time,
extra
-- TODO: count_char is an UDF, add it back when we support similar functionality.
-- https://github.com/nexmark/nexmark/blob/master/nexmark-flink/src/main/java/com/github/nexmark/flink/udf/CountChar.java
-- ignore UDF in planner test
-- count_char(extra, 'c') AS c_counts
FROM bid
WHERE 0.908 * price > 1000000 AND 0.908 * price < 50000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,7 @@
END AS bidTimeType,
date_time,
extra
-- TODO: count_char is an UDF, add it back when we support similar functionality.
-- https://github.com/nexmark/nexmark/blob/master/nexmark-flink/src/main/java/com/github/nexmark/flink/udf/CountChar.java
-- ignore UDF in planner test
-- count_char(extra, 'c') AS c_counts
FROM bid
WHERE 0.908 * price > 1000000 AND 0.908 * price < 50000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,7 @@
END AS bidTimeType,
date_time,
extra
-- TODO: count_char is an UDF, add it back when we support similar functionality.
-- https://github.com/nexmark/nexmark/blob/master/nexmark-flink/src/main/java/com/github/nexmark/flink/udf/CountChar.java
-- ignore UDF in planner test
-- count_char(extra, 'c') AS c_counts
FROM bid
WHERE 0.908 * price > 1000000 AND 0.908 * price < 50000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1208,8 +1208,7 @@
END AS bidTimeType,
date_time,
extra
-- TODO: count_char is an UDF, add it back when we support similar functionality.
-- https://github.com/nexmark/nexmark/blob/master/nexmark-flink/src/main/java/com/github/nexmark/flink/udf/CountChar.java
-- ignore UDF in planner test
-- count_char(extra, 'c') AS c_counts
FROM bid
WHERE 0.908 * price > 1000000 AND 0.908 * price < 50000000;
Expand Down

0 comments on commit 7b640e2

Please sign in to comment.