Skip to content

Commit

Permalink
That was the last reference to to_flat_graph, so goodbye to all that
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed Jul 17, 2019
1 parent 6be4ac0 commit 1a4daab
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 128 deletions.
16 changes: 0 additions & 16 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,22 +379,6 @@ def patch_nodes(self, patches):
'not found or is disabled').format(patch.name)
)

def to_flat_graph(self):
"""Convert the parsed manifest to the 'flat graph' that the compiler
expects.
Kind of hacky note: everything in the code is happy to deal with
macros as ParsedMacro objects (in fact, it's been changed to require
that), so those can just be returned without any work. Nodes sadly
require a lot of work on the compiler side.
Ideally in the future we won't need to have this method.
"""
return {
'nodes': {k: v.to_shallow_dict() for k, v in self.nodes.items()},
'macros': self.macros,
}

def __getattr__(self, name):
raise AttributeError("'{}' object has no attribute '{}'".format(
type(self).__name__, name)
Expand Down
33 changes: 0 additions & 33 deletions test/unit/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,6 @@ def test__nested_nodes(self):
[]
)

def test__to_flat_graph(self):
nodes = copy.copy(self.nested_nodes)
manifest = Manifest(nodes=nodes, macros={}, docs={},
generated_at=timestring(), disabled=[])
flat_graph = manifest.to_flat_graph()
flat_nodes = flat_graph['nodes']
self.assertEqual(set(flat_graph), set(['nodes', 'macros']))
self.assertEqual(flat_graph['macros'], {})
self.assertEqual(set(flat_nodes), set(self.nested_nodes))
expected_keys = set(ParsedNode.SCHEMA['required']) | {'agate_table'}
for node in flat_nodes.values():
self.assertEqual(set(node), expected_keys)

@mock.patch.object(tracking, 'active_user')
def test_get_metadata(self, mock_user):
mock_user.id = 'cfc9500f-dc7f-4c83-9ea7-2c581c1b38cf'
Expand Down Expand Up @@ -622,23 +609,3 @@ def test__nested_nodes(self):
child_map['model.snowplow.events'],
[]
)

def test__to_flat_graph(self):
nodes = copy.copy(self.nested_nodes)
manifest = Manifest(nodes=nodes, macros={}, docs={},
generated_at=timestring(), disabled=[])
flat_graph = manifest.to_flat_graph()
flat_nodes = flat_graph['nodes']
self.assertEqual(set(flat_graph), set(['nodes', 'macros']))
self.assertEqual(flat_graph['macros'], {})
self.assertEqual(set(flat_nodes), set(self.nested_nodes))
parsed_keys = set(ParsedNode.SCHEMA['required']) | {'agate_table'}
compiled_keys = set(CompiledNode.SCHEMA['required']) | {'agate_table'}
compiled_count = 0
for node in flat_nodes.values():
if node.get('compiled'):
self.assertEqual(set(node), compiled_keys)
compiled_count += 1
else:
self.assertEqual(set(node), parsed_keys)
self.assertEqual(compiled_count, 2)
152 changes: 73 additions & 79 deletions test/unit/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,88 +1692,82 @@ def test__process_refs__packages(self):

processed_manifest = ParserUtils.process_refs(manifest, 'root')
self.assertEqual(
processed_manifest.to_flat_graph(),
processed_manifest.serialize()['nodes'],
{
'macros': {},
'nodes': {
'model.snowplow.events': {
'name': 'events',
'alias': 'events',
'database': 'test',
'schema': 'analytics',
'resource_type': 'model',
'unique_id': 'model.snowplow.events',
'fqn': ['snowplow', 'events'],
'empty': False,
'package_name': 'snowplow',
'refs': [],
'sources': [],
'depends_on': {
'nodes': [],
'macros': []
},
'config': self.disabled_config,
'tags': [],
'path': 'events.sql',
'original_file_path': 'events.sql',
'root_path': get_os_path('/usr/src/app'),
'raw_sql': 'does not matter',
'agate_table': None,
'columns': {},
'description': '',
'model.snowplow.events': {
'name': 'events',
'alias': 'events',
'database': 'test',
'schema': 'analytics',
'resource_type': 'model',
'unique_id': 'model.snowplow.events',
'fqn': ['snowplow', 'events'],
'empty': False,
'package_name': 'snowplow',
'refs': [],
'sources': [],
'depends_on': {
'nodes': [],
'macros': []
},
'model.root.events': {
'name': 'events',
'alias': 'events',
'database': 'test',
'schema': 'analytics',
'resource_type': 'model',
'unique_id': 'model.root.events',
'fqn': ['root', 'events'],
'empty': False,
'package_name': 'root',
'refs': [],
'sources': [],
'depends_on': {
'nodes': [],
'macros': []
},
'config': self.model_config,
'tags': [],
'path': 'events.sql',
'original_file_path': 'events.sql',
'root_path': get_os_path('/usr/src/app'),
'raw_sql': 'does not matter',
'agate_table': None,
'columns': {},
'description': '',
'config': self.disabled_config,
'tags': [],
'path': 'events.sql',
'original_file_path': 'events.sql',
'root_path': get_os_path('/usr/src/app'),
'raw_sql': 'does not matter',
'columns': {},
'description': '',
},
'model.root.events': {
'name': 'events',
'alias': 'events',
'database': 'test',
'schema': 'analytics',
'resource_type': 'model',
'unique_id': 'model.root.events',
'fqn': ['root', 'events'],
'empty': False,
'package_name': 'root',
'refs': [],
'sources': [],
'depends_on': {
'nodes': [],
'macros': []
},
'model.root.dep': {
'name': 'dep',
'alias': 'dep',
'database': 'test',
'schema': 'analytics',
'resource_type': 'model',
'unique_id': 'model.root.dep',
'fqn': ['root', 'dep'],
'empty': False,
'package_name': 'root',
'refs': [['events']],
'sources': [],
'depends_on': {
'nodes': ['model.root.events'],
'macros': []
},
'config': self.model_config,
'tags': [],
'path': 'multi.sql',
'original_file_path': 'multi.sql',
'root_path': get_os_path('/usr/src/app'),
'raw_sql': 'does not matter',
'agate_table': None,
'columns': {},
'description': '',
}
'config': self.model_config,
'tags': [],
'path': 'events.sql',
'original_file_path': 'events.sql',
'root_path': get_os_path('/usr/src/app'),
'raw_sql': 'does not matter',
'columns': {},
'description': '',
},
'model.root.dep': {
'name': 'dep',
'alias': 'dep',
'database': 'test',
'schema': 'analytics',
'resource_type': 'model',
'unique_id': 'model.root.dep',
'fqn': ['root', 'dep'],
'empty': False,
'package_name': 'root',
'refs': [['events']],
'sources': [],
'depends_on': {
'nodes': ['model.root.events'],
'macros': []
},
'config': self.model_config,
'tags': [],
'path': 'multi.sql',
'original_file_path': 'multi.sql',
'root_path': get_os_path('/usr/src/app'),
'raw_sql': 'does not matter',
'columns': {},
'description': '',
}
}
)
Expand Down

0 comments on commit 1a4daab

Please sign in to comment.