You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "xupefei (via GitHub)" <gi...@apache.org> on 2024/08/06 13:40:33 UTC
[PR] [SPARK-49122][Connect][SQL] Add addArtifact API to the Spark SQL Core [spark]
xupefei opened a new pull request, #47631:
URL: https://github.com/apache/spark/pull/47631
### What changes were proposed in this pull request?
This PR improves Spark SQL Core to add a bunch of `addArtifact` APIs to `SparkSession`. These APIs are first introduced to Spark Connect a while ago.
### Why are the changes needed?
To close the API compatibility gap between Spark Connect and Spark Classic.
### Does this PR introduce _any_ user-facing change?
Yes, users will be able to use some new APIs.
### How was this patch tested?
Added new tests.
### Was this patch authored or co-authored using generative AI tooling?
No.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-49122][Connect][SQL] Add `addArtifact` API to the Spark SQL Core [spark]
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #47631:
URL: https://github.com/apache/spark/pull/47631#discussion_r1707728409
##########
sql/api/src/main/scala/org/apache/spark/sql/Artifact.scala:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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
+
+import java.io.{ByteArrayInputStream, File, InputStream, PrintStream}
+import java.net.URI
+import java.nio.file.{Files, Path, Paths}
+
+import org.apache.commons.lang3.StringUtils
+
+import org.apache.spark.sql.Artifact.LocalData
+import org.apache.spark.util.ArrayImplicits._
+import org.apache.spark.util.MavenUtils
+
+
+class Artifact private(val path: Path, val storage: LocalData) {
Review Comment:
Can this be unified with the client class?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-49249][SPARK-49122][Connect][SQL] Add `addArtifact` API to the Spark SQL Core [spark]
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #47631:
URL: https://github.com/apache/spark/pull/47631#discussion_r1733896895
##########
sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala:
##########
@@ -900,6 +988,29 @@ class SparkSession private(
internalCreateDataFrame(rowRdd, schema)
}
+ private def addArtifactsInternal(artifacts: Seq[Artifact]): Unit = artifacts.foreach { artifact =>
Review Comment:
Can you put this in ArtifactManager?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-49249][SPARK-49122][Connect][SQL] Add `addArtifact` API to the Spark SQL Core [spark]
Posted by "xupefei (via GitHub)" <gi...@apache.org>.
xupefei commented on code in PR #47631:
URL: https://github.com/apache/spark/pull/47631#discussion_r1734232729
##########
sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala:
##########
@@ -900,6 +988,29 @@ class SparkSession private(
internalCreateDataFrame(rowRdd, schema)
}
+ private def addArtifactsInternal(artifacts: Seq[Artifact]): Unit = artifacts.foreach { artifact =>
Review Comment:
Done!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-49249][SPARK-49122][Connect][SQL] Add `addArtifact` API to the Spark SQL Core [spark]
Posted by "asfgit (via GitHub)" <gi...@apache.org>.
asfgit closed pull request #47631: [SPARK-49249][SPARK-49122][Connect][SQL] Add `addArtifact` API to the Spark SQL Core
URL: https://github.com/apache/spark/pull/47631
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-49122][Connect][SQL] Add `addArtifact` API to the Spark SQL Core [spark]
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on PR #47631:
URL: https://github.com/apache/spark/pull/47631#issuecomment-2274256697
@xupefei can you check if this works with UDFs?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-49122][Connect][SQL] Add `addArtifact` API to the Spark SQL Core [spark]
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #47631:
URL: https://github.com/apache/spark/pull/47631#discussion_r1707723597
##########
sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala:
##########
@@ -900,6 +988,29 @@ class SparkSession private(
internalCreateDataFrame(rowRdd, schema)
}
+ private def addArtifactsInternal(artifacts: Seq[Artifact]): Unit = artifacts.foreach { artifact =>
+ artifact.storage match {
+ case d: Artifact.LocalFile =>
+ artifactManager.addArtifact(
+ artifact.path,
+ d.path,
+ fragment = None,
+ deleteStagedFile = false)
+ case d: Artifact.InMemory =>
+ val tempDir = Utils.createTempDir().toPath
+ val tempFile = tempDir.resolve(artifact.path.getFileName)
+ val outStream = Files.newOutputStream(tempFile)
+ Utils.tryWithSafeFinallyAndFailureCallbacks {
+ d.stream.transferTo(outStream)
+ artifactManager.addArtifact(artifact.path, tempFile, fragment = None)
+ }(finallyBlock = {
+ outStream.close()
+ })
+ case _ =>
+ throw new IllegalArgumentException(s"Unsupported artifact storage: ${artifact.storage}")
Review Comment:
Use `SparkException.internalError(..)`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-49122][Connect][SQL] Add `addArtifact` API to the Spark SQL Core [spark]
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #47631:
URL: https://github.com/apache/spark/pull/47631#discussion_r1707727129
##########
sql/api/src/main/scala/org/apache/spark/sql/Artifact.scala:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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
+
+import java.io.{ByteArrayInputStream, File, InputStream, PrintStream}
+import java.net.URI
+import java.nio.file.{Files, Path, Paths}
+
+import org.apache.commons.lang3.StringUtils
+
+import org.apache.spark.sql.Artifact.LocalData
+import org.apache.spark.util.ArrayImplicits._
+import org.apache.spark.util.MavenUtils
+
+
+class Artifact private(val path: Path, val storage: LocalData) {
Review Comment:
This should not be public API.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-49249][SPARK-49122][Connect][SQL] Add `addArtifact` API to the Spark SQL Core [spark]
Posted by "xupefei (via GitHub)" <gi...@apache.org>.
xupefei commented on PR #47631:
URL: https://github.com/apache/spark/pull/47631#issuecomment-2296256354
> @xupefei can you check if this works with UDFs?
I checked and found it doesn't work. The Spark Core session is currently not using the class loader provided by ArtifactManager: https://github.com/apache/spark/blob/11b682cf5b7c5360a02410be288b7905eecc1d28/common/utils/src/main/scala/org/apache/spark/util/SparkClassUtils.scala#L28-L47
For now we have to wrap the code with `artifactManager.withResources` to replace the class loader. THis issue needs to be fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-49249][SPARK-49122][Connect][SQL] Add `addArtifact` API to the Spark SQL Core [spark]
Posted by "xupefei (via GitHub)" <gi...@apache.org>.
xupefei commented on code in PR #47631:
URL: https://github.com/apache/spark/pull/47631#discussion_r1719777024
##########
sql/api/src/main/scala/org/apache/spark/sql/Artifact.scala:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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
+
+import java.io.{ByteArrayInputStream, File, InputStream, PrintStream}
+import java.net.URI
+import java.nio.file.{Files, Path, Paths}
+
+import org.apache.commons.lang3.StringUtils
+
+import org.apache.spark.sql.Artifact.LocalData
+import org.apache.spark.util.ArrayImplicits._
+import org.apache.spark.util.MavenUtils
+
+
+class Artifact private(val path: Path, val storage: LocalData) {
Review Comment:
Done!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org