使用 databricks-connect 调试运行另一个笔记本的笔记本

Using databricks-connect debugging a notebook that runs another notebook

我可以使用 visual studio 代码从我的 Linux Centos VM 连接到 Azure Databricks 集群。

下面的代码甚至可以正常工作

from pyspark.sql import SparkSession

spark = SparkSession.builder.getOrCreate()

print("Cluster access test - ",spark.range(100).count())

setting = spark.conf.get("spark.master")  # returns local[*]
if "local" in setting:
    from pyspark.dbutils import DBUtils
    dbutils = DBUtils().get_dbutils(spark)
else:
    print("Do nothing - dbutils should be available already")

out = dbutils.fs.ls('/FileStore/')
print(out)

我在本地有一个笔记本,运行 另一个笔记本使用 %run path/anothernotebook

因为 %运行 字符串被注释了 # python 没有执行它。

所以我试图包括 dbutils.notebook.run('pathofnotebook') 但它错误地指出 notebook

Exception has occurred: AttributeError
'SparkServiceClientDBUtils' object has no attribute 'notebook'

是否可以在本地调试调用另一个笔记本的笔记本?

这是不可能的 - Databricks Connect 中包含的 dbutils 实现仅支持“fs”和“secrets”子命令(参见 docs)。

Databricks Connect 旨在处理本地开发的代码,而不是笔记本。如果您可以将该笔记本的内容打包为 Python 包,那么您就可以对其进行调试。

P.S。请注意 dbutils.notebook.run 将 notebook 作为单独的作业执行,与 %运行

不同