I’m pretty new to dbt Cloud. Here’s what I’m trying to do:
I’ve got stage files that import every field from my source (snowflake, if it matters). I’m going to go through these staging files and do some field selection and I’d like to have an explicit naming convention
So I’m going to end up doing something like this like 60 times.
field1 as mytable_field1,
field2 as mytable_field2,
field3 as mytable_field3,
field5 as mytable_field5
What I’m looking for:
- I’d like to find some automation that would allow me to loop through each column in the stage file and rename each field procedurally.
- Ideally I could come up with a pattern that would let me select specific fields to include up front. This would be a bonus and would ultimately save me a ton of time.
For 1, I found some code on stack overflow that uses this dbt_utils.star function that les you loop through like ‘for each col in dbt_utils.star(mymodel)’ but the trouble seems to be that when you iterate through the the columns the “as name” piece seems to be included in the output which does not give me the opportunity to rename.
So in psuedo code I expect the solution looks like this:
fieldlist = (‘field1’,‘field2’,‘field3’,‘field5’)
for col in somefunction(mymodel)
if col in fieldlist
col as mytable_col,
This seems like something that should be achievable but I think I’m just too green to know how to approach this competently.