Is there a way to use python based hooks with dbt?
I'm using seed data to create dynamic models with jinja but am looking for a bit more python flexibility than with what's available with jinja natively. As a comparison, something along the lines of the way Django views can inject variables into templates.
I'm new to dbt and perhaps approaching this wrong. Thanks to anyone with help or advice.
Here's an example where I was looking to use python zip and ended up using similar sql logic. I have a similar need to use python's enumerate. Should I just use sql over python for these types of scenario? I suppose most if not all of this can be achieved with sql (i just happen to be more familiar with python than sql when it comes to this type manipulation).
Current working example using sql:
{% set mappings = dbt_utils.get_query_results_as_dict("select
CONCAT(my_field, ' AS ', my_alias) AS my_pairs FROM " ~
ref('data_seed_schema1_to_schema2') ) %}
SELECT
{% for map in mappings %}
{{',\n\t\t'.join(mappings[map]) }}
{% endfor %}
FROM my_table
-->
SELECT
fooA AS barA,
fooB AS barb
FROM my_table
desired python example:
{% set mappings = dbt_utils.get_query_results_as_dict("select * FROM " ~
ref('data_seed_schema1_to_schema2') ) %}
# my_zip = [f"{x} AS {y} for x, y in zip(mappings['my_field'], mappings['my_alias'])]
SELECT
{% for x in my_zip%}
{{',\n\t\t'.join(x) }}
{% endfor %}
FROM my_table