@@ -41,7 +41,7 @@ def make_python_env(
4141 module_path : Path ,
4242 macros : MacroRegistry ,
4343 variables : t .Optional [t .Dict [str , t .Any ]] = None ,
44- used_variables : t .Optional [t .Set [str ]] = None ,
44+ referenced_variables : t .Optional [t .Set [str ]] = None ,
4545 path : t .Optional [Path ] = None ,
4646 python_env : t .Optional [t .Dict [str , Executable ]] = None ,
4747 strict_resolution : bool = True ,
@@ -55,7 +55,7 @@ def make_python_env(
5555 blueprint_variables = blueprint_variables or {}
5656
5757 used_macros : t .Dict [str , t .Tuple [MacroCallable , bool ]] = {}
58- used_variable_referenced_in_metadata_expression = dict .fromkeys (used_variables or set (), False )
58+ used_variables = dict .fromkeys (referenced_variables or set (), False ) # var -> is_metadata
5959
6060 # For an expression like @foo(@v1, @bar(@v1, @v2), @v3), the following mapping would be:
6161 # v1 -> {"foo", "bar"}, v2 -> {"bar"}, v3 -> "foo"
@@ -96,10 +96,7 @@ def make_python_env(
9696 )
9797
9898 var_name = args [0 ].this .lower ()
99- used_variable_referenced_in_metadata_expression [var_name ] = (
100- used_variable_referenced_in_metadata_expression .get (var_name , True )
101- and is_metadata
102- )
99+ used_variables [var_name ] = used_variables .get (var_name , True ) and is_metadata
103100 else :
104101 for var_ref in _extract_macro_func_variable_references (macro_func_or_var ):
105102 macro_funcs_by_used_var [var_ref ].add (name )
@@ -112,10 +109,7 @@ def make_python_env(
112109 used_macros .get (name , (None , is_metadata ))[1 ] and is_metadata ,
113110 )
114111 elif name in variables or name in blueprint_variables :
115- used_variable_referenced_in_metadata_expression [name ] = (
116- used_variable_referenced_in_metadata_expression .get (name , True )
117- and is_metadata
118- )
112+ used_variables [name ] = used_variables .get (name , True ) and is_metadata
119113 elif (
120114 isinstance (macro_func_or_var , (exp .Identifier , d .MacroStrReplace , d .MacroSQL ))
121115 ) and "@" in macro_func_or_var .name :
@@ -124,9 +118,8 @@ def make_python_env(
124118 ):
125119 var_name = braced_identifier or identifier
126120 if var_name in variables or var_name in blueprint_variables :
127- used_variable_referenced_in_metadata_expression [var_name ] = (
128- used_variable_referenced_in_metadata_expression .get (var_name , True )
129- and is_metadata
121+ used_variables [var_name ] = (
122+ used_variables .get (var_name , True ) and is_metadata
130123 )
131124
132125 for macro_ref in jinja_macro_references or set ():
@@ -148,7 +141,7 @@ def make_python_env(
148141 python_env .update (serialize_env (env , path = module_path ))
149142 return _add_variables_to_python_env (
150143 python_env ,
151- used_variable_referenced_in_metadata_expression ,
144+ used_variables ,
152145 variables ,
153146 blueprint_variables = blueprint_variables ,
154147 dialect = dialect ,
@@ -189,37 +182,34 @@ def _prune_nested_macro_func(expression: exp.Expression) -> bool:
189182
190183def _add_variables_to_python_env (
191184 python_env : t .Dict [str , Executable ],
192- used_variable_referenced_in_metadata_expression : t .Dict [str , bool ],
185+ used_variables : t .Dict [str , bool ],
193186 variables : t .Optional [t .Dict [str , t .Any ]],
194187 strict_resolution : bool = True ,
195188 blueprint_variables : t .Optional [t .Dict [str , t .Any ]] = None ,
196189 dialect : DialectType = None ,
197190 macro_funcs_by_used_var : t .Optional [t .DefaultDict [str , t .Set [str ]]] = None ,
198191) -> t .Dict [str , Executable ]:
199- _ , python_used_variable_referenced_in_metadata_expression = parse_dependencies (
192+ _ , python_used_variables = parse_dependencies (
200193 python_env ,
201194 None ,
202195 strict_resolution = strict_resolution ,
203196 variables = variables ,
204197 blueprint_variables = blueprint_variables ,
205198 )
206- for var_name , is_metadata in python_used_variable_referenced_in_metadata_expression .items ():
207- used_variable_referenced_in_metadata_expression [var_name ] = (
208- used_variable_referenced_in_metadata_expression .get (var_name , True ) and is_metadata
209- )
199+ for var_name , is_metadata in python_used_variables .items ():
200+ used_variables [var_name ] = used_variables .get (var_name , True ) and is_metadata
210201
211202 # Variables are treated as metadata when:
212203 # - They are only referenced in metadata-only contexts, such as `audits (...)`, virtual statements, etc
213- # - They are only referenced in metadata-only macros, either as their arguments of within their definitions
204+ # - They are only referenced in metadata-only macros, either as their arguments or within their definitions
214205 metadata_used_variables = set ()
215206 for used_var , macro_names in (macro_funcs_by_used_var or {}).items ():
216- if used_variable_referenced_in_metadata_expression .get (used_var ) or all (
207+ if used_variables .get (used_var ) or all (
217208 name in python_env and python_env [name ].is_metadata for name in macro_names
218209 ):
219210 metadata_used_variables .add (used_var )
220211
221- used_variables = set (used_variable_referenced_in_metadata_expression )
222- non_metadata_used_variables = used_variables - metadata_used_variables
212+ non_metadata_used_variables = set (used_variables ) - metadata_used_variables
223213
224214 metadata_variables = {
225215 k : v for k , v in (variables or {}).items () if k in metadata_used_variables
@@ -295,7 +285,7 @@ def blueprint_var(var_name: str, default: t.Optional[t.Any] = None) -> t.Optiona
295285 local_env = dict .fromkeys (("context" , "evaluator" ), VariableResolutionContext )
296286
297287 depends_on = set ()
298- used_variable_referenced_in_metadata_expression : t .Dict [str , bool ] = {}
288+ used_variables : t .Dict [str , bool ] = {}
299289
300290 for executable in python_env .values ():
301291 if not executable .is_definition :
@@ -358,12 +348,9 @@ def get_first_arg(keyword_arg_name: str) -> t.Any:
358348 )
359349
360350 for var_name in next_variables :
361- used_variable_referenced_in_metadata_expression [var_name ] = (
362- used_variable_referenced_in_metadata_expression .get (var_name , True )
363- and bool (is_metadata )
364- )
351+ used_variables [var_name ] = used_variables .get (var_name , True ) and bool (is_metadata )
365352
366- return depends_on , used_variable_referenced_in_metadata_expression
353+ return depends_on , used_variables
367354
368355
369356def validate_extra_and_required_fields (
0 commit comments