## Coverage Report

#### Created: 2024-10-13 08:39

    /Users/andrewlamb/Software/datafusion/datafusion/common/src/parsers.rs

    Line
    Count
    Source (jump to first uncovered line)
    1
    // Licensed to the Apache Software Foundation (ASF) under one
    2
    // or more contributor license agreements.  See the NOTICE file
    3
    // distributed with this work for additional information
    4
    // regarding copyright ownership.  The ASF licenses this file
    5
    // to you under the Apache License, Version 2.0 (the
    6
    // "License"); you may not use this file except in compliance
    7
    // with the License.  You may obtain a copy of the License at
    8
    //
    9
    //   http://www.apache.org/licenses/LICENSE-2.0
    10
    //
    11
    // Unless required by applicable law or agreed to in writing,
    12
    // software distributed under the License is distributed on an
    13
    // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    14
    // KIND, either express or implied.  See the License for the
    15
    // specific language governing permissions and limitations
    16
    // under the License.
    17
    18
    //! Interval parsing logic
    19
    20
    use std::fmt::Display;
    21
    use std::result;
    22
    use std::str::FromStr;
    23
    24
    use sqlparser::parser::ParserError;
    25
    26
    /// Readable file compression type
    27
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
    28
    pub enum CompressionTypeVariant {
    29
        /// Gzip-ed file
    30
        GZIP,
    31
        /// Bzip2-ed file
    32
        BZIP2,
    33
        /// Xz-ed file (liblzma)
    34
        XZ,
    35
        /// Zstd-ed file,
    36
        ZSTD,
    37
        /// Uncompressed file
    38
        UNCOMPRESSED,
    39
    }
    40
    41
    impl FromStr for CompressionTypeVariant {
    42
        type Err = ParserError;
    43
    44
    0
        fn from_str(s: &str) -> result::Result<Self, ParserError> {
    45
    0
            let s = s.to_uppercase();
    46
    0
            match s.as_str() {
    47
    0
                "GZIP" | "GZ" => Ok(Self::GZIP),
    48
    0
                "BZIP2" | "BZ2" => Ok(Self::BZIP2),
    49
    0
                "XZ" => Ok(Self::XZ),
    50
    0
                "ZST" | "ZSTD" => Ok(Self::ZSTD),
    51
    0
                "" | "UNCOMPRESSED" => Ok(Self::UNCOMPRESSED),
    52
    0
                _ => Err(ParserError::ParserError(format!(
    53
    0
                    "Unsupported file compression type {s}"
    54
    0
                ))),
    55
            }
    56
    0
        }
    57
    }
    58
    59
    impl Display for CompressionTypeVariant {
    60
    0
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    61
    0
            let str = match self {
    62
    0
                Self::GZIP => "GZIP",
    63
    0
                Self::BZIP2 => "BZIP2",
    64
    0
                Self::XZ => "XZ",
    65
    0
                Self::ZSTD => "ZSTD",
    66
    0
                Self::UNCOMPRESSED => "",
    67
            };
    68
    0
            write!(f, "{}", str)
    69
    0
        }
    70
    }
    71
    72
    impl CompressionTypeVariant {
    73
    0
        pub const fn is_compressed(&self) -> bool {
    74
    0
            !matches!(self, &Self::UNCOMPRESSED)
    75
    0
        }
    76
    }