Skip to content

Commit

Permalink
Check length of FIXED_LEN_BYTE_ARRAY for uuid logical parquet type (
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrobbel authored May 31, 2024
1 parent 95ef912 commit c2b05cd
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion parquet/src/schema/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,13 @@ impl<'a> PrimitiveTypeBuilder<'a> {
(LogicalType::String, PhysicalType::BYTE_ARRAY) => {}
(LogicalType::Json, PhysicalType::BYTE_ARRAY) => {}
(LogicalType::Bson, PhysicalType::BYTE_ARRAY) => {}
(LogicalType::Uuid, PhysicalType::FIXED_LEN_BYTE_ARRAY) => {}
(LogicalType::Uuid, PhysicalType::FIXED_LEN_BYTE_ARRAY) if self.length == 16 => {}
(LogicalType::Uuid, PhysicalType::FIXED_LEN_BYTE_ARRAY) => {
return Err(general_err!(
"UUID cannot annotate field '{}' because it is not a FIXED_LEN_BYTE_ARRAY(16) field",
self.name
))
}
(LogicalType::Float16, PhysicalType::FIXED_LEN_BYTE_ARRAY)
if self.length == 2 => {}
(LogicalType::Float16, PhysicalType::FIXED_LEN_BYTE_ARRAY) => {
Expand Down Expand Up @@ -1594,6 +1600,20 @@ mod tests {
"Parquet error: FLOAT16 cannot annotate field 'foo' because it is not a FIXED_LEN_BYTE_ARRAY(2) field"
);
}

// Must have length 16
result = Type::primitive_type_builder("foo", PhysicalType::FIXED_LEN_BYTE_ARRAY)
.with_repetition(Repetition::REQUIRED)
.with_logical_type(Some(LogicalType::Uuid))
.with_length(15)
.build();
assert!(result.is_err());
if let Err(e) = result {
assert_eq!(
format!("{e}"),
"Parquet error: UUID cannot annotate field 'foo' because it is not a FIXED_LEN_BYTE_ARRAY(16) field"
);
}
}

#[test]
Expand Down

0 comments on commit c2b05cd

Please sign in to comment.