zhjwpku commented on code in PR #1114:
URL: https://github.com/apache/iceberg-cpp/pull/1114#discussion_r4727800554


##########
src/iceberg/parquet/parquet_bloom_row_group_filter.cc:
##########
@@ -0,0 +1,345 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <algorithm>
+#include <cmath>
+#include <limits>
+#include <utility>
+#include <vector>
+
+#include <parquet/bloom_filter.h>
+
+#include "iceberg/expression/expression_visitor.h"
+#include "iceberg/expression/rewrite_not.h"
+#include "iceberg/metadata_columns.h"
+#include "iceberg/parquet/parquet_bloom_row_group_filter_internal.h"
+#include "iceberg/parquet/parquet_schema_util_internal.h"
+#include "iceberg/util/macros.h"
+
+namespace iceberg::parquet {
+namespace {
+
+// True means a matching row may exist; false means the group can be skipped.
+constexpr bool kRowsMightMatch = true;
+constexpr bool kRowsCannotMatch = false;
+
+bool FindBytes(const ::parquet::BloomFilter& bloom, std::span<const uint8_t> 
bytes) {
+  ::parquet::ByteArray value{static_cast<uint32_t>(bytes.size()), 
bytes.data()};
+  return bloom.FindHash(bloom.Hash(value));
+}
+
+// Hash the file's physical representation, not Iceberg's single-value 
encoding.
+// Java's BloomEvalVisitor.shouldRead uses the same physical-type dispatch.
+bool MightContain(const ::parquet::ColumnDescriptor& column, const Literal& 
value,
+                  const ::parquet::BloomFilter& bloom) {
+  if (value.IsNull() || value.IsAboveMax() || value.IsBelowMin() || 
value.IsNaN()) {
+    // Bloom hashes floating-point bits, whereas equality treats all NaN 
payloads
+    // alike. Neither a NaN predicate nor a NaN literal can safely exclude 
rows.
+    return kRowsMightMatch;
+  }
+  auto type = value.type()->type_id();
+  switch (column.physical_type()) {
+    case ::parquet::Type::INT32: {
+      int128_t number;
+      switch (type) {
+        case TypeId::kInt:
+        case TypeId::kDate:
+          number = std::get<int32_t>(value.value());
+          break;
+        case TypeId::kLong:
+          number = std::get<int64_t>(value.value());
+          break;
+        case TypeId::kDecimal:
+          number = std::get<Decimal>(value.value()).value();

Review Comment:
   Fixed, if they differ, we keep the row group.



-- 
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