jerry-024 commented on code in PR #7933: URL: https://github.com/apache/paimon/pull/7933#discussion_r3302956900
########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/globalindex/ESIndexTopoBuilder.java: ########## @@ -0,0 +1,667 @@ +/* + * 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.flink.globalindex; + +import org.apache.paimon.CoreOptions; +import org.apache.paimon.data.BinaryRow; +import org.apache.paimon.data.InternalRow; +import org.apache.paimon.flink.sink.Committable; +import org.apache.paimon.flink.sink.CommittableTypeInfo; +import org.apache.paimon.flink.sink.CommitterOperatorFactory; +import org.apache.paimon.flink.sink.NoopCommittableStateManager; +import org.apache.paimon.flink.sink.StoreCommitter; +import org.apache.paimon.flink.utils.BoundedOneInputOperator; +import org.apache.paimon.flink.utils.JavaTypeInfo; +import org.apache.paimon.flink.utils.StreamExecutionEnvironmentUtils; +import org.apache.paimon.globalindex.GlobalIndexMultiColumnWriter; +import org.apache.paimon.globalindex.GlobalIndexSingletonWriter; +import org.apache.paimon.globalindex.GlobalIndexWriter; +import org.apache.paimon.globalindex.ResultEntry; +import org.apache.paimon.index.IndexFileMeta; +import org.apache.paimon.io.DataFileMeta; +import org.apache.paimon.manifest.ManifestEntry; +import org.apache.paimon.options.Options; +import org.apache.paimon.partition.PartitionPredicate; +import org.apache.paimon.reader.RecordReader; +import org.apache.paimon.schema.SchemaManager; +import org.apache.paimon.table.FileStoreTable; +import org.apache.paimon.table.SpecialFields; +import org.apache.paimon.table.sink.BatchWriteBuilder; +import org.apache.paimon.table.sink.CommitMessage; +import org.apache.paimon.table.sink.CommitMessageImpl; +import org.apache.paimon.table.source.DataSplit; +import org.apache.paimon.table.source.ReadBuilder; +import org.apache.paimon.table.source.TableRead; +import org.apache.paimon.types.DataField; +import org.apache.paimon.types.RowType; +import org.apache.paimon.utils.CloseableIterator; +import org.apache.paimon.utils.ProjectedRow; +import org.apache.paimon.utils.Range; + +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.operators.OneInputStreamOperatorFactory; +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Closeable; +import java.io.IOException; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; + +import static org.apache.paimon.globalindex.GlobalIndexBuilderUtils.createIndexWriter; +import static org.apache.paimon.globalindex.GlobalIndexBuilderUtils.toIndexFileMetas; +import static org.apache.paimon.io.CompactIncrement.emptyIncrement; +import static org.apache.paimon.io.DataIncrement.indexIncrement; +import static org.apache.paimon.utils.Preconditions.checkArgument; + +/** + * Builds a Flink topology for creating ES-based global indexes with parallelism. Follows the same + * shard-based approach as {@link GenericIndexTopoBuilder} but specialized for ES vector indexes + * with multi-column support. + */ +public class ESIndexTopoBuilder { + Review Comment: This entire file is an ES-specific topology builder, unrelated to the multi-column GlobalIndex SPI framework. Consider moving it to a separate PR to keep this one focused on the framework changes. Also, `findMinNonIndexableRowId`, `filterEntriesBefore`, `computeShardTasks`, and `closeWriterQuietly` are copy-pasted from `GenericIndexTopoBuilder` — consider extracting them into a shared utility (e.g. `GlobalIndexBuilderUtils`). ########## paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/globalindex/ESGlobalIndexTopoBuilder.java: ########## @@ -0,0 +1,341 @@ +/* + * 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.spark.globalindex; + +import org.apache.paimon.data.BinaryRow; +import org.apache.paimon.data.InternalRow; +import org.apache.paimon.globalindex.IndexedSplit; +import org.apache.paimon.io.DataFileMeta; +import org.apache.paimon.manifest.ManifestEntry; +import org.apache.paimon.options.Options; +import org.apache.paimon.partition.PartitionPredicate; +import org.apache.paimon.reader.RecordReader; +import org.apache.paimon.schema.SchemaManager; +import org.apache.paimon.table.FileStoreTable; +import org.apache.paimon.table.sink.CommitMessage; +import org.apache.paimon.table.sink.CommitMessageSerializer; +import org.apache.paimon.table.source.DataSplit; +import org.apache.paimon.table.source.ReadBuilder; +import org.apache.paimon.types.DataField; +import org.apache.paimon.types.RowType; +import org.apache.paimon.utils.CloseableIterator; +import org.apache.paimon.utils.FileStorePathFactory; +import org.apache.paimon.utils.InstantiationUtil; +import org.apache.paimon.utils.Pair; +import org.apache.paimon.utils.Range; + +import org.apache.spark.api.java.JavaSparkContext; +import org.apache.spark.sql.SparkSession; +import org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.apache.paimon.CoreOptions.GLOBAL_INDEX_ROW_COUNT_PER_SHARD; +import static org.apache.paimon.utils.Preconditions.checkArgument; + +/** + * ES-specific topology builder for Spark. Builds es-vector-diskbbq global indexes using Spark's + * parallelism. Supports both single-column and multi-column indexing. + */ +public class ESGlobalIndexTopoBuilder implements GlobalIndexTopologyBuilder { + Review Comment: Same as `ESIndexTopoBuilder` on the Flink side — this ES-specific Spark topology builder is not part of the multi-column framework and should go in a separate PR. `findMinNonIndexableRowId` and `filterEntriesBefore` are again duplicated here (third copy). Please extract into a shared utility. ########## paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/globalindex/GlobalIndexTopologyBuilderUtils.java: ########## @@ -54,7 +54,17 @@ public class GlobalIndexTopologyBuilderUtils { } public static GlobalIndexTopologyBuilder createTopoBuilder(String indexType) { + // Exact match first GlobalIndexTopologyBuilder builder = FACTORIES.get(indexType); - return builder == null ? new DefaultGlobalIndexTopoBuilder() : builder; + if (builder != null) { + return builder; + } + // Prefix match: e.g. "es-multi-index-diskbbq" matches registered "es-multi-index" Review Comment: The prefix matching logic here is ES-specific — the comment even says `"es-multi-index-diskbbq" matches registered "es-multi-index"`. Consider moving this to the ES-specific PR. ########## paimon-spark/paimon-spark-common/src/main/resources/META-INF/services/org.apache.paimon.spark.globalindex.GlobalIndexTopologyBuilder: ########## @@ -14,3 +14,4 @@ # limitations under the License. org.apache.paimon.spark.globalindex.btree.BTreeIndexTopoBuilder +org.apache.paimon.spark.globalindex.ESGlobalIndexTopoBuilder Review Comment: Registration of `ESGlobalIndexTopoBuilder` should go with the ES-specific PR. ########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/procedure/CreateGlobalIndexProcedure.java: ########## @@ -97,26 +107,34 @@ public String[] call( BTreeIndexTopoBuilder.buildIndexAndExecute( procedureContext.getExecutionEnvironment(), table, - indexColumn, + indexColumns.get(0), partitionPredicate, userOptions); return new String[] { "BTree global index created successfully for table: " + table.name() }; + } else if (indexType.startsWith(ESIndexTopoBuilder.ES_INDEX_TYPE_PREFIX)) { Review Comment: This ES routing branch (`ESIndexTopoBuilder.ES_INDEX_TYPE_PREFIX`) is ES-specific and not related to multi-column support. Consider moving it to the ES-specific PR. -- 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]
