問題
您正在嚐試使用Databricks Connect運行代碼(AWS|Azure|GCP)當你得到一個sparkSession為空錯誤消息。
assertionerror:斷言失敗:sparkSession是空的,而試圖執行在scala.Predef$.assert(Predef.scala:170)在org.apache.spark.sql. execute . sparkplan .executeCollectResult(SparkPlan.scala:323)在org.apache.spark.sql.Dataset$$anonfun$50.apply(Dataset.scala:3351)在org.apache.spark.sql.Dataset$$anonfun$50.apply(Dataset.scala:3350)在org.apache.spark.sql.Dataset$$anonfun$54.apply(Dataset.scala:3485)在org.apache.spark.sql.Dataset$$anonfun$54.apply(Dataset.scala:3480)在org.apache.spark.sql.execution.SQLExecution anonfun withCustomExecutionEnv美元1.美元(SQLExecution.scala: 111)應用org.apache.spark.sql.execution.SQLExecution .withSQLConfPropagated美元(SQLExecution.scala: 240)美元org.apache.spark.sql.execution.SQLExecution .withCustomExecutionEnv (SQLExecution.scala: 97)美元org.apache.spark.sql.execution.SQLExecution .withNewExecutionId (SQLExecution.scala: 170) org.apache.spark.sql.Dataset.org apache火花sql數據集$ $美元美元withAction (Dataset.scala: 3480)org.apache.spark.sql.Dataset.collectToPython(Dataset.scala:3350) at sun.reflect.NativeMethodAccessorImpl。invoke0(本機方法)sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java: 62) sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java: 43) java.lang.reflect.Method.invoke (Method.java: 498) py4j.reflection.MethodInvoker.invoke (MethodInvoker.java: 244) py4j.reflection.ReflectionEngine.invoke (ReflectionEngine.java: 380) py4j.Gateway.invoke (Gateway.java: 295) py4j.commands.AbstractCommand.invokeMethod (AbstractCommand.java: 132)py4j.commands.CallCommand.execute(CallCommand.java:79) at py4j.GatewayConnection.run(GatewayConnection.java:251) at java.lang.Thread.run(Thread.java:748)
導致
你會得到sparkSession為空當您嚐試使用DBConnect運行您的代碼時,如果Spark會話在您的集群上不活躍,則會出現錯誤消息。
解決方案
在嚐試使用DBConnect在本地運行代碼之前,必須確保集群上的Spark會話處於活動狀態。
您可以使用以下Python示例代碼來檢查Spark會話,如果不存在則創建一個。
%python從pyspark。spark = SparkSession.builder. getorcreate ()