Dynamic Data Sources
This feature is under active development and will be coming soon!
Use Case
In some scenario, you want to point the dashboards to different data source (database or data warehouse) dynamically, based on who's viewing the report or whether it's in production or dev mode.
Thanks to its programmable nature, Holistics can support this capability natively. This will enable popular use cases such as:
- Clients Dashboarding: Build the same set of models/datasets/dashboards for clients but different data source for each client underneath.
- Dev/Prod environment: Dynamically switch the underlying data sources (from dev → prod and vice versa) based on the environment that analysts are working on
- Dynamic data sources for embedded analytics: Embedded analytics but different customers use different databases.
Approach
In Holistics, you can specify a function/expression in the data source definition (of dataset or data model).
// In a dataset
Dataset sales {
models: [ orders ]
data_source_name: function_or_expression_here
}
// Or in a data model
Model orders {
data_source_name: function_or_expression_here
dimension order_id { ... }
dimension user_id { ... }
...
}
The below example use an "if expression" to tell Holistics to use different database when doing development vs when deployed.
Dataset sales {
label: 'Dynamic Client Dataset'
models: [ ... ]
relationships: [ ... ]
data_source_name:
if (H_ENV.git.current_branch == 'master') {
'production'
} else if (H_ENV.git.current_branch == 'staging') {
'staging'
} else {
'develop'
}
}
Notes:
- Ensure data sources connected: You need to make sure you have defined the 3 data sources named
production
,staging
, anddevelop
. - Run-time evaluation: The expression is evaluated at run-time (i.e when dashboard is viewed, or queries are generated to send to database.
data_source_name
is only available when defining data model or dataset, not dashboard. The dataset's data source will override whatever defined in data model.
Available Variables
While not exhaustive, here are some common system variables you can use:
H.current_users.user_attribute
→ this will return the user_attribute value of the current user. You can use this to set data source dynamically by the user's viewing the dashboard.H.env.git.current_branch
→ this will return the name of the current branch
Example: Dynamical Data Source at User Level
Suppose you have many different customers who want the same set of reports. You maintain different data source for each customer. You want each customer when logging in to Holistics will be able to see the same reports but pointing to their respective database.
Here's how you can utilize user attributes in Holistics to achive that.
1. Connect databases
First, connect to all of your customers' databases.
2. Define new user attribute & set values for each user
Go to Users (or Group Management) in Holistics, define a new attribute name data_source
. You can do this either at the user level, or usergroup's level.
Once done, to go each user and set the corresponding data_source
value for them. For more information, refer to User Attributes
3. Write dynamic code to set data source
Dataset dynamic_client_dataset {
label: 'Dynamic Client Dataset'
// The underlying data source will be dynamically switched based on who use it
data_source_name: H.current_user.data_source
models: [ revenue ]
relationships: [ ]
}
4. Test your setup by using our View As feature
In this step, you can test how a specific group of users will view your dashboard by using the View As
feature.
By selecting a particular user or user group, the corresponding value of their user attribute (in this case, the data source name) will be applied to the data_source_name
property of the dataset (and model). This allows the same dashboards to display different data for different users.
The list of users and user groups available in the View As
option is directly retrieved from the User Management page.