[Feature] dbt show: add options to specify max_column_width and max_columns options
- Dominant language
- Rust
- Stars
- 13.8k
- Forks
- 2.6k
- Avg merge
- 21h 31m
- Merged PRs (30d)
- 56
Description
### Is this your first time submitting a feature request?
- [x] I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)
- [x] I have searched the existing issues, and I could not find an existing issue for this feature
- [x] I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion
### Describe the feature
[`agate.Table.print_table`](https://agate.readthedocs.io/en/latest/api/table.html#agate.Table.print_table) supports `max_columns` and `max_column_width` keyword arguments:
> * `max_columns` – The maximum number of columns to display before truncating the data. This defaults to `6` to prevent wrapping in most cases. Pass `None` to disable the limit.
> ...
> * `max_column_width` – Truncate all columns to at most this width. The remainder will be replaced with ellipsis. [default: `20`]
We currently [do not specify either of these](https://github.com/dbt-labsdbt/dbt-core/blob/8bbbe677447173b5c1d3295d3b39d5dfbe239473/core/dbt/task/show.py#L98):
```python
class ShowTask(CompileTask):
...
def task_end_messages(self, results) -> None:
...
for result in matched_results:
if self.args.output == "json":
...
else:
table.print_table(output=output, max_rows=None)
```
This has made table-styled output mostly useful for my purposes, as many table values exceed 20 characters, and many tables have more than 5 columns I'd like to look at.
Could we add command line options to tune these parameters?
I'm not sure what to call them - we already have `--printer-width` which seems like it should be related. Maybe `--output-max-table-columns` and `--output-max-table-column-width`? Though those seem like they'd be expected to affect JSON output (or non-`show` command output) too... 🤷
### Describe alternatives you've considered
#### 0. don't use `dbt show` for testing in local dev
This is what I'm most frequently doing now; use `dbt build` and then inspect the output directly in the database browser (Databricks UI for me).
#### 1. Local workaround
Apply the following diff in my virtual environment (wiped away when I re-`uv sync`):
```diff
diff --git a/core/dbt/task/show.py b/core/dbt/task/show.py
index 20b62013b..dc17e5bce 100644
--- a/core/dbt/task/show.py
+++ b/core/dbt/task/show.py
@@ -95,7 +95,7 @@ class ShowTask(CompileTask):
if self.args.output == "json":
table.to_json(path=output)
else:
- table.print_table(output=output, max_rows=None)
+ table.print_table(output=output, max_rows=None, max_columns=None, max_column_width=None)
node_name = result.node.name
```
This gets full values of all columns to print! I do pipe the resulting output to `less -S` (the `-S` flag means don't wrap lines) so that I can scroll through the output.
#### 2. dbt plugin?
On [`initialize`](https://github.com/vergenzt/dbt-core/blob/8bbbe677447173b5c1d3295d3b39d5dfbe239473/core/dbt/plugins/manager.py#L46-L51) it could monkey-patch `agate` to change the defaults for [`agate.Table.print_table`](https://agate.readthedocs.io/en/latest/api/table.html#agate.Table.print_table).
I don't love this though -- it's hacky and global.
### Who will this benefit?
Me. 😄 Doing local dev, so that I can simply use `dbt show` to view my results in tabular form without having to pass `--output=json | jq -c .show[] | in2csv -f ndjson | csvlook`. 🙃
### Are you interested in contributing this feature?
Sure! Just could use guidance on what y'all would want the CLI flags to be called.
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.