fix(db_engine_specs): generate correct boolean filter SQL syntax for Athena compatibility (#34598)

This commit is contained in:
Oliver Schlüter
2025-08-07 17:39:31 +02:00
committed by GitHub
parent 1e1310dbd8
commit f3e3bd0348
2 changed files with 35 additions and 0 deletions

View File

@@ -36,6 +36,8 @@ class AthenaEngineSpec(BaseEngineSpec):
engine_name = "Amazon Athena"
allows_escaped_colons = False
disable_ssh_tunneling = True
# Athena doesn't support IS true/false syntax, use = true/false instead
use_equality_for_boolean_filters = True
_time_grain_expressions = {
None: "{col}",

View File

@@ -87,3 +87,36 @@ def test_get_text_clause_with_colon() -> None:
)
text_clause = AthenaEngineSpec.get_text_clause(query)
assert text_clause.text == query
def test_handle_boolean_filter() -> None:
"""
Test that Athena uses equality operators for boolean filters instead of IS.
"""
from sqlalchemy import Boolean, Column
from superset.db_engine_specs.athena import AthenaEngineSpec
# Create a mock SQLAlchemy column
bool_col = Column("test_col", Boolean)
# Test IS_TRUE filter - use actual FilterOperator values
from superset.utils.core import FilterOperator
result_true = AthenaEngineSpec.handle_boolean_filter(
bool_col, FilterOperator.IS_TRUE, True
)
# The result should be a equality comparison, not an IS comparison
assert (
str(result_true.compile(compile_kwargs={"literal_binds": True}))
== "test_col = true"
)
# Test IS_FALSE filter
result_false = AthenaEngineSpec.handle_boolean_filter(
bool_col, FilterOperator.IS_FALSE, False
)
assert (
str(result_false.compile(compile_kwargs={"literal_binds": True}))
== "test_col = false"
)