英文:
How to abort a notebook in DataFactory
问题
我正在尝试编写一个查询来访问数据工厂中的表格。我已经有了函数和查询,它可以正常工作。现在,当代码进入except部分时,我想立即中止笔记本。我目前有以下代码:
try:
df = spark.sql(query)
df.write.format(formato).mode(method).saveAsTable(table)
except Exception as e:
msg = "写入查询到表格时发生错误: {}".format(e)
dbutils.notebook.exit(msg)
实际上,它会在笔记本上显示一条消息并阻止它继续运行。但是,在数据工厂上,它会显示运行成功 ,但我想显示为 "失败" 。
有人能帮我吗?
非常感谢!
英文:
I am trying to write a query to a table in data factory.
I already have functions and query and it works fine.
Now I want to abort the notebook as soon as the code enters the except part.
I have this right now:
try:
df = spark.sql(query)
df.write.format(formato).mode(method).saveAsTable(table)
except Exception as e:
msg = "An error occured while writing the query to the table: {}".format(e)
dbutils.notebook.exit(msg)
It does actually show a message on the notebook and stop it from continuing. BUT, on data factory it does show that the run was successfully , but I wanted to show as "Failed" .
Does anyone can help me?
Thank you so much!!
答案1
得分: 1
我尝试了与您的代码相同的操作,我的笔记本也显示成功。
在这里,您正在处理错误并通过 dbutils.notebook.exit(msg)
向笔记本传递消息。
笔记本在退出并附带消息时不会失败,但 Databricks 笔记本执行将被中止。
如果您想在 ADF 管道中获取导致 Databricks 笔记本中止的原因(消息),请在笔记本活动的成功后使用以下表达式。
@activity('Notebook1').output.runOutput
(或)
如果您希望笔记本活动失败,您需要生成错误并中止笔记本,像下面的示例一样。
try:
df = spark.sql(query)
df.write.format(formato).mode(method).saveAsTable(table)
except Exception as e:
msg = "写入查询到表时发生错误: {}".format(e)
logging.error(msg)
raise
现在,要在 ADF 中获取错误消息,请在笔记本活动失败后使用以下表达式。
@activity('Notebook1').output.runError
英文:
I tried the same with your code and my Notebook is also gave me Success.
Here, you are handling the error and passing a message to the notebook using dbutils.notebook.exit(msg)
.
Notebook won't fail when it exited with a message but the databricks notebook execution will be aborted.
If you want to get the reason(Message) causing the abort of the databricks notebook in the ADF pipeline, use the below expression after the Success of the notebook activity.
@activity('Notebook1').output.runOutput
(OR)
If you want Notebook activity to fail, you need to generate the error and abort the notebook like below sample.
try:
df = spark.sql(query)
df.write.format(formato).mode(method).saveAsTable(table)
except Exception as e:
msg = "An error occured while writing the query to the table: {}".format(e)
logging.error(msg)
raise
Now, to get the error message in ADF, use the below expression after the Failure of the Notebook activity.
@activity('Notebook1').output.runError
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论