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
1 change: 1 addition & 0 deletions crates/iceberg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#[macro_use]
extern crate derive_builder;
extern crate core;
// Required so `#[derive(Properties)]` output can name `::iceberg::Error`.
extern crate self as iceberg;

mod error;
Expand Down
19 changes: 14 additions & 5 deletions crates/property-macro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Documentation attributes on the field are copied to the generated getter. The
macro generates no setters, backing fields, or conversion back to a property
map.

`Option<T>` key fields and `HashMap<String, T>` prefix fields must use the
corresponding types from `std`. The macro recognizes those field shapes
syntactically and generates code using the standard-library variants.

## Complete example

This example covers exact keys and defaults, optional values, case-insensitive
Expand Down Expand Up @@ -141,14 +145,16 @@ struct TableLikeProperties {
#[property(prefix = COLUMN_FPP_PREFIX, getter)]
column_fpp: HashMap<String, f64>,

/// A single-key parser can validate and normalize a property value.
/// An explicitly configured data path override.
/// `None` means callers should use `<table-location>/data`.
/// A single-key parser validates and normalizes configured values.
#[property(
key = LOCATION,
default = "warehouse",
default = None,
parse_with = parse_location,
getter
)]
location: String,
location: Option<String>,
Comment thread
blackmwk marked this conversation as resolved.

/// A full-map parser can model one field with multiple property keys.
#[property(
Expand All @@ -167,7 +173,7 @@ fn main() -> iceberg::Result<()> {
assert_eq!(defaults.owner(), &None);
assert!(defaults.fanout_enabled());
assert!(defaults.column_fpp().is_empty());
assert_eq!(defaults.location(), "warehouse");
assert_eq!(defaults.location(), &None);
assert_eq!(defaults.dimensions(), (640, 480, 320));

let raw = HashMap::from([
Expand All @@ -187,7 +193,10 @@ fn main() -> iceberg::Result<()> {
assert_eq!(properties.owner().as_deref(), Some("iceberg"));
assert!(!properties.fanout_enabled());
assert_eq!(properties.column_fpp()["id"], 0.01);
assert_eq!(properties.location(), "s3://bucket/table");
assert_eq!(
properties.location().as_deref(),
Some("s3://bucket/table")
);
assert_eq!(properties.dimensions(), (1920, 1080, 720));

let error = TableLikeProperties::from_properties(&HashMap::from([(
Expand Down
9 changes: 9 additions & 0 deletions crates/property-macro/tests/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ fn custom_single_value_parser_wraps_present_optional_values() {
)]))
.unwrap();
assert_eq!(parsed.location().as_deref(), Some("path"));

let error = OptionalValidatedProperties::from_properties(&HashMap::from([(
"optional-location".to_string(),
" ".to_string(),
)]))
.unwrap_err();
assert_eq!(error.kind(), ErrorKind::DataInvalid);
assert_eq!(error.message(), "value must not be empty");
assert!(format!("{error}").contains("property: optional-location"));
}

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