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

Rip out dry run #281

Merged
merged 2 commits into from
Feb 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 6 deletions dbt/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ def model_sources(self, this_project, own_project=None):
own_project=own_project
).get_models(paths, self.create_template)

elif self.create_template.label == 'test':
return Source(
this_project,
own_project=own_project
).get_test_models(paths, self.create_template)

elif self.create_template.label == 'archive':
return []
else:
Expand Down
3 changes: 2 additions & 1 deletion dbt/compiled_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hashlib
import jinja2
from dbt.utils import compiler_error, to_unicode
from dbt.adapters.factory import get_adapter


class CompiledModel(object):
Expand Down Expand Up @@ -157,7 +158,7 @@ def __repr__(self):
def make_compiled_model(fqn, data):
run_type = data['dbt_run_type']

if run_type in ['run', 'dry-run']:
if run_type == 'run':
return CompiledModel(fqn, data)
elif run_type == 'test':
return CompiledTest(fqn, data)
Expand Down
6 changes: 0 additions & 6 deletions dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,6 @@ def parse_args(args):
sub.set_defaults(cls=clean_task.CleanTask, which='clean')

sub = subs.add_parser('compile', parents=[base_subparser])
sub.add_argument(
'--dry',
action='store_true',
help="Compile 'dry run' models"
)
sub.add_argument(
'--non-destructive',
action='store_true',
Expand Down Expand Up @@ -277,7 +272,6 @@ def parse_args(args):
sub.set_defaults(cls=archive_task.ArchiveTask, which='archive')

sub = subs.add_parser('run', parents=[base_subparser])
sub.add_argument('--dry', action='store_true', help="'dry run' models")
sub.add_argument(
'--models',
required=False,
Expand Down
44 changes: 1 addition & 43 deletions dbt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import yaml
import jinja2
import re
from dbt.templates import BaseCreateTemplate, DryCreateTemplate
from dbt.templates import BaseCreateTemplate
from dbt.utils import split_path
import dbt.schema_tester
import dbt.project
Expand Down Expand Up @@ -502,48 +502,6 @@ def __repr__(self):
return "<Analysis {}: {}>".format(self.name, self.filepath)


class TestModel(Model):
dbt_run_type = 'dry-run'

def __init__(
self,
project,
target_dir,
rel_filepath,
own_project,
create_template
):
return super(TestModel, self).__init__(
project, target_dir, rel_filepath, own_project, create_template
)

def build_path(self):
build_dir = self.create_template.label
filename = "{}.sql".format(self.name)
path_parts = [build_dir] + self.fqn[:-1] + [filename]
return os.path.join(*path_parts)

@property
def fqn(self):
"""fully-qualified name for model. Includes all subdirs below 'models'
path and the filename"""
parts = split_path(self.filepath)
name, _ = os.path.splitext(parts[-1])
test_name = DryCreateTemplate.model_name(name)
return [self.own_project['name']] + parts[1:-1] + [test_name]

@property
def original_fqn(self):
parts = split_path(self.filepath)
name, _ = os.path.splitext(parts[-1])
return [self.project['name']] + parts[1:-1] + [name]

def __repr__(self):
return "<TestModel {}.{}: {}>".format(
self.project['name'], self.name, self.filepath
)


class SchemaTest(DBTSource):
test_type = "base"
dbt_run_type = 'test'
Expand Down
49 changes: 0 additions & 49 deletions dbt/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,51 +205,6 @@ def post_run_all(self, models, results, context):
self.__run_hooks(hooks, context, 'on-run-end hooks')


class DryRunner(ModelRunner):
run_type = 'dry-run'

def pre_run_msg(self, model):
output = ("DRY-RUN model {schema}.{model_name} "
.format(
schema=self.adapter.get_default_schema(self.profile),
model_name=model.name))
return output

def post_run_msg(self, result):
model = result.model
output = ("DONE model {schema}.{model_name} "
.format(
schema=self.adapter.get_default_schema(self.profile),
model_name=model.name))
return output

def pre_run_all_msg(self, models):
return "Dry-running {} models".format(len(models))

def post_run_all_msg(self, results):
return ("{} Finished dry-running {} models"
.format(get_timestamp(), len(results)))

def post_run_all(self, models, results, context):
profile = self.project.run_environment()
adapter = get_adapter(profile)

count_dropped = 0
for result in results:
if result.errored or result.skipped:
continue
model = result.model
schema_name = self.adapter.get_default_schema(self.profile)

relation_type = ('table' if model.materialization == 'incremental'
else 'view')
adapter.drop(profile, model.name, relation_type, model.name)
count_dropped += 1

adapter.commit(profile)
logger.info("Dropped {} dry-run models".format(count_dropped))


class TestRunner(ModelRunner):
run_type = 'test'

Expand Down Expand Up @@ -735,10 +690,6 @@ def run(self, limit_to=None):
runner = ModelRunner(self.project)
return self.run_from_graph(runner, limit_to)

def dry_run(self, limit_to=None):
runner = DryRunner(self.project)
return self.run_from_graph(runner, limit_to)

def run_archive(self):
runner = ArchiveRunner(self.project)
return self.run_from_graph(runner, None)
13 changes: 1 addition & 12 deletions dbt/source.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os.path
import fnmatch
from dbt.model import Model, Analysis, TestModel, SchemaFile, Csv, Macro, \
from dbt.model import Model, Analysis, SchemaFile, Csv, Macro, \
ArchiveModel, DataTest

import dbt.clients.system
Expand Down Expand Up @@ -42,17 +42,6 @@ def get_models(self, model_dirs, create_template):
file_matches,
[create_template])

def get_test_models(self, model_dirs, create_template):
file_matches = dbt.clients.system.find_matching(
self.own_project_root,
model_dirs,
"[!.#~]*.sql")

return self.build_models_from_file_matches(
TestModel,
file_matches,
[create_template])

def get_analyses(self, analysis_dirs):
file_matches = dbt.clients.system.find_matching(
self.own_project_root,
Expand Down
9 changes: 2 additions & 7 deletions dbt/task/compile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dbt.compilation import Compiler, CompilableEntities
from dbt.templates import BaseCreateTemplate, DryCreateTemplate
from dbt.templates import BaseCreateTemplate
from dbt.logger import GLOBAL_LOGGER as logger


Expand All @@ -9,12 +9,7 @@ def __init__(self, args, project):
self.project = project

def run(self):
if self.args.dry:
create_template = DryCreateTemplate
else:
create_template = BaseCreateTemplate

compiler = Compiler(self.project, create_template, self.args)
compiler = Compiler(self.project, BaseCreateTemplate, self.args)
compiler.initialize()
results = compiler.compile(limit_to=CompilableEntities)

Expand Down
15 changes: 4 additions & 11 deletions dbt/task/run.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import print_function

import os

from dbt.compilation import Compiler, CompilableEntities
from dbt.logger import GLOBAL_LOGGER as logger
from dbt.runner import RunManager
from dbt.templates import DryCreateTemplate, BaseCreateTemplate
from dbt.templates import BaseCreateTemplate

THREAD_LIMIT = 9

Expand All @@ -16,9 +14,7 @@ def __init__(self, args, project):
self.project = project

def compile(self):
create_template = DryCreateTemplate if self.args.dry \
else BaseCreateTemplate
compiler = Compiler(self.project, create_template, self.args)
compiler = Compiler(self.project, BaseCreateTemplate, self.args)
compiler.initialize()
results = compiler.compile(limit_to=['models'])

Expand All @@ -27,7 +23,7 @@ def compile(self):
])
logger.info("Compiled {}".format(stat_line))

