marin-ma commented on code in PR #11769:
URL: https://github.com/apache/gluten/pull/11769#discussion_r2958823994


##########
cpp/core/shuffle/BlockStatistics.cc:
##########
@@ -0,0 +1,316 @@
+/*
+ * 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 "shuffle/BlockStatistics.h"
+
+#include <arrow/buffer.h>
+#include <arrow/type.h>
+#include <arrow/util/bit_util.h>
+
+namespace gluten {
+namespace {
+
+// Returns true if the row at the given index is valid (non-null).
+inline bool isRowValid(const std::shared_ptr<arrow::Buffer>& validityBuffer, 
uint32_t row) {
+  if (!validityBuffer) {
+    return true; // No validity buffer means all rows are valid.
+  }
+  return arrow::bit_util::GetBit(validityBuffer->data(), row);
+}
+
+// Returns true if the column has any null rows.
+bool hasAnyNull(const std::shared_ptr<arrow::Buffer>& validityBuffer, uint32_t 
numRows) {
+  if (!validityBuffer || numRows == 0) {
+    return false;
+  }
+  // Check each bit — return early on first null found.
+  for (uint32_t i = 0; i < numRows; ++i) {
+    if (!arrow::bit_util::GetBit(validityBuffer->data(), i)) {

Review Comment:
   Perhaps check each bytes by comparing with 0xff can be faster



##########
cpp/core/jni/JniWrapper.cc:
##########
@@ -962,6 +962,14 @@ 
Java_org_apache_gluten_vectorized_LocalPartitionWriterJniWrapper_createPartition
       numSubDirs,
       enableDictionary);
 
+  // Reuse the dynamic filter config to also enable block statistics 
collection,
+  // since stats are only useful when dynamic filter pushdown is active.
+  const auto& confMap = ctx->getConfMap();
+  auto it = 
confMap.find("spark.gluten.sql.columnar.backend.velox.valueStream.dynamicFilter.enabled");

Review Comment:
   Other option values are passing through function args. Can you add a new arg 
`enableBlockStatistics`?



##########
cpp/core/shuffle/Payload.cc:
##########
@@ -413,12 +437,27 @@ arrow::Result<std::unique_ptr<InMemoryPayload>> 
InMemoryPayload::merge(
       }
     }
   }
-  return std::make_unique<InMemoryPayload>(mergedRows, isValidityBuffer, 
source->schema(), std::move(merged));
+  auto result = std::make_unique<InMemoryPayload>(mergedRows, 
isValidityBuffer, source->schema(), std::move(merged));
+  // Merge block statistics if both payloads have them.
+  if (source->hasBlockStats() && append->hasBlockStats()) {
+    auto mergedStats = *source->blockStats_;
+    mergedStats.merge(*append->blockStats_);
+    result->setBlockStats(std::move(mergedStats));
+  } else if (source->hasBlockStats()) {
+    result->setBlockStats(*source->blockStats_);

Review Comment:
   If only source or append has blockStats, should we either discard it or 
compute for the missing side and merge them?



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