-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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-49249][SPARK-49122] Artifact isolation in Spark Classic #48120
base: master
Are you sure you want to change the base?
Changes from all commits
fe143d6
e2597c1
827e01e
73d13f9
caa4251
5043ce3
3c8fef5
255e85d
7e3ecfe
a9c20e0
355bea8
6564ccf
06a658c
225ec6f
e4f5a5c
7630e2f
7b8f1da
786d48f
1849ac5
a0ae922
bfa6d85
fe7947f
04a5bb2
24f99a5
39a8086
7cce314
80289b8
4542a21
0b021d9
97c7d6c
aa9c21d
a2849f8
508ee7b
fdcb05b
c9cf1a2
be49405
5c15612
3899b22
d8ec1d3
3bcda6d
216b467
4de3ce8
7a0910b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import org.apache.spark.sql.api.java.UDF2 | ||
|
||
class IntSumUdf extends UDF2[Long, Long, Long] { | ||
override def call(t1: Long, t2: Long): Long = t1 + t2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,6 @@ import org.apache.spark.sql.execution.python.UserDefinedPythonFunction | |
import org.apache.spark.sql.expressions.{SparkUserDefinedFunction, UserDefinedAggregateFunction, UserDefinedAggregator, UserDefinedFunction} | ||
import org.apache.spark.sql.internal.UserDefinedFunctionUtils.toScalaUDF | ||
import org.apache.spark.sql.types.DataType | ||
import org.apache.spark.util.Utils | ||
|
||
/** | ||
* Functions for registering user-defined functions. Use `SparkSession.udf` to access this: | ||
|
@@ -44,7 +43,7 @@ import org.apache.spark.util.Utils | |
* @since 1.3.0 | ||
*/ | ||
@Stable | ||
class UDFRegistration private[sql] (functionRegistry: FunctionRegistry) | ||
class UDFRegistration private[sql] (session: SparkSession, functionRegistry: FunctionRegistry) | ||
extends api.UDFRegistration | ||
with Logging { | ||
protected[sql] def registerPython(name: String, udf: UserDefinedPythonFunction): Unit = { | ||
|
@@ -121,7 +120,7 @@ class UDFRegistration private[sql] (functionRegistry: FunctionRegistry) | |
*/ | ||
private[sql] def registerJavaUDAF(name: String, className: String): Unit = { | ||
try { | ||
val clazz = Utils.classForName[AnyRef](className) | ||
val clazz = session.artifactManager.classloader.loadClass(className) | ||
if (!classOf[UserDefinedAggregateFunction].isAssignableFrom(clazz)) { | ||
throw QueryCompilationErrors | ||
.classDoesNotImplementUserDefinedAggregateFunctionError(className) | ||
|
@@ -138,16 +137,20 @@ class UDFRegistration private[sql] (functionRegistry: FunctionRegistry) | |
|
||
// scalastyle:off line.size.limit | ||
/** | ||
* Register a Java UDF class using reflection, for use from pyspark | ||
* Register a Java UDF class using it's class name. The class must implement one of the UDF | ||
* interfaces in the [[org.apache.spark.sql.api.java]] package, and discoverable by the current | ||
* session's class loader. | ||
* | ||
* @param name udf name | ||
* @param className fully qualified class name of udf | ||
* @param returnDataType return type of udf. If it is null, spark would try to infer | ||
* @param name Name of the UDF. | ||
* @param className Fully qualified class name of the UDF. | ||
* @param returnDataType Return type of UDF. If it is `null`, Spark would try to infer | ||
* via reflection. | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
private[sql] def registerJava(name: String, className: String, returnDataType: DataType): Unit = { | ||
def registerJava(name: String, className: String, returnDataType: DataType): Unit = { | ||
Comment on lines
-148
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to make this method public so I can call it from REPL. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not against this. I am trying to understand the user facing consequences though. I'd probably prefer that we add support for Scala UDFs as well. That can be done in a follow-up though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you file a follow-up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. |
||
try { | ||
val clazz = Utils.classForName[AnyRef](className) | ||
val clazz = session.artifactManager.classloader.loadClass(className) | ||
val udfInterfaces = clazz.getGenericInterfaces | ||
.filter(_.isInstanceOf[ParameterizedType]) | ||
.map(_.asInstanceOf[ParameterizedType]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One follow-up here would be to cache the ArtifactManager classloader. I think we create that thing over and over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. We can invalidate the cache when a new JAR is added.