iceberg-cpp
Loading...
Searching...
No Matches
sort_order.h
Go to the documentation of this file.
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
24
25#include <cstdint>
26#include <memory>
27#include <span>
28#include <unordered_set>
29#include <vector>
30
32#include "iceberg/sort_field.h"
33#include "iceberg/type_fwd.h"
35
36namespace iceberg {
37
43class ICEBERG_EXPORT SortOrder : public util::Formattable {
44 public:
45 static constexpr int32_t kUnsortedOrderId = 0;
46 static constexpr int32_t kInitialSortOrderId = 1;
47
49 static const std::shared_ptr<SortOrder>& Unsorted();
50
52 int32_t order_id() const;
53
55 std::span<const SortField> fields() const;
56
58 bool is_sorted() const { return !fields_.empty(); }
59
62 bool is_unsorted() const { return fields_.empty(); }
63
65 bool Satisfies(const SortOrder& other) const;
66
69 bool SameOrder(const SortOrder& other) const;
70
71 std::string ToString() const override;
72
73 friend bool operator==(const SortOrder& lhs, const SortOrder& rhs) {
74 return lhs.Equals(rhs);
75 }
76
80 Status Validate(const Schema& schema) const;
81
87 static Result<std::unique_ptr<SortOrder>> Make(const Schema& schema, int32_t sort_id,
88 std::vector<SortField> fields);
89
95 static Result<std::unique_ptr<SortOrder>> Make(int32_t sort_id,
96 std::vector<SortField> fields);
97
98 static std::unordered_set<std::string_view> OrderPreservingSortedColumns(
99 const Schema& schema, const SortOrder& order);
100
101 private:
106 SortOrder(int32_t order_id, std::vector<SortField> fields);
107
109 bool Equals(const SortOrder& other) const;
110
111 int32_t order_id_;
112 std::vector<SortField> fields_;
113};
114
115} // namespace iceberg
A schema for a Table.
Definition schema.h:51
A sort order for a table.
Definition sort_order.h:43
bool SameOrder(const SortOrder &other) const
Checks whether this order is equivalent to another order while ignoring the order id.
static Result< std::unique_ptr< SortOrder > > Make(int32_t sort_id, std::vector< SortField > fields)
Create a SortOrder without binding to a schema.
std::span< const SortField > fields() const
Get the list of sort fields.
int32_t order_id() const
Get the sort order id.
std::string ToString() const override
Get a user-readable string representation.
bool is_sorted() const
Returns true if the sort order is sorted.
Definition sort_order.h:58
bool Satisfies(const SortOrder &other) const
Checks whether this order satisfies another order.
Status Validate(const Schema &schema) const
Validates the sort order against a schema.
static const std::shared_ptr< SortOrder > & Unsorted()
Get an unsorted sort order singleton.
static Result< std::unique_ptr< SortOrder > > Make(const Schema &schema, int32_t sort_id, std::vector< SortField > fields)
Create a SortOrder.
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:62
Interface for objects that can be formatted via std::format.
Definition formattable.h:36
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88