[ 
https://issues.apache.org/jira/browse/CALCITE-7542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18082909#comment-18082909
 ] 

Sean Broeder commented on CALCITE-7542:
---------------------------------------

That's a great suggestion because I could eliminate the per case guards and it 
would be cleaner IMO.  But I worry about asserts only firing in test code, so I 
think I'll model it after RexLiteral.isAlwaysTrue which has already set the 
precedent to return false early if the type is not BOOLEAN.  I think this 
approach will satisfy both of us.

> 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
>            Priority: Minor
>              Labels: pull-request-available
>
> 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)

Reply via email to