cancel
Showing results for 
Search instead for 
Did you mean: 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results for 
Search instead for 
Did you mean: 

Parameters in dashboards data section passing via asset bundles

drag7ter
Contributor

A new functionality allows deploy dashboards with a asset bundles. Here is an example :

# This is the contents of the resulting baby_gender_by_county.dashboard.yml file.
resources:
  dashboards:
    baby_gender_by_county:
      display_name: "Baby gender by county"
      warehouse_id: aae11o8e6fe9zz79
      file_path: ../src/baby_gender_by_county.lvdash.json

In my dashboard Data section I have datasets and I want pass parameters to the query and use as parameter the same as I can do in jobs. Lets say catalog name, so I can specify variable and pass it in the bundle to deploy same dashboard to dev, prod:

SELECT * FROM IDENTIFIER(:catalog||'.my_schema.my_table')

And dashboard json file will have my parameters value from the bundle:

"datasets": [
    {
      "displayName": "My Dashboard",
      "name": "16b8c208",
      "parameters": [
        {
          "dataType": "STRING",
          "defaultSelection": {
            "values": {
              "dataType": "STRING",
              "values": [
                {
                  "value": "prod"
                }
              ]
            }
          },
          "displayName": "catalog",
          "keyword": "catalog"
        }
      ],
      "query": "SELECT * FROM IDENTIFIER(:catalog||'.my_schema.my_table')"
    },


Is it possible to pass parameters for Dashboards Datasets in asset bundles?

Or may be there is another way how to deploy the same json dashboard to PROD, DEV and somehow change queries, to use dev catalog in dev workspace, prod catalog in prod?

 

3 REPLIES 3

Alberto_Umana
Databricks Employee
Databricks Employee

Yes, it is possible to pass parameters for Dashboards Datasets in asset bundles. You can define custom variables in the bundle configuration file and use these variables in your dashboard queries

You can define variables in the databricks.yml file. For instance, you can define a variable for the catalog name:

 

variables:

  catalog:

    description: "Catalog name for the dataset"

    default: "dev"

You can reference these variables in your dashboard configuration file. For example, in your baby_gender_by_county.dashboard.yml file, you can use the variable in the query:

resources:

  dashboards:

    baby_gender_by_county:

      display_name: "Baby gender by county"

      warehouse_id: aae11o8e6fe9zz79

      file_path: ../src/baby_gender_by_county.lvdash.json

      parameters:

        catalog: ${var.catalog}

https://docs.databricks.com/en/dev-tools/bundles/settings.html

Thx for advice, but unfortunately it doesn't work, my cli version is 232:

Deploying resources...
Updating deployment state...
Deployment complete!
Warning: unknown field: parameters
at resources.dashboards.my_dashboard
in resources\dashboards\bundles\my_dashboard.yml:7:7

drag7ter
Contributor

variables:

  catalog:

    description: "Catalog name for the dataset"

    default: "dev"

 

parameters:

        catalog: ${var.catalog}

doesn't replace parameter values prod -> dev in json when it is being deployed

"datasets": [
    {
      "displayName": "my_table",
      "name": "16b8c208",
      "parameters": [
        {
          "dataType": "STRING",
          "defaultSelection": {
            "values": {
              "dataType": "STRING",
              "values": [
                {
                  "value": "prod"
                }
              ]
            }
          },
          "displayName": "catalog",
          "keyword": "catalog"
        }
      ],
      "query": "SELECT * FROM IDENTIFIER(:catalog||'.my_schema.my_table')"
    },



Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now