From 1cc87ec249acb65c1377b3df6d6226ed95df329f Mon Sep 17 00:00:00 2001 From: fan Date: Wed, 18 Oct 2023 15:49:49 +0800 Subject: [PATCH] fix only support lower and uppercase Signed-off-by: fan --- parquet/src/basic.rs | 55 ++++++++++++++++++---------------- parquet/src/file/properties.rs | 14 ++++----- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/parquet/src/basic.rs b/parquet/src/basic.rs index e38bcdaa945f..cdad3597ffef 100644 --- a/parquet/src/basic.rs +++ b/parquet/src/basic.rs @@ -283,16 +283,20 @@ impl FromStr for Encoding { type Err = ParquetError; fn from_str(s: &str) -> Result { - match s.to_owned().to_uppercase().as_str() { - "PLAIN" => Ok(Encoding::PLAIN), - "PLAIN_DICTIONARY" => Ok(Encoding::PLAIN_DICTIONARY), - "RLE" => Ok(Encoding::RLE), - "BIT_PACKED" => Ok(Encoding::BIT_PACKED), - "DELTA_BINARY_PACKED" => Ok(Encoding::DELTA_BINARY_PACKED), - "DELTA_LENGTH_BYTE_ARRAY" => Ok(Encoding::DELTA_LENGTH_BYTE_ARRAY), - "DELTA_BYTE_ARRAY" => Ok(Encoding::DELTA_BYTE_ARRAY), - "RLE_DICTIONARY" => Ok(Encoding::RLE_DICTIONARY), - "BYTE_STREAM_SPLIT" => Ok(Encoding::BYTE_STREAM_SPLIT), + match s { + "PLAIN" | "plain" => Ok(Encoding::PLAIN), + "PLAIN_DICTIONARY" | "plain_dictionary" => Ok(Encoding::PLAIN_DICTIONARY), + "RLE" | "rle" => Ok(Encoding::RLE), + "BIT_PACKED" | "bit_packed" => Ok(Encoding::BIT_PACKED), + "DELTA_BINARY_PACKED" | "delta_binary_packed" => { + Ok(Encoding::DELTA_BINARY_PACKED) + } + "DELTA_LENGTH_BYTE_ARRAY" | "delta_length_byte_array" => { + Ok(Encoding::DELTA_LENGTH_BYTE_ARRAY) + } + "DELTA_BYTE_ARRAY" | "delta_byte_array" => Ok(Encoding::DELTA_BYTE_ARRAY), + "RLE_DICTIONARY" | "rle_dictionary" => Ok(Encoding::RLE_DICTIONARY), + "BYTE_STREAM_SPLIT" | "byte_stream_split" => Ok(Encoding::BYTE_STREAM_SPLIT), _ => Err(general_err!("unknown encoding: {}", s)), } } @@ -345,7 +349,7 @@ fn check_level_is_none(level: &Option) -> Result<(), ParquetError> { Ok(()) } -fn require_level(codec: &String, level: Option) -> Result { +fn require_level(codec: &str, level: Option) -> Result { level.ok_or(ParquetError::General(format!("{} require level", codec))) } @@ -354,38 +358,37 @@ impl FromStr for Compression { fn from_str(s: &str) -> std::result::Result { 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" => { - let level = require_level(&codec, level)?; + "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" => { - let level = require_level(&codec, level)?; + "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" => { - let level = require_level(&codec, level)?; + "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 } @@ -2258,7 +2261,7 @@ mod tests { assert_eq!(encoding, Encoding::BYTE_STREAM_SPLIT); // test lowercase - encoding = "Byte_Stream_Split".parse().unwrap(); + encoding = "byte_stream_split".parse().unwrap(); assert_eq!(encoding, Encoding::BYTE_STREAM_SPLIT); // test unknown string @@ -2280,7 +2283,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); diff --git a/parquet/src/file/properties.rs b/parquet/src/file/properties.rs index 51d964ecf5ff..93b034cf4f60 100644 --- a/parquet/src/file/properties.rs +++ b/parquet/src/file/properties.rs @@ -77,9 +77,9 @@ impl FromStr for WriterVersion { type Err = String; fn from_str(s: &str) -> Result { - 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)), } } @@ -672,10 +672,10 @@ impl FromStr for EnabledStatistics { type Err = String; fn from_str(s: &str) -> Result { - 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)), } }