Skip to content

[SPARK-52014][SQL] Support FoldableUnevaluable in HiveGenericUDFEvaluator #50800

New issue

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

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

Already on GitHub? # to your account

Closed
wants to merge 1 commit 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 @@ -919,6 +919,10 @@ private[hive] trait HiveInspectors {
// We will enumerate all of the possible constant expressions, throw exception if we missed
case Literal(_, dt) =>
throw SparkException.internalError(s"Hive doesn't support the constant type [$dt].")
// FoldableUnevaluable will be replaced with a foldable value in FinishAnalysis rule,
// skip eval() for them.
case _ if expr.collectFirst { case e: FoldableUnevaluable => e }.isDefined =>
toInspector(expr.dataType)
// ideally, we don't test the foldable here(but in optimizer), however, some of the
// Hive UDF / UDAF requires its argument to be constant objectinspector, we do it eagerly.
case _ if expr.foldable => toInspector(Literal.create(expr.eval(), expr.dataType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,17 @@ class HiveUDFSuite extends QueryTest with TestHiveSingleton with SQLTestUtils {
}
}
}

test("SPARK-52014: Support FoldableUnevaluable in HiveGenericUDFEvaluator") {
withUserDefinedFunction("hive_concat" -> true) {
sql(s"CREATE TEMPORARY FUNCTION hive_concat AS '${classOf[GenericUDFConcat].getName}'")
assert(sql(
s"""SELECT hive_concat(
| date_format(CAST(CURRENT_DATE() AS DATE), 'yyyyMMdd'),
| now())""".stripMargin).collect().length == 1)
}
hiveContext.reset()
}
}

class TestPair(x: Int, y: Int) extends Writable with Serializable {
Expand Down