pratik0316 commented on code in PR #2002:
URL: https://github.com/apache/iceberg-rust/pull/2002#discussion_r2665354135
##########
crates/iceberg/src/spec/table_metadata.rs:
##########
@@ -3795,4 +3806,111 @@ mod tests {
assert!(final_metadata.name_exists_in_any_schema("new_field")); //
only in current schema
assert!(!final_metadata.name_exists_in_any_schema("never_existed"));
}
+
+ #[test]
+ fn test_table_properties_with_defaults() {
+ use crate::spec::TableProperties;
+
+ let schema = Schema::builder()
+ .with_fields(vec![
+ NestedField::required(1, "id",
Type::Primitive(PrimitiveType::Long)).into(),
+ ])
+ .build()
+ .unwrap();
+
+ let metadata = TableMetadataBuilder::new(
+ schema,
+ PartitionSpec::unpartition_spec().into_unbound(),
+ SortOrder::unsorted_order(),
+ "s3://test/location".to_string(),
+ FormatVersion::V2,
+ HashMap::new(),
+ )
+ .unwrap()
+ .build()
+ .unwrap()
+ .metadata;
+
+ let props = metadata.table_properties().unwrap();
+
+ assert_eq!(
+ props.commit_num_retries,
+ TableProperties::PROPERTY_COMMIT_NUM_RETRIES_DEFAULT
+ );
+ assert_eq!(
+ props.write_target_file_size_bytes,
+ TableProperties::PROPERTY_WRITE_TARGET_FILE_SIZE_BYTES_DEFAULT
+ );
+ }
+
+ #[test]
+ fn test_table_properties_with_custom_values() {
+ use crate::spec::TableProperties;
+
+ let schema = Schema::builder()
+ .with_fields(vec![
+ NestedField::required(1, "id",
Type::Primitive(PrimitiveType::Long)).into(),
+ ])
+ .build()
+ .unwrap();
+
+ let properties = HashMap::from([
+ (
+ TableProperties::PROPERTY_COMMIT_NUM_RETRIES.to_string(),
+ "10".to_string(),
+ ),
+ (
+
TableProperties::PROPERTY_WRITE_TARGET_FILE_SIZE_BYTES.to_string(),
+ "1024".to_string(),
+ ),
+ ]);
+
+ let metadata = TableMetadataBuilder::new(
+ schema,
+ PartitionSpec::unpartition_spec().into_unbound(),
+ SortOrder::unsorted_order(),
+ "s3://test/location".to_string(),
+ FormatVersion::V2,
+ properties,
+ )
+ .unwrap()
+ .build()
+ .unwrap()
+ .metadata;
+
+ let props = metadata.table_properties().unwrap();
+
+ assert_eq!(props.commit_num_retries, 10);
+ assert_eq!(props.write_target_file_size_bytes, 1024);
+ }
+
+ #[test]
+ fn test_table_properties_with_invalid_value() {
+ let schema = Schema::builder()
+ .with_fields(vec![
+ NestedField::required(1, "id",
Type::Primitive(PrimitiveType::Long)).into(),
+ ])
+ .build()
+ .unwrap();
+
+ let properties = HashMap::from([(
+ "commit.retry.num-retries".to_string(),
+ "not_a_number".to_string(),
+ )]);
+
+ let metadata = TableMetadataBuilder::new(
+ schema,
+ PartitionSpec::unpartition_spec().into_unbound(),
+ SortOrder::unsorted_order(),
+ "s3://test/location".to_string(),
+ FormatVersion::V2,
+ properties,
+ )
+ .unwrap()
+ .build()
+ .unwrap()
+ .metadata;
+
+ assert!(metadata.table_properties().is_err());
Review Comment:
lets have a check on the error kind and error message
--
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]