cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

How to abort/fail a notebook in databricks (and in datafactory)

tiagomotap5
New Contributor

Hello everyone!

I have a pipeline in Data Factory full of notebooks. In one of the notebooks I have the following (inside a function take writes a query to a table):

"

try:
df = spark.sql(query)
df.write.format(format).mode(method).saveAsTable(table)
except Exception as e:
(???)

"

And I want that if the code enters this "except Exception as e:" part, that the notebook abort (and that in the pipeline in DF the notebook shows as "failed").

I tried this methods:

1)

raise e

2)

raise Exception("error")

3)

assert False

4)

msg = "An error occured while writing the query to the table: {}".format(e)
dbutils.notebook.exit(msg)

 

None of them worked like I wanted. I want that the notebook fails. The last one actually stopped the rest of the cells from executing, but it still appears that was "successful" in Data Factory, and I want "failed".

Does anyone know how can I do this?

Please and thank you!! 😄

0 REPLIES 0
Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.