Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

fix(ingest): format Parquet cells instead of entire columns

Rudy Celeklif2f3b5f40d9a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3d864085..60ca1c85 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -46,6 +46,10 @@ All notable changes to Open Ontologies are documented here.
### Fixed
+- Parquet ingest formats each non-primitive cell with Arrow's value formatter,
+ preserving date and decimal lexical values instead of embedding a debug dump
+ of the complete column in every row. Formatting errors fail the import.
+
- **The embedding model is loaded once per process rather than once per HTTP
session** (#262). The HTTP arm hands the same server constructor to
`StreamableHttpService::new` as a per-session factory, so everything that
diff --git a/src/ingest.rs b/src/ingest.rs
index 2f6ed7ad..bc686bac 100644
--- a/src/ingest.rs
+++ b/src/ingest.rs
@@ -292,6 +292,12 @@ impl DataIngester {
String::new()
} else {
Self::arrow_array_value_to_string(col.as_ref(), row_idx, field.data_type())
+ .with_context(|| {
+ format!(
+ "Failed to format Parquet column {} row {row_idx}",
+ field.name()
+ )
+ })?
};
row.insert(field.name().clone(), value);
}
@@ -306,11 +312,11 @@ impl DataIngester {
array: &dyn arrow::array::Array,
idx: usize,
data_type: &arrow::datatypes::DataType,
- ) -> String {
+ ) -> Result<String> {
use arrow::array::*;
use arrow::datatypes::DataType as ArrowType;
- match data_type {
+ Ok(match data_type {
ArrowType::Boolean => {
let a = array.as_any().downcast_ref::<BooleanArray>().unwrap();
a.value(idx).to_string()
@@ -363,10 +369,12 @@ impl DataIngester {
let a = array.as_any().downcast_ref::<LargeStringArray>().unwrap();
a.value(idx).to_string()
}
- _ => format!("{array:?}[{idx}]"),
- }
+ // Format this cell, never the whole column's Debug view. Dates,
+ // timestamps and scaled decimals otherwise include every other
+ // row's value in the string assigned to this one.
+ _ => arrow::util::display::array_value_to_string(array, idx)?,
+ })
}
-
/// Read a whole text file into memory, refusing anything over the ingest cap.
/// Ingest reads the entire file at once, so an unbounded read is an
/// out-of-memory lever for any caller that can point the tool at a large file.
diff --git a/tests/ingest_parquet_cell_test.rs b/tests/ingest_parquet_cell_test.rs
new file mode 100644
index 00000000..049b06fc
--- /dev/null
+++ b/tests/ingest_parquet_cell_test.rs
@@ -0,0 +1,73 @@
+use arrow::array::{Date32Array, Decimal128Array, Int64Array, StringArray};
+use arrow::datatypes::{DataType, Field, Schema};
+use arrow::record_batch::RecordBatch;
+use open_ontologies::ingest::DataIngester;
+use parquet::arrow::ArrowWriter;
+use std::sync::Arc;
+
+#[test]
+fn parquet_cells_keep_their_own_date_decimal_and_null_values() {
+ let dir = tempfile::tempdir().unwrap();
+ let file = dir.path().join("dates.parquet");
+ let schema = Arc::new(Schema::new(vec![
+ Field::new("id", DataType::Utf8, false),
+ Field::new("date", DataType::Date32, true),
+ Field::new("amount", DataType::Decimal128(6, 2), true),
+ Field::new("count", DataType::Int64, false),
+ ]));
+ let batch = RecordBatch::try_new(
+ schema.clone(),
+ vec![
+ Arc::new(StringArray::from(vec!["one", "two", "three"])),
+ Arc::new(Date32Array::from(vec![Some(20727), Some(20728), None])),
+ Arc::new(
+ Decimal128Array::from(vec![Some(1234), Some(5678), None])
+ .with_precision_and_scale(6, 2)
+ .unwrap(),
+ ),
+ Arc::new(Int64Array::from(vec![10, 20, 30])),
+ ],
+ )
+ .unwrap();
+ let mut writer =
+ ArrowWriter::try_new(std::fs::File::create(&file).unwrap(), schema, None).unwrap();
+ writer.write(&batch).unwrap();
+ writer.close().unwrap();
+ let rows = DataIngester::parse_file(file.to_str().unwrap()).unwrap();
+ assert_eq!(rows.len(), 3);
+ assert_eq!(rows[0]["date"], "2026-10-01");
+ assert_eq!(rows[1]["date"], "2026-10-02");
+ assert_eq!(rows[0]["amount"], "12.34");
+ assert_eq!(rows[1]["amount"], "56.78");
+ assert_eq!(rows[2]["date"], "");
+ assert_eq!(rows[2]["amount"], "");
+ assert_eq!(rows[0]["id"], "one");
+ assert_eq!(rows[1]["count"], "20");
+}
+
+#[test]
+fn primitive_and_null_parquet_cells_keep_existing_lexical_values() {
+ let dir = tempfile::tempdir().unwrap();
+ let file = dir.path().join("primitives.parquet");
+ let schema = Arc::new(Schema::new(vec![
+ Field::new("name", DataType::Utf8, true),
+ Field::new("count", DataType::Int64, true),
+ ]));
+ let batch = RecordBatch::try_new(
+ schema.clone(),
+ vec![
+ Arc::new(StringArray::from(vec![Some("one"), None])),
+ Arc::new(Int64Array::from(vec![Some(10), None])),
+ ],
+ )
+ .unwrap();
+ let mut writer =
+ ArrowWriter::try_new(std::fs::File::create(&file).unwrap(), schema, None).unwrap();
+ writer.write(&batch).unwrap();
+ writer.close().unwrap();
+ let rows = DataIngester::parse_file(file.to_str().unwrap()).unwrap();
+ assert_eq!(rows[0]["name"], "one");
+ assert_eq!(rows[0]["count"], "10");
+ assert_eq!(rows[1]["name"], "");
+ assert_eq!(rows[1]["count"], "");
+}