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 28ecfe94c..55cef30fa 100644 --- a/dbt/adapters/snowflake/impl.py +++ b/dbt/adapters/snowflake/impl.py @@ -18,6 +18,9 @@ from dbt.utils import filter_null_values +SNOWFLAKE_WAREHOUSE_MACRO_NAME = "snowflake_warehouse" + + @dataclass class SnowflakeConfig(AdapterConfig): transient: Optional[bool] = None @@ -71,8 +74,10 @@ 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 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 %}