yihua commented on code in PR #12379:
URL: https://github.com/apache/hudi/pull/12379#discussion_r1864070083
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/compact/HoodieCompactor.java:
##########
@@ -130,9 +159,27 @@ public HoodieData<WriteStatus> compact(
TaskContextSupplier taskContextSupplier = table.getTaskContextSupplier();
// if this is a MDT, set up the instant range of log reader just like
regular MDT snapshot reader.
Option<InstantRange> instantRange =
CompactHelpers.getInstance().getInstantRange(metaClient);
- return context.parallelize(operations).map(operation -> compact(
- compactionHandler, metaClient, config, operation,
compactionInstantTime, maxInstantTime, instantRange, taskContextSupplier,
executionHelper))
- .flatMap(List::iterator);
+
+ // do one upfront processing to detect if we need partial update.
+ // if yes, call prepareBroadcast.
+ HoodiePairData<CompactionOperation, Boolean> operationPartialUpdatePair =
context.parallelize(operations)
+ .mapToPair(operation -> Pair.of(operation,
containsPartialUpdate(compactionHandler, metaClient, config, operation,
compactionInstantTime, maxInstantTime,
+ instantRange, taskContextSupplier, executionHelper)));
+ // should we persist operationPartialUpdatePair?
+
+ boolean containsPartialUpdate =
operationPartialUpdatePair.values().collectAsList().stream().anyMatch(partialUpdate
-> partialUpdate);
+ Option<PartialUpdateReaderContext> partialUpdateReaderContextOpt =
Option.empty();
+ if (containsPartialUpdate) {
+ partialUpdateReaderContextOpt = getPartialUpdateReaderContext(context);
+ // Broadcast ParquetFileReader for file group reader if needed.
+ ValidationUtils.checkArgument(partialUpdateReaderContextOpt.isPresent(),
"Partial update cannot be supported without PartialUpdateReaderContext");
+ partialUpdateReaderContextOpt.get().prepareReaderContext();
+ }
+
+ Option<PartialUpdateReaderContext> finalPartialUpdateReaderContextOpt =
partialUpdateReaderContextOpt;
+ return
operationPartialUpdatePair.map((SerializableFunction<Pair<CompactionOperation,
Boolean>, List<WriteStatus>>) v1 -> compact(
Review Comment:
This will trigger the log reading again in `.mapToPair(operation ->
Pair.of(operation, containsPartialUpdate(compactionHandler, metaClient, config,
operation, compactionInstantTime, maxInstantTime,
instantRange, taskContextSupplier, executionHelper)))`. It's
better to collect `operationPartialUpdatePair` to driver and parallelize it
again to avoid repeated log reading.
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/PartialUpdateReaderContext.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.table;
+
+import org.apache.hudi.common.engine.HoodieReaderContext;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.storage.StoragePath;
+
+import org.apache.hadoop.conf.Configuration;
+
+import java.io.Serializable;
+
+public class PartialUpdateReaderContext implements Serializable {
+
+ // Prepare broadcast variables.
+ public void prepareReaderContext() {
+ // NO operation.
+ }
+
+ // Create reader context based on broadcast variables.
+ public Option<HoodieReaderContext> getReaderContext(StoragePath basePath) {
+ return Option.empty();
+ }
+
+ // Fetch broadcast storage config.
+ public Option<Configuration> getStorageConfig() {
+ return Option.empty();
+ }
Review Comment:
If we could not easily make such changes, I think it's OK to leave it this
way now for supporting compaction with partial updates.
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/PartialUpdateReaderContext.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.table;
+
+import org.apache.hudi.common.engine.HoodieReaderContext;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.storage.StoragePath;
+
+import org.apache.hadoop.conf.Configuration;
+
+import java.io.Serializable;
+
+public class PartialUpdateReaderContext implements Serializable {
+
+ // Prepare broadcast variables.
+ public void prepareReaderContext() {
+ // NO operation.
+ }
+
+ // Create reader context based on broadcast variables.
+ public Option<HoodieReaderContext> getReaderContext(StoragePath basePath) {
+ return Option.empty();
+ }
+
+ // Fetch broadcast storage config.
+ public Option<Configuration> getStorageConfig() {
+ return Option.empty();
+ }
Review Comment:
I think it's better to put these new APIs to the `EngineContext` class.
--
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]