holdenk commented on code in PR #59216:
URL: https://github.com/apache/spark/pull/59216#discussion_r4585180888


##########
python/pyspark/sql/transpile.py:
##########
@@ -828,60 +1105,45 @@ def _convert_chunk(self, params: List[str], body: 
ast.AST | None) -> Column:
                     orelse[0] if orelse else None,
                 )
             case ast.Compare(left, ops, comps):
-                if len(ops) != 1 or len(comps) != 1:
+                # `in` / `not in` are container membership, not a chainable 
value
+                # comparison, and need their own NULL analysis: Python's `in`

Review Comment:
   Fixed in a3787b8f621. Confirmed with `ast.parse`: `a < b in (1, 2)` is one 
`Compare` with ops `[Lt, In]`. The comment now says `in` / `not in` are 
membership rather than value comparisons, though one can be a link of a chain, 
which matches the refusal scanning every operator.
   
   ---
   <sub>🤖 Posted by an AI agent (Claude Code · skill `none`) on behalf of 
@holdenk.</sub>
   <!-- agent-attribution v1: agent=claude-code; skill=none; operator=holdenk 
-->



##########
python/pyspark/sql/transpile.py:
##########
@@ -692,11 +975,19 @@ def branch_category(b: ast.AST) -> Optional[str]:
                         "ternary with all-None branches has no usable column 
category"
                     )
                 return result_cat
+            case ast.Compare():
+                # Checked by node kind, not through `_is_definitely_boolean`: 
that
+                # also demands basic-type operands, so it misses `(a < b) == 
True`,
+                # which then reached the numeric catch-all below and let a 
boolean
+                # body satisfy a numeric declared return type -- emitting
+                # `cast(<boolean> as bigint)` where the interpreted path 
returns
+                # NULL. EVERY Python comparison evaluates to a bool.
+                return "bool"
             case _ if _is_definitely_boolean(node):
-                # Comparisons, `not`, and boolean ops produce a boolean column.
-                # Labeling them "numeric" (the old catch-all) let booleans into
+                # `not` and boolean ops produce a boolean column. Labeling them
+                # "numeric" (the old catch-all) let booleans into
                 # arithmetic/equality lowerings where ANSI analysis fails (e.g.
-                # `(x > 0) + 1`, valid Python) instead of falling back.
+                # `(not x) + 1`, valid Python) instead of falling back.

Review Comment:
   Fixed in a3787b8f621. Confirmed by running the transpiler: `(not x) + 1` is 
refused by the `not` arm ("operand type is not statically known to be 
boolean"), while `(not (x > 0)) + 1` gets past it and fails the `Add` type 
check. The comment's example is now `(not (x > 0)) + 1`.
   
   ---
   <sub>🤖 Posted by an AI agent (Claude Code · skill `none`) on behalf of 
@holdenk.</sub>
   <!-- agent-attribution v1: agent=claude-code; skill=none; operator=holdenk 
-->



-- 
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