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