Skip to content

Commit 86a53a6

Browse files
committed
ARROW-7503: [Rust] [Parquet] Fix build failures
This replaces the deprecated `Error::description()` with a simpler ToString. I'm not familiar with the `quick-error` crate, but did my best from what I could see on the tailhook/quick-error@b26770f commit that addressed the deprecation warning/error.
1 parent 4634c89 commit 86a53a6

File tree

5 files changed

+77
-52
lines changed

5 files changed

+77
-52
lines changed

rust/parquet/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ edition = "2018"
3030

3131
[dependencies]
3232
parquet-format = "~2.6"
33-
quick-error = "1.2.2"
33+
quick-error = "1.2"
3434
byteorder = "1"
3535
thrift = "0.12"
3636
snap = "0.2"

rust/parquet/src/column/writer.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -865,8 +865,6 @@ impl EncodingWriteSupport for ColumnWriterImpl<FixedLenByteArrayType> {
865865
mod tests {
866866
use super::*;
867867

868-
use std::error::Error;
869-
870868
use rand::distributions::range::SampleRange;
871869

872870
use crate::column::{
@@ -892,8 +890,8 @@ mod tests {
892890
assert!(res.is_err());
893891
if let Err(err) = res {
894892
assert_eq!(
895-
err.description(),
896-
"Inconsistent length of definition and repetition levels: 3 != 2"
893+
err.to_string(),
894+
"Parquet error: Inconsistent length of definition and repetition levels: 3 != 2"
897895
);
898896
}
899897
}
@@ -907,8 +905,8 @@ mod tests {
907905
assert!(res.is_err());
908906
if let Err(err) = res {
909907
assert_eq!(
910-
err.description(),
911-
"Definition levels are required, because max definition level = 1"
908+
err.to_string(),
909+
"Parquet error: Definition levels are required, because max definition level = 1"
912910
);
913911
}
914912
}
@@ -922,8 +920,8 @@ mod tests {
922920
assert!(res.is_err());
923921
if let Err(err) = res {
924922
assert_eq!(
925-
err.description(),
926-
"Repetition levels are required, because max repetition level = 1"
923+
err.to_string(),
924+
"Parquet error: Repetition levels are required, because max repetition level = 1"
927925
);
928926
}
929927
}
@@ -937,8 +935,8 @@ mod tests {
937935
assert!(res.is_err());
938936
if let Err(err) = res {
939937
assert_eq!(
940-
err.description(),
941-
"Expected to write 4 values, but have only 2"
938+
err.to_string(),
939+
"Parquet error: Expected to write 4 values, but have only 2"
942940
);
943941
}
944942
}
@@ -969,7 +967,10 @@ mod tests {
969967
let res = writer.write_dictionary_page();
970968
assert!(res.is_err());
971969
if let Err(err) = res {
972-
assert_eq!(err.description(), "Dictionary encoder is not set");
970+
assert_eq!(
971+
err.to_string(),
972+
"Parquet error: Dictionary encoder is not set"
973+
);
973974
}
974975
}
975976

rust/parquet/src/errors.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use std::{cell, convert, io, result, str};
2222
use arrow::error::ArrowError;
2323
use quick_error::quick_error;
2424
use snap;
25-
use std::error::Error;
2625
use thrift;
2726

2827
quick_error! {
@@ -33,7 +32,7 @@ quick_error! {
3332
/// Returned when code violates normal workflow of working with Parquet files.
3433
General(message: String) {
3534
display("Parquet error: {}", message)
36-
description(message)
35+
display(message)
3736
from(e: io::Error) -> (format!("underlying IO error: {}", e))
3837
from(e: snap::Error) -> (format!("underlying snap error: {}", e))
3938
from(e: thrift::Error) -> (format!("underlying Thrift error: {}", e))
@@ -44,25 +43,25 @@ quick_error! {
4443
/// Returned when functionality is not yet available.
4544
NYI(message: String) {
4645
display("NYI: {}", message)
47-
description(message)
46+
display(message)
4847
}
4948
/// "End of file" Parquet error.
5049
/// Returned when IO related failures occur, e.g. when there are not enough bytes to
5150
/// decode.
5251
EOF(message: String) {
5352
display("EOF: {}", message)
54-
description(message)
53+
display(message)
5554
}
5655
/// Arrow error.
5756
/// Returned when reading into arrow or writing from arrow.
5857
ArrowError(message: String) {
5958
display("Arrow: {}", message)
60-
description(message)
59+
display(message)
6160
from(e: ArrowError) -> (format!("underlying Arrow error: {:?}", e))
6261
}
6362
IndexOutOfBound(index: usize, bound: usize) {
6463
display("Index {} out of bound: {}", index, bound)
65-
description("Index out of bound error")
64+
display("Index out of bound error")
6665
}
6766
}
6867
}
@@ -105,6 +104,6 @@ macro_rules! eof_err {
105104

106105
impl Into<ArrowError> for ParquetError {
107106
fn into(self) -> ArrowError {
108-
ArrowError::ParquetError(self.description().to_string())
107+
ArrowError::ParquetError(self.to_string())
109108
}
110109
}

rust/parquet/src/file/writer.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl<T: Write + Position> PageWriter for SerializedPageWriter<T> {
524524
mod tests {
525525
use super::*;
526526

527-
use std::{error::Error, fs::File, io::Cursor};
527+
use std::{fs::File, io::Cursor};
528528

529529
use crate::basic::{Compression, Encoding, Repetition, Type};
530530
use crate::column::page::PageReader;
@@ -548,14 +548,14 @@ mod tests {
548548
let res = writer.next_row_group();
549549
assert!(res.is_err());
550550
if let Err(err) = res {
551-
assert_eq!(err.description(), "File writer is closed");
551+
assert_eq!(err.to_string(), "Parquet error: File writer is closed");
552552
}
553553
}
554554
{
555555
let res = writer.close();
556556
assert!(res.is_err());
557557
if let Err(err) = res {
558-
assert_eq!(err.description(), "File writer is closed");
558+
assert_eq!(err.to_string(), "Parquet error: File writer is closed");
559559
}
560560
}
561561
}
@@ -572,7 +572,7 @@ mod tests {
572572
let res = row_group_writer.next_column();
573573
assert!(res.is_err());
574574
if let Err(err) = res {
575-
assert_eq!(err.description(), "Row group writer is closed");
575+
assert_eq!(err.to_string(), "Parquet error: Row group writer is closed");
576576
}
577577
}
578578

@@ -596,7 +596,10 @@ mod tests {
596596
let res = row_group_writer.close();
597597
assert!(res.is_err());
598598
if let Err(err) = res {
599-
assert_eq!(err.description(), "Column length mismatch: 1 != 0");
599+
assert_eq!(
600+
err.to_string(),
601+
"Parquet error: Column length mismatch: 1 != 0"
602+
);
600603
}
601604
}
602605

@@ -641,8 +644,8 @@ mod tests {
641644
assert!(res.is_err());
642645
if let Err(err) = res {
643646
assert_eq!(
644-
err.description(),
645-
"Incorrect number of rows, expected 3 != 2 rows"
647+
err.to_string(),
648+
"Parquet error: Incorrect number of rows, expected 3 != 2 rows"
646649
);
647650
}
648651
}

rust/parquet/src/schema/types.rs

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,8 +1063,6 @@ fn to_thrift_helper(schema: &Type, elements: &mut Vec<SchemaElement>) {
10631063
mod tests {
10641064
use super::*;
10651065

1066-
use std::error::Error;
1067-
10681066
use crate::schema::parser::parse_message_type;
10691067

10701068
#[test]
@@ -1097,7 +1095,10 @@ mod tests {
10971095
.build();
10981096
assert!(result.is_err());
10991097
if let Err(e) = result {
1100-
assert_eq!(e.description(), "BSON can only annotate BYTE_ARRAY fields");
1098+
assert_eq!(
1099+
e.to_string(),
1100+
"Parquet error: BSON can only annotate BYTE_ARRAY fields"
1101+
);
11011102
}
11021103

11031104
result = Type::primitive_type_builder("foo", PhysicalType::INT96)
@@ -1109,8 +1110,8 @@ mod tests {
11091110
assert!(result.is_err());
11101111
if let Err(e) = result {
11111112
assert_eq!(
1112-
e.description(),
1113-
"DECIMAL can only annotate INT32, INT64, BYTE_ARRAY and FIXED"
1113+
e.to_string(),
1114+
"Parquet error: DECIMAL can only annotate INT32, INT64, BYTE_ARRAY and FIXED"
11141115
);
11151116
}
11161117

@@ -1122,7 +1123,10 @@ mod tests {
11221123
.build();
11231124
assert!(result.is_err());
11241125
if let Err(e) = result {
1125-
assert_eq!(e.description(), "Invalid DECIMAL precision: -1");
1126+
assert_eq!(
1127+
e.to_string(),
1128+
"Parquet error: Invalid DECIMAL precision: -1"
1129+
);
11261130
}
11271131

11281132
result = Type::primitive_type_builder("foo", PhysicalType::BYTE_ARRAY)
@@ -1133,7 +1137,7 @@ mod tests {
11331137
.build();
11341138
assert!(result.is_err());
11351139
if let Err(e) = result {
1136-
assert_eq!(e.description(), "Invalid DECIMAL precision: 0");
1140+
assert_eq!(e.to_string(), "Parquet error: Invalid DECIMAL precision: 0");
11371141
}
11381142

11391143
result = Type::primitive_type_builder("foo", PhysicalType::BYTE_ARRAY)
@@ -1144,7 +1148,7 @@ mod tests {
11441148
.build();
11451149
assert!(result.is_err());
11461150
if let Err(e) = result {
1147-
assert_eq!(e.description(), "Invalid DECIMAL scale: -1");
1151+
assert_eq!(e.to_string(), "Parquet error: Invalid DECIMAL scale: -1");
11481152
}
11491153

11501154
result = Type::primitive_type_builder("foo", PhysicalType::BYTE_ARRAY)
@@ -1156,8 +1160,8 @@ mod tests {
11561160
assert!(result.is_err());
11571161
if let Err(e) = result {
11581162
assert_eq!(
1159-
e.description(),
1160-
"Invalid DECIMAL: scale (2) cannot be greater than or equal to precision (1)"
1163+
e.to_string(),
1164+
"Parquet error: Invalid DECIMAL: scale (2) cannot be greater than or equal to precision (1)"
11611165
);
11621166
}
11631167

@@ -1170,8 +1174,8 @@ mod tests {
11701174
assert!(result.is_err());
11711175
if let Err(e) = result {
11721176
assert_eq!(
1173-
e.description(),
1174-
"Cannot represent INT32 as DECIMAL with precision 18"
1177+
e.to_string(),
1178+
"Parquet error: Cannot represent INT32 as DECIMAL with precision 18"
11751179
);
11761180
}
11771181

@@ -1184,8 +1188,8 @@ mod tests {
11841188
assert!(result.is_err());
11851189
if let Err(e) = result {
11861190
assert_eq!(
1187-
e.description(),
1188-
"Cannot represent INT64 as DECIMAL with precision 32"
1191+
e.to_string(),
1192+
"Parquet error: Cannot represent INT64 as DECIMAL with precision 32"
11891193
);
11901194
}
11911195

@@ -1199,8 +1203,8 @@ mod tests {
11991203
assert!(result.is_err());
12001204
if let Err(e) = result {
12011205
assert_eq!(
1202-
e.description(),
1203-
"Cannot represent FIXED_LEN_BYTE_ARRAY as DECIMAL with length 5 and precision 12"
1206+
e.to_string(),
1207+
"Parquet error: Cannot represent FIXED_LEN_BYTE_ARRAY as DECIMAL with length 5 and precision 12"
12041208
);
12051209
}
12061210

@@ -1210,7 +1214,10 @@ mod tests {
12101214
.build();
12111215
assert!(result.is_err());
12121216
if let Err(e) = result {
1213-
assert_eq!(e.description(), "UINT_8 can only annotate INT32");
1217+
assert_eq!(
1218+
e.to_string(),
1219+
"Parquet error: UINT_8 can only annotate INT32"
1220+
);
12141221
}
12151222

12161223
result = Type::primitive_type_builder("foo", PhysicalType::INT32)
@@ -1219,7 +1226,10 @@ mod tests {
12191226
.build();
12201227
assert!(result.is_err());
12211228
if let Err(e) = result {
1222-
assert_eq!(e.description(), "TIME_MICROS can only annotate INT64");
1229+
assert_eq!(
1230+
e.to_string(),
1231+
"Parquet error: TIME_MICROS can only annotate INT64"
1232+
);
12231233
}
12241234

12251235
result = Type::primitive_type_builder("foo", PhysicalType::BYTE_ARRAY)
@@ -1229,8 +1239,8 @@ mod tests {
12291239
assert!(result.is_err());
12301240
if let Err(e) = result {
12311241
assert_eq!(
1232-
e.description(),
1233-
"INTERVAL can only annotate FIXED_LEN_BYTE_ARRAY(12)"
1242+
e.to_string(),
1243+
"Parquet error: INTERVAL can only annotate FIXED_LEN_BYTE_ARRAY(12)"
12341244
);
12351245
}
12361246

@@ -1242,8 +1252,8 @@ mod tests {
12421252
assert!(result.is_err());
12431253
if let Err(e) = result {
12441254
assert_eq!(
1245-
e.description(),
1246-
"INTERVAL can only annotate FIXED_LEN_BYTE_ARRAY(12)"
1255+
e.to_string(),
1256+
"Parquet error: INTERVAL can only annotate FIXED_LEN_BYTE_ARRAY(12)"
12471257
);
12481258
}
12491259

@@ -1253,7 +1263,10 @@ mod tests {
12531263
.build();
12541264
assert!(result.is_err());
12551265
if let Err(e) = result {
1256-
assert_eq!(e.description(), "ENUM can only annotate BYTE_ARRAY fields");
1266+
assert_eq!(
1267+
e.to_string(),
1268+
"Parquet error: ENUM can only annotate BYTE_ARRAY fields"
1269+
);
12571270
}
12581271

12591272
result = Type::primitive_type_builder("foo", PhysicalType::INT32)
@@ -1262,7 +1275,10 @@ mod tests {
12621275
.build();
12631276
assert!(result.is_err());
12641277
if let Err(e) = result {
1265-
assert_eq!(e.description(), "MAP cannot be applied to a primitive type");
1278+
assert_eq!(
1279+
e.to_string(),
1280+
"Parquet error: MAP cannot be applied to a primitive type"
1281+
);
12661282
}
12671283

12681284
result = Type::primitive_type_builder("foo", PhysicalType::FIXED_LEN_BYTE_ARRAY)
@@ -1272,7 +1288,10 @@ mod tests {
12721288
.build();
12731289
assert!(result.is_err());
12741290
if let Err(e) = result {
1275-
assert_eq!(e.description(), "Invalid FIXED_LEN_BYTE_ARRAY length: -1");
1291+
assert_eq!(
1292+
e.to_string(),
1293+
"Parquet error: Invalid FIXED_LEN_BYTE_ARRAY length: -1"
1294+
);
12761295
}
12771296
}
12781297

@@ -1757,7 +1776,10 @@ mod tests {
17571776
let thrift_schema = to_thrift(&schema);
17581777
assert!(thrift_schema.is_err());
17591778
if let Err(e) = thrift_schema {
1760-
assert_eq!(e.description(), "Root schema must be Group type");
1779+
assert_eq!(
1780+
e.to_string(),
1781+
"Parquet error: Root schema must be Group type"
1782+
);
17611783
}
17621784
}
17631785

0 commit comments

Comments
 (0)