cancel
Showing results for 
Search instead for 
Did you mean: 
Community Platform Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results for 
Search instead for 
Did you mean: 

Parameters in dashboards data section passing via asset bundles

drag7ter
New Contributor III

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
New Contributor III

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')"
    },



Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group