leaves12138 commented on code in PR #8549: URL: https://github.com/apache/paimon/pull/8549#discussion_r3563957313
########## paimon-core/src/main/java/org/apache/paimon/index/pkvector/PkVectorAnnSegmentFile.java: ########## @@ -0,0 +1,293 @@ +/* + * 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.index.pkvector; + +import org.apache.paimon.fs.FileIO; +import org.apache.paimon.fs.Path; +import org.apache.paimon.fs.PositionOutputStream; +import org.apache.paimon.globalindex.GlobalIndexSingleColumnWriter; +import org.apache.paimon.globalindex.GlobalIndexWriter; +import org.apache.paimon.globalindex.GlobalIndexer; +import org.apache.paimon.globalindex.ResultEntry; +import org.apache.paimon.globalindex.VectorGlobalIndexer; +import org.apache.paimon.globalindex.io.GlobalIndexFileWriter; +import org.apache.paimon.index.GlobalIndexMeta; +import org.apache.paimon.index.IndexFile; +import org.apache.paimon.index.IndexFileMeta; +import org.apache.paimon.index.IndexPathFactory; +import org.apache.paimon.io.DataFileMeta; +import org.apache.paimon.options.Options; +import org.apache.paimon.types.DataField; +import org.apache.paimon.types.VectorType; +import org.apache.paimon.utils.IOUtils; + +import javax.annotation.Nullable; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.function.LongPredicate; + +import static org.apache.paimon.index.pkvector.PkVectorSegmentMeta.Role.ANN; +import static org.apache.paimon.utils.Preconditions.checkArgument; + +/** Builds immutable ANN payloads whose index ids are source data-file row positions. */ +public class PkVectorAnnSegmentFile extends IndexFile { + + public static final String PK_VECTOR_ANN = "pk-vector-ann"; + + public PkVectorAnnSegmentFile(FileIO fileIO, IndexPathFactory pathFactory) { + super(fileIO, pathFactory); + } + + public IndexFileMeta build( + List<Source> sources, + PkVectorSegmentMeta.OrdinalLayout ordinalLayout, + DataField vectorField, + Options indexOptions, + String indexDefinitionId, + String vectorTypeFingerprint, + String metric, + String algorithm, + byte[] optionsHash, + long buildSnapshotId) + throws IOException { + checkArgument(!sources.isEmpty(), "An ANN segment must reference source files."); Review Comment: Now that `ordinalLayout` is caller-supplied, this method needs to preserve the layout/source-count invariant previously enforced by `buildSingleSource` / `buildMultiSource`. Passing multiple sources with `ROW_POSITION` currently completes the ANN build and persists the metadata, but `PkVectorAnnSegmentSearcher` later rejects that segment because row-position layout must reference exactly one source file. Please validate the source cardinality against the layout here (and add an invalid-combination test) so the builder cannot create an unreadable segment. -- 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]
