MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / visit_compound_select

Method visit_compound_select

lib/sqlalchemy/sql/compiler.py:3170–3235  ·  view source on GitHub ↗
(
        self, cs, asfrom=False, compound_index=None, **kwargs
    )

Source from the content-addressed store, hash-verified

3168 return func.clause_expr._compiler_dispatch(self, **kwargs)
3169
3170 def visit_compound_select(
3171 self, cs, asfrom=False, compound_index=None, **kwargs
3172 ):
3173 if self._collect_params:
3174 self._add_to_params(cs)
3175 toplevel = not self.stack
3176
3177 compile_state = cs._compile_state_factory(cs, self, **kwargs)
3178
3179 if toplevel and not self.compile_state:
3180 self.compile_state = compile_state
3181
3182 compound_stmt = compile_state.statement
3183
3184 entry = self._default_stack_entry if toplevel else self.stack[-1]
3185 need_result_map = toplevel or (
3186 not compound_index
3187 and entry.get("need_result_map_for_compound", False)
3188 )
3189
3190 # indicates there is already a CompoundSelect in play
3191 if compound_index == 0:
3192 entry["select_0"] = cs
3193
3194 self.stack.append(
3195 {
3196 "correlate_froms": entry["correlate_froms"],
3197 "asfrom_froms": entry["asfrom_froms"],
3198 "selectable": cs,
3199 "compile_state": compile_state,
3200 "need_result_map_for_compound": need_result_map,
3201 }
3202 )
3203
3204 if compound_stmt._independent_ctes:
3205 self._dispatch_independent_ctes(compound_stmt, kwargs)
3206
3207 keyword = self.compound_keywords[cs.keyword]
3208
3209 text = (" " + keyword + " ").join(
3210 (
3211 c._compiler_dispatch(
3212 self, asfrom=asfrom, compound_index=i, **kwargs
3213 )
3214 for i, c in enumerate(cs.selects)
3215 )
3216 )
3217
3218 kwargs["include_table"] = False
3219 text += self.group_by_clause(cs, **dict(asfrom=asfrom, **kwargs))
3220 text += self.order_by_clause(cs, **kwargs)
3221 if cs._has_row_limiting_clause:
3222 text += self._row_limit_clause(cs, **kwargs)
3223
3224 if self.ctes:
3225 nesting_level = len(self.stack) if not toplevel else None
3226 text = (
3227 self._render_cte_clause(

Callers

nothing calls this directly

Calls 11

_add_to_paramsMethod · 0.95
group_by_clauseMethod · 0.95
order_by_clauseMethod · 0.95
_row_limit_clauseMethod · 0.95
_render_cte_clauseMethod · 0.95
getMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45
_compiler_dispatchMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected