Skip to content
Next Next commit
cache the function name from the catalog for lookupFunction
  • Loading branch information
kevinyu98 committed Jul 10, 2018
commit 5c8648c581fff1244b74fb25a0ff9e64f98919af
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.spark.sql.catalyst.analysis

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.util.Random

Expand Down Expand Up @@ -1209,10 +1210,18 @@ class Analyzer(
* @see https://issues.apache.org/jira/browse/SPARK-19737
*/
object LookupFunctions extends Rule[LogicalPlan] {
override def apply(plan: LogicalPlan): LogicalPlan = plan.transformAllExpressions {
case f: UnresolvedFunction if !catalog.functionExists(f.name) =>
withPosition(f) {
throw new NoSuchFunctionException(f.name.database.getOrElse("default"), f.name.funcName)
override def apply(plan: LogicalPlan): LogicalPlan = {
val catalogFunctionNameSet = new mutable.HashSet[FunctionIdentifier]()
plan.transformAllExpressions {
Copy link
Member

Choose a reason for hiding this comment

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

style: indent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed, thanks.

case f: UnresolvedFunction if catalogFunctionNameSet.contains(f.name) => f
case f: UnresolvedFunction if catalog.functionExists(f.name) =>
catalogFunctionNameSet.add(f.name)
Copy link
Member

Choose a reason for hiding this comment

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

Normalize the name before adding it to the cache? This can cover more cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I will do that. Thanks.

f
case f: UnresolvedFunction =>
withPosition(f) {
throw new NoSuchFunctionException(f.name.database.getOrElse("default"),
f.name.funcName)
}
}
}
}
Expand Down