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 @@ -32,6 +32,7 @@
import io.trino.metadata.TableProceduresRegistry;
import io.trino.metadata.TablePropertyManager;
import io.trino.security.AllowAllAccessControl;
import io.trino.spi.ErrorCode;
import io.trino.spi.TrinoException;
import io.trino.spi.predicate.DiscreteValues;
import io.trino.spi.predicate.Domain;
Expand Down Expand Up @@ -94,6 +95,7 @@
import static io.airlift.slice.SliceUtf8.setCodePointAt;
import static io.airlift.slice.Slices.utf8Slice;
import static io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;
import static io.trino.spi.StandardErrorCode.INVALID_CAST_ARGUMENT;
import static io.trino.spi.function.InvocationConvention.InvocationArgumentConvention.NEVER_NULL;
import static io.trino.spi.function.InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL;
import static io.trino.spi.function.InvocationConvention.simpleConvention;
Expand Down Expand Up @@ -835,8 +837,19 @@ private Optional<Expression> coerceComparisonWithRounding(
}
Type valueType = nullableValue.getType();
Object value = nullableValue.getValue();
return floorValue(valueType, symbolExpressionType, value)
.map(floorValue -> rewriteComparisonExpression(symbolExpressionType, symbolExpression, valueType, value, floorValue, comparisonOperator));
Optional<Object> floorValueOptional;
try {
floorValueOptional = floorValue(valueType, symbolExpressionType, value);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this the only usage of SaturatedFloorCast that needs to be fixed?

}
catch (TrinoException e) {
ErrorCode errorCode = e.getErrorCode();
if (INVALID_CAST_ARGUMENT.toErrorCode().equals(errorCode)) {
// There's no such value at symbolExpressionType
return Optional.of(FALSE_LITERAL);
}
throw e;
}
return floorValueOptional.map(floorValue -> rewriteComparisonExpression(symbolExpressionType, symbolExpression, valueType, value, floorValue, comparisonOperator));
}

private Expression rewriteComparisonExpression(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,16 @@ public void testFromBasicComparisonsWithNaN()
assertUnsupportedPredicate(not(isDistinctFrom(C_REAL, nanReal)));
}

@Test
public void testFromCoercionComparisonsWithNaN()
{
Expression nanDouble = literalEncoder.toExpression(TEST_SESSION, Double.NaN, DOUBLE);

assertPredicateIsAlwaysFalse(equal(cast(C_TINYINT, DOUBLE), nanDouble));
assertPredicateIsAlwaysFalse(equal(cast(C_SMALLINT, DOUBLE), nanDouble));
assertPredicateIsAlwaysFalse(equal(cast(C_INTEGER, DOUBLE), nanDouble));
}

@Test
public void testNonImplicitCastOnSymbolSide()
{
Expand Down