<?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 Databricks Job : Unable to read Databricks job run parameter in scala code and sql query. in Administration &amp; Architecture</title>
    <link>https://community.databricks.com/t5/administration-architecture/databricks-job-unable-to-read-databricks-job-run-parameter-in/m-p/141671#M4632</link>
    <description>&lt;P&gt;we are created data bricks job with Jar (scala code) and provided parameters/jar parameters and able to read those as arguments in main method.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;we are running job with parameters (run parameters / job parameters) , those parametes are not able to read in scala code and sql query.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;we tried creating widget and getting parameters. it is also not working.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Could you please suggest any way to read run parameters/ job parameters.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Dec 2025 13:46:29 GMT</pubDate>
    <dc:creator>kumarV</dc:creator>
    <dc:date>2025-12-11T13:46:29Z</dc:date>
    <item>
      <title>Databricks Job : Unable to read Databricks job run parameter in scala code and sql query.</title>
      <link>https://community.databricks.com/t5/administration-architecture/databricks-job-unable-to-read-databricks-job-run-parameter-in/m-p/141671#M4632</link>
      <description>&lt;P&gt;we are created data bricks job with Jar (scala code) and provided parameters/jar parameters and able to read those as arguments in main method.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;we are running job with parameters (run parameters / job parameters) , those parametes are not able to read in scala code and sql query.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;we tried creating widget and getting parameters. it is also not working.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Could you please suggest any way to read run parameters/ job parameters.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Dec 2025 13:46:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/administration-architecture/databricks-job-unable-to-read-databricks-job-run-parameter-in/m-p/141671#M4632</guid>
      <dc:creator>kumarV</dc:creator>
      <dc:date>2025-12-11T13:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks Job : Unable to read Databricks job run parameter in scala code and sql query.</title>
      <link>https://community.databricks.com/t5/administration-architecture/databricks-job-unable-to-read-databricks-job-run-parameter-in/m-p/141741#M4633</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/200490"&gt;@kumarV&lt;/a&gt;&amp;nbsp;, I did some digging and here are some hints/tips to help you further troubleshoot.&lt;/P&gt;
&lt;P class="p1"&gt;Yep — this really comes down to how parameters flow through Lakeflow Jobs depending on the task type. JAR tasks are the odd duck: they don’t get the same “key/value auto-pushdown” behavior that SQL tasks and notebooks do. Here’s the clean mental model and the wiring pattern that will make both your Scala (JAR) and SQL behave predictably.&lt;/P&gt;
&lt;P class="p1"&gt;What’s going on (and why your current approach is failing)&lt;/P&gt;
&lt;OL start="1"&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;JAR tasks only get positional args&lt;/P&gt;
&lt;P class="p1"&gt;A JAR task’s entrypoint is main(String[] args). Databricks will only pass what you explicitly put into the JAR task’s Parameters list, and it passes those values as a JSON array -&amp;gt; args[].&lt;/P&gt;
&lt;P class="p1"&gt;Job parameters are not magically injected into the JAR task unless you reference them there.&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P class="p1"&gt;Also: widgets are notebook-only. dbutils.widgets is not a JAR task thing, so any “widget style” approach will dead-end.&lt;/P&gt;
&lt;OL start="2"&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;Job parameters auto-push only into task types that accept key/value params&lt;/P&gt;
&lt;P class="p1"&gt;Notebook tasks, SQL tasks, Python wheel tasks with keyword args, Run Job tasks, etc. can consume named parameters more naturally.&lt;/P&gt;
&lt;P class="p1"&gt;JAR tasks don’t, because they’re an array.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;SQL parameter syntax depends on where the SQL runs&lt;/P&gt;
&lt;P class="p1"&gt;SQL task (query/file): use {{parameter_key}}.&lt;/P&gt;
&lt;P class="p1"&gt;SQL inside a notebook cell: use named params like :year_param, and fetch/set via widgets/job parameters.&lt;/P&gt;
&lt;P class="p1"&gt;Spark SQL in Scala (inside the JAR): no notebook-style named parameters; read from args and use DataFrame APIs (preferred) or careful string interpolation.&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;How to pass job/run parameters into a JAR task (Scala)&lt;/P&gt;
&lt;P class="p1"&gt;Step 1: Define job parameters (job-level)&lt;/P&gt;
&lt;P class="p1"&gt;Example: input_table, process_date.&lt;/P&gt;
&lt;P class="p1"&gt;This gives you defaults and enables “Run now with different parameters”.&lt;/P&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;Step 2: In the JAR task, explicitly thread them into Parameters using dynamic references&lt;/P&gt;
&lt;P class="p1"&gt;In the UI (JAR task → Parameters), do something like:&lt;/P&gt;
&lt;P class="p1"&gt;–input_table&lt;/P&gt;
&lt;P class="p1"&gt;{{job.parameters.input_table}}&lt;/P&gt;
&lt;P class="p1"&gt;–process_date&lt;/P&gt;
&lt;P class="p1"&gt;{{job.parameters.process_date}}&lt;/P&gt;
&lt;P class="p1"&gt;That forces the resolved values into args[] for that run.&lt;/P&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;Step 3: Parse args in Scala and use them safely&lt;/P&gt;
&lt;P class="p1"&gt;Your sliding(2,2) pattern is totally fine for a minimal parser:&lt;/P&gt;
&lt;P class="p1"&gt;object Main {&lt;/P&gt;
&lt;P class="p1"&gt;def main(args: Array[String]): Unit = {&lt;/P&gt;
&lt;P class="p1"&gt;val params = args.sliding(2, 2).toList.collect { case Array(k, v) =&amp;gt; k -&amp;gt; v }.toMap&lt;/P&gt;
&lt;P class="p1"&gt;val inputTable&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;= params.getOrElse(”–input_table”, sys.error(“Missing –input_table”))&lt;/P&gt;
&lt;P class="p1"&gt;val processDate = params.getOrElse(”–process_date”, sys.error(“Missing –process_date”))&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;val spark = org.apache.spark.sql.SparkSession.builder().getOrCreate()
import spark.implicits._

val df = spark.table(inputTable).filter($"process_date" === processDate)
df.write.mode("overwrite").saveAsTable(s"${inputTable}_processed")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;}&lt;/P&gt;
&lt;P class="p1"&gt;}&lt;/P&gt;
&lt;P class="p1"&gt;Step 4: “Run now with different parameters” just works&lt;/P&gt;
&lt;P class="p1"&gt;When you override job parameters at runtime, those dynamic references expand into new resolved values, and your JAR sees them as args for that run.&lt;/P&gt;
&lt;P class="p1"&gt;How to use parameters in SQL (pick the lane)&lt;/P&gt;
&lt;P class="p1"&gt;A) SQL Task (query/file)&lt;/P&gt;
&lt;P class="p1"&gt;Reference parameters inside the SQL asset using:&lt;/P&gt;
&lt;P class="p1"&gt;SELECT *&lt;/P&gt;
&lt;P class="p1"&gt;FROM {{input_table}}&lt;/P&gt;
&lt;P class="p1"&gt;WHERE process_date = ‘{{process_date}}’;&lt;/P&gt;
&lt;P class="p1"&gt;If the task supports it, the job parameters will be available by key, or you can define task parameters explicitly.&lt;/P&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;B) SQL inside a notebook task&lt;/P&gt;
&lt;P class="p1"&gt;Use widgets + named parameter syntax.&lt;/P&gt;
&lt;P class="p1"&gt;In a SQL cell:&lt;/P&gt;
&lt;P class="p1"&gt;SELECT *&lt;/P&gt;
&lt;P class="p1"&gt;FROM baby_names_prepared&lt;/P&gt;
&lt;P class="p1"&gt;WHERE Year_Of_Birth = :year_param&lt;/P&gt;
&lt;P class="p1"&gt;And in Python/Scala notebook code (not JAR code), you can read:&lt;/P&gt;
&lt;P class="p1"&gt;dbutils.widgets.get(“year_param”)&lt;/P&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;C) Spark SQL inside your Scala JAR&lt;/P&gt;
&lt;P class="p1"&gt;Read from args, then use DataFrame APIs to avoid building fragile SQL strings.&lt;/P&gt;
&lt;P class="p1"&gt;Debugging checklist (the stuff that saves hours)&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;Keys must match exactly (case-sensitive) across job params, task config, and your code.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;For the JAR task, check run details and confirm Resolved Parameters show the expanded values, and that args order is what your parser expects.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;Widgets do not apply to JAR tasks. If you see dbutils.widgets in JAR code, that’s the bug.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="p1"&gt;If you need to pass values between tasks, use task values from an upstream notebook and reference them downstream with something like:&lt;/P&gt;
&lt;P class="p1"&gt;{{tasks.prev_task.values.some_key}}&lt;/P&gt;
&lt;P class="p1"&gt;inside the JAR Parameters array.&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P class="p1"&gt;Hope this helps, Louis.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Dec 2025 11:00:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/administration-architecture/databricks-job-unable-to-read-databricks-job-run-parameter-in/m-p/141741#M4633</guid>
      <dc:creator>Louis_Frolio</dc:creator>
      <dc:date>2025-12-12T11:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks Job : Unable to read Databricks job run parameter in scala code and sql query.</title>
      <link>https://community.databricks.com/t5/administration-architecture/databricks-job-unable-to-read-databricks-job-run-parameter-in/m-p/142181#M4654</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/34815"&gt;@Louis_Frolio&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;&lt;STRONG&gt;Thank you for your suggestion. We are following the approach you recommended, but we encountered an issue while creating the job.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;We are creating a Databricks job using a JSON file through a pipeline. When we declare job-level parameters under spark_job and reference them in task-level parameters using {{job.parameters.&amp;lt;name&amp;gt;}} in the JSON file, the job creation fails during the Terraform transformation process.&lt;/P&gt;&lt;P&gt;Could you please suggest an alternative way to declare and use job-level parameters in this scenario?&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 18 Dec 2025 16:11:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/administration-architecture/databricks-job-unable-to-read-databricks-job-run-parameter-in/m-p/142181#M4654</guid>
      <dc:creator>kumarV</dc:creator>
      <dc:date>2025-12-18T16:11:39Z</dc:date>
    </item>
  </channel>
</rss>

