calcite icon indicating copy to clipboard operation
calcite copied to clipboard

[CALCITE-4777]Casting from DECIMAL to BOOLEAN throws an exception

Open xuyangzhong opened this issue 4 years ago • 4 comments

According to the discussion in [calcite-4777], casting from decimal to boolean is invalid, and an exception like "Cast function cannot convert value of type DECIMAL(2,1) to type BOOLEAN" will be thrown in the period of validating. This pr changes:

  • remove the coerce rule from decimal to boolean, which will lead to throw a conversion exception and let users know this is an invalid conversion.
  • add some test cases in SqlOperatorBaseTest.
  • change the reference.md to say this invalid conversion

xuyangzhong avatar Sep 29 '21 02:09 xuyangzhong

LGTM @xuyangzhong the PR looks in a good shape, could you please squash commits into a single one so that we can merge it shortly?

rubenada avatar Oct 06 '21 07:10 rubenada

LGTM @xuyangzhong the PR looks in a good shape, could you please squash commits into a single one so that we can merge it shortly?

@rubenada As discussed in Jira(According to my understanding of the comments). The SQL:

select cast(1 as boolean)
select cast(0 as boolean)

is also invalid.

NobiGo avatar Oct 07 '21 00:10 NobiGo

@NobiGo my understanding was that casting decimal (and float, real, double) into boolean will be forbidden (implemented by this PR); but casting integer types into boolean is (and will continue being) allowed. A different issue is that currently casting integer into boolean always returns false (instead of zero->false; non-zero->true), but there was another ticket to deal with this problem: CALCITE-4782. Let us clarify this in the Jira ticket.

rubenada avatar Oct 07 '21 07:10 rubenada

@rubenada done

xuyangzhong avatar Oct 08 '21 01:10 xuyangzhong