Skip to content

test(partition-mapping): cover Hive/Impala mirrored SQL, cache outage and migration - #46319

Merged
rusackas merged 3 commits into
apache:masterfrom
preset-io:sdet-pfm-unit-gaps
Nov 21, 2026
Merged

rusackas merged 3 commits into
apache:masterfrom
preset-io:sdet-pfm-unit-gaps

Conversation

@drivaspreset

Copy link
Copy Markdown
Contributor

SUMMARY

Test-only change that closes three unit-test gaps in Partition Filter Mapping. No production code changes.

1. Hive/Impala-specific mirrored SQL (tests/unit_tests/models/partition_mirroring_test.py)

test_hive_family_mirrors_epoch_buckets_as_numeric_keys_or_null runs 28 cases: Hive and Impala × hourly (3600) and daily (86400) epoch-key recipes × ==, IN, >, >=, <, <= and the time range.

  • What is faked: only partition_mapping._probe, the single call that sends the transform to the warehouse. The chart SQL is compiled by get_query_str in each engine's own dialect.
  • How it asserts: it reads the mirror from the sqlglot tree that superset.sql.parse.SQLStatement builds for that engine, not from SQL text. It checks that:
    • every bound on the partition key is a numeric literal equal to the expected epoch key;
    • strict bounds are widened (< becomes <=, > becomes >=);
    • IN maps element-wise;
    • the predicate is ORed with key IS NULL and ANDed onto the chart's own filter;
    • no :value placeholder remains.
  • Robust to rendering: identifier quoting (PyHive backticks) and redundant parentheses don't affect the result.
  • Scope: the generic operator, quoting and NULL-escape behavior was already covered by existing tests on the default dialect. What's new is the Hive/Impala path. Before this PR Impala had no coverage, and Hive only had one DATE-key case. An Impala-only change that wrote the key as a string passed every existing test; it now fails 12 cases.

2. Cache outage fails open (tests/unit_tests/connectors/sqla/partition_verdict_identity_test.py)

A MagicMock(spec=Cache) that raises on get and set replaces the cache. Five tests check that while the cache is down:

  • a chart against a real SQLite table still returns its rows and still prunes;
  • every chart re-probes the engine;
  • the mirror verdict reads as unknown (None, not False);
  • each lost cache write logs a warning.

These cover the four exception handlers that previously had no tests (_cache_get, _cache_set, record_mirror_verdict, known_mirror_verdict). Before this PR, making any of them re-raise passed every existing test.

3. Migration a7f3c2e91d84 upgrade/downgrade (tests/unit_tests/migrations/test_add_partition_filter_mapping.py, 11 cases)

Modelled on test_add_deleted_at_to_tables.py. The tests check that:

  • upgrade adds the partition mapping columns to tables, table_columns and their version tables;
  • existing columns read as not monotonic after upgrade (server default);
  • downgrade drops exactly those columns;
  • both upgrade and downgrade are safe to run twice.

Refactor of an existing test: test_epoch_bucket_queries_preserve_actual_rows now builds its transform and filters with the shared helpers _epoch_bucket_transform / _epoch_bucket_filter (the same code, moved), and _query takes its defaults from _query_obj. To prove nothing changed, I recorded every SQL string the test generates (28 cases × mirrored and unmirrored, 56 in total) on master and on this branch: they are identical, and the 28 collected case IDs match.

Question for maintainers: a failed cache read (_cache_get, known_mirror_verdict) returns None without logging, while a failed write logs a warning. Is that intended? The tests don't depend on either answer: they assert that write failures are logged and don't count warnings. I checked this by temporarily adding read-failure warnings to production code; all cache-outage tests still passed.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A (tests only).

Coverage of superset/connectors/sqla/partition_mapping.py (coverage run --branch over the partition-mapping unit test files):

Statements Missed Branches Partial Cover
Before 941 56 392 29 93.62%
After 941 48 392 29 94.22%

Newly covered: lines 2664-2665, 2672-2673, 2769-2770, 2786-2787 (the cache exception handlers). Nothing became newly uncovered.

Mutation checks. Each change was applied temporarily to production code, then reverted:

Mutation Existing tests With this PR
Impala-only handle_comparison_filter writes the key as a string 0 fail 12 fail
Hive-only override, same change 2 fail 14 fail
A cache handler re-raises (each of the four) 0 fail 1-4 fail
Upgrade leaves out a column / a version-table column; downgrade leaves columns in place; monotonic default set to true 0 fail 1-2 fail

The new Hive/Impala test still passes when only the rendering changes: Hive identifiers left unquoted, or explicit (a AND b) OR c parentheses.

TESTING INSTRUCTIONS

The Impala cases need the impyla dialect. CI installs .[hive,impala], so they run there. Locally they are skipped when impyla is missing.

pip install -e ".[hive,impala]"

pytest tests/unit_tests/models/partition_mirroring_test.py \
       tests/unit_tests/connectors/sqla/partition_verdict_identity_test.py \
       tests/unit_tests/migrations/test_add_partition_filter_mapping.py
# 262 passed

pytest -n auto --dist loadfile \
       tests/unit_tests/models/partition_mirroring_test.py \
       tests/unit_tests/connectors/sqla/partition_verdict_identity_test.py \
       tests/unit_tests/migrations/test_add_partition_filter_mapping.py

