Skip to main content

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