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

fix: exposure parsing with aliased model #283

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion dbtmetabase/_exposures.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def extract_exposures(
models = self.manifest.read_models()

ctx = self.__Context(
model_refs={m.name.lower(): m.ref for m in models if m.ref},
model_refs={m.alias.lower(): m.ref for m in models if m.ref},
table_names={t["id"]: t["name"] for t in self.metabase.get_tables()},
)

Expand Down
Binary file modified sandbox/metabase/metabase.db.mv.db
Binary file not shown.
3 changes: 3 additions & 0 deletions sandbox/models/payments.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ config(alias='transactions') }}

select * from {{ ref('stg_payments') }}
26 changes: 26 additions & 0 deletions sandbox/models/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,29 @@ models:
description: Amount of the order (AUD) paid for by gift card
data_tests:
- not_null

- name: payments
description: This table has basic information about payments
columns:
- name: payment_id
constraints:
- type: primary_key
data_tests:
- unique
- not_null
description: This is a unique identifier for a payment

- name: payment_method
data_tests:
- accepted_values:
values: ['credit_card', 'coupon', 'bank_transfer', 'gift_card']

- name: order_id
description: Foreign key to the orders table
constraints:
- type: foreign_key
expression: orders (order_id)
data_tests:
- not_null

- name: amount
4 changes: 2 additions & 2 deletions tests/fixtures/api/card/27.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cache_invalidated_at": null,
"description": "Orders and customers",
"archived": false,
"view_count": 389,
"view_count": 425,
"collection_position": null,
"table_id": 10,
"can_run_adhoc_query": true,
Expand Down Expand Up @@ -561,7 +561,7 @@
"creator": {
"email": "[email protected]",
"first_name": "dbtmetabase",
"last_login": "2024-07-04T05:55:25.914119Z",
"last_login": "2024-10-12T02:16:15.081959Z",
"is_qbnewb": false,
"is_superuser": true,
"id": 1,
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/api/card/28.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cache_invalidated_at": null,
"description": null,
"archived": false,
"view_count": 194,
"view_count": 212,
"collection_position": null,
"table_id": 10,
"can_run_adhoc_query": true,
Expand Down Expand Up @@ -549,7 +549,7 @@
"creator": {
"email": "[email protected]",
"first_name": "dbtmetabase",
"last_login": "2024-07-04T05:55:25.914119Z",
"last_login": "2024-10-12T02:16:15.081959Z",
"is_qbnewb": false,
"is_superuser": true,
"id": 1,
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/api/card/29.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cache_invalidated_at": null,
"description": null,
"archived": false,
"view_count": 193,
"view_count": 211,
"collection_position": null,
"table_id": null,
"can_run_adhoc_query": true,
Expand Down Expand Up @@ -41,7 +41,7 @@
"creator": {
"email": "[email protected]",
"first_name": "dbtmetabase",
"last_login": "2024-07-04T05:55:25.914119Z",
"last_login": "2024-10-12T02:16:15.081959Z",
"is_qbnewb": false,
"is_superuser": true,
"id": 1,
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/api/card/30.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cache_invalidated_at": null,
"description": "Dummy 1",
"archived": false,
"view_count": 28,
"view_count": 37,
"collection_position": null,
"table_id": null,
"can_run_adhoc_query": true,
Expand Down Expand Up @@ -41,7 +41,7 @@
"creator": {
"email": "[email protected]",
"first_name": "dbtmetabase",
"last_login": "2024-07-04T05:55:25.914119Z",
"last_login": "2024-10-12T02:16:15.081959Z",
"is_qbnewb": false,
"is_superuser": true,
"id": 1,
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/api/card/31.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cache_invalidated_at": null,
"description": "Dummy 2",
"archived": false,
"view_count": 28,
"view_count": 37,
"collection_position": null,
"table_id": null,
"can_run_adhoc_query": true,
Expand Down Expand Up @@ -41,7 +41,7 @@
"creator": {
"email": "[email protected]",
"first_name": "dbtmetabase",
"last_login": "2024-07-04T05:55:25.914119Z",
"last_login": "2024-10-12T02:16:15.081959Z",
"is_qbnewb": false,
"is_superuser": true,
"id": 1,
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/api/card/32.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cache_invalidated_at": null,
"description": "CTE SQL",
"archived": false,
"view_count": 19,
"view_count": 28,
"collection_position": null,
"table_id": null,
"can_run_adhoc_query": true,
Expand Down Expand Up @@ -276,7 +276,7 @@
"creator": {
"email": "[email protected]",
"first_name": "dbtmetabase",
"last_login": "2024-07-04T05:55:25.914119Z",
"last_login": "2024-10-12T02:16:15.081959Z",
"is_qbnewb": false,
"is_superuser": true,
"id": 1,
Expand Down
210 changes: 210 additions & 0 deletions tests/fixtures/api/card/33.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
{
"cache_invalidated_at": null,
"description": null,
"archived": false,
"view_count": 9,
"collection_position": null,
"table_id": 18,
"can_run_adhoc_query": true,
"result_metadata": [
{
"description": "This is a unique identifier for a payment",
"semantic_type": "type/PK",
"coercion_strategy": null,
"name": "payment_id",
"settings": null,
"fk_target_field_id": null,
"field_ref": [
"field",
111,
null
],
"effective_type": "type/Integer",
"id": 111,
"visibility_type": "normal",
"display_name": "Payment ID",
"fingerprint": {
"global": {
"distinct-count": 113,
"nil%": 0.0
},
"type": {
"type/Number": {
"min": 1.0,
"q1": 28.75,
"q3": 85.25,
"max": 113.0,
"sd": 32.76097144469315,
"avg": 57.0
}
}
},
"base_type": "type/Integer"
},
{
"description": null,
"semantic_type": "type/Category",
"coercion_strategy": null,
"name": "payment_method",
"settings": null,
"fk_target_field_id": null,
"field_ref": [
"field",
113,
null
],
"effective_type": "type/Text",
"id": 113,
"visibility_type": "normal",
"display_name": "Payment Method",
"fingerprint": {
"global": {
"distinct-count": 4,
"nil%": 0.0
},
"type": {
"type/Text": {
"percent-json": 0.0,
"percent-url": 0.0,
"percent-email": 0.0,
"percent-state": 0.0,
"average-length": 10.79646017699115
}
}
},
"base_type": "type/Text"
},
{
"description": "Foreign key to the orders table",
"semantic_type": "type/FK",
"coercion_strategy": null,
"name": "order_id",
"settings": null,
"fk_target_field_id": 84,
"field_ref": [
"field",
112,
null
],
"effective_type": "type/Integer",
"id": 112,
"visibility_type": "normal",
"display_name": "Order ID",
"fingerprint": {
"global": {
"distinct-count": 99,
"nil%": 0.0
},
"type": {
"type/Number": {
"min": 1.0,
"q1": 24.904857366030992,
"q3": 75.25,
"max": 99.0,
"sd": 28.540193317267853,
"avg": 50.0353982300885
}
}
},
"base_type": "type/Integer"
},
{
"description": null,
"semantic_type": "type/Category",
"coercion_strategy": null,
"name": "amount",
"settings": null,
"fk_target_field_id": null,
"field_ref": [
"field",
114,
null
],
"effective_type": "type/Integer",
"id": 114,
"visibility_type": "normal",
"display_name": "Amount",
"fingerprint": {
"global": {
"distinct-count": 30,
"nil%": 0.0
},
"type": {
"type/Number": {
"min": 0.0,
"q1": 6.064037815689349,
"q3": 22.787918451395115,
"max": 30.0,
"sd": 9.198368733518729,
"avg": 14.79646017699115
}
}
},
"base_type": "type/Integer"
}
],
"creator": {
"email": "[email protected]",
"first_name": "dbtmetabase",
"last_login": "2024-10-12T02:16:15.081959Z",
"is_qbnewb": false,
"is_superuser": true,
"id": 1,
"last_name": null,
"date_joined": "2024-06-19T11:49:37.507897Z",
"common_name": "dbtmetabase"
},
"initially_published_at": null,
"can_write": true,
"database_id": 2,
"enable_embedding": false,
"collection_id": null,
"query_type": "query",
"name": "Transactions",
"last_query_start": "2024-10-12T01:52:30.557471Z",
"dashboard_count": 0,
"last_used_at": "2024-10-12T01:52:30.585371Z",
"type": "question",
"average_query_time": 58.0,
"creator_id": 1,
"moderation_reviews": [],
"updated_at": "2024-10-12T01:52:30.606845Z",
"made_public_by_id": null,
"embedding_params": null,
"cache_ttl": null,
"dataset_query": {
"database": 2,
"type": "query",
"query": {
"source-table": 18
}
},
"id": 33,
"parameter_mappings": [],
"display": "table",
"entity_id": "ZRX529pNYbPiCLCi8HvZ6",
"collection_preview": true,
"last-edit-info": {
"id": 1,
"email": "[email protected]",
"first_name": "dbtmetabase",
"last_name": null,
"timestamp": "2024-10-11T23:46:29.299411Z"
},
"visualization_settings": {
"table.cell_column": "payment_id"
},
"collection": {
"metabase.models.collection.root/is-root?": true,
"authority_level": null,
"name": "Our analytics",
"is_personal": false,
"id": "root",
"can_write": true
},
"metabase_version": "v0.50.5 (48f6978)",
"parameters": [],
"created_at": "2024-10-11T23:46:29.272117Z",
"parameter_usage_count": 0,
"public_uuid": null
}
23 changes: 23 additions & 0 deletions tests/fixtures/api/collection/root/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,28 @@
},
"location": null,
"model": "dashboard"
},
{
"description": null,
"collection_position": null,
"can_write": true,
"database_id": null,
"collection_id": null,
"name": "Transactions",
"fully_parameterized": true,
"moderated_status": null,
"id": 33,
"display": "table",
"entity_id": "ZRX529pNYbPiCLCi8HvZ6",
"collection_preview": true,
"last-edit-info": {
"id": 1,
"last_name": null,
"first_name": "dbtmetabase",
"email": "[email protected]",
"timestamp": "2024-10-11T23:46:29.299411Z"
},
"location": null,
"model": "card"
}
]
Loading