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

Let UDF to handle null value

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.6.0
    • Component/s: SQL
    • Labels:
    • Target Version/s:

      Description

      I notice that currently spark will take the long field as -1 if it is null.
      Here's the sample code.

      sqlContext.udf.register("f", (x:Int)=>x+1)
      df.withColumn("age2", expr("f(age)")).show()
      
      //////////////// Output ///////////////////////
      +----+-------+----+
      | age|   name|age2|
      +----+-------+----+
      |null|Michael|   0|
      |  30|   Andy|  31|
      |  19| Justin|  20|
      +----+-------+----+
      

      I think for the null value we have 3 options

      • Use a special value to represent it (what spark does now)
      • Always return null if the udf input has null value argument
      • Let udf itself to handle null

      I would prefer the third option

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                cloud_fan Wenchen Fan
                Reporter:
                zjffdu Jeff Zhang
              • Votes:
                0 Vote for this issue
                Watchers:
                12 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: