Skip to content

Commit 22448d1

Browse files
feat(isthmus): support bitwise left shift (#605)
Signed-off-by: Mark S. Lewis <[email protected]>
1 parent 6acb389 commit 22448d1

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

isthmus/src/main/java/io/substrait/isthmus/expression/FunctionMappings.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ public class FunctionMappings {
8686
s(SqlStdOperatorTable.IS_DISTINCT_FROM, "is_distinct_from"),
8787
s(SqlLibraryOperators.LOG2, "log2"),
8888
s(SqlLibraryOperators.LEAST, "least"),
89-
s(SqlLibraryOperators.GREATEST, "greatest"))
89+
s(SqlLibraryOperators.GREATEST, "greatest"),
90+
s(SqlStdOperatorTable.BIT_LEFT_SHIFT, "shift_left"),
91+
s(SqlStdOperatorTable.LEFTSHIFT, "shift_left"))
9092
.build();
9193

9294
public static final ImmutableList<Sig> AGGREGATE_SIGS =
@@ -131,7 +133,9 @@ public class FunctionMappings {
131133
resolver(
132134
SqlStdOperatorTable.MINUS, Set.of("i8", "i16", "i32", "i64", "fp32", "fp64", "dec")),
133135
SqlStdOperatorTable.MINUS_DATE,
134-
resolver(SqlStdOperatorTable.MINUS_DATE, Set.of("date", "timestamp_tz", "timestamp")));
136+
resolver(SqlStdOperatorTable.MINUS_DATE, Set.of("date", "timestamp_tz", "timestamp")),
137+
SqlStdOperatorTable.BIT_LEFT_SHIFT,
138+
resolver(SqlStdOperatorTable.BIT_LEFT_SHIFT, Set.of("i8", "i16", "i32", "i64")));
135139

136140
public static void main(String[] args) {
137141
SCALAR_SIGS.forEach(System.out::println);

isthmus/src/test/java/io/substrait/isthmus/ArithmeticFunctionTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,18 @@ void factorial(String column) throws Exception {
206206
String query = String.format("SELECT FACTORIAL(%s) FROM numbers", column);
207207
assertFullRoundTrip(query, CREATES);
208208
}
209+
210+
@ParameterizedTest
211+
@ValueSource(strings = {"i8", "i16", "i32", "i64"})
212+
void bit_left_shift(String column) throws Exception {
213+
String query = String.format("SELECT %s << 1 FROM numbers", column);
214+
assertFullRoundTrip(query, CREATES);
215+
}
216+
217+
@ParameterizedTest
218+
@ValueSource(strings = {"i8", "i16", "i32", "i64"})
219+
void leftshift(String column) throws Exception {
220+
String query = String.format("SELECT LEFTSHIFT(%s, 1) FROM numbers", column);
221+
assertFullRoundTrip(query, CREATES);
222+
}
209223
}

0 commit comments

Comments
 (0)