Skip to content

fix(trino/presto): use equality for boolean filters to support computed columns#39500

Merged
rusackas merged 2 commits into
apache:masterfrom
mistercrunch:fix-boolean-filter-trino-presto
May 8, 2026
Merged

fix(trino/presto): use equality for boolean filters to support computed columns#39500
rusackas merged 2 commits into
apache:masterfrom
mistercrunch:fix-boolean-filter-trino-presto

Conversation

@mistercrunch
Copy link
Copy Markdown
Member

SUMMARY

Selecting IS TRUE (or IS FALSE) on a boolean chart filter raised an error on Trino/Presto when the column was derived from a cast such as (expiration = 1) AS expiration. The backend generated col IS true, which Trino/Presto reject on these computed boolean expressions.

This PR sets use_equality_for_boolean_filters = True on PrestoBaseEngineSpec, so both TrinoEngineSpec and PrestoEngineSpec emit col = true / col = false instead. This matches the existing Athena behavior introduced in #34598 (Athena is Presto-based and hit the same issue).

Fixes internal ticket sc-97540.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — purely a SQL generation fix.

Before: SELECT ... WHERE expiration IS true → query error on Trino/Presto.
After: SELECT ... WHERE expiration = true → succeeds.

TESTING INSTRUCTIONS

  1. Connect Superset to a Trino or Presto database.
  2. Create a dataset with a computed boolean column, e.g. a virtual dataset selecting (expiration = 1) AS expiration.
  3. Build a chart against that dataset and add a filter on the expiration column with operator IS TRUE (or IS FALSE).
  4. Click Update Chart — the query should run successfully and the generated SQL in the query history should use expiration = true instead of expiration IS true.

Unit tests added:

  • tests/unit_tests/db_engine_specs/test_trino.py::test_handle_boolean_filter
  • tests/unit_tests/db_engine_specs/test_presto.py::test_handle_boolean_filter

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

…ed columns

Selecting IS TRUE / IS FALSE on a boolean chart filter raised an error on
Trino/Presto when the column was derived from a cast like
`(expiration = 1) AS expiration`. Switch these engines to generate
`col = true`/`col = false` instead of `col IS true`/`col IS false`, matching
the existing Athena behavior. The flag is set on PrestoBaseEngineSpec so
both TrinoEngineSpec and PrestoEngineSpec inherit the fix.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.44%. Comparing base (151d7d7) to head (8bf2c4b).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #39500   +/-   ##
=======================================
  Coverage   64.44%   64.44%           
=======================================
  Files        2560     2560           
  Lines      133574   133575    +1     
  Branches    31017    31017           
=======================================
+ Hits        86082    86083    +1     
  Misses      45999    45999           
  Partials     1493     1493           
Flag Coverage Δ
hive 39.76% <100.00%> (+<0.01%) ⬆️
mysql 60.27% <100.00%> (+<0.01%) ⬆️
postgres 60.35% <100.00%> (+<0.01%) ⬆️
presto 41.53% <100.00%> (+<0.01%) ⬆️
python 61.92% <100.00%> (+<0.01%) ⬆️
sqlite 59.98% <100.00%> (+<0.01%) ⬆️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The original bug (sc-97540) was specifically about computed boolean
expressions like `(expiration = 1) AS expiration`, not plain boolean
columns. Add a case using `literal_column` to pin that scenario.
@mistercrunch mistercrunch marked this pull request as ready for review April 21, 2026 04:57
@dosubot dosubot Bot added data:connect:presto Related to Presto data:connect:trino Related to Trino labels Apr 21, 2026
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Apr 21, 2026

Code Review Agent Run #e1dd96

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: 025b7bd..8bf2c4b
    • superset/db_engine_specs/presto.py
    • tests/unit_tests/db_engine_specs/test_presto.py
    • tests/unit_tests/db_engine_specs/test_trino.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Copy link
Copy Markdown
Contributor

@aminghadersohi aminghadersohi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Straightforward fix — sets use_equality_for_boolean_filters = True on PrestoBaseEngineSpec, which covers both Presto and Trino. Matches the existing pattern in Athena (#34598) and Snowflake. Tests cover IS_TRUE, IS_FALSE, and the computed-column regression case.

@rusackas rusackas merged commit d023fe1 into apache:master May 8, 2026
120 of 121 checks passed
qfcwell pushed a commit to qfcwell/superset that referenced this pull request May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data:connect:presto Related to Presto data:connect:trino Related to Trino size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants