Skip to content

Commit e2bf158

Browse files
authored
add field name to parquet PrimitiveTypeBuilder error messages (#2805)
1 parent da8f742 commit e2bf158

File tree

1 file changed

+45
-33
lines changed

1 file changed

+45
-33
lines changed

parquet/src/schema/types.rs

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,9 @@ impl<'a> PrimitiveTypeBuilder<'a> {
281281
// Check length before logical type, since it is used for logical type validation.
282282
if self.physical_type == PhysicalType::FIXED_LEN_BYTE_ARRAY && self.length < 0 {
283283
return Err(general_err!(
284-
"Invalid FIXED_LEN_BYTE_ARRAY length: {}",
285-
self.length
284+
"Invalid FIXED_LEN_BYTE_ARRAY length: {} for field '{}'",
285+
self.length,
286+
self.name
286287
));
287288
}
288289

@@ -295,9 +296,10 @@ impl<'a> PrimitiveTypeBuilder<'a> {
295296
!= self.converted_type
296297
{
297298
return Err(general_err!(
298-
"Logical type {:?} is imcompatible with converted type {}",
299+
"Logical type {:?} is incompatible with converted type {} for field '{}'",
299300
logical_type,
300-
self.converted_type
301+
self.converted_type,
302+
self.name
301303
));
302304
}
303305
} else {
@@ -308,25 +310,28 @@ impl<'a> PrimitiveTypeBuilder<'a> {
308310
match (logical_type, self.physical_type) {
309311
(LogicalType::Map, _) | (LogicalType::List, _) => {
310312
return Err(general_err!(
311-
"{:?} cannot be applied to a primitive type",
312-
logical_type
313+
"{:?} cannot be applied to a primitive type for field '{}'",
314+
logical_type,
315+
self.name
313316
));
314317
}
315318
(LogicalType::Enum, PhysicalType::BYTE_ARRAY) => {}
316319
(LogicalType::Decimal { scale, precision }, _) => {
317320
// Check that scale and precision are consistent with legacy values
318321
if *scale != self.scale {
319322
return Err(general_err!(
320-
"DECIMAL logical type scale {} must match self.scale {}",
323+
"DECIMAL logical type scale {} must match self.scale {} for field '{}'",
321324
scale,
322-
self.scale
325+
self.scale,
326+
self.name
323327
));
324328
}
325329
if *precision != self.precision {
326330
return Err(general_err!(
327-
"DECIMAL logical type precision {} must match self.precision {}",
331+
"DECIMAL logical type precision {} must match self.precision {} for field '{}'",
328332
precision,
329-
self.precision
333+
self.precision,
334+
self.name
330335
));
331336
}
332337
self.check_decimal_precision_scale()?;
@@ -342,7 +347,8 @@ impl<'a> PrimitiveTypeBuilder<'a> {
342347
(LogicalType::Time { unit, .. }, PhysicalType::INT64) => {
343348
if *unit == TimeUnit::MILLIS(Default::default()) {
344349
return Err(general_err!(
345-
"Cannot use millisecond unit on INT64 type"
350+
"Cannot use millisecond unit on INT64 type for field '{}'",
351+
self.name
346352
));
347353
}
348354
}
@@ -359,9 +365,10 @@ impl<'a> PrimitiveTypeBuilder<'a> {
359365
(LogicalType::Uuid, PhysicalType::FIXED_LEN_BYTE_ARRAY) => {}
360366
(a, b) => {
361367
return Err(general_err!(
362-
"Cannot annotate {:?} from {} fields",
368+
"Cannot annotate {:?} from {} for field '{}'",
363369
a,
364-
b
370+
b,
371+
self.name
365372
))
366373
}
367374
}
@@ -374,8 +381,9 @@ impl<'a> PrimitiveTypeBuilder<'a> {
374381
ConvertedType::UTF8 | ConvertedType::BSON | ConvertedType::JSON => {
375382
if self.physical_type != PhysicalType::BYTE_ARRAY {
376383
return Err(general_err!(
377-
"{} can only annotate BYTE_ARRAY fields",
378-
self.converted_type
384+
"{} cannot annotate field '{}' because it is not a BYTE_ARRAY field",
385+
self.converted_type,
386+
self.name
379387
));
380388
}
381389
}
@@ -392,8 +400,9 @@ impl<'a> PrimitiveTypeBuilder<'a> {
392400
| ConvertedType::INT_32 => {
393401
if self.physical_type != PhysicalType::INT32 {
394402
return Err(general_err!(
395-
"{} can only annotate INT32",
396-
self.converted_type
403+
"{} cannot annotate field '{}' because it is not a INT32 field",
404+
self.converted_type,
405+
self.name
397406
));
398407
}
399408
}
@@ -404,8 +413,9 @@ impl<'a> PrimitiveTypeBuilder<'a> {
404413
| ConvertedType::INT_64 => {
405414
if self.physical_type != PhysicalType::INT64 {
406415
return Err(general_err!(
407-
"{} can only annotate INT64",
408-
self.converted_type
416+
"{} cannot annotate field '{}' because it is not a INT64 field",
417+
self.converted_type,
418+
self.name
409419
));
410420
}
411421
}
@@ -414,19 +424,21 @@ impl<'a> PrimitiveTypeBuilder<'a> {
414424
|| self.length != 12
415425
{
416426
return Err(general_err!(
417-
"INTERVAL can only annotate FIXED_LEN_BYTE_ARRAY(12)"
427+
"INTERVAL cannot annotate field '{}' because it is not a FIXED_LEN_BYTE_ARRAY(12) field",
428+
self.name
418429
));
419430
}
420431
}
421432
ConvertedType::ENUM => {
422433
if self.physical_type != PhysicalType::BYTE_ARRAY {
423-
return Err(general_err!("ENUM can only annotate BYTE_ARRAY fields"));
434+
return Err(general_err!("ENUM cannot annotate field '{}' because it is not a BYTE_ARRAY field", self.name));
424435
}
425436
}
426437
_ => {
427438
return Err(general_err!(
428-
"{} cannot be applied to a primitive type",
429-
self.converted_type
439+
"{} cannot be applied to primitive field '{}'",
440+
self.converted_type,
441+
self.name
430442
));
431443
}
432444
}
@@ -1258,7 +1270,7 @@ mod tests {
12581270
if let Err(e) = result {
12591271
assert_eq!(
12601272
format!("{}", e),
1261-
"Parquet error: Cannot annotate Integer { bit_width: 8, is_signed: true } from INT64 fields"
1273+
"Parquet error: Cannot annotate Integer { bit_width: 8, is_signed: true } from INT64 for field 'foo'"
12621274
);
12631275
}
12641276

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

@@ -1302,7 +1314,7 @@ mod tests {
13021314
if let Err(e) = result {
13031315
assert_eq!(
13041316
format!("{}", e),
1305-
"Parquet error: DECIMAL logical type scale 32 must match self.scale -1"
1317+
"Parquet error: DECIMAL logical type scale 32 must match self.scale -1 for field 'foo'"
13061318
);
13071319
}
13081320

@@ -1419,7 +1431,7 @@ mod tests {
14191431
if let Err(e) = result {
14201432
assert_eq!(
14211433
format!("{}", e),
1422-
"Parquet error: UINT_8 can only annotate INT32"
1434+
"Parquet error: UINT_8 cannot annotate field 'foo' because it is not a INT32 field"
14231435
);
14241436
}
14251437

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

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

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

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

@@ -1480,7 +1492,7 @@ mod tests {
14801492
if let Err(e) = result {
14811493
assert_eq!(
14821494
format!("{}", e),
1483-
"Parquet error: MAP cannot be applied to a primitive type"
1495+
"Parquet error: MAP cannot be applied to primitive field 'foo'"
14841496
);
14851497
}
14861498

@@ -1493,7 +1505,7 @@ mod tests {
14931505
if let Err(e) = result {
14941506
assert_eq!(
14951507
format!("{}", e),
1496-
"Parquet error: Invalid FIXED_LEN_BYTE_ARRAY length: -1"
1508+
"Parquet error: Invalid FIXED_LEN_BYTE_ARRAY length: -1 for field 'foo'"
14971509
);
14981510
}
14991511
}

0 commit comments

Comments
 (0)