Skip to content
Prev Previous commit
Next Next commit
Update show.py
  • Loading branch information
aranke authored May 9, 2023
commit 685e06fd9ffbb8b9a93732f083bb84f4c6738be0
23 changes: 16 additions & 7 deletions core/dbt/task/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ def __init__(self, config, adapter, node, node_index, num_nodes):

def execute(self, compiled_node, manifest):
start_time = time.time()

# Allow passing in -1 (or any negative number) to get all rows
limit = None if self.config.args.limit < 0 else self.config.args.limit

if "sql_header" in compiled_node.unrendered_config:
compiled_node.compiled_code = (
compiled_node.unrendered_config["sql_header"] + compiled_node.compiled_code
)

adapter_response, execute_result = self.adapter.execute(
compiled_node.compiled_code, fetch=True
compiled_node.compiled_code, fetch=True, limit=limit
)
end_time = time.time()

Expand Down Expand Up @@ -66,23 +75,23 @@ def task_end_messages(self, results):
)

for result in matched_results:
# Allow passing in -1 (or any negative number) to get all rows
table = result.agate_table

if self.args.limit >= 0:
table = table.limit(self.args.limit)
result.agate_table = table

# Hack to get Agate table output as string
output = io.StringIO()
if self.args.output == "json":
table.to_json(path=output)
else:
table.print_table(output=output, max_rows=None)

node_name = result.node.name

if hasattr(result.node, "version") and result.node.version:
node_name += f".v{result.node.version}"

fire_event(
ShowNode(
node_name=result.node.name,
node_name=node_name,
preview=output.getvalue(),
is_inline=is_inline,
output_format=self.args.output,
Expand Down