Skip to content
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

[SPARK-43995][SPARK-43996][CONNECT] Add support for UDFRegistration to the Connect Scala Client #41953

Closed
wants to merge 9 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 @@ -417,6 +417,30 @@ class SparkSession private[sql] (
range(start, end, step, Option(numPartitions))
}

/**
* A collection of methods for registering user-defined functions (UDF).
*
* The following example registers a Scala closure as UDF:
* {{{
* sparkSession.udf.register("myUDF", (arg1: Int, arg2: String) => arg2 + arg1)
* }}}
*
* The following example registers a UDF in Java:
* {{{
* sparkSession.udf().register("myUDF",
* (Integer arg1, String arg2) -> arg2 + arg1,
* DataTypes.StringType);
* }}}
*
* @note
* The user-defined functions must be deterministic. Due to optimization, duplicate
* invocations may be eliminated or the function may even be invoked more times than it is
* present in the query.
*
* @since 3.5.0
*/
lazy val udf: UDFRegistration = new UDFRegistration(this)

// scalastyle:off
// Disable style checker so "implicits" object can start with lowercase i
/**
Expand Down Expand Up @@ -525,6 +549,13 @@ class SparkSession private[sql] (
client.execute(plan).asScala.toSeq
}

private[sql] def registerUdf(udf: proto.CommonInlineUserDefinedFunction): Unit = {
val command = proto.Command.newBuilder().setRegisterFunction(udf).build()
val plan = proto.Plan.newBuilder().setCommand(command).build()

client.execute(plan)
}

@DeveloperApi
def execute(extension: com.google.protobuf.Any): Unit = {
val command = proto.Command.newBuilder().setExtension(extension).build()
Expand Down
Loading