-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Operation result #774
Operation result #774
Changes from 40 commits
e09f8bf
89ad5d6
2ae45ab
8cb3091
da107f3
b29fe7f
1e95657
612d88b
223a764
b232d7f
4f6cd0a
0c5e214
7abb9d9
0c62326
512493f
9c74375
2db41c5
7d27c1b
2c47a31
ef22e70
4f39ef6
8ca876a
e2c1cde
6f78e63
fcbc9d7
b26ac2c
2622194
1b03e36
9ec5d70
f1a6461
d0a7ee0
3d7ed8e
55d98f7
9324a2c
5216b51
726aaad
fda7013
15fe9a3
f6fb149
70da428
0dd2375
9b432b8
04ffaba
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 |
---|---|---|
|
@@ -471,7 +471,7 @@ def acquire_connection(cls, profile, name): | |
lock.release() | ||
|
||
@classmethod | ||
def release_connection(cls, profile, name): | ||
def release_connection(cls, profile, name='master'): | ||
global connections_in_use, connections_available, lock | ||
|
||
if connections_in_use.get(name) is None: | ||
|
@@ -773,3 +773,45 @@ def convert_agate_type(cls, agate_table, col_idx): | |
for agate_cls, func in conversions: | ||
if isinstance(agate_type, agate_cls): | ||
return func(agate_table, col_idx) | ||
|
||
### | ||
# Operations involving the manifest | ||
### | ||
@classmethod | ||
def run_operation(cls, profile, project_cfg, manifest, operation_name, | ||
result_key): | ||
"""Look the operation identified by operation_name up in the manifest | ||
and run it. | ||
|
||
Return an an AttrDict with three attributes: 'table', 'data', and | ||
'status'. 'table' is an agate.Table. | ||
""" | ||
operation = manifest.find_operation_by_name(operation_name, None) | ||
|
||
# This causes a reference cycle, as dbt.context.runtime.generate() | ||
# ends up calling get_adapter, so the import has to be here. | ||
import dbt.context.runtime | ||
context = dbt.context.runtime.generate( | ||
operation, | ||
project_cfg, | ||
manifest.to_flat_graph(), | ||
) | ||
|
||
# TODO: should I get the return value here in case future operations | ||
# want to return some string? Jinja (I think) stringifies the results | ||
# so it's not super useful. Status, I guess? | ||
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. no, i think this is fine as is. can you remove this comment? |
||
operation.generator(context)() | ||
|
||
# This is a lot of magic, have to know the magic name is 'catalog'. | ||
# TODO: How can we make this part of the data set? Could we make it | ||
# the operation's name/unique ID somehow instead? | ||
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. this comment is out of date |
||
result = context['load_result'](result_key) | ||
return result | ||
|
||
### | ||
# Abstract methods involving the flat graph | ||
### | ||
@classmethod | ||
def get_catalog(cls, profile, project_cfg, run_operation): | ||
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. there's some naming inconsistency here. the comment should read |
||
raise dbt.exceptions.NotImplementedException( | ||
'`get_catalog` is not implemented for this adapter!') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,7 +182,10 @@ | |
'maxLength': 127, | ||
}, | ||
'resource_type': { | ||
'enum': [NodeType.Macro], | ||
'enum': [ | ||
NodeType.Macro, | ||
NodeType.Operation, | ||
], | ||
}, | ||
'unique_id': { | ||
'type': 'string', | ||
|
@@ -344,6 +347,29 @@ def serialize(self): | |
'child_map': forward_edges, | ||
} | ||
|
||
def _find_by_name(self, name, package, subgraph, nodetype): | ||
""" | ||
|
||
Find a node by its given name in the appropraite sugraph. | ||
""" | ||
if subgraph == 'nodes': | ||
search = self.nodes | ||
elif subgraph == 'macros': | ||
search = self.macros | ||
else: | ||
raise NotImplementedError( | ||
'subgraph search for {} not implemented'.format(subgraph) | ||
) | ||
return dbt.utils.find_in_subgraph_by_name( | ||
search, | ||
name, | ||
package, | ||
nodetype) | ||
|
||
def find_operation_by_name(self, name, package): | ||
return self._find_by_name(name, package, 'macros', | ||
[NodeType.Operation]) | ||
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. love this |
||
|
||
def to_flat_graph(self): | ||
"""Convert the parsed manifest to the 'flat graph' that the compiler | ||
expects. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{% operation get_catalog_data %} | ||
{% set catalog = dbt.get_catalog() %} | ||
{{ return(catalog) }} | ||
{% endoperation %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
import dbt.task.seed as seed_task | ||
import dbt.task.test as test_task | ||
import dbt.task.archive as archive_task | ||
import dbt.task.generate as generate_task | ||
|
||
import dbt.tracking | ||
import dbt.config as config | ||
|
@@ -414,6 +415,15 @@ def parse_args(args): | |
) | ||
seed_sub.set_defaults(cls=seed_task.SeedTask, which='seed') | ||
|
||
catalog_sub = subs.add_parser('catalog', parents=[base_subparser]) | ||
catalog_subs = catalog_sub.add_subparsers() | ||
# it might look like catalog_sub is the correct parents entry, but that | ||
# will cause weird errors about 'conflicting option strings'. | ||
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. @drewbanin should this be 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. Yeah, I was thinking 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. Yup, I'll fix the catalog -> docs. Is this actually a "docs task"? I assume the point of having |
||
generate_sub = catalog_subs.add_parser('generate', | ||
parents=[base_subparser]) | ||
generate_sub.set_defaults(cls=generate_task.GenerateTask, | ||
which='generate') | ||
|
||
sub = subs.add_parser('test', parents=[base_subparser]) | ||
sub.add_argument( | ||
'--data', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
from dbt.exceptions import NotImplementedException | ||
from dbt.utils import get_nodes_by_tags | ||
from dbt.node_types import NodeType, RunHookType | ||
from dbt.adapters.factory import get_adapter | ||
|
||
import dbt.clients.jinja | ||
import dbt.context.runtime | ||
|
@@ -61,6 +62,26 @@ def skipped(self): | |
return self.skip | ||
|
||
|
||
class RunOperationResult(RunModelResult): | ||
def __init__(self, node, error=None, skip=False, status=None, | ||
failed=None, execution_time=0, returned=None): | ||
super(RunOperationResult, self).__init__(node, error, skip, status, | ||
failed, execution_time) | ||
self.returned = returned | ||
|
||
@property | ||
def errored(self): | ||
return self.error is not None | ||
|
||
@property | ||
def failed(self): | ||
return self.fail | ||
|
||
@property | ||
def skipped(self): | ||
return self.skip | ||
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. it looks to me like you don't need to override |
||
|
||
|
||
class BaseRunner(object): | ||
print_header = True | ||
|
||
|
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.
i believe you can pass
"dbt"
as the package name here instead ofNone