pandvan commented on PR #36777:
URL: https://github.com/apache/superset/pull/36777#issuecomment-4834395298

   I've tried to backport this PR into 6.1.0 branch because I'm stuck with 
6.0.0 due to this issue.
   PR does not seems to work properly. Found a remaining issue in the 
implementation
   
   ```
   [DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES] Cannot resolve "(col = 1)" due to 
data type mismatch:
   the left and right operands of the binary operator have incompatible types 
("BOOLEAN" and "INT")
   ```
   
   **Root cause:** `handle_boolean_in_clause` returns `or_(*(sqla_col == val 
for val in boolean_values))` where `val` is a Python `bool`. The 
Hive/Databricks SQLAlchemy dialect processes Python `True`/`False` as bind 
parameters and converts them to integers (`1`/`0`) — so the generated SQL is 
still `col = 1`, not `col = TRUE`.
   
   **Proposed Fix:** Use SQLAlchemy's `true()`/`false()` clause elements, which 
emit `TRUE`/`FALSE` as SQL keywords and bypass the bind parameter type 
processor entirely:
   
   ```python
   from sqlalchemy import false, or_, true
   
   sa_literals = {True: true(), False: false()}
   return or_(*(sqla_col == sa_literals[val] for val in boolean_values))
   ```
   
   **Also:** the EQUALS operator (non-IN filters) has the same problem — 
`handle_comparison_filter` in the base class does `sqla_col == value` with a 
Python bool. A `handle_comparison_filter` override should also needed in 
`DatabricksNativeEngineSpec`:
   
   ```python
   @classmethod
   def handle_comparison_filter(cls, sqla_col, op, value):
       if isinstance(value, bool):
           sa_val = true() if value else false()
           if op == FilterOperator.EQUALS:
               return sqla_col == sa_val
           if op == FilterOperator.NOT_EQUALS:
               return sqla_col != sa_val
       return super().handle_comparison_filter(sqla_col, op, value)
   ```


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