datafusion_physical_plan/
ordering.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
18/// Specifies how the input to an aggregation or window operator is ordered
19/// relative to their `GROUP BY` or  `PARTITION BY` expressions.
20///
21/// For example, if the existing ordering is `[a ASC, b ASC, c ASC]`
22///
23/// ## Window Functions
24/// - A `PARTITION BY b` clause can use `Linear` mode.
25/// - A `PARTITION BY a, c` or a `PARTITION BY c, a` can use
26///   `PartiallySorted([0])` or `PartiallySorted([1])` modes, respectively.
27///   (The vector stores the index of `a` in the respective PARTITION BY expression.)
28/// - A `PARTITION BY a, b` or a `PARTITION BY b, a` can use `Sorted` mode.
29///
30/// ## Aggregations
31/// - A `GROUP BY b` clause can use `Linear` mode, as the only one permutation `[b]`
32///   cannot satisfy the existing ordering.
33/// - A `GROUP BY a, c` or a `GROUP BY c, a` can use
34///   `PartiallySorted([0])` or `PartiallySorted([1])` modes, respectively, as
35///   the permutation `[a]` satisfies the existing ordering.
36///   (The vector stores the index of `a` in the respective PARTITION BY expression.)
37/// - A `GROUP BY a, b` or a `GROUP BY b, a` can use `Sorted` mode, as the
38///   full permutation `[a, b]` satisfies the existing ordering.
39///
40/// Note these are the same examples as above, but with `GROUP BY` instead of
41/// `PARTITION BY` to make the examples easier to read.
42#[derive(Debug, Clone, PartialEq)]
43pub enum InputOrderMode {
44    /// There is no partial permutation of the expressions satisfying the
45    /// existing ordering.
46    Linear,
47    /// There is a partial permutation of the expressions satisfying the
48    /// existing ordering. Indices describing the longest partial permutation
49    /// are stored in the vector.
50    PartiallySorted(Vec<usize>),
51    /// There is a (full) permutation of the expressions satisfying the
52    /// existing ordering.
53    Sorted,
54}