Skip to content

Commit

Permalink
Exposure updated format (#182)
Browse files Browse the repository at this point in the history
* Exposure updated format (#175)

* Changed exposure format (lowercased name, deduped depends_on).

* Change where the lowercasing happens.

* Hyphens are no longer allowed.

* Updated comment.

* Revert useless formatting

* Set comprehension for deduping

* Lowercase all exposure names in tests

---------

Co-authored-by: Elon Gliksberg <[email protected]>
  • Loading branch information
gouline and elongl authored Oct 6, 2023
1 parent abf5517 commit bda1a40
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ emails & names, links to exposures, and even native SQL propagated over from Met
.. code-block:: yaml
exposures:
- name: Number_of_orders_over_time
- name: number_of_orders_over_time
description: '
### Visualization: Line
Expand Down
16 changes: 9 additions & 7 deletions dbtmetabase/metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ def increase_indent(self, flow=False, indentless=False):
creator_name = creator.get("common_name")

exposure_label = exposure_name
# Only letters, numbers, underscores and hyphens allowed in model names in dbt docs DAG / No duplicate model names
exposure_name = re.sub(r"[^\w-]", "_", exposure_name)
# Only letters, numbers and underscores allowed in model names in dbt docs DAG / No duplicate model names
exposure_name = re.sub(r"[^\w]", "_", exposure_name).lower()
enumer = 1
while exposure_name in documented_exposure_names:
exposure_name = f"{exposure_name}_{enumer}"
Expand Down Expand Up @@ -951,11 +951,13 @@ def _build_exposure(
"name": creator_name,
"email": creator_email or "",
},
"depends_on": [
refable_models[exposure.upper()]
for exposure in list({m for m in self.models_exposed})
if exposure.upper() in refable_models
],
"depends_on": list(
{
refable_models[exposure.upper()]
for exposure in list({m for m in self.models_exposed})
if exposure.upper() in refable_models
}
),
}

def api(
Expand Down
36 changes: 18 additions & 18 deletions tests/fixtures/exposure/baseline_test_exposures.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2
exposures:
- name: Customers__Sum_of_Number_Of_Orders_and_Average_of_Number_Of_Orders__Grouped_by_Most_Recent_Order__day_
- name: customers__sum_of_number_of_orders_and_average_of_number_of_orders__grouped_by_most_recent_order__day_
label: Customers, Sum of Number Of Orders and Average of Number Of Orders, Grouped
by Most Recent Order (day)
description: '### Visualization: Line
Expand All @@ -24,7 +24,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Orders__Count
- name: orders__count
label: Orders, Count
description: '### Visualization: Scalar
Expand All @@ -47,7 +47,7 @@ exposures:
email: [email protected]
depends_on:
- ref('orders')
- name: A_look_at_your_customers_table
- name: a_look_at_your_customers_table
label: A look at your customers table
description: '### Dashboard Cards: 18
Expand All @@ -70,7 +70,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Customer_lifetime_value_over_time
- name: customer_lifetime_value_over_time
label: Customer_lifetime_value over time
description: '### Visualization: Line
Expand All @@ -93,7 +93,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Customer_lifetime_value_over_time_1
- name: customer_lifetime_value_over_time_1
label: Customer_lifetime_value over time
description: '### Visualization: Line
Expand All @@ -116,7 +116,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Customers_added_in_the_last_30_days
- name: customers_added_in_the_last_30_days
label: Customers added in the last 30 days
description: '### Visualization: Scalar
Expand All @@ -139,7 +139,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Customers_added_in_the_last_30_days_1
- name: customers_added_in_the_last_30_days_1
label: Customers added in the last 30 days
description: '### Visualization: Scalar
Expand All @@ -162,7 +162,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Customers_by_customer_lifetime_value
- name: customers_by_customer_lifetime_value
label: Customers by customer_lifetime_value
description: '### Visualization: Bar
Expand All @@ -185,7 +185,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Customers_by_number_of_orders
- name: customers_by_number_of_orders
label: Customers by number_of_orders
description: '### Visualization: Bar
Expand All @@ -208,7 +208,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Number_of_orders_over_time
- name: number_of_orders_over_time
label: Number_of_orders over time
description: '### Visualization: Line
Expand All @@ -231,7 +231,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Number_of_orders_over_time_1
- name: number_of_orders_over_time_1
label: Number_of_orders over time
description: '### Visualization: Line
Expand All @@ -254,7 +254,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Timestamp_by_day_of_the_week
- name: timestamp_by_day_of_the_week
label: Timestamp by day of the week
description: '### Visualization: Bar
Expand All @@ -277,7 +277,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Timestamp_by_day_of_the_week_1
- name: timestamp_by_day_of_the_week_1
label: Timestamp by day of the week
description: '### Visualization: Bar
Expand All @@ -300,7 +300,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Timestamp_by_month_of_the_year
- name: timestamp_by_month_of_the_year
label: Timestamp by month of the year
description: '### Visualization: Bar
Expand All @@ -323,7 +323,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Timestamp_by_month_of_the_year_1
- name: timestamp_by_month_of_the_year_1
label: Timestamp by month of the year
description: '### Visualization: Bar
Expand All @@ -346,7 +346,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Timestamp_by_quarter_of_the_year
- name: timestamp_by_quarter_of_the_year
label: Timestamp by quarter of the year
description: '### Visualization: Bar
Expand All @@ -369,7 +369,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Timestamp_by_quarter_of_the_year_1
- name: timestamp_by_quarter_of_the_year_1
label: Timestamp by quarter of the year
description: '### Visualization: Bar
Expand All @@ -392,7 +392,7 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Total_customers
- name: total_customers
label: Total customers
description: '### Visualization: Scalar
Expand Down

0 comments on commit bda1a40

Please sign in to comment.