Skip to content
Open
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
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.spark.sql.connect.execution.command

import org.apache.spark.sql.{classic, Row, SparkSession}
import org.apache.spark.sql.execution.command.LeafRunnableCommand
import org.apache.spark.sql.execution.python.UserDefinedPythonTableFunction

case class RegisterPythonTableFunctionCommand(udtf: UserDefinedPythonTableFunction)
extends LeafRunnableCommand {
override def run(sparkSession: SparkSession): Seq[Row] = {
val session = sparkSession.asInstanceOf[classic.SparkSession]
session.udtf.registerPython(udtf.name, udtf)
Seq.empty[Row]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import org.apache.spark.sql.classic.ClassicConversions._
import org.apache.spark.sql.connect.client.arrow.ArrowSerializer
import org.apache.spark.sql.connect.common.{DataTypeProtoConverter, ForeachWriterPacket, LiteralValueProtoConverter, StorageLevelProtoConverter, StreamingListenerPacket, UdfPacket}
import org.apache.spark.sql.connect.config.Connect.CONNECT_GRPC_ARROW_MAX_BATCH_SIZE
import org.apache.spark.sql.connect.execution.command.RegisterPythonTableFunctionCommand
import org.apache.spark.sql.connect.ml.MLHandler
import org.apache.spark.sql.connect.pipelines.PipelinesHandler
import org.apache.spark.sql.connect.plugin.SparkConnectPluginRegistry
Expand Down Expand Up @@ -2654,6 +2655,8 @@ class SparkConnectPlanner(
Some(transformMergeIntoTableCommand(command.getMergeIntoTableCommand))
case proto.Command.CommandTypeCase.CREATE_DATAFRAME_VIEW =>
Some(_ => transformCreateViewCommand(command.getCreateDataframeView))
case proto.Command.CommandTypeCase.REGISTER_TABLE_FUNCTION =>
Some(_ => transformRegisterUserDefinedTableFunction(command.getRegisterTableFunction))
case _ =>
None
}
Expand All @@ -2670,8 +2673,6 @@ class SparkConnectPlanner(
command.getCommandTypeCase match {
case proto.Command.CommandTypeCase.REGISTER_FUNCTION =>
handleRegisterUserDefinedFunction(command.getRegisterFunction)
case proto.Command.CommandTypeCase.REGISTER_TABLE_FUNCTION =>
handleRegisterUserDefinedTableFunction(command.getRegisterTableFunction)
case proto.Command.CommandTypeCase.REGISTER_DATA_SOURCE =>
handleRegisterUserDefinedDataSource(command.getRegisterDataSource)
case proto.Command.CommandTypeCase.EXTENSION =>
Expand Down Expand Up @@ -2979,16 +2980,14 @@ class SparkConnectPlanner(
executeHolder.eventsManager.postFinished()
}

private def handleRegisterUserDefinedTableFunction(
fun: proto.CommonInlineUserDefinedTableFunction): Unit = {
private def transformRegisterUserDefinedTableFunction(
fun: proto.CommonInlineUserDefinedTableFunction): LogicalPlan = {
fun.getFunctionCase match {
case proto.CommonInlineUserDefinedTableFunction.FunctionCase.PYTHON_UDTF =>
val function = createPythonUserDefinedTableFunction(fun)
session.udtf.registerPython(fun.getFunctionName, function)
RegisterPythonTableFunctionCommand(createPythonUserDefinedTableFunction(fun))
case other =>
throw InvalidInputErrors.invalidOneOfField(other, fun.getDescriptorForType)
}
executeHolder.eventsManager.postFinished()
}

private def handleRegisterUserDefinedDataSource(
Expand Down