Skip to content

Add support for various DBT macros#519

Merged
izeigerman merged 1 commit intomainfrom
various-dbt-macros
Mar 13, 2023
Merged

Add support for various DBT macros#519
izeigerman merged 1 commit intomainfrom
various-dbt-macros

Conversation

@izeigerman
Copy link
Contributor

This PR adds support for the following DBT macros and filters:

  • adapter.create_schema
  • adapter.drop_schema
  • adapter.drop_relation
  • as_bool
  • as_native
  • as_number
  • as_text
  • builtins
  • fromjson
  • fromyaml
  • set
  • set_strict
  • tojson
  • toyaml
  • zip
  • zip_strict

@izeigerman izeigerman requested review from a team, crericha, eakmanrq and georgesittas March 10, 2023 21:46
@izeigerman izeigerman merged commit 937b0b5 into main Mar 13, 2023
@izeigerman izeigerman deleted the various-dbt-macros branch March 13, 2023 17:42
builtins.update(jinja_globals)
builtin_globals.update(
{
**jinja_globals,
Copy link
Contributor

Choose a reason for hiding this comment

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

why are jinja_globals added to builtin and also returned return {**builtin_globals, **jinja_globals}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So that values in jinja_globals take precedence over the values that end up in the final builtin_globals.

Copy link
Contributor

@crericha crericha Mar 13, 2023

Choose a reason for hiding this comment

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

What I don't understand is if the methods are in builtin_globals, why do they need to be returned again?

  1. builtin_globals.update( { **jinja_globals,...} ) #builtin_globals now contains all jinja_globals
  2. return {**builtin_globals, **jinja_globals} # isn't this redundant since builtin_globals contains all jinja_globals?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because var, ref, etc. are set after the builtin_globals.update( { **jinja_globals,...} ) and we want those keys from jinja_globals to take precedence. This is essentially a safe way to avoid doing if "<key>" not in jinja_globals:

self._jinja_globals = create_builtins(
self._jinja_globals = create_builtin_globals(
jinja_macros=context.jinja_macros,
jinja_globals={
Copy link
Contributor

Choose a reason for hiding this comment

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

is overrides a better term for this behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, since this dict contains all globals and not just the ones that will be overridden.

Copy link
Contributor

@crericha crericha Mar 13, 2023

Choose a reason for hiding this comment

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

Can we either change the name of the kwarg to express how it behaves or add a method comment block that does so?

Copy link
Contributor Author

@izeigerman izeigerman Mar 13, 2023

Choose a reason for hiding this comment

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

The name of the kwargs is still accurate due to the discussion in the other thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants