grundprinzip commented on code in PR #41013:
URL: https://github.com/apache/spark/pull/41013#discussion_r1194722082


##########
python/pyspark/sql/session.py:
##########
@@ -394,6 +394,36 @@ def enableHiveSupport(self) -> "SparkSession.Builder":
             """
             return self.config("spark.sql.catalogImplementation", "hive")
 
+        def create(self) -> "SparkSession":
+            """Creates a new SparkSession. Can only be used in the context of 
Spark Connect
+            and will throw an exception otherwise.
+
+            .. versionadded:: 3.5.0
+
+            Returns
+            -------
+            :class:`SparkSession`
+            """
+            opts = dict(self._options)
+            if "SPARK_REMOTE" in os.environ or "spark.remote" in opts:
+                from pyspark.sql.connect.session import SparkSession as 
RemoteSparkSession
+
+                url = opts.get("spark.remote", os.environ.get("SPARK_REMOTE"))
+
+                if url.startswith("local"):
+                    raise RuntimeError(
+                        "Creating new SparkSessions with `local` "
+                        "connection string is not supported."
+                    )
+
+                # Mark this Spark Session as Spark Connect. This prevents that 
local PySpark is
+                # used in conjunction with Spark Connect mode.
+                os.environ["SPARK_ENABLE_CONNECT_MODE"] = "1"
+                opts["spark.remote"] = url
+                return RemoteSparkSession.builder.config(map=opts).create()
+            else:
+                raise RuntimeError("Create a new SparkSession is only 
supported with SparkConnect.")

Review Comment:
   I reused the logic for validating the URIs and will update the error message.



-- 
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-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to