## Coverage Report

#### Created: 2025-11-22 06:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)

    /Users/andrewlamb/Software/datafusion/datafusion/expr/src/select_expr.rs

    Line
    Count
    Source
    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
    use std::fmt;
    19
    20
    use arrow::datatypes::FieldRef;
    21
    use datafusion_common::{Column, TableReference};
    22
    23
    use crate::{expr::WildcardOptions, Expr};
    24
    25
    /// Represents a SELECT expression in a SQL query.
    26
    ///
    27
    /// `SelectExpr` supports three types of expressions commonly found in the SELECT clause:
    28
    ///
    29
    /// * Wildcard (`*`) - Selects all columns
    30
    /// * Qualified wildcard (`table.*`) - Selects all columns from a specific table
    31
    /// * Regular expression - Any other expression like columns, functions, literals etc.
    32
    ///
    33
    /// This enum is typically used when you need to handle wildcards. After expanding `*` in the query,
    34
    /// you can use `Expr` for all other expressions.
    35
    ///
    36
    /// # Examples
    37
    ///
    38
    /// ```
    39
    /// use datafusion_expr::col;
    40
    /// use datafusion_expr::expr::WildcardOptions;
    41
    /// use datafusion_expr::select_expr::SelectExpr;
    42
    ///
    43
    /// // SELECT *
    44
    /// let wildcard = SelectExpr::Wildcard(WildcardOptions::default());
    45
    ///
    46
    /// // SELECT mytable.*
    47
    /// let qualified =
    48
    ///     SelectExpr::QualifiedWildcard("mytable".into(), WildcardOptions::default());
    49
    ///
    50
    /// // SELECT col1
    51
    /// let expr = SelectExpr::Expression(col("col1").into());
    52
    /// ```
    53
    #[derive(Clone, Debug)]
    54
    pub enum SelectExpr {
    55
        /// Represents a wildcard (`*`) that selects all columns from all tables.
    56
        /// The `WildcardOptions` control additional behavior like exclusions.
    57
        Wildcard(WildcardOptions),
    58
    59
        /// Represents a qualified wildcard (`table.*`) that selects all columns from a specific table.
    60
        /// The `TableReference` specifies the table and `WildcardOptions` control additional behavior.
    61
        QualifiedWildcard(TableReference, WildcardOptions),
    62
    63
        /// Represents any other valid SELECT expression like column references,
    64
        /// function calls, literals, etc.
    65
        Expression(Expr),
    66
    }
    67
    68
    impl fmt::Display for SelectExpr {
    69
    0
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    70
    0
            match self {
    71
    0
                SelectExpr::Wildcard(opt) => write!(f, "*{opt}"),
    72
    0
                SelectExpr::QualifiedWildcard(table, opt) => write!(f, "{table}.*{opt}"),
    73
    0
                SelectExpr::Expression(expr) => write!(f, "{expr}"),
    74
            }
    75
    0
        }
    76
    }
    77
    78
    impl From<Expr> for SelectExpr {
    79
    0
        fn from(expr: Expr) -> Self {
    80
    0
            SelectExpr::Expression(expr)
    81
    0
        }
    82
    }
    83
    84
    /// Create an [`SelectExpr::Expression`] from a [`Column`]
    85
    impl From<Column> for SelectExpr {
    86
    0
        fn from(value: Column) -> Self {
    87
    0
            Expr::Column(value).into()
    88
    0
        }
    89
    }
    90
    91
    /// Create an [`SelectExpr::Expression`] from an optional qualifier and a [`FieldRef`]. This is
    92
    /// useful for creating [`SelectExpr::Expression`] from a `DFSchema`.
    93
    ///
    94
    /// See example on [`Expr`]
    95
    impl<'a> From<(Option<&'a TableReference>, &'a FieldRef)> for SelectExpr {
    96
    0
        fn from(value: (Option<&'a TableReference>, &'a FieldRef)) -> Self {
    97
    0
            Expr::from(Column::from(value)).into()
    98
    0
        }
    99
    }