Skip to content

Commit 7e73e8b

Browse files
committed
fix review comments
1 parent b5aa7aa commit 7e73e8b

File tree

5 files changed

+42
-20
lines changed

5 files changed

+42
-20
lines changed

src/iceberg/sort_order.cc

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ std::span<const SortField> SortOrder::fields() const { return fields_; }
4141

4242
bool SortOrder::Satisfies(const SortOrder& other) const {
4343
// any ordering satisfies an unsorted ordering
44-
if (other.IsUnsorted()) {
44+
if (other.is_unsorted()) {
4545
return true;
4646
}
4747

@@ -61,17 +61,7 @@ bool SortOrder::Satisfies(const SortOrder& other) const {
6161
}
6262

6363
bool SortOrder::SameOrder(const SortOrder& other) const {
64-
if (fields_.size() != other.fields().size()) {
65-
return false;
66-
}
67-
68-
for (const auto& [field, other_field] : std::views::zip(fields_, other.fields())) {
69-
if (!(field == other_field)) {
70-
return false;
71-
}
72-
}
73-
74-
return true;
64+
return fields_ == other.fields_;
7565
}
7666

7767
std::string SortOrder::ToString() const {

src/iceberg/sort_order.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class ICEBERG_EXPORT SortOrder : public util::Formattable {
5050
std::span<const SortField> fields() const;
5151

5252
/// \brief Returns true if the sort order is sorted
53-
bool IsSorted() const { return !fields_.empty(); }
53+
bool is_sorted() const { return !fields_.empty(); }
5454

5555
/// \brief Returns true if the sort order is unsorted
5656
/// A SortOrder is unsorted if it has no sort fields.
57-
bool IsUnsorted() const { return fields_.empty(); }
57+
bool is_unsorted() const { return fields_.empty(); }
5858

5959
/// \brief Checks whether this order satisfies another order.
6060
bool Satisfies(const SortOrder& other) const;

src/iceberg/test/sort_order_test.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ TEST(SortOrderTest, Equality) {
8686

8787
TEST(SortOrderTest, IsUnsorted) {
8888
auto unsorted = SortOrder::Unsorted();
89-
EXPECT_TRUE(unsorted->IsUnsorted());
90-
EXPECT_FALSE(unsorted->IsSorted());
89+
EXPECT_TRUE(unsorted->is_unsorted());
90+
EXPECT_FALSE(unsorted->is_sorted());
9191
}
9292

9393
TEST(SortOrderTest, IsSorted) {
@@ -97,8 +97,8 @@ TEST(SortOrderTest, IsSorted) {
9797
NullOrder::kFirst);
9898
SortOrder sorted_order(100, {st_field1});
9999

100-
EXPECT_TRUE(sorted_order.IsSorted());
101-
EXPECT_FALSE(sorted_order.IsUnsorted());
100+
EXPECT_TRUE(sorted_order.is_sorted());
101+
EXPECT_FALSE(sorted_order.is_unsorted());
102102
}
103103

104104
TEST(SortOrderTest, Satisfies) {

src/iceberg/test/transform_test.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,20 @@ TEST(TransformSatisfiesOrderOfTest, SatisfiesOrderOf) {
767767
.other_transform_str = "bucket[16]",
768768
.expected = false},
769769

770+
// Truncate satisfies Truncate with smaller width
771+
{.transform_str = "truncate[32]",
772+
.other_transform_str = "truncate[16]",
773+
.expected = true},
774+
{.transform_str = "truncate[16]",
775+
.other_transform_str = "truncate[16]",
776+
.expected = true},
777+
{.transform_str = "truncate[16]",
778+
.other_transform_str = "truncate[32]",
779+
.expected = false},
780+
{.transform_str = "truncate[16]",
781+
.other_transform_str = "bucket[32]",
782+
.expected = false},
783+
770784
// Hour satisfies hour, day, month, and year
771785
{.transform_str = "hour", .other_transform_str = "hour", .expected = true},
772786
{.transform_str = "hour", .other_transform_str = "day", .expected = true},

src/iceberg/transform.cc

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <format>
2323
#include <regex>
24+
#include <utility>
2425

2526
#include "iceberg/transform_function.h"
2627
#include "iceberg/type.h"
@@ -130,16 +131,29 @@ bool Transform::PreservesOrder() const {
130131
case TransformType::kVoid:
131132
case TransformType::kBucket:
132133
return false;
133-
default:
134+
case TransformType::kIdentity:
135+
case TransformType::kTruncate:
136+
case TransformType::kYear:
137+
case TransformType::kMonth:
138+
case TransformType::kDay:
139+
case TransformType::kHour:
134140
return true;
135141
}
142+
std::unreachable();
136143
}
137144

138145
bool Transform::SatisfiesOrderOf(const Transform& other) const {
139146
auto other_type = other.transform_type();
140147
switch (transform_type_) {
141148
case TransformType::kIdentity:
149+
// ordering by value is the same as long as the other preserves order
142150
return other.PreservesOrder();
151+
case TransformType::kTruncate: {
152+
if (other_type != TransformType::kTruncate) {
153+
return false;
154+
}
155+
return std::get<int32_t>(param_) >= std::get<int32_t>(other.param_);
156+
}
143157
case TransformType::kHour:
144158
return other_type == TransformType::kHour || other_type == TransformType::kDay ||
145159
other_type == TransformType::kMonth || other_type == TransformType::kYear;
@@ -148,9 +162,13 @@ bool Transform::SatisfiesOrderOf(const Transform& other) const {
148162
other_type == TransformType::kYear;
149163
case TransformType::kMonth:
150164
return other_type == TransformType::kMonth || other_type == TransformType::kYear;
151-
default:
165+
case TransformType::kYear:
166+
case TransformType::kBucket:
167+
case TransformType::kUnknown:
168+
case TransformType::kVoid:
152169
return *this == other;
153170
}
171+
std::unreachable();
154172
}
155173

156174
bool TransformFunction::Equals(const TransformFunction& other) const {

0 commit comments

Comments
 (0)