HaoYang670 commented on code in PR #4637:
URL: https://github.com/apache/arrow-datafusion/pull/4637#discussion_r1049570255


##########
datafusion/core/src/datasource/file_format/file_type.rs:
##########
@@ -50,48 +52,59 @@ pub trait GetExt {
 
 /// Readable file compression type
 #[derive(Debug, Clone, PartialEq, Eq)]
-pub enum FileCompressionType {
-    /// Gzip-ed file
-    GZIP,
-    /// Bzip2-ed file
-    BZIP2,
-    /// Xz-ed file (liblzma)
-    XZ,
-    /// Uncompressed file
-    UNCOMPRESSED,
+pub struct FileCompressionType {
+    variant: CompressionTypeVariant,
 }
 
 impl GetExt for FileCompressionType {
     fn get_ext(&self) -> String {
-        match self {
-            FileCompressionType::GZIP => ".gz".to_owned(),
-            FileCompressionType::BZIP2 => ".bz2".to_owned(),
-            FileCompressionType::XZ => ".xz".to_owned(),
-            FileCompressionType::UNCOMPRESSED => "".to_owned(),
+        match self.variant {
+            GZIP => ".gz".to_owned(),
+            BZIP2 => ".bz2".to_owned(),
+            XZ => ".xz".to_owned(),
+            UNCOMPRESSED => "".to_owned(),
         }
     }
 }
 
+impl From<CompressionTypeVariant> for FileCompressionType {
+    fn from(t: CompressionTypeVariant) -> Self {
+        Self { variant: t }
+    }
+}
+
 impl FromStr for FileCompressionType {
     type Err = DataFusionError;
 
     fn from_str(s: &str) -> Result<Self> {
-        let s = s.to_uppercase();
-        match s.as_str() {
-            "GZIP" | "GZ" => Ok(FileCompressionType::GZIP),
-            "BZIP2" | "BZ2" => Ok(FileCompressionType::BZIP2),
-            "XZ" => Ok(FileCompressionType::XZ),
-            "" => Ok(FileCompressionType::UNCOMPRESSED),
-            _ => Err(DataFusionError::NotImplemented(format!(
-                "Unknown FileCompressionType: {}",
-                s
-            ))),
-        }
+        let variant = CompressionTypeVariant::from_str(s).map_err(|_| {
+            DataFusionError::NotImplemented(format!("Unknown 
FileCompressionType: {}", s))
+        })?;
+        Ok(Self { variant })
     }
 }
 
 /// `FileCompressionType` implementation
 impl FileCompressionType {
+    /// Gzip-ed file
+    pub const GZIP: Self = Self { variant: GZIP };
+
+    /// Bzip2-ed file
+    pub const BZIP2: Self = Self { variant: BZIP2 };
+
+    /// Xz-ed file (liblzma)
+    pub const XZ: Self = Self { variant: XZ };
+
+    /// Uncompressed file
+    pub const UNCOMPRESSED: Self = Self {
+        variant: UNCOMPRESSED,
+    };

Review Comment:
   They are a little tricky, but can minimize the code change.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to