From 82c640d1c61bfdb1137756295533f8ae9fabe662 Mon Sep 17 00:00:00 2001 From: Javier Calvo Date: Mon, 21 Mar 2022 16:17:44 +0100 Subject: [PATCH 1/4] added macro for wh selection --- dbt/adapters/snowflake/impl.py | 10 ++++++++++ dbt/include/snowflake/macros/etc.sql | 3 +++ 2 files changed, 13 insertions(+) create mode 100644 dbt/include/snowflake/macros/etc.sql diff --git a/dbt/adapters/snowflake/impl.py b/dbt/adapters/snowflake/impl.py index e609ba5f5..3058c2856 100644 --- a/dbt/adapters/snowflake/impl.py +++ b/dbt/adapters/snowflake/impl.py @@ -19,6 +19,9 @@ from dbt.utils import filter_null_values +SNOWFLAKE_WAREHOUSE_MACRO_NAME = 'snowflake_warehouse' + + @dataclass class SnowflakeConfig(AdapterConfig): transient: Optional[bool] = None @@ -82,6 +85,13 @@ def _get_warehouse(self) -> str: def _use_warehouse(self, warehouse: str): """Use the given warehouse. Quotes are never applied.""" + kwargs = { + 'warehouse': warehouse + } + warehouse = self.execute_macro( + SNOWFLAKE_WAREHOUSE_MACRO_NAME, + kwargs=kwargs + ) self.execute('use warehouse {}'.format(warehouse)) def pre_model_hook(self, config: Mapping[str, Any]) -> Optional[str]: diff --git a/dbt/include/snowflake/macros/etc.sql b/dbt/include/snowflake/macros/etc.sql new file mode 100644 index 000000000..f77925599 --- /dev/null +++ b/dbt/include/snowflake/macros/etc.sql @@ -0,0 +1,3 @@ +{% macro snowflake_warehouse(warehouse) -%} + {{ return(warehouse) }} +{%- endmacro %} From 40c5948a361a76888b5c07e41076bad6619a7ae9 Mon Sep 17 00:00:00 2001 From: Javier Calvo Date: Mon, 21 Mar 2022 16:30:49 +0100 Subject: [PATCH 2/4] added changes --- .changes/unreleased/Added-20220321-162832.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changes/unreleased/Added-20220321-162832.yaml diff --git a/.changes/unreleased/Added-20220321-162832.yaml b/.changes/unreleased/Added-20220321-162832.yaml new file mode 100644 index 000000000..49b2a5d0e --- /dev/null +++ b/.changes/unreleased/Added-20220321-162832.yaml @@ -0,0 +1,3 @@ +kind: Added +body: Macro for custom warehouse selection +time: 2022-03-21T16:28:32.82239+01:00 From db1f7cb72c90727f18aad78c59ed9781b9921e15 Mon Sep 17 00:00:00 2001 From: Matthew McKnight Date: Tue, 7 Mar 2023 14:32:28 -0600 Subject: [PATCH 3/4] init push of takeover of pr:115 --- .changes/unreleased/Features-20230307-140933.yaml | 6 ++++++ dbt/adapters/snowflake/impl.py | 14 ++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 .changes/unreleased/Features-20230307-140933.yaml diff --git a/.changes/unreleased/Features-20230307-140933.yaml b/.changes/unreleased/Features-20230307-140933.yaml new file mode 100644 index 000000000..be6f13bc8 --- /dev/null +++ b/.changes/unreleased/Features-20230307-140933.yaml @@ -0,0 +1,6 @@ +kind: Features +body: take over pr:103 to allow Macro for custom warehouse selection +time: 2023-03-07T14:09:33.713772-06:00 +custom: + Author: javiCalvo + Issue: "438" diff --git a/dbt/adapters/snowflake/impl.py b/dbt/adapters/snowflake/impl.py index d6373643f..b2bedfbdf 100644 --- a/dbt/adapters/snowflake/impl.py +++ b/dbt/adapters/snowflake/impl.py @@ -18,7 +18,7 @@ from dbt.utils import filter_null_values -SNOWFLAKE_WAREHOUSE_MACRO_NAME = 'snowflake_warehouse' +SNOWFLAKE_WAREHOUSE_MACRO_NAME = "snowflake_warehouse" @dataclass @@ -76,15 +76,9 @@ def _get_warehouse(self) -> str: def _use_warehouse(self, warehouse: str): """Use the given warehouse. Quotes are never applied.""" - kwargs = { - 'warehouse': warehouse - } - warehouse = self.execute_macro( - SNOWFLAKE_WAREHOUSE_MACRO_NAME, - kwargs=kwargs - ) - self.execute('use warehouse {}'.format(warehouse)) - + kwargs = {"warehouse": warehouse} + warehouse = self.execute_macro(SNOWFLAKE_WAREHOUSE_MACRO_NAME, kwargs=kwargs) # type: ignore + self.execute("use warehouse {}".format(warehouse)) def pre_model_hook(self, config: Mapping[str, Any]) -> Optional[str]: default_warehouse = self.config.credentials.warehouse From ed0c3a05b35e69f56ddb683d1164d9cba5b6d366 Mon Sep 17 00:00:00 2001 From: Matthew McKnight Date: Wed, 8 Mar 2023 11:31:31 -0600 Subject: [PATCH 4/4] remove original commmunity changie entry and remove a variable type definition. --- .changes/unreleased/Added-20220321-162832.yaml | 3 --- dbt/adapters/snowflake/impl.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 .changes/unreleased/Added-20220321-162832.yaml diff --git a/.changes/unreleased/Added-20220321-162832.yaml b/.changes/unreleased/Added-20220321-162832.yaml deleted file mode 100644 index 49b2a5d0e..000000000 --- a/.changes/unreleased/Added-20220321-162832.yaml +++ /dev/null @@ -1,3 +0,0 @@ -kind: Added -body: Macro for custom warehouse selection -time: 2022-03-21T16:28:32.82239+01:00 diff --git a/dbt/adapters/snowflake/impl.py b/dbt/adapters/snowflake/impl.py index b2bedfbdf..55cef30fa 100644 --- a/dbt/adapters/snowflake/impl.py +++ b/dbt/adapters/snowflake/impl.py @@ -74,7 +74,7 @@ def _get_warehouse(self) -> str: raise DbtRuntimeError("Could not get current warehouse: no results") return str(table[0][0]) - def _use_warehouse(self, warehouse: str): + def _use_warehouse(self, warehouse): """Use the given warehouse. Quotes are never applied.""" kwargs = {"warehouse": warehouse} warehouse = self.execute_macro(SNOWFLAKE_WAREHOUSE_MACRO_NAME, kwargs=kwargs) # type: ignore