bito-code-review[bot] commented on code in PR #44355:
URL: https://github.com/apache/superset/pull/44355#discussion_r4188068163
##########
superset/db_engine_specs/databricks.py:
##########
@@ -251,13 +251,36 @@ class DatabricksPythonConnectorPropertiesType(TypedDict):
class DatabricksBaseEngineSpec(BaseEngineSpec):
+ """Base engine specification for Databricks flavors and connection
methods."""
+
_time_grain_expressions = time_grain_expressions
# Databricks SQL is Spark SQL under the hood: identifiers are quoted with
# backticks, not the inherited ANSI double quotes.
identifier_quote_start: str = "`"
identifier_quote_end: str = "`"
+ # Databricks SQL applies strict type checking: comparing a boolean column
+ # against an integer literal (or a bound Python boolean that the
+ # Hive/Databricks driver renders as 0/1) fails with
+ # DATATYPE_MISMATCH.DATA_DIFF_TYPES (see #36765). Enabling equality
+ # operators ensures boolean filters compile as 'col = true' / 'col =
false'.
+ use_equality_for_boolean_filters: bool = True
+
+ @classmethod
+ def coerce_boolean_for_sql(cls, value: bool | None) -> Any:
+ """
+ Render Python booleans as explicit boolean keywords.
+
+ The Hive/Databricks SQLAlchemy dialects render Python booleans as
+ integer literals (0/1) in some binding paths, so emit sqlalchemy
+ true()/false() instead: they always compile to the TRUE/FALSE keywords
+ and never reach the driver as bind parameters (#36765).
+ """
+ if value is None:
+ return None
+ return true() if value else false()
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Duplicated boolean coercion</b></div>
<div id="fix">
`coerce_boolean_for_sql` is byte-identical in `DatabricksBaseEngineSpec`
(271-282), `DatabricksHiveEngineSpec` (1213-1218) and `SparkEngineSpec`
(spark.py 60-66), each paired with `use_equality_for_boolean_filters=True`.
Since the latter two both extend `HiveEngineSpec`, hoist this into a shared
mixin/base so a future change to the coercion (e.g. a third keyword) can't
drift across copies.
</div>
</div>
<small><i>Code Review Run #11498e</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]