## 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/table_source.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
    //! Table source
    19
    20
    use crate::{Expr, LogicalPlan};
    21
    22
    use arrow::datatypes::SchemaRef;
    23
    use datafusion_common::{Constraints, Result};
    24
    25
    use std::{any::Any, borrow::Cow};
    26
    27
    /// Indicates how a filter expression is handled by
    28
    /// [`TableProvider::scan`].
    29
    ///
    30
    /// Filter expressions are boolean expressions used to reduce the number of
    31
    /// rows that are read from a table. Only rows that evaluate to `true` ("pass
    32
    /// the filter") are returned. Rows that evaluate to `false` or `NULL` are
    33
    /// omitted.
    34
    ///
    35
    /// [`TableProvider::scan`]: https://docs.rs/datafusion/latest/datafusion/datasource/trait.TableProvider.html#tymethod.scan
    36
    #[derive(Debug, Clone, PartialEq, Eq)]
    37
    pub enum TableProviderFilterPushDown {
    38
        /// The filter cannot be used by the provider and will not be pushed down.
    39
        Unsupported,
    40
        /// The filter can be used, but the provider might still return some tuples
    41
        /// that do not pass the filter.
    42
        ///
    43
        /// In this case, DataFusion applies an additional `Filter` operation
    44
        /// after the scan to ensure all rows are filtered correctly.
    45
        Inexact,
    46
        /// The provider **guarantees** that it will omit **only** tuples which
    47
        /// pass the filter.
    48
        ///
    49
        /// In this case, DataFusion will not apply additional filtering.
    50
        Exact,
    51
    }
    52
    53
    /// Indicates the type of this table for metadata/catalog purposes.
    54
    #[derive(Debug, Clone, Copy, PartialEq, Eq)]
    55
    pub enum TableType {
    56
        /// An ordinary physical table.
    57
        Base,
    58
        /// A non-materialized table that itself uses a query internally to provide data.
    59
        View,
    60
        /// A transient table.
    61
        Temporary,
    62
    }
    63
    64
    impl std::fmt::Display for TableType {
    65
    0
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    66
    0
            match self {
    67
    0
                TableType::Base => write!(f, "Base"),
    68
    0
                TableType::View => write!(f, "View"),
    69
    0
                TableType::Temporary => write!(f, "Temporary"),
    70
            }
    71
    0
        }
    72
    }
    73
    74
    /// Planning time information about a table.
    75
    ///
    76
    /// This trait is used during logical query planning and optimizations, and
    77
    /// provides a subset of the [`TableProvider`] trait, such as schema information
    78
    /// and filter push-down capabilities. The [`TableProvider`] trait provides
    79
    /// additional information needed for physical query execution, such as the
    80
    /// ability to perform a scan or insert data.
    81
    ///
    82
    /// # See Also:
    83
    ///
    84
    /// [`DefaultTableSource`]  to go from [`TableProvider`], to `TableSource`
    85
    ///
    86
    /// # Rationale
    87
    ///
    88
    /// The reason for having two separate traits is to avoid having the logical
    89
    /// plan code be dependent on the DataFusion execution engine. Some projects use
    90
    /// DataFusion's logical plans and have their own execution engine.
    91
    ///
    92
    /// [`TableProvider`]: https://docs.rs/datafusion/latest/datafusion/datasource/trait.TableProvider.html
    93
    /// [`DefaultTableSource`]: https://docs.rs/datafusion/latest/datafusion/datasource/default_table_source/struct.DefaultTableSource.html
    94
    pub trait TableSource: Sync + Send {
    95
        fn as_any(&self) -> &dyn Any;
    96
    97
        /// Get a reference to the schema for this table
    98
        fn schema(&self) -> SchemaRef;
    99
    100
        /// Get primary key indices, if any
    101
    0
        fn constraints(&self) -> Option<&Constraints> {
    102
    0
            None
    103
    0
        }
    104
    105
        /// Get the type of this table for metadata/catalog purposes.
    106
    0
        fn table_type(&self) -> TableType {
    107
    0
            TableType::Base
    108
    0
        }
    109
    110
        /// Tests whether the table provider can make use of any or all filter expressions
    111
        /// to optimize data retrieval. Only non-volatile expressions are passed to this function.
    112
    0
        fn supports_filters_pushdown(
    113
    0
            &self,
    114
    0
            filters: &[&Expr],
    115
    0
        ) -> Result<Vec<TableProviderFilterPushDown>> {
    116
    0
            Ok((0..filters.len())
    117
    0
                .map(|_| TableProviderFilterPushDown::Unsupported)
    118
    0
                .collect())
    119
    0
        }
    120
    121
        /// Get the Logical plan of this table provider, if available.
    122
        ///
    123
        /// For example, a view may have a logical plan, but a CSV file does not.
    124
    0
        fn get_logical_plan(&'_ self) -> Option<Cow<'_, LogicalPlan>> {
    125
    0
            None
    126
    0
        }
    127
    128
        /// Get the default value for a column, if available.
    129
    0
        fn get_column_default(&self, _column: &str) -> Option<&Expr> {
    130
    0
            None
    131
    0
        }
    132
    }