Skip to content

Commit

Permalink
Prefer ParquetError::oos to ParquetError::OutOfSpec (#17314)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanTater authored Jul 1, 2024
1 parent 227b350 commit 71e43b6
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion crates/polars-parquet/src/arrow/write/row_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn row_group_iter<A: AsRef<dyn Array> + 'static + Send + Sync>(
let pages = DynIter::new(
pages
.into_iter()
.map(|x| x.map_err(|e| ParquetError::OutOfSpec(e.to_string()))),
.map(|x| x.map_err(|e| ParquetError::oos(e.to_string()))),
);

let compressed_pages = Compressor::new(pages, options.compression, vec![])
Expand Down
4 changes: 1 addition & 3 deletions crates/polars-parquet/src/parquet/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ pub fn decompress(

let len = decompress_len(input_buf)?;
if len > output_buf.len() {
return Err(ParquetError::OutOfSpec(String::from(
"snappy header out of spec",
)));
return Err(ParquetError::oos("snappy header out of spec"));
}
Decoder::new()
.decompress(input_buf, output_buf)
Expand Down
1 change: 1 addition & 0 deletions crates/polars-parquet/src/parquet/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub enum ParquetError {
}

impl ParquetError {
/// Create an OutOfSpec error from any Into<String>
pub(crate) fn oos<I: Into<String>>(message: I) -> Self {
Self::OutOfSpec(message.into())
}
Expand Down
8 changes: 4 additions & 4 deletions crates/polars-parquet/src/parquet/read/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ fn decompress_v2(

if can_decompress {
if offset > buffer.len() || offset > compressed.len() {
return Err(ParquetError::OutOfSpec(
"V2 Page Header reported incorrect offset to compressed data".to_string(),
return Err(ParquetError::oos(
"V2 Page Header reported incorrect offset to compressed data",
));
}

Expand All @@ -43,8 +43,8 @@ fn decompress_v2(
compression::decompress(compression, &compressed[offset..], &mut buffer[offset..])?;
} else {
if buffer.len() != compressed.len() {
return Err(ParquetError::OutOfSpec(
"V2 Page Header reported incorrect decompressed size".to_string(),
return Err(ParquetError::oos(
"V2 Page Header reported incorrect decompressed size",
));
}
buffer.copy_from_slice(compressed);
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-parquet/src/parquet/read/page/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub(super) fn build_page<R: Read>(

if bytes_read != read_size {
return Err(ParquetError::oos(
"The page header reported the wrong page size".to_string(),
"The page header reported the wrong page size",
));
}

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-parquet/src/parquet/read/page/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn _get_page_stream<R: AsyncRead + Unpin + Send>(

if bytes_read != read_size {
Err(ParquetError::oos(
"The page header reported the wrong page size".to_string(),
"The page header reported the wrong page size",
))?
}

Expand Down
9 changes: 4 additions & 5 deletions crates/polars-parquet/src/parquet/schema/types/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ fn check_decimal_invariants(
PhysicalType::ByteArray => {},
_ => {
return Err(ParquetError::oos(
"DECIMAL can only annotate INT32, INT64, BYTE_ARRAY and FIXED_LEN_BYTE_ARRAY"
.to_string(),
"DECIMAL can only annotate INT32, INT64, BYTE_ARRAY and FIXED_LEN_BYTE_ARRAY",
))
},
};
Expand Down Expand Up @@ -111,14 +110,14 @@ pub fn check_converted_invariants(
Interval => {
if physical_type != &PhysicalType::FixedLenByteArray(12) {
return Err(ParquetError::oos(
"INTERVAL can only annotate FIXED_LEN_BYTE_ARRAY(12)".to_string(),
"INTERVAL can only annotate FIXED_LEN_BYTE_ARRAY(12)",
));
}
},
Enum => {
if physical_type != &PhysicalType::ByteArray {
return Err(ParquetError::oos(
"ENUM can only annotate BYTE_ARRAY fields".to_string(),
"ENUM can only annotate BYTE_ARRAY fields",
));
}
},
Expand Down Expand Up @@ -153,7 +152,7 @@ pub fn check_logical_invariants(
(Time { unit, .. }, PhysicalType::Int64) => {
if unit == TimeUnit::Milliseconds {
return Err(ParquetError::oos(
"Cannot use millisecond unit on INT64 type".to_string(),
"Cannot use millisecond unit on INT64 type",
));
}
},
Expand Down

0 comments on commit 71e43b6

Please sign in to comment.