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

Exposure updated format #175

Merged
Changes from all commits
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
24 changes: 11 additions & 13 deletions dbtmetabase/metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,6 @@ def increase_indent(self, flow=False, indentless=False):
parsed_exposures = []

for collection in self.collections:

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert irrelevant changes.

# Exclude collections by name
if collection["name"] in collection_excludes:
continue
Expand All @@ -657,7 +656,6 @@ def increase_indent(self, flow=False, indentless=False):
# Iter through collection
logger().info(":sparkles: Exploring collection %s", collection["name"])
for item in self.api("get", f"/api/collection/{collection['id']}/items"):

# Ensure collection item is of parsable type
exposure_type = item["model"]
exposure_id = item["id"]
Expand All @@ -678,7 +676,6 @@ def increase_indent(self, flow=False, indentless=False):

# Process exposure
if exposure_type == "card":

# Build header for card and extract models to self.models_exposed
header = "### Visualization: {}\n\n".format(
exposure.get("display", "Unknown").title()
Expand All @@ -689,7 +686,6 @@ def increase_indent(self, flow=False, indentless=False):
native_query = self.native_query

elif exposure_type == "dashboard":

# We expect this dict key in order to iter through questions
if "ordered_cards" not in exposure:
continue
Expand Down Expand Up @@ -730,8 +726,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, underscores are 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 @@ -824,7 +820,6 @@ def _extract_card_exposures(

# Find models exposed through joins
for query_join in query.get("query", {}).get("joins", []):

# Handle questions based on other question in virtual db
if str(query_join.get("source-table", "")).startswith("card__"):
self._extract_card_exposures(
Expand Down Expand Up @@ -853,7 +848,6 @@ def _extract_card_exposures(

# Parse SQL for exposures through FROM or JOIN clauses
for sql_ref in re.findall(self.exposure_parser, native_query):

# Grab just the table / model name
clean_exposure = sql_ref.split(".")[-1].strip('"').upper()

Expand Down Expand Up @@ -951,11 +945,15 @@ 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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deduping in case a dashboard has two views on the same table.

set(
[
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
Loading