Skip to content

Commit

Permalink
Parquet: schema validation should allow scale == precision for decima…
Browse files Browse the repository at this point in the history
…l type (#1607)
  • Loading branch information
sunchao committed Apr 23, 2022
1 parent fd9cb23 commit 4e22b89
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions parquet/src/schema/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,13 @@ impl<'a> PrimitiveTypeBuilder<'a> {
return Err(general_err!("Invalid DECIMAL scale: {}", self.scale));
}

if self.scale >= self.precision {
if self.scale > self.precision {
return Err(general_err!(
"Invalid DECIMAL: scale ({}) cannot be greater than or equal to precision \
"Invalid DECIMAL: scale ({}) cannot be greater than precision \
({})",
self.scale,
self.precision
));
self.scale,
self.precision
));
}

// Check precision and scale based on physical type limitations.
Expand Down Expand Up @@ -1345,10 +1345,19 @@ mod tests {
if let Err(e) = result {
assert_eq!(
format!("{}", e),
"Parquet error: Invalid DECIMAL: scale (2) cannot be greater than or equal to precision (1)"
"Parquet error: Invalid DECIMAL: scale (2) cannot be greater than precision (1)"
);
}

// It is OK if precision == scale
result = Type::primitive_type_builder("foo", PhysicalType::BYTE_ARRAY)
.with_repetition(Repetition::REQUIRED)
.with_converted_type(ConvertedType::DECIMAL)
.with_precision(1)
.with_scale(1)
.build();
assert!(result.is_ok());

result = Type::primitive_type_builder("foo", PhysicalType::INT32)
.with_repetition(Repetition::REQUIRED)
.with_converted_type(ConvertedType::DECIMAL)
Expand Down

0 comments on commit 4e22b89

Please sign in to comment.