Skip to content

Commit 780ebae

Browse files
authored
chore: add blueprint model to sushi (#4537)
1 parent 53b06e4 commit 780ebae

7 files changed

Lines changed: 67 additions & 18 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MODEL (
2+
name @name,
3+
kind FULL,
4+
description "Count of customers by status, done with a fancy unnecessary blueprint",
5+
grain status,
6+
blueprints (
7+
(
8+
name := sushi.count_customers_active,
9+
blueprint_status := 'active',
10+
),
11+
(
12+
name := sushi.count_customers_inactive,
13+
blueprint_status := 'inactive',
14+
)
15+
)
16+
);
17+
18+
SELECT
19+
COUNT(customer_id) AS count_customers
20+
FROM sushi.customers
21+
WHERE status = @blueprint_status;

tests/core/analytics/test_collector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def test_on_plan_apply(
183183
{
184184
"seq_num": 0,
185185
"event_type": "PLAN_APPLY_START",
186-
"event": f'{{"plan_id": "{plan_id}", "engine_type": "bigquery", "state_sync_type": "mysql", "scheduler_type": "builtin", "is_dev": false, "skip_backfill": false, "no_gaps": false, "forward_only": false, "ensure_finalized_snapshots": false, "has_restatements": false, "directly_modified_count": 19, "indirectly_modified_count": 0, "environment_name_hash": "d6e4a9b6646c62fc48baa6dd6150d1f7"}}',
186+
"event": f'{{"plan_id": "{plan_id}", "engine_type": "bigquery", "state_sync_type": "mysql", "scheduler_type": "builtin", "is_dev": false, "skip_backfill": false, "no_gaps": false, "forward_only": false, "ensure_finalized_snapshots": false, "has_restatements": false, "directly_modified_count": 21, "indirectly_modified_count": 0, "environment_name_hash": "d6e4a9b6646c62fc48baa6dd6150d1f7"}}',
187187
**common_fields,
188188
}
189189
),

tests/core/test_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ def test_janitor(sushi_context, mocker: MockerFixture) -> None:
818818
)
819819
# Assert that the views are dropped for each snapshot just once and make sure that the name used is the
820820
# view name with the environment as a suffix
821-
assert adapter_mock.drop_view.call_count == 14
821+
assert adapter_mock.drop_view.call_count == 16
822822
adapter_mock.drop_view.assert_has_calls(
823823
[
824824
call(

tests/core/test_integration.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,16 @@ def test_full_history_restatement_model_regular_plan_preview_enabled(
476476
waiter_as_customer_snapshot = context.get_snapshot(
477477
"sushi.waiter_as_customer_by_day", raise_if_missing=True
478478
)
479+
count_customers_active_snapshot = context.get_snapshot(
480+
"sushi.count_customers_active", raise_if_missing=True
481+
)
482+
count_customers_inactive_snapshot = context.get_snapshot(
483+
"sushi.count_customers_inactive", raise_if_missing=True
484+
)
479485

480486
plan = context.plan_builder("dev", skip_tests=True, enable_preview=True).build()
481487

482-
assert len(plan.new_snapshots) == 4
488+
assert len(plan.new_snapshots) == 6
483489
assert (
484490
plan.context_diff.snapshots[snapshot.snapshot_id].change_category
485491
== SnapshotChangeCategory.FORWARD_ONLY
@@ -505,6 +511,18 @@ def test_full_history_restatement_model_regular_plan_preview_enabled(
505511
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
506512
],
507513
),
514+
SnapshotIntervals(
515+
snapshot_id=count_customers_active_snapshot.snapshot_id,
516+
intervals=[
517+
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
518+
],
519+
),
520+
SnapshotIntervals(
521+
snapshot_id=count_customers_inactive_snapshot.snapshot_id,
522+
intervals=[
523+
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
524+
],
525+
),
508526
SnapshotIntervals(
509527
snapshot_id=customers_snapshot.snapshot_id,
510528
intervals=[
@@ -1517,6 +1535,8 @@ def test_run_with_select_models(
15171535
"assert_item_price_above_zero": to_timestamp("2023-01-08"),
15181536
'"memory"."sushi"."active_customers"': to_timestamp("2023-01-08"),
15191537
'"memory"."sushi"."customers"': to_timestamp("2023-01-08"),
1538+
'"memory"."sushi"."count_customers_active"': to_timestamp("2023-01-08"),
1539+
'"memory"."sushi"."count_customers_inactive"': to_timestamp("2023-01-08"),
15201540
}
15211541

15221542

@@ -1555,6 +1575,8 @@ def test_plan_with_run(
15551575
"assert_item_price_above_zero": to_timestamp("2023-01-09"),
15561576
'"memory"."sushi"."active_customers"': to_timestamp("2023-01-09"),
15571577
'"memory"."sushi"."customers"': to_timestamp("2023-01-09"),
1578+
'"memory"."sushi"."count_customers_active"': to_timestamp("2023-01-09"),
1579+
'"memory"."sushi"."count_customers_inactive"': to_timestamp("2023-01-09"),
15581580
}
15591581

15601582

@@ -1592,6 +1614,8 @@ def test_run_with_select_models_no_auto_upstream(
15921614
"assert_item_price_above_zero": to_timestamp("2023-01-08"),
15931615
'"memory"."sushi"."active_customers"': to_timestamp("2023-01-08"),
15941616
'"memory"."sushi"."customers"': to_timestamp("2023-01-08"),
1617+
'"memory"."sushi"."count_customers_active"': to_timestamp("2023-01-08"),
1618+
'"memory"."sushi"."count_customers_inactive"': to_timestamp("2023-01-08"),
15951619
}
15961620

15971621

@@ -5185,7 +5209,7 @@ def test_environment_suffix_target_table(init_and_plan_context: t.Callable):
51855209
assert set(metadata.schemas) - starting_schemas == {"raw"}
51865210
prod_views = {x for x in metadata.qualified_views if x.db in environments_schemas}
51875211
# Make sure that all models are present
5188-
assert len(prod_views) == 14
5212+
assert len(prod_views) == 16
51895213
apply_to_environment(context, "dev")
51905214
# Make sure no new schemas are created
51915215
assert set(metadata.schemas) - starting_schemas == {"raw"}
@@ -5243,9 +5267,9 @@ def get_default_catalog_and_non_tables(
52435267
user_default_tables,
52445268
non_default_tables,
52455269
) = get_default_catalog_and_non_tables(metadata, context.default_catalog)
5246-
assert len(prod_views) == 14
5270+
assert len(prod_views) == 16
52475271
assert len(dev_views) == 0
5248-
assert len(user_default_tables) == 17
5272+
assert len(user_default_tables) == 21
52495273
assert state_metadata.schemas == ["sqlmesh"]
52505274
assert {x.sql() for x in state_metadata.qualified_tables}.issuperset(
52515275
{
@@ -5262,9 +5286,9 @@ def get_default_catalog_and_non_tables(
52625286
user_default_tables,
52635287
non_default_tables,
52645288
) = get_default_catalog_and_non_tables(metadata, context.default_catalog)
5265-
assert len(prod_views) == 14
5266-
assert len(dev_views) == 14
5267-
assert len(user_default_tables) == 17
5289+
assert len(prod_views) == 16
5290+
assert len(dev_views) == 16
5291+
assert len(user_default_tables) == 21
52685292
assert len(non_default_tables) == 0
52695293
assert state_metadata.schemas == ["sqlmesh"]
52705294
assert {x.sql() for x in state_metadata.qualified_tables}.issuperset(
@@ -5282,9 +5306,9 @@ def get_default_catalog_and_non_tables(
52825306
user_default_tables,
52835307
non_default_tables,
52845308
) = get_default_catalog_and_non_tables(metadata, context.default_catalog)
5285-
assert len(prod_views) == 14
5286-
assert len(dev_views) == 28
5287-
assert len(user_default_tables) == 17
5309+
assert len(prod_views) == 16
5310+
assert len(dev_views) == 32
5311+
assert len(user_default_tables) == 21
52885312
assert len(non_default_tables) == 0
52895313
assert state_metadata.schemas == ["sqlmesh"]
52905314
assert {x.sql() for x in state_metadata.qualified_tables}.issuperset(
@@ -5303,9 +5327,9 @@ def get_default_catalog_and_non_tables(
53035327
user_default_tables,
53045328
non_default_tables,
53055329
) = get_default_catalog_and_non_tables(metadata, context.default_catalog)
5306-
assert len(prod_views) == 14
5307-
assert len(dev_views) == 14
5308-
assert len(user_default_tables) == 17
5330+
assert len(prod_views) == 16
5331+
assert len(dev_views) == 16
5332+
assert len(user_default_tables) == 21
53095333
assert len(non_default_tables) == 0
53105334
assert state_metadata.schemas == ["sqlmesh"]
53115335
assert {x.sql() for x in state_metadata.qualified_tables}.issuperset(

tests/core/test_plan.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,8 @@ def test_restate_models(sushi_context_pre_scheduling: Context):
832832
'"memory"."sushi"."waiter_as_customer_by_day"',
833833
'"memory"."sushi"."waiter_names"',
834834
'"memory"."sushi"."waiters"',
835+
'"memory"."sushi"."count_customers_active"',
836+
'"memory"."sushi"."count_customers_inactive"',
835837
}
836838

837839

tests/integrations/github/cicd/test_integration.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,8 @@ def test_overlapping_changes_models(
17051705
17061706
**Indirectly Modified:**
17071707
- `sushi.active_customers`
1708+
- `sushi.count_customers_active`
1709+
- `sushi.count_customers_inactive`
17081710
- `sushi.waiter_as_customer_by_day`
17091711
17101712
"""
@@ -1744,7 +1746,7 @@ def test_overlapping_changes_models(
17441746
"""
17451747
)
17461748

1747-
assert len(get_environment_objects(controller, "hello_world_2")) == 4
1749+
assert len(get_environment_objects(controller, "hello_world_2")) == 6
17481750
assert "new_col" in get_columns(controller, "hello_world_2", "customers")
17491751

17501752
assert mock_pull_request.merge.called

tests/integrations/jupyter/test_magics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,15 +756,15 @@ def test_info(notebook, sushi_context, convert_all_html_output_to_text, get_all_
756756
assert not output.stderr
757757
assert len(output.outputs) == 6
758758
assert convert_all_html_output_to_text(output) == [
759-
"Models: 18",
759+
"Models: 20",
760760
"Macros: 8",
761761
"",
762762
"Connection:\n type: duckdb\n concurrent_tasks: 1\n register_comments: true\n pre_ping: false\n pretty_sql: false\n extensions: []\n connector_config: {}\n secrets: None",
763763
"Test Connection:\n type: duckdb\n concurrent_tasks: 1\n register_comments: true\n pre_ping: false\n pretty_sql: false\n extensions: []\n connector_config: {}\n secrets: None",
764764
"Data warehouse connection succeeded",
765765
]
766766
assert get_all_html_output(output) == [
767-
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Models: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">18</span></pre>",
767+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Models: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">20</span></pre>",
768768
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Macros: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">8</span></pre>",
769769
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>",
770770
'<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace">Connection: type: duckdb concurrent_tasks: <span style="color: #008080; text-decoration-color: #008080; font-weight: bold">1</span> register_comments: true pre_ping: false pretty_sql: false extensions: <span style="font-weight: bold">[]</span> connector_config: <span style="font-weight: bold">{}</span> secrets: <span style="color: #800080; text-decoration-color: #800080; font-style: italic">None</span></pre>',

0 commit comments

Comments
 (0)