## 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/physical-expr/src/window/standard_window_function_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 crate::{PhysicalExpr, PhysicalSortExpr};
    19
    20
    use arrow::array::ArrayRef;
    21
    use arrow::datatypes::{FieldRef, SchemaRef};
    22
    use arrow::record_batch::RecordBatch;
    23
    use datafusion_common::Result;
    24
    use datafusion_expr::{LimitEffect, PartitionEvaluator};
    25
    26
    use datafusion_physical_expr_common::utils::evaluate_expressions_to_arrays;
    27
    use std::any::Any;
    28
    use std::sync::Arc;
    29
    30
    /// Evaluates a window function by instantiating a
    31
    /// `[PartitionEvaluator]` for calculating the function's output in
    32
    /// that partition.
    33
    ///
    34
    /// Note that unlike aggregation based window functions, some window
    35
    /// functions such as `rank` ignore the values in the window frame,
    36
    /// but others such as `first_value`, `last_value`, and
    37
    /// `nth_value` need the value.
    38
    #[allow(rustdoc::private_intra_doc_links)]
    39
    pub trait StandardWindowFunctionExpr: Send + Sync + std::fmt::Debug {
    40
        /// Returns the aggregate expression as [`Any`] so that it can be
    41
        /// downcast to a specific implementation.
    42
        fn as_any(&self) -> &dyn Any;
    43
    44
        /// The field of the final result of evaluating this window function.
    45
        fn field(&self) -> Result<FieldRef>;
    46
    47
        /// Expressions that are passed to the [`PartitionEvaluator`].
    48
        fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>>;
    49
    50
        /// Human readable name such as `"MIN(c2)"` or `"RANK()"`. The default
    51
        /// implementation returns placeholder text.
    52
    0
        fn name(&self) -> &str {
    53
    0
            "StandardWindowFunctionExpr: default name"
    54
    0
        }
    55
    56
        /// Evaluate window function's arguments against the input window
    57
        /// batch and return an [`ArrayRef`].
    58
        ///
    59
        /// Typically, the resulting vector is a single element vector.
    60
    0
        fn evaluate_args(&self, batch: &RecordBatch) -> Result<Vec<ArrayRef>> {
    61
    0
            evaluate_expressions_to_arrays(&self.expressions(), batch)
    62
    0
        }
    63
    64
        /// Create a [`PartitionEvaluator`] for evaluating the function on
    65
        /// a particular partition.
    66
        fn create_evaluator(&self) -> Result<Box<dyn PartitionEvaluator>>;
    67
    68
        /// Construct a new [`StandardWindowFunctionExpr`] that produces
    69
        /// the same result as this function on a window with reverse
    70
        /// order. The return value of this function is used by the
    71
        /// DataFusion optimizer to avoid re-sorting the data when
    72
        /// possible.
    73
        ///
    74
        /// Returns `None` (the default) if no reverse is known (or possible).
    75
        ///
    76
        /// For example, the reverse of `lead(10)` is `lag(10)`.
    77
    0
        fn reverse_expr(&self) -> Option<Arc<dyn StandardWindowFunctionExpr>> {
    78
    0
            None
    79
    0
        }
    80
    81
        /// Returns the ordering introduced by the window function, if applicable.
    82
        /// Most window functions don't introduce an ordering, hence the default
    83
        /// value is `None`. Note that this information is used to update ordering
    84
        /// equivalences.
    85
    0
        fn get_result_ordering(&self, _schema: &SchemaRef) -> Option<PhysicalSortExpr> {
    86
    0
            None
    87
    0
        }
    88
    89
        fn limit_effect(&self) -> LimitEffect;
    90
    }