|
9 | 9 | import textwrap |
10 | 10 | from itertools import zip_longest |
11 | 11 | from pathlib import Path |
12 | | -from humanize import naturalsize, metric |
13 | 12 | from hyperscript import h |
14 | 13 | from rich.console import Console as RichConsole |
15 | 14 | from rich.live import Live |
@@ -4031,7 +4030,9 @@ def show_table_diff_summary(self, table_diff: TableDiff) -> None: |
4031 | 4030 | self._write(f"Join On: {keys}") |
4032 | 4031 |
|
4033 | 4032 |
|
4034 | | -_CONSOLE: Console = NoopConsole() |
| 4033 | +# TODO: remove this |
| 4034 | +# _CONSOLE: Console = NoopConsole() |
| 4035 | +_CONSOLE: Console = TerminalConsole() |
4035 | 4036 |
|
4036 | 4037 |
|
4037 | 4038 | def set_console(console: Console) -> None: |
@@ -4188,15 +4189,15 @@ def _create_evaluation_model_annotation( |
4188 | 4189 | if execution_stats: |
4189 | 4190 | rows_processed = execution_stats.total_rows_processed |
4190 | 4191 | 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 |
4193 | 4194 | else "" |
4194 | 4195 | ) |
4195 | 4196 |
|
4196 | 4197 | bytes_processed = execution_stats.total_bytes_processed |
4197 | 4198 | 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 |
4200 | 4201 | else "" |
4201 | 4202 | ) |
4202 | 4203 | execution_stats_str = f" ({execution_stats_str})" if execution_stats_str else "" |
@@ -4300,3 +4301,39 @@ def _calculate_annotation_str_len( |
4300 | 4301 | + execution_stats_len, |
4301 | 4302 | ) |
4302 | 4303 | 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 "" |
0 commit comments