HeartSaVioR commented on code in PR #60674:
URL: https://github.com/apache/spark/pull/60674#discussion_r4620174101


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/python/PythonGlobalPyFilesSuite.scala:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.execution.python
+
+import java.io.File
+import java.nio.file.{Files, Paths}
+import java.util.zip.{ZipEntry, ZipOutputStream}
+
+import org.apache.spark.SparkConf
+import 
org.apache.spark.internal.config.Python.PYTHON_ISOLATED_SESSION_GLOBAL_PY_FILES_ENABLED
+import org.apache.spark.sql.{QueryTest, Row}
+import 
org.apache.spark.sql.IntegratedUDFTestUtils.{createUserDefinedPythonTableFunction,
 shouldTestPythonUDFs}
+import org.apache.spark.sql.classic.SparkSession
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.util.Utils
+
+/**
+ * Tests that the Python workers of a session with artifact isolation, as in 
Spark Connect, can
+ * import the Python files that the application was started with 
(`spark.submit.pyFiles`).
+ */
+class PythonGlobalPyFilesSuite extends QueryTest with SharedSparkSession {
+
+  // The application's Python files: a module, a package in a zip file, and a 
module whose name
+  // a session can also use.
+  private lazy val globalPyFiles: Seq[String] = {
+    val dir = Utils.createTempDir()
+    val module = new File(dir, "global_py_files_module.py")
+    Files.writeString(module.toPath, "value = 'global module'")
+    val clash = new File(dir, "global_py_files_clash.py")
+    Files.writeString(clash.toPath, "value = 'global clash'")
+    val pkg = new File(dir, "global_py_files_pkg.zip")
+    val out = new ZipOutputStream(Files.newOutputStream(pkg.toPath))
+    try {
+      out.putNextEntry(new ZipEntry("global_py_files_pkg/__init__.py"))
+      out.write("value = 'global package'".getBytes("UTF-8"))
+      out.closeEntry()
+    } finally {
+      out.close()
+    }
+    Seq(module, clash, pkg).map(_.getAbsolutePath)
+  }
+
+  // As spark-submit does with --py-files outside YARN.
+  override protected def sparkConf: SparkConf = super.sparkConf
+    .set("spark.files", globalPyFiles.mkString(","))
+    .set("spark.submit.pyFiles", globalPyFiles.mkString(","))

Review Comment:
   > [!NOTE]
   > **DISCLAIMER:** This comment was written by an LLM: Claude Opus 5.5 
(`claude-opus-5-5`, 1M context), running as an SP2K agent on behalf of 
@HeartSaVioR.
   
   Thanks, fixed in 1fe984f86f9. `spark.submit.pyFiles` in the suite now names 
the same files under a directory that doesn't exist, while `spark.files` has 
the real paths, and a comment says why. With the submit-side paths instead of 
the copies, the import and precedence tests now fail.
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to