<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Airflow - How to pull XComs value in the notebook task? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/airflow-how-to-pull-xcoms-value-in-the-notebook-task/m-p/16161#M10372</link>
    <description>&lt;P&gt;From what I understand - you want to pass a run_id parameter to the second notebook task?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can: &lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a widget param inside your databricks notebook (https://docs.databricks.com/notebooks/widgets.html) that will consume your run_id&lt;/LI&gt;&lt;LI&gt;Pass the parameter in DatabricksSubmitRunOperator (example here: &lt;A href="https://stackoverflow.com/questions/61542653/airflow-databrickssubmitrunoperator-does-not-take-in-notebook-parameters)" target="test_blank"&gt;https://stackoverflow.com/questions/61542653/airflow-databrickssubmitrunoperator-does-not-take-in-notebook-parameters)&lt;/A&gt;&lt;/LI&gt;&lt;/OL&gt;</description>
    <pubDate>Thu, 22 Dec 2022 13:32:04 GMT</pubDate>
    <dc:creator>daniel_sahal</dc:creator>
    <dc:date>2022-12-22T13:32:04Z</dc:date>
    <item>
      <title>Airflow - How to pull XComs value in the notebook task?</title>
      <link>https://community.databricks.com/t5/data-engineering/airflow-how-to-pull-xcoms-value-in-the-notebook-task/m-p/16160#M10371</link>
      <description>&lt;P&gt;Using AIrflow, I have created a DAG with a sequence of notebook tasks.  The first notebook returns a batch id; the subsequent notebook tasks need this batch_id.&lt;/P&gt;&lt;P&gt;I am using the DatabricksSubmitRunOperator to run the notebook task. This operator pushes two values(run_id,run_page_url)  to airflow Xcom. I used the run_id and using the data bricks rest API, I retrieved the notebook output. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Xcom value retrieval works within the callable function of the python operator. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How would I do the same operation in the DatabricksSubmitRunOperator? &lt;/P&gt;&lt;P&gt;How do I get the handle to the task instance inside the notebook?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;U&gt;Working python operator code &lt;/U&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def pull_databricks_task_run_xcom_values(**kwargs):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;ti = kwargs['ti']&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;run_id = ti.xcom_pull(key='run_id', task_ids="notebook_task1")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;logger.info("======pulled value based on run_id:===== " +str(run_id))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;run_page_url = ti.xcom_pull(key='run_page_url', task_ids='initiate_batch')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;logger.info("======pulled value based on run_page_url:===== " +str(run_page_url))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with DAG('trigger_db_notebooks_tasks',start_date = days_ago(2),schedule_interval = None,default_args = default_args) as dag:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;#Task 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;notebook_task1=DatabricksSubmitRunOperator(task_id="notebook_task1",notebook_task=notebook_task1_dict,new_cluster=default_cluster_conf['clusters_spec'],do_xcom_push=True)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;#Task 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;xcom_pull=PythonOperator(task_id='download_files',provide_context=True,python_callable=pull_databricks_task_run_xcom_values)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Dec 2022 19:16:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/airflow-how-to-pull-xcoms-value-in-the-notebook-task/m-p/16160#M10371</guid>
      <dc:creator>Choolanadu</dc:creator>
      <dc:date>2022-12-17T19:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Airflow - How to pull XComs value in the notebook task?</title>
      <link>https://community.databricks.com/t5/data-engineering/airflow-how-to-pull-xcoms-value-in-the-notebook-task/m-p/16161#M10372</link>
      <description>&lt;P&gt;From what I understand - you want to pass a run_id parameter to the second notebook task?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can: &lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a widget param inside your databricks notebook (https://docs.databricks.com/notebooks/widgets.html) that will consume your run_id&lt;/LI&gt;&lt;LI&gt;Pass the parameter in DatabricksSubmitRunOperator (example here: &lt;A href="https://stackoverflow.com/questions/61542653/airflow-databrickssubmitrunoperator-does-not-take-in-notebook-parameters)" target="test_blank"&gt;https://stackoverflow.com/questions/61542653/airflow-databrickssubmitrunoperator-does-not-take-in-notebook-parameters)&lt;/A&gt;&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Thu, 22 Dec 2022 13:32:04 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/airflow-how-to-pull-xcoms-value-in-the-notebook-task/m-p/16161#M10372</guid>
      <dc:creator>daniel_sahal</dc:creator>
      <dc:date>2022-12-22T13:32:04Z</dc:date>
    </item>
  </channel>
</rss>

