zhztheplayer commented on code in PR #12040:
URL: https://github.com/apache/gluten/pull/12040#discussion_r3235066382


##########
cpp/velox/compute/delta/DeltaSplit.h:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.
+ */
+/*
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * Licensed 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.
+ */
+
+#pragma once
+
+#include <algorithm>
+#include <limits>
+#include <optional>
+#include <vector>
+
+#include "compute/Runtime.h"
+#include "velox/connectors/hive/HiveConnectorSplit.h"
+
+namespace gluten::delta {
+
+using namespace facebook::velox;
+using namespace facebook::velox::connector;
+using namespace facebook::velox::connector::hive;
+
+enum class DeltaRowIndexFilterType {
+  kKeepAll,
+  kIfContained,
+  kIfNotContained,
+};
+
+/// Protocol version information for a Delta table.
+/// Used to validate that the table supports deletion vectors.
+/// Per Delta spec: DVs require Reader v3+ and Writer v7+ with
+/// 'deletionVectors' feature flag.
+struct DeltaProtocolInfo {
+  int32_t minReaderVersion;
+  int32_t minWriterVersion;
+  std::optional<std::vector<std::string>> readerFeatures;
+  std::optional<std::vector<std::string>> writerFeatures;
+
+  /// Check if this protocol supports deletion vectors.
+  /// Returns true if:
+  /// - minReaderVersion >= 3
+  /// - minWriterVersion >= 7
+  /// - 'deletionVectors' is in readerFeatures
+  bool supportsDeletionVectors() const {
+    if (minReaderVersion < 3 || minWriterVersion < 7) {
+      return false;
+    }
+    if (!readerFeatures.has_value()) {
+      return false;
+    }
+    return std::find(readerFeatures->begin(), readerFeatures->end(), 
"deletionVectors") != readerFeatures->end();
+  }
+};

Review Comment:
   In which case do we need this struct and the validation logics? Won't we 
only use native DV features when the Java side feature exists?



##########
cpp/velox/compute/delta/tests/DeltaConnectorTest.cpp:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+/*
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * Licensed 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 <gtest/gtest.h>
+
+#include "compute/delta/DeltaConnector.h"
+#include "velox/connectors/Connector.h"
+#include "velox/connectors/hive/HiveConfig.h"
+
+namespace gluten::delta {
+
+namespace {
+
+class DeltaConnectorTest : public ::testing::Test {

Review Comment:
   Can we also add some test cases that are more E2E? E.g., read a file with a 
passed-in DV, then verify whether the unwanted rows are filtered out?



##########
cpp/velox/compute/delta/DeltaDeletionVectorReader.h:
##########
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ */
+/*
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * Licensed 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.
+ */
+
+#pragma once
+
+#include "velox/common/base/BitUtil.h"
+#include "velox/vector/ComplexVector.h"
+
+#include <memory>
+#include <optional>
+#include <roaring/roaring64map.hh>
+#include <string>
+#include <string_view>
+
+namespace gluten::delta {
+
+using namespace facebook::velox;
+
+/// Reads and manages Delta Lake deletion vectors for filtering deleted rows
+/// during table scans.
+///
+/// The JVM Delta side materializes the deletion vector and hands the 
serialized
+/// bitmap payload to native. This reader only deserializes that payload and
+/// applies row filtering during scan.
+///
+/// Usage example:
+/// @code
+///   auto reader = std::make_unique<DeltaDeletionVectorReader>();
+///   reader->loadSerializedDeletionVector(serializedPayload, 
expectedCardinality);
+///   if (reader->isRowDeleted(42)) {
+///     // Skip this row during scan
+///   }
+/// @endcode
+class DeltaDeletionVectorReader {
+ public:
+  DeltaDeletionVectorReader() = default;
+
+  /// Loads a deletion vector from an already decoded serialized Delta payload.
+  void loadSerializedDeletionVector(
+      std::string_view serializedPayload,
+      std::optional<uint64_t> expectedCardinality = std::nullopt);

Review Comment:
   Can we add comments explaining `expectedCardinality`?



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