Skip to content

Commit

Permalink
added macro for wh selection (#503)
Browse files Browse the repository at this point in the history
* added macro for wh selection

* added changes

* init push of takeover of pr:115

* remove original commmunity changie entry and remove a variable type definition.

---------

Co-authored-by: Javier Calvo <javier.calvo.martinez@gmail.com>
  • Loading branch information
McKnight-42 and javiCalvo authored Mar 8, 2023
1 parent 9d2f8f3 commit 2e061fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230307-140933.yaml
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 6 additions & 1 deletion dbt/adapters/snowflake/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down
3 changes: 3 additions & 0 deletions dbt/include/snowflake/macros/etc.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro snowflake_warehouse(warehouse) -%}
{{ return(warehouse) }}
{%- endmacro %}

0 comments on commit 2e061fc

Please sign in to comment.