Looker's User Attributes feature can be used to dynamically insert schema and/or table names on a per-user basis.
The first step is to
create a user attribute,
such as custom_schema
or custom_table
, to which you
will assign a value for each user. You can assign these values:
- Through the UI
- In bulk via the API
- In the SSO URL for embedded contexts.
Once you have created the user attribute and assigned the appropriate value for
your users, you can add a reference to that attribute in the
sql_table_name
of your view files, via
Liquid variables.
Following are two examples, one using a custom schema and one a custom table.
Example A
Using a custom_schema
:
view: events { sql_table_name: {{ _user_attributes['custom_schema'] }}.events ;; dimension: event_id { type: number primary_key: yes sql: ${TABLE}.id ;; } }
Example B
Using a custom_table
:
view: events { sql_table_name: web_traffic.{{ _user_attributes['custom_event_table_name'] }} ;; dimension: event_id { type: number primary_key: yes sql: ${TABLE}.id ;; } }