Skip to main content

datafusion_functions_window_common/
expr.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5use datafusion_common::arrow::datatypes::FieldRef;
6use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
7use std::sync::Arc;
8
9/// Arguments passed to user-defined window function
10#[derive(Debug, Default)]
11pub struct ExpressionArgs<'a> {
12    /// The expressions passed as arguments to the user-defined window
13    /// function.
14    input_exprs: &'a [Arc<dyn PhysicalExpr>],
15    /// The corresponding fields of expressions passed as arguments
16    /// to the user-defined window function.
17    input_fields: &'a [FieldRef],
18}
19
20impl<'a> ExpressionArgs<'a> {
21    /// Create an instance of [`ExpressionArgs`].
22    ///
23    /// # Arguments
24    ///
25    /// * `input_exprs` - The expressions passed as arguments
26    ///   to the user-defined window function.
27    /// * `input_fields` - The fields corresponding to the
28    ///   arguments to the user-defined window function.
29    pub fn new(
30        input_exprs: &'a [Arc<dyn PhysicalExpr>],
31        input_fields: &'a [FieldRef],
32    ) -> Self {
33        Self {
34            input_exprs,
35            input_fields,
36        }
37    }
38
39    /// Returns the expressions passed as arguments to the user-defined
40    /// window function.
41    pub fn input_exprs(&self) -> &'a [Arc<dyn PhysicalExpr>] {
42        self.input_exprs
43    }
44
45    /// Returns the [`FieldRef`]s corresponding to the input expressions
46    /// to the user-defined window function.
47    pub fn input_fields(&self) -> &'a [FieldRef] {
48        self.input_fields
49    }
50}