rusackas commented on code in PR #45771:
URL: https://github.com/apache/superset/pull/45771#discussion_r4386197830


##########
superset/sql/parse.py:
##########
@@ -1139,6 +1139,22 @@ def _deduplicate_oracle_output_names(query: 
exp.Expression) -> None:
             projection.replace(exp.alias_(projection.copy(), alias))
 
 
+def _flatten_and(condition: exp.Expression) -> list[exp.Expression]:
+    """
+    Return the leaves of a chain of `AND`s, looking through parentheses.
+
+    `exp.And.flatten()` only unwraps a left- or right-leaning chain of plain
+    `AND`s; a nested `AND` grouped in parentheses, as in `x AND (y AND z)`,
+    comes back as a single `And` leaf rather than its own `y` and `z` leaves.
+    This recurses instead, so a condition `AND`-ed together with others stays
+    found regardless of how it is grouped.
+    """
+    condition = condition.unnest()
+    if not isinstance(condition, exp.And):
+        return [condition]
+    return _flatten_and(condition.this) + _flatten_and(condition.expression)

Review Comment:
   Good catch. `_flatten_and` now walks an explicit stack instead of recursing, 
so chain length no longer affects recursion depth.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to