datafusion_functions_window_common/
expr.rs

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
18use datafusion_common::arrow::datatypes::FieldRef;
19use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
20use std::sync::Arc;
21
22/// Arguments passed to user-defined window function
23#[derive(Debug, Default)]
24pub struct ExpressionArgs<'a> {
25    /// The expressions passed as arguments to the user-defined window
26    /// function.
27    input_exprs: &'a [Arc<dyn PhysicalExpr>],
28    /// The corresponding fields of expressions passed as arguments
29    /// to the user-defined window function.
30    input_fields: &'a [FieldRef],
31}
32
33impl<'a> ExpressionArgs<'a> {
34    /// Create an instance of [`ExpressionArgs`].
35    ///
36    /// # Arguments
37    ///
38    /// * `input_exprs` - The expressions passed as arguments
39    ///   to the user-defined window function.
40    /// * `input_fields` - The fields corresponding to the
41    ///   arguments to the user-defined window function.
42    pub fn new(
43        input_exprs: &'a [Arc<dyn PhysicalExpr>],
44        input_fields: &'a [FieldRef],
45    ) -> Self {
46        Self {
47            input_exprs,
48            input_fields,
49        }
50    }
51
52    /// Returns the expressions passed as arguments to the user-defined
53    /// window function.
54    pub fn input_exprs(&self) -> &'a [Arc<dyn PhysicalExpr>] {
55        self.input_exprs
56    }
57
58    /// Returns the [`FieldRef`]s corresponding to the input expressions
59    /// to the user-defined window function.
60    pub fn input_fields(&self) -> &'a [FieldRef] {
61        self.input_fields
62    }
63}