简体   繁体   中英

How to raise an exception to exit Synapse Apache Spark notebook

I am attempting to carry out two actions in the event of a failure scenario.

  1. Write the results of a table to a single file in parquet.
  2. Exit a the notebook.

Take action based on the results

if validation_result["success"]:
    print("Successful")
else:
    (
        spark.sql("Select * from notify_error")
        .coalesce(1)
        .write.format("delta")
        .mode("overwrite")
        .save(lakePath)
    )

As you can see from the above, I'm trying to create a single table using coalesce(1) . To exit a notebook in Synapse I believe the code is:

mssparkutils.notebook.exit(returnValue)

But I'm not where to place the code in my code above.

Any thoughts?

Can you just do raise with ValueError , eg

%%pyspark

notebookName = mssparkutils.runtime.context.get('notebookname')
errorString = f"error in notebook '{notebookName}'"

raiseError = True

if raiseError:
  raise ValueError(errorString)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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