Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Avoid comparing case value with operand when class types don't match #23324 #23911

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -663,6 +663,10 @@ else if (!found && result) {
simplifiedWhenClauses.add(new SpecialFormExpression(operand.getSourceLocation(), WHEN, whenClause.getType(), toRowExpression(operandValue, operand), toRowExpression(processWithExceptionHandling(result, context), result)));
}
else if (operandValue != null) {
//Check to avoid class cast exception
if (!value.getClass().isInstance(operandValue)) {
break;
}
Boolean isEqual = (Boolean) invokeOperator(
EQUAL,
ImmutableList.of(node.getArguments().get(0).getType(), operand.getType()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,44 @@ public void testLiterals()
assertEquals(optimize("X'1234'"), Slices.wrappedBuffer((byte) 0x12, (byte) 0x34));
}

@Test
public void testCaseMixedLongDecimalAndIntegral() {
assertRowExpressionEquals(OPTIMIZED, "case 1 " +
"when 0.11111111 then 2 " +
"when 3 then 4 " +
"end",
"NULL");

assertRowExpressionEquals(OPTIMIZED, "case 1 " +
"when 0.111111111 then 2 " +
"when 3 then 4 " +
"end",
"NULL");

assertRowExpressionEquals(OPTIMIZED, "case 0.11111111 " +
"when 0.11111111 then 2 " +
"when 3 then 4 " +
"end",
"2");

assertRowExpressionEquals(OPTIMIZED, "case 0.111111111 " +
"when 0.111111111 then 2 " +
"when 3 then 4 " +
"end",
"NULL");

assertRowExpressionEquals(OPTIMIZED, "case 1 " +
"when 1 then 2 " +
"when 3 then 4 " +
"end",
"2");
assertRowExpressionEquals(OPTIMIZED, "case 3 " +
"when 1 then 2 " +
"when 3 then 4 " +
"end",
"4");
}

private static void assertLike(byte[] value, String pattern, boolean expected)
{
Expression predicate = new LikePredicate(
Expand Down
Loading