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 @@ -35,19 +35,6 @@ trait FunctionRegistry {
def lookupFunction(name: String, children: Seq[Expression]): Expression
}

class OverrideFunctionRegistry(underlying: FunctionRegistry) extends FunctionRegistry {

private val functionBuilders = StringKeyHashMap[FunctionBuilder](caseSensitive = false)

override def registerFunction(name: String, builder: FunctionBuilder): Unit = {
functionBuilders.put(name, builder)
}

override def lookupFunction(name: String, children: Seq[Expression]): Expression = {
functionBuilders.get(name).map(_(children)).getOrElse(underlying.lookupFunction(name, children))
}
}

class SimpleFunctionRegistry extends FunctionRegistry {

private val functionBuilders = StringKeyHashMap[FunctionBuilder](caseSensitive = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ class SQLContext(@transient val sparkContext: SparkContext)

// TODO how to handle the temp function per user session?
@transient
protected[sql] lazy val functionRegistry: FunctionRegistry =
new OverrideFunctionRegistry(FunctionRegistry.builtin)
protected[sql] lazy val functionRegistry: FunctionRegistry = FunctionRegistry.builtin

@transient
protected[sql] lazy val analyzer: Analyzer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
// Note that HiveUDFs will be overridden by functions registered in this context.
@transient
override protected[sql] lazy val functionRegistry: FunctionRegistry =
new OverrideFunctionRegistry(new HiveFunctionRegistry(FunctionRegistry.builtin))
new HiveFunctionRegistry(FunctionRegistry.builtin)
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't this throw UnsupportedOperationException when we register a UDF?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it will not throws exception. HiveFunctionRegistry seems now is like a delegation, the function registry actually will apply to FunctionRegistry.builtin directly. And I think that's the original purpose of the master code. See UDFSuite.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm missing something, but doesn't HiveFunctionRegistry just throw an exception?

  override def registerFunction(name: String, builder: FunctionBuilder): Unit =
    throw new UnsupportedOperationException

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's the tricky thing, as this code path is hidden(never be called) as we had the wrapper of OverrideFunctionRegistry, see code in HiveContext:

override protected[sql] lazy val functionRegistry: FunctionRegistry =
    new OverrideFunctionRegistry(new HiveFunctionRegistry(FunctionRegistry.builtin))

Since the OverrideFunctionRegistry is removed, we should update this part too.
UPDATE: I mean we should update the code of HiveFunctionRegistry.registerFunction.


/* An analyzer that uses the Hive metastore. */
@transient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private[hive] class HiveFunctionRegistry(underlying: analysis.FunctionRegistry)
}

override def registerFunction(name: String, builder: FunctionBuilder): Unit =
throw new UnsupportedOperationException
underlying.registerFunction(name, builder)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a unit test in hive to make sure function registration works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The unit test does exist in the master branch.
See: 'org.apache.spark.sql.hive.UDFSuite' and 'org.apache.spark.sql.UDFSuite'

}

private[hive] case class HiveSimpleUDF(funcWrapper: HiveFunctionWrapper, children: Seq[Expression])
Expand Down