Skip to content

Commit c2e2dc3

Browse files
committed
Report 0 rows correctly
1 parent 2648a47 commit c2e2dc3

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

sqlmesh/core/console.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4189,15 +4189,15 @@ def _create_evaluation_model_annotation(
41894189
if execution_stats:
41904190
rows_processed = execution_stats.total_rows_processed
41914191
execution_stats_str += (
4192-
f"{_abbreviate_integer_count(rows_processed)} row{'s' if rows_processed > 1 else ''}"
4193-
if rows_processed
4192+
f"{_abbreviate_integer_count(rows_processed)} row{'s' if rows_processed != 1 else ''}"
4193+
if rows_processed is not None and rows_processed >= 0
41944194
else ""
41954195
)
41964196

41974197
bytes_processed = execution_stats.total_bytes_processed
41984198
execution_stats_str += (
41994199
f"{', ' if execution_stats_str else ''}{_format_bytes(bytes_processed)}"
4200-
if bytes_processed
4200+
if bytes_processed is not None and bytes_processed >= 0
42014201
else ""
42024202
)
42034203
execution_stats_str = f" ({execution_stats_str})" if execution_stats_str else ""
@@ -4306,7 +4306,7 @@ def _calculate_annotation_str_len(
43064306
# Convert number of bytes to a human-readable string
43074307
# https://github.com/dbt-labs/dbt-adapters/blob/34fd178539dcb6f82e18e738adc03de7784c032f/dbt-bigquery/src/dbt/adapters/bigquery/connections.py#L165
43084308
def _format_bytes(num_bytes: t.Optional[int]) -> str:
4309-
if num_bytes and num_bytes >= 0:
4309+
if num_bytes is not None and num_bytes >= 0:
43104310
if num_bytes < 1024:
43114311
return f"{num_bytes} bytes"
43124312

@@ -4324,7 +4324,7 @@ def _format_bytes(num_bytes: t.Optional[int]) -> str:
43244324
# Abbreviate integer count. Example: 1,000,000,000 -> 1b
43254325
# https://github.com/dbt-labs/dbt-adapters/blob/34fd178539dcb6f82e18e738adc03de7784c032f/dbt-bigquery/src/dbt/adapters/bigquery/connections.py#L178
43264326
def _abbreviate_integer_count(count: t.Optional[int]) -> str:
4327-
if count and count >= 0:
4327+
if count is not None and count >= 0:
43284328
if count < 1000:
43294329
return str(count)
43304330

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
from sqlglot.optimizer.qualify_columns import quote_identifiers
@@ -2468,6 +2469,24 @@ def capture_execution_stats(
24682469
assert actual_execution_stats["incremental_model"].total_bytes_processed
24692470
assert actual_execution_stats["full_model"].total_bytes_processed
24702471

2472+
# run that loads 0 rows in incremental model
2473+
with patch.object(
2474+
context.console, "update_snapshot_evaluation_progress", capture_execution_stats
2475+
):
2476+
with time_machine.travel(date.today() + timedelta(days=1)):
2477+
context.run()
2478+
2479+
if ctx.engine_adapter.SUPPORTS_QUERY_EXECUTION_TRACKING:
2480+
assert actual_execution_stats["incremental_model"].total_rows_processed == 0
2481+
# snowflake doesn't track rows for CTAS
2482+
assert actual_execution_stats["full_model"].total_rows_processed == (
2483+
None if ctx.mark.startswith("snowflake") else 3
2484+
)
2485+
2486+
if ctx.mark.startswith("bigquery"):
2487+
assert actual_execution_stats["incremental_model"].total_bytes_processed
2488+
assert actual_execution_stats["full_model"].total_bytes_processed
2489+
24712490
# make and validate unmodified dev environment
24722491
no_change_plan: Plan = context.plan_builder(
24732492
environment="test_dev",

0 commit comments

Comments
 (0)