Skip to content

Commit db350b9

Browse files
committed
Remove humanize functions
1 parent c7622f2 commit db350b9

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

sqlmesh/core/console.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import textwrap
1010
from itertools import zip_longest
1111
from pathlib import Path
12-
from humanize import naturalsize, metric
1312
from hyperscript import h
1413
from rich.console import Console as RichConsole
1514
from rich.live import Live
@@ -4031,7 +4030,9 @@ def show_table_diff_summary(self, table_diff: TableDiff) -> None:
40314030
self._write(f"Join On: {keys}")
40324031

40334032

4034-
_CONSOLE: Console = NoopConsole()
4033+
# TODO: remove this
4034+
# _CONSOLE: Console = NoopConsole()
4035+
_CONSOLE: Console = TerminalConsole()
40354036

40364037

40374038
def set_console(console: Console) -> None:
@@ -4188,15 +4189,15 @@ def _create_evaluation_model_annotation(
41884189
if execution_stats:
41894190
rows_processed = execution_stats.total_rows_processed
41904191
execution_stats_str += (
4191-
f"{metric(rows_processed)} row{'s' if rows_processed != 1 else ''}"
4192-
if rows_processed is not None and rows_processed >= 0
4192+
f"{_abbreviate_integer_count(rows_processed)} row{'s' if rows_processed > 1 else ''}"
4193+
if rows_processed
41934194
else ""
41944195
)
41954196

41964197
bytes_processed = execution_stats.total_bytes_processed
41974198
execution_stats_str += (
4198-
f"{', ' if execution_stats_str else ''}{naturalsize(bytes_processed, binary=True)}"
4199-
if bytes_processed is not None and bytes_processed >= 0
4199+
f"{', ' if execution_stats_str else ''}{_format_bytes(bytes_processed)}"
4200+
if bytes_processed
42004201
else ""
42014202
)
42024203
execution_stats_str = f" ({execution_stats_str})" if execution_stats_str else ""
@@ -4300,3 +4301,39 @@ def _calculate_annotation_str_len(
43004301
+ execution_stats_len,
43014302
)
43024303
return annotation_str_len
4304+
4305+
4306+
# Convert number of bytes to a human-readable string
4307+
# https://github.com/dbt-labs/dbt-adapters/blob/34fd178539dcb6f82e18e738adc03de7784c032f/dbt-bigquery/src/dbt/adapters/bigquery/connections.py#L165
4308+
def _format_bytes(num_bytes: t.Optional[int]) -> str:
4309+
if num_bytes and num_bytes >= 0:
4310+
if num_bytes < 1024:
4311+
return f"{num_bytes} bytes"
4312+
4313+
num_bytes_float = float(num_bytes) / 1024.0
4314+
for unit in ["KiB", "MiB", "GiB", "TiB", "PiB"]:
4315+
if num_bytes_float < 1024.0:
4316+
return f"{num_bytes_float:3.1f} {unit}"
4317+
num_bytes_float /= 1024.0
4318+
4319+
num_bytes_float *= 1024.0 # undo last division in loop
4320+
return f"{num_bytes_float:3.1f} {unit}"
4321+
return ""
4322+
4323+
4324+
# Abbreviate integer count. Example: 1,000,000,000 -> 1b
4325+
# https://github.com/dbt-labs/dbt-adapters/blob/34fd178539dcb6f82e18e738adc03de7784c032f/dbt-bigquery/src/dbt/adapters/bigquery/connections.py#L178
4326+
def _abbreviate_integer_count(count: t.Optional[int]) -> str:
4327+
if count and count >= 0:
4328+
if count < 1000:
4329+
return str(count)
4330+
4331+
count_float = float(count) / 1000.0
4332+
for unit in ["k", "m", "b", "t"]:
4333+
if count_float < 1000.0:
4334+
return f"{count_float:3.1f}{unit}".strip()
4335+
count_float /= 1000.0
4336+
4337+
count_float *= 1000.0 # undo last division in loop
4338+
return f"{count_float:3.1f}{unit}".strip()
4339+
return ""

sqlmesh/core/engine_adapter/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2458,7 +2458,9 @@ def _execute(self, sql: str, track_rows_processed: bool = False, **kwargs: t.Any
24582458
and track_rows_processed
24592459
and QueryExecutionTracker.is_tracking()
24602460
):
2461-
if (rowcount := getattr(self.cursor, "rowcount", None)) and rowcount is not None:
2461+
if (
2462+
rowcount := getattr(self.cursor, "rowcount", None)
2463+
) is not None and rowcount is not None:
24622464
try:
24632465
self._record_execution_stats(sql, int(rowcount))
24642466
except (TypeError, ValueError):

0 commit comments

Comments
 (0)