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

fix for null output for tests defined in ephemeral dir [development] #509

Merged
merged 3 commits into from
Aug 22, 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
15 changes: 10 additions & 5 deletions dbt/node_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ def __init__(self, project, adapter, node, node_index, num_nodes):
def raise_on_first_error(self):
return False

def is_ephemeral(self):
return dbt.utils.get_materialization(self.node) == 'ephemeral'
@classmethod
def is_ephemeral_model(cls, node):
materialized = dbt.utils.get_materialization(node)
resource_type = node.get('resource_type')

return materialized == 'ephemeral' and resource_type == NodeType.Model

def safe_run(self, flat_graph, existing):
catchable_errors = (dbt.exceptions.CompilationException,
Expand All @@ -95,7 +99,7 @@ def safe_run(self, flat_graph, existing):
result.node = compiled_node

# for ephemeral nodes, we only want to compile, not run
if not self.is_ephemeral():
if not self.is_ephemeral_model(self.node):
result = self.run(compiled_node, existing, flat_graph)

except catchable_errors as e:
Expand Down Expand Up @@ -156,8 +160,9 @@ def on_skip(self):
schema_name = self.get_schema(self.adapter, self.profile)

node_name = self.node.get('name')
dbt.ui.printer.print_skip_line(self.node, schema_name, node_name,
self.node_index, self.num_nodes)
if not self.is_ephemeral_model(self.node):
dbt.ui.printer.print_skip_line(self.node, schema_name, node_name,
self.node_index, self.num_nodes)

node_result = RunModelResult(self.node, skip=True)
return node_result
Expand Down
11 changes: 6 additions & 5 deletions dbt/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def get_runners(self, Runner, adapter, node_dependency_list):
all_nodes = dbt.utils.flatten_nodes(node_dependency_list)

num_nodes = len([
n for n in all_nodes if get_materialization(n) != 'ephemeral'
n for n in all_nodes if not Runner.is_ephemeral_model(n)
])

node_runners = {}
i = 0
for node in all_nodes:
uid = node.get('unique_id')
if get_materialization(node) == 'ephemeral':
if Runner.is_ephemeral_model(node):
runner = Runner(self.project, adapter, node, 0, 0)
else:
i += 1
Expand All @@ -78,12 +78,12 @@ def call_runner(self, data):
return runner.on_skip()

# no before/after printing for ephemeral mdoels
if not runner.is_ephemeral():
if not runner.is_ephemeral_model(runner.node):
runner.before_execute()

result = runner.safe_run(flat_graph, existing)

if not runner.is_ephemeral():
if not runner.is_ephemeral_model(runner.node):
runner.after_execute(result)

if result.errored and runner.raise_on_first_error():
Expand Down Expand Up @@ -130,7 +130,8 @@ def execute_nodes(self, linker, Runner, flat_graph, node_dependency_list):

try:
for result in pool.imap_unordered(self.call_runner, args_list):
node_results.append(result)
if not Runner.is_ephemeral_model(result.node):
node_results.append(result)

node_id = result.node.get('unique_id')
flat_graph['nodes'][node_id] = result.node
Expand Down
6 changes: 6 additions & 0 deletions test/integration/007_graph_selection_tests/models/emails.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

{{
config(materialized='ephemeral')
}}

select distinct email from {{ ref('base_users') }}
4 changes: 4 additions & 0 deletions test/integration/007_graph_selection_tests/models/schema.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

emails:
constraints:
unique:
- email

users:
constraints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def test__postgres__specific_model(self):
created_models = self.get_models_in_schema()
self.assertFalse('users_rollup' in created_models)
self.assertFalse('base_users' in created_models)
self.assertFalse('emails' in created_models)

@attr(type='snowflake')
def test__snowflake__specific_model(self):
Expand All @@ -36,6 +37,7 @@ def test__snowflake__specific_model(self):
created_models = self.get_models_in_schema()
self.assertFalse('users_rollup' in created_models)
self.assertFalse('base_users' in created_models)
self.assertFalse('emails' in created_models)


@attr(type='postgres')
Expand All @@ -50,6 +52,7 @@ def test__postgres__specific_model_and_children(self):
self.assertTablesEqual("summary_expected", "users_rollup")
created_models = self.get_models_in_schema()
self.assertFalse('base_users' in created_models)
self.assertFalse('emails' in created_models)

@attr(type='snowflake')
def test__snowflake__specific_model_and_children(self):
Expand All @@ -63,6 +66,7 @@ def test__snowflake__specific_model_and_children(self):
self.assertTablesEqual("summary_expected", "users_rollup")
created_models = self.get_models_in_schema()
self.assertFalse('base_users' in created_models)
self.assertFalse('emails' in created_models)


@attr(type='postgres')
Expand All @@ -77,6 +81,7 @@ def test__postgres__specific_model_and_parents(self):
self.assertTablesEqual("summary_expected", "users_rollup")
created_models = self.get_models_in_schema()
self.assertFalse('base_users' in created_models)
self.assertFalse('emails' in created_models)

@attr(type='snowflake')
def test__snowflake__specific_model_and_parents(self):
Expand All @@ -90,6 +95,7 @@ def test__snowflake__specific_model_and_parents(self):
self.assertTablesEqual("summary_expected", "users_rollup")
created_models = self.get_models_in_schema()
self.assertFalse('base_users' in created_models)
self.assertFalse('emails' in created_models)


@attr(type='postgres')
Expand All @@ -104,6 +110,7 @@ def test__postgres__specific_model_with_exclusion(self):
created_models = self.get_models_in_schema()
self.assertFalse('base_users' in created_models)
self.assertFalse('users_rollup' in created_models)
self.assertFalse('emails' in created_models)

@attr(type='snowflake')
def test__snowflake__specific_model_with_exclusion(self):
Expand All @@ -117,3 +124,4 @@ def test__snowflake__specific_model_with_exclusion(self):
created_models = self.get_models_in_schema()
self.assertFalse('base_users' in created_models)
self.assertFalse('users_rollup' in created_models)
self.assertFalse('emails' in created_models)
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def setUp(self):

self.use_default_project()
self.project = read_project('dbt_project.yml')
self.expected_ephemeral = []

def run_schema_and_assert(self, include, exclude, expected_tests):
self.use_profile('postgres')
Expand All @@ -47,7 +46,7 @@ def run_schema_and_assert(self, include, exclude, expected_tests):
print(test_results)

ran_tests = sorted([test.node.get('name') for test in test_results])
expected_sorted = sorted(expected_tests + self.expected_ephemeral)
expected_sorted = sorted(expected_tests)

self.assertEqual(ran_tests, expected_sorted)

Expand All @@ -56,7 +55,7 @@ def test__postgres__schema_tests_no_specifiers(self):
self.run_schema_and_assert(
None,
None,
['base_users',
['unique_emails_email',
'unique_table_id',
'unique_users_id',
'unique_users_rollup_gender']
Expand All @@ -67,39 +66,39 @@ def test__postgres__schema_tests_specify_model(self):
self.run_schema_and_assert(
['users'],
None,
['base_users', 'unique_users_id']
['unique_users_id']
)

@attr(type='postgres')
def test__postgres__schema_tests_specify_model_and_children(self):
self.run_schema_and_assert(
['users+'],
None,
['base_users', 'unique_users_id', 'unique_users_rollup_gender']
['unique_users_id', 'unique_users_rollup_gender']
)

@attr(type='postgres')
def test__postgres__schema_tests_specify_model_and_parents(self):
self.run_schema_and_assert(
['+users_rollup'],
None,
['base_users', 'unique_users_id', 'unique_users_rollup_gender']
['unique_users_id', 'unique_users_rollup_gender']
)

@attr(type='postgres')
def test__postgres__schema_tests_specify_model_and_parents_with_exclude(self):
self.run_schema_and_assert(
['+users_rollup'],
['users_rollup'],
['base_users', 'unique_users_id']
['unique_users_id']
)

@attr(type='postgres')
def test__postgres__schema_tests_specify_exclude_only(self):
self.run_schema_and_assert(
None,
['users_rollup'],
['base_users', 'unique_table_id', 'unique_users_id']
['unique_emails_email', 'unique_table_id', 'unique_users_id']
)

@attr(type='postgres')
Expand All @@ -109,15 +108,15 @@ def test__postgres__schema_tests_specify_model_in_pkg(self):
None,
# TODO: change this. there's no way to select only direct ancestors
# atm.
['base_users', 'unique_users_rollup_gender']
['unique_users_rollup_gender']
)

@attr(type='postgres')
def test__postgres__schema_tests_with_glob(self):
self.run_schema_and_assert(
['*'],
['users'],
['base_users', 'unique_table_id', 'unique_users_rollup_gender']
['unique_emails_email', 'unique_table_id', 'unique_users_rollup_gender']
)

@attr(type='postgres')
Expand All @@ -141,5 +140,5 @@ def test__postgres__schema_tests_exclude_pkg(self):
self.run_schema_and_assert(
None,
['dbt_integration_project'],
['base_users', 'unique_users_id', 'unique_users_rollup_gender']
['unique_emails_email', 'unique_users_id', 'unique_users_rollup_gender']
)