nsivabalan commented on a change in pull request #1402: URL: https://github.com/apache/incubator-hudi/pull/1402#discussion_r417046515
########## File path: hudi-client/src/main/java/org/apache/hudi/index/HoodieGlobalSimpleIndex.java ########## @@ -0,0 +1,157 @@ +/* + * 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.hudi.index; + +import org.apache.hudi.common.fs.FSUtils; +import org.apache.hudi.common.model.EmptyHoodieRecordPayload; +import org.apache.hudi.common.model.HoodieKey; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.model.HoodieRecordLocation; +import org.apache.hudi.common.model.HoodieRecordPayload; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.config.HoodieWriteConfig; +import org.apache.hudi.exception.HoodieIOException; +import org.apache.hudi.table.HoodieTable; + +import org.apache.spark.api.java.JavaPairRDD; +import org.apache.spark.api.java.JavaRDD; +import org.apache.spark.api.java.JavaSparkContext; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import scala.Tuple2; + +import static java.util.stream.Collectors.toList; +import static org.apache.hudi.index.HoodieIndexUtils.loadLatestDataFilesForAllPartitions; + +/** + * A global simple index which reads interested fields(record key and partition path) from base files and + * joins with incoming records to find the tagged location. + * + * @param <T> + */ +public class HoodieGlobalSimpleIndex<T extends HoodieRecordPayload> extends HoodieSimpleIndex<T> { + + public HoodieGlobalSimpleIndex(HoodieWriteConfig config) { + super(config); + } + + @Override + public JavaRDD<HoodieRecord<T>> tagLocation(JavaRDD<HoodieRecord<T>> recordRDD, JavaSparkContext jsc, + HoodieTable<T> hoodieTable) { + return tagLocationInternal(recordRDD, jsc, hoodieTable); + } + + /** + * Tags records location for incoming records. + * + * @param recordRDD {@link JavaRDD} of incoming records + * @param jsc instance of {@link JavaSparkContext} to use + * @param hoodieTable instance of {@link HoodieTable} to use + * @return {@link JavaRDD} of records with record locations set + */ + protected JavaRDD<HoodieRecord<T>> tagLocationInternal(JavaRDD<HoodieRecord<T>> recordRDD, JavaSparkContext jsc, + HoodieTable<T> hoodieTable) { + JavaPairRDD<HoodieKey, HoodieRecord> incomingRecords = recordRDD.mapToPair(entry -> new Tuple2<>(entry.getKey(), entry)); + + JavaPairRDD<HoodieKey, HoodieRecordLocation> existingRecords = fetchRecordLocations(incomingRecords.keys(), jsc, hoodieTable, Review comment: I didn't realize that we can't use the same fetchRecordLocations that we used for SimpleIndex since we calculate the list of distinct partitions which makes sense for non-global, but not for global. Have fixed it. Btw, wanted to remind a difference in global when compared to non-global(I am sure you are aware of this, but wanted to call it out). We need to do left outer join with recordKeys and not HoodieKeys(which is what we do in non global simple index), since partition path could differ in existing records when compared to incoming keys. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
