Skip to content

[SPARK-12258] [SQL] Hive Timestamp UDF is binded with '1969-12-31 15:59:59.999999' for null value #10249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,10 @@ class Analyzer(
// TODO: skip null handling for not-nullable primitive inputs after we can completely
// trust the `nullable` information.
// .filter { case (cls, expr) => cls.isPrimitive && expr.nullable }
.filter { case (cls, _) => cls.isPrimitive }
.filter { case (cls, _) =>
cls.isPrimitive ||
cls == classOf[java.sql.Timestamp] ||
cls == classOf[java.sql.Date] }
.map { case (_, expr) => IsNull(expr) }
.reduceLeftOption[Expression]((e1, e2) => Or(e1, e2))
inputsNullCheck.map(If(_, Literal.create(null, udf.dataType), udf)).getOrElse(udf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.hive.execution

import java.io.{PrintWriter, File, DataInput, DataOutput}
import java.sql.Timestamp
import java.util.{ArrayList, Arrays, Properties}

import org.apache.hadoop.conf.Configuration
Expand Down Expand Up @@ -350,6 +351,16 @@ class HiveUDFSuite extends QueryTest with TestHiveSingleton with SQLTestUtils {
sqlContext.dropTempTable("testUDF")
}

test("SPARK-12258 Timestamp UDF and Null value") {
hiveContext.runSqlHive("CREATE TABLE ts_test (ts TIMESTAMP) STORED AS TEXTFILE")
hiveContext.runSqlHive("INSERT INTO TABLE ts_test VALUES(Null)")
hiveContext.udf.register("dummy",
(ts: Timestamp) => ts
)
val result = hiveContext.sql("SELECT dummy(ts) FROM ts_test").collect().mkString("\n")
assertResult("[null]")(result)
}

test("SPARK-11522 select input_file_name from non-parquet table"){

withTempDir { tempDir =>
Expand Down