简体   繁体   English

Python笔记本output格式

[英]Python notebook output format

I'm pretty new to Databricks and I'm playing around with capturing the output from one notebook in another notebook.我对 Databricks 很陌生,我正在尝试从另一个笔记本中的一个笔记本捕获 output。

Here's my code:这是我的代码:

Notebook1笔记本1

%python
result = dbutils.notebook.run("/01.Mig/SM02. Project /02 Processing Staging/04 User Notebooks/Notebook1", 60)
print("Result: " + result )
if result == 0: dbutils.notebook.exit
else: dbutils.notebook.run("/01.Mig/SM02. Project/02 Processing Staging/04 User Notebooks/Output",60)

Notebook2笔记本2

%python
resultValue = spark.sql("select count(1) from Notes_Final where record1 like 'GAB%'")
dbutils.notebook.exit(str(resultValue))

The result that gets passed back from Notebook2 is DataFrame[count(1): bigint] .从 Notebook2 传回的结果是DataFrame[count(1): bigint] I need it to pass back the value of the count from the SQL in Notebook2 rather than the data type.我需要它从 Notebook2 中的 SQL 传回计数值,而不是数据类型。

What am I missing?我错过了什么?

You need to collect the resulting value back to the driver, and even then you might need to print that value out as a string before passing it to dbutils as an exit value.您需要将结果值收集回驱动程序,即使这样,您也可能需要将该值作为字符串打印出来,然后再将其作为退出值传递给 dbutils。

Your code as is doesnt actually execute a count - it simply creates a DAG to generate the result.您的代码实际上并没有执行计数 - 它只是创建一个 DAG 来生成结果。 Once you call .collect() on your result dataframe it will execute the DAG and give you the count.一旦您对结果 dataframe 调用.collect() ,它将执行 DAG 并为您提供计数。 You can then pass this count as an exit value of the notebook.然后,您可以将此计数作为笔记本的退出值传递。 You may have to pass it as a string by printing it, as I said.正如我所说,您可能必须通过打印将其作为字符串传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM