vinothchandar commented on a change in pull request #1402:
URL: https://github.com/apache/incubator-hudi/pull/1402#discussion_r416354734
##########
File path: hudi-client/src/main/java/org/apache/hudi/index/HoodieIndex.java
##########
@@ -128,9 +133,26 @@ protected HoodieIndex(HoodieWriteConfig config) {
/**
* Each index type should implement it's own logic to release any resources
acquired during the process.
*/
- public void close() {}
+ public void close() {
+ }
+
+ protected HoodieRecord<T> getTaggedRecord(HoodieRecord<T> inputRecord,
Option<HoodieRecordLocation> location) {
Review comment:
this can very well go into `HoodieIndexUtils` ? There is no instance
stats accessed in this method IIUC
##########
File path:
hudi-client/src/main/java/org/apache/hudi/config/HoodieIndexConfig.java
##########
@@ -92,6 +100,9 @@
public static final String BLOOM_INDEX_UPDATE_PARTITION_PATH =
"hoodie.bloom.index.update.partition.path";
public static final String DEFAULT_BLOOM_INDEX_UPDATE_PARTITION_PATH =
"false";
+ public static final String GLOBAL_SIMPLE_INDEX_UPDATE_PARTITION_PATH =
"hoodie.global.simple.index.update.partition.path";
Review comment:
just `hoodie.simple.index.update.partition.path` to be consistent with
the other config?
##########
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:
@nsivabalan This is problematic.. since we don't cache (rightfully so)
the input here for Global index,
```
JavaPairRDD<String, String> partitionRecordKeyPairRDD =
hoodieKeys.mapToPair(entry -> new Tuple2(entry.getPartitionPath(),
entry.getRecordKey()));
List<String> affectedPartitionPathList =
partitionRecordKeyPairRDD.map(tuple -> tuple._1).distinct().collect();
```
will collect() once reading the input, and then later ` return
getTaggedRecords(incomingRecordsKeyedOnRecordKeys,
existingRecordsKeyedOnRecordKeys);` will also read the input again for
joining..
Also why `fetchRecordLocations()` we should be loading all the partitions,
not just the ones based on incomingRecord, right?
Global should be much simpler.. All it needs is to create `existingRecords`
based on listing from all partitions and then do the getTaggedRecords() join..
----------------------------------------------------------------
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]