Skip to content

Commit 5469b2e

Browse files
authored
Merge pull request #102 from pdet/function_mapping
Extra Function mapping
2 parents e1f5aa7 + 31eb7ea commit 5469b2e

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

src/from_substrait.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ const std::unordered_map<std::string, std::string> SubstraitToDuckDB::function_n
3030
{"modulus", "mod"}, {"std_dev", "stddev"}, {"starts_with", "prefix"},
3131
{"ends_with", "suffix"}, {"substring", "substr"}, {"char_length", "length"},
3232
{"is_nan", "isnan"}, {"is_finite", "isfinite"}, {"is_infinite", "isinf"},
33-
{"like", "~~"}, {"extract", "date_part"}};
33+
{"like", "~~"}, {"extract", "date_part"}, {"bitwise_and", "&"},
34+
{"bitwise_or", "|"}, {"bitwise_xor", "xor"}, {"octet_length", "strlen"}};
3435

3536
const case_insensitive_set_t SubstraitToDuckDB::valid_extract_subfields = {
3637
"year", "month", "day", "decade", "century", "millenium",

src/to_substrait.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ const std::unordered_map<std::string, std::string> DuckDBToSubstrait::function_n
3838
{"+", "add"},
3939
{"/", "divide"},
4040
{"first", "any_value"},
41-
{"!~~", "not_equal"}};
41+
{"!~~", "not_equal"},
42+
{"&", "bitwise_and"},
43+
{"|", "bitwise_or"},
44+
{"xor", "bitwise_xor"},
45+
{"strlen", "octet_length"}};
4246

4347
const case_insensitive_set_t DuckDBToSubstrait::valid_extract_subfields = {
4448
"year", "month", "day", "decade", "century", "millenium",

test/sql/test_functions.test

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# name: test/sql/test_functions.test
2+
# description: Test functions roundtrip
3+
# group: [sql]
4+
5+
require substrait
6+
7+
statement ok
8+
PRAGMA enable_verification
9+
10+
statement ok
11+
create table t as select 1 as a ,2 as b;
12+
13+
# bitwise_and
14+
statement ok
15+
CALL get_substrait('select a & b from t', strict = true)
16+
17+
# bitwise_or
18+
statement ok
19+
CALL get_substrait('select a | b from t', strict = true)
20+
21+
# bitwise_xor
22+
statement ok
23+
CALL get_substrait('select xor(a,b) from t', strict = true)
24+
25+
# strlen gets transformed to octet_length
26+
statement ok
27+
CALL get_substrait('select strlen(a::varchar) from t', strict = true)
28+
29+
# coalesce
30+
statement ok
31+
CALL get_substrait('select coalesce(a) from t', strict = true)
32+
33+
# acosh
34+
# asinh
35+
# atanh
36+
# cosh
37+
# sinh
38+
# tanh
39+
statement ok
40+
CALL get_substrait('select acosh(a),asinh(a),atanh(a),cosh(a),sinh(a),tanh(a) from t', strict = true)

0 commit comments

Comments
 (0)