Skip to content
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

Write JSON manifest file to disk #761

Merged
merged 31 commits into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b1c5577
Convert unparsed contracts code to use json-schema
jwerderits May 2, 2018
1eaa1e7
Make parser for unparsed nodes use json-schema
jwerderits May 2, 2018
04a61e8
More contracts converted to json-schema. Note tags changed from set -…
jwerderits May 2, 2018
3672cbc
PEP8
jwerderits May 2, 2018
6bb051e
More set -> list fun
jwerderits May 2, 2018
dcce83a
Commit this horrible mess I've made while I go back and refactor a bit
jwerderits May 2, 2018
f6d2e9e
Finished converting dbt.contracts.graph to json-schema.
jwerderits May 2, 2018
9ef1d5b
Convert dbt.contracts.connection
jwerderits May 3, 2018
4c2031a
Revert OrderedDict to array change, finish up contracts
jwerderits May 3, 2018
2ecb504
Remove voluptuous validators, replace any with a function
jwerderits May 3, 2018
541b2b3
Add missing redshift type to pg connections
jwerderits May 3, 2018
a4b4ab5
Remove last remaining voluptuous references
jwerderits May 3, 2018
674d4c5
remove vestigal code
jwerderits May 3, 2018
351d2c4
Naming, make APIObject.get more pythonic
jwerderits May 3, 2018
a3e55f0
removed fields that I forgot to remove earlier, add some description …
jwerderits May 3, 2018
5a69fe0
Rewrite parse_macro_file to use UnparsedMacro, ParsedMacro objects
May 3, 2018
802226d
Fix unit tests to look up generator properly
jwerderits May 3, 2018
6283d97
Attach agate_property to ParsedNode
jwerderits May 4, 2018
c318aa7
Make more things create UnparsedNodes, add a number of comments about…
jwerderits May 4, 2018
75137ac
Make parse_node return a ParsedNode instead of a dict.
jwerderits May 4, 2018
25e1035
Add a to_dict method to ParsedNode so that compilation can have a dic…
jwerderits May 4, 2018
c3caa52
Convert nodes to dicts after loading to make compiling work
jwerderits May 4, 2018
6f03738
Fix the whole unparsed/parsed node thing up so tests pass
jwerderits May 4, 2018
3432b52
Changed parse_node and seed/archive parsing so that parse_node can sa…
jwerderits May 4, 2018
73a2a7d
Move the conversion from GraphLoader output to what compiler expects …
jwerderits May 4, 2018
2dd3ffa
Have the GraphLoader just return a new object that does all the hard …
jwerderits May 4, 2018
071dfa2
Actually write the manifest to disk
jwerderits May 4, 2018
b14366e
Add missing import, clean up _LOADERS logic
jwerderits May 4, 2018
4c6aeb8
TODO cleanups
jwerderits May 4, 2018
b8b71ac
More TODO cleanup
jwerderits May 4, 2018
55e2c14
Update changelog
jwerderits May 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from dbt.adapters.postgres import PostgresAdapter
from dbt.adapters.bigquery.relation import BigQueryRelation
from dbt.contracts.connection import validate_connection
from dbt.contracts.connection import Connection
from dbt.logger import GLOBAL_LOGGER as logger

import google.auth
Expand Down Expand Up @@ -168,7 +168,7 @@ def open_connection(cls, connection):
@classmethod
def close(cls, connection):
if dbt.flags.STRICT_MODE:
validate_connection(connection)
Connection(**connection)

connection['state'] = 'closed'

Expand Down Expand Up @@ -314,7 +314,7 @@ def execute_model(cls, profile, project_cfg, model,

if flags.STRICT_MODE:
connection = cls.get_connection(profile, model.get('name'))
validate_connection(connection)
Connection(**connection)

model_name = model.get('name')
model_schema = model.get('schema')
Expand Down
12 changes: 6 additions & 6 deletions dbt/adapters/default/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import dbt.schema
import dbt.clients.agate_helper

from dbt.contracts.connection import validate_connection
from dbt.contracts.connection import Connection
from dbt.logger import GLOBAL_LOGGER as logger
from dbt.schema import Column
from dbt.utils import filter_null_values
Expand Down Expand Up @@ -464,7 +464,7 @@ def acquire_connection(cls, profile, name):
}

