-
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
add parser #292
Merged
Merged
add parser #292
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
78e2353
first pass at wiring in parser
39e2c1c
add fqn to model representation, rewiring some of the compiler
6658d87
Merge branch 'development' of github.com:analyst-collective/dbt into …
beedfd5
almost there
2473b12
down to 10 integration test failures
50d9896
schema and data tests running in parser
a125043
archive passing, hooks not so much
5a64113
integration tests passing!
f34892f
remove runners (they are unused now)
1a2ada7
remove get_compiled_models -- unused
c7dd776
ripping things out, part 1: compiled_model.py
8dc998b
ripping stuff out, part 2: archival and other unused model types
b3b17ee
pep8 compliance
7db4b1d
remove print() call from runner.py
7a0039d
remove print() calls from selector.py
6a3202e
remove schema_tester, dbt.archival import
2a2aec2
fix unit tests, compile cmd
305c80c
functional test improvements
77c480a
fix skipping, functional testing w/ revzilla
ac3e5ee
hooks work... finishing up?
102e8df
add compat module to deal with str/unicode/basestring diffs in 2 vs 3
f24c0b1
switch compilation import
99b9ea1
fun with string compatibility
d96913d
write_file is necessary
96b3d49
merged master
caf6105
re-add analyses
d3142cb
update changelog
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import codecs | ||
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 is great |
||
|
||
WHICH_PYTHON = None | ||
|
||
try: | ||
basestring | ||
WHICH_PYTHON = 2 | ||
except NameError: | ||
WHICH_PYTHON = 3 | ||
|
||
if WHICH_PYTHON == 2: | ||
basestring = basestring | ||
else: | ||
basestring = str | ||
|
||
|
||
def to_unicode(s): | ||
if WHICH_PYTHON == 2: | ||
return unicode(s) | ||
else: | ||
return str(s) | ||
|
||
|
||
def to_string(s): | ||
if WHICH_PYTHON == 2: | ||
if isinstance(s, unicode): | ||
return s | ||
elif isinstance(s, basestring): | ||
return to_unicode(s) | ||
else: | ||
return to_unicode(str(s)) | ||
else: | ||
if isinstance(s, basestring): | ||
return s | ||
else: | ||
return str(s) | ||
|
||
|
||
def write_file(path, s): | ||
if WHICH_PYTHON == 2: | ||
with codecs.open(path, 'w', encoding='utf-8') as f: | ||
return f.write(to_string(s)) | ||
else: | ||
with open(path, 'w') as f: | ||
return f.write(to_string(s)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,12 @@ | |
from dbt.model import Model, NodeType | ||
from dbt.source import Source | ||
from dbt.utils import find_model_by_fqn, find_model_by_name, \ | ||
split_path, This, Var, compiler_error, to_string | ||
split_path, This, Var, compiler_error | ||
|
||
from dbt.linker import Linker | ||
from dbt.runtime import RuntimeContext | ||
|
||
import dbt.compat | ||
import dbt.contracts.graph.compiled | ||
import dbt.contracts.graph.parsed | ||
import dbt.contracts.project | ||
|
@@ -33,10 +34,27 @@ | |
graph_file_name = 'graph.yml' | ||
|
||
|
||
def compile_and_print_status(project, args): | ||
compiler = Compiler(project, args) | ||
compiler.initialize() | ||
results = { | ||
NodeType.Model: 0, | ||
NodeType.Test: 0, | ||
NodeType.Archive: 0, | ||
} | ||
|
||
results.update(compiler.compile()) | ||
|
||
stat_line = ", ".join( | ||
["{} {}s".format(ct, t) for t, ct in results.items()]) | ||
|
||
logger.info("Compiled {}".format(stat_line)) | ||
|
||
|
||
def compile_string(string, ctx): | ||
try: | ||
env = jinja2.Environment() | ||
template = env.from_string(str(string), globals=ctx) | ||
template = env.from_string(dbt.compat.to_string(string), globals=ctx) | ||
return template.render(ctx) | ||
except jinja2.exceptions.TemplateSyntaxError as e: | ||
compiler_error(None, str(e)) | ||
|
@@ -130,7 +148,7 @@ def inject_ctes_into_sql(sql, ctes): | |
with_stmt, | ||
sqlparse.sql.Token(sqlparse.tokens.Keyword, ", ".join(ctes))) | ||
|
||
return str(parsed) | ||
return dbt.compat.to_string(parsed) | ||
|
||
|
||
class Compiler(object): | ||
|
@@ -158,8 +176,7 @@ def __write(self, build_filepath, payload): | |
if not os.path.exists(os.path.dirname(target_path)): | ||
os.makedirs(os.path.dirname(target_path)) | ||
|
||
with open(target_path, 'w') as f: | ||
f.write(to_string(payload)) | ||
dbt.compat.write_file(target_path, payload) | ||
|
||
def __model_config(self, model, linker): | ||
def do_config(*args, **kwargs): | ||
|
@@ -224,7 +241,8 @@ def wrapped_do_ref(*args): | |
logger.info("Compiler error in {}".format(model.get('path'))) | ||
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. 👏 |
||
logger.info("Enabled models:") | ||
for n, m in all_models.items(): | ||
logger.info(" - {}".format(".".join(m.get('fqn')))) | ||
if m.get('resource_type') == NodeType.Model: | ||
logger.info(" - {}".format(m.get('unique_id'))) | ||
raise e | ||
|
||
return wrapped_do_ref | ||
|
@@ -397,7 +415,8 @@ def compile_nodes(self, linker, nodes, macro_generator): | |
injected_node.get('path'), | ||
all_projects.get(injected_node.get('package_name'))) | ||
|
||
model._config = injected_node.get('config', {}) | ||
cfg = injected_node.get('config', {}) | ||
model._config = cfg | ||
|
||
context = self.get_context(linker, model, injected_nodes) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we'll break these out into separate nodes in a future PR, yeah?
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.
absolutely