Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-2783

"COALESCE(s, TRUE) = TRUE" and "(s OR s IS UNKNOWN) = TRUE" causes NullPointerException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.18.0
    • 1.19.0
    • core
    • None

    Description

      This first appears in 1.18, and is introduced by CALCITE-1413.

      I have a table "table" with column "f0" of nullable booleans. Table contains the following values:

      true
      false
      null
      

      Working query:

      SELECT coalesce(f0, true) FROM table;
      
      true
      false
      true
      

      Broken query:

      SELECT coalesce(f0, true) = true FROM table;
      
      Caused by: java.lang.NullPointerException
       at org.apache.calcite.runtime.SqlFunctions.cannotConvert(SqlFunctions.java:1457)
       at org.apache.calcite.runtime.SqlFunctions.toBoolean(SqlFunctions.java:1480)
       at SC.eval0(Unknown Source)
      

      Broken generated code:

      {
       final Boolean inp0_ = ((Row) c.element()).getBoolean(0);
       c.output(Row.withSchema(outputSchema).addValue((SqlFunctions.isTrue(inp0_) || inp0_ == null ? Boolean.TRUE : inp0_ == null ? (Boolean) null : Boolean.FALSE) == null ? (Boolean) null : Boolean.valueOf(SqlFunctions.toBoolean(inp0_) || inp0_ == null)).build());
      }
      

      Attachments

        Issue Links

          Activity

            People

              kgyrtkirk Zoltan Haindrich
              apilloud Andrew Pilloud
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: