<?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: Passing UNIX-based parameter to a task in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/passing-unix-based-parameter-to-a-task/m-p/97153#M39437</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/127157"&gt;@Garrus990&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;To pass a parameter to a task that is based on a UNIX function, you can use the Databricks Jobs API to dynamically calculate dates with respect to the date of running your job.&amp;nbsp;&lt;/P&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;STRONG&gt;Use a Notebook to Calculate Dates&lt;/STRONG&gt;: Create a notebook that calculates the required dates using Python or Scala. For example, in Python:&lt;/P&gt;
&lt;DIV class="gb5fhw1"&gt;
&lt;PRE&gt;&lt;CODE class="markdown-code-python _1t7bu9hb hljs language-python gb5fhw2"&gt;%py &lt;BR /&gt;&lt;SPAN class="hljs-keyword"&gt;from&lt;/SPAN&gt; datetime &lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; datetime, timedelta

 period_start = (datetime.now() - timedelta(days=&lt;SPAN class="hljs-number"&gt;7&lt;/SPAN&gt;)).strftime(&lt;SPAN class="hljs-string"&gt;'%Y-%m-%d'&lt;/SPAN&gt;)
 period_end = (datetime.now() - timedelta(days=&lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt;)).strftime(&lt;SPAN class="hljs-string"&gt;'%Y-%m-%d'&lt;/SPAN&gt;)

 dbutils.notebook.exit(&lt;SPAN class="hljs-string"&gt;f'{{"period_start": "&lt;SPAN class="hljs-subst"&gt;{period_start}&lt;/SPAN&gt;", "period_end": "&lt;SPAN class="hljs-subst"&gt;{period_end}&lt;/SPAN&gt;"}}'&lt;/SPAN&gt;)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="gb5fhw3"&gt;
&lt;DIV class="gb5fhw4"&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;STRONG&gt;Run the Notebook as a Job&lt;/STRONG&gt;: Configure this notebook as a job in Databricks. This job will calculate the dates and return them as a JSON string.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;STRONG&gt;Use the Output in Subsequent Tasks&lt;/STRONG&gt;: In your main job, use the output of the first notebook as input parameters for subsequent tasks. You can achieve this by chaining jobs and passing the output of one job to another.&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;Here is an example of how you can set up the job configuration:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;STRONG&gt;Job 1&lt;/STRONG&gt;: Calculate Dates&lt;/P&gt;
&lt;UL class="_1t7bu9h7 _1t7bu9h2"&gt;
&lt;LI&gt;Notebook: &lt;CODE&gt;calculate_dates&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;Output: &lt;CODE&gt;{"period_start": "2024-10-25", "period_end": "2024-10-31"}&lt;/CODE&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;STRONG&gt;Job 2&lt;/STRONG&gt;: Main Job&lt;/P&gt;
&lt;UL class="_1t7bu9h7 _1t7bu9h2"&gt;
&lt;LI&gt;Notebook: &lt;CODE&gt;main_job&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;Parameters: &lt;CODE&gt;--period-start {{job1_output.period_start}} --period-end {{job1_output.period_end}}&lt;/CODE&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
Thanks!&lt;/DIV&gt;
&lt;DIV class="gb5fhw4"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Fri, 01 Nov 2024 05:31:37 GMT</pubDate>
    <dc:creator>NandiniN</dc:creator>
    <dc:date>2024-11-01T05:31:37Z</dc:date>
    <item>
      <title>Passing UNIX-based parameter to a task</title>
      <link>https://community.databricks.com/t5/data-engineering/passing-unix-based-parameter-to-a-task/m-p/94196#M38835</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;I would like to pass to a task a parameter that is based on a UNIX function. Concretely, I would like to specify dates - dynamically calculated with respect to the date of running my job. I wanted to it like that:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;"--period-start"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"$(date -d '-7 days' +'%Y-%m-%d')"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"--period-end"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"$(date -d '-1 days' +'%Y-%m-%d')"&lt;/SPAN&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;It doesn't seem to work, though. Is there any way of achieving it?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2024 20:13:53 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/passing-unix-based-parameter-to-a-task/m-p/94196#M38835</guid>
      <dc:creator>Garrus990</dc:creator>
      <dc:date>2024-10-15T20:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Passing UNIX-based parameter to a task</title>
      <link>https://community.databricks.com/t5/data-engineering/passing-unix-based-parameter-to-a-task/m-p/97153#M39437</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/127157"&gt;@Garrus990&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;To pass a parameter to a task that is based on a UNIX function, you can use the Databricks Jobs API to dynamically calculate dates with respect to the date of running your job.&amp;nbsp;&lt;/P&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;STRONG&gt;Use a Notebook to Calculate Dates&lt;/STRONG&gt;: Create a notebook that calculates the required dates using Python or Scala. For example, in Python:&lt;/P&gt;
