阿帕契spark会议在DBCONNET无效

`sparkSession为空并试图执行ColectResult'错误消息时使用DBCONET时发生

写由荷塞冈萨雷斯

2022年4月1日

问题

您正试图使用Databricks连通操作代码高山市AWS系统|休眠|GCP)获取时sparkSession无效报错消息

java.lang.AssertionError: assertion failed: sparkSession is null while trying to executeCollectResult  at scala.Predef$.assert(Predef.scala:170)  at org.apache.spark.sql.execution.SparkPlan.executeCollectResult(SparkPlan.scala:323)  at org.apache.spark.sql.Dataset$$anonfun$50.apply(Dataset.scala:3351)  at org.apache.spark.sql.Dataset$$anonfun$50.apply(Dataset.scala:3350)  at org.apache.spark.sql.Dataset$$anonfun$54.apply(Dataset.scala:3485)  at org.apache.spark.sql.Dataset$$anonfun$54.apply(Dataset.scala:3480)  at org.apache.spark.sql.execution.SQLExecution$$anonfun$withCustomExecutionEnv$1.apply(SQLExecution.scala:111)  at org.apache.spark.sql.execution.SQLExecution$.withSQLConfPropagated(SQLExecution.scala:240)  at org.apache.spark.sql.execution.SQLExecution$.withCustomExecutionEnv(SQLExecution.scala:97)  at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:170)  at org.apache.spark.sql.Dataset.org$apache$spark$sql$Dataset$$withAction(Dataset.scala:3480)  at org.apache.spark.sql.Dataset.collectToPython(Dataset.scala:3350)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  at java.lang.reflect.Method.invoke(Method.java:498)  at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)  at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:380)  at py4j.Gateway.invoke(Gateway.java:295)  at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)  at py4j.commands.CallCommand.execute(CallCommand.java:79)  at py4j.GatewayConnection.run(GatewayConnection.java:251)  at java.lang.Thread.run(Thread.java:748)

因果

获取sparkSession无效stark会议不活动时使用DBConnect运行代码时报错

求解

必须确保spark会话激活集群后使用DBConnect本地运算代码

可使用下Python示例代码检查spark 会话并创建

Pyspark.sql导入sparkSessionspark
删除

警告

DBConnect仅使用支持Databricks Runtime版本确保在使用DBConnect前对集群使用支持运行时间

文章有帮助吗