Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-8636

CaseKeyWhen has incorrect NULL handling

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.4.0
    • 1.5.0
    • SQL

    Description

      CaseKeyWhen implementation in Spark uses the following equals implementation:

        private def equalNullSafe(l: Any, r: Any) = {
          if (l == null && r == null) {
            true
          } else if (l == null || r == null) {
            false
          } else {
            l == r
          }
        }
      

      Which is not correct, since in SQL, NULL is never equal to NULL (actually, it is not unequal either). In this case, a NULL value in a CASE WHEN expression should never match.

      For example, you can execute this in MySQL:

      SELECT CASE NULL WHEN NULL THEN "NULL MATCHES" ELSE "NULL DOES NOT MATCH" END FROM DUAL;
      

      And the result will be "NULL DOES NOT MATCH".

      Attachments

        Issue Links

          Activity

            People

              vinodkc Vinod KC
              smolav Santiago M. Mola
              Michael Armbrust Michael Armbrust
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: