Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed exposure names and added labels #172

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions dbtmetabase/metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,9 @@ def increase_indent(self, flow=False, indentless=False):
creator_email = creator.get("email")
creator_name = creator.get("common_name")

# No spaces allowed in model names in dbt docs DAG / No duplicate model names
exposure_name = exposure_name.replace(" ", "_")
exposure_label = exposure_name
# Only lower case letters and underscores allowed in model names in dbt docs DAG / No duplicate model names
exposure_name = re.sub("[^a-z0-9]", "_", exposure_name.lower())
gouline marked this conversation as resolved.
Show resolved Hide resolved
enumer = 1
while exposure_name in documented_exposure_names:
exposure_name = f"{exposure_name}_{enumer}"
Expand All @@ -742,6 +743,7 @@ def increase_indent(self, flow=False, indentless=False):
exposure_type=exposure_type,
exposure_id=exposure_id,
name=exposure_name,
label=exposure_label,
header=header,
created_at=exposure["created_at"],
creator_name=creator_name,
Expand Down Expand Up @@ -875,6 +877,7 @@ def _build_exposure(
exposure_type: str,
exposure_id: int,
name: str,
label: str,
header: str,
created_at: str,
creator_name: str,
Expand All @@ -888,7 +891,8 @@ def _build_exposure(
Arguments:
exposure_type {str} -- Model type in Metabase being either `card` or `dashboard`
exposure_id {str} -- Card or Dashboard id in Metabase
name {str} -- Name of exposure as the title of the card or dashboard in Metabase
name {str} -- Name of exposure
label {str} -- Title of the card or dashboard in Metabase
header {str} -- The header goes at the top of the description and is useful for prefixing metadata
created_at {str} -- Timestamp of exposure creation derived from Metabase
creator_name {str} -- Creator name derived from Metabase
Expand Down Expand Up @@ -938,6 +942,7 @@ def _build_exposure(

return {
"name": name,
"label": label,
"description": description,
"type": "analysis" if exposure_type == "card" else "dashboard",
"url": f"{self.base_url}/{exposure_type}/{exposure_id}",
Expand Down
55 changes: 37 additions & 18 deletions tests/fixtures/exposure/baseline_test_exposures.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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 @@ -22,7 +24,8 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Orders,_Count
- name: orders__count
label: Orders, Count
description: '### Visualization: Scalar


Expand All @@ -44,7 +47,8 @@ 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 @@ -66,7 +70,8 @@ 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 @@ -88,7 +93,8 @@ 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 @@ -110,7 +116,8 @@ 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 @@ -132,7 +139,8 @@ 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 @@ -154,7 +162,8 @@ 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 @@ -176,7 +185,8 @@ 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 @@ -198,7 +208,8 @@ 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 @@ -220,7 +231,8 @@ 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 @@ -242,7 +254,8 @@ 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 @@ -264,7 +277,8 @@ 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 @@ -286,7 +300,8 @@ 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 @@ -308,7 +323,8 @@ 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 @@ -330,7 +346,8 @@ 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 @@ -352,7 +369,8 @@ 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 @@ -374,7 +392,8 @@ exposures:
email: [email protected]
depends_on:
- ref('customers')
- name: Total_customers
- name: total_customers
label: Total customers
description: '### Visualization: Scalar


Expand Down
Loading