codeant-ai-for-open-source[bot] commented on code in PR #36777:
URL: https://github.com/apache/superset/pull/36777#discussion_r3488410256


##########
superset/db_engine_specs/databricks.py:
##########
@@ -252,6 +252,51 @@ def convert_dttm(
     def epoch_to_dttm(cls) -> str:
         return HiveEngineSpec.epoch_to_dttm()
 
+    @classmethod
+    def handle_boolean_in_clause(cls, sqla_col: Any, values: list[Any]) -> Any:
+        """
+        Build an IN-style predicate for a boolean column using boolean 
literals.
+
+        Databricks requires boolean literals (``TRUE``/``FALSE``) rather than
+        integer literals (``0``/``1``) when comparing against a boolean column,
+        so the IN clause is expanded into OR'd equality checks against real
+        booleans.
+
+        :param sqla_col: SQLAlchemy column element
+        :param values: List of values for the IN clause
+        :return: SQLAlchemy expression, or a constant ``FALSE`` when none of 
the
+            values map to a boolean
+        """
+        boolean_values: list[bool] = []
+        for val in values:
+            coerced: bool | None
+            if val is None:
+                continue
+            if isinstance(val, bool):
+                coerced = val
+            elif isinstance(val, (int, float)):
+                coerced = bool(val)
+            elif isinstance(val, str):
+                lowered = val.strip().lower()
+                if lowered in ("true", "1"):
+                    coerced = True
+                elif lowered in ("false", "0"):
+                    coerced = False
+                else:
+                    # Unrecognized strings don't map to a boolean, so skip them
+                    coerced = None
+            else:
+                coerced = bool(val)
+            # Deduplicate while preserving order to avoid redundant OR terms
+            if coerced is not None and coerced not in boolean_values:
+                boolean_values.append(coerced)
+
+        if not boolean_values:
+            # Nothing usable (e.g. only None or unrecognized values); match 
nothing
+            return false()
+
+        return or_(*(sqla_col == val for val in boolean_values))

Review Comment:
   **Suggestion:** Avoid building equality predicates that can become 
comparisons to false; construct the boolean predicate so false values use 
negation instead of equality. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The helper expands boolean IN predicates into equality comparisons against 
boolean literals. When `boolean_values` contains `False`, this produces 
`sqla_col == False` in a query/filter expression, which matches the custom rule 
violation. Using negation for the false case would avoid that pattern.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=98500717b79c49f6b29c590949a9424f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=98500717b79c49f6b29c590949a9424f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/db_engine_specs/databricks.py
   **Line:** 298:298
   **Comment:**
        *Custom Rule: Avoid building equality predicates that can become 
comparisons to false; construct the boolean predicate so false values use 
negation instead of equality.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F36777&comment_hash=4efa26df245e1d5e557998677aba7cba2f6731f4b5c25e929f811326052b079e&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F36777&comment_hash=4efa26df245e1d5e557998677aba7cba2f6731f4b5c25e929f811326052b079e&reaction=dislike'>👎</a>



##########
tests/integration_tests/db_engine_specs/databricks_tests.py:
##########
@@ -59,3 +61,56 @@ def test_extras_with_ssl_custom(self):
         extras = DatabricksNativeEngineSpec.get_extra_params(database)
         connect_args = extras["engine_params"]["connect_args"]
         assert connect_args["ssl"] == "1"
+
+    def test_handle_boolean_in_clause(self):
+        """
+        Boolean IN clauses should expand to equality checks against boolean
+        literals (Databricks rejects integer literals like 0/1 here), with
+        coerced values de-duplicated and no usable value yielding a constant
+        FALSE.
+        """
+
+        def compiled(expr):

Review Comment:
   **Suggestion:** Add parameter and return type annotations to this newly 
added helper function. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This nested helper function was newly added and has neither a parameter type 
annotation nor a return type annotation. That matches the custom rule violation 
for new Python code lacking full type hints.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a1f4d48c55ad4a69a29ad2bf60ad5543&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a1f4d48c55ad4a69a29ad2bf60ad5543&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/integration_tests/db_engine_specs/databricks_tests.py
   **Line:** 73:73
   **Comment:**
        *Custom Rule: Add parameter and return type annotations to this newly 
added helper function.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F36777&comment_hash=2458728ce8fb6335fe9789054e6a408349551d8412f9302d0d66b2faa06855f0&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F36777&comment_hash=2458728ce8fb6335fe9789054e6a408349551d8412f9302d0d66b2faa06855f0&reaction=dislike'>👎</a>



##########
tests/integration_tests/db_engine_specs/databricks_tests.py:
##########
@@ -59,3 +61,56 @@ def test_extras_with_ssl_custom(self):
         extras = DatabricksNativeEngineSpec.get_extra_params(database)
         connect_args = extras["engine_params"]["connect_args"]
         assert connect_args["ssl"] == "1"
+
+    def test_handle_boolean_in_clause(self):

Review Comment:
   **Suggestion:** Add full type hints to this newly added test method, 
including an explicit return type annotation. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This is a newly added test method in changed Python code and it omits a 
return type annotation. The custom rule requires new Python functions and 
methods to be fully typed, so the violation is real.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=664f94d91316420cb45006f274dce105&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=664f94d91316420cb45006f274dce105&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/integration_tests/db_engine_specs/databricks_tests.py
   **Line:** 65:65
   **Comment:**
        *Custom Rule: Add full type hints to this newly added test method, 
including an explicit return type annotation.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F36777&comment_hash=001af22611cc63540acba3cd10c1498605af0278bfbc61c92c617eb985864308&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F36777&comment_hash=001af22611cc63540acba3cd10c1498605af0278bfbc61c92c617eb985864308&reaction=dislike'>👎</a>



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