Skip to content

Commit 8664ad2

Browse files
committed
Add test and change initial_default
1 parent 3925336 commit 8664ad2

File tree

2 files changed

+73
-13
lines changed

2 files changed

+73
-13
lines changed

crates/iceberg/src/spec/manifest/_serde.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,75 @@ mod tests {
398398

399399
assert_eq!(data_files, actual_data_file);
400400
}
401+
402+
#[tokio::test]
403+
async fn test_data_file_serialize_deserialize_v1() {
404+
let schema = Arc::new(
405+
Schema::builder()
406+
.with_fields(vec![
407+
Arc::new(NestedField::optional(
408+
1,
409+
"v1",
410+
Type::Primitive(PrimitiveType::Int),
411+
)),
412+
Arc::new(NestedField::optional(
413+
2,
414+
"v2",
415+
Type::Primitive(PrimitiveType::String),
416+
)),
417+
Arc::new(NestedField::optional(
418+
3,
419+
"v3",
420+
Type::Primitive(PrimitiveType::String),
421+
)),
422+
])
423+
.build()
424+
.unwrap(),
425+
);
426+
let data_files = vec![DataFile {
427+
content: DataContentType::Data,
428+
file_path: "s3://testbucket/iceberg_data/iceberg_ctl/iceberg_db/iceberg_tbl/data/00000-7-45268d71-54eb-476c-b42c-942d880c04a1-00001.parquet".to_string(),
429+
file_format: DataFileFormat::Parquet,
430+
partition: Struct::empty(),
431+
record_count: 1,
432+
file_size_in_bytes: 875,
433+
column_sizes: HashMap::from([(1,47),(2,48),(3,52)]),
434+
value_counts: HashMap::from([(1,1),(2,1),(3,1)]),
435+
null_value_counts: HashMap::from([(1,0),(2,0),(3,0)]),
436+
nan_value_counts: HashMap::new(),
437+
lower_bounds: HashMap::from([(1,Datum::int(1)),(2,Datum::string("a")),(3,Datum::string("AC/DC"))]),
438+
upper_bounds: HashMap::from([(1,Datum::int(1)),(2,Datum::string("a")),(3,Datum::string("AC/DC"))]),
439+
key_metadata: None,
440+
split_offsets: vec![4],
441+
equality_ids: vec![],
442+
sort_order_id: Some(0),
443+
partition_spec_id: 0,
444+
first_row_id: None,
445+
referenced_data_file: None,
446+
content_offset: None,
447+
content_size_in_bytes: None,
448+
}];
449+
450+
let mut buffer = Vec::new();
451+
let _ = write_data_files_to_avro(
452+
&mut buffer,
453+
data_files.clone().into_iter(),
454+
&StructType::new(vec![]),
455+
FormatVersion::V1,
456+
)
457+
.unwrap();
458+
459+
let actual_data_file = read_data_files_from_avro(
460+
&mut Cursor::new(buffer),
461+
&schema,
462+
0,
463+
&StructType::new(vec![]),
464+
FormatVersion::V1,
465+
)
466+
.unwrap();
467+
468+
assert_eq!(actual_data_file[0].content, DataContentType::Data)
469+
470+
471+
}
401472
}

crates/iceberg/src/spec/manifest/entry.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ use typed_builder::TypedBuilder;
2424
use crate::avro::schema_to_avro_schema;
2525
use crate::error::Result;
2626
use crate::spec::{
27-
DataContentType, DataFile, INITIAL_SEQUENCE_NUMBER, ListType, ManifestFile, MapType,
28-
NestedField, NestedFieldRef, PrimitiveType, Schema, StructType, Type,
27+
DataContentType, DataFile, ListType, Literal, ManifestFile, MapType, NestedField, NestedFieldRef, PrimitiveLiteral, PrimitiveType, Schema, StructType, Type, INITIAL_SEQUENCE_NUMBER
2928
};
3029
use crate::{Error, ErrorKind};
3130

@@ -236,7 +235,7 @@ static CONTENT: Lazy<NestedFieldRef> = {
236235
134,
237236
"content",
238237
Type::Primitive(PrimitiveType::Int),
239-
))
238+
).with_initial_default(Literal::Primitive(PrimitiveLiteral::Int(1))))
240239
})
241240
};
242241

@@ -563,16 +562,6 @@ pub(super) fn manifest_schema_v2(partition_type: &StructType) -> Result<AvroSche
563562

564563
fn data_file_fields_v1(partition_type: &StructType) -> Vec<NestedFieldRef> {
565564
vec![
566-
// Content is always 1.
567-
Arc::new(NestedField::builder()
568-
.id(134)
569-
.name("content")
570-
.required(false)
571-
.field_type(Type::Primitive(PrimitiveType::Int))
572-
.initial_default(Some(serde_json::Value::Number(1.into())))
573-
.write_default(Some(serde_json::Value::Number(1.into())))
574-
.build()
575-
),
576565
FILE_PATH.clone(),
577566
FILE_FORMAT.clone(),
578567
Arc::new(NestedField::required(

0 commit comments

Comments
 (0)