datafusion_functions_window_common/
field.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;
19
20/// Metadata for defining the result field from evaluating a
21/// user-defined window function.
22pub struct WindowUDFFieldArgs<'a> {
23    /// The fields corresponding to the arguments to the
24    /// user-defined window function.
25    input_fields: &'a [FieldRef],
26    /// The display name of the user-defined window function.
27    display_name: &'a str,
28}
29
30impl<'a> WindowUDFFieldArgs<'a> {
31    /// Create an instance of [`WindowUDFFieldArgs`].
32    ///
33    /// # Arguments
34    ///
35    /// * `input_fields` - The fields corresponding to the
36    ///   arguments to the user-defined window function.
37    /// * `function_name` - The qualified schema name of the
38    ///   user-defined window function expression.
39    ///
40    pub fn new(input_fields: &'a [FieldRef], display_name: &'a str) -> Self {
41        WindowUDFFieldArgs {
42            input_fields,
43            display_name,
44        }
45    }
46
47    /// Returns the field of input expressions passed as arguments
48    /// to the user-defined window function.
49    pub fn input_fields(&self) -> &[FieldRef] {
50        self.input_fields
51    }
52
53    /// Returns the name for the field of the final result of evaluating
54    /// the user-defined window function.
55    pub fn name(&self) -> &str {
56        self.display_name
57    }
58
59    /// Returns `Some(Field)` of input expression at index, otherwise
60    /// returns `None` if the index is out of bounds.
61    pub fn get_input_field(&self, index: usize) -> Option<FieldRef> {
62        self.input_fields.get(index).cloned()
63    }
64}