Skip to content
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 @@ -1311,7 +1311,10 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
protected def visitFunctionName(ctx: QualifiedNameContext): FunctionIdentifier = {
ctx.identifier().asScala.map(_.getText) match {
case Seq(db, fn) => FunctionIdentifier(fn, Option(db))
case Seq(fn) => FunctionIdentifier(fn, None)
case Seq(fn) => fn.split('.').toSeq match {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, at the very least, breaks users app ... even if this is a correct behaviour within Hive, we should target this 3.0.0.

case Seq(d, f) => FunctionIdentifier(f, Option(d))
case _ => FunctionIdentifier(fn, None)
}
case other => throw new ParseException(s"Unsupported function name '${ctx.getText}'", ctx)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2281,4 +2281,23 @@ class HiveDDLSuite
}
}
}

test("SPARK-25301: checks view with udf from non default database") {
val db = "d1"
withDatabase(db) {
spark.sql(s"CREATE DATABASE $db")
val table = "t1"
withTable(s"$db.$table") {
spark.sql(s"CREATE TABLE $db.$table AS SELECT 'abcd' c1, 'xyz' c2")
val functionNameUpper = "udfUpper"
withUserDefinedFunction(s"$db.$functionNameUpper" -> false) {
val functionClass =
classOf[org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper].getCanonicalName
sql(s"CREATE FUNCTION $db.$functionNameUpper AS '$functionClass'")
val ds = sql(s"SELECT `$db.$functionNameUpper`(`$table`.`c1`) FROM `$db`.`$table`")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the expected behaivour of backquotes; ANTLR parses inputs like;

  • `testdb.f1` => funcName: f1 dbName: testdb
  • testdb.f1 => funcName: testdb.f1 dbName: default

checkAnswer(ds, Row("ABCD"))
}
}
}
}
}