shangxinli commented on code in PR #284:
URL: https://github.com/apache/iceberg-cpp/pull/284#discussion_r2484218223


##########
src/iceberg/sort_order.cc:
##########
@@ -38,10 +39,48 @@ int32_t SortOrder::order_id() const { return order_id_; }
 
 std::span<const SortField> SortOrder::fields() const { return fields_; }
 
+bool SortOrder::Satisfies(const SortOrder& other) const {
+  // any ordering satisfies an unsorted ordering
+  if (other.IsUnsorted()) {
+    return true;
+  }
+
+  // this ordering cannot satisfy an ordering with more sort fields
+  if (fields_.size() < other.fields().size()) {
+    return false;
+  }
+
+  // this ordering has either more or the same number of sort fields
+  for (const auto& [field, other_field] : std::views::zip(fields_, 
other.fields_)) {
+    if (!field.Satisfies(other_field)) {
+      return false;
+    }
+  }
+
+  return true;
+}
+
+bool SortOrder::SameOrder(const SortOrder& other) const {
+  if (fields_.size() != other.fields().size()) {
+    return false;
+  }
+
+  for (const auto& [field, other_field] : std::views::zip(fields_, 
other.fields())) {

Review Comment:
   same comments as above.



##########
src/iceberg/sort_order.cc:
##########
@@ -38,10 +39,48 @@ int32_t SortOrder::order_id() const { return order_id_; }
 
 std::span<const SortField> SortOrder::fields() const { return fields_; }
 
+bool SortOrder::Satisfies(const SortOrder& other) const {
+  // any ordering satisfies an unsorted ordering
+  if (other.IsUnsorted()) {
+    return true;
+  }
+
+  // this ordering cannot satisfy an ordering with more sort fields
+  if (fields_.size() < other.fields().size()) {
+    return false;
+  }
+
+  // this ordering has either more or the same number of sort fields
+  for (const auto& [field, other_field] : std::views::zip(fields_, 
other.fields_)) {

Review Comment:
   It seems using std::views::zip from C++23 without checking C++ standard 
compliance. I remember std::views::zip is C++23 only (not available in C++20 or 
earlier). Not sure if the codebase doesn't appear to enforce C++23. This will 
cause compilation failures on older compilers. 
   
   // Option 1: Traditional iteration (works in C++17+)
     for (size_t i = 0; i < other.fields().size(); ++i) {
       if (!fields_[i].Satisfies(other.fields()[i])) {
         return false;
       }
     }
   
     // Option 2: Use std::ranges::zip only if C++23 is available
     #if __cplusplus >= 202302L
       for (const auto& [field, other_field] : std::views::zip(fields_, 
other.fields())) {
     #else
       for (size_t i = 0; i < other.fields().size(); ++i) {
         const auto& field = fields_[i];
         const auto& other_field = other.fields()[i];
     #endif
         if (!field.Satisfies(other_field)) {
           return false;
         }
       }
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to