0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Databricksにてdbutilsにより実行したノートブックのRUN IDを取得する方法

Last updated at Posted at 2021-06-22

追記

環境によっては下記のようなエラーがでるようです。代替案を、Databricksにてdbutils.widget により RUN IDを取得する方法 - Qiita にて記載しました。

py4j.security.Py4JSecurityException: Method public java.lang.String com.databricks.backend.common.rpc.CommandContext.toJson() is not whitelisted on class class com.databricks.backend.common.rpc.CommandContext

image.png

概要

Databricksにてdbutilsにより実行したノートブックのRUN IDを取得するには、dbutilsに実行されるノートブックにてリターン値としてRUN IDを返すことで可能です。リターン値を設定するには、dbutils.notebook.exitを利用します。

下記がサンプルコードです。

import json 
notebook_info = json.loads(dbutils.notebook.entry_point.getDbutils().notebook().getContext().toJson())
try:
  runId = notebook_info["tags"]["runId"]
except:
  runId = -1 
dbutils.notebook.exit(runId) 

Githubにサンプルノートブック群での実行手順を本記事で紹介します。

手順

1. ノートブックのインポート

https://github.com/manabian-/databricks_tecks_for_qiita/blob/main/tecks/get_runid_when_using_dbutilsnotebookrun/dbc/get_runid_when_using_dbutilsnotebookrun.dbc

image.png

2. mainノートブックを実行して、リターン値としてRUN IDが取得できることを確認

image.png

3. 実行したジョブの詳細ページへのリンク(例:Notebook job #12608)を選択

image.png

4. 2の値と一致することを確認

image.png

参考情報

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?