Skip to content

Commit

Permalink
add field name to parquet PrimitiveTypeBuilder error messages (#2805)
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Sep 29, 2022
1 parent da8f742 commit e2bf158
Showing 1 changed file with 45 additions and 33 deletions.
78 changes: 45 additions & 33 deletions parquet/src/schema/types.rs
Expand Up @@ -281,8 +281,9 @@ impl<'a> PrimitiveTypeBuilder<'a> {
// Check length before logical type, since it is used for logical type validation.
if self.physical_type == PhysicalType::FIXED_LEN_BYTE_ARRAY && self.length < 0 {
return Err(general_err!(
"Invalid FIXED_LEN_BYTE_ARRAY length: {}",
self.length
"Invalid FIXED_LEN_BYTE_ARRAY length: {} for field '{}'",
self.length,
self.name
));
}

Expand All @@ -295,9 +296,10 @@ impl<'a> PrimitiveTypeBuilder<'a> {
!= self.converted_type
{
return Err(general_err!(
"Logical type {:?} is imcompatible with converted type {}",
"Logical type {:?} is incompatible with converted type {} for field '{}'",
logical_type,
self.converted_type
self.converted_type,
self.name
));
}
} else {
Expand All @@ -308,25 +310,28 @@ impl<'a> PrimitiveTypeBuilder<'a> {
match (logical_type, self.physical_type) {
(LogicalType::Map, _) | (LogicalType::List, _) => {
return Err(general_err!(
"{:?} cannot be applied to a primitive type",
logical_type
"{:?} cannot be applied to a primitive type for field '{}'",
logical_type,
self.name
));
}
(LogicalType::Enum, PhysicalType::BYTE_ARRAY) => {}
(LogicalType::Decimal { scale, precision }, _) => {
// Check that scale and precision are consistent with legacy values
if *scale != self.scale {
return Err(general_err!(
"DECIMAL logical type scale {} must match self.scale {}",
"DECIMAL logical type scale {} must match self.scale {} for field '{}'",
scale,
self.scale
self.scale,
self.name
));
}
if *precision != self.precision {
return Err(general_err!(
"DECIMAL logical type precision {} must match self.precision {}",
"DECIMAL logical type precision {} must match self.precision {} for field '{}'",
precision,
self.precision
self.precision,
self.name
));
}
self.check_decimal_precision_scale()?;
Expand All @@ -342,7 +347,8 @@ impl<'a> PrimitiveTypeBuilder<'a> {
(LogicalType::Time { unit, .. }, PhysicalType::INT64) => {
if *unit == TimeUnit::MILLIS(Default::default()) {
return Err(general_err!(
"Cannot use millisecond unit on INT64 type"
"Cannot use millisecond unit on INT64 type for field '{}'",
self.name
));
}
}
Expand All @@ -359,9 +365,10 @@ impl<'a> PrimitiveTypeBuilder<'a> {
(LogicalType::Uuid, PhysicalType::FIXED_LEN_BYTE_ARRAY) => {}
(a, b) => {
return Err(general_err!(
"Cannot annotate {:?} from {} fields",
"Cannot annotate {:?} from {} for field '{}'",
a,
b
b,
self.name
))
}
}
Expand All @@ -374,8 +381,9 @@ impl<'a> PrimitiveTypeBuilder<'a> {
ConvertedType::UTF8 | ConvertedType::BSON | ConvertedType::JSON => {
if self.physical_type != PhysicalType::BYTE_ARRAY {
return Err(general_err!(
"{} can only annotate BYTE_ARRAY fields",
self.converted_type
"{} cannot annotate field '{}' because it is not a BYTE_ARRAY field",
self.converted_type,
self.name
));
}
}
Expand All @@ -392,8 +400,9 @@ impl<'a> PrimitiveTypeBuilder<'a> {
| ConvertedType::INT_32 => {
if self.physical_type != PhysicalType::INT32 {
return Err(general_err!(
"{} can only annotate INT32",
self.converted_type
"{} cannot annotate field '{}' because it is not a INT32 field",
self.converted_type,
self.name
));
}
}
Expand All @@ -404,8 +413,9 @@ impl<'a> PrimitiveTypeBuilder<'a> {
| ConvertedType::INT_64 => {
if self.physical_type != PhysicalType::INT64 {
return Err(general_err!(
"{} can only annotate INT64",
self.converted_type
"{} cannot annotate field '{}' because it is not a INT64 field",
self.converted_type,
self.name
));
}
}
Expand All @@ -414,19 +424,21 @@ impl<'a> PrimitiveTypeBuilder<'a> {
|| self.length != 12
{
return Err(general_err!(
"INTERVAL can only annotate FIXED_LEN_BYTE_ARRAY(12)"
"INTERVAL cannot annotate field '{}' because it is not a FIXED_LEN_BYTE_ARRAY(12) field",
self.name
));
}
}
ConvertedType::ENUM => {
if self.physical_type != PhysicalType::BYTE_ARRAY {
return Err(general_err!("ENUM can only annotate BYTE_ARRAY fields"));
return Err(general_err!("ENUM cannot annotate field '{}' because it is not a BYTE_ARRAY field", self.name));
}
}
_ => {
return Err(general_err!(
"{} cannot be applied to a primitive type",
self.converted_type
"{} cannot be applied to primitive field '{}'",
self.converted_type,
self.name
));
}
}
Expand Down Expand Up @@ -1258,7 +1270,7 @@ mod tests {
if let Err(e) = result {
assert_eq!(
format!("{}", e),
"Parquet error: Cannot annotate Integer { bit_width: 8, is_signed: true } from INT64 fields"
"Parquet error: Cannot annotate Integer { bit_width: 8, is_signed: true } from INT64 for field 'foo'"
);
}

Expand All @@ -1271,7 +1283,7 @@ mod tests {
if let Err(e) = result {
assert_eq!(
format!("{}", e),
"Parquet error: BSON can only annotate BYTE_ARRAY fields"
"Parquet error: BSON cannot annotate field 'foo' because it is not a BYTE_ARRAY field"
);
}

Expand Down Expand Up @@ -1302,7 +1314,7 @@ mod tests {
if let Err(e) = result {
assert_eq!(
format!("{}", e),
"Parquet error: DECIMAL logical type scale 32 must match self.scale -1"
"Parquet error: DECIMAL logical type scale 32 must match self.scale -1 for field 'foo'"
);
}

Expand Down Expand Up @@ -1419,7 +1431,7 @@ mod tests {
if let Err(e) = result {
assert_eq!(
format!("{}", e),
"Parquet error: UINT_8 can only annotate INT32"
"Parquet error: UINT_8 cannot annotate field 'foo' because it is not a INT32 field"
);
}

Expand All @@ -1431,7 +1443,7 @@ mod tests {
if let Err(e) = result {
assert_eq!(
format!("{}", e),
"Parquet error: TIME_MICROS can only annotate INT64"
"Parquet error: TIME_MICROS cannot annotate field 'foo' because it is not a INT64 field"
);
}

Expand All @@ -1443,7 +1455,7 @@ mod tests {
if let Err(e) = result {
assert_eq!(
format!("{}", e),
"Parquet error: INTERVAL can only annotate FIXED_LEN_BYTE_ARRAY(12)"
"Parquet error: INTERVAL cannot annotate field 'foo' because it is not a FIXED_LEN_BYTE_ARRAY(12) field"
);
}

Expand All @@ -1456,7 +1468,7 @@ mod tests {
if let Err(e) = result {
assert_eq!(
format!("{}", e),
"Parquet error: INTERVAL can only annotate FIXED_LEN_BYTE_ARRAY(12)"
"Parquet error: INTERVAL cannot annotate field 'foo' because it is not a FIXED_LEN_BYTE_ARRAY(12) field"
);
}

Expand All @@ -1468,7 +1480,7 @@ mod tests {
if let Err(e) = result {
assert_eq!(
format!("{}", e),
"Parquet error: ENUM can only annotate BYTE_ARRAY fields"
"Parquet error: ENUM cannot annotate field 'foo' because it is not a BYTE_ARRAY field"
);
}

Expand All @@ -1480,7 +1492,7 @@ mod tests {
if let Err(e) = result {
assert_eq!(
format!("{}", e),
"Parquet error: MAP cannot be applied to a primitive type"
"Parquet error: MAP cannot be applied to primitive field 'foo'"
);
}

Expand All @@ -1493,7 +1505,7 @@ mod tests {
if let Err(e) = result {
assert_eq!(
format!("{}", e),
"Parquet error: Invalid FIXED_LEN_BYTE_ARRAY length: -1"
"Parquet error: Invalid FIXED_LEN_BYTE_ARRAY length: -1 for field 'foo'"
);
}
}
Expand Down

0 comments on commit e2bf158

Please sign in to comment.