datafusion_functions_window_common/partition.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 created user-defined window function state
23/// during physical execution.
24#[derive(Debug, Default)]
25pub struct PartitionEvaluatorArgs<'a> {
26 /// The expressions passed as arguments to the user-defined window
27 /// function.
28 input_exprs: &'a [Arc<dyn PhysicalExpr>],
29 /// The corresponding fields of expressions passed as arguments
30 /// to the user-defined window function.
31 input_fields: &'a [FieldRef],
32 /// Set to `true` if the user-defined window function is reversed.
33 is_reversed: bool,
34 /// Set to `true` if `IGNORE NULLS` is specified.
35 ignore_nulls: bool,
36}
37
38impl<'a> PartitionEvaluatorArgs<'a> {
39 /// Create an instance of [`PartitionEvaluatorArgs`].
40 ///
41 /// # Arguments
42 ///
43 /// * `input_exprs` - The expressions passed as arguments
44 /// to the user-defined window function.
45 /// * `input_fields` - The fields corresponding to the
46 /// arguments to the user-defined window function.
47 /// * `is_reversed` - Set to `true` if and only if the user-defined
48 /// window function is reversible and is reversed.
49 /// * `ignore_nulls` - Set to `true` when `IGNORE NULLS` is
50 /// specified.
51 pub fn new(
52 input_exprs: &'a [Arc<dyn PhysicalExpr>],
53 input_fields: &'a [FieldRef],
54 is_reversed: bool,
55 ignore_nulls: bool,
56 ) -> Self {
57 Self {
58 input_exprs,
59 input_fields,
60 is_reversed,
61 ignore_nulls,
62 }
63 }
64
65 /// Returns the expressions passed as arguments to the user-defined
66 /// window function.
67 pub fn input_exprs(&self) -> &'a [Arc<dyn PhysicalExpr>] {
68 self.input_exprs
69 }
70
71 /// Returns the [`FieldRef`]s corresponding to the input expressions
72 /// to the user-defined window function.
73 pub fn input_fields(&self) -> &'a [FieldRef] {
74 self.input_fields
75 }
76
77 /// Returns `true` when the user-defined window function is
78 /// reversed, otherwise returns `false`.
79 pub fn is_reversed(&self) -> bool {
80 self.is_reversed
81 }
82
83 /// Returns `true` when `IGNORE NULLS` is specified, otherwise
84 /// returns `false`.
85 pub fn ignore_nulls(&self) -> bool {
86 self.ignore_nulls
87 }
88}