Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added macro for wh selection #503

Merged
merged 10 commits into from
Mar 8, 2023
3 changes: 3 additions & 0 deletions .changes/unreleased/Added-20220321-162832.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Added
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a supported format? I feel like our process to roll up change logs might not like this. Based on the timestamp, it might be an older format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part might be from before some more recent changes to our changie logic so yeah can remove

body: Macro for custom warehouse selection
time: 2022-03-21T16:28:32.82239+01:00
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"
5 changes: 5 additions & 0 deletions 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 @@ -73,6 +76,8 @@ 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) # type: ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious if anyone has an idea as to why this causes a
dbt/adapters/snowflake/impl.py:80: error: Incompatible types in assignment (expression has type "AttrDict", variable has type "str") [assignment] error? seems same as all implementations in dbt-core I could find. just curious if there is better path than the ignore

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's silly, but you can remove the type annotation from warehouse and mypy will be happy; you can also update it to Any. The issue is that self.execute_macro() lists the type for kwargs as Dict[str, Any]. mypy doesn't like it when you make the type more strict (str is a proper subset of Any).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh that's interesting iI didn't think the type value for the "warehouse" input would bother the previously defined one for execute_macro thank you for clearing that up @mikealfare

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 %}