From cb3c007acd71bca6d87cf1ee64bc6b6d6a5577b4 Mon Sep 17 00:00:00 2001 From: NiallRees Date: Sun, 24 Jan 2021 16:19:20 +0000 Subject: [PATCH 1/4] Make generated CTE test names lowercase to match style guide --- core/dbt/adapters/base/relation.py | 2 +- core/dbt/compilation.py | 10 +++---- core/dbt/utils.py | 2 +- .../020_ephemeral_test/test_ephemeral.py | 18 +++++------ test/integration/100_rpc_test/test_rpc.py | 4 +-- test/unit/test_compiler.py | 30 +++++++++---------- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/core/dbt/adapters/base/relation.py b/core/dbt/adapters/base/relation.py index 8cbe4b8f17b..ba85a0ee38b 100644 --- a/core/dbt/adapters/base/relation.py +++ b/core/dbt/adapters/base/relation.py @@ -203,7 +203,7 @@ def create_from_source( @staticmethod def add_ephemeral_prefix(name: str): - return f'__dbt__CTE__{name}' + return f'__dbt__cte__{name}' @classmethod def create_ephemeral_from_node( diff --git a/core/dbt/compilation.py b/core/dbt/compilation.py index 0a929c34033..7afb3e20d74 100644 --- a/core/dbt/compilation.py +++ b/core/dbt/compilation.py @@ -191,11 +191,11 @@ def _inject_ctes_into_sql(self, sql: str, ctes: List[InjectedCTE]) -> str: [ InjectedCTE( id="cte_id_1", - sql="__dbt__CTE__ephemeral as (select * from table)", + sql="__dbt__cte__ephemeral as (select * from table)", ), InjectedCTE( id="cte_id_2", - sql="__dbt__CTE__events as (select id, type from events)", + sql="__dbt__cte__events as (select id, type from events)", ), ] @@ -206,8 +206,8 @@ def _inject_ctes_into_sql(self, sql: str, ctes: List[InjectedCTE]) -> str: This will spit out: - "with __dbt__CTE__ephemeral as (select * from table), - __dbt__CTE__events as (select id, type from events), + "with __dbt__cte__ephemeral as (select * from table), + __dbt__cte__events as (select id, type from events), with internal_cte as (select * from sessions) select * from internal_cte" @@ -246,7 +246,7 @@ def _inject_ctes_into_sql(self, sql: str, ctes: List[InjectedCTE]) -> str: return str(parsed) def _get_dbt_test_name(self) -> str: - return 'dbt__CTE__INTERNAL_test' + return 'dbt__cte__internal_test' # This method is called by the 'compile_node' method. Starting # from the node that it is passed in, it will recursively call diff --git a/core/dbt/utils.py b/core/dbt/utils.py index aac730ebc51..f100fa27a65 100644 --- a/core/dbt/utils.py +++ b/core/dbt/utils.py @@ -298,7 +298,7 @@ def filter_null_values(input: Dict[K_T, Optional[V_T]]) -> Dict[K_T, V_T]: def add_ephemeral_model_prefix(s: str) -> str: - return '__dbt__CTE__{}'.format(s) + return '__dbt__cte__{}'.format(s) def timestring() -> str: diff --git a/test/integration/020_ephemeral_test/test_ephemeral.py b/test/integration/020_ephemeral_test/test_ephemeral.py index 1419d6c8f13..e72ebdb5040 100644 --- a/test/integration/020_ephemeral_test/test_ephemeral.py +++ b/test/integration/020_ephemeral_test/test_ephemeral.py @@ -29,15 +29,15 @@ def test__postgres(self): sql_file = re.sub(r'\d+', '', sql_file) expected_sql = ('create view "dbt"."test_ephemeral_"."double_dependent__dbt_tmp" as (' - 'with __dbt__CTE__base as (' + 'with __dbt__cte__base as (' 'select * from test_ephemeral_.seed' - '), __dbt__CTE__base_copy as (' - 'select * from __dbt__CTE__base' + '), __dbt__cte__base_copy as (' + 'select * from __dbt__cte__base' ')-- base_copy just pulls from base. Make sure the listed' '-- graph of CTEs all share the same dbt_cte__base cte' - "select * from __dbt__CTE__base where gender = 'Male'" + "select * from __dbt__cte__base where gender = 'Male'" 'union all' - "select * from __dbt__CTE__base_copy where gender = 'Female'" + "select * from __dbt__cte__base_copy where gender = 'Female'" ');') sql_file = "".join(sql_file.split()) expected_sql = "".join(expected_sql.split()) @@ -79,11 +79,11 @@ def test__postgres(self): sql_file = re.sub(r'\d+', '', sql_file) expected_sql = ( 'create view "dbt"."test_ephemeral_"."root_view__dbt_tmp" as (' - 'with __dbt__CTE__ephemeral_level_two as (' + 'with __dbt__cte__ephemeral_level_two as (' 'select * from "dbt"."test_ephemeral_"."source_table"' - '), __dbt__CTE__ephemeral as (' - 'select * from __dbt__CTE__ephemeral_level_two' - ')select * from __dbt__CTE__ephemeral' + '), __dbt__cte__ephemeral as (' + 'select * from __dbt__cte__ephemeral_level_two' + ')select * from __dbt__cte__ephemeral' ');') sql_file = "".join(sql_file.split()) diff --git a/test/integration/100_rpc_test/test_rpc.py b/test/integration/100_rpc_test/test_rpc.py index cccf60fc6d2..733ce6341a6 100644 --- a/test/integration/100_rpc_test/test_rpc.py +++ b/test/integration/100_rpc_test/test_rpc.py @@ -87,11 +87,11 @@ def query_url(url, query): return requests.post(url, headers=headers, data=json.dumps(query)) -_select_from_ephemeral = '''with __dbt__CTE__ephemeral_model as ( +_select_from_ephemeral = '''with __dbt__cte__ephemeral_model as ( select 1 as id -)select * from __dbt__CTE__ephemeral_model''' +)select * from __dbt__cte__ephemeral_model''' def addr_in_use(err, *args): diff --git a/test/unit/test_compiler.py b/test/unit/test_compiler.py index 775b6af0c3c..694427f276d 100644 --- a/test/unit/test_compiler.py +++ b/test/unit/test_compiler.py @@ -80,7 +80,7 @@ def setUp(self): def mock_generate_runtime_model_context(model, config, manifest): def ref(name): - result = f'__dbt__CTE__{name}' + result = f'__dbt__cte__{name}' unique_id = f'model.root.{name}' model.extra_ctes.append(InjectedCTE(id=unique_id, sql=None)) return result @@ -121,7 +121,7 @@ def test__prepend_ctes__already_has_cte(self): extra_ctes=[InjectedCTE(id='model.root.ephemeral', sql='select * from source_table')], compiled_sql=( 'with cte as (select * from something_else) ' - 'select * from __dbt__CTE__ephemeral'), + 'select * from __dbt__cte__ephemeral'), checksum=FileHash.from_contents(''), ), 'model.root.ephemeral': CompiledModelNode( @@ -168,10 +168,10 @@ def test__prepend_ctes__already_has_cte(self): self.assertEqual(result.extra_ctes_injected, True) self.assertEqualIgnoreWhitespace( result.compiled_sql, - ('with __dbt__CTE__ephemeral as (' + ('with __dbt__cte__ephemeral as (' 'select * from source_table' '), cte as (select * from something_else) ' - 'select * from __dbt__CTE__ephemeral')) + 'select * from __dbt__cte__ephemeral')) self.assertEqual( manifest.nodes['model.root.ephemeral'].extra_ctes_injected, @@ -296,7 +296,7 @@ def test__prepend_ctes(self): compiled=True, extra_ctes_injected=False, extra_ctes=[InjectedCTE(id='model.root.ephemeral', sql='select * from source_table')], - compiled_sql='select * from __dbt__CTE__ephemeral', + compiled_sql='select * from __dbt__cte__ephemeral', checksum=FileHash.from_contents(''), ), 'model.root.ephemeral': CompiledModelNode( @@ -345,10 +345,10 @@ def test__prepend_ctes(self): self.assertTrue(result.extra_ctes_injected) self.assertEqualIgnoreWhitespace( result.compiled_sql, - ('with __dbt__CTE__ephemeral as (' + ('with __dbt__cte__ephemeral as (' 'select * from source_table' ') ' - 'select * from __dbt__CTE__ephemeral')) + 'select * from __dbt__cte__ephemeral')) print(f"\n---- line 349 ----") self.assertFalse(manifest.nodes['model.root.ephemeral'].extra_ctes_injected) @@ -423,7 +423,7 @@ def test__prepend_ctes__cte_not_compiled(self): compiled=True, extra_ctes_injected=False, extra_ctes=[InjectedCTE(id='model.root.ephemeral', sql='select * from source_table')], - compiled_sql='select * from __dbt__CTE__ephemeral', + compiled_sql='select * from __dbt__cte__ephemeral', checksum=FileHash.from_contents(''), ), 'model.root.ephemeral': parsed_ephemeral, @@ -454,10 +454,10 @@ def test__prepend_ctes__cte_not_compiled(self): self.assertTrue(result.extra_ctes_injected) self.assertEqualIgnoreWhitespace( result.compiled_sql, - ('with __dbt__CTE__ephemeral as (' + ('with __dbt__cte__ephemeral as (' 'select * from source_table' ') ' - 'select * from __dbt__CTE__ephemeral')) + 'select * from __dbt__cte__ephemeral')) self.assertTrue(manifest.nodes['model.root.ephemeral'].extra_ctes_injected) @@ -488,7 +488,7 @@ def test__prepend_ctes__multiple_levels(self): compiled=True, extra_ctes_injected=False, extra_ctes=[InjectedCTE(id='model.root.ephemeral', sql=None)], - compiled_sql='select * from __dbt__CTE__ephemeral', + compiled_sql='select * from __dbt__cte__ephemeral', checksum=FileHash.from_contents(''), ), @@ -552,12 +552,12 @@ def test__prepend_ctes__multiple_levels(self): self.assertTrue(result.extra_ctes_injected) self.assertEqualIgnoreWhitespace( result.compiled_sql, - ('with __dbt__CTE__ephemeral_level_two as (' + ('with __dbt__cte__ephemeral_level_two as (' 'select * from source_table' - '), __dbt__CTE__ephemeral as (' - 'select * from __dbt__CTE__ephemeral_level_two' + '), __dbt__cte__ephemeral as (' + 'select * from __dbt__cte__ephemeral_level_two' ') ' - 'select * from __dbt__CTE__ephemeral')) + 'select * from __dbt__cte__ephemeral')) self.assertTrue(manifest.nodes['model.root.ephemeral'].compiled) self.assertTrue(manifest.nodes['model.root.ephemeral_level_two'].compiled) From 82496c30b122a8791c94da842215f66a29085e5f Mon Sep 17 00:00:00 2001 From: NiallRees Date: Sun, 24 Jan 2021 16:35:40 +0000 Subject: [PATCH 2/4] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a47134ab72f..5ed42ea129a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Fixes - Fix exit code from dbt debug not returning a failure when one of the tests fail ([#3017](/~https://github.com/fishtown-analytics/dbt/issues/3017)) +- Auto-generated dbt test CTE's have lowercase names to comply with dbt coding conventions. ### Features - Add optional configs for `require_partition_filter` and `partition_expiration_days` in BigQuery ([#1843](/~https://github.com/fishtown-analytics/dbt/issues/1843), [#2928](/~https://github.com/fishtown-analytics/dbt/pull/2928)) From f72873a1ce73cc89212fd95248ad3e1573102c08 Mon Sep 17 00:00:00 2001 From: NiallRees Date: Mon, 25 Jan 2021 11:13:32 +0000 Subject: [PATCH 3/4] Update CHANGELOG.md Co-authored-by: Jeremy Cohen --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ed42ea129a..aa1eaf55a99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### Fixes - Fix exit code from dbt debug not returning a failure when one of the tests fail ([#3017](/~https://github.com/fishtown-analytics/dbt/issues/3017)) -- Auto-generated dbt test CTE's have lowercase names to comply with dbt coding conventions. +- Auto-generated CTEs in tests and ephemeral models have lowercase names to comply with dbt coding conventions ([#3027](/~https://github.com/fishtown-analytics/dbt/issues/3027), [#3028](/~https://github.com/fishtown-analytics/dbt/issues/3028)) ### Features - Add optional configs for `require_partition_filter` and `partition_expiration_days` in BigQuery ([#1843](/~https://github.com/fishtown-analytics/dbt/issues/1843), [#2928](/~https://github.com/fishtown-analytics/dbt/pull/2928)) From a170764fc582e0d647f3c226988bfb1d9ca5eb64 Mon Sep 17 00:00:00 2001 From: NiallRees Date: Mon, 25 Jan 2021 11:16:00 +0000 Subject: [PATCH 4/4] Add to contributors --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa1eaf55a99..d16f104b1ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Contributors: - [@yu-iskw](/~https://github.com/yu-iskw) ([#2928](/~https://github.com/fishtown-analytics/dbt/pull/2928)) - [@sdebruyn](/~https://github.com/sdebruyn) / [@lynxcare](/~https://github.com/lynxcare) ([#3018](/~https://github.com/fishtown-analytics/dbt/pull/3018)) - [@rvacaru](/~https://github.com/rvacaru) ([#2974](/~https://github.com/fishtown-analytics/dbt/pull/2974)) +- [@NiallRees](/~https://github.com/NiallRees) ([#3028](/~https://github.com/fishtown-analytics/dbt/pull/3028)) ## dbt 0.19.0 (Release TBD)