coverage run --branch -m pytest \
  tests/unit_tests/connectors/sqla/partition_mapping_test.py \
  tests/unit_tests/connectors/sqla/partition_validation_test.py \
  tests/unit_tests/connectors/sqla/partition_verdict_identity_test.py \
  tests/unit_tests/models/partition_mirroring_test.py \
  tests/unit_tests/datasets/partition_mapping_preview_test.py \
  tests/unit_tests/datasets/partition_mapping_serialization_test.py \
  tests/unit_tests/migrations/test_add_partition_filter_mapping.py
coverage report -m --include="*partition_mapping.py"

The touched files also pass in random order (pytest-randomly, 5 seeds) and under pytest-xdist.

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

Test-only: adds unit tests for an existing migration (a7f3c2e91d84) and does not add a migration.

🤖 Generated with Claude Code

… and migration

- Golden mirrored-predicate SQL on Hive and Impala for hourly and daily
  epoch-key recipes across =, IN, >, >=, <, <= and the time range:
  unquoted integer keys, strict bounds widened, the NULL-partition escape,
  no leaked :value placeholder, and SQL the engine's parser reads. Only
  the warehouse probe is faked.
- A cache outage fails open: charts keep their rows and their pruning,
  every chart re-probes, the mirror verdict reads as unknown, and each
  lost cache write logs a warning.
- Migration a7f3c2e91d84 adds the four partition mapping columns to the
  dataset tables and their version tables, defaults existing columns to
  not monotonic, drops them on downgrade, and is safe to re-run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace the golden-string Hive/Impala mirror test and its separate parse
test with one test that reads the mirror from the engine's sqlglot tree:
the bounds on the partition key are numeric literals equal to the
expected epoch keys, strict bounds are widened, IN maps element-wise,
the predicate is ORed with `key IS NULL` and ANDed onto the chart's own
filter, and no `:value` placeholder remains. Identifier quoting and
redundant parentheses no longer affect the outcome.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: 841a02f238ab

@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.66%. Comparing base (f357ec3) to head (841a02f).
⚠️ Report is 86 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #46319      +/-   ##
==========================================
- Coverage   85.66%   85.66%   -0.01%     
==========================================
  Files        3111     3108       -3     
  Lines      214938   214745     -193     
  Branches    50908    50793     -115     
==========================================
- Hits       184136   183953     -183     
+ Misses      27381    27375       -6     
+ Partials     3421     3417       -4     
Flag Coverage Δ
hive 34.00% <ø> (ø)
mysql 51.66% <ø> (ø)
postgres 51.70% <ø> (?)
presto 35.69% <ø> (ø)
python 88.31% <ø> (+0.01%) ⬆️
sqlite 51.37% <ø> (ø)
unit 83.58% <ø> (+<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.

@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 @drivaspreset, nice set of gap-fills, and the mutation table in the description is a great touch. LGTM!

On your question about read vs. write failures: I think it's fine as is. A failed read just falls through to a fresh probe and the chart still works, so warning on every read while the cache is down would mostly be noise. Happy to revisit if anyone feels strongly.

Re-ran CI too, since the last run tripped over a GitHub API rate limit.

@rusackas
rusackas merged commit 3f3faff into apache:master Nov 21, 2026
105 of 123 checks passed
@rusackas
rusackas deleted the sdet-pfm-unit-gaps branch November 21, 2026 21:55
jprinet added a commit to jprinet/superset that referenced this pull request Nov 23, 2026
* origin/master: (393 commits)
  fix(a11y): name the semantic view description input (apache#46458)
  docs(semantic): explain datasource list modification eligibility (apache#46462)
  docs(semantic-layer): document NULL-preserving exclusion filters (apache#46447)
  fix(uploads): skip folder and system entries in columnar ZIP uploads (apache#45617)
  fix(i18n-es): promote 47 of the zero-context backfill entries (apache#45847)
  fix(mcp): return structured ChartError on SQLAlchemyError in get_chart_sql (apache#44351)
  fix(datasets): follow semantic view modification permissions (apache#46448)
  fix(docker): account for container memory limits in frontend-mem-nag.sh (apache#46373)
  fix(reports): carry the report's native filters in the email and Slack link (apache#46062)
  fix(explore): apply the dataset timezone to grained temporal filter values (apache#46175)
  fix(i18n): enforce the do-not-translate registry across the catalogs (apache#45974)
  chore(logging): log unparseable virtual dataset SQL at debug in the RLS lookup (apache#46139)
  fix(i18n): split parameter-suggestion plural into two messages (apache#46049)
  test(partition-mapping): cover Hive/Impala mirrored SQL, cache outage and migration (apache#46319)
  perf(dashboard): look up the dashboard once per filter_state read (apache#46314)
  fix(i18n): load the dayjs locale for every language with a catalog (apache#45982)
  test(semantic-layer): make date export parametrization deterministic (apache#46449)
  fix(oauth2): idempotent OAuth2 completion and resilient listener (apache#40292)
  fix(explore): prevent full table scan when SQL expression is used as x-axis (apache#41339)
  feat(mcp): radar chart type plugin (apache#43571)
  ...

# Conflicts:
#	.github/workflows/docker.yml
#	.github/workflows/superset-frontend.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants