Sean Broeder created CALCITE-7542:
-------------------------------------
Summary: RexCall.isAlwaysTrue()/isAlwaysFalse() incorrectly
returns true for CAST(boolean AS non-boolean)
Key: CALCITE-7542
URL: https://issues.apache.org/jira/browse/CALCITE-7542
Project: Calcite
Issue Type: Bug
Components: core
Affects Versions: 1.41.0
Reporter: Sean Broeder
Assignee: Sean Broeder
RexCall.isAlwaysTrue() and isAlwaysFalse() delegate to the operand for any CAST
expression, without checking whether the result type is BOOLEAN. This means
CAST(TRUE AS INTEGER) — an INTEGER expression — incorrectly reports
isAlwaysTrue() == true.
Root cause
In RexCall.isAlwaysTrue(), the CAST case falls through to return
operands.get(0).isAlwaysTrue() with no type guard. The fix is to only delegate
when getType().getSqlTypeName() == SqlTypeName.BOOLEAN.
Reproduction (unit test)
RexNode castTrueToInt = rexBuilder.makeAbstractCast(intType, trueLiteral);
// CAST(TRUE AS INTEGER) is an INTEGER — isAlwaysTrue() must be false
assertThat(castTrueToInt.isAlwaysTrue(), is(false)); // FAILS: returns true
--
This message was sent by Atlassian Jira
(v8.20.10#820010)