Skip to content
Open
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 @@ -65,7 +65,10 @@ public int compareTo(ComparableLiteral other) {
|| other instanceof DecimalLiteral || other instanceof DecimalV3Literal) {
return this.getBigDecimalValue().compareTo(((NumericLiteral) other).getBigDecimalValue());
}
return Double.compare(this.getDouble(), ((Literal) other).getDouble());
double left = this.getDouble();
double right = ((Literal) other).getDouble();
// SQL treats signed zeros as equal, while Double.compare distinguishes them.
return left == right ? 0 : Double.compare(left, right);
}
if (other instanceof NullLiteral) {
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,26 @@

class FoldConstantTest extends ExpressionRewriteTestHelper {

@Test
void testSignedZeroComparisonFold() {
executor = new ExpressionRuleExecutor(ImmutableList.of(
bottomUp(FoldConstantRuleOnFE.VISITOR_INSTANCE)
));
for (String type : ImmutableList.of("float", "double")) {
for (String zero : ImmutableList.of("0.0", "-0.0")) {
String left = "cast('" + zero + "' as " + type + ")";
String right = "cast('" + (zero.equals("0.0") ? "-0.0" : "0.0") + "' as " + type + ")";
assertRewriteAfterTypeCoercion(left + " = " + right, "true");
assertRewriteAfterTypeCoercion(left + " <=> " + right, "true");
assertRewriteAfterTypeCoercion(left + " != " + right, "false");
assertRewriteAfterTypeCoercion(left + " < " + right, "false");
assertRewriteAfterTypeCoercion(left + " > " + right, "false");
assertRewriteAfterTypeCoercion(left + " <= " + right, "true");
assertRewriteAfterTypeCoercion(left + " >= " + right, "true");
}
}
}

@Test
void testCaseWhenFold() {
executor = new ExpressionRuleExecutor(ImmutableList.of(
Expand Down
Loading