mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
fix(db_engine_specs): generate correct boolean filter SQL syntax for Athena compatibility (#34598)
This commit is contained in:
@@ -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}",
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user