-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New command: dbt show #7208
New command: dbt show #7208
Changes from 26 commits
e6dcca4
f0ad043
eab733f
d726061
bc09cd7
f28af9c
2bcb790
e0db983
45a7f1a
3133d22
09bec45
e845b37
ea6b2b0
f25b44b
2ff263d
b3cc37d
9a6baa9
3f36494
f885193
aac83b5
ac008e0
5c96420
ffc66bd
e20af84
0bec7c4
310ddf3
05fcd34
b576018
c5d4f11
b1f29c1
06fd124
4309fac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: 'New command: dbt show' | ||
time: 2023-03-24T12:36:21.173419-07:00 | ||
custom: | ||
Author: aranke | ||
Issue: 7207 7179 6359 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import json | ||
|
||
from dbt.ui import line_wrap_message, warning_tag, red, green, yellow | ||
from dbt.constants import MAXIMUM_SEED_SIZE_NAME, PIN_PACKAGE_URL | ||
from dbt.events.base_types import ( | ||
|
@@ -1605,14 +1607,6 @@ def message(self) -> str: | |
return f"Concurrency: {self.num_threads} threads (target='{self.target_name}')" | ||
|
||
|
||
class CompiledNode(InfoLevel): | ||
def code(self): | ||
return "Q028" | ||
|
||
def message(self) -> str: | ||
return f"Compiled node '{self.node_name}' is:\n{self.compiled}" | ||
|
||
|
||
class WritingInjectedSQLForNode(DebugLevel): | ||
def code(self): | ||
return "Q029" | ||
|
@@ -1719,6 +1713,42 @@ def message(self) -> str: | |
return f"Command `{self.command}` {status} at {self.completed_at} after {self.elapsed:0.2f} seconds" | ||
|
||
|
||
class ShowNode(InfoLevel): | ||
def code(self): | ||
return "Q041" | ||
|
||
def message(self) -> str: | ||
if self.output_format == "json": | ||
if self.is_inline: | ||
return json.dumps({"show": json.loads(self.preview)}, indent=2) | ||
else: | ||
return json.dumps( | ||
{"node": self.node_name, "show": json.loads(self.preview)}, indent=2 | ||
) | ||
else: | ||
if self.is_inline: | ||
return f"Previewing inline node:\n{self.preview}" | ||
else: | ||
return f"Previewing node '{self.node_name}':\n{self.preview}" | ||
|
||
|
||
class CompiledNode(InfoLevel): | ||
def code(self): | ||
return "Q042" | ||
|
||
def message(self) -> str: | ||
if self.output_format == "json": | ||
if self.is_inline: | ||
return json.dumps({"compiled": self.compiled}, indent=2) | ||
else: | ||
return json.dumps({"node": self.node_name, "compiled": self.compiled}, indent=2) | ||
Comment on lines
+1740
to
+1744
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Not blocking] It makes sense to me that we'd want to support similar arguments for both
I don't have a very strong feeling about what to show here. The most important use case for JSON-formatted output is programmatic consumers of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! |
||
else: | ||
if self.is_inline: | ||
return f"Compiled inline node is:\n{self.compiled}" | ||
else: | ||
return f"Compiled node '{self.node_name}' is:\n{self.compiled}" | ||
|
||
|
||
# ======================================================= | ||
# W - Node testing | ||
# ======================================================= | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
from dbt.contracts.graph.manifest import WritableManifest | ||
from dbt.contracts.results import RunStatus, RunResult | ||
from dbt.events.functions import fire_event | ||
from dbt.events.types import CompileComplete, CompiledNode | ||
from dbt.events.types import CompiledNode | ||
from dbt.exceptions import DbtInternalError, DbtRuntimeError | ||
from dbt.graph import ResourceTypeSelector | ||
from dbt.node_types import NodeType | ||
|
@@ -61,23 +61,27 @@ def get_runner_type(self, _): | |
return CompileRunner | ||
|
||
def task_end_messages(self, results): | ||
if getattr(self.args, "inline", None): | ||
result = results[0] | ||
fire_event( | ||
CompiledNode(node_name=result.node.name, compiled=result.node.compiled_code) | ||
) | ||
is_inline = bool(getattr(self.args, "inline", None)) | ||
|
||
if self.selection_arg: | ||
if is_inline: | ||
matched_results = [result for result in results if result.node.name == "inline_query"] | ||
elif self.selection_arg: | ||
matched_results = [ | ||
result for result in results if result.node.name == self.selection_arg[0] | ||
result for result in results if result.node.name in self.selection_arg | ||
] | ||
if len(matched_results) == 1: | ||
result = matched_results[0] | ||
fire_event( | ||
CompiledNode(node_name=result.node.name, compiled=result.node.compiled_code) | ||
) | ||
# No selector passed, compiling all nodes | ||
else: | ||
matched_results = [] | ||
|
||
fire_event(CompileComplete()) | ||
for result in matched_results: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jtcohen6 did we agree on firing one event for each selected node is a good idea? what if we accidentally selected 1000 node? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ChenyuLInx The node name explicitly needs to be in the selector, so this situation is pretty unlikely. e.g., selector There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I had my druthers, I'd prefer we do this in a way that kept more of this logic within dbt's selection syntax, e.g. "we only want to support the As it is, we're going to apply the selection syntax, and then filter it down to only preview the nodes whose names explicitly appear in the
In terms of the "happy path" for the
If we can do that, then this is fine by me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this comment addressed? @aranke There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ChenyuLInx Yes, done now. |
||
fire_event( | ||
CompiledNode( | ||
node_name=result.node.name, | ||
compiled=result.node.compiled_code, | ||
is_inline=is_inline, | ||
output_format=self.args.output, | ||
) | ||
) | ||
|
||
def _get_deferred_manifest(self) -> Optional[WritableManifest]: | ||
if not self.args.defer: | ||
|
@@ -119,3 +123,13 @@ def _runtime_initialize(self): | |
process_node(self.config, self.manifest, sql_node) | ||
|
||
super()._runtime_initialize() | ||
|
||
def _handle_result(self, result): | ||
super()._handle_result(result) | ||
|
||
if ( | ||
result.node.is_ephemeral_model | ||
and type(self) is CompileTask | ||
and (self.args.select or getattr(self.args, "inline", None)) | ||
): | ||
self.node_results.append(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we recreating as a new event type (with a new code)? The additional fields aren't a breaking change, right?
I think this will need to be updated to account for the changes we made last week to our event/proto system (#7190)I was mistaken about what had changed in that PRThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're not, I just ran out of space in the numbering and wanted to move them to the right spot before shipping.