Skip to content

Commit 4b83666

Browse files
authored
feat(isthmus): mapping of factorial function from substrait (#589)
1 parent 9c4db92 commit 4b83666

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

isthmus/src/main/java/io/substrait/isthmus/calcite/SubstraitOperatorTable.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public class SubstraitOperatorTable implements SqlOperatorTable {
4646
// Utilisation of extended library operators available from calcite 1.35+, i.e hyperbolic
4747
// functions
4848
private static final SqlOperatorTable LIBRARY_OPERATOR_TABLE =
49-
SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(SqlLibrary.ALL);
49+
SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
50+
EnumSet.of(SqlLibrary.HIVE, SqlLibrary.SPARK, SqlLibrary.ALL));
5051

5152
private static final SqlOperatorTable STANDARD_OPERATOR_TABLE = SqlStdOperatorTable.instance();
5253

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public class FunctionMappings {
7777
s(SqlStdOperatorTable.BITAND, "bitwise_and"),
7878
s(SqlStdOperatorTable.BITXOR, "bitwise_xor"),
7979
s(SqlStdOperatorTable.RADIANS, "radians"),
80-
s(SqlStdOperatorTable.DEGREES, "degrees"))
80+
s(SqlStdOperatorTable.DEGREES, "degrees"),
81+
s(SqlLibraryOperators.FACTORIAL, "factorial"))
8182
.build();
8283

8384
public static final ImmutableList<Sig> AGGREGATE_SIGS =

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,11 @@ void degrees(String column) throws Exception {
199199
String query = String.format("SELECT DEGREES(%s) FROM numbers", column);
200200
assertFullRoundTrip(query, CREATES);
201201
}
202+
203+
@ParameterizedTest
204+
@ValueSource(strings = {"i32", "i64"})
205+
void factorial(String column) throws Exception {
206+
String query = String.format("SELECT FACTORIAL(%s) FROM numbers", column);
207+
assertFullRoundTrip(query, CREATES);
208+
}
202209
}

0 commit comments

Comments
 (0)