wangyong9999 commented on code in PR #253:
URL: https://github.com/apache/paimon-cpp/pull/253#discussion_r3881301625


##########
src/paimon/core/index/pksorted/pk_sorted_bucket_index_state.cpp:
##########
@@ -71,39 +91,86 @@ PkSortedBucketIndexState 
PkSortedBucketIndexState::FromActiveDataFiles(
             continue;
         }
         PrimaryKeyIndexSourceMeta source_meta = 
std::move(source_meta_result).value();
-        auto desired = sources_by_level.find(source_meta.DataLevel());
-        if (desired == sources_by_level.end() || desired->second != 
source_meta.SourceFiles()) {
+        const std::vector<PrimaryKeyIndexSourceFile>& payload_sources = 
source_meta.SourceFiles();
+        bool valid_candidate = !payload_sources.empty();
+        std::vector<PrimaryKeyIndexSourceFile> active_intersection;
+        for (size_t i = 0; valid_candidate && i < payload_sources.size(); i++) 
{
+            const PrimaryKeyIndexSourceFile& source = payload_sources[i];
+            if (i > 0 && payload_sources[i - 1].file_name >= source.file_name) 
{
+                valid_candidate = false;
+                break;
+            }
+            auto active_source = active_sources.find(source.file_name);
+            if (active_source == active_sources.end()) {
+                continue;
+            }
+            if (active_source->second != source.row_count ||
+                ambiguous_active_source_names.count(source.file_name) > 0) {
+                valid_candidate = false;
+                break;
+            }
+            active_intersection.push_back(source);
+        }
+        if (!valid_candidate || active_intersection.empty()) {
+            rejected.push_back(payload);
+            continue;
+        }
+        std::shared_ptr<PkSortedIndexGroup> group =
+            PkSortedIndexGroup::Create(field_id, index_type, payload_sources, 
payload, source_meta);
+        if (group == nullptr) {
             rejected.push_back(payload);
             continue;
         }
-        payloads_by_level[source_meta.DataLevel()].push_back(payload);
-        
payload_metas_by_level[source_meta.DataLevel()].push_back(std::move(source_meta));
+        candidates.push_back(
+            {payload, std::move(group), std::move(active_intersection), 
/*conflicted=*/false});
+    }
+
+    std::map<std::pair<std::string, int64_t>, std::vector<size_t>> 
candidates_by_source;

Review Comment:
   The Java maintainer still keeps exactly one sorted-index group per level and 
rejects multiple units, so no current writer can produce this state. This 
conflict graph adds a C++-only lifecycle model beyond the partial-retirement 
fix. Could we keep the one-group-per-level invariant here and limit this PR to 
reusing that group’s active intersection?



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

Reply via email to