iceberg-cpp
Loading...
Searching...
No Matches
sort_order.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <cstdint>
23#include <memory>
24#include <span>
25#include <unordered_set>
26#include <vector>
27
28#include "iceberg/iceberg_export.h"
29#include "iceberg/sort_field.h"
30#include "iceberg/type_fwd.h"
32
33namespace iceberg {
34
40class ICEBERG_EXPORT SortOrder : public util::Formattable {
41 public:
42 static constexpr int32_t kUnsortedOrderId = 0;
43 static constexpr int32_t kInitialSortOrderId = 1;
44
46 static const std::shared_ptr<SortOrder>& Unsorted();
47
49 int32_t order_id() const;
50
52 std::span<const SortField> fields() const;
53
55 bool is_sorted() const { return !fields_.empty(); }
56
59 bool is_unsorted() const { return fields_.empty(); }
60
62 bool Satisfies(const SortOrder& other) const;
63
66 bool SameOrder(const SortOrder& other) const;
67
68 std::string ToString() const override;
69
70 friend bool operator==(const SortOrder& lhs, const SortOrder& rhs) {
71 return lhs.Equals(rhs);
72 }
73
77 Status Validate(const Schema& schema) const;
78
84 static Result<std::unique_ptr<SortOrder>> Make(const Schema& schema, int32_t sort_id,
85 std::vector<SortField> fields);
86
92 static Result<std::unique_ptr<SortOrder>> Make(int32_t sort_id,
93 std::vector<SortField> fields);
94
95 static std::unordered_set<std::string_view> OrderPreservingSortedColumns(
96 const Schema& schema, const SortOrder& order);
97
98 private:
103 SortOrder(int32_t order_id, std::vector<SortField> fields);
104
106 bool Equals(const SortOrder& other) const;
107
108 int32_t order_id_;
109 std::vector<SortField> fields_;
110};
111
112} // namespace iceberg
A sort order for a table.
Definition sort_order.h:40
bool is_sorted() const
Returns true if the sort order is sorted.
Definition sort_order.h:55
bool is_unsorted() const
Returns true if the sort order is unsorted A SortOrder is unsorted if it has no sort fields.
Definition sort_order.h:59
Interface for objects that can be formatted via std::format.
Definition formattable.h:36