0

I'm trying to do a SQL transform with Apache Beam using Calcite SQL syntax. I'm doing an int to boolean cast. My sql looks like this:

,CASE WHEN cast(IsService as BOOLEAN) THEN CASE WHEN IsEligible THEN 1 ELSE 0 END ELSE NULL END AS Reported

Where IsService is an indicator int and IsEligible is a boolean.

According to the documentation an explicit cast from int to boolean is fine. However, I get the below error when I run the pipeline:

Caused by: org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.sql.validate.SqlValidatorException: Cast function cannot convert value of type INTEGER to type BOOLEAN

Can anyone explain why I'm getting the error?

Kenn Knowles
  • 5,838
  • 18
  • 22
artofdoe
  • 167
  • 2
  • 14

1 Answers1

1

To solve your problem immediately, you could use IsService > 0 instead of CAST. In my opinion, it is even more clear what the conversion is. I am not a fan of relying on "falsey" values.

Kenn Knowles
  • 5,838
  • 18
  • 22
  • using `> 0` would solve the problem, but that requires changes in the sql which is auto generated and it's a big hassle – artofdoe Jan 12 '21 at 18:57