Skip to content
Open
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
10 changes: 10 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ Every level reports through one vocabulary in `problem.rs`: a `Problem` (a `code

Test fixtures for the spec rules are in `crates/data-dict/tests/fixtures/{valid,invalid,spec}/`. Each fixture has a `# expected: ...` header documenting the intended outcome. Integration tests mirror the levels: `tests/validate_spec.rs` / `validate_meta.rs` / `validate_data.rs`.

Every test that asserts a diagnostic error or warning must also include a snapshot assertion:

```rust
diagnostic.assert_contains(&["S07", "expected phrase"]);
#[cfg(unix)]
assert_snapshot!(diagnostic);
```

After adding new snapshot assertions, generate them with `cargo insta test -p data-dict --test validate_spec`, inspect the `.snap.new` files to confirm they look right, then accept with `cargo insta accept --workspace`.

### Problem reporting

Two principles guide how problems are surfaced:
Expand Down
27 changes: 27 additions & 0 deletions crates/data-dict-parquet/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,16 @@ fn parquet_type_to_dict_type(field: &Type) -> String {
LogicalType::Integer { .. } | LogicalType::Float16 | LogicalType::Decimal { .. } => {
return "number".into();
}
LogicalType::List => return parquet_list_to_dict_type(field),
_ => {}
}
}

// Group types with no list logical annotation are structs.
if field.is_group() {
return "struct".into();
}

match field.get_physical_type() {
PhysicalType::BOOLEAN => "boolean".into(),
PhysicalType::INT32 | PhysicalType::INT64 => "number".into(),
Expand All @@ -156,3 +162,24 @@ fn parquet_type_to_dict_type(field: &Type) -> String {
PhysicalType::BYTE_ARRAY | PhysicalType::FIXED_LEN_BYTE_ARRAY => "string".into(),
}
}

/// Map a Parquet LIST-annotated group field to a `list(element_type)` string.
/// Parquet encodes lists as `list<repeated group list { optional/required T element }>`;
/// we descend through the standard wrapper to find the element field.
fn parquet_list_to_dict_type(field: &Type) -> String {
let elem_type = parquet_list_element(field)
.map(|e| parquet_type_to_dict_type(e))
.unwrap_or_else(|| "string".into());
format!("list({elem_type})")
}

/// Navigate the standard Parquet LIST encoding to the element field:
/// repeated group <name> (LIST) { repeated group list { optional <T> element } }
/// Returns `None` when the structure deviates from the standard layout.
fn parquet_list_element(field: &Type) -> Option<&Type> {
let fields = field.get_fields();
// The outer LIST group has one repeated child ("list" or similar).
let middle = fields.first()?;
// That middle group has one child — the element.
middle.get_fields().first().map(|f| f.as_ref())
}
13 changes: 13 additions & 0 deletions crates/data-dict/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ fn lower_column(node: &YamlWithSourceInfo) -> Option<Column> {
let mut examples: Option<Representation> = None;
let mut units: Option<Spanned<String>> = None;
let mut time_zone: Option<Spanned<String>> = None;
let mut fields: Option<Vec<Column>> = None;
for entry in entries {
let Some(key) = entry.key.yaml.as_str() else {
continue;
Expand Down Expand Up @@ -147,6 +148,17 @@ fn lower_column(node: &YamlWithSourceInfo) -> Option<Column> {
}
}
}
"fields" => {
if let Some(items) = entry.value.as_array() {
let mut fs = Vec::new();
for f in items {
if let Some(col) = lower_column(f) {
fs.push(col);
}
}
fields = Some(fs);
}
}
_ => {}
}
}
Expand All @@ -159,6 +171,7 @@ fn lower_column(node: &YamlWithSourceInfo) -> Option<Column> {
examples,
units,
time_zone,
fields,
})
}

Expand Down
4 changes: 4 additions & 0 deletions crates/data-dict/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ pub struct Column {
pub examples: Option<Representation>,
pub units: Option<Spanned<String>>,
pub time_zone: Option<Spanned<String>>,
/// Fields for `struct` and `list(struct)` columns. `None` means the
/// `fields` key was absent; `Some` means it was present (possibly empty,
/// which S07 rejects).
pub fields: Option<Vec<Column>>,
}

#[derive(Debug, Clone)]
Expand Down
Loading
Loading