return create_template.label
return BaseCreateTemplate.label

def run(self):
graph_type = self.compile()
Expand All @@ -36,10 +32,7 @@ def run(self):
self.project, self.project['target-path'], graph_type, self.args
)

if self.args.dry:
results = runner.dry_run(self.args.models)
else:
results = runner.run(self.args.models)
results = runner.run(self.args.models)

total = len(results)
passed = len([r for r in results if not r.errored and not r.skipped])
Expand Down
7 changes: 1 addition & 6 deletions dbt/task/test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import os
import psycopg2
import sys
import yaml

from dbt.compilation import Compiler, CompilableEntities
from dbt.templates import DryCreateTemplate, BaseCreateTemplate
from dbt.templates import BaseCreateTemplate
from dbt.runner import RunManager
from dbt.schema_tester import SchemaTester
from dbt.logger import GLOBAL_LOGGER as logger


Expand Down
50 changes: 0 additions & 50 deletions dbt/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,56 +118,6 @@ def wrap(self, opts):
return self.add_extras(opts, sql)


class DryCreateTemplate(object):
base_template = u"""
create view "{schema}"."{identifier}" as (
SELECT * FROM (
{query}
) as tmp LIMIT 0
);"""


incremental_template = u"""
create table "{schema}"."{identifier}" {dist_qualifier} {sort_qualifier} as (
select * from (
{query}
) s limit 0
);
"""

incremental_delete_template = u"""
delete from "{schema}"."{identifier}" where ({unique_key}) in (
select ({unique_key}) from "{identifier}__dbt_incremental_tmp"
);
"""

label = "test"

@classmethod
def model_name(cls, base_name):
return 'test_{}'.format(base_name)

def wrap(self, opts):
sql = ""
if opts['materialization'] in ('table', 'view'):
sql = self.base_template.format(**opts)
elif opts['materialization'] == 'incremental':
if opts.get('unique_key') is not None:
delete_sql = self.incremental_delete_template.format(**opts)
else:
delete_sql = "-- no unique key provided... skipping delete"

opts['incremental_delete_statement'] = delete_sql
sql = self.incremental_template.format(**opts)

elif opts['materialization'] == 'ephemeral':
sql = opts['query']
else:
raise RuntimeError("Invalid materialization parameter ({})".format(opts['materialization']))

return "{}\n\n{}".format(opts['prologue'], sql)


SCDArchiveTemplate = u"""

with "current_data" as (
Expand Down
5 changes: 1 addition & 4 deletions dbt/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ def get_options(args):


def get_run_type(args):
if 'dry' in args and args.dry is True:
return 'dry'
else:
return 'regular'
return 'regular'


def get_invocation_context(invocation_id, user, project, args):
Expand Down
12 changes: 0 additions & 12 deletions test/integration/007_dry_run_test/models/seed_summary.sql

This file was deleted.

Loading