Skip to content

fix(export): honor layer definition queries (#1998) - #2417

Merged
Mavrick-F merged 6 commits into
opengeos:mainfrom
Mavrick-F:fix/export-definition-query
Nov 18, 2026
Merged

Mavrick-F merged 6 commits into
opengeos:mainfrom
Mavrick-F:fix/export-definition-query

Conversation

@Mavrick-F

@Mavrick-F Mavrick-F commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Apply the layer's definition query before writing features, including browser downloads and exports that read a whole source a chunk at a time.
  • Report the number of features excluded by the query after writing the file. Count format losses separately.
  • The Data ribbon and command search open the same Export Features dialog. Its shared command covers the desktop, CLI, Python Layer.to_file(), Assistant, MCP, and any plugin workflow that dispatches it. The browser applies the same filtering before download. On a phone, Export Features is available through the desktop interface. Exported files can be reopened as layers.

A filtered in-memory export briefly holds a copy of the kept rows because bounded writing across the whole-dataset and browser formats requires a separate writer change.

Testing

  • Regression tests cover in-memory and streamed layers, a background GeoPackage export, whole-source Shapefile export, and browser downloads. They inspect the written rows and the notice with and without a query. A chunked export test covers a row-number condition across chunk boundaries.
  • In the Twin Cities reproduction, the unpatched CLI wrote 1,505 tracts and the fixed CLI wrote the 329 matching tracts. The export reported the 1,176 query exclusions.
  • After merging upstream main, formatting, Clippy and local suites for rustgis-data, rustgis-engine and rustgis-ui-egui passed. The local data suite excluded one existing FileGDB test after reproducing GDAL 3.10.3 rejecting its TIN fixture.
  • The Linux fork gate, including the WebAssembly build, passed on the merge commit. Fork CI

UI evidence

Both screenshots use the sample Cities layer with pop_max > 10000000. The export went from 243 cities to 17. The Messages pane reports the 226 excluded cities.

Before, the Messages pane shows the export confirmation

After, the Messages pane also shows that the query left out 226 cities

Related issue

Part of #1998

Summary by CodeRabbit

  • New Features
    • Layer exports apply definition queries across the entire source, including features outside the current view, and report how many features are excluded.
    • Blank queries leave all features included without a query notice. If a query cannot be read or parsed, exports proceed without filtering and report the issue.
    • Query filtering works for streamed and in-memory exports, browser exports, and data conversions.
  • Documentation
    • Sharing guidance and layer export documentation clarify query filtering and exclusion notices for streamed exports.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Feature exports now apply a layer’s definition query to in-memory and streamed data. Export results track excluded features and query parse errors. The share command, data conversion, and browser export report query omissions. Documentation describes query scope for streamed sources.

Changes: Definition-query exports

Layer / File(s) Summary
Query-aware filtering and chunked export
crates/data/src/query.rs, crates/data/src/export.rs, crates/data/src/export/tests.rs
Query evaluation accounts for row offsets across chunks. Chunked and whole-dataset filtering apply parsed queries, and Exported records the filtered count and query parse error. Tests cover row-number filtering across chunks and update existing export expectations.
Engine exports and omission notices
crates/engine/src/cmd/share.rs, crates/engine/src/cmd/workflows.rs, crates/engine/src/tests/write_notices.rs
share.exportLayer and data.convert apply definition queries to resident datasets and streamed sources. Refusal notes and post-write notices report query omissions or parse errors. Tests cover export formats and execution paths.
Browser export and documented behavior
crates/ui-egui/src/lib.rs, apps/rustgis-python/python/rustgis/__init__.py, docs/user-guide/sharing.md
Browser exports apply the definition query and report omissions after an accepted download. The Python API and user guide describe query scope and omission reporting.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Low

Sequence Diagram(s)

sequenceDiagram
  participant Exporter as share.exportLayer
  participant LayerExport as write_layer
  participant FilteredExport as write_source_filtered
  participant ChunkWriter as write_chunks_as
  participant Source as FeatureSource
  participant Session
  Exporter->>LayerExport: pass layer and export path
  LayerExport->>FilteredExport: pass source and definition query
  FilteredExport->>ChunkWriter: pass parsed query
  ChunkWriter->>Source: read source chunks
  ChunkWriter-->>LayerExport: return export result with filtered count
  LayerExport->>Session: report query omissions or parse error
Loading

Possibly related issues

Possibly related PRs

  • opengeos/RustGIS#1146: It introduces chunked streaming for desktop share.exportLayer; this change applies definition-query filtering within that streamed path.

Suggested reviewers: giswqs, pick2510, choupeanut

Merge Risk: Minimal · up to 4c157

Exports now honor a layer's definition query and report how many features it excluded. Empty queries still export everything, and unreadable queries export everything with a notice. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(export): honor layer definition queries (#1998)" names the main change: exports now apply a layer's definition query before writing. The changeset adds query filtering to export paths i…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the repository template. It has a Summary, a Testing section, a UI evidence section with before and after screenshots, and a Related issue line (Part of #1998). The Summary sta…
Full details: Title check

Explanation

The title "fix(export): honor layer definition queries (#1998)" names the main change: exports now apply a layer's definition query before writing. The changeset adds query filtering to export paths in the data, engine, UI and docs crates, so the title matches the primary change. The title uses a conventional-commit prefix and a specific subject. The PR objectives cite the title as "fix(export): honor layer definition queries" under PR #2417, while the title here carries #1998; this number mismatch does not change the title's relevance to the changeset.

Full details: Description check

Explanation

The description follows the repository template. It has a Summary, a Testing section, a UI evidence section with before and after screenshots, and a Related issue line (Part of #1998). The Summary states what changed: the layer definition query now applies before writing features, including browser downloads and chunked whole-source exports, and the export reports excluded features. The Testing section lists regression tests, a manual CLI reproduction with counts, and CI results. The UI evidence section includes the required before and after images with a clear description. The description is specific and complete for this change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the rows in flight
The query keeps the ones just right
Across each chunk, row numbers stay
Omitted counts are shown along the way
The export hops into the night

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 48af4bc9-7759-48b7-a1c3-77f61815a8aa
Commits

Reviewing files that changed from the base of the PR and between c99d9bd and 4c15747.

Files selected for processing: 7

  • apps/rustgis-python/python/rustgis/__init__.py
  • crates/data/src/export.rs
  • crates/data/src/export/tests.rs
  • crates/engine/src/cmd/share.rs
  • crates/engine/src/cmd/workflows.rs
  • crates/engine/src/tests/write_notices.rs
  • crates/ui-egui/src/lib.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

Comment thread crates/engine/src/cmd/share.rs Outdated
(None, rustgis_map::Unreadable::default())
};
let (mut whole, unreadable) =
if l.is_streamed() && chunks.is_none() { l.load_all_counted()? } else { (l.dataset.clone(), rustgis_map::Unreadable::default()) };

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.

Performance (medium, high confidence). This now copies the whole in-memory dataset (l.dataset.clone()) on every export, including exports with no definition query. The old code borrowed &l.dataset, so a large non-streamed layer now needs roughly twice its memory at export time. The same applies to the else branch on the chunked path, where the clone is never used. Suggest copying only when a query is set, and borrowing otherwise, e.g. let owned = (query.is_some() && chunks.is_none()).then(|| l.dataset.clone()); and then filtering a clone only when owned is present. Note that filter_dataset and write_source_filtered already see the query, so the clone is only needed in the in-memory case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Native exports now borrow the in-memory dataset and make an owned copy only when filtering removes rows. The original clone copied dataset metadata and shared the feature storage. This also removes the unused metadata clone on the streaming path.

0364bf25e4 passed fork CI.

Comment thread crates/ui-egui/src/lib.rs Outdated
} else {
(None, Default::default())
};
let (mut dataset, lost) = if l.is_streamed() { l.load_all_counted()? } else { (l.dataset.clone(), Default::default()) };

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.

Performance (medium, high confidence). The same full clone happens in the web download path: (l.dataset.clone(), ...) runs on every non-streamed download, even without a definition query. The browser is single-threaded and memory-constrained, so this doubles the peak memory of large layers. Copy only when l.definition_query is set, as in the share.rs comment. The let ds = &dataset; alias below also adds nothing and can be dropped.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Browser downloads now borrow the in-memory dataset until a query removes rows. A whole read of a streamed layer is already owned and can be filtered in place.

0364bf25e4 passed fork CI.

Comment thread crates/data/src/export.rs Outdated
/// Applies a layer's definition query to a whole dataset, using the same missing or invalid
/// query behavior as drawing the layer. Returns the number of rows excluded.
pub fn filter_dataset(ds: &mut Dataset, definition_query: Option<&str>) -> Result<usize> {
match definition_query.and_then(|text| query::parse_fields(text, ds).ok()) {

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.

Never silent (low-medium, about 40% confidence). .ok() throws away the parse error. If the stored query doesn't parse, for example one imported from another program, every feature is exported with no notice, and the export shows rows the user filtered out. Drawing the layer also ignores such a query, so this matches the map, which is probably why it was written this way. Still, the user asked for a filter and gets none, so either refuse the export with the parse error or add a notice that the query was not applied. A test with an unparseable query would show which behaviour is intended.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

An unreadable stored query now produces one notice with the parser error. The export uses the unfiltered rows because the map shows those same rows when its stored query cannot be read. Regression coverage checks the output and notice for in-memory and read-in-place exports, alongside the valid-query and no-query cases.

0364bf25e4 passed fork CI.

Comment thread crates/data/src/export.rs Outdated
crate::progress::begin(src.info().count.map_or(0, |n| usize::try_from(n).unwrap_or(usize::MAX)));
let batch = src.visit_chunks(None, bytes, &mut |mut chunk| {
if let Some(expr) = query {
let mut input = layer.clone();

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.

Performance (nit, high confidence). layer.clone() runs for every chunk, copying the layer's name and every Field just to carry the chunk's features. Build the scratch Dataset once before visit_chunks and swap the features in and out per chunk. This is cheap next to the write, so it's a release-quality-pass item unless it shows up in a profile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The streamed writer now sets up one scratch dataset for the query and moves each chunk's features in and out of it. The scratch dataset is reused across chunks and writer retries.

0364bf25e4 passed fork CI.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

The PR makes Export Features honor a layer's definition query. The row-number offset across chunks, the query-omission notice, and the no-double-notice path all check out on reading. The tests cover streamed, in-memory, background, and browser exports, with and without a query. I could not compile or run the tests here, so the findings below come from reading the code.

Bugs

  • None confirmed.

Security

  • None found.

Performance

  • Medium, high confidence: write_layer now clones the whole in-memory dataset on every export, including exports with no query (crates/engine/src/cmd/share.rs:694). Peak memory roughly doubles for large layers.
  • Medium, high confidence: the browser download path makes the same full clone on every non-streamed download (crates/ui-egui/src/lib.rs:4921). The browser is single-threaded and memory-constrained.
  • Nit, high confidence: layer.clone() runs per chunk in the streamed writer (crates/data/src/export.rs:223). Build the scratch dataset once.

Quality

  • The query-filtering logic is duplicated: Layer::query_rows_with in crates/map/src/lib.rs already does it, and eval_in_chunk duplicates matches with an offset. Consider sharing one helper. Left for the release quality pass.
  • The share.exportLayer params string puts its prose after the closing brace (share.rs:285), unlike the other entries that keep prose inside the JSON. Check how the Assistant and MCP render it. Left for the release quality pass.
  • let ds = &dataset; in lib.rs adds nothing. Left for the release quality pass.

Never silent

  • Low-medium, about 40% confidence: filter_dataset and write_source_filtered discard parse errors with .ok() (crates/data/src/export.rs:161). An unparseable query exports every feature with no notice. Drawing ignores such a query too, so this matches the map, but the user asked for a filter and gets none. Refusing the export or adding a notice would fit the rule better.

AGENTS.md

  • The changes follow the rules: unwrap appears only in tests, the shared export command runs in the background with Cancel, ui.exportLayer and the browser path are covered, and the tests check both the lossy and clean cases.
  • Two items for the PR author: the desktop and browser are covered, but the PR should state whether the ribbon, shortcuts, and command search need any change (the PR body covers the rest of the surfaces). The Python docstring change has no test.

Low-confidence observations (not posted)

  • Export evaluates queries with Env::default(), so page variables such as @page_number read as null. A layout's series-page query can therefore exclude every row. The notice reports the count, so this is not silent, but the reason is unexplained.

Prior reviews: none on this PR, so no earlier concerns were left alone.

Change size

Compared: the whole PR against main (merge base fd81ab2 to PR head 7d7877f).

Measure Value
Files changed 8 (0 added, 8 modified, 0 removed, 0 renamed)
Size before 734.6 KB
Size after 745.6 KB
Total size change +10.0 KB
Path Before After Change
crates/engine/src/tests/write_notices.rs 22.7 KB 25.3 KB +2.6 KB
crates/data/src/export.rs 13.3 KB 15.7 KB +2.4 KB
crates/ui-egui/src/lib.rs 486.0 KB 487.8 KB +1.8 KB
crates/engine/src/cmd/share.rs 43.2 KB 44.6 KB +1.4 KB
crates/data/src/export/tests.rs 30.1 KB 31.1 KB +1.1 KB
crates/data/src/query.rs 88.3 KB 88.8 KB +0.5 KB
apps/rustgis-python/python/rustgis/init.py 36.4 KB 36.5 KB +0.2 KB
docs/user-guide/sharing.md 13.7 KB 13.9 KB +0.1 KB

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2417/
Web app https://preview.rustgis.app/pr-2417/app/
Commit 4c15747

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

Comment thread crates/data/src/export.rs Outdated
}
if filtered > 0 {
let mut keep = keep.into_iter();
ds.to_mut().features.retain(|_| keep.next().unwrap_or(false));

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.

Performance (medium, about 70% confidence). This is the memory concern from the earlier threads, narrowed but still present. ds is Cow::Borrowed(&l.dataset) on the in-memory path (share.rs and the browser download). Dataset clones share the Features Arc, so the first to_mut() / DerefMut retain calls Arc::make_mut, which deep-clones every feature in the layer, then drops the excluded ones. A query that excludes a single row of a large layer therefore still needs about twice the layer's memory at export time.

Suggested direction: when the input is borrowed, copy only the kept rows, for example:

let kept: Vec<Feature> = ds.features.iter().zip(keep).filter(|(_, k)| *k).map(|(f, _)| f.clone()).collect();
ds.to_mut().features = kept.into();

Keep the in-place retain for Cow::Owned, where the Arc is already unique, so streamed whole reads don't pay an extra copy. The Features::from(Vec) conversion is already used by the chunk path. The two earlier threads (share.rs full clone, lib.rs web clone) are answered for the unfiltered case but this path still doubles memory whenever any row is excluded.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Confirmed that retain on the borrowed path called Arc::make_mut and cloned the full feature vector before dropping excluded rows. The borrowed path now copies just the matching rows into a new Features value while preserving source order. The owned path still retains rows in place. The existing export tests passed locally.

c99d9bd9f5 passed fork CI.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • No confirmed correctness bugs in the export paths. I traced the row-offset logic for @row_number across chunks, the notice plumbing for success, refusal and the browser download, and the Cow borrow patterns in ui-egui. All hold up. The browser filter_dataset call is compiled on wasm because export is not cfg-gated in data/src/lib.rs.
  • Low confidence (~30%): total + filtered as the chunk row offset ignores rows the source skipped as unreadable (batch.skipped), so @row_number shifts after an unreadable row. Not silent, but the numbering can differ from the source.

Security

  • None found. The query is parsed with the existing parse_fields, and parse failures are reported.

Performance

  • Medium (~70%): filtering a borrowed in-memory layer deep-copies the whole layer, not only the kept rows (crates/data/src/export.rs:172). Arc::make_mut runs on the first retain, so any query that excludes a row doubles peak memory. This is the same concern as the earlier share.rs and ui-egui threads, narrowed to the filtered case, and I posted it inline with a direction for the fix.

Quality (nits, grouped; per AGENTS these may wait for the release quality pass)

  • write_source_to has no callers left in the workspace after this change. Keep it as public API or remove it.
  • write_chunks_as now takes a (bytes, query) tuple parameter, which reads awkwardly.
  • The share.exportLayer doc comment in crates/engine/src/cmd/share.rs (around lines 611–615) has uneven line wrapping.
  • The notice says "of the source features" even for in-memory layers, where "layer features" would be more precise.

AGENTS.md

  • Checked the rules that apply: no unwrap/expect in non-test code, the notice is emitted through NoticeText and counted, the export runs in the background via export_start, Cancel is checked in the filter loop (progress::step), the wasm build path is preserved, the PR body states the surfaces reached, and the docs were updated. No violations found.
  • The new test covers in-memory, streamed shapefile and background streamed GeoPackage cases, with and without a query, plus a chunk-boundary GeoJSON test.

Prior threads: 4 earlier threads on this PR. Two are answered and left alone: the unreadable-query .ok() silence (now reported) and the per-chunk layer.clone() (now built once). Two are re-raised in narrowed form as the single inline comment above, because the filtered path still doubles memory.

Change size

Compared with the base branch (merge base fd81ab2 to PR head 0364bf2): the whole PR against main.

Measure Value
Files changed 8 (0 added, 8 modified, 0 removed, 0 renamed)
Size before 734.1 KB
Size after 748.2 KB
Total size change +12.6 KB
Path Before After Change
crates/data/src/export.rs 13.3 KB 16.7 KB +3.5 KB
crates/engine/src/tests/write_notices.rs 22.7 KB 25.9 KB +3.2 KB
crates/engine/src/cmd/share.rs 43.2 KB 45.3 KB +2.2 KB
crates/ui-egui/src/lib.rs 486.1 KB 488.2 KB +2.0 KB
crates/data/src/export/tests.rs 30.1 KB 31.1 KB +1.1 KB
crates/data/src/query.rs 88.3 KB 88.8 KB +0.5 KB
apps/rustgis-python/python/rustgis/init.py 36.4 KB 36.5 KB +0.2 KB
docs/user-guide/sharing.md 13.7 KB 13.9 KB +0.1 KB

Comment thread crates/data/src/export.rs
kept.try_reserve_exact(len - filtered).map_err(|_| DataError::Format("not enough memory to filter export rows".into()))?;
for feature in source.kept_features(&keep) {
crate::progress::check()?;
kept.push(feature.clone());

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.

Performance (medium, about 60% confidence). Re-raised because the code changed and the cost is still there.

The borrowed branch now copies only kept rows, which fixes the Arc::make_mut clone of excluded rows. But kept.push(feature.clone()) deep-clones every kept feature (geometry vectors and Text attributes). When a query is set on an in-memory layer, peak memory is the layer plus a full copy of the kept rows, roughly 2x for a query that keeps most rows. Without a query there is no copy.

The chunk path avoids this because it filters one chunk at a time. Routing the in-memory export through the same chunk writer, or writing the kept rows in CHUNK_BYTES-sized batches, would keep the peak near one chunk. If that is out of scope for this PR, say so in the description.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Confirmed the kept-row copy. I documented it in the PR description. The chunk writer covers only some native formats. Removing this copy across the whole-dataset writers and browser downloads would require a separate writer change.

4c15747abe passed fork CI.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • Data Interop ignores the definition query (medium, about 70%). data.convert reads the layer through feature_ds (crates/engine/src/cmd/workflows.rs:109), which returns the unfiltered &l.dataset. convert_work (lines 1909–1957) never applies definition_query on either the chunk path (line 1921) or the whole-read path (line 1957). A filtered layer converts with every row and no notice, which breaks the "never silent" rule. This file is not in the PR diff, so I could not post it inline. The PR covers exports in general and the sharing guide says Data Interop converts layers, so either apply the query there or state in the PR that Data Interop is left out.
  • Unreadable saved query exports unfiltered (answered, left alone). The author now emits a notice with the parser error and keeps the rows, matching how the map draws the layer. That is acceptable under "never silent."

Security

  • None found. The query text comes from the project file and is parsed with parse_fields. The allocations are sized by the dataset length, and nothing unsafe was added.

Performance

  • Kept-row copy still roughly doubles memory (medium, about 60%). Posted inline at crates/data/src/export.rs:177. The earlier thread's concern is still present in the new code: a set query on an in-memory layer deep-clones every kept feature. This is re-raised because the code changed and the cost remains.
  • Query evaluation is single-threaded (low, about 30%). retain_matches evaluates rows sequentially. The writers are sequential too, so this is probably acceptable, but the AGENTS threading rule asks for a reason if the work could be split.

Quality (grouped nits; these fall under the release quality pass)

  • progress::begin(len) in retain_matches (crates/data/src/export.rs) resets the count that load_all_counted already advanced for streamed whole reads. The progress bar jumps back to zero (about 50%, cosmetic).
  • The share.exportLayer params string (crates/engine/src/cmd/share.rs:332) now puts prose after the closing brace. Other commands keep descriptions inside the braces. Parsing is unaffected because the text is only stored (lib.rs:177).
  • write_chunks_as takes its last parameter as a tuple (bytes, query). This is a style choice only.

AGENTS.md

  • Reach-every-surface and never-silent are addressed for Export Features (desktop, background job, CLI, Python, browser, tests both ways). The Data Interop gap above is the exception.
  • No new background command was added, so long_commands needs no change. The new per-row check in retain_matches is covered by progress::step.

Prior threads: 5 earlier concerns on this PR. 4 are fixed in the new code (per-export dataset clone, per-chunk layer clone, full make_mut clone, web-download clone). 1 was answered by the author with a notice (silent parse error). I left all 5 alone except the kept-row copy above, which I re-raised with new evidence.

Not verified: the new test covers empty chunks only for GeoJSON. Empty chunks are now passed to the GeoPackage, FlatGeobuf, Parquet and CSV writers, and I did not confirm they handle that.

Change size

Compared with the base branch, merge base fd81ab2 to PR head c99d9bd.

Measure Value
Files changed 8 (0 added, 8 modified, 0 removed, 0 renamed)
Size before 734.6 KB
Size after 747.2 KB
Total size change +13.2 KB
Path Before After Change
crates/data/src/export.rs 13.3 KB 17.3 KB +4.0 KB
crates/engine/src/tests/write_notices.rs 22.7 KB 25.9 KB +3.2 KB
crates/engine/src/cmd/share.rs 43.2 KB 45.3 KB +2.2 KB
crates/ui-egui/src/lib.rs 486.0 KB 488.0 KB +2.0 KB
crates/data/src/export/tests.rs 30.1 KB 31.1 KB +1.1 KB
crates/data/src/query.rs 88.3 KB 88.8 KB +0.5 KB
apps/rustgis-python/python/rustgis/init.py 36.4 KB 36.5 KB +0.2 KB
docs/user-guide/sharing.md 13.7 KB 13.9 KB +0.1 KB

…on-query

# Conflicts:
#	crates/ui-egui/src/lib.rs
@Mavrick-F

Copy link
Copy Markdown
Member Author

Data Interop now shares Export Features’ query filtering and notices. The regression covers text conversion, streamed GeoJSON, and a whole-source WKT conversion, each with and without a query. I checked the empty-chunk paths in the writers. CSV and FlatGeobuf iterate features, Parquet creates row groups only for nonempty batches, and GeoPackage inserts zero rows and can replay the feed if a later chunk needs a different geometry layout. The progress reset, parameter prose placement, tuple argument, and threading are left for the release quality pass.

4c15747abe passed fork CI.

Comment thread crates/data/src/export.rs
let batch = src.visit_chunks(None, bytes, &mut |mut chunk| {
if let Some((expr, input)) = &mut scratch {
input.to_mut().features = chunk.into();
filtered += retain_matches(input, expr, total.saturating_add(filtered), false)?;

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.

Bugs (low-medium, about 50% confidence). Streamed exports number @row_number by source position: offset is total + filtered, so rows are numbered across chunks. The streamed map view evaluates the same query per chunk, with positions restarting at each chunk (crates/map/src/source/window.rs:164). The same definition query can therefore select different rows on screen than in the export. The export's numbering is arguably the more correct one, but the PR doesn't say the two differ. Either note it in docs/user-guide/sharing.md and the PR, or align the view in a follow-up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Confirmed. The export numbers rows by position in the whole layer, which is what @row_number means. The streamed map view restarting at each chunk is the older bug, so it is now on #1998 to fix in the view rather than here.

Comment thread crates/data/src/export.rs
let mut filtered = 0;
for row in 0..len {
crate::progress::step(usize::from(count_progress))?;
let matches = query::eval_in_chunk(expr, ds, row, offset);

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.

Never silent (low, about 35% confidence). eval_in_chunk returns cond == Some(true), so a row whose evaluation faults (division by zero, a type error that gives null) is dropped. The export then counts it as "left out by the definition query" with no mention of the fault. The fault is kept in Eval (value_or_fault) but only the field calculator reads it. The count is accurate, but the reason is not reported. Consider counting faulting rows separately in QueryReport and saying so in the notice, or documenting that a faulting row is excluded.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Leaving this as is. A row whose condition evaluates to null or faults is not drawn by the map view either, so the export writes the rows the map shows, as SQL WHERE does. Reporting faults separately would be a change to the query language, not to export, and is left for the release quality pass.

Comment thread crates/data/src/export.rs
kept.try_reserve_exact(len - filtered).map_err(|_| DataError::Format("not enough memory to filter export rows".into()))?;
for feature in source.kept_features(&keep) {
crate::progress::check()?;
kept.push(feature.clone());

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.

Re-raised, with new evidence. The author's reply says the kept-row copy (about 2x peak memory for an in-memory layer when the query keeps most rows) is "documented in the PR description". The current PR body (pr-context/metadata.json) has no such note. The code is unchanged here, so the cost is still there. Please add the memory note to the description, or drop the claim. The code can stay as it is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The description has it now (Summary, last line): "A filtered in-memory export briefly holds a copy of the kept rows because bounded writing across the whole-dataset and browser formats requires a separate writer change." The metadata you read was probably from before that edit.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I checked the source the diff touches, not just the diff. I found no crash paths, no silent loss on the paths I traced, and no unsafe use. The chunk-offset arithmetic, the Features sharing, the Cow copy-on-filter, the cancel checks and the parse-error notice all hold up. The findings below are the three I posted inline.

Bugs

  • @row_number differs between the streamed map view and the export (low-medium, about 50%). The export numbers rows by source position across chunks. The streamed view numbers them per chunk (crates/map/src/source/window.rs:164), so the same query can select different rows on screen and in the file. The PR doesn't mention this. Posted at crates/data/src/export.rs:273.

Security

  • None found.

Performance

  • The kept-row copy on the in-memory path is still there (export.rs:192). This was already raised and answered. I re-raised it only because the reply says the memory cost is documented in the PR description, and the staged body doesn't mention it (about 2x peak for an in-memory layer when the query keeps most rows). Posted at crates/data/src/export.rs:192.

Quality

  • Rows whose query evaluation faults are dropped and counted as query exclusions without the reason (low, about 35%). Posted at crates/data/src/export.rs:181.
  • Nits, for the release quality pass: the function-local use std::borrow::Cow; repeats in share.rs, workflows.rs (twice) and ui-egui/src/lib.rs; "left out 1 of the source features" reads awkwardly; docs/user-guide/sharing.md line 814 and the share.rs doc comment near line 358 run past the surrounding wrap.

AGENTS.md

  • Checked and consistent: the parse-error and count notices use Session::notify/notify_text with one notice per kind; both the background and the direct paths are covered by tests; share.exportLayer already sits in the cancellation lists; query.rs changes stay in the expression vocabulary; no wasm-only or desktop-only code was added without cfg. I did not compile or run tests.
  • Not verified: whether the phone (ui-touch) surface is reached, as the description claims.

Prior threads

  • 6 earlier threads. 5 were answered and their code changed, so I left them alone. The sixth (kept-row copy) is re-raised above with new evidence. Nothing else was re-raised.

Change size

Compared: the whole PR against main (merge base 5f49f29 to PR head 4c15747).

Measure Value
Files changed 9 (0 added, 9 modified, 0 removed, 0 renamed)
Size before 841.7 KB
Size after 858.5 KB
Total size change +16.8 KB
Path Before After Change
crates/engine/src/tests/write_notices.rs 22.7 KB 28.2 KB +5.5 KB
crates/data/src/export.rs 13.3 KB 17.8 KB +4.5 KB
crates/engine/src/cmd/share.rs 43.1 KB 45.3 KB +2.2 KB
crates/ui-egui/src/lib.rs 487.4 KB 489.4 KB +2.0 KB
crates/data/src/export/tests.rs 30.8 KB 31.9 KB +1.1 KB
crates/engine/src/cmd/workflows.rs 106.0 KB 106.8 KB +0.8 KB
crates/data/src/query.rs 88.3 KB 88.8 KB +0.5 KB
apps/rustgis-python/python/rustgis/init.py 36.4 KB 36.5 KB +0.2 KB
docs/user-guide/sharing.md 13.7 KB 13.9 KB +0.1 KB

@Mavrick-F Mavrick-F mentioned this pull request Nov 18, 2026
56 of 63 tasks
@Mavrick-F
Mavrick-F added this pull request to the merge queue Nov 18, 2026
Merged via the queue into opengeos:main with commit 62526f0 Nov 18, 2026
26 checks passed
@Mavrick-F
Mavrick-F deleted the fix/export-definition-query branch November 18, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant