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_types` - The data types 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 ///
52 pub fn new(
53 input_exprs: &'a [Arc<dyn PhysicalExpr>],
54 input_fields: &'a [FieldRef],
55 is_reversed: bool,
56 ignore_nulls: bool,
57 ) -> Self {
58 Self {
59 input_exprs,
60 input_fields,
61 is_reversed,
62 ignore_nulls,
63 }
64 }
65
66 /// Returns the expressions passed as arguments to the user-defined
67 /// window function.
68 pub fn input_exprs(&self) -> &'a [Arc<dyn PhysicalExpr>] {
69 self.input_exprs
70 }
71
72 /// Returns the [`FieldRef`]s corresponding to the input expressions
73 /// to the user-defined window function.
74 pub fn input_fields(&self) -> &'a [FieldRef] {
75 self.input_fields
76 }
77
78 /// Returns `true` when the user-defined window function is
79 /// reversed, otherwise returns `false`.
80 pub fn is_reversed(&self) -> bool {
81 self.is_reversed
82 }
83
84 /// Returns `true` when `IGNORE NULLS` is specified, otherwise
85 /// returns `false`.
86 pub fn ignore_nulls(&self) -> bool {
87 self.ignore_nulls
88 }
89}