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 1cc87ec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
55 changes: 29 additions & 26 deletions parquet/src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,20 @@ impl FromStr for Encoding {
type Err = ParquetError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
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)),
}
}
Expand Down Expand Up @@ -345,7 +349,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 +358,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" => {
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
}
Expand Down Expand Up @@ -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
Expand All @@ -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);
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 1cc87ec

Please sign in to comment.