Skip to content

fix(table-chart): support where for adhoc columns with server-side pagination - #42706

Merged
rusackas merged 1 commit into
apache:masterfrom
MallikarjunaReddyN:fix/filter-support-for-adhoc-column-table-chart
Aug 29, 2026
Merged

rusackas merged 1 commit into
apache:masterfrom
MallikarjunaReddyN:fix/filter-support-for-adhoc-column-table-chart

Conversation

@MallikarjunaReddyN

@MallikarjunaReddyN MallikarjunaReddyN commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

SUMMARY

This PR fixes an issue with server-side pagination in Table Charts where filtering on custom SQL expression (adhoc) columns was not applied correctly. When a filter targeted an adhoc column, the generated server-side query failed to include the corresponding SQL expression in the filtering logic, causing all records to be returned instead of only the matching rows.

The query generation has been updated to correctly resolve and apply adhoc column expressions during server-side filtering, ensuring consistent behavior between physical dataset columns and custom SQL expression columns.

Additionally, this PR fixes a pagination UI issue where the page size was incorrectly displayed as 0 when the total number of returned records was less than the configured Server Page Length. The page size is now calculated based on the actual number of records returned, providing accurate pagination information.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:

adhoc-column-filter-fix-before.mp4

After:

adhoc-column-filter-fix-after.mp4

