Skip to content

Commit 8f14f62

Browse files
feat(spark): use core spec bitwise shift functions (#424)
1 parent 5e6741d commit 8f14f62

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

spark/src/main/resources/spark.yml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,3 @@ scalar_functions:
2525
- name: days
2626
value: i32
2727
return: date
28-
- name: shift_right
29-
description: >-
30-
Bitwise (signed) shift right.
31-
Params:
32-
base – the base number to shift.
33-
shift – number of bits to right shift.
34-
impls:
35-
- args:
36-
- name: base
37-
value: i64
38-
- name: shift
39-
value: i32
40-
return: i64
41-
- args:
42-
- name: base
43-
value: i32
44-
- name: shift
45-
value: i32
46-
return: i32

spark/src/main/scala/io/substrait/spark/expression/FunctionMappings.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ class FunctionMappings {
157157
s[Lower]("lower"),
158158
s[Concat]("concat"),
159159
s[Coalesce]("coalesce"),
160+
s[ShiftLeft]("shift_left"),
160161
s[ShiftRight]("shift_right"),
162+
s[ShiftRightUnsigned]("shift_right_unsigned"),
161163
s[BitwiseAnd]("bitwise_and"),
162164
s[BitwiseOr]("bitwise_or"),
163165
s[BitwiseXor]("bitwise_xor"),

spark/src/test/scala/io/substrait/spark/NumericSuite.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,10 @@ class NumericSuite extends SparkFunSuite with SharedSparkSession with SubstraitP
4747
assertSqlSubstraitRelRoundTrip(
4848
"select sum(num), avg(num)from (values (2.5), (-0.5)) as table(num)")
4949
}
50+
51+
test("bitwise") {
52+
assertSqlSubstraitRelRoundTrip(
53+
"select shiftleft(num, 2), shiftright(num, 2), shiftrightunsigned(num, 2) from (values (4), (1)) as table(num)"
54+
)
55+
}
5056
}

0 commit comments

Comments
 (0)