Skip to content

Commit 60a7b8b

Browse files
committed
fix
1 parent 6415d40 commit 60a7b8b

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

crates/iceberg/src/spec/manifest_list.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ impl ManifestListWriter {
132132
("sequence-number".to_string(), sequence_number.to_string()),
133133
("format-version".to_string(), "2".to_string()),
134134
]);
135-
if let Some(parent_snapshot_id) = parent_snapshot_id {
136-
metadata.insert(
137-
"parent-snapshot-id".to_string(),
138-
parent_snapshot_id.to_string(),
139-
);
140-
}
135+
metadata.insert(
136+
"parent-snapshot-id".to_string(),
137+
parent_snapshot_id
138+
.map(|v| v.to_string())
139+
.unwrap_or("null".to_string()),
140+
);
141141
Self::new(
142142
FormatVersion::V2,
143143
output_file,

crates/iceberg/src/transaction.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<'a> Transaction<'a> {
140140
FastAppendAction::new(
141141
self,
142142
snapshot_id,
143-
commit_uuid.unwrap_or_else(Uuid::new_v4),
143+
commit_uuid.unwrap_or_else(Uuid::now_v7),
144144
key_metadata,
145145
HashMap::new(),
146146
)
@@ -320,22 +320,23 @@ impl<'a> SnapshotProduceAction<'a> {
320320
"Partition value is not compatitable with partition type",
321321
));
322322
}
323-
if partition_value
324-
.fields()
325-
.iter()
326-
.zip(partition_type.fields())
327-
.any(|(value, field)| {
328-
!field
329-
.field_type
330-
.as_primitive_type()
331-
.unwrap()
332-
.compatible(&value.as_primitive_literal().unwrap())
333-
})
334-
{
335-
return Err(Error::new(
336-
ErrorKind::DataInvalid,
337-
"Partition value is not compatitable partition type",
338-
));
323+
for (value, field) in partition_value.fields().iter().zip(partition_type.fields()) {
324+
if !field
325+
.field_type
326+
.as_primitive_type()
327+
.ok_or_else(|| {
328+
Error::new(
329+
ErrorKind::Unexpected,
330+
"Partition field should only be primitve type.",
331+
)
332+
})?
333+
.compatible(&value.as_primitive_literal().unwrap())
334+
{
335+
return Err(Error::new(
336+
ErrorKind::DataInvalid,
337+
"Partition value is not compatitable partition type",
338+
));
339+
}
339340
}
340341
Ok(())
341342
}
@@ -387,7 +388,7 @@ impl<'a> SnapshotProduceAction<'a> {
387388
let builder = ManifestEntry::builder()
388389
.status(crate::spec::ManifestStatus::Added)
389390
.data_file(data_file);
390-
if self.tx.table.metadata().format_version() as u8 == 1u8 {
391+
if self.tx.table.metadata().format_version() == FormatVersion::V1 {
391392
builder.snapshot_id(self.snapshot_id).build()
392393
} else {
393394
// For format version > 1, we set the snapshot id at the inherited time to avoid rewrite the manifest file when
@@ -781,6 +782,19 @@ mod tests {
781782
async fn test_fast_append_action() {
782783
let table = make_v2_minimal_table();
783784
let tx = Transaction::new(&table);
785+
let mut action = tx.fast_append(None, vec![]).unwrap();
786+
787+
// check add data file with uncompatitable partition value
788+
let data_file = DataFileBuilder::default()
789+
.content(DataContentType::Data)
790+
.file_path("test/3.parquet".to_string())
791+
.file_format(DataFileFormat::Parquet)
792+
.file_size_in_bytes(100)
793+
.record_count(1)
794+
.partition(Struct::from_iter([Some(Literal::string("test"))]))
795+
.build()
796+
.unwrap();
797+
assert!(action.add_data_files(vec![data_file.clone()]).is_err());
784798

785799
let data_file = DataFileBuilder::default()
786800
.content(DataContentType::Data)
@@ -791,7 +805,6 @@ mod tests {
791805
.partition(Struct::from_iter([Some(Literal::long(300))]))
792806
.build()
793807
.unwrap();
794-
let mut action = tx.fast_append(None, vec![]).unwrap();
795808
action.add_data_files(vec![data_file.clone()]).unwrap();
796809
let tx = action.apply().await.unwrap();
797810

0 commit comments

Comments
 (0)