Repository navigation
Conversation
|
Bito Automatic Review Skipped - Branch Excluded |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## hughhhh/pfm-1-model-migration-api #43758 +/- ##
=====================================================================
+ Coverage 81.72% 81.74% +0.01%
=====================================================================
Files 2979 2979
Lines 181790 182029 +239
Branches 42012 42066 +54
=====================================================================
+ Hits 148575 148794 +219
- Misses 30491 30500 +9
- Partials 2724 2735 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
6f5fb95 to
eb2d23b
Compare
3d7615a to
3c96ebe
Compare
eb2d23b to
180fb82
Compare
3c96ebe to
218eec5
Compare
180fb82 to
0ac039d
Compare
218eec5 to
0927c4a
Compare
0ac039d to
b37eefd
Compare
0927c4a to
7ad9986
Compare
b37eefd to
588f71c
Compare
7ad9986 to
d33754b
Compare
588f71c to
d909e49
Compare
d33754b to
9c5b4a6
Compare
d909e49 to
d092638
Compare
9c5b4a6 to
e14aad3
Compare
d092638 to
f21009f
Compare
c90781e to
21693ee
Compare
rusackas
left a comment
There was a problem hiding this comment.
Heya @hughhhh :)
@sadpandajoe's two open threads on helpers.py (NULL/special partition values, and grain-truncated ranges silently dropping rows) look like legit gaps, not nits. Given how much of this PR's own description leans on soundness, I'd want those addressed before this moves forward.
ae07ef6 to
4ffddb3
Compare
21693ee to
05b7c5c
Compare
| payload = json.dumps( | ||
| [ | ||
| database.id, | ||
| database.backend, | ||
| catalog, | ||
| schema, | ||
| transform, | ||
| [repr(value) for value in values], | ||
| ], |
There was a problem hiding this comment.
Suggestion: The probe cache key omits connection and session settings, so changing a database URI or timezone can reuse transformed values from the old environment for 24 hours.
Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Cache
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/connectors/sqla/partition_mapping.py
**Line:** 438:446
**Comment:**
*Cache: The probe cache key omits connection and session settings, so changing a database URI or timezone can reuse transformed values from the old environment for 24 hours.
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 fixThere was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 3d24984.
The cache key now includes database.sqlalchemy_uri, database.extra, and database.changed_on along with the database identity, preventing reuse across connection or session-setting changes.
If that's not right, unresolve this thread and CodeAnt will leave it open.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of da9f21c.
The cache key now includes database.sqlalchemy_uri, database.extra, and database.changed_on alongside the transform inputs, invalidating entries when connection or session settings change.
If that's not right, unresolve this thread and CodeAnt will leave it open.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 766673e.
The probe cache key now includes database.sqlalchemy_uri, database.extra, and database.changed_on in addition to the database identity, so URI, session settings, and other database edits invalidate prior entries.
If that's not right, unresolve this thread and CodeAnt will leave it open.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of ea00aa4.
The probe cache key now includes database.sqlalchemy_uri, database.extra, and database.changed_on in addition to the database identity, so URI, session settings, and other database edits invalidate prior entries.
If that's not right, unresolve this thread and CodeAnt will leave it open.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 3c07046.
The probe cache key now includes database.sqlalchemy_uri, database.extra, and database.changed_on in addition to the database identity, so URI, session settings, and other database edits invalidate prior entries.
If that's not right, unresolve this thread and CodeAnt will leave it open.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 73b753c.
The probe cache key now includes database.sqlalchemy_uri, database.extra, and database.changed_on in addition to the database identity, so URI, session settings, and other database edits invalidate prior entries.
If that's not right, unresolve this thread and CodeAnt will leave it open.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 3d028a0.
The probe cache key now includes database.sqlalchemy_uri, database.extra, and database.changed_on in addition to the database identity, so URI, session settings, and other database edits invalidate prior entries.
If that's not right, unresolve this thread and CodeAnt will leave it open.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 74564b9.
The probe cache key now includes database.sqlalchemy_uri, database.extra, and database.changed_on in addition to the database identity, so URI, session settings, and other database edits invalidate prior entries.
If that's not right, unresolve this thread and CodeAnt will leave it open.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of 7951536.
The cache key now includes database.sqlalchemy_uri, database.extra, and database.changed_on alongside the database identity and backend, preventing reuse across connection or session-setting changes.
If that's not right, unresolve this thread and CodeAnt will leave it open.
3d24984 to
3561db1
Compare
9289071 to
dbd8371
Compare
ea00aa4 to
24e44a0
Compare
56a68c0 to
c10ad3e
Compare
3c07046 to
73b753c
Compare
Second of four. Reads the mapping added by the previous PR and appends an equivalent predicate on the partition column to every query, so chart authors change nothing and queries prune. Operator safety is the whole of this change. The PRD says "comparison and range operators map directly; IN maps element-wise", and that is not sound in general -- the unsoundness is silent, showing up as wrong chart numbers rather than an error. A mirrored predicate may only be AND-ed on when the original implies it: `=` and `IN` always -- T is a function ranges and TEMPORAL_RANGE only when T preserves ordering negations, LIKE, IS NULL, ... never Negations are never safe because T need not be injective: `lower(:value)` with `country != 'US'` mirrors to `region_key != 'us'`, which excludes rows whose country is already lowercase 'us' -- rows the original filter keeps. Monotonicity is a property of the transform, not of the column's data type. `hour(:value)`, `date_format(:value, 'dd')` and `dayofweek(:value)` are all reasonable transforms on a TIMESTAMP column and none preserve ordering, so it is declared by the owner rather than inferred. `T(lower) <= T(upper)` is asserted at runtime as a backstop -- necessary, not sufficient, and free because both bounds are already being resolved. The transform is resolved against the engine and emitted as a literal, so "View query" shows an ordinary WHERE clause. Values are bound, never interpolated: they are attacker-controlled in the sense that a Gamma user picks filter values. Any failure at all falls open to no pruning -- the query still runs and is still correct, it just scans more partitions. Two things worth flagging for review: `get_time_filter` applied the dataset timezone and legacy hour offset to the bounds internally. That adjustment is extracted into `adjust_time_bounds` so the mirrored predicate is resolved from the *same* instants the timestamp predicate compares against. Probing the raw bounds would be wrong by exactly the offset, silently, and duplicating the logic would drift. `PARTITION_FILTER_MAPPING` must be configured as a static boolean. FEATURE_FLAGS also accepts per-request callables, and since the mapping only enters the cache key when active, a flag that resolved per user would let a flag-off user read a cache entry written from pruned SQL by a flag-on user. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A mirrored predicate stands in for a real one, so it may only ever be
wider. Two cases made it narrower and silently dropped rows.
A grain makes the real predicate compare the truncated column, while the
mirror used the raw value. Drill-to-detail sends the clicked bucket as
`==` plus the chart's grain, so `DATE_TRUNC('week', event_time) = X`
mirrored to `dt_epoch = T(X)` and kept only the rows at the bucket's first
instant. A grained range has the same flaw at its upper bound: a row in
the final partial bucket satisfies `DATE_TRUNC(...) < until` while the raw
bound excludes it. Neither bound is recoverable here -- "week ending
Saturday" rounds forward, and TIME_GRAIN_ADDONS are arbitrary SQL -- so
filters carrying a grain no longer mirror. Only drill queries carry one;
ordinary charts keep pruning.
A comparison against a NULL partition value is NULL, so a row in a NULL
partition was dropped even when the real filter matched it: Hive and
Impala's default partition, or a transform returning NULL for an input it
cannot convert. The mirror now admits NULL partitions, which keeps those
rows and still prunes, at one extra partition read.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The probe asks a specific database to evaluate the transform, so the answer belongs to that connection, but the cache key carried only `database.id`. That survives an edit to the URI or to `extra` -- a session timezone, say -- so values computed against the old environment were reused for the whole timeout, and a wrong transformed bound prunes away rows the real filter keeps. Add the URI and `extra` to the key, plus `changed_on` for the edits that do not appear in either, such as a rotated password. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A grained range compares the truncated column, so the raw bounds it carries do not describe the rows it keeps: a row in the final partial bucket satisfies `trunc(col) < until` while `col < until` excludes it. That case previously skipped mirroring altogether, which is safe but gives up pruning on exactly the queries that scan the most -- drill-to-detail. Widening recovers it. The obvious floor-based version would be wrong: which way a grain rounds is not knowable from its duration, and shipped specs disagree -- `WEEK_ENDING_SATURDAY` is `date_add(col, 6-dow)` on Hive and `date_trunc(...) + interval '5' day` on Presto, both forward, while Ocient's grains are `ROUND`, i.e. to nearest. Widening only the upper bound would drop up to a week of rows off the bottom of a week-ending range. What every grain does satisfy is `|trunc(ts) - ts| < width(grain)`, so widening *both* bounds by one bucket is no narrower than the real predicate whichever way it rounds -- and it needs no monotonicity of `trunc` itself, which is what rescues Hive's oddly-anchored `P1W`. Width is a property of the grain, not the engine, so `grain_bucket_width` is one literal table rather than a per-engine matrix nobody could keep current. The widened upper bound is `<=` rather than `<`: `ts < until + width` only gives `T(ts) <= T(until + width)` for a transform that is monotonic but not strictly so, such as `unix_timestamp` on a sub-second column. This also closes that gap on the ungrained path, where a strict `<` was already slightly optimistic. Widths are written out rather than parsed -- four week grains are ISO intervals with an anchor that `parse_duration` rejects, and `PT0.5H`/`P0.25Y` are fractional -- and held as `relativedelta` so `P1M` stays calendar arithmetic. Grains an operator supplied have no width we can claim to know: both `TIME_GRAIN_ADDONS` and a per-engine `TIME_GRAIN_ADDON_EXPRESSIONS` override of a built-in duration fall back to not mirroring. Scope is `TEMPORAL_RANGE`. Grained `==` would have to become a two-sided range, needing a monotonic transform that `EQUALS` does not require today; grained `IN` would need a union of buckets the AND-ed sink cannot express. Both stay deferred, and the comment there now says so rather than reading as unsafe in principle. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
f191e0b to
ae33f9f
Compare
73b753c to
3d028a0
Compare
Three review findings on the query-rewrite PR, and the flag description that this PR makes stale. `_transform_is_usable` restated a subset of `validate_transform`: blank, placeholder, Jinja, parseable -- but not the non-deterministic denylist. Since create and import do not validate a mapping at all, a transform calling `now()` or `rand()` could reach storage, be treated as usable here, and mirror a filter with a value frozen at whatever moment the probe ran. Meanwhile `is_transform_active` -- which drives the Explore indicator and *does* run that check -- reported the mapping inactive, so there was no signal anywhere that mirroring was happening with a non-deterministic value. Deleted in favour of `is_transform_active` itself. Two statements of one rule is one too many. `is_parseable`'s docstring claimed "a single select expression" and did not check it. `SELECT lower(:value), 'x'` parses exactly as well as `SELECT lower(:value)` but returns two columns per input, and the probe reads one column per input: for a two-value `IN` filter it took columns 0 and 1, which are the two *expressions* of the first value, so the second value's partition vanished from the predicate and its rows were excluded. Now rejected at validation time, via a new `SQLStatement.count_select_expressions`. The probe's own guard was `len(row) < len(distinct)`, which only caught the harmless direction. 2N columns for N inputs sailed through it and produced the misaligned read above, so it is now `!=` -- a backstop for a transform stored before the validation existed. The probe also built a bare `SELECT <expr>` with no `FROM`, which Oracle and Db2 reject. `_run_probe` swallows the error, so the only symptom was a correctly configured mapping that silently never pruned. `select_without_from_suffix` on the engine spec supplies `FROM DUAL` / `FROM SYSIBM.SYSDUMMY1` where they are needed and nothing where they are not. Finally, `PARTITION_FILTER_MAPPING`'s description still said no query consumer emits the mirrored predicate. This is the PR that makes that false. `docs/static/feature-flags.json` is regenerated from it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Closing in favour of #43870, which now carries the whole feature against Nothing is lost. The commits are unchanged and still in #43870's history, so this stage is still reviewable on its own, and the 2 unresolved comments from this PR are reproduced in an inventory comment there — each with a link back to the original thread and the commit that addressed it. They were all addressed in the review pass of 2026-10-01; they show as unresolved here only because the threads were never clicked shut. @sadpandajoe @rusackas — sorry for the churn. If you would rather keep reviewing stage by stage, say so and I will reopen; the branches are all still there. |
Stack (review bottom-up):
SUMMARY
Second of four, stacked on the model/migration PR. Reads the mapping and appends an equivalent predicate on the partition column to every query, so chart authors change nothing and queries prune.
Operator safety is the whole of this change. The PRD says "comparison and range operators map directly;
INmaps element-wise" — that is not sound in general, and the unsoundness is silent, showing up as wrong chart numbers rather than an error. A mirrored predicateP2may only beAND-ed onto the query when the originalP1implies it:col = v,col IN (…)Tis a functioncol >=,>,<,<=,TEMPORAL_RANGETis monotoniccol != v,NOT IN,LIKE,IS NULL, …Negations are never safe because
Tneed not be injective:lower(:value)withcountry != 'US'mirrors toregion_key != 'us', which excludes rows whosecountryis already lowercase'us'— rows the original filter keeps.Monotonicity is declared, not inferred. An earlier draft inferred it from the column type ("a temporal→partition-key transform is monotonic by construction"). That's wrong, and it fails on partition schemes people actually use:
hour(:value),date_format(:value, 'dd')anddayofweek(:value)are all reasonable transforms on aTIMESTAMPcolumn and none preserve ordering. Since the Explore time range is a range operator, this is not an edge case.T(lower) <= T(upper)is asserted at runtime as a backstop — necessary, not sufficient, and free because both bounds are already being resolved.Two things worth reviewer attention:
get_time_filterapplied the dataset timezone and legacy hour offset to the bounds internally. That adjustment is extracted intoadjust_time_boundsso the mirrored predicate is resolved from the same instants the timestamp predicate compares against. Probing the raw bounds would be wrong by exactly the offset, silently; duplicating the logic would drift.PARTITION_FILTER_MAPPINGmust be configured as a static boolean.FEATURE_FLAGSalso accepts per-request callables, and since the mapping only enters the cache key when active, a flag resolving per user would let a flag-off user read a cache entry written from pruned SQL by a flag-on user.Safety posture. Values are bound, never interpolated — they're attacker-controlled in the sense that a Gamma user picks filter values. The probe query references no tables, so it can't leak data or bypass RLS. Any failure at all falls open to no pruning: the query still runs and is still correct, it just scans more partitions.
Deliberate non-coverage, documented in PR 4: filter-value dropdowns (
values_for_columnbuilds its ownSELECT DISTINCTand never reaches this code path), RLS predicates andextras.where(raw SQL appended downstream of the structured-filter loop), and columns with an activeadvanced_data_type(translate_filterbuilds its own predicate shape from translated values, so the(operator, value)pair this reasoning depends on doesn't exist).BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
The mirrored predicate lands in
where_clause_andand shows up in View query as an ordinaryWHEREclause, by design:TESTING INSTRUCTIONS
pytest tests/unit_tests/models/partition_mirroring_test.py \ tests/unit_tests/connectors/sqla/partition_mapping_test.pyThe mirroring tests stub the engine probe and assert on the generated SQL, so they pin down which predicates are emitted and with what values — where the correctness argument lives. Worth reading as the review surface: nothing emitted for
!=/NOT IN/LIKE/IS NULL; nothing for a range when the transform isn't declared monotonic; nothing whenT(lo) > T(hi); no duplicate whengranularityand aTEMPORAL_RANGEfilter hit the same column; and the timezone/hour-offset tests, which catch the whole class of off-by-offset bugs.There is no UI to configure a mapping yet — this is exercised through the ORM.
ADDITIONAL INFORMATION
PARTITION_FILTER_MAPPING(off by default)