@@ -128,6 +128,23 @@ def _macro_str_replace(text: str) -> str:
128128 return f"self.template({ text } , locals())"
129129
130130
131+ class CaseInsensitiveMapping (dict ):
132+ def __init__ (self , data : t .Dict [str , t .Any ]) -> None :
133+ super ().__init__ (data )
134+
135+ self ._lower = {k .lower (): v for k , v in data .items ()}
136+
137+ def __getitem__ (self , key : str ) -> t .Any :
138+ if key in self :
139+ return super ().__getitem__ (key )
140+ return self ._lower [key .lower ()]
141+
142+ def get (self , key : str , default : t .Any = None ) -> t .Any :
143+ if key in self :
144+ return super ().get (key , default )
145+ return self ._lower .get (key .lower (), default )
146+
147+
131148class MacroDialect (Python ):
132149 class Generator (Python .Generator ):
133150 TRANSFORMS = {
@@ -313,11 +330,11 @@ def template(self, text: t.Any, local_variables: t.Dict[str, t.Any]) -> str:
313330 """
314331 # We try to convert all variables into sqlglot expressions because they're going to be converted
315332 # into strings; in sql we don't convert strings because that would result in adding quotes
316- mapping = {
333+ base_mapping = {
317334 k : convert_sql (v , self .dialect )
318335 for k , v in chain (self .variables .items (), self .locals .items (), local_variables .items ())
319336 }
320- return MacroStrTemplate (str (text )).safe_substitute (mapping )
337+ return MacroStrTemplate (str (text )).safe_substitute (CaseInsensitiveMapping ( base_mapping ) )
321338
322339 def evaluate (self , node : MacroFunc ) -> exp .Expression | t .List [exp .Expression ] | None :
323340 if isinstance (node , MacroDef ):
0 commit comments