Skip to content

Commit d11fcdd

Browse files
authored
Fix: ensure partial works when a query is used to produce data (#4583)
1 parent 405e218 commit d11fcdd

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

sqlmesh/core/test/definition.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,10 @@ def _create_df(
559559
) -> pd.DataFrame:
560560
query = values.get("query")
561561
if query:
562-
return self._execute(self._add_missing_columns(query, columns))
562+
if not partial:
563+
query = self._add_missing_columns(query, columns)
564+
565+
return self._execute(query)
563566

564567
rows = values["rows"]
565568
if columns:

tests/core/test_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,33 @@ def test_generate_input_data_using_sql(mocker: MockerFixture, tmp_path: Path) ->
14741474
).run()
14751475
)
14761476

1477+
_check_successful_or_raise(
1478+
_create_test(
1479+
body=load_yaml(
1480+
"""
1481+
test_example_full_model_partial:
1482+
model: sqlmesh_example.full_model
1483+
inputs:
1484+
sqlmesh_example.incremental_model:
1485+
rows:
1486+
- id: 1
1487+
item_id: 1
1488+
- id: 2
1489+
item_id: 1
1490+
- id: 3
1491+
item_id: 2
1492+
outputs:
1493+
query:
1494+
partial: true
1495+
query: "SELECT 2 AS num_orders UNION ALL SELECT 1 AS num_orders"
1496+
"""
1497+
),
1498+
test_name="test_example_full_model_partial",
1499+
model=context.get_model("sqlmesh_example.full_model"),
1500+
context=context,
1501+
).run()
1502+
)
1503+
14771504
mocker.patch("sqlmesh.core.test.definition.random_id", return_value="jzngz56a")
14781505
test = _create_test(
14791506
body=load_yaml(

0 commit comments

Comments
 (0)