liurenjie1024 commented on code in PR #1511:
URL: https://github.com/apache/iceberg-rust/pull/1511#discussion_r2222019640
##########
crates/iceberg/src/spec/manifest/mod.rs:
##########
@@ -1056,4 +1089,120 @@ mod tests {
assert!(!partitions[2].clone().contains_null);
assert_eq!(partitions[2].clone().contains_nan, Some(false));
}
+
+ #[test]
+ fn test_data_file_serialization() {
+ // Create a simple schema
+ let schema = Schema::builder()
+ .with_schema_id(1)
+ .with_identifier_field_ids(vec![1])
+ .with_fields(vec![
+ crate::spec::NestedField::required(1, "id",
Type::Primitive(PrimitiveType::Long))
+ .into(),
+ crate::spec::NestedField::required(
+ 2,
+ "name",
+ Type::Primitive(PrimitiveType::String),
+ )
+ .into(),
+ ])
+ .build()
+ .unwrap();
+
+ // Create a partition spec
+ let partition_spec = PartitionSpec::builder(schema.clone())
+ .with_spec_id(1)
+ .add_partition_field("id", "id_partition",
crate::spec::Transform::Identity)
+ .unwrap()
+ .build()
+ .unwrap();
+
+ // Get partition type from the partition spec
+ let partition_type = partition_spec.partition_type(&schema).unwrap();
+
+ // Create a vector of DataFile objects
+ let data_files = vec![
+ DataFileBuilder::default()
+ .content(crate::spec::DataContentType::Data)
+ .file_format(DataFileFormat::Parquet)
+ .file_path("path/to/file1.parquet".to_string())
+ .file_size_in_bytes(1024)
+ .record_count(100)
+ .partition_spec_id(1)
+ .partition(Struct::empty())
+ .column_sizes(HashMap::from([(1, 512), (2, 512)]))
+ .value_counts(HashMap::from([(1, 100), (2, 100)]))
+ .null_value_counts(HashMap::from([(1, 0), (2, 0)]))
+ .build()
+ .unwrap(),
+ DataFileBuilder::default()
+ .content(crate::spec::DataContentType::Data)
+ .file_format(DataFileFormat::Parquet)
+ .file_path("path/to/file2.parquet".to_string())
+ .file_size_in_bytes(2048)
+ .record_count(200)
+ .partition_spec_id(1)
+ .partition(Struct::empty())
+ .column_sizes(HashMap::from([(1, 1024), (2, 1024)]))
+ .value_counts(HashMap::from([(1, 200), (2, 200)]))
+ .null_value_counts(HashMap::from([(1, 10), (2, 5)]))
+ .build()
+ .unwrap(),
+ ];
+
+ // Serialize the DataFile objects
+ let serialized_files = data_files
+ .into_iter()
+ .map(|f| {
+ let json =
+ serialize_data_file_to_json(f, &partition_type,
FormatVersion::V2).unwrap();
+ println!("Test serialized data file: {}", json);
+ json
+ })
+ .collect::<Vec<String>>();
+
+ // Verify we have the expected number of serialized files
+ assert_eq!(serialized_files.len(), 2);
+
+ // Verify each serialized file contains expected data
+ for json in &serialized_files {
+ assert!(json.contains("path/to/file"));
Review Comment:
nit: Why not assert the json output? We could use snapshot test to make it
easier, see https://docs.rs/expect-test/latest/expect_test/
##########
crates/iceberg/src/arrow/value.rs:
##########
@@ -440,10 +440,12 @@ impl PartnerAccessor<ArrayRef> for ArrowArrayAccessor {
Ok(schema_partner)
}
+ // todo generate field_pos in datafusion instead of passing to here
Review Comment:
Why we need to convert `RecordBatch`'s schema to iceberg schema?
##########
crates/iceberg/src/arrow/value.rs:
##########
@@ -440,10 +440,12 @@ impl PartnerAccessor<ArrayRef> for ArrowArrayAccessor {
Ok(schema_partner)
}
+ // todo generate field_pos in datafusion instead of passing to here
Review Comment:
The method you mentioned is typically used to convert parquet file's schema
to iceberg schema.
##########
crates/iceberg/src/writer/base_writer/rolling_writer.rs:
##########
@@ -0,0 +1,333 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::mem::take;
+
+use arrow_array::RecordBatch;
+use async_trait::async_trait;
+use futures::future::try_join_all;
+
+use crate::runtime::{JoinHandle, spawn};
+use crate::spec::DataFile;
+use crate::writer::{IcebergWriter, IcebergWriterBuilder};
+use crate::{Error, ErrorKind, Result};
+
+/// A writer that can roll over to a new file when certain conditions are met.
+///
+/// This trait extends `IcebergWriter` with the ability to determine when to
start
+/// writing to a new file based on the size of incoming data.
+#[async_trait]
+pub trait RollingFileWriter: IcebergWriter {
Review Comment:
Sorry I forgot that currently we don't have `RollingFileWriter`. It's fine
to leave it in this pr, but it would be better to use a separate pr to add
this. `RollingFileWriter` should be a `FileWriter` rather an `IcebergWriter`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]