Skip to content

Commit f59ecc5

Browse files
authored
feat(isthmus): true, false, distinct comparator scalar fn mappings (#597)
1 parent cce51cd commit f59ecc5

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ public class FunctionMappings {
7878
s(SqlStdOperatorTable.BITXOR, "bitwise_xor"),
7979
s(SqlStdOperatorTable.RADIANS, "radians"),
8080
s(SqlStdOperatorTable.DEGREES, "degrees"),
81-
s(SqlLibraryOperators.FACTORIAL, "factorial"))
81+
s(SqlLibraryOperators.FACTORIAL, "factorial"),
82+
s(SqlStdOperatorTable.IS_TRUE, "is_true"),
83+
s(SqlStdOperatorTable.IS_FALSE, "is_false"),
84+
s(SqlStdOperatorTable.IS_NOT_TRUE, "is_not_true"),
85+
s(SqlStdOperatorTable.IS_NOT_FALSE, "is_not_false"),
86+
s(SqlStdOperatorTable.IS_DISTINCT_FROM, "is_distinct_from"))
8287
.build();
8388

8489
public static final ImmutableList<Sig> AGGREGATE_SIGS =
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package io.substrait.isthmus;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.provider.CsvSource;
6+
import org.junit.jupiter.params.provider.ValueSource;
7+
8+
public class ComparisonFunctionsTest extends PlanTestBase {
9+
static String CREATES =
10+
"CREATE TABLE numbers (int_a INT, int_b INT, double_a DOUBLE, double_b DOUBLE)";
11+
12+
@Test
13+
void is_true() throws Exception {
14+
String query = "SELECT ((int_a > int_b) IS TRUE) FROM numbers";
15+
assertSqlSubstraitRelRoundTrip(query, CREATES);
16+
}
17+
18+
@Test
19+
void is_false() throws Exception {
20+
String query = "SELECT ((int_a > int_b) IS FALSE) FROM numbers";
21+
assertSqlSubstraitRelRoundTrip(query, CREATES);
22+
}
23+
24+
@Test
25+
void is_not_true() throws Exception {
26+
String query = "SELECT ((int_a > int_b) IS NOT TRUE) FROM numbers";
27+
assertSqlSubstraitRelRoundTrip(query, CREATES);
28+
}
29+
30+
@Test
31+
void is_not_false() throws Exception {
32+
String query = "SELECT ((int_a > int_b) IS NOT FALSE) FROM numbers";
33+
assertSqlSubstraitRelRoundTrip(query, CREATES);
34+
}
35+
36+
@ParameterizedTest
37+
@CsvSource({"int_a, int_b", "int_b, int_a", "double_a, double_b", "double_b, double_a"})
38+
void is_distinct_from(String left, String right) throws Exception {
39+
String query = String.format("SELECT (%s IS DISTINCT FROM %s) FROM numbers", left, right);
40+
assertSqlSubstraitRelRoundTrip(query, CREATES);
41+
}
42+
43+
@ParameterizedTest
44+
@ValueSource(strings = {"int_a", "int_b", "double_a", "double_b"})
45+
void is_distinct_from_null_vs_col(String column) throws Exception {
46+
String query = String.format("SELECT (NULL IS DISTINCT FROM %s) FROM numbers", column);
47+
assertSqlSubstraitRelRoundTrip(query, CREATES);
48+
}
49+
}

0 commit comments

Comments
 (0)