&lt;DIV class="gb5fhw1"&gt;
&lt;PRE&gt;&lt;CODE class="markdown-code-python _1t7bu9hb hljs language-python gb5fhw2"&gt;%py &lt;BR /&gt;&lt;SPAN class="hljs-keyword"&gt;from&lt;/SPAN&gt; datetime &lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; datetime, timedelta

 period_start = (datetime.now() - timedelta(days=&lt;SPAN class="hljs-number"&gt;7&lt;/SPAN&gt;)).strftime(&lt;SPAN class="hljs-string"&gt;'%Y-%m-%d'&lt;/SPAN&gt;)
 period_end = (datetime.now() - timedelta(days=&lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt;)).strftime(&lt;SPAN class="hljs-string"&gt;'%Y-%m-%d'&lt;/SPAN&gt;)

 dbutils.notebook.exit(&lt;SPAN class="hljs-string"&gt;f'{{"period_start": "&lt;SPAN class="hljs-subst"&gt;{period_start}&lt;/SPAN&gt;", "period_end": "&lt;SPAN class="hljs-subst"&gt;{period_end}&lt;/SPAN&gt;"}}'&lt;/SPAN&gt;)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="gb5fhw3"&gt;
&lt;DIV class="gb5fhw4"&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;STRONG&gt;Run the Notebook as a Job&lt;/STRONG&gt;: Configure this notebook as a job in Databricks. This job will calculate the dates and return them as a JSON string.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;STRONG&gt;Use the Output in Subsequent Tasks&lt;/STRONG&gt;: In your main job, use the output of the first notebook as input parameters for subsequent tasks. You can achieve this by chaining jobs and passing the output of one job to another.&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;Here is an example of how you can set up the job configuration:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;STRONG&gt;Job 1&lt;/STRONG&gt;: Calculate Dates&lt;/P&gt;
&lt;UL class="_1t7bu9h7 _1t7bu9h2"&gt;
&lt;LI&gt;Notebook: &lt;CODE&gt;calculate_dates&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;Output: &lt;CODE&gt;{"period_start": "2024-10-25", "period_end": "2024-10-31"}&lt;/CODE&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;STRONG&gt;Job 2&lt;/STRONG&gt;: Main Job&lt;/P&gt;
&lt;UL class="_1t7bu9h7 _1t7bu9h2"&gt;
&lt;LI&gt;Notebook: &lt;CODE&gt;main_job&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;Parameters: &lt;CODE&gt;--period-start {{job1_output.period_start}} --period-end {{job1_output.period_end}}&lt;/CODE&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
Thanks!&lt;/DIV&gt;
&lt;DIV class="gb5fhw4"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 01 Nov 2024 05:31:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/passing-unix-based-parameter-to-a-task/m-p/97153#M39437</guid>
      <dc:creator>NandiniN</dc:creator>
      <dc:date>2024-11-01T05:31:37Z</dc:date>
    </item>
  </channel>
</rss>

