Create repeated explores with different base views using view_name, view_label, from, and extends.

Knowledge Drop

Last tested: Sep 25, 2020
 

Scenario:
User consistently joins the same table to each of their explores, and wants to avoid having to write out 10 explores. So, different base view, same joined table on the same field from other views.

Solution:

explore: base {

view_name: base_table

join: joined_table {

sql_on: ${base_table.joined_table_id} = ${joined_table.id}

}

}

explore: table_1 {

view_label: "Table 1"

extends: [base]

from: table_1

}

explore: table_2 {

view_label: "Table 2"

extends: [base]

from: table_2

}

The view_name parameter in the base explore, that the extended explores will be based on, aliases the name of the table being used in the FROM statement in the generated SQL. By doing this, we can avoid having to rewrite the join since the other explores will be okay with having 'base_table' in the SQL because the from parameter tells us which view to actually use in the FROM statement of the generated SQL.

So for the table_1 explore, the generated SQL will look something like:

SELECT fields FROM table 1 AS 'base_table' JOIN joined_table ON base_table.joined_table_id = ...

The view_label ensures that the view only appears this way in the generated SQL but it's labeled appropriately in the Explore itself.

This content is subject to limited support.                

Version history
Last update:
‎07-07-2021 01:12 PM
Updated by: