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

Do not print compression level in schema printer #6271

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions parquet/src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ pub enum Compression {
LZ4_RAW,
}

impl Compression {
/// Returns the codec type of this compression setting as a string, without the compression
/// level.
pub(crate) fn codec_to_string(self) -> String {
format!("{:?}", self).split('(').next().unwrap().to_owned()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to avoid panic'ing here if there is no ( in the string -- I think this will panic if it is called on CompressionLevel::UNCOMPRESSED for example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no (, then split() will return just one component – the entire string (even if it's empty). There is no way this can panic. But I've added a test anyway.

}
}

fn split_compression_string(str_setting: &str) -> Result<(&str, Option<u32>), ParquetError> {
let split_setting = str_setting.split_once('(');

Expand Down Expand Up @@ -1915,6 +1923,15 @@ mod tests {
);
}

#[test]
fn test_compression_codec_to_string() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

assert_eq!(Compression::UNCOMPRESSED.codec_to_string(), "UNCOMPRESSED");
assert_eq!(
Compression::ZSTD(ZstdLevel::default()).codec_to_string(),
"ZSTD"
);
}

#[test]
fn test_display_compression() {
assert_eq!(Compression::UNCOMPRESSED.to_string(), "UNCOMPRESSED");
Expand Down
6 changes: 5 additions & 1 deletion parquet/src/schema/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ fn print_column_chunk_metadata(out: &mut dyn io::Write, cc_metadata: &ColumnChun
writeln!(out, "file path: {file_path_str}");
writeln!(out, "file offset: {}", cc_metadata.file_offset());
writeln!(out, "num of values: {}", cc_metadata.num_values());
writeln!(out, "compression: {}", cc_metadata.compression());
writeln!(
out,
"compression: {}",
cc_metadata.compression().codec_to_string()
);
writeln!(
out,
"total compressed size (in bytes): {}",
Expand Down
Loading