Uploaded image for project: 'Apache Drill'
  1. Apache Drill
  2. DRILL-5579

Nested cast to boolean fails for integer values greater than 1

    XMLWordPrintableJSON

Details

    Description

      As per Drill's casting rules, integer value 0 when casted to Boolean returns false. All other integers when casted to Boolean should return true.

      The following query fails:

      > select cast(cast(345 as int) as boolean) as a from (values(1));
      Error: SYSTEM ERROR: IllegalArgumentException: Invalid value for boolean: 345
        (java.lang.IllegalArgumentException) Invalid value for boolean: 345
          org.apache.drill.exec.expr.BooleanType.get():74
          org.apache.drill.exec.test.generated.ProjectorGen10.doSetup():88
          org.apache.drill.exec.test.generated.ProjectorGen10.setup():101
          org.apache.drill.exec.physical.impl.project.ProjectRecordBatch.setupNewSchema():492
          org.apache.drill.exec.record.AbstractSingleRecordBatch.innerNext():78
          org.apache.drill.exec.physical.impl.project.ProjectRecordBatch.innerNext():135
          org.apache.drill.exec.record.AbstractRecordBatch.next():162
          org.apache.drill.exec.physical.impl.BaseRootExec.next():104
          org.apache.drill.exec.physical.impl.ScreenCreator$ScreenRoot.innerNext():81
          org.apache.drill.exec.physical.impl.BaseRootExec.next():94
          org.apache.drill.exec.work.fragment.FragmentExecutor$1.run():232
          org.apache.drill.exec.work.fragment.FragmentExecutor$1.run():226
          java.security.AccessController.doPrivileged():-2
          javax.security.auth.Subject.doAs():422
          org.apache.hadoop.security.UserGroupInformation.doAs():1595
          org.apache.drill.exec.work.fragment.FragmentExecutor.run():226
          org.apache.drill.common.SelfCleaningRunnable.run():38
          java.util.concurrent.ThreadPoolExecutor.runWorker():1142
          java.util.concurrent.ThreadPoolExecutor$Worker.run():617
          java.lang.Thread.run():745 (state=,code=0)
      

      The following query works as expected:

      > select cast(t.a as boolean) from (select cast(345 as int) as a from (values(1)) )t;
      +---------+
      | EXPR$0  |
      +---------+
      | true    |
      +---------+
      1 row selected (0.244 seconds)
      

      Attachments

        Activity

          People

            cshi Chunhui Shi
            agirish Abhishek Girish
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: