summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-04-12 13:52:31 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-04-13 17:19:31 -0400
commit428262a2d5374613f4a4cf925bbd9e94e0e34acc (patch)
tree9f71ec4a09d3ea584b3e399085254fb278049a6f /lib/sqlalchemy/sql/compiler.py
parenta45e2284dad17fbbba3bea9d5e5304aab21c8c94 (diff)
downloadsqlalchemy-428262a2d5374613f4a4cf925bbd9e94e0e34acc.tar.gz
implement multi-element expression constructs
Improved the construction of SQL binary expressions to allow for very long expressions against the same associative operator without special steps needed in order to avoid high memory use and excess recursion depth. A particular binary operation ``A op B`` can now be joined against another element ``op C`` and the resulting structure will be "flattened" so that the representation as well as SQL compilation does not require recursion. To implement this more cleanly, the biggest change here is that column-oriented lists of things are broken away from ClauseList in a new class ExpressionClauseList, that also forms the basis of BooleanClauseList. ClauseList is still used for the generic "comma-separated list" of things such as Tuple and things like ORDER BY, as well as in some API endpoints. Also adds __slots__ to the TypeEngine-bound Comparator classes. Still can't really do __slots__ on ClauseElement. Fixes: #7744 Change-Id: I81a8ceb6f8f3bb0fe52d58f3cb42e4b6c2bc9018
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 522a0bd4a..9c074db33 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -2013,6 +2013,24 @@ class SQLCompiler(Compiled):
return self._generate_delimited_list(clauselist.clauses, sep, **kw)
+ def visit_expression_clauselist(self, clauselist, **kw):
+ operator_ = clauselist.operator
+
+ disp = self._get_operator_dispatch(
+ operator_, "expression_clauselist", None
+ )
+ if disp:
+ return disp(clauselist, operator_, **kw)
+
+ try:
+ opstring = OPERATORS[operator_]
+ except KeyError as err:
+ raise exc.UnsupportedCompilationError(self, operator_) from err
+ else:
+ return self._generate_delimited_list(
+ clauselist.clauses, opstring, **kw
+ )
+
def visit_case(self, clause, **kwargs):
x = "CASE "
if clause.value is not None: