Skip to content

Commit

Permalink
[#3210] Make --models and --select synonyms, except for 'ls'
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Aug 23, 2021
1 parent 4591788 commit d4974cd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
17 changes: 5 additions & 12 deletions core/dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,17 +615,10 @@ def _add_common_selector_arguments(sub):
)


def _add_selection_arguments(*subparsers, **kwargs):
models_name = kwargs.get('models_name', 'models')
def _add_selection_arguments(*subparsers):
for sub in subparsers:
if models_name == 'models':
_add_models_argument(sub)
elif models_name == 'select':
# these still get stored in 'models', so they present the same
# interface to the task
_add_select_argument(sub)
else:
raise InternalException(f'Unknown models style {models_name}')
_add_models_argument(sub)
_add_select_argument(sub)
_add_common_selector_arguments(sub)


Expand Down Expand Up @@ -1075,8 +1068,8 @@ def parse_args(args, cls=DBTArgumentParser):
rpc_sub, seed_sub, parse_sub, build_sub)
# --models, --exclude
# list_sub sets up its own arguments.
_add_selection_arguments(build_sub, run_sub, compile_sub, generate_sub, test_sub)
_add_selection_arguments(snapshot_sub, seed_sub, models_name='select')
_add_selection_arguments(
build_sub, run_sub, compile_sub, generate_sub, test_sub, snapshot_sub, seed_sub)
# --defer
_add_defer_argument(run_sub, test_sub, build_sub)
# --full-refresh
Expand Down
52 changes: 26 additions & 26 deletions test/integration/007_graph_selection_tests/test_graph_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def assert_correct_schemas(self):
def test__postgres__specific_model(self):
self.run_sql_file("seed.sql")

results = self.run_dbt(['run', '--models', 'users'])
results = self.run_dbt(['run', '--select', 'users'])
self.assertEqual(len(results), 1)

self.assertTablesEqual("seed", "users")
Expand Down Expand Up @@ -80,7 +80,7 @@ def test__postgres__tags(self):
def test__postgres__tags_and_children(self):
self.run_sql_file("seed.sql")

results = self.run_dbt(['run', '--models', 'tag:base+'])
results = self.run_dbt(['run', '--select', 'tag:base+'])
self.assertEqual(len(results), 5)

created_models = self.get_models_in_schema()
Expand All @@ -96,7 +96,7 @@ def test__postgres__tags_and_children(self):
def test__postgres__tags_and_children_limited(self):
self.run_sql_file("seed.sql")

results = self.run_dbt(['run', '--models', 'tag:base+2'])
results = self.run_dbt(['run', '--select', 'tag:base+2'])
self.assertEqual(len(results), 4)

created_models = self.get_models_in_schema()
Expand All @@ -113,7 +113,7 @@ def test__postgres__tags_and_children_limited(self):
def test__snowflake__specific_model(self):
self.run_sql_file("seed.sql")

results = self.run_dbt(['run', '--models', 'users'])
results = self.run_dbt(['run', '--select', 'users'])
self.assertEqual(len(results), 1)

self.assertTablesEqual("SEED", "USERS")
Expand All @@ -127,7 +127,7 @@ def test__snowflake__specific_model(self):
def test__postgres__specific_model_and_children(self):
self.run_sql_file("seed.sql")

results = self.run_dbt(['run', '--models', 'users+'])
results = self.run_dbt(['run', '--select', 'users+'])
self.assertEqual(len(results), 4)

self.assertTablesEqual("seed", "users")
Expand All @@ -143,7 +143,7 @@ def test__postgres__specific_model_and_children(self):
def test__snowflake__specific_model_and_children(self):
self.run_sql_file("seed.sql")

results = self.run_dbt(['run', '--models', 'users+'])
results = self.run_dbt(['run', '--select', 'users+'])
self.assertEqual(len(results), 4)

self.assertManyTablesEqual(
Expand All @@ -158,7 +158,7 @@ def test__snowflake__specific_model_and_children(self):
def test__postgres__specific_model_and_children_limited(self):
self.run_sql_file("seed.sql")

results = self.run_dbt(['run', '--models', 'users+1'])
results = self.run_dbt(['run', '--select', 'users+1'])
self.assertEqual(len(results), 3)

self.assertTablesEqual("seed", "users")
Expand All @@ -174,7 +174,7 @@ def test__postgres__specific_model_and_children_limited(self):
def test__postgres__specific_model_and_parents(self):
self.run_sql_file("seed.sql")

results = self.run_dbt(['run', '--models', '+users_rollup'])
results = self.run_dbt(['run', '--select', '+users_rollup'])
self.assertEqual(len(results), 2)

self.assertTablesEqual("seed", "users")
Expand All @@ -188,7 +188,7 @@ def test__postgres__specific_model_and_parents(self):
def test__snowflake__specific_model_and_parents(self):
self.run_sql_file("seed.sql")

results = self.run_dbt(['run', '--models', '+users_rollup'])
results = self.run_dbt(['run', '--select', '+users_rollup'])
self.assertEqual(len(results), 2)

self.assertManyTablesEqual(
Expand All @@ -204,7 +204,7 @@ def test__snowflake__specific_model_and_parents(self):
def test__postgres__specific_model_and_parents_limited(self):
self.run_sql_file("seed.sql")

results = self.run_dbt(['run', '--models', '1+users_rollup'])
results = self.run_dbt(['run', '--select', '1+users_rollup'])
self.assertEqual(len(results), 2)

self.assertTablesEqual("seed", "users")
Expand All @@ -219,7 +219,7 @@ def test__postgres__specific_model_with_exclusion(self):
self.run_sql_file("seed.sql")

results = self.run_dbt(
['run', '--models', '+users_rollup', '--exclude', 'models/users_rollup.sql']
['run', '--select', '+users_rollup', '--exclude', 'models/users_rollup.sql']
)
self.assertEqual(len(results), 1)

Expand All @@ -235,7 +235,7 @@ def test__snowflake__specific_model_with_exclusion(self):
self.run_sql_file("seed.sql")

results = self.run_dbt(
['run', '--models', '+users_rollup', '--exclude', 'users_rollup']
['run', '--select', '+users_rollup', '--exclude', 'users_rollup']
)
self.assertEqual(len(results), 1)

Expand All @@ -247,7 +247,7 @@ def test__snowflake__specific_model_with_exclusion(self):

@use_profile('postgres')
def test__postgres__locally_qualified_name(self):
results = self.run_dbt(['run', '--models', 'test.subdir'])
results = self.run_dbt(['run', '--select', 'test.subdir'])
self.assertEqual(len(results), 2)

created_models = self.get_models_in_schema()
Expand All @@ -258,7 +258,7 @@ def test__postgres__locally_qualified_name(self):
self.assertIn('nested_users', created_models)
self.assert_correct_schemas()

results = self.run_dbt(['run', '--models', 'models/test/subdir*'])
results = self.run_dbt(['run', '--select', 'models/test/subdir*'])
self.assertEqual(len(results), 2)

created_models = self.get_models_in_schema()
Expand All @@ -272,14 +272,14 @@ def test__postgres__locally_qualified_name(self):
@use_profile('postgres')
def test__postgres__locally_qualified_name_model_with_dots(self):
self.run_sql_file("seed.sql")
results = self.run_dbt(['run', '--models', 'alternative.users'])
results = self.run_dbt(['run', '--select', 'alternative.users'])
self.assertEqual(len(results), 1)

created_models = self.get_models_in_schema()
self.assertIn('alternative.users', created_models)
self.assert_correct_schemas()

results = self.run_dbt(['run', '--models', 'models/alternative.*'])
results = self.run_dbt(['run', '--select', 'models/alternative.*'])
self.assertEqual(len(results), 1)

created_models = self.get_models_in_schema()
Expand All @@ -289,7 +289,7 @@ def test__postgres__locally_qualified_name_model_with_dots(self):
@use_profile('postgres')
def test__postgres__childrens_parents(self):
self.run_sql_file("seed.sql")
results = self.run_dbt(['run', '--models', '@base_users'])
results = self.run_dbt(['run', '--select', '@base_users'])
self.assertEqual(len(results), 5)

created_models = self.get_models_in_schema()
Expand All @@ -301,15 +301,15 @@ def test__postgres__childrens_parents(self):
self.assertNotIn('nested_users', created_models)

results = self.run_dbt(
['test', '--models', 'test_name:not_null'],
['test', '--select', 'test_name:not_null'],
)
self.assertEqual(len(results), 1)
assert results[0].node.name == 'not_null_emails_email'

@use_profile('postgres')
def test__postgres__more_childrens_parents(self):
self.run_sql_file("seed.sql")
results = self.run_dbt(['run', '--models', '@users'])
results = self.run_dbt(['run', '--select', '@users'])
# users, emails_alt, users_rollup, users_rollup_dependency, but not base_users (ephemeral)
self.assertEqual(len(results), 4)

Expand All @@ -321,7 +321,7 @@ def test__postgres__more_childrens_parents(self):
self.assertNotIn('nested_users', created_models)

results = self.run_dbt(
['test', '--models', 'test_name:unique'],
['test', '--select', 'test_name:unique'],
)
self.assertEqual(len(results), 2)
assert sorted([r.node.name for r in results]) == ['unique_users_id', 'unique_users_rollup_gender']
Expand All @@ -330,12 +330,12 @@ def test__postgres__more_childrens_parents(self):
@use_profile('snowflake')
def test__snowflake__skip_intermediate(self):
self.run_sql_file("seed.sql")
results = self.run_dbt(['run', '--models', '@models/users.sql'])
results = self.run_dbt(['run', '--select', '@models/users.sql'])
# base_users, emails, users_rollup, users_rollup_dependency
self.assertEqual(len(results), 4)

# now re-run, skipping users_rollup
results = self.run_dbt(['run', '--models', '@users', '--exclude', 'users_rollup'])
results = self.run_dbt(['run', '--select', '@users', '--exclude', 'users_rollup'])
self.assertEqual(len(results), 3)

# make sure that users_rollup_dependency and users don't interleave
Expand All @@ -351,7 +351,7 @@ def test__snowflake__skip_intermediate(self):
@use_profile('postgres')
def test__postgres__concat(self):
self.run_sql_file("seed.sql")
results = self.run_dbt(['run', '--models', '@emails_alt', 'users_rollup'])
results = self.run_dbt(['run', '--select', '@emails_alt', 'users_rollup'])
# users, emails_alt, users_rollup
self.assertEqual(len(results), 3)

Expand All @@ -365,7 +365,7 @@ def test__postgres__concat(self):
@use_profile('postgres')
def test__postgres__concat_exclude(self):
self.run_sql_file("seed.sql")
results = self.run_dbt(['run', '--models', '@emails_alt', 'users_rollup', '--exclude', 'emails_alt'])
results = self.run_dbt(['run', '--select', '@emails_alt', 'users_rollup', '--exclude', 'emails_alt'])
# users, users_rollup
self.assertEqual(len(results), 2)

Expand All @@ -380,7 +380,7 @@ def test__postgres__concat_exclude(self):
def test__postgres__concat_exclude_concat(self):
self.run_sql_file("seed.sql")
results = self.run_dbt(
['run', '--models', '@emails_alt', 'users_rollup', '--exclude', 'emails_alt', 'users_rollup']
['run', '--select', '@emails_alt', 'users_rollup', '--exclude', 'emails_alt', 'users_rollup']
)
# users
self.assertEqual(len(results), 1)
Expand All @@ -394,7 +394,7 @@ def test__postgres__concat_exclude_concat(self):
self.assertNotIn('nested_users', created_models)

results = self.run_dbt(
['test', '--models', '@emails_alt', 'users_rollup', '--exclude', 'emails_alt', 'users_rollup']
['test', '--select', '@emails_alt', 'users_rollup', '--exclude', 'emails_alt', 'users_rollup']
)
self.assertEqual(len(results), 1)
assert results[0].node.name == 'unique_users_id'
Expand Down

0 comments on commit d4974cd

Please sign in to comment.