leaves12138 commented on code in PR #8603: URL: https://github.com/apache/paimon/pull/8603#discussion_r3572167212
########## paimon-core/src/main/java/org/apache/paimon/table/source/PrimaryKeySortedIndexResult.java: ########## @@ -0,0 +1,143 @@ +/* + * 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. + */ + +package org.apache.paimon.table.source; + +import org.apache.paimon.globalindex.GlobalIndexResult; +import org.apache.paimon.globalindex.IndexedSplit; +import org.apache.paimon.utils.Range; +import org.apache.paimon.utils.RoaringNavigableMap64; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +/** Snapshot-scoped scalar-index result addressed by physical data-file row positions. */ +public class PrimaryKeySortedIndexResult implements GlobalIndexSplitResult { + + private static final Logger LOG = LoggerFactory.getLogger(PrimaryKeySortedIndexResult.class); + private static final int MAX_INDEXED_RANGES_PER_FILE = 4096; + + private final long snapshotId; + private final List<Split> splits; + + PrimaryKeySortedIndexResult(PrimaryKeySortedIndexScan.EvaluatedPlan plan) { + this.snapshotId = plan.snapshotId(); + List<Split> converted = new ArrayList<>(); + Set<DataSplit> preservedNonRawSplits = Collections.newSetFromMap(new IdentityHashMap<>()); + for (PrimaryKeySortedIndexScan.EvaluatedFile evaluatedFile : plan.files()) { + PrimaryKeySortedIndexScan.FilePlan file = evaluatedFile.file(); + DataSplit sourceSplit = file.sourceSplit(); + if (!sourceSplit.rawConvertible()) { + if (preservedNonRawSplits.add(sourceSplit)) { + converted.add(sourceSplit); + } + continue; + } + + Optional<GlobalIndexResult> result = evaluatedFile.result(); + if (!result.isPresent()) { + converted.add(toSingleFileSplit(file)); + continue; + } + + RoaringNavigableMap64 positions = result.get().results(); + if (positions.isEmpty()) { + continue; + } + List<Range> ranges = ranges(positions, file.dataFile().rowCount()); + if (ranges == null) { + LOG.warn( + "Primary-key sorted index returned an invalid row position for data file " + + "{}; falling back to a raw scan for this file.", + file.dataFile().fileName()); + converted.add(toSingleFileSplit(file)); + } else { + converted.add(new IndexedSplit(toSingleFileSplit(file), ranges, null)); Review Comment: `$audit_log` reads cannot consume this split. `AuditLogTable.newRead()` always calls `forceKeepDelete()`, while `PrimaryKeyIndexedSplitReadProvider.match` explicitly rejects every `IndexedSplit` when `forceKeepDelete` is true; no later provider accepts `IndexedSplit`, so the read reaches `KeyValueTableRead.reader` and throws `RuntimeException("Should not happen.")`. I reproduced this end to end on the latest head with two writes, a compaction, and an indexed `score = 10` filter: planning produced this `IndexedSplit`, then the audit-log reader failed at runtime. Please either prevent the automatic scan from emitting `IndexedSplit` for force-keep-delete consumers (including `$audit_log`) or make the indexed reader path support that mode, and add a regression test. -- 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]
