MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / visit_function

Method visit_function

lib/sqlalchemy/sql/compiler.py:3108–3156  ·  view source on GitHub ↗
(
        self,
        func: Function[Any],
        add_to_result_map: Optional[_ResultMapAppender] = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

3106 return "(%s).%s" % (compiled_fn, compiled_col)
3107
3108 def visit_function(
3109 self,
3110 func: Function[Any],
3111 add_to_result_map: Optional[_ResultMapAppender] = None,
3112 **kwargs: Any,
3113 ) -> str:
3114 if self._collect_params:
3115 self._add_to_params(func)
3116 if add_to_result_map is not None:
3117 add_to_result_map(func.name, func.name, (func.name,), func.type)
3118
3119 disp = getattr(self, "visit_%s_func" % func.name.lower(), None)
3120
3121 text: str
3122
3123 kwargs["within_aggregate_function"] = True
3124
3125 if disp:
3126 text = disp(func, **kwargs)
3127 else:
3128 name = FUNCTIONS.get(func._deannotate().__class__, None)
3129 if name:
3130 if func._has_args:
3131 name += "%(expr)s"
3132 else:
3133 name = func.name
3134 name = (
3135 self.preparer.quote(name)
3136 if self.preparer._requires_quotes_illegal_chars(name)
3137 or isinstance(name, elements.quoted_name)
3138 else name
3139 )
3140 name = name + "%(expr)s"
3141 text = ".".join(
3142 [
3143 (
3144 self.preparer.quote(tok)
3145 if self.preparer._requires_quotes_illegal_chars(tok)
3146 or isinstance(name, elements.quoted_name)
3147 else tok
3148 )
3149 for tok in func.packagenames
3150 ]
3151 + [name]
3152 ) % {"expr": self.function_argspec(func, **kwargs)}
3153
3154 if func._with_ordinality:
3155 text += " WITH ORDINALITY"
3156 return text
3157
3158 def visit_next_value_func(self, next_value, **kw):
3159 return self.visit_sequence(next_value.sequence)

Callers 2

default_greatestMethod · 0.45

Calls 8

_add_to_paramsMethod · 0.95
function_argspecMethod · 0.95
lowerMethod · 0.80
getMethod · 0.45
_deannotateMethod · 0.45
quoteMethod · 0.45
joinMethod · 0.45

Tested by 1

default_greatestMethod · 0.36