if dbt.flags.STRICT_MODE:
validate_connection(result)
Connection(**result)

return cls.open_connection(result)
finally:
Expand Down Expand Up @@ -542,7 +542,7 @@ def begin(cls, profile, name='master'):
connection = cls.get_connection(profile, name)

if dbt.flags.STRICT_MODE:
validate_connection(connection)
Connection(**connection)

if connection['transaction_open'] is True:
raise dbt.exceptions.InternalException(
Expand Down Expand Up @@ -575,7 +575,7 @@ def commit(cls, profile, connection):
global connections_in_use

if dbt.flags.STRICT_MODE:
validate_connection(connection)
Connection(**connection)

connection = cls.reload(connection)

Expand All @@ -595,7 +595,7 @@ def commit(cls, profile, connection):
@classmethod
def rollback(cls, connection):
if dbt.flags.STRICT_MODE:
validate_connection(connection)
Connection(**connection)

connection = cls.reload(connection)

Expand All @@ -615,7 +615,7 @@ def rollback(cls, connection):
@classmethod
def close(cls, connection):
if dbt.flags.STRICT_MODE:
validate_connection(connection)
Connection(**connection)

connection.get('handle').close()
connection['state'] = 'closed'
Expand Down
9 changes: 6 additions & 3 deletions dbt/api/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def validate(self):

for error in validator.iter_errors(self.serialize()):
errors.append('.'.join(
list(map(str, error.path)) + [error.message])
)
list(map(str, error.path)) + [error.message]
))

if errors:
raise ValidationException(
Expand All @@ -92,7 +92,10 @@ def __len__(self):

# implement this because everyone always expects it.
def get(self, key, default=None):
return self._contents.get(key, default)
try:
return self[key]
except KeyError:
return default

# most users of APIObject also expect the attributes to be available via
# dot-notation because the previous implementation assigned to __dict__.
Expand Down
2 changes: 1 addition & 1 deletion dbt/clients/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def clone(repo, cwd, dirname=None, remove_git_dir=False):

def list_tags(cwd):
out, err = run_cmd(cwd, ['git', 'tag', '--list'])
tags = set(out.decode('utf-8').strip().split("\n"))
tags = out.decode('utf-8').strip().split("\n")
return tags


Expand Down
2 changes: 1 addition & 1 deletion dbt/clients/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def call(*args, **kwargs):


class MaterializationExtension(jinja2.ext.Extension):
tags = set(['materialization'])
tags = ['materialization']

def parse(self, parser):
node = jinja2.nodes.Macro(lineno=next(parser.stream).lineno)
Expand Down
32 changes: 23 additions & 9 deletions dbt/compilation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import itertools
import os
import json
from collections import OrderedDict, defaultdict
import sqlparse

Expand All @@ -21,9 +22,11 @@
import dbt.loader
import dbt.parser

from dbt.clients.system import write_file
from dbt.logger import GLOBAL_LOGGER as logger

graph_file_name = 'graph.gpickle'
manifest_file_name = 'manifest.json'


def print_compile_stats(stats):
Expand Down Expand Up @@ -54,16 +57,16 @@ def prepend_ctes(model, flat_graph):

def recursively_prepend_ctes(model, flat_graph):
if dbt.flags.STRICT_MODE:
dbt.contracts.graph.compiled.validate_node(model)
dbt.contracts.graph.compiled.validate(flat_graph)
dbt.contracts.graph.compiled.CompiledNode(**model)
dbt.contracts.graph.compiled.CompiledGraph(**flat_graph)

model = model.copy()
prepend_ctes = OrderedDict()

if model.get('all_ctes_injected') is True:
return (model, model.get('extra_ctes').keys(), flat_graph)

for cte_id in model.get('extra_ctes', {}).keys():
for cte_id in model.get('extra_ctes', {}):
cte_to_add = flat_graph.get('nodes').get(cte_id)
cte_to_add, new_prepend_ctes, flat_graph = recursively_prepend_ctes(
cte_to_add, flat_graph)
Expand All @@ -78,7 +81,7 @@ def recursively_prepend_ctes(model, flat_graph):
model['extra_ctes'] = prepend_ctes
model['injected_sql'] = inject_ctes_into_sql(
model.get('compiled_sql'),
model.get('extra_ctes'))
prepend_ctes)

flat_graph['nodes'][model.get('unique_id')] = model

Expand Down Expand Up @@ -148,8 +151,7 @@ def initialize(self):
def __write(self, build_filepath, payload):
target_path = os.path.join(self.project['target-path'], build_filepath)

dbt.clients.system.make_directory(os.path.dirname(target_path))
dbt.compat.write_file(target_path, payload)
write_file(target_path, payload)

return target_path

Expand Down Expand Up @@ -207,6 +209,15 @@ def compile_node(self, node, flat_graph):

return injected_node

def write_manifest_file(self, manifest):
"""Write the manifest file to disk.

manifest should be a ParsedManifest.
"""
filename = manifest_file_name
manifest_path = os.path.join(self.project['target-path'], filename)
write_file(manifest_path, json.dumps(manifest.serialize()))

def write_graph_file(self, linker):
filename = graph_file_name
graph_path = os.path.join(self.project['target-path'], filename)
Expand Down Expand Up @@ -257,7 +268,7 @@ def get_all_projects(self):
all_projects[name] = project.cfg

if dbt.flags.STRICT_MODE:
dbt.contracts.project.validate_list(all_projects)
dbt.contracts.project.ProjectList(**all_projects)

return all_projects

Expand All @@ -283,8 +294,11 @@ def compile(self):
root_project = self.project.cfg
all_projects = self.get_all_projects()

flat_graph = dbt.loader.GraphLoader.load_all(
root_project, all_projects)
manifest = dbt.loader.GraphLoader.load_all(root_project, all_projects)

self.write_manifest_file(manifest)

flat_graph = manifest.to_flat_graph()

self._check_resource_uniqueness(flat_graph)

Expand Down
18 changes: 14 additions & 4 deletions dbt/context/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import os
import pytz
import voluptuous

from dbt.adapters.factory import get_adapter
from dbt.compat import basestring, to_string
Expand Down Expand Up @@ -79,7 +78,7 @@ def _add_macros(context, model, flat_graph):
package_name = macro.get('package_name')

macro_map = {
macro.get('name'): macro.get('generator')(context)
macro.get('name'): macro.generator(context)
}

if context.get(package_name) is None:
Expand Down Expand Up @@ -117,9 +116,20 @@ def _add_tracking(context):


def _add_validation(context):
def validate_any(*args):
def inner(value):
for arg in args:
if isinstance(arg, type) and isinstance(value, arg):
return
elif value == arg:
return
raise dbt.exceptions.ValidationException(
'Expected value "{}" to be one of {}'
.format(value, ','.join(map(str, args))))
return inner

validation_utils = dbt.utils.AttrDict({
'any': voluptuous.Any,
'all': voluptuous.All,
'any': validate_any,
})

return dbt.utils.merge(
Expand Down
2 changes: 1 addition & 1 deletion dbt/context/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def ref(db_wrapper, model, project_cfg, profile, flat_graph):

def ref(*args):
if len(args) == 1 or len(args) == 2:
model['refs'].append(args)
model['refs'].append(list(args))

else:
dbt.exceptions.ref_invalid_args(model, args)
Expand Down
21 changes: 0 additions & 21 deletions dbt/contracts/common.py

This file was deleted.

Loading