You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "shangxinli (via GitHub)" <gi...@apache.org> on 2025/11/02 03:59:31 UTC

Re: [PR] feat: implement all functions of bound predicates [iceberg-cpp]

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


##########
src/iceberg/expression/predicate.cc:
##########
@@ -287,10 +307,10 @@ BoundPredicate::BoundPredicate(Expression::Operation op, std::shared_ptr<BoundTe
 
 BoundPredicate::~BoundPredicate() = default;
 
-Result<Literal::Value> BoundPredicate::Evaluate(const StructLike& data) const {
+Result<Literal> BoundPredicate::Evaluate(const StructLike& data) const {

Review Comment:
   Not sure if we have a tool to capture the API signature changes in release notes. 



##########
src/iceberg/expression/predicate.cc:
##########
@@ -331,12 +376,91 @@ BoundLiteralPredicate::BoundLiteralPredicate(Expression::Operation op,
 
 BoundLiteralPredicate::~BoundLiteralPredicate() = default;
 
-Result<bool> BoundLiteralPredicate::Test(const Literal::Value& value) const {
-  return NotImplemented("BoundLiteralPredicate::Test not implemented");
+Result<bool> BoundLiteralPredicate::Test(const Literal& value) const {

Review Comment:
   Can we add null checking? 
       if (value.IsNull() || literal_.IsNull()) {
         return false;
       }



##########
src/iceberg/expression/literal.cc:
##########
@@ -554,4 +554,51 @@ Result<Literal> LiteralCaster::CastTo(const Literal& literal,
                       target_type->ToString());
 }
 
+// LiteralValueHash implementation
+std::size_t LiteralValueHash::operator()(const Literal::Value& value) const noexcept {
+  return std::visit(
+      [](const auto& v) -> std::size_t {
+        using T = std::decay_t<decltype(v)>;
+
+        constexpr size_t kHashPrime = 0x9e3779b9;
+
+        if constexpr (std::is_same_v<T, std::monostate>) {
+          return 0;
+        } else if constexpr (std::is_same_v<T, Literal::BelowMin>) {
+          return std::numeric_limits<std::size_t>::min();
+        } else if constexpr (std::is_same_v<T, Literal::AboveMax>) {
+          return std::numeric_limits<std::size_t>::max();
+        } else if constexpr (std::is_same_v<T, bool> || std::is_same_v<T, int32_t> ||
+                             std::is_same_v<T, int64_t> || std::is_same_v<T, float> ||
+                             std::is_same_v<T, double> ||
+                             std::is_same_v<T, std::string>) {
+          return std::hash<T>{}(v);
+        } else if constexpr (std::is_same_v<T, std::vector<uint8_t>>) {
+          std::size_t hash = 0;
+          for (size_t i = 0; i < v.size(); ++i) {
+            hash ^= std::hash<uint8_t>{}(v[i]) + kHashPrime + (hash << 6) + (hash >> 2);

Review Comment:
   Hashing identical bytes at different positions can produce same hash (e.g., [1,2] and [2,1] might collide).
   Can we add position i into the hash value to decrease the possibility of collide? 



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org