Server Pagination page size fix(#42243):

server-pagination-page-size-fix.mp4

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

@dosubot dosubot Bot added explore:filter Related to filters in Explore viz:charts:table Related to the Table chart labels Aug 3, 2026
@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Review Failed - Technical Failure Bito encountered technical difficulties while starting a code review session. To retry, type /review in a comment and save. If the issue persists, contact [email protected].

@codecov

codecov Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.18%. Comparing base (e39bfb2) to head (180d51d).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
superset/models/helpers.py 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #42706      +/-   ##
==========================================
- Coverage   79.18%   79.18%   -0.01%     
==========================================
  Files        2879     2879              
  Lines      165858   165863       +5     
  Branches    38348    38350       +2     
==========================================
+ Hits       131341   131344       +3     
- Misses      32039    32040       +1     
- Partials     2478     2479       +1     
Flag Coverage Δ
hive 37.94% <0.00%> (-0.01%) ⬇️
javascript 74.63% <100.00%> (-0.01%) ⬇️
mysql 57.66% <0.00%> (-0.01%) ⬇️
postgres 57.70% <0.00%> (-0.01%) ⬇️
presto 39.85% <0.00%> (-0.01%) ⬇️
python 83.74% <75.00%> (-0.01%) ⬇️
sqlite 57.39% <0.00%> (-0.01%) ⬇️
unit 73.96% <75.00%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

Comment on lines +464 to +465
const getServerPagination = (n: number) =>
n <= Math.max(rowCount, serverPageLength);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: The page-size filter does not account for the currently selected serverPaginationData.pageSize. If a user selects a page size larger than both rowCount and the configured serverPageLength—for example, selects 20 when there are 15 rows and the configured length is 10—option 20 is removed from pageSizeOptions. DataTable then cannot find the active option and sets the displayed page size to 0. Include the active server page size in the upper bound so the current selection remains available. [incorrect condition logic]

Severity Level: Major ⚠️
- ⚠️ Table pagination displays zero after result counts shrink.
- ⚠️ Server search and dashboard filtering expose the stale-size state.
- ⚠️ Users cannot see the actual active rows-per-page value.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx
**Line:** 464:465
**Comment:**
	*Incorrect Condition Logic: The page-size filter does not account for the currently selected `serverPaginationData.pageSize`. If a user selects a page size larger than both `rowCount` and the configured `serverPageLength`—for example, selects 20 when there are 15 rows and the configured length is 10—option 20 is removed from `pageSizeOptions`. `DataTable` then cannot find the active option and sets the displayed page size to 0. Include the active server page size in the upper bound so the current selection remains available.

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

Comment on lines +4026 to +4029
sqla_col, _unused = self.adhoc_column_to_sqla(
col=adhoc_columns_by_label[flt_col],
template_processor=template_processor,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: The generic type returned by adhoc_column_to_sqla is discarded, and this call does not set force_type_check=True, so expressions that are not backed by metadata leave adhoc_generic_type unset. Numeric and temporal filter values therefore fall back to GenericDataType.STRING, causing values to be quoted or otherwise coerced incorrectly for comparisons and IN filters. Preserve the returned generic type and force the type probe for this label-based filter path. [type error]

Severity Level: Major ⚠️
- ❌ Numeric adhoc-column filters can compare against incorrectly typed bind values.
- ⚠️ `IN` filters may be quoted or rejected by the database.
- ⚠️ Table-chart server-side pagination can return incorrect filtered results.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/models/helpers.py
**Line:** 4026:4029
**Comment:**
	*Type Error: The generic type returned by `adhoc_column_to_sqla` is discarded, and this call does not set `force_type_check=True`, so expressions that are not backed by metadata leave `adhoc_generic_type` unset. Numeric and temporal filter values therefore fall back to `GenericDataType.STRING`, causing values to be quoted or otherwise coerced incorrectly for comparisons and `IN` filters. Preserve the returned generic type and force the type probe for this label-based filter path.

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

Comment on lines +4767 to +4783
def test_filter_adhoc_column(database: Database) -> None:
"""
Test that filter works with adhoc column labels.
When filter contains a string that matches the label of an adhoc column
in the columns list, it should correctly convert to a SQLAlchemy column
instead of raising QueryObjectValidationError.
"""
from superset.connectors.sqla.models import SqlaTable, TableColumn

table = SqlaTable(
table_name="test_table",
database=database,
columns=[
TableColumn(column_name="name", type="TEXT"),
TableColumn(column_name="real_name", type="TEXT"),
],
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: The regression test covers only a string-valued ILIKE filter whose expression is a direct physical column reference. It does not exercise the adhoc generic type returned by adhoc_column_to_sqla, so numeric or date expressions can still mis-coerce comparison and IN filter values while this test continues to pass. Add cases using numeric/date expressions and operators that verify the compiled predicates use the correct value types. [code quality]

Severity Level: Major ⚠️
- ❌ Numeric adhoc label filters may generate invalid predicates.
- ❌ Date adhoc label filters may return incorrect results.
- ⚠️ Existing test covers only text metadata resolution.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/models/helpers_test.py
**Line:** 4767:4783
**Comment:**
	*Code Quality: The regression test covers only a string-valued `ILIKE` filter whose expression is a direct physical column reference. It does not exercise the adhoc generic type returned by `adhoc_column_to_sqla`, so numeric or date expressions can still mis-coerce comparison and `IN` filter values while this test continues to pass. Add cases using numeric/date expressions and operators that verify the compiled predicates use the correct value types.

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

@rusackas
rusackas requested a review from villebro August 3, 2026 16:31
@MallikarjunaReddyN

Copy link
Copy Markdown
Contributor Author

@villebro @rusackas Could you please review this PR too.

@rusackas rusackas left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for pinging, and sorry for the delay. Confirmed the adhoc filter path was silently dropping the WHERE clause when col_obj stayed None, and the page-size fix checks out too. Worth assessing/applying the bot-suggested changes, but otherwis looks good, CI's green, let's get this merged.

@bito-code-review

bito-code-review Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #b90bb6

Actionable Suggestions - 0
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • tests/unit_tests/models/helpers_test.py - 1
Review Details
  • Files reviewed - 3 · Commit Range: a71a91a..d40b7b8
    • superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx
    • superset/models/helpers.py
    • tests/unit_tests/models/helpers_test.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

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

  • /review - Manually triggers an incremental AI Review.

  • /review full - 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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@rusackas

Copy link
Copy Markdown
Member

Well, CI was green. Seeing if I can get that green for real.

@rusackas
rusackas force-pushed the fix/filter-support-for-adhoc-column-table-chart branch from d40b7b8 to 180d51d Compare August 28, 2026 04:34
@bito-code-review

bito-code-review Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #474a76

Actionable Suggestions - 0
Additional Suggestions - 2
  • tests/unit_tests/models/helpers_test.py - 1
    • Weak assertion on filter resolution · Line 5016-5016
      Per BITO rule 6262, tests must verify the actual behavior. The current assertions only check that `result is not None` and that substrings appear in the SQL. Add a stronger assertion that the WHERE predicate binds to the resolved adhoc expression (e.g., assert `lower(real_name) LIKE` is the only WHERE filter, and that `full_name` does not appear in the WHERE clause).
  • superset/models/helpers.py - 1
    • Dead isinstance guard on ColumnElement · Line 4784-4784
      `adhoc_column_to_sqla` is annotated to return `tuple[ColumnElement, ...]` (line 2024 of `connectors/sqla/models.py`), so the `isinstance(sqla_col, ColumnElement)` check at line 4784 is always true and serves no purpose. The existing adhoc branch (line 4748) appends unconditionally for the same reason.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/models/helpers.py - 1
Review Details
  • Files reviewed - 3 · Commit Range: 180d51d..180d51d
    • superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx
    • superset/models/helpers.py
    • tests/unit_tests/models/helpers_test.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

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

  • /review - Manually triggers an incremental AI Review.

  • /review full - 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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@rusackas
rusackas merged commit de33efa into apache:master Aug 29, 2026
80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

explore:filter Related to filters in Explore plugins size/M viz:charts:table Related to the Table chart

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants