Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ public class FunctionMappings {
s(SqlStdOperatorTable.BITXOR, "bitwise_xor"),
s(SqlStdOperatorTable.RADIANS, "radians"),
s(SqlStdOperatorTable.DEGREES, "degrees"),
s(SqlLibraryOperators.FACTORIAL, "factorial"))
s(SqlLibraryOperators.FACTORIAL, "factorial"),
s(SqlStdOperatorTable.IS_TRUE, "is_true"),
s(SqlStdOperatorTable.IS_FALSE, "is_false"),
s(SqlStdOperatorTable.IS_NOT_TRUE, "is_not_true"),
s(SqlStdOperatorTable.IS_NOT_FALSE, "is_not_false"),
s(SqlStdOperatorTable.IS_DISTINCT_FROM, "is_distinct_from"))
.build();

public static final ImmutableList<Sig> AGGREGATE_SIGS =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.substrait.isthmus;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

public class ComparisonFunctionsTest extends PlanTestBase {
static String CREATES =
"CREATE TABLE numbers (int_a INT, int_b INT, double_a DOUBLE, double_b DOUBLE)";

@Test
void is_true() throws Exception {
String query = "SELECT ((int_a > int_b) IS TRUE) FROM numbers";
assertSqlSubstraitRelRoundTrip(query, CREATES);
}

@Test
void is_false() throws Exception {
String query = "SELECT ((int_a > int_b) IS FALSE) FROM numbers";
assertSqlSubstraitRelRoundTrip(query, CREATES);
}

@Test
void is_not_true() throws Exception {
String query = "SELECT ((int_a > int_b) IS NOT TRUE) FROM numbers";
assertSqlSubstraitRelRoundTrip(query, CREATES);
}

@Test
void is_not_false() throws Exception {
String query = "SELECT ((int_a > int_b) IS NOT FALSE) FROM numbers";
assertSqlSubstraitRelRoundTrip(query, CREATES);
}

@ParameterizedTest
@CsvSource({"int_a, int_b", "int_b, int_a", "double_a, double_b", "double_b, double_a"})
void is_distinct_from(String left, String right) throws Exception {
String query = String.format("SELECT (%s IS DISTINCT FROM %s) FROM numbers", left, right);
assertSqlSubstraitRelRoundTrip(query, CREATES);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment looking at this from the future. This doesn't actually test the IS DISTINCT FROM mapping because a query like

SELECT (int_a IS DISTINCT FROM int_b) FROM numbers

gets processed into the following Calcite representation

LogicalProject(EXPR$0=[AND(OR(IS NOT NULL($0), IS NOT NULL($1)), IS NOT TRUE(=($0, $1)))])
  LogicalTableScan(table=[[NUMBERS]])

I only noticed this because I was poking around updating some tests. The same thing happens with IS NOT DISTINCT FROM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for bringing this to my attention @vbarua! I'll take a look and rectify this tomorrow morning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vbarua I believe I've addressed the logical rewrite in this pull request: #628 - let me know if this works

}

@ParameterizedTest
@ValueSource(strings = {"int_a", "int_b", "double_a", "double_b"})
void is_distinct_from_null_vs_col(String column) throws Exception {
String query = String.format("SELECT (NULL IS DISTINCT FROM %s) FROM numbers", column);
assertSqlSubstraitRelRoundTrip(query, CREATES);
}
}