Skip to content

Commit c2b05cd

Browse files
authored
Check length of FIXED_LEN_BYTE_ARRAY for uuid logical parquet type (#5821)
1 parent 95ef912 commit c2b05cd

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

parquet/src/schema/types.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,13 @@ impl<'a> PrimitiveTypeBuilder<'a> {
357357
(LogicalType::String, PhysicalType::BYTE_ARRAY) => {}
358358
(LogicalType::Json, PhysicalType::BYTE_ARRAY) => {}
359359
(LogicalType::Bson, PhysicalType::BYTE_ARRAY) => {}
360-
(LogicalType::Uuid, PhysicalType::FIXED_LEN_BYTE_ARRAY) => {}
360+
(LogicalType::Uuid, PhysicalType::FIXED_LEN_BYTE_ARRAY) if self.length == 16 => {}
361+
(LogicalType::Uuid, PhysicalType::FIXED_LEN_BYTE_ARRAY) => {
362+
return Err(general_err!(
363+
"UUID cannot annotate field '{}' because it is not a FIXED_LEN_BYTE_ARRAY(16) field",
364+
self.name
365+
))
366+
}
361367
(LogicalType::Float16, PhysicalType::FIXED_LEN_BYTE_ARRAY)
362368
if self.length == 2 => {}
363369
(LogicalType::Float16, PhysicalType::FIXED_LEN_BYTE_ARRAY) => {
@@ -1594,6 +1600,20 @@ mod tests {
15941600
"Parquet error: FLOAT16 cannot annotate field 'foo' because it is not a FIXED_LEN_BYTE_ARRAY(2) field"
15951601
);
15961602
}
1603+
1604+
// Must have length 16
1605+
result = Type::primitive_type_builder("foo", PhysicalType::FIXED_LEN_BYTE_ARRAY)
1606+
.with_repetition(Repetition::REQUIRED)
1607+
.with_logical_type(Some(LogicalType::Uuid))
1608+
.with_length(15)
1609+
.build();
1610+
assert!(result.is_err());
1611+
if let Err(e) = result {
1612+
assert_eq!(
1613+
format!("{e}"),
1614+
"Parquet error: UUID cannot annotate field 'foo' because it is not a FIXED_LEN_BYTE_ARRAY(16) field"
1615+
);
1616+
}
15971617
}
15981618

15991619
#[test]

0 commit comments

Comments
 (0)