Skip to content

Commit

Permalink
fix only support lower and uppercase
Browse files Browse the repository at this point in the history
Signed-off-by: fan <[email protected]>
  • Loading branch information
fansehep committed Oct 18, 2023
1 parent 3b5a198 commit 730a102
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
23 changes: 11 additions & 12 deletions parquet/src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ fn check_level_is_none(level: &Option<u32>) -> Result<(), ParquetError> {
Ok(())
}

fn require_level(codec: &String, level: Option<u32>) -> Result<u32, ParquetError> {
fn require_level(codec: &str, level: Option<u32>) -> Result<u32, ParquetError> {
level.ok_or(ParquetError::General(format!("{} require level", codec)))
}

Expand All @@ -354,38 +354,37 @@ impl FromStr for Compression {

fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
let (codec, level) = split_compression_string(s)?;
let codec = codec.to_uppercase();

let c = match codec.as_str() {
"UNCOMPRESSED" => {
let c = match codec {
"UNCOMPRESSED" | "uncompressed" => {
check_level_is_none(&level)?;
Compression::UNCOMPRESSED
}
"SNAPPY" => {
"SNAPPY" | "snappy" => {
check_level_is_none(&level)?;
Compression::SNAPPY
}
"GZIP" => {
"GZIP" | "gzip" => {
let level = require_level(&codec, level)?;
Compression::GZIP(GzipLevel::try_new(level)?)
}
"LZO" => {
"LZO" | "lzo" => {
check_level_is_none(&level)?;
Compression::LZO
}
"BROTLI" => {
"BROTLI" | "brotli" => {
let level = require_level(&codec, level)?;
Compression::BROTLI(BrotliLevel::try_new(level)?)
}
"LZ4" => {
"LZ4" | "lz4" => {
check_level_is_none(&level)?;
Compression::LZ4
}
"ZSTD" => {
"ZSTD" | "zstd" => {
let level = require_level(&codec, level)?;
Compression::ZSTD(ZstdLevel::try_new(level as i32)?)
}
"LZ4_RAW" => {
"LZ4_RAW" | "lz4_raw" => {
check_level_is_none(&level)?;
Compression::LZ4_RAW
}
Expand Down Expand Up @@ -2280,7 +2279,7 @@ mod tests {
assert_eq!(compress, Compression::LZO);
compress = "zstd(3)".parse().unwrap();
assert_eq!(compress, Compression::ZSTD(ZstdLevel::try_new(3).unwrap()));
compress = "LZ4_raw".parse().unwrap();
compress = "LZ4_RAW".parse().unwrap();
assert_eq!(compress, Compression::LZ4_RAW);
compress = "uncompressed".parse().unwrap();
assert_eq!(compress, Compression::UNCOMPRESSED);
Expand Down
14 changes: 7 additions & 7 deletions parquet/src/file/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ impl FromStr for WriterVersion {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_owned().to_uppercase().as_str() {
"PARQUET_1_0" => Ok(WriterVersion::PARQUET_1_0),
"PARQUET_2_0" => Ok(WriterVersion::PARQUET_2_0),
match s {
"PARQUET_1_0" | "parquet_1_0" => Ok(WriterVersion::PARQUET_1_0),
"PARQUET_2_0" | "parquet_2_0" => Ok(WriterVersion::PARQUET_2_0),
_ => Err(format!("Invalid writer version: {}", s)),
}
}
Expand Down Expand Up @@ -672,10 +672,10 @@ impl FromStr for EnabledStatistics {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_owned().to_uppercase().as_str() {
"NONE" => Ok(EnabledStatistics::None),
"CHUNK" => Ok(EnabledStatistics::Chunk),
"PAGE" => Ok(EnabledStatistics::Page),
match s {
"NONE" | "none" => Ok(EnabledStatistics::None),
"CHUNK" | "chunk" => Ok(EnabledStatistics::Chunk),
"PAGE" | "page" => Ok(EnabledStatistics::Page),
_ => Err(format!("Invalid statistics arg: {}", s)),
}
}
Expand Down

0 comments on commit 730a102

Please sign in to comment.