Skip to content

Commit 89f91b2

Browse files
committed
Report 0 rows correctly
1 parent 09b2970 commit 89f91b2

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

sqlmesh/core/console.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4163,15 +4163,15 @@ def _create_evaluation_model_annotation(
41634163
if execution_stats:
41644164
rows_processed = execution_stats.total_rows_processed
41654165
execution_stats_str += (
4166-
f"{_abbreviate_integer_count(rows_processed)} row{'s' if rows_processed > 1 else ''}"
4167-
if rows_processed
4166+
f"{_abbreviate_integer_count(rows_processed)} row{'s' if rows_processed != 1 else ''}"
4167+
if rows_processed is not None and rows_processed >= 0
41684168
else ""
41694169
)
41704170

41714171
bytes_processed = execution_stats.total_bytes_processed
41724172
execution_stats_str += (
41734173
f"{', ' if execution_stats_str else ''}{_format_bytes(bytes_processed)}"
4174-
if bytes_processed
4174+
if bytes_processed is not None and bytes_processed >= 0
41754175
else ""
41764176
)
41774177
execution_stats_str = f" ({execution_stats_str})" if execution_stats_str else ""
@@ -4280,7 +4280,7 @@ def _calculate_annotation_str_len(
42804280
# Convert number of bytes to a human-readable string
42814281
# https://github.com/dbt-labs/dbt-adapters/blob/34fd178539dcb6f82e18e738adc03de7784c032f/dbt-bigquery/src/dbt/adapters/bigquery/connections.py#L165
42824282
def _format_bytes(num_bytes: t.Optional[int]) -> str:
4283-
if num_bytes and num_bytes >= 0:
4283+
if num_bytes is not None and num_bytes >= 0:
42844284
if num_bytes < 1024:
42854285
return f"{num_bytes} bytes"
42864286

@@ -4298,7 +4298,7 @@ def _format_bytes(num_bytes: t.Optional[int]) -> str:
42984298
# Abbreviate integer count. Example: 1,000,000,000 -> 1b
42994299
# https://github.com/dbt-labs/dbt-adapters/blob/34fd178539dcb6f82e18e738adc03de7784c032f/dbt-bigquery/src/dbt/adapters/bigquery/connections.py#L178
43004300
def _abbreviate_integer_count(count: t.Optional[int]) -> str:
4301-
if count and count >= 0:
4301+
if count is not None and count >= 0:
43024302
if count < 1000:
43034303
return str(count)
43044304

tests/core/engine_adapter/integration/test_integration.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
import sys
88
import typing as t
99
import shutil
10-
from datetime import datetime, timedelta
10+
from datetime import date, datetime, timedelta
1111
from unittest.mock import patch
1212
import numpy as np # noqa: TID253
1313
import pandas as pd # noqa: TID253
1414
import pytest
1515
import pytz
16+
import time_machine
1617
from sqlglot import exp, parse_one
1718
from sqlglot.optimizer.normalize_identifiers import normalize_identifiers
1819

@@ -2424,6 +2425,24 @@ def capture_execution_stats(
24242425
assert actual_execution_stats["incremental_model"].total_bytes_processed
24252426
assert actual_execution_stats["full_model"].total_bytes_processed
24262427

2428+
# run that loads 0 rows in incremental model
2429+
with patch.object(
2430+
context.console, "update_snapshot_evaluation_progress", capture_execution_stats
2431+
):
2432+
with time_machine.travel(date.today() + timedelta(days=1)):
2433+
context.run()
2434+
2435+
if ctx.engine_adapter.SUPPORTS_QUERY_EXECUTION_TRACKING:
2436+
assert actual_execution_stats["incremental_model"].total_rows_processed == 0
2437+
# snowflake doesn't track rows for CTAS
2438+
assert actual_execution_stats["full_model"].total_rows_processed == (
2439+
None if ctx.mark.startswith("snowflake") else 3
2440+
)
2441+
2442+
if ctx.mark.startswith("bigquery"):
2443+
assert actual_execution_stats["incremental_model"].total_bytes_processed
2444+
assert actual_execution_stats["full_model"].total_bytes_processed
2445+
24272446
# make and validate unmodified dev environment
24282447
no_change_plan: Plan = context.plan_builder(
24292448
environment="test_dev",

0 commit comments

Comments
 (0)