danny0405 commented on code in PR #18103:
URL: https://github.com/apache/hudi/pull/18103#discussion_r2791395993
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/source/rebalance/selector/StreamReadBucketIndexKeySelector.java:
##########
@@ -18,14 +18,50 @@
package org.apache.hudi.source.rebalance.selector;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.storage.StoragePath;
import org.apache.hudi.table.format.mor.MergeOnReadInputSplit;
import org.apache.flink.api.java.functions.KeySelector;
-public class StreamReadBucketIndexKeySelector implements
KeySelector<MergeOnReadInputSplit, String> {
+import java.util.List;
+
+public class StreamReadBucketIndexKeySelector implements
KeySelector<MergeOnReadInputSplit, Pair<String, String>> {
+
+ private final StoragePath basePath;
+
+ public StreamReadBucketIndexKeySelector(String basePath) {
+ this.basePath = new StoragePath(basePath);
+ }
@Override
- public String getKey(MergeOnReadInputSplit mergeOnReadInputSplit) throws
Exception {
- return mergeOnReadInputSplit.getFileId();
+ public Pair<String, String> getKey(MergeOnReadInputSplit
mergeOnReadInputSplit) throws Exception {
+ Option<String> validFilePath =
getValidFilePathFromInputSplit(mergeOnReadInputSplit);
+ String relPartitionPath = "";
+ if (validFilePath.isPresent()) {
+ StoragePath fullPartitonPath = new
StoragePath(validFilePath.get()).getParent();
+ relPartitionPath = FSUtils.getRelativePartitionPath(basePath,
fullPartitonPath);
+ }
+
+ return Pair.of(relPartitionPath, mergeOnReadInputSplit.getFileId());
+ }
+
+ /**
+ * Get a valid file path from MergeOnReadInputSplit
+ *
+ */
+ private Option<String> getValidFilePathFromInputSplit(MergeOnReadInputSplit
mergeOnReadInputSplit) {
Review Comment:
we can add a method `MergeOnReadInputSplit#parsePartitonPath` and move this
util method there.
--
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]