Fifth of the stack, and the one that makes the feature reachable: until now a
mapping could only be configured with a PUT, and the preview endpoint had no
caller. Implements wireframes 1a, 1b, 1c, 1g and 1h.
Two places where the spec and the merged backend disagreed, resolved rather
than papered over:
- The mockups have no monotonicity control, but the query path only mirrors
ranges when the transform is declared order-preserving -- so 1d/1e's own
example, a time range producing two `dt_epoch` bounds, was unreachable
through the UI. Adds the checkbox the shipped docs already describe.
- `unix_timestamp(:value)` is Hive syntax and the PRD asks for it as the
temporal default. Pre-filling it on Postgres or BigQuery would hand the
owner an expression that cannot parse, so the default moves to the engine
spec (`partition_value_transform_default`, set on Hive/Impala/Spark) and
engines without one offer no pre-fill at all.
The preview endpoint now takes `sample_values` plus an operator and builds its
predicate with `build_mirrored_predicates` -- the same function the query path
uses -- so what the panel shows is what a chart emits, `IN` included. It also
accepts a candidate `partition_column`: the editor previews a mapping the owner
has not saved yet, and a preview that requires saving first is not a preview.
Failed probes now carry the engine's own message through an opt-in `errors`
sink, because sqlglot parses unknown functions happily and a misspelled one is
otherwise reported as an unexplained blank.
Two read-path gaps this uncovered, both silent:
- `columns.partition_value_transform` and its monotonic flag were in the
model, the export fields and the PUT schema but not in `show_columns`, so
the editor reopened a saved mapping as if it had none -- and the next save
wrote that emptiness back. Related-model fields have to be listed in
`show_columns`, not only `show_select_columns`.
- `partition_value_transform_default` needed the same treatment to reach the
pre-fill.
Both are now pinned by tests in the serialization suite, whose whole premise is
that a field missing from any one layer is dropped without a sound.
`Field` gains an opt-in `passItemToControl`: the row-expand section keys off the
whole column record, not just the transform it edits, and handing an unknown
`item` prop to every TextControl and Select was not worth the convenience.
Verified against a partitioned table in Docker: the editor configures a mapping,
"View query" carries `dt_epoch >= ... AND dt_epoch < ...` alongside the
`event_time` bounds, a non-temporal `country -> region_key` mapping emits
`region_key IN ('us', 'ca')`, and with the flag off the controls disappear, the
preview endpoint 404s and no predicate is added.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
SUMMARY
Fifth of the partition filter mapping stack, and the PR that makes the feature reachable. Until now a mapping could only be configured with a
PUT /api/v1/dataset/<pk>, and the preview endpoint added in #pfm-3 had no caller — its own commit message says the visual controls "are not in this PR". This implements them: wireframes 1a, 1b, 1c, 1g, 1h.Stacked on
hughhhh/pfm-4-docs. Review the compare against pfm-4 rather than the diff against master.What's new in the editor
partition_mapped_column ?? main_dttm_col, and a second select would let it drift from the default datetime column silently.PARTITIONtag, and defaultsIs filterable/Is dimensionoff — still manually togglable.Two places the spec and the merged backend disagreed
dt_epochbounds) was unreachable through the UI. This adds the Transform preserves ordering checkbox that the docs in pfm-4 already describe.unix_timestamp(:value)as the temporal default, but that's Hive syntax and would not parse on Postgres, Trino or BigQuery. The default moves to the engine spec (partition_value_transform_default, set on Hive/Impala/Spark); engines without one offer no pre-fill rather than a wrong one.Backend changes
sample_values+ anoperatorand builds its predicate withbuild_mirrored_predicates— the same function the query path uses — so what the panel shows is what a chart emits,INincluded. It also accepts a candidatepartition_column, because the editor previews a mapping the owner hasn't saved yet and a preview that requires saving first isn't a preview.errorssink (the hot query path passes nothing and stays silent). sqlglot parses unknown functions happily, so a misspelled one is an engine error and was previously reported as an unexplained blank.SELECTprefix and the:value→NULLsubstitution so it points at what the owner actually typed.Two silent read-path bugs this uncovered
Neither was reachable from unit tests; both needed the running app.
columns.partition_value_transformand its monotonic flag were in the model, the export fields and the PUT schema but not inshow_columns— so the editor reopened a saved mapping as if it had none, and the next save wrote that emptiness back. Related-model fields must be listed inshow_columns, not onlyshow_select_columns(columns.advanced_data_typeis in both for the same reason).partition_value_transform_defaultneeded the same treatment to reach the pre-fill.Both are now pinned by tests in
partition_mapping_serialization_test.py, whose whole premise is that a field missing from any one layer is dropped without a sound.One small shared change:
Fieldgains an opt-inpassItemToControl. The row-expand section keys off the whole column record, not just the transform it edits, and handing an unknownitemprop to everyTextControlandSelectwasn't worth the convenience.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Screenshots captured during validation; attaching separately.
1aPartition column + Maps to partition, and1bthe mutedPARTITIONrow1cRow expand with transform, ordering checkbox and a valid preview1cParse error state — only one of preview/error is ever visible1gPartition column set with nothing mapped1hNon-temporalcountry → region_keyTESTING INSTRUCTIONS
Automated:
1800backend unit tests and225frontend Datasource tests pass;tsc,ruff,ruff formatandoxlintare clean (oxlint warnings insrc/components/Datasourcego 32 → 30, since the duplicated column-name renderer was folded into one helper).Manually, against a real engine:
FEATURE_FLAGS = {"PARTITION_FILTER_MAPPING": True}.dt_epoch. Confirm Maps to partition showsevent_timetagged Default datetime column, and thatdt_epoch's row is muted with aPARTITIONtag and its toggles off.cast(extract(epoch from cast(:value as timestamp)) as bigint)and check Transform preserves ordering. The preview should readevent_time >= '2026-01-15 00:00:00'→dt_epoch >= 1768435200. Unchecking it drops the preview back to=.lower(:value))) → Can't parse transform with a position, and the preview panel disappears.region_key, move the mapping tocountry, setlower(:value). Preview showscountry IN ('US', 'CA')→region_key IN ('us', 'ca'), and a chart filtered oncountryemitsAND region_key IN ('us', 'ca').Merge order. pfm-4's docs describe this UI, so if pfm-4 merges first the published docs tell operators to click controls that don't exist yet. Merging this before or together with pfm-4 avoids that window; no docs edit is needed either way.
Known limitation, not introduced here: SQLAlchemy's
text()misparses Postgres::casts, so a transform written as:value::timestampleaves the placeholder unbound. This comes frombuild_probe_sqlin pfm-2 and is harmless on Hive/Impala, which have no::syntax — the ANSIcast(:value as timestamp)form works. Worth a follow-up for Postgres/Redshift users.ADDITIONAL INFORMATION
PARTITION_FILTER_MAPPING🤖 Generated with Claude Code
How Has This Been Tested?
Validated against the full stack under Docker (Flask + Celery worker + Postgres + Redis) serving this branch, driving the real browser. Two rounds: once during implementation, once after pushing — the second round found the three defects fixed in
8f873f3.Bring-up (non-default ports, since 8088/5432 are usually taken by another stack):
Fixture — a table where the partition key really is the transform of the business column, so a mirrored predicate is verifiably correct rather than merely present:
The walk (543 rows, 5 columns):
00-before-no-partition-column.png— Partition columnNone, no Maps to partition, all rows normaldt_epoch01-1a-1b-partition-column-selected.png— Maps to partition →event_timetagged Default datetime column;dt_epochrow muted withPARTITIONtag and its three toggles off, every other row untouched02-1c-row-expand-valid-preview.png— previewevent_time >= '2026-01-15 00:00:00'→dt_epoch >= 1768435200. Unticking drops it back to=lower(:value)))03-1c-parse-error.png— Can't parse transform, syntax error at position 14, preview hidden (only one of preview/error is ever visible)04-1g-partition-column-no-mapping.png—No mappingchip, Map a column →, and the scan-every-partition warningregion_key, move the mapping tocountry,lower(:value)05-1h-non-temporal-mapping.png— required asterisk,country IN ('US', 'CA')→region_key IN ('us', 'ca')Screenshots live in
.context/pfm-ui-screenshots/(gitignored) and are attached above.Non-visual proof. The generated SQL, via
/api/v1/chart/datawithresult_type: query— the same SQL the View query panel renders:1782864000is exactly2026-07-01T00:00:00Z, matching how the fixture populatesdt_epoch— so the pruning predicate selects the same rows rather than merely looking plausible.Negative case — with
PARTITION_FILTER_MAPPINGoff: the Partition column field, thePARTITIONtag and the muted row all disappear, the preview endpoint returns 404, and the same query emits noregion_keypredicate at all.Also verified the engine-specific default behaves: on Postgres
partition_value_transform_defaultisNone, so the editor offers no pre-fill rather than a Hive expression that would not parse.What the browser pass caught that tests did not
Worth calling out, since it's the argument for doing this at all:
show_columns, so reopening showed an empty transform and the next save persisted that emptiness. Fixed, and pinned by tests.8f873f3: the engine's error text clipped mid-sentence (expanded antd rows size to content, and alert descriptions arenowrapin this theme), and Map a column → suggestingrevenue— inviting an owner to mirror a currency metric onto a region key.Additionally verified (third pass)
GET /api/v1/explore/?datasource_type=table&datasource_id=…) carriesregion_key: {groupby: false, filterable: false}while every other column staystrue;dndControls.tsxbuilds the Dimensions options fromcolumns.filter(c => c.groupby)and the Filters options fromcolumns.filter(c => c.filterable). Both ends verified against the running app. I could not get the drag-and-drop popover itself to open under automation, so this rests on the payload plus Superset's existing filter rather than on my having seen the rendered list.region_keyfrom the physical table with the mapping live, then hit Sync columns from source: three toasts fire —Metadata has been synced,The partition filter mapping was cleared: its column is gone,Removed 1 column from the virtual dataset— the Columns badge goes 5 → 4, and Partition column resets toNonewith Maps to partition gone.06-sync-clears-dangling-mapping.pngcaptures the resulting state (the toasts auto-dismiss before a screenshot lands; the strings above are read straight from the DOM).Wireframe 1e in the real panel
View query shows the mirrored predicate as an ordinary
WHEREclause, exactly as 1e specifies — captured in07-1e-view-query-mirrored-predicate.png:Known limitation (pre-existing, not introduced here)
SQLAlchemy's
text()misparses Postgres::casts, so a transform written:value::timestampleaves the placeholder unbound and the probe fails with "This text() construct doesn't define a bound parameter named 'value'". It comes frombuild_probe_sqlin pfm-2 and is harmless on Hive/Impala, which have no::syntax. The ANSI formcast(:value as timestamp)works and is what the walk above uses. Worth a follow-up for Postgres/Redshift.