Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add field name to parquet PrimitiveTypeBuilder error messages #2805

Merged
merged 1 commit into from Sep 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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