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

Let UDF to handle null value

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Blocker
    • Resolution: Fixed
    • None
    • 1.6.0
    • SQL

    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

              cloud_fan Wenchen Fan
              zjffdu Jeff Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: