Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions apps/rustgis-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,8 @@ impl Engine {
.unwrap_or_default();
let (ds, report) = found.load_all_reported().map_err(|e| format!("{}: {e}", found.name))?;
let name = found.name.clone();
match report.skipped {
0 => {}
1 => session.warn(format!("{name}: 1 row couldn't be read and was left out")),
n => session.warn(format!("{name}: {n} rows couldn't be read and were left out")),
if report.skipped > 0 {
session.say(rustgis_engine::cmd::whole::unread_note(&name, report.skipped));
}
// A Z/M loss this export says from its read; one said only when the layer opened
// isn't said here again, so the export's own note says it.
Expand All @@ -249,7 +247,7 @@ impl Engine {
// a feature with a place that can't be given there is in it without its geometry.
let (lonlat, unplaced) = ds.in_lonlat_leaving_out()?;
if let Some(note) = rustgis_engine::data::unplaced_note(&format!("{name} as GeoJSON"), &ds.name, unplaced) {
session.notify(note, false);
session.say(note);

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.

This changed export path is coded, but the "rows couldn't be read" notice a few lines up (lib.rs 224-228, not in this diff) is still a plain session.warn, so it carries no loss code. Python's loss warnings and --strict won't see it. Every other path that says this notice now uses whole::unread_note, which carries dropped.feature (whole.rs Unread::say, share.rs write_layer, workflows.rs convert, the ui-egui download). The PR says the codes reach "the rows a whole read can't read", and this path misses that.

Suggested fix for 224-228, keeping the wording (unread_note wraps unread_notice, so test_session.py's match still passes):

if report.skipped > 0 {
    session.say(rustgis_engine::cmd::whole::unread_note(&name, report.skipped));
}

report.skipped is a usize, and name is defined on line 223. Confidence: high that the notice is uncoded.

Category: bug

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.

Fixed in 38ff798: the Python GeoJSON export says its unread rows with whole::unread_note, dropped.feature, in the same words.

}
return Ok(rustgis_engine::data::io::to_geojson(&lonlat).to_string());
}
Expand All @@ -267,7 +265,7 @@ impl Engine {
session.say(note);
}
if let Some(note) = unplaced {
session.notify(note, false);
session.say(note);
}
return Ok(text);
}
Expand Down Expand Up @@ -302,7 +300,7 @@ impl Engine {
session.say(note);
}
if let Some(note) = rustgis_engine::data::unplaced_note(&format!("{} as GeoJSON", ds.name), &ds.name, unplaced) {
session.notify(note, false);
session.say(note);
}
Ok::<String, String>(text)
});
Expand Down
2 changes: 1 addition & 1 deletion crates/data/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct Exported {
/// empty for the other formats).
pub written_values: Vec<usize>,
/// GeoParquet timestamp representation changes counted during export.
pub date_messages: Vec<String>,
pub date_messages: Vec<crate::loss::Note>,
/// What reading the source lost or assumed besides the counts above
/// ([`crate::source::Batch::notes`]), said as they are.
pub read_notes: crate::loss::Notes,
Expand Down
7 changes: 4 additions & 3 deletions crates/data/src/export/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,11 @@ fn geoparquet_counts_values_written_as_null() {
assert_eq!(streamed.unfit, vec![0, 2, 1, 1]);
let note = crate::source::parquet::unfit_note(&layer.fields, &streamed.unfit, "lossy.parquet").unwrap();
assert_eq!(
note,
note.as_str(),
"lossy.parquet: 4 values couldn't be written as their columns' types and were written as null, in 'count', 'share', 'open'"
);
assert_eq!(crate::source::parquet::values_note(&ds, "lossy.parquet").as_deref(), Some(note.as_str()));
assert_eq!(note.loss, Some(crate::loss::LossCode::DroppedValue));
assert_eq!(crate::source::parquet::values_note(&ds, "lossy.parquet").as_ref().map(crate::loss::Note::as_str), Some(note.as_str()));
let back = read_back(&d.join("lossy.parquet"));
assert_eq!((&back.features[1].attrs[1], &back.features[3].attrs[3]), (&Value::Null, &Value::Null));

Expand All @@ -543,7 +544,7 @@ fn geoparquet_counts_values_written_as_null() {
let fields = vec![Field::new("a\u{202E}b\nc", FieldType::Integer), Field::new("x".repeat(60), FieldType::Integer)];
let note = crate::source::parquet::unfit_note(&fields, &[1, 1], "out\u{2028}.parquet").unwrap();
let want = "out .parquet: 2 values couldn't be written as their columns' types and were written as null, in 'a b c'";
assert_eq!(note, format!("{want}, '{}…'", "x".repeat(40)));
assert_eq!(note.as_str(), format!("{want}, '{}…'", "x".repeat(40)));
let _ = std::fs::remove_dir_all(d);
}

Expand Down
366 changes: 274 additions & 92 deletions crates/data/src/io.rs

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions crates/data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,9 +815,12 @@ fn layer_list(names: &[&str]) -> String {
/// What `what` (an export to a file, a copy, a package: "{target}") says of the `n` features of
/// `layer` it took without their geometry, as a place of each can't be given in
/// longitude/latitude ([`Dataset::in_lonlat_leaving_out`]). `None` for none.
pub fn unplaced_note(target: &str, layer: &str, n: usize) -> Option<String> {
pub fn unplaced_note(target: &str, layer: &str, n: usize) -> Option<loss::Note> {
(n > 0).then(|| {
format!("{target}: {n} feature(s) of {layer} have a place that can't be given in longitude/latitude, so their geometry is left out (and the feature, where only features with geometry are kept)")
loss::Note::loss(
loss::LossCode::DroppedGeometry,
format!("{target}: {n} feature(s) of {layer} have a place that can't be given in longitude/latitude, so their geometry is left out (and the feature, where only features with geometry are kept)"),
)
})
}

Expand Down
16 changes: 13 additions & 3 deletions crates/data/src/loss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ macro_rules! loss_codes {

loss_codes! {
DroppedLegend => ("dropped.legend", Dropped, "Use a service with short HTTP or HTTPS addresses for its legend pictures."),
DroppedRing => ("dropped.ring", Dropped, "Correct the unreadable polygon ring in the source."),
DroppedRing => ("dropped.ring", Dropped, "Correct the unreadable polygon ring in the source, or write to a format that holds holes, such as GeoPackage."),
DroppedExtraAttributes => (
"dropped.extra-attributes",
Dropped,
Expand All @@ -81,7 +81,7 @@ loss_codes! {
DroppedCrsName => (
"dropped.crs-name",
Dropped,
"Keep the source file's coordinate system definition with the export."
"Keep the source file's coordinate system definition with the export, or export in WGS 84, which every format can name."
),
DroppedFeature => (
"dropped.feature",
Expand All @@ -99,6 +99,16 @@ loss_codes! {
"Read less at once, such as by filtering or clipping the source first."
),
ChangedTruncated => ("changed.truncated", Changed, "Use a decimal field to keep the fractional part."),
ChangedFieldName => (
"changed.field-name",
Changed,
"Use field names the format holds: at most 10 bytes and unique ignoring case for a Shapefile, unique ignoring case for a GeoPackage."
),
ChangedCut => (
"changed.cut",
Changed,
"Shorten the text to what the format holds (254 bytes for a Shapefile; nothing past a NUL character), or write to a format without the limit, such as GeoPackage."
),
ChangedBody => ("changed.body", Changed, "Export in the layer's own coordinate system, which keeps its body."),
ChangedEncoding => (
"changed.encoding",
Expand All @@ -108,7 +118,7 @@ loss_codes! {
ChangedRounded => (
"changed.rounded",
Changed,
"Keep the source file where times finer than a microsecond matter."
"Keep the source file where finer values matter, or write to a format that holds them (times finer than the format keeps, or numbers past a dBase field's precision)."
),
ChangedPosition => (
"changed.position",
Expand Down
2 changes: 1 addition & 1 deletion crates/data/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ pub fn shapefile(ds: &Dataset, path: &Path, synced: &Synced) -> Result<Published

// 3. The layer, written, reads back as the layer.
if let Some(note) = crate::io::shapefile_names_note(&ds.fields, &name) {
return Err(refused(path, note));
return Err(refused(path, note.text));
}
crate::progress::begin(ds.features.len());
let (mut parts, left_out, widened) = crate::io::shapefile_parts_styled(&*in_file(ds, crs, as_held)?, written_crs, Some(&style))?;
Expand Down
42 changes: 30 additions & 12 deletions crates/data/src/source/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1733,19 +1733,25 @@ impl DateLayout {
}
/// Counts each representation change and names its fields for the user-facing export notice,
/// each after `target: ` (nothing before it when `target` is empty: the caller adds the path).
fn notes(&self, fields: &[Field], target: &str) -> Vec<String> {
/// An offset left out is a value lost; ISO text keeps the value.
fn notes(&self, fields: &[Field], target: &str) -> Vec<crate::loss::Note> {
let target: String = target.chars().map(crate::io::dbf_notice_char).collect();
let target = if target.is_empty() { String::new() } else { format!("{target}: ") };
let mut notes = Vec::new();
let utc: Vec<usize> = self.offsets.iter().enumerate().map(|(k, &n)| if self.modes.get(k) == Some(&2) { n } else { 0 }).collect();
let text: Vec<usize> = self.counts.iter().enumerate().map(|(k, &n)| if self.modes.get(k) == Some(&3) { n } else { 0 }).collect();
for (counts, what) in [
(&utc, "date-times were written in UTC without their original offsets"),
(&text, "date-times were written as ISO text because their column mixes zoned and unzoned values"),
for (counts, what, lost) in [
(&utc, "date-times were written in UTC without their original offsets", true),
(&text, "date-times were written as ISO text because their column mixes zoned and unzoned values", false),
] {
let n: usize = counts.iter().sum();
if n > 0 {
notes.push(format!("{target}{n} {what}, in {}", crate::io::named_fields(fields, counts)));
let text = format!("{target}{n} {what}, in {}", crate::io::named_fields(fields, counts));
notes.push(if lost {
crate::loss::Note::loss(crate::loss::LossCode::DroppedValue, text)
} else {
crate::loss::Note::plain(text)
Comment on lines +1749 to +1753

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.

Nit: this let text = format!(...) shadows the text: Vec<usize> counts bound a few lines up (line 1742), and the loop's array reads that binding before the shadow. It compiles and behaves correctly, but a reader has to check which text is meant. Naming the line line removes the ambiguity:

Suggested change
let text = format!("{target}{n} {what}, in {}", crate::io::named_fields(fields, counts));
notes.push(if lost {
crate::loss::Note::loss(crate::loss::LossCode::DroppedValue, text)
} else {
crate::loss::Note::plain(text)
let line = format!("{target}{n} {what}, in {}", crate::io::named_fields(fields, counts));
notes.push(if lost {
crate::loss::Note::loss(crate::loss::LossCode::DroppedValue, line)
} else {
crate::loss::Note::plain(line)
});

Confidence: high that it is harmless; this is a naming point only.

Category: quality

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.

Left for the release quality pass: it compiles and behaves as intended.

});
}
}
notes
Expand Down Expand Up @@ -1789,7 +1795,7 @@ fn unfit(ty: FieldType, value: &Value) -> bool {
/// The notice for values a GeoParquet export wrote as null because their column's type couldn't
/// hold them, given the count per field (as `write_features` returns); `None` when there are
/// none. Names the first five fields.
pub fn unfit_note(fields: &[Field], counts: &[usize], target: &str) -> Option<String> {
pub fn unfit_note(fields: &[Field], counts: &[usize], target: &str) -> Option<crate::loss::Note> {
let total = counts.iter().fold(0usize, |a, n| a.saturating_add(*n));
if total == 0 {
return None;
Expand All @@ -1804,12 +1810,15 @@ pub fn unfit_note(fields: &[Field], counts: &[usize], target: &str) -> Option<St
format!("{total} values couldn't be written as their columns' types and were")
};
let target: String = target.chars().map(crate::io::dbf_notice_char).collect();
Some(format!("{target}: {what} written as null, in {}{more}", list.join(", ")))
Some(crate::loss::Note::loss(
crate::loss::LossCode::DroppedValue,
format!("{target}: {what} written as null, in {}{more}", list.join(", ")),
))
}

/// Export notices for the whole of `ds`: unfit values and timestamp representation changes.
/// Cancellation omits notices; the following writer's check returns the cancellation error.
pub fn values_note(ds: &crate::Dataset, target: &str) -> Option<String> {
pub fn values_note(ds: &crate::Dataset, target: &str) -> Option<crate::loss::Note> {
let mut counts = vec![0usize; ds.fields.len()];
let mut layout = DateLayout::default();
for chunk in ds.features.chunks(BATCH) {
Expand All @@ -1824,9 +1833,18 @@ pub fn values_note(ds: &crate::Dataset, target: &str) -> Option<String> {
}
}
}
let mut notes: Vec<String> = unfit_note(&ds.fields, &counts, target).into_iter().collect();
notes.extend(layout.notes(&ds.fields, target));
if notes.is_empty() { None } else { Some(notes.join("; ")) }
// One notice: the values written as null, then how date-times are written; coded when either
// loses a value.
let said: Vec<crate::loss::Note> =
unfit_note(&ds.fields, &counts, target).into_iter().chain(layout.notes(&ds.fields, target)).collect();
let loss = said.iter().find_map(|n| n.loss);
(!said.is_empty()).then(|| {
let text = said.iter().map(|n| n.text.as_str()).collect::<Vec<_>>().join("; ");
match loss {
Some(code) => crate::loss::Note::loss(code, text),
None => crate::loss::Note::plain(text),
}
})
}

/// Writes GeoParquet to `out`: the features `feed` hands to the function it is given, a run at
Expand All @@ -1844,7 +1862,7 @@ pub(crate) fn write_features<W: std::io::Write + Send>(
crs: Crs,
out: W,
feed: &mut dyn FnMut(&mut dyn FnMut(&[Feature]) -> Result<()>) -> Result<()>,
) -> Result<(W, Vec<usize>, Vec<String>)> {
) -> Result<(W, Vec<usize>, Vec<crate::loss::Note>)> {
use parquet::basic::{Compression, Encoding, Repetition, ZstdLevel};
use parquet::data_type::{BoolType, ByteArray, ByteArrayType, DoubleType, Int32Type, Int64Type};
use parquet::file::metadata::KeyValue;
Expand Down
34 changes: 24 additions & 10 deletions crates/data/src/source/postgis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,26 +1354,31 @@ fn count_offset(saved: &mut Saved, field: usize, column: &str, v: &Value) {
/// What saving to `table` says of the date-times its columns didn't keep as they were
/// ([`Saved::utc_dates`], [`Saved::zoneless_dates`], [`Saved::assumed_utc`]), naming the fields
/// of `fields` they were in.
pub fn saved_dates_notes(fields: &[Field], saved: &Saved, table: &str) -> Vec<String> {
pub fn saved_dates_notes(fields: &[Field], saved: &Saved, table: &str) -> Vec<crate::loss::Note> {
let table: String = table.chars().map(crate::io::dbf_notice_char).collect();
let kinds: [(&[usize], &str, &str); 3] = [
(&saved.utc_dates, "1 date-time was saved in UTC, without its offset", "date-times were saved in UTC, without their offsets"),
// An offset left out is a value lost; a date-time without one saved as UTC keeps its clock time.
let kinds: [(&[usize], &str, &str, bool); 3] = [
(&saved.utc_dates, "1 date-time was saved in UTC, without its offset", "date-times were saved in UTC, without their offsets", true),
(
&saved.zoneless_dates,
"1 date-time was saved at the clock time shown, without its offset",
"date-times were saved at the clock time shown, without their offsets",
true,
),
(&saved.assumed_utc, "1 date-time without a time zone was saved as UTC", "date-times without a time zone were saved as UTC"),
(&saved.assumed_utc, "1 date-time without a time zone was saved as UTC", "date-times without a time zone were saved as UTC", false),
];
let why =
["(a timestamptz column holds only the moment)", "(a timestamp column has no time zone)", "(a timestamptz column holds a moment)"];
kinds
.iter()
.zip(why)
.filter_map(|((counts, one, many), why)| {
.filter_map(|((counts, one, many, lost), why)| {
let total: usize = counts.iter().sum();
let what = if total == 1 { (*one).to_string() } else { format!("{total} {many}") };
(total > 0).then(|| format!("{table}: {what} {why}, in {}", crate::io::named_fields(fields, counts)))
(total > 0).then(|| {
let text = format!("{table}: {what} {why}, in {}", crate::io::named_fields(fields, counts));
if *lost { crate::loss::Note::loss(crate::loss::LossCode::DroppedValue, text) } else { crate::loss::Note::plain(text) }
})
})
.collect()
}
Expand Down Expand Up @@ -2185,12 +2190,21 @@ mod tests {
(&[0, 1][..], &[0, 2][..], &[0, 2][..])
);
let fields = [Field::new("id", FieldType::Integer), Field::new("seen", FieldType::DateTime)];
use crate::loss::LossCode::DroppedValue;
let notes = saved_dates_notes(&fields, &saved, "wells");
assert_eq!(
saved_dates_notes(&fields, &saved, "wells"),
notes.iter().map(|n| (n.text.as_str(), n.loss)).collect::<Vec<_>>(),
[
"wells: 1 date-time was saved in UTC, without its offset (a timestamptz column holds only the moment), in 'seen'",
"wells: 2 date-times were saved at the clock time shown, without their offsets (a timestamp column has no time zone), in 'seen'",
"wells: 2 date-times without a time zone were saved as UTC (a timestamptz column holds a moment), in 'seen'"
(
"wells: 1 date-time was saved in UTC, without its offset (a timestamptz column holds only the moment), in 'seen'",
Some(DroppedValue)
),
(
"wells: 2 date-times were saved at the clock time shown, without their offsets (a timestamp column has no time zone), in 'seen'",
Some(DroppedValue)
),
// Its clock time is kept, read as UTC.
("wells: 2 date-times without a time zone were saved as UTC (a timestamptz column holds a moment), in 'seen'", None)
]
);
assert!(saved_dates_notes(&fields, &Saved::default(), "wells").is_empty());
Expand Down
Loading
Loading