You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by vi...@apache.org on 2026/07/14 01:07:59 UTC
(hudi) branch master updated: refactor(common): consolidate *Utils classes (dead code, fold-ins, renames, dedup) (#19212)
This is an automated email from the ASF dual-hosted git repository.
vinothchandar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new 2bed01a98acd refactor(common): consolidate *Utils classes (dead code, fold-ins, renames, dedup) (#19212)
2bed01a98acd is described below
commit 2bed01a98acd11371a0cc2cf16ca32d0d08a1350
Author: vinoth chandar <vi...@users.noreply.github.com>
AuthorDate: Mon Jul 13 18:07:53 2026 -0700
refactor(common): consolidate *Utils classes (dead code, fold-ins, renames, dedup) (#19212)
* refactor(common): remove dead code and duplicate helpers from *Utils classes
Behavior-preserving cleanup from the *Utils consolidation sweep across
hudi-io, hudi-common, and hudi-hadoop-common:
- Delete ActiveTimelineUtils (empty class) and fix stale comment reference
- Delete HadoopFSUtils#getFileSize(FileSystem,Path) and
#getFileIdFromFilePath(Path) (no callers)
- Delete HadoopConfigUtils#getBooleanWithAltKeys (test-only) and its test
- Delete TableServiceUtils#isStale(long,long) overload (test-only) and its test
- Dedupe IOUtils#copy(InputStream,OutputStream) / #readAsByteArray against
the byte-identical FileIOUtils twins in the same package (keep FileIOUtils)
- HoodieSchemaUtils#convertBytesToBigDecimal(byte[],int,int) now delegates to
the byte-identical HoodieAvroUtils implementation
- Collapse StringUtils private stringIsNullOrEmpty into public isNullOrEmpty
Verified no reflection-based use: repo-wide scan for deleted names as string
literals is clean. CommitUtils#buildMetadataFromInstant and
HadoopFSUtils#getAllDataFilesInPartition were candidates but are kept: each
has a single Scala caller (TimelineRelation, ShowInvalidParquetProcedure);
migrating those callers belongs to the follow-up consolidation PRs.
* refactor(common): fold six tiny single-use *Utils classes into natural homes
Behavior-preserving continuation of the *Utils consolidation sweep; each
fold deletes a class with 1-3 caller edits:
- ArrayUtils (one method) -> CollectionUtils#toPrimitive
- HadoopInLineFSUtils -> callers use InLineFSUtils directly; buildInlineConf
inlined into HadoopStorageConfiguration#getInline; the Hadoop-Path adapter
becomes a private helper in InLineFileSystem, its only user
- HoodieColumnStatsIndexUtils (two thin delegates) -> HoodieMetadataWriteUtils
- InputSplitUtils -> writeString/readString become static interface methods
on RealtimeSplit (its only caller); trivial boolean wrappers replaced with
direct DataOutput/DataInput calls. Kept Java-8 compatible since
hudi-hadoop-mr pins compiler release 8.
- HoodieIncrSourceCheckpointValUtils -> folded into package sibling
checkpoint.CheckpointUtils; tests merged into TestCheckpointUtils
- ThreadUtils -> collectActiveThreads inlined into PulsarSource, its only
caller
Verified no reflection-based use (repo-wide string-literal scan) and no
remaining references across all file types including Scala.
* refactor(common): rename colliding *Utils class names
Five pairs of same-name/different-purpose utility classes made call sites
ambiguous. Pure renames, no logic changes:
- common.util.CheckpointUtils -> KafkaCheckpointUtils (parses Kafka-offset
checkpoint strings; distinct from table.checkpoint.CheckpointUtils which
translates Streamer checkpoint V1/V2 and keeps the name). Its test becomes
TestKafkaCheckpointUtils, resolving a TestCheckpointUtils collision too.
- org.apache.hudi.io.hfile.HFileUtils (hudi-io) -> HFileByteUtils (low-level
byte/key primitives; the FileFormatUtils subclass in hudi-common keeps
HFileUtils, symmetric with ParquetUtils/OrcUtils/LanceUtils)
- org.apache.hudi.io.IOUtils (hudi-client-common) -> MergeUtils
(merge/compaction memory sizing + runMerge; distinct from hudi-io's
byte-primitives IOUtils). TestSparkIOUtils -> TestSparkMergeUtils.
- client.heartbeat.HeartbeatUtils -> WriterHeartbeatUtils (writer-side
delete/abort; distinct from hudi-common's read/expiry HoodieHeartbeatUtils)
- index.secondary.SecondaryIndexUtils -> SecondaryIndexDefinitionUtils
(JSON serde of index definitions, unrelated to the SI key codec)
* refactor(config): collapse HadoopConfigUtils alt-key reader onto ConfigUtils
HadoopConfigUtils re-implemented the key-then-alternatives walk (with its own
copy of the deprecation warning) against Hadoop Configuration. Extract the
walk as ConfigUtils.getRawValueWithAltKeys(Function<String,Object>, ...) --
mirroring the Properties overload's no-default-fallback semantics -- and make
the Hadoop variant a one-line adapter over conf::get. HadoopConfigUtils
shrinks to createHadoopConf + the adapter. Behavior-preserving: same lookup
order, same Option semantics, same deprecation warning text.
* refactor(common): delegate hadoop-mr table-path resolution to TablePathUtils
- HoodieInputFormatUtils#getTableMetaClientForBasePathUnchecked re-implemented
TablePathUtils#getTablePath's two-branch walk (partition metadata -> nth
parent; else walk up to .hoodie). Now delegates, throwing
TableNotFoundException on empty like before.
- Fix latent bug in TablePathUtils#getTablePathFromPartitionPath exposed by
the delegation: the parent walk assumed StoragePath#getParent returns null
at the root, but it throws IllegalStateException, so non-Hudi paths crashed
instead of returning Option.empty(). Guard on depth()==0; add unit test.
- Migrate ShowInvalidParquetProcedure off the FileSystem-based
HadoopFSUtils#getAllDataFilesInPartition to the HoodieStorage-based
FSUtils variant (it already had a HoodieStorage in scope) and delete the
Hadoop twin, which was kept alive solely for this caller.
Verified: TestInputPathHandler (exercises non-Hudi path classification),
TestTablePathUtils (incl. new root-walk test), TestShowInvalidParquetProcedure
(ScalaTest, end-to-end incl. delete path), TestHoodieRealtimeInputFormatUtils.
* refactor(common): move record reconstruction from SpillableMapUtils to HoodieAvroUtils
The three convertToHoodieRecordPayload overloads (+ private getPreCombineVal)
build a HoodieAvroRecord from an Avro record: extract key/partition from meta
fields, compute the ordering value, optionally strip meta fields, and
instantiate the payload. Nothing about them is specific to spillable maps --
they were only historically located there, and their sole production caller
is HoodieAvroUtils#createHoodieRecordFromAvro (the dispatcher).
Relocate them next to the dispatcher in HoodieAvroUtils; SpillableMapUtils
now contains only spill I/O (readBytesFromDisk/spillToDisk/computePayloadSize).
Behavior-preserving; one test call site updated.
* refactor(core): dedupe commit-metadata reads and reverse-instant scans in timeline utils
- RepairUtils#getBaseAndLogFilePathsFromTimeline hand-rolled the same
commit-vs-replace-commit metadata dispatch that TimelineUtils#getCommitMetadata
encapsulates; collapse the two switch arms into one that delegates. The
load-bearing default -> Option.empty() arm for unsupported actions stays.
- Extract TimelineUtils#findLatestInCommitMetadata: scan reverse-ordered
instants, read each commit metadata, return the first non-empty extraction.
TimelineUtils#getLatestInstantAndCommitMetadataWithValidCheckpointInfo and
CommitUtils#getValidCheckpointForCurrentWriter were near-identical copies of
this loop; both become 5-line specializations.
- RestoreUtils#getRestorePlan used getRollbackRequestedInstant instead of
getRestoreRequestedInstant. Both InstantGenerator implementations (V1/V2)
are currently identical for the two, so this is behavior-preserving, but
the restore-specific hook is the correct one to call.
Considered and rejected: a generic requested-plan reader template across
Compaction/Cleaner/Clustering/Rollback/RestoreUtils -- after recent upstream
refactoring those methods share only ~3 lines each with differing checked
exception contracts; a template would add indirection without removing
meaningful duplication.
* refactor(common): eliminate private duplicates of nullable-union unwrapping
Two private copies of the lenient nullable-union resolver existed alongside
the canonical helpers:
- Spark4VariantShreddingProvider#unwrapNullable(Schema) was byte-identical to
HoodieAvroUtils#unwrapNullable; use the canonical one via static import.
- HoodieVariantReconstruction#unwrapNullable(HoodieSchema) computed
isNullable() ? getNonNullType() : schema, which is provably equivalent to
HoodieSchema#getNonNullType() alone in every case (non-union and non-null
unions return `this`); call it directly.
The remaining resolvers each keep distinct, load-bearing semantics and are
intentionally NOT merged: AvroSchemaUtils#getNonNullTypeFromUnion (strict,
throws on multi-member unions), HoodieAvroUtils#unwrapNullable (lenient,
first non-null member), HoodieAvroUtils#getActualSchemaFromUnion (data-driven
resolution for complex unions), HoodieSchemaUtils#resolveUnionSchema
(by-fullname match), and AvroOrcUtils#getActualSchemaType (ORC-specific:
all-null union maps to a NULL schema).
* refactor(core): pull duplicated iterator boilerplate up into FileFormatUtils
Three methods on the FileFormatUtils contract had byte-identical bodies in
ParquetUtils, OrcUtils, and LanceUtils; convert them from abstract to
concrete on the base class:
- getHoodieKeyIterator(storage, filePath) delegates to the 4-arg overload
- fetchRecordKeysWithPositions(storage, filePath) delegates to the 4-arg one
- fetchRecordKeysWithPositions(storage, filePath, keyGen, partitionPath)
wraps getHoodieKeyIterator in a position-tracking CloseableMappingIterator
OrcUtils keeps its 4-arg fetch override (adds an existence guard) and
HFileUtils keeps its UnsupportedOperationException overrides so behavior is
unchanged everywhere; only the redundant Parquet/Orc/Lance copies are gone.
* fix(core): checkState(boolean, Supplier) throws IllegalStateException
The Supplier overload of ValidationUtils#checkState threw
IllegalArgumentException -- a copy-paste slip from the checkArgument family;
both sibling checkState overloads and the javadoc'd contract throw
IllegalStateException. Repo-wide audit found no callers of this overload and
no code catching IllegalArgumentException around checkState call sites, so
the thrown-type change has no observable impact today. Add a test pinning
the exception contract of all checkArgument/checkState overloads.
* style(common): fix import ordering nits from utils consolidation sweep
Seven checkstyle violations (ImportOrder / blank-line) introduced by the
scripted import swaps in the preceding commits; found by running the
checkstyle+scalastyle lifecycle gates locally across all touched module
chains, which now pass with zero violations.
* refactor(core): reconcile utils sweep with latest master (Vortex format)
- VortexUtils (new FileFormatUtils subclass on master) carried the same three
iterator boilerplate methods this branch pulled up into the base class;
drop the now-redundant overrides (byte-identical to the inherited impls).
- Restore HoodieCommitMetadata/HoodieException imports in
HoodieMetadataWriteUtils: master no longer uses them in this file but the
relocated updateColsToIndex does (rebase fallout).
* refactor(common): address utils-sweep review feedback
- Rename HoodieAvroUtils#convertToHoodieRecordPayload -> convertToRecord
(review: name described the payload era, not what it returns).
- Add direct unit test for convertToRecord covering meta-field key/partition
extraction, preCombine ordering value, explicit partition-name override,
and meta-field stripping via schemaWithoutMetaFields.
- getTableMetaClientForBasePathUnchecked: map FileNotFoundException from the
TablePathUtils lookup to TableNotFoundException, preserving the historical
contract for nonexistent input paths; add test.
---
.../hudi/client/BaseHoodieTableServiceClient.java | 6 +-
.../apache/hudi/client/BaseHoodieWriteClient.java | 8 +--
.../client/heartbeat/HoodieHeartbeatClient.java | 4 +-
...artbeatUtils.java => WriterHeartbeatUtils.java} | 2 +-
.../client/validator/StreamingOffsetValidator.java | 10 +--
.../FileGroupReaderBasedInlineLogAppendHandle.java | 2 +-
.../hudi/io/FileGroupReaderBasedMergeHandle.java | 6 +-
.../FileGroupReaderBasedNativeLogAppendHandle.java | 2 +-
.../org/apache/hudi/io/HoodieWriteMergeHandle.java | 2 +-
.../hudi/io/{IOUtils.java => MergeUtils.java} | 2 +-
.../hudi/io/cdc/HoodieCDCLogWriterFactory.java | 4 +-
.../hudi/metadata/HoodieColumnStatsIndexUtils.java | 80 ---------------------
.../hudi/metadata/HoodieMetadataWriteUtils.java | 44 ++++++++++++
.../java/org/apache/hudi/table/HoodieTable.java | 4 +-
.../action/commit/BaseCommitActionExecutor.java | 4 +-
.../hudi/table/action/restore/RestoreUtils.java | 2 +-
.../org/apache/hudi/table/repair/RepairUtils.java | 15 ++--
.../heartbeat/TestHoodieHeartbeatClient.java | 2 +-
.../validator/TestStreamingOffsetValidator.java | 2 +-
.../hudi/table/HoodieFlinkCopyOnWriteTable.java | 4 +-
.../commit/BaseFlinkCommitActionExecutor.java | 4 +-
.../run/strategy/JavaExecutionStrategy.java | 4 +-
.../hudi/table/HoodieJavaCopyOnWriteTable.java | 4 +-
.../commit/BaseJavaCommitActionExecutor.java | 4 +-
.../MultipleSparkJobExecutionStrategy.java | 6 +-
...SparkJobConsistentHashingExecutionStrategy.java | 6 +-
.../hudi/table/HoodieSparkCopyOnWriteTable.java | 4 +-
.../commit/BaseSparkCommitActionExecutor.java | 4 +-
.../ClusteringIdentityTestExecutionStrategy.java | 4 +-
...tSparkIOUtils.java => TestSparkMergeUtils.java} | 14 ++--
.../apache/hudi/common/avro/HoodieAvroUtils.java | 83 +++++++++++++++++++--
.../hudi/common/schema/HoodieSchemaUtils.java | 7 +-
.../common/table/checkpoint/CheckpointUtils.java | 47 ++++++++++++
.../HoodieIncrSourceCheckpointValUtils.java | 71 ------------------
.../common/table/timeline/ActiveTimelineUtils.java | 23 ------
.../hudi/common/table/timeline/TimelineUtils.java | 27 +++++--
.../apache/hudi/common/util/CollectionUtils.java | 29 ++++++++
.../org/apache/hudi/common/util/CommitUtils.java | 24 +++----
.../org/apache/hudi/common/util/ConfigUtils.java | 26 +++++++
.../apache/hudi/common/util/FileFormatUtils.java | 22 ++++--
...ckpointUtils.java => KafkaCheckpointUtils.java} | 2 +-
.../apache/hudi/common/util/SpillableMapUtils.java | 84 ----------------------
.../apache/hudi/common/util/TablePathUtils.java | 8 ++-
.../apache/hudi/common/util/TableServiceUtils.java | 11 ---
.../org/apache/hudi/common/util/ThreadUtils.java | 44 ------------
.../org/apache/hudi/common/util/VortexUtils.java | 22 ------
.../hudi/common/util/collection/ArrayUtils.java | 62 ----------------
...ils.java => SecondaryIndexDefinitionUtils.java} | 6 +-
.../index/secondary/SecondaryIndexManager.java | 10 +--
.../io/storage/HoodieNativeAvroHFileReader.java | 2 +-
.../hudi/common/avro/TestHoodieAvroUtils.java | 40 +++++++++++
.../table/checkpoint/TestCheckpointUtils.java | 48 +++++++++++++
.../TestHoodieIncrSourceCheckpointValUtils.java | 80 ---------------------
...intUtils.java => TestKafkaCheckpointUtils.java} | 76 ++++++++++----------
.../hudi/common/util/TestTableServiceUtils.java | 13 ----
.../hudi/sink/clustering/ClusteringOperator.java | 4 +-
.../sink/validator/FlinkKafkaOffsetValidator.java | 2 +-
.../validator/TestFlinkKafkaCheckpointParsing.java | 42 +++++------
.../apache/hudi/common/util/HadoopConfigUtils.java | 34 +--------
.../org/apache/hudi/common/util/LanceUtils.java | 22 ------
.../java/org/apache/hudi/common/util/OrcUtils.java | 17 -----
.../org/apache/hudi/common/util/ParquetUtils.java | 25 -------
.../org/apache/hudi/hadoop/fs/HadoopFSUtils.java | 40 -----------
.../hudi/hadoop/fs/inline/HadoopInLineFSUtils.java | 66 -----------------
.../hudi/hadoop/fs/inline/InLineFileSystem.java | 13 ++--
.../hadoop/HoodieVariantReconstruction.java | 10 +--
.../storage/hadoop/HadoopStorageConfiguration.java | 9 ++-
.../org/apache/hudi/common/fs/TestFSUtils.java | 4 +-
.../common/fs/inline/TestInLineFileSystem.java | 6 +-
.../TestInLineFileSystemWithHFileReader.java | 2 +-
.../table/timeline/TestHoodieActiveTimeline.java | 2 +-
.../hudi/common/util/TestHadoopConfigUtils.java | 18 -----
.../hudi/common/util/TestTablePathUtils.java | 14 ++++
.../hadoop/TestHadoopStorageConfiguration.java | 25 +++++++
.../hive/HoodieCombineRealtimeFileSplit.java | 6 +-
.../apache/hudi/hadoop/realtime/RealtimeSplit.java | 58 +++++++++------
.../hudi/hadoop/utils/HoodieInputFormatUtils.java | 33 ++++-----
.../apache/hudi/hadoop/utils/InputSplitUtils.java | 49 -------------
.../apache/hudi/hadoop/TestInputPathHandler.java | 14 ++++
.../org/apache/hudi/common/util/StringUtils.java | 6 +-
.../apache/hudi/common/util/ValidationUtils.java | 4 +-
.../hfile/{HFileUtils.java => HFileByteUtils.java} | 2 +-
.../org/apache/hudi/io/hfile/HFileReaderImpl.java | 2 +-
.../main/java/org/apache/hudi/io/hfile/Key.java | 2 +-
.../main/java/org/apache/hudi/io/util/IOUtils.java | 16 -----
.../hudi/common/util/TestValidationUtils.java | 53 ++++++++++++++
.../org/apache/hudi/io/hfile/TestHFileReader.java | 2 +-
.../hudi/io/storage/TestHoodieStorageBase.java | 4 +-
...TestHFileUtils.java => TestHFileByteUtils.java} | 6 +-
.../connect/writers/BufferedConnectWriter.java | 4 +-
.../HoodieFileGroupReaderBasedFileFormat.scala | 4 +-
.../procedures/ShowInvalidParquetProcedure.scala | 5 +-
.../TestColStatsRecordWithMetadataRecord.java | 4 +-
.../variant/Spark4VariantShreddingProvider.java | 13 +---
.../hudi/utilities/sources/HoodieIncrSource.java | 2 +-
.../hudi/utilities/sources/PulsarSource.java | 17 ++++-
.../validator/SparkKafkaOffsetValidator.java | 2 +-
.../TestHoodieIncrSourceE2EAutoUpgrade.java | 4 +-
98 files changed, 729 insertions(+), 1064 deletions(-)
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieTableServiceClient.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieTableServiceClient.java
index f68c078f167e..24ace4f86180 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieTableServiceClient.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieTableServiceClient.java
@@ -28,8 +28,8 @@ import org.apache.hudi.avro.model.HoodieRequestedReplaceMetadata;
import org.apache.hudi.avro.model.HoodieRollbackMetadata;
import org.apache.hudi.avro.model.HoodieRollbackPlan;
import org.apache.hudi.client.embedded.EmbeddedTimelineService;
-import org.apache.hudi.client.heartbeat.HeartbeatUtils;
import org.apache.hudi.client.heartbeat.HoodieHeartbeatClient;
+import org.apache.hudi.client.heartbeat.WriterHeartbeatUtils;
import org.apache.hudi.client.timeline.HoodieTimelineArchiver;
import org.apache.hudi.client.timeline.TimelineArchivers;
import org.apache.hudi.common.HoodiePendingRollbackInfo;
@@ -1116,11 +1116,11 @@ public abstract class BaseHoodieTableServiceClient<I, T, O> extends BaseHoodieCl
HoodieTimeline.FULL_BOOTSTRAP_INSTANT_TS)) {
// do we need to handle failed rollback of a bootstrap
rollbackFailedBootstrap();
- HeartbeatUtils.deleteHeartbeatFile(storage, basePath, entry.getKey(), config);
+ WriterHeartbeatUtils.deleteHeartbeatFile(storage, basePath, entry.getKey(), config);
break;
} else {
rollback(entry.getKey(), entry.getValue(), skipLocking, skipVersionCheck);
- HeartbeatUtils.deleteHeartbeatFile(storage, basePath, entry.getKey(), config);
+ WriterHeartbeatUtils.deleteHeartbeatFile(storage, basePath, entry.getKey(), config);
}
}
}
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java
index bd0fd7497366..a3229c5bb72f 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java
@@ -29,7 +29,7 @@ import org.apache.hudi.callback.HoodieWriteCommitCallback;
import org.apache.hudi.callback.common.HoodieWriteCommitCallbackMessage;
import org.apache.hudi.callback.common.WriteStatusValidator;
import org.apache.hudi.client.embedded.EmbeddedTimelineService;
-import org.apache.hudi.client.heartbeat.HeartbeatUtils;
+import org.apache.hudi.client.heartbeat.WriterHeartbeatUtils;
import org.apache.hudi.client.transaction.TransactionManager;
import org.apache.hudi.client.transaction.TransactionUtils;
import org.apache.hudi.client.validator.PreWriteValidatorUtils;
@@ -88,7 +88,7 @@ import org.apache.hudi.exception.HoodieRollbackException;
import org.apache.hudi.exception.HoodieSavepointException;
import org.apache.hudi.index.HoodieIndex;
import org.apache.hudi.keygen.constant.KeyGeneratorType;
-import org.apache.hudi.metadata.HoodieColumnStatsIndexUtils;
+import org.apache.hudi.metadata.HoodieMetadataWriteUtils;
import org.apache.hudi.metadata.HoodieTableMetadataUtil;
import org.apache.hudi.metadata.HoodieTableMetadataWriter;
import org.apache.hudi.metadata.MetadataPartitionType;
@@ -267,7 +267,7 @@ public abstract class BaseHoodieWriteClient<T, I, K, O> extends BaseHoodieClient
CommitUtils.buildMetadata(tableWriteStats.getDataTableWriteStats(), partitionToReplaceFileIds,
extraMetadata, operationType, config.getWriteSchema(), commitActionType));
HoodieInstant inflightInstant = table.getMetaClient().createNewInstant(State.INFLIGHT, commitActionType, instantTime);
- HeartbeatUtils.abortIfHeartbeatExpired(instantTime, table, heartbeatClient, config);
+ WriterHeartbeatUtils.abortIfHeartbeatExpired(instantTime, table, heartbeatClient, config);
this.txnManager.beginStateChange(Option.of(inflightInstant),
lastCompletedTxnAndMetadata.isPresent() ? Option.of(lastCompletedTxnAndMetadata.get().getLeft()) : Option.empty());
try {
@@ -339,7 +339,7 @@ public abstract class BaseHoodieWriteClient<T, I, K, O> extends BaseHoodieClient
completedInstant -> table.getMetaClient().getTableFormat().commit(metadata, completedInstant, getEngineContext(), table.getMetaClient(), table.getViewManager())
);
// update cols to Index as applicable
- HoodieColumnStatsIndexUtils.updateColsToIndex(table, config, metadata, commitActionType,
+ HoodieMetadataWriteUtils.updateColsToIndex(table, config, metadata, commitActionType,
(Functions.Function2<HoodieTableMetaClient, List<String>, Void>) (metaClient, columnsToIndex) -> {
updateColumnsToIndexWithColStats(metaClient, columnsToIndex);
return null;
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/heartbeat/HoodieHeartbeatClient.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/heartbeat/HoodieHeartbeatClient.java
index b8f2f15fdf0a..beeae36a4246 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/heartbeat/HoodieHeartbeatClient.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/heartbeat/HoodieHeartbeatClient.java
@@ -162,7 +162,7 @@ public class HoodieHeartbeatClient implements AutoCloseable, Serializable {
Heartbeat heartbeat = instantToHeartbeatMap.remove(instantTime);
if (isHeartbeatStarted(heartbeat)) {
stopHeartbeatScheduler(heartbeat);
- HeartbeatUtils.deleteHeartbeatFile(storage, basePath, instantTime);
+ WriterHeartbeatUtils.deleteHeartbeatFile(storage, basePath, instantTime);
log.info("Deleted heartbeat file for instant {}", instantTime);
}
return heartbeat;
@@ -241,7 +241,7 @@ public class HoodieHeartbeatClient implements AutoCloseable, Serializable {
if (heartbeat.getLastHeartbeatTime() != null && isHeartbeatExpired(instantTime)) {
// A previous refresh was delayed past the tolerable interval. Stop refreshing this heartbeat
// (cancel the scheduler) and do NOT advance the last heartbeat time, so the heartbeat stays expired
- // and the writer aborts at commit time via HeartbeatUtils.abortIfHeartbeatExpired(). We must not
+ // and the writer aborts at commit time via WriterHeartbeatUtils.abortIfHeartbeatExpired(). We must not
// keep refreshing here: a concurrent process (e.g. an async cleaner under LAZY failed-writes
// policy) may already have started rolling back this instant once it observed the expiry, and
// resurrecting the heartbeat could let this writer commit on top of rolled-back files.
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/heartbeat/HeartbeatUtils.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/heartbeat/WriterHeartbeatUtils.java
similarity index 99%
rename from hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/heartbeat/HeartbeatUtils.java
rename to hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/heartbeat/WriterHeartbeatUtils.java
index 9bbc810b4cd6..9763142628e4 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/heartbeat/HeartbeatUtils.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/heartbeat/WriterHeartbeatUtils.java
@@ -36,7 +36,7 @@ import static org.apache.hudi.common.heartbeat.HoodieHeartbeatUtils.getLastHeart
* Helper class to delete heartbeat for completed or failed instants with expired heartbeats.
*/
@Slf4j
-public class HeartbeatUtils {
+public class WriterHeartbeatUtils {
/**
* Deletes the heartbeat file for the specified instant.
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/validator/StreamingOffsetValidator.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/validator/StreamingOffsetValidator.java
index 26ad49366f4d..e70293539704 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/validator/StreamingOffsetValidator.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/validator/StreamingOffsetValidator.java
@@ -21,8 +21,8 @@ package org.apache.hudi.client.validator;
import org.apache.hudi.common.config.TypedProperties;
import org.apache.hudi.common.model.HoodieCommitMetadata;
-import org.apache.hudi.common.util.CheckpointUtils;
-import org.apache.hudi.common.util.CheckpointUtils.CheckpointFormat;
+import org.apache.hudi.common.util.KafkaCheckpointUtils;
+import org.apache.hudi.common.util.KafkaCheckpointUtils.CheckpointFormat;
import org.apache.hudi.common.util.Option;
import org.apache.hudi.config.HoodiePreCommitValidatorConfig;
import org.apache.hudi.config.HoodiePreCommitValidatorConfig.ValidationFailurePolicy;
@@ -133,7 +133,7 @@ public abstract class StreamingOffsetValidator extends BasePreCommitValidator {
String currentCheckpoint = currentCheckpointOpt.get();
// Validate current checkpoint format
- if (!CheckpointUtils.isValidCheckpointFormat(checkpointFormat, currentCheckpoint)) {
+ if (!KafkaCheckpointUtils.isValidCheckpointFormat(checkpointFormat, currentCheckpoint)) {
log.warn("Current checkpoint has invalid format: {}. Skipping validation.", currentCheckpoint);
return;
}
@@ -148,7 +148,7 @@ public abstract class StreamingOffsetValidator extends BasePreCommitValidator {
String previousCheckpoint = previousCheckpointOpt.get();
// Validate previous checkpoint format
- if (!CheckpointUtils.isValidCheckpointFormat(checkpointFormat, previousCheckpoint)) {
+ if (!KafkaCheckpointUtils.isValidCheckpointFormat(checkpointFormat, previousCheckpoint)) {
log.warn("Previous checkpoint has invalid format: {}. Skipping validation.", previousCheckpoint);
return;
}
@@ -156,7 +156,7 @@ public abstract class StreamingOffsetValidator extends BasePreCommitValidator {
// Calculate offset difference using format-specific logic.
// Note: calculateOffsetDifference always returns >= 0 because negative per-partition
// diffs (offset resets) are handled internally by using the current offset.
- long offsetDifference = CheckpointUtils.calculateOffsetDifference(
+ long offsetDifference = KafkaCheckpointUtils.calculateOffsetDifference(
checkpointFormat, previousCheckpoint, currentCheckpoint);
// Get actual new record count from write stats.
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/FileGroupReaderBasedInlineLogAppendHandle.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/FileGroupReaderBasedInlineLogAppendHandle.java
index 7f77f87df9b8..d2c0d1e0a002 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/FileGroupReaderBasedInlineLogAppendHandle.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/FileGroupReaderBasedInlineLogAppendHandle.java
@@ -76,7 +76,7 @@ public class FileGroupReaderBasedInlineLogAppendHandle<T, I, K, O> extends Hoodi
boolean usePosition = config.getBooleanOrDefault(MERGE_USE_RECORD_POSITIONS);
Option<InternalSchema> internalSchemaOption = SerDeHelper.fromJson(config.getInternalSchema());
TypedProperties props = TypedProperties.copy(config.getProps());
- long maxMemoryPerCompaction = IOUtils.getMaxMemoryPerCompaction(taskContextSupplier, config);
+ long maxMemoryPerCompaction = MergeUtils.getMaxMemoryPerCompaction(taskContextSupplier, config);
props.put(HoodieMemoryConfig.MAX_MEMORY_FOR_MERGE.key(), String.valueOf(maxMemoryPerCompaction));
Stream<HoodieLogFile> logFiles = operation.getDeltaFileNames().stream().map(logFileName ->
new HoodieLogFile(new StoragePath(FSUtils.constructAbsolutePath(
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/FileGroupReaderBasedMergeHandle.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/FileGroupReaderBasedMergeHandle.java
index 393e69ef2539..42cf14cc9c9d 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/FileGroupReaderBasedMergeHandle.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/FileGroupReaderBasedMergeHandle.java
@@ -206,7 +206,7 @@ public class FileGroupReaderBasedMergeHandle<T, I, K, O> extends HoodieWriteMerg
storage,
getWriterSchema(),
createLogWriter(instantTime, HoodieCDCUtils.CDC_LOGFILE_SUFFIX, Option.empty()),
- IOUtils.getMaxMemoryPerPartitionMerge(taskContextSupplier, config));
+ MergeUtils.getMaxMemoryPerPartitionMerge(taskContextSupplier, config));
}
private void init(CompactionOperation operation, String partitionPath) {
@@ -335,8 +335,8 @@ public class FileGroupReaderBasedMergeHandle<T, I, K, O> extends HoodieWriteMerg
}
protected long getMaxMemoryForMerge() {
- return compactionOperation.isPresent() ? IOUtils.getMaxMemoryPerCompaction(taskContextSupplier, config)
- : IOUtils.getMaxMemoryPerPartitionMerge(taskContextSupplier, config);
+ return compactionOperation.isPresent() ? MergeUtils.getMaxMemoryPerCompaction(taskContextSupplier, config)
+ : MergeUtils.getMaxMemoryPerPartitionMerge(taskContextSupplier, config);
}
protected HoodieRecordReader<T> getFileGroupReader(boolean usePosition, Option<InternalSchema> internalSchemaOption, TypedProperties props,
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/FileGroupReaderBasedNativeLogAppendHandle.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/FileGroupReaderBasedNativeLogAppendHandle.java
index c30a5f8bca1e..98cedd037a83 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/FileGroupReaderBasedNativeLogAppendHandle.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/FileGroupReaderBasedNativeLogAppendHandle.java
@@ -72,7 +72,7 @@ public class FileGroupReaderBasedNativeLogAppendHandle<T, I, K, O> extends Hoodi
boolean usePosition = config.getBooleanOrDefault(MERGE_USE_RECORD_POSITIONS);
Option<InternalSchema> internalSchemaOption = SerDeHelper.fromJson(config.getInternalSchema());
TypedProperties props = TypedProperties.copy(config.getProps());
- long maxMemoryPerCompaction = IOUtils.getMaxMemoryPerCompaction(taskContextSupplier, config);
+ long maxMemoryPerCompaction = MergeUtils.getMaxMemoryPerCompaction(taskContextSupplier, config);
props.put(HoodieMemoryConfig.MAX_MEMORY_FOR_MERGE.key(), String.valueOf(maxMemoryPerCompaction));
Stream<HoodieLogFile> logFiles = operation.getDeltaFileNames().stream().map(logFileName ->
new HoodieLogFile(new StoragePath(FSUtils.constructAbsolutePath(
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/HoodieWriteMergeHandle.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/HoodieWriteMergeHandle.java
index 495f0559d958..f343aefe9a40 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/HoodieWriteMergeHandle.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/HoodieWriteMergeHandle.java
@@ -200,7 +200,7 @@ public class HoodieWriteMergeHandle<T, I, K, O> extends HoodieAbstractMergeHandl
protected void initIncomingRecordsMap() {
try {
// Load the new records in a map
- long memoryForMerge = IOUtils.getMaxMemoryPerPartitionMerge(taskContextSupplier, config);
+ long memoryForMerge = MergeUtils.getMaxMemoryPerPartitionMerge(taskContextSupplier, config);
log.info("MaxMemoryPerPartitionMerge => {}", memoryForMerge);
this.keyToNewRecords = new ExternalSpillableMap<>(memoryForMerge, config.getSpillableMapBasePath(),
new DefaultSizeEstimator<>(), new HoodieRecordSizeEstimator<>(writeSchema),
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/IOUtils.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/MergeUtils.java
similarity index 99%
rename from hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/IOUtils.java
rename to hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/MergeUtils.java
index 778feffa51f8..aff49a7eed2d 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/IOUtils.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/MergeUtils.java
@@ -41,7 +41,7 @@ import static org.apache.hudi.common.config.HoodieMemoryConfig.MAX_MEMORY_FRACTI
import static org.apache.hudi.common.config.HoodieMemoryConfig.MAX_MEMORY_FRACTION_FOR_MERGE;
@Slf4j
-public class IOUtils {
+public class MergeUtils {
/**
* Dynamic calculation of max memory to use for spillable map. There is always more than one task
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/cdc/HoodieCDCLogWriterFactory.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/cdc/HoodieCDCLogWriterFactory.java
index 9ba1f30e9724..73c4341f5ea3 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/cdc/HoodieCDCLogWriterFactory.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/cdc/HoodieCDCLogWriterFactory.java
@@ -25,7 +25,7 @@ import org.apache.hudi.common.table.HoodieTableConfig;
import org.apache.hudi.common.table.log.HoodieLogFormat;
import org.apache.hudi.common.table.log.LogFileCreationCallback;
import org.apache.hudi.config.HoodieWriteConfig;
-import org.apache.hudi.io.IOUtils;
+import org.apache.hudi.io.MergeUtils;
import org.apache.hudi.storage.HoodieStorage;
import org.apache.hudi.table.HoodieTable;
import org.apache.hudi.util.CommonClientUtils;
@@ -77,6 +77,6 @@ public final class HoodieCDCLogWriterFactory {
storage,
writerSchema,
logWriterSupplier.get(),
- IOUtils.getMaxMemoryPerPartitionMerge(taskContextSupplier, config));
+ MergeUtils.getMaxMemoryPerPartitionMerge(taskContextSupplier, config));
}
}
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/HoodieColumnStatsIndexUtils.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/HoodieColumnStatsIndexUtils.java
deleted file mode 100644
index 0394039168f8..000000000000
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/HoodieColumnStatsIndexUtils.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.metadata;
-
-import org.apache.hudi.common.model.ActionType;
-import org.apache.hudi.common.model.HoodieCommitMetadata;
-import org.apache.hudi.common.table.HoodieTableMetaClient;
-import org.apache.hudi.common.util.Functions;
-import org.apache.hudi.common.util.Option;
-import org.apache.hudi.common.util.VisibleForTesting;
-import org.apache.hudi.config.HoodieWriteConfig;
-import org.apache.hudi.exception.HoodieException;
-import org.apache.hudi.table.HoodieTable;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.apache.hudi.metadata.HoodieTableMetadataUtil.PARTITION_NAME_COLUMN_STATS;
-
-/**
- * Utils to assist with updating columns to index with col stats.
- */
-public class HoodieColumnStatsIndexUtils {
-
- /**
- * Updates the list of columns to index with col stats partition in MDT.
- * @param dataTable {@link HoodieTable} of interest.
- * @param config {@link HoodieWriteConfig} of interest.
- * @param commitMetadata commit metadata of interest.
- * @param commitActionType commit action type to include interested actions.
- * @param updateColStatsFunc function to assist with updating columns to index.
- */
- @VisibleForTesting
- public static void updateColsToIndex(HoodieTable dataTable,
- HoodieWriteConfig config,
- HoodieCommitMetadata commitMetadata,
- String commitActionType,
- Functions.Function2<HoodieTableMetaClient, List<String>, Void> updateColStatsFunc) {
- if (config.isMetadataTableEnabled() // this is a data table
- && config.getMetadataConfig().isColumnStatsIndexEnabled() // the col_stats is enabled
- && ActionType.isCommitActionType(commitActionType)) { // with interested actions
- dataTable.getMetaClient().reloadTableConfig();
- try {
- // update data table's table config for list of columns indexed.
- List<String> columnsToIndex = new ArrayList<>(HoodieTableMetadataUtil.getColumnsToIndex(commitMetadata, dataTable.getMetaClient(), config.getMetadataConfig(),
- Option.of(config.getRecordMerger().getRecordType())).keySet());
- // if col stats is getting updated, lets also update list of columns indexed if changed.
- updateColStatsFunc.apply(dataTable.getMetaClient(), columnsToIndex);
- } catch (Exception e) {
- throw new HoodieException("Updating data table config to latest set of columns indexed with col stats failed ", e);
- }
- }
- }
-
- /**
- * Deletes col stats index definition for the given table of interest.
- * @param dataTableMetaClient {@link HoodieTableMetaClient} instance for the data table.
- */
- @VisibleForTesting
- public static void deleteColumnStatsIndexDefinition(HoodieTableMetaClient dataTableMetaClient) {
- dataTableMetaClient.deleteIndexDefinition(PARTITION_NAME_COLUMN_STATS);
- }
-}
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/HoodieMetadataWriteUtils.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/HoodieMetadataWriteUtils.java
index fa332bc83f40..f4c223992a7b 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/HoodieMetadataWriteUtils.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/HoodieMetadataWriteUtils.java
@@ -33,9 +33,11 @@ import org.apache.hudi.common.config.metrics.HoodieMetricsM3Config;
import org.apache.hudi.common.config.metrics.HoodieMetricsPrometheusConfig;
import org.apache.hudi.common.engine.HoodieLocalEngineContext;
import org.apache.hudi.common.fs.ConsistencyGuardConfig;
+import org.apache.hudi.common.model.ActionType;
import org.apache.hudi.common.model.HoodieAvroRecordMerger;
import org.apache.hudi.common.model.HoodieBaseFile;
import org.apache.hudi.common.model.HoodieCleaningPolicy;
+import org.apache.hudi.common.model.HoodieCommitMetadata;
import org.apache.hudi.common.model.HoodieFailedWritesCleaningPolicy;
import org.apache.hudi.common.model.HoodieLogFile;
import org.apache.hudi.common.model.HoodieRecordMerger;
@@ -50,6 +52,7 @@ import org.apache.hudi.common.table.timeline.HoodieInstant;
import org.apache.hudi.common.table.view.FileSystemViewManager;
import org.apache.hudi.common.table.view.SpillableMapBasedFileSystemView;
import org.apache.hudi.common.table.view.SyncableFileSystemView;
+import org.apache.hudi.common.util.Functions;
import org.apache.hudi.common.util.Option;
import org.apache.hudi.common.util.ValidationUtils;
import org.apache.hudi.common.util.VisibleForTesting;
@@ -60,10 +63,12 @@ import org.apache.hudi.config.HoodieLockConfig;
import org.apache.hudi.config.HoodiePayloadConfig;
import org.apache.hudi.config.HoodieWriteConfig;
import org.apache.hudi.core.transaction.lock.InProcessLockProvider;
+import org.apache.hudi.exception.HoodieException;
import org.apache.hudi.exception.HoodieMetadataException;
import org.apache.hudi.metadata.stats.HoodieColumnRangeMetadata;
import org.apache.hudi.storage.StoragePath;
import org.apache.hudi.storage.StoragePathInfo;
+import org.apache.hudi.table.HoodieTable;
import org.apache.hudi.table.action.compact.CompactionTriggerStrategy;
import org.apache.hudi.table.action.compact.strategy.UnBoundedCompactionStrategy;
@@ -435,4 +440,43 @@ public class HoodieMetadataWriteUtils {
.filter(e -> Objects.nonNull(e) && !filesWithColumnStats.contains(e) && !fileGroupIdsToReplace.contains(e))
.collect(Collectors.toSet());
}
+
+ /**
+ * Updates the list of columns to index with col stats partition in MDT.
+ * @param dataTable {@link HoodieTable} of interest.
+ * @param config {@link HoodieWriteConfig} of interest.
+ * @param commitMetadata commit metadata of interest.
+ * @param commitActionType commit action type to include interested actions.
+ * @param updateColStatsFunc function to assist with updating columns to index.
+ */
+ @VisibleForTesting
+ public static void updateColsToIndex(HoodieTable dataTable,
+ HoodieWriteConfig config,
+ HoodieCommitMetadata commitMetadata,
+ String commitActionType,
+ Functions.Function2<HoodieTableMetaClient, List<String>, Void> updateColStatsFunc) {
+ if (config.isMetadataTableEnabled() // this is a data table
+ && config.getMetadataConfig().isColumnStatsIndexEnabled() // the col_stats is enabled
+ && ActionType.isCommitActionType(commitActionType)) { // with interested actions
+ dataTable.getMetaClient().reloadTableConfig();
+ try {
+ // update data table's table config for list of columns indexed.
+ List<String> columnsToIndex = new ArrayList<>(HoodieTableMetadataUtil.getColumnsToIndex(commitMetadata, dataTable.getMetaClient(), config.getMetadataConfig(),
+ Option.of(config.getRecordMerger().getRecordType())).keySet());
+ // if col stats is getting updated, lets also update list of columns indexed if changed.
+ updateColStatsFunc.apply(dataTable.getMetaClient(), columnsToIndex);
+ } catch (Exception e) {
+ throw new HoodieException("Updating data table config to latest set of columns indexed with col stats failed ", e);
+ }
+ }
+ }
+
+ /**
+ * Deletes col stats index definition for the given table of interest.
+ * @param dataTableMetaClient {@link HoodieTableMetaClient} instance for the data table.
+ */
+ @VisibleForTesting
+ public static void deleteColumnStatsIndexDefinition(HoodieTableMetaClient dataTableMetaClient) {
+ dataTableMetaClient.deleteIndexDefinition(HoodieTableMetadataUtil.PARTITION_NAME_COLUMN_STATS);
+ }
}
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/HoodieTable.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/HoodieTable.java
index 4335f266ca8c..dd2b9eadd17b 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/HoodieTable.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/HoodieTable.java
@@ -81,7 +81,7 @@ import org.apache.hudi.exception.HoodieMetadataException;
import org.apache.hudi.exception.HoodieUpsertException;
import org.apache.hudi.exception.SchemaCompatibilityException;
import org.apache.hudi.index.HoodieIndex;
-import org.apache.hudi.metadata.HoodieColumnStatsIndexUtils;
+import org.apache.hudi.metadata.HoodieMetadataWriteUtils;
import org.apache.hudi.metadata.HoodieTableMetadata;
import org.apache.hudi.metadata.HoodieTableMetadataWriter;
import org.apache.hudi.metadata.MetadataPartitionType;
@@ -1153,7 +1153,7 @@ public abstract class HoodieTable<T, I, K, O> implements Serializable {
}
if (partitionType == MetadataPartitionType.COLUMN_STATS) {
// delete index definition as well
- HoodieColumnStatsIndexUtils.deleteColumnStatsIndexDefinition(getMetaClient());
+ HoodieMetadataWriteUtils.deleteColumnStatsIndexDefinition(getMetaClient());
}
clearMetadataTablePartitionsConfig(Option.of(partitionType), false);
} catch (HoodieMetadataException e) {
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/commit/BaseCommitActionExecutor.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/commit/BaseCommitActionExecutor.java
index 597489d219f8..c666615571ff 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/commit/BaseCommitActionExecutor.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/commit/BaseCommitActionExecutor.java
@@ -52,7 +52,7 @@ import org.apache.hudi.config.HoodieWriteConfig;
import org.apache.hudi.exception.HoodieClusteringException;
import org.apache.hudi.exception.HoodieCommitException;
import org.apache.hudi.exception.HoodieIOException;
-import org.apache.hudi.metadata.HoodieColumnStatsIndexUtils;
+import org.apache.hudi.metadata.HoodieMetadataWriteUtils;
import org.apache.hudi.table.HoodieTable;
import org.apache.hudi.table.WorkloadProfile;
import org.apache.hudi.table.WorkloadStat;
@@ -236,7 +236,7 @@ public abstract class BaseCommitActionExecutor<T, I, K, O, R>
log.info("Committed {}", instantTime);
result.setCommitMetadata(Option.of(metadata));
// update cols to Index as applicable
- HoodieColumnStatsIndexUtils.updateColsToIndex(table, config, metadata, actionType,
+ HoodieMetadataWriteUtils.updateColsToIndex(table, config, metadata, actionType,
(Functions.Function2<HoodieTableMetaClient, List<String>, Void>) (metaClient, columnsToIndex) -> {
updateColumnsToIndexForColumnStats(metaClient, columnsToIndex);
return null;
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/restore/RestoreUtils.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/restore/RestoreUtils.java
index eaed71a94996..d0223d862872 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/restore/RestoreUtils.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/restore/RestoreUtils.java
@@ -40,7 +40,7 @@ public class RestoreUtils {
*/
public static HoodieRestorePlan getRestorePlan(HoodieTableMetaClient metaClient, HoodieInstant restoreInstant)
throws IOException {
- final HoodieInstant requested = metaClient.getInstantGenerator().getRollbackRequestedInstant(restoreInstant);
+ final HoodieInstant requested = metaClient.getInstantGenerator().getRestoreRequestedInstant(restoreInstant);
return metaClient.getActiveTimeline().readRestorePlan(requested);
}
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/repair/RepairUtils.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/repair/RepairUtils.java
index 185e594dd232..7e8146b6a3bf 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/repair/RepairUtils.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/repair/RepairUtils.java
@@ -21,12 +21,12 @@ package org.apache.hudi.table.repair;
import org.apache.hudi.common.fs.FSUtils;
import org.apache.hudi.common.model.HoodieCommitMetadata;
-import org.apache.hudi.common.model.HoodieReplaceCommitMetadata;
import org.apache.hudi.common.model.HoodieWriteStat;
import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
import org.apache.hudi.common.table.timeline.HoodieArchivedTimeline;
import org.apache.hudi.common.table.timeline.HoodieInstant;
import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.table.timeline.TimelineUtils;
import org.apache.hudi.common.util.Option;
import org.apache.hudi.exception.HoodieException;
import org.apache.hudi.storage.StoragePath;
@@ -89,16 +89,13 @@ public final class RepairUtils {
switch (instant.getAction()) {
case COMMIT_ACTION:
- case DELTA_COMMIT_ACTION: {
- final HoodieCommitMetadata commitMetadata = timeline.readCommitMetadata(instant);
- return Option.of(commitMetadata.getPartitionToWriteStats().values().stream().flatMap(List::stream)
- .map(HoodieWriteStat::getPath).collect(Collectors.toSet()));
- }
+ case DELTA_COMMIT_ACTION:
case REPLACE_COMMIT_ACTION:
case CLUSTERING_ACTION: {
- final HoodieReplaceCommitMetadata replaceCommitMetadata =
- timeline.readReplaceCommitMetadata(instant);
- return Option.of(replaceCommitMetadata.getPartitionToWriteStats().values().stream().flatMap(List::stream)
+ // TimelineUtils#getCommitMetadata dispatches to the replace-commit read for
+ // REPLACE_COMMIT/CLUSTERING actions
+ final HoodieCommitMetadata commitMetadata = TimelineUtils.getCommitMetadata(instant, timeline);
+ return Option.of(commitMetadata.getPartitionToWriteStats().values().stream().flatMap(List::stream)
.map(HoodieWriteStat::getPath).collect(Collectors.toSet()));
}
default:
diff --git a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/heartbeat/TestHoodieHeartbeatClient.java b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/heartbeat/TestHoodieHeartbeatClient.java
index 5feb79ee83bc..2df16a1c90c9 100644
--- a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/heartbeat/TestHoodieHeartbeatClient.java
+++ b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/heartbeat/TestHoodieHeartbeatClient.java
@@ -106,7 +106,7 @@ public class TestHoodieHeartbeatClient extends HoodieCommonTestHarness {
hoodieHeartbeatClient.start(instantTime1);
hoodieHeartbeatClient.stop(instantTime1);
assertFalse(
- HeartbeatUtils.deleteHeartbeatFile(metaClient.getStorage(), basePath, instantTime2));
+ WriterHeartbeatUtils.deleteHeartbeatFile(metaClient.getStorage(), basePath, instantTime2));
}
@Test
diff --git a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/validator/TestStreamingOffsetValidator.java b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/validator/TestStreamingOffsetValidator.java
index 8e41b50e6078..1c66439bd098 100644
--- a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/validator/TestStreamingOffsetValidator.java
+++ b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/validator/TestStreamingOffsetValidator.java
@@ -25,7 +25,7 @@ import org.apache.hudi.common.model.HoodieWriteStat;
import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
import org.apache.hudi.common.table.timeline.HoodieInstant;
import org.apache.hudi.common.table.timeline.versioning.v2.InstantComparatorV2;
-import org.apache.hudi.common.util.CheckpointUtils.CheckpointFormat;
+import org.apache.hudi.common.util.KafkaCheckpointUtils.CheckpointFormat;
import org.apache.hudi.common.util.Option;
import org.apache.hudi.config.HoodiePreCommitValidatorConfig;
import org.apache.hudi.config.HoodiePreCommitValidatorConfig.ValidationFailurePolicy;
diff --git a/hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/table/HoodieFlinkCopyOnWriteTable.java b/hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/table/HoodieFlinkCopyOnWriteTable.java
index a6cf00fb6f26..3143a37bd99a 100644
--- a/hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/table/HoodieFlinkCopyOnWriteTable.java
+++ b/hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/table/HoodieFlinkCopyOnWriteTable.java
@@ -45,7 +45,7 @@ import org.apache.hudi.io.HoodieCreateHandle;
import org.apache.hudi.io.HoodieMergeHandle;
import org.apache.hudi.io.HoodieMergeHandleFactory;
import org.apache.hudi.io.HoodieWriteHandle;
-import org.apache.hudi.io.IOUtils;
+import org.apache.hudi.io.MergeUtils;
import org.apache.hudi.keygen.BaseKeyGenerator;
import org.apache.hudi.keygen.factory.HoodieAvroKeyGeneratorFactory;
import org.apache.hudi.metadata.MetadataPartitionType;
@@ -413,7 +413,7 @@ public class HoodieFlinkCopyOnWriteTable<T>
config.setRecordMergerClass(HoodieAvroRecordMerger.class.getName());
// these are updates
HoodieMergeHandle mergeHandle = getUpdateHandle(instantTime, partitionPath, fileId, keyToNewRecords, oldDataFile);
- return IOUtils.runMerge(mergeHandle, instantTime, fileId);
+ return MergeUtils.runMerge(mergeHandle, instantTime, fileId);
}
protected HoodieMergeHandle getUpdateHandle(String instantTime, String partitionPath, String fileId,
diff --git a/hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/table/action/commit/BaseFlinkCommitActionExecutor.java b/hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/table/action/commit/BaseFlinkCommitActionExecutor.java
index b8363a9f052c..c75aeeaaf9ad 100644
--- a/hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/table/action/commit/BaseFlinkCommitActionExecutor.java
+++ b/hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/table/action/commit/BaseFlinkCommitActionExecutor.java
@@ -36,7 +36,7 @@ import org.apache.hudi.io.HoodieCreateHandle;
import org.apache.hudi.io.HoodieMergeHandle;
import org.apache.hudi.io.HoodieWriteHandle;
import org.apache.hudi.io.HoodieWriteMergeHandle;
-import org.apache.hudi.io.IOUtils;
+import org.apache.hudi.io.MergeUtils;
import org.apache.hudi.table.HoodieTable;
import org.apache.hudi.table.action.HoodieWriteMetadata;
@@ -192,7 +192,7 @@ public abstract class BaseFlinkCommitActionExecutor<T> extends
ValidationUtils.checkArgument(this.writeHandle instanceof HoodieMergeHandle,
"`writeHandle` should be an instance of `HoodieMergeHandle`");
// these are updates
- return IOUtils.runMerge((HoodieMergeHandle<?, ?, ?, ?>) this.writeHandle, instantTime, fileId);
+ return MergeUtils.runMerge((HoodieMergeHandle<?, ?, ?, ?>) this.writeHandle, instantTime, fileId);
}
@Override
diff --git a/hudi-client/hudi-java-client/src/main/java/org/apache/hudi/client/clustering/run/strategy/JavaExecutionStrategy.java b/hudi-client/hudi-java-client/src/main/java/org/apache/hudi/client/clustering/run/strategy/JavaExecutionStrategy.java
index 27dbab4d0926..be9d9f03d388 100644
--- a/hudi-client/hudi-java-client/src/main/java/org/apache/hudi/client/clustering/run/strategy/JavaExecutionStrategy.java
+++ b/hudi-client/hudi-java-client/src/main/java/org/apache/hudi/client/clustering/run/strategy/JavaExecutionStrategy.java
@@ -38,7 +38,7 @@ import org.apache.hudi.common.util.collection.LazyConcatenatingIterator;
import org.apache.hudi.config.HoodieWriteConfig;
import org.apache.hudi.execution.bulkinsert.JavaBulkInsertInternalPartitionerFactory;
import org.apache.hudi.execution.bulkinsert.JavaCustomColumnsSortPartitioner;
-import org.apache.hudi.io.IOUtils;
+import org.apache.hudi.io.MergeUtils;
import org.apache.hudi.table.BulkInsertPartitioner;
import org.apache.hudi.table.HoodieTable;
import org.apache.hudi.table.action.HoodieWriteMetadata;
@@ -139,7 +139,7 @@ public abstract class JavaExecutionStrategy<T>
List<ClusteringOperation> clusteringOps = clusteringGroup.getSlices().stream().map(ClusteringOperation::create).collect(Collectors.toList());
HoodieWriteConfig config = getWriteConfig();
List<HoodieRecord<T>> records = new ArrayList<>();
- long maxMemoryPerCompaction = IOUtils.getMaxMemoryPerCompaction(new JavaTaskContextSupplier(), config);
+ long maxMemoryPerCompaction = MergeUtils.getMaxMemoryPerCompaction(new JavaTaskContextSupplier(), config);
log.info("MaxMemoryPerCompaction run as part of clustering => {}", maxMemoryPerCompaction);
List<Supplier<ClosableIterator<HoodieRecord<T>>>> suppliers = new ArrayList<>(clusteringOps.size());
diff --git a/hudi-client/hudi-java-client/src/main/java/org/apache/hudi/table/HoodieJavaCopyOnWriteTable.java b/hudi-client/hudi-java-client/src/main/java/org/apache/hudi/table/HoodieJavaCopyOnWriteTable.java
index bdac5434a059..01dc850319ba 100644
--- a/hudi-client/hudi-java-client/src/main/java/org/apache/hudi/table/HoodieJavaCopyOnWriteTable.java
+++ b/hudi-client/hudi-java-client/src/main/java/org/apache/hudi/table/HoodieJavaCopyOnWriteTable.java
@@ -44,7 +44,7 @@ import org.apache.hudi.exception.HoodieNotSupportedException;
import org.apache.hudi.io.HoodieCreateHandle;
import org.apache.hudi.io.HoodieMergeHandle;
import org.apache.hudi.io.HoodieMergeHandleFactory;
-import org.apache.hudi.io.IOUtils;
+import org.apache.hudi.io.MergeUtils;
import org.apache.hudi.keygen.BaseKeyGenerator;
import org.apache.hudi.keygen.factory.HoodieAvroKeyGeneratorFactory;
import org.apache.hudi.metadata.MetadataPartitionType;
@@ -282,7 +282,7 @@ public class HoodieJavaCopyOnWriteTable<T>
throws IOException {
// these are updates
HoodieMergeHandle mergeHandle = getUpdateHandle(instantTime, partitionPath, fileId, keyToNewRecords, oldDataFile);
- return IOUtils.runMerge(mergeHandle, instantTime, fileId);
+ return MergeUtils.runMerge(mergeHandle, instantTime, fileId);
}
protected HoodieMergeHandle getUpdateHandle(String instantTime, String partitionPath, String fileId,
diff --git a/hudi-client/hudi-java-client/src/main/java/org/apache/hudi/table/action/commit/BaseJavaCommitActionExecutor.java b/hudi-client/hudi-java-client/src/main/java/org/apache/hudi/table/action/commit/BaseJavaCommitActionExecutor.java
index 7746bdf3be7e..dd3b62f7fb55 100644
--- a/hudi-client/hudi-java-client/src/main/java/org/apache/hudi/table/action/commit/BaseJavaCommitActionExecutor.java
+++ b/hudi-client/hudi-java-client/src/main/java/org/apache/hudi/table/action/commit/BaseJavaCommitActionExecutor.java
@@ -39,7 +39,7 @@ import org.apache.hudi.execution.JavaLazyInsertIterable;
import org.apache.hudi.io.CreateHandleFactory;
import org.apache.hudi.io.HoodieMergeHandle;
import org.apache.hudi.io.HoodieMergeHandleFactory;
-import org.apache.hudi.io.IOUtils;
+import org.apache.hudi.io.MergeUtils;
import org.apache.hudi.keygen.BaseKeyGenerator;
import org.apache.hudi.keygen.factory.HoodieAvroKeyGeneratorFactory;
import org.apache.hudi.storage.StoragePath;
@@ -241,7 +241,7 @@ public abstract class BaseJavaCommitActionExecutor<T> extends
}
// these are updates
HoodieMergeHandle<?, ?, ?, ?> mergeHandle = getUpdateHandle(partitionPath, fileId, recordItr);
- return IOUtils.runMerge(mergeHandle, instantTime, fileId);
+ return MergeUtils.runMerge(mergeHandle, instantTime, fileId);
}
protected HoodieMergeHandle<?, ?, ?, ?> getUpdateHandle(String partitionPath, String fileId, Iterator<HoodieRecord<T>> recordItr) {
diff --git a/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/client/clustering/run/strategy/MultipleSparkJobExecutionStrategy.java b/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/client/clustering/run/strategy/MultipleSparkJobExecutionStrategy.java
index f56caacd4baf..befa4b925e8d 100644
--- a/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/client/clustering/run/strategy/MultipleSparkJobExecutionStrategy.java
+++ b/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/client/clustering/run/strategy/MultipleSparkJobExecutionStrategy.java
@@ -57,7 +57,7 @@ import org.apache.hudi.execution.bulkinsert.RDDCustomColumnsSortPartitioner;
import org.apache.hudi.execution.bulkinsert.RDDSpatialCurveSortPartitioner;
import org.apache.hudi.execution.bulkinsert.RowCustomColumnsSortPartitioner;
import org.apache.hudi.execution.bulkinsert.RowSpatialCurveSortPartitioner;
-import org.apache.hudi.io.IOUtils;
+import org.apache.hudi.io.MergeUtils;
import org.apache.hudi.table.BulkInsertPartitioner;
import org.apache.hudi.table.HoodieTable;
import org.apache.hudi.table.action.HoodieWriteMetadata;
@@ -276,7 +276,7 @@ public abstract class MultipleSparkJobExecutionStrategy<T>
ReaderContextFactory<T> readerContextFactory = getEngineContext().getReaderContextFactory(getHoodieTable().getMetaClient());
return HoodieJavaRDD.of(jsc.parallelize(clusteringOps, readParallelism).mapPartitions(clusteringOpsPartition -> {
List<Supplier<ClosableIterator<HoodieRecord<T>>>> suppliers = new ArrayList<>();
- long maxMemoryPerCompaction = IOUtils.getMaxMemoryPerCompaction(new SparkTaskContextSupplier(), getWriteConfig());
+ long maxMemoryPerCompaction = MergeUtils.getMaxMemoryPerCompaction(new SparkTaskContextSupplier(), getWriteConfig());
log.info("MaxMemoryPerCompaction run as part of clustering => {}", maxMemoryPerCompaction);
clusteringOpsPartition.forEachRemaining(clusteringOp -> {
Supplier<ClosableIterator<HoodieRecord<T>>> iteratorSupplier = () -> getRecordIterator(readerContextFactory, clusteringOp, instantTime, maxMemoryPerCompaction);
@@ -297,7 +297,7 @@ public abstract class MultipleSparkJobExecutionStrategy<T>
.map(ClusteringOperation::create).collect(Collectors.toList());
String basePath = getWriteConfig().getBasePath();
// construct supporting cast that executors might need
- long maxMemoryPerCompaction = IOUtils.getMaxMemoryPerCompaction(getEngineContext().getTaskContextSupplier(), writeConfig);
+ long maxMemoryPerCompaction = MergeUtils.getMaxMemoryPerCompaction(getEngineContext().getTaskContextSupplier(), writeConfig);
TypedProperties readerProperties = getReaderProperties(maxMemoryPerCompaction);
final boolean usePosition = getWriteConfig().getBooleanOrDefault(MERGE_USE_RECORD_POSITIONS);
String internalSchemaStr = getWriteConfig().getInternalSchema();
diff --git a/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/client/clustering/run/strategy/SingleSparkJobConsistentHashingExecutionStrategy.java b/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/client/clustering/run/strategy/SingleSparkJobConsistentHashingExecutionStrategy.java
index 707aa2d7d4fa..90ae591d026b 100644
--- a/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/client/clustering/run/strategy/SingleSparkJobConsistentHashingExecutionStrategy.java
+++ b/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/client/clustering/run/strategy/SingleSparkJobConsistentHashingExecutionStrategy.java
@@ -43,7 +43,7 @@ import org.apache.hudi.execution.ExecutorFactory;
import org.apache.hudi.index.bucket.ConsistentBucketIdentifier;
import org.apache.hudi.io.CreateHandleFactory;
import org.apache.hudi.io.HoodieWriteHandle;
-import org.apache.hudi.io.IOUtils;
+import org.apache.hudi.io.MergeUtils;
import org.apache.hudi.io.WriteHandleFactory;
import org.apache.hudi.keygen.KeyGenUtils;
import org.apache.hudi.table.HoodieTable;
@@ -109,7 +109,7 @@ public class SingleSparkJobConsistentHashingExecutionStrategy<T> extends SingleS
private List<WriteStatus> performBucketMergeForGroup(ReaderContextFactory<T> readerContextFactory, ClusteringGroupInfo clusteringGroup, Map<String, String> strategyParams,
TaskContextSupplier taskContextSupplier, String instantTime) {
- long maxMemoryPerCompaction = IOUtils.getMaxMemoryPerCompaction(taskContextSupplier, writeConfig);
+ long maxMemoryPerCompaction = MergeUtils.getMaxMemoryPerCompaction(taskContextSupplier, writeConfig);
log.info("MaxMemoryPerCompaction run as part of clustering => {}", maxMemoryPerCompaction);
Option<Map<String, String>> extraMetadata = clusteringGroup.getExtraMetadata();
ValidationUtils.checkArgument(extraMetadata.isPresent(), "Extra metadata should be present for consistent hashing operations");
@@ -209,7 +209,7 @@ public class SingleSparkJobConsistentHashingExecutionStrategy<T> extends SingleS
metadata.setChildrenNodes(nodes);
ConsistentBucketIdentifier identifier = new ConsistentBucketIdentifier(metadata);
ClusteringOperation operation = clusteringGroup.getOperations().get(0);
- ClosableIterator<HoodieRecord<T>> iterator = getRecordIterator(readerContextFactory, operation, instantTime, IOUtils.getMaxMemoryPerCompaction(new SparkTaskContextSupplier(), writeConfig));
+ ClosableIterator<HoodieRecord<T>> iterator = getRecordIterator(readerContextFactory, operation, instantTime, MergeUtils.getMaxMemoryPerCompaction(new SparkTaskContextSupplier(), writeConfig));
Function<HoodieRecord<T>, String> fileIdPrefixExtractor = record -> identifier.getBucket(record.getRecordKey(), this.indexKeyFieldList).getFileIdPrefix();
HoodieConsumer<HoodieRecord<T>, List<WriteStatus>> insertHandler =
diff --git a/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/table/HoodieSparkCopyOnWriteTable.java b/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/table/HoodieSparkCopyOnWriteTable.java
index 7c2be198a61d..50a5ddf7936b 100644
--- a/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/table/HoodieSparkCopyOnWriteTable.java
+++ b/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/table/HoodieSparkCopyOnWriteTable.java
@@ -49,7 +49,7 @@ import org.apache.hudi.exception.HoodieNotSupportedException;
import org.apache.hudi.io.HoodieCreateHandle;
import org.apache.hudi.io.HoodieMergeHandle;
import org.apache.hudi.io.HoodieMergeHandleFactory;
-import org.apache.hudi.io.IOUtils;
+import org.apache.hudi.io.MergeUtils;
import org.apache.hudi.keygen.BaseKeyGenerator;
import org.apache.hudi.keygen.factory.HoodieSparkKeyGeneratorFactory;
import org.apache.hudi.metadata.MetadataPartitionType;
@@ -240,7 +240,7 @@ public class HoodieSparkCopyOnWriteTable<T>
Map<String, HoodieRecord<T>> keyToNewRecords, HoodieBaseFile oldDataFile) throws IOException {
// these are updates
HoodieMergeHandle mergeHandle = getUpdateHandle(instantTime, partitionPath, fileId, keyToNewRecords, oldDataFile);
- return IOUtils.runMerge(mergeHandle, instantTime, fileId);
+ return MergeUtils.runMerge(mergeHandle, instantTime, fileId);
}
protected HoodieMergeHandle getUpdateHandle(String instantTime, String partitionPath, String fileId,
diff --git a/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/table/action/commit/BaseSparkCommitActionExecutor.java b/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/table/action/commit/BaseSparkCommitActionExecutor.java
index ed0dcaf321be..d253210f4b56 100644
--- a/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/table/action/commit/BaseSparkCommitActionExecutor.java
+++ b/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/table/action/commit/BaseSparkCommitActionExecutor.java
@@ -53,7 +53,7 @@ import org.apache.hudi.io.CreateHandleFactory;
import org.apache.hudi.io.HoodieMergeHandle;
import org.apache.hudi.io.HoodieMergeHandleFactory;
import org.apache.hudi.io.HoodieWriteMergeHandle;
-import org.apache.hudi.io.IOUtils;
+import org.apache.hudi.io.MergeUtils;
import org.apache.hudi.keygen.BaseKeyGenerator;
import org.apache.hudi.keygen.factory.HoodieSparkKeyGeneratorFactory;
import org.apache.hudi.table.HoodieTable;
@@ -436,7 +436,7 @@ public abstract class BaseSparkCommitActionExecutor<T> extends
// these are updates
HoodieMergeHandle mergeHandle = getUpdateHandle(partitionPath, fileId, recordItr);
- return IOUtils.runMerge(mergeHandle, instantTime, fileId);
+ return MergeUtils.runMerge(mergeHandle, instantTime, fileId);
}
protected HoodieMergeHandle getUpdateHandle(String partitionPath, String fileId, Iterator<HoodieRecord<T>> recordItr) {
diff --git a/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/ClusteringIdentityTestExecutionStrategy.java b/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/ClusteringIdentityTestExecutionStrategy.java
index a867581d5101..81df56907bf8 100644
--- a/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/ClusteringIdentityTestExecutionStrategy.java
+++ b/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/ClusteringIdentityTestExecutionStrategy.java
@@ -29,7 +29,7 @@ import org.apache.hudi.common.util.collection.ClosableIterator;
import org.apache.hudi.config.HoodieWriteConfig;
import org.apache.hudi.exception.HoodieClusteringException;
import org.apache.hudi.execution.SparkLazyInsertIterable;
-import org.apache.hudi.io.IOUtils;
+import org.apache.hudi.io.MergeUtils;
import org.apache.hudi.io.SingleFileHandleCreateFactory;
import org.apache.hudi.table.HoodieTable;
@@ -63,7 +63,7 @@ public class ClusteringIdentityTestExecutionStrategy<T extends HoodieRecordPaylo
throw new HoodieClusteringException("Expect only one partition and one fileId in clustering group for identity strategy: " + getClass().getName());
}
- long maxMemoryPerCompaction = IOUtils.getMaxMemoryPerCompaction(taskContextSupplier, getWriteConfig());
+ long maxMemoryPerCompaction = MergeUtils.getMaxMemoryPerCompaction(taskContextSupplier, getWriteConfig());
String fileId = clusteringGroup.getOperations().get(0).getFileId();
try (ClosableIterator recordItr =
getRecordIterator(readerContextFactory, clusteringGroup.getOperations().get(0), instantTime, maxMemoryPerCompaction)) {
diff --git a/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/io/TestSparkIOUtils.java b/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/io/TestSparkMergeUtils.java
similarity index 79%
rename from hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/io/TestSparkIOUtils.java
rename to hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/io/TestSparkMergeUtils.java
index 0a97e60d43c0..2ce98f316e66 100644
--- a/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/io/TestSparkIOUtils.java
+++ b/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/io/TestSparkMergeUtils.java
@@ -29,7 +29,7 @@ import static org.apache.hudi.common.config.HoodieMemoryConfig.MAX_MEMORY_FRACTI
import static org.apache.hudi.common.config.HoodieMemoryConfig.MAX_MEMORY_FRACTION_FOR_MERGE;
import static org.junit.jupiter.api.Assertions.assertEquals;
-public class TestSparkIOUtils {
+public class TestSparkMergeUtils {
@TempDir
public java.nio.file.Path basePath;
@@ -45,8 +45,8 @@ public class TestSparkIOUtils {
HoodieMemoryConfig memoryConfig = HoodieMemoryConfig.newBuilder().withMaxMemoryMaxSize(mergeMaxSize, compactionMaxSize).build();
HoodieWriteConfig config = HoodieWriteConfig.newBuilder().withPath(path).withMemoryConfig(memoryConfig).build();
- assertEquals(mergeMaxSize, IOUtils.getMaxMemoryPerPartitionMerge(contextSupplier, config));
- assertEquals(compactionMaxSize, IOUtils.getMaxMemoryPerCompaction(contextSupplier, config));
+ assertEquals(mergeMaxSize, MergeUtils.getMaxMemoryPerPartitionMerge(contextSupplier, config));
+ assertEquals(compactionMaxSize, MergeUtils.getMaxMemoryPerCompaction(contextSupplier, config));
}
@Test
@@ -56,12 +56,12 @@ public class TestSparkIOUtils {
HoodieWriteConfig config = HoodieWriteConfig.newBuilder().withPath(path).build();
String compactionFraction = config.getProps().getProperty(MAX_MEMORY_FRACTION_FOR_COMPACTION.key(), MAX_MEMORY_FRACTION_FOR_COMPACTION.defaultValue());
- long compactionMaxSize = IOUtils.getMaxMemoryAllowedForMerge(contextSupplier, compactionFraction);
+ long compactionMaxSize = MergeUtils.getMaxMemoryAllowedForMerge(contextSupplier, compactionFraction);
String mergeFraction = config.getProps().getProperty(MAX_MEMORY_FRACTION_FOR_MERGE.key(), MAX_MEMORY_FRACTION_FOR_MERGE.defaultValue());
- long mergeMaxSize = IOUtils.getMaxMemoryAllowedForMerge(contextSupplier, mergeFraction);
+ long mergeMaxSize = MergeUtils.getMaxMemoryAllowedForMerge(contextSupplier, mergeFraction);
- assertEquals(mergeMaxSize, IOUtils.getMaxMemoryPerPartitionMerge(contextSupplier, config));
- assertEquals(compactionMaxSize, IOUtils.getMaxMemoryPerCompaction(contextSupplier, config));
+ assertEquals(mergeMaxSize, MergeUtils.getMaxMemoryPerPartitionMerge(contextSupplier, config));
+ assertEquals(compactionMaxSize, MergeUtils.getMaxMemoryPerCompaction(contextSupplier, config));
}
}
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/avro/HoodieAvroUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/avro/HoodieAvroUtils.java
index 976617807c10..15f76a0fbc7f 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/avro/HoodieAvroUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/avro/HoodieAvroUtils.java
@@ -18,13 +18,18 @@
package org.apache.hudi.common.avro;
+import org.apache.hudi.common.model.HoodieAvroRecord;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieOperation;
import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordPayload;
import org.apache.hudi.common.schema.HoodieAvroSchemaCache;
import org.apache.hudi.common.schema.HoodieSchema;
import org.apache.hudi.common.schema.HoodieSchemaUtils;
import org.apache.hudi.common.util.DateTimeUtils;
+import org.apache.hudi.common.util.HoodieRecordUtils;
import org.apache.hudi.common.util.Option;
-import org.apache.hudi.common.util.SpillableMapUtils;
+import org.apache.hudi.common.util.OrderingValues;
import org.apache.hudi.common.util.StringUtils;
import org.apache.hudi.common.util.ValidationUtils;
import org.apache.hudi.common.util.collection.Pair;
@@ -1407,17 +1412,87 @@ public class HoodieAvroUtils {
boolean populateMetaFields,
Option<HoodieSchema> schemaWithoutMetaFields) {
if (populateMetaFields) {
- return SpillableMapUtils.convertToHoodieRecordPayload((GenericRecord) data,
+ return convertToRecord((GenericRecord) data,
payloadClass, preCombineFields, withOperation);
} else if (simpleKeyGenFieldsOpt.isPresent()) {
- return SpillableMapUtils.convertToHoodieRecordPayload((GenericRecord) data,
+ return convertToRecord((GenericRecord) data,
payloadClass, preCombineFields, simpleKeyGenFieldsOpt.get(), withOperation, partitionNameOp, schemaWithoutMetaFields);
} else {
- return SpillableMapUtils.convertToHoodieRecordPayload((GenericRecord) data,
+ return convertToRecord((GenericRecord) data,
payloadClass, preCombineFields, withOperation, partitionNameOp, schemaWithoutMetaFields);
}
}
+ /**
+ * Utility method to convert bytes to HoodieRecord using schema and payload class.
+ */
+ public static <R> HoodieRecord<R> convertToRecord(GenericRecord rec, String payloadClazz, String[] preCombineFields, boolean withOperationField) {
+ return convertToRecord(rec, payloadClazz, preCombineFields,
+ Pair.of(HoodieRecord.RECORD_KEY_METADATA_FIELD, HoodieRecord.PARTITION_PATH_METADATA_FIELD),
+ withOperationField, Option.empty(), Option.empty());
+ }
+
+ public static <R> HoodieRecord<R> convertToRecord(GenericRecord record, String payloadClazz,
+ String[] preCombineFields,
+ boolean withOperationField,
+ Option<String> partitionName,
+ Option<HoodieSchema> schemaWithoutMetaFields) {
+ return convertToRecord(record, payloadClazz, preCombineFields,
+ Pair.of(HoodieRecord.RECORD_KEY_METADATA_FIELD, HoodieRecord.PARTITION_PATH_METADATA_FIELD),
+ withOperationField, partitionName, schemaWithoutMetaFields);
+ }
+
+ /**
+ * Utility method to convert bytes to HoodieRecord using schema and payload class.
+ */
+ public static <R> HoodieRecord<R> convertToRecord(GenericRecord record, String payloadClazz,
+ String[] preCombineFields,
+ Pair<String, String> recordKeyPartitionPathFieldPair,
+ boolean withOperationField,
+ Option<String> partitionName,
+ Option<HoodieSchema> schemaWithoutMetaFields) {
+ final String recKey = record.get(recordKeyPartitionPathFieldPair.getKey()).toString();
+ final String partitionPath = (partitionName.isPresent() ? partitionName.get() :
+ record.get(recordKeyPartitionPathFieldPair.getRight()).toString());
+
+ Comparable preCombineVal = getPreCombineVal(record, preCombineFields);
+ HoodieOperation operation = withOperationField
+ ? HoodieOperation.fromName(getNullableValAsString(record, HoodieRecord.OPERATION_METADATA_FIELD)) : null;
+
+ if (schemaWithoutMetaFields.isPresent()) {
+ Schema schema = schemaWithoutMetaFields.get().toAvroSchema();
+ GenericRecord recordWithoutMetaFields = new GenericData.Record(schema);
+ for (Schema.Field f : schema.getFields()) {
+ recordWithoutMetaFields.put(f.pos(), record.get(f.name()));
+ }
+ record = recordWithoutMetaFields;
+ }
+
+ HoodieRecord<? extends HoodieRecordPayload> hoodieRecord = new HoodieAvroRecord<>(new HoodieKey(recKey, partitionPath),
+ HoodieRecordUtils.loadPayload(payloadClazz, record, preCombineVal), operation);
+ return (HoodieRecord<R>) hoodieRecord;
+ }
+
+ /**
+ * Returns the preCombine value with given field name.
+ *
+ * @param rec The avro record
+ * @param preCombineFields The preCombine field names
+ * @return the preCombine field value or 0 if the field does not exist in the avro schema
+ */
+ private static Comparable getPreCombineVal(GenericRecord rec, @Nullable String[] preCombineFields) {
+ if (preCombineFields == null) {
+ return OrderingValues.getDefault();
+ }
+ // keep consistent with writer side, using Java type for ordering value, see `DefaultHoodieRecordPayload`.
+ return OrderingValues.create(
+ preCombineFields,
+ field -> {
+ Object orderingValue = getNestedFieldVal(rec, field, true, false);
+ return orderingValue == null ? OrderingValues.getDefault() : (Comparable) orderingValue;
+ });
+ }
+
/**
* Given avro records, rewrites them with new schema.
*
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchemaUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchemaUtils.java
index 7f300856a61d..98a2d262a8fa 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchemaUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchemaUtils.java
@@ -32,9 +32,6 @@ import org.apache.avro.Schema;
import org.apache.avro.generic.GenericData;
import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.math.MathContext;
-import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -407,6 +404,7 @@ public final class HoodieSchemaUtils {
/**
* Converts a byte array to a BigDecimal with the specified precision and scale.
+ * Delegates to {@link HoodieAvroUtils#convertBytesToBigDecimal(byte[], int, int)}.
*
* @param value the byte array to convert
* @param precision the precision of the decimal
@@ -414,8 +412,7 @@ public final class HoodieSchemaUtils {
* @return the resulting BigDecimal
*/
public static BigDecimal convertBytesToBigDecimal(byte[] value, int precision, int scale) {
- return new BigDecimal(new BigInteger(value),
- scale, new MathContext(precision, RoundingMode.HALF_UP));
+ return HoodieAvroUtils.convertBytesToBigDecimal(value, precision, scale);
}
/**
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/table/checkpoint/CheckpointUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/table/checkpoint/CheckpointUtils.java
index 443383c77297..d81a1dcbedf2 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/table/checkpoint/CheckpointUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/table/checkpoint/CheckpointUtils.java
@@ -58,6 +58,10 @@ public class CheckpointUtils {
HOODIE_INCREMENTAL_SOURCES = Collections.unmodifiableSet(hoodieIncSource);
}
+ public static final String RESET_CHECKPOINT_V2_SEPARATOR = ":";
+ public static final String REQUEST_TIME_PREFIX = "resumeFromInstantRequestTime";
+ public static final String COMPLETION_TIME_PREFIX = "resumeFromInstantCompletionTime";
+
public static Checkpoint getCheckpoint(HoodieCommitMetadata commitMetadata) {
if (!StringUtils.isNullOrEmpty(commitMetadata.getMetadata(STREAMER_CHECKPOINT_KEY_V2))
|| !StringUtils.isNullOrEmpty(commitMetadata.getMetadata(STREAMER_CHECKPOINT_RESET_KEY_V2))) {
@@ -150,4 +154,47 @@ public class CheckpointUtils {
throw new UnsupportedOperationException("Unsupported checkpoint type: " + checkpoint.getClass());
}
+
+ /**
+ * For hoodie incremental source ingestion, if the target table is version 8 or higher, the checkpoint
+ * key set by streamer config can be in either of the following format:
+ * - resumeFromInstantRequestTime:[checkpoint value based on request time]
+ * - resumeFromInstantCompletionTime:[checkpoint value based on completion time]
+ *
+ * StreamerCheckpointV2FromCfgCkp class itself captured the fact that this is version 8 and higher, plus
+ * the checkpoint source is from streamer config override.
+ *
+ * When the checkpoint is consumed by individual data sources, we need to convert them to either vanilla
+ * checkpoint v1 (request time based) or checkpoint v2 (completion time based).
+ */
+ public static Checkpoint resolveToActualCheckpointVersion(UnresolvedStreamerCheckpointBasedOnCfg checkpoint) {
+ String[] parts = extractKeyValues(checkpoint);
+ switch (parts[0]) {
+ case REQUEST_TIME_PREFIX: {
+ return new StreamerCheckpointV1(checkpoint).setCheckpointKey(parts[1]);
+ }
+ case COMPLETION_TIME_PREFIX: {
+ return new StreamerCheckpointV2(checkpoint).setCheckpointKey(parts[1]);
+ }
+ default:
+ throw new IllegalArgumentException("Unknown event ordering mode " + parts[0]);
+ }
+ }
+
+ private static String[] extractKeyValues(UnresolvedStreamerCheckpointBasedOnCfg checkpoint) {
+ String checkpointKey = checkpoint.getCheckpointKey();
+ String[] parts = checkpointKey.split(RESET_CHECKPOINT_V2_SEPARATOR);
+ if (parts.length != 2
+ || (
+ !parts[0].trim().equals(REQUEST_TIME_PREFIX)
+ && !parts[0].trim().equals(COMPLETION_TIME_PREFIX)
+ )) {
+ throw new IllegalArgumentException(
+ "Illegal checkpoint key override `" + checkpointKey + "`. Valid format is either `resumeFromInstantRequestTime:<checkpoint value>` or "
+ + "`resumeFromInstantCompletionTime:<checkpoint value>`.");
+ }
+ parts[0] = parts[0].trim();
+ parts[1] = parts[1].trim();
+ return parts;
+ }
}
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/table/checkpoint/HoodieIncrSourceCheckpointValUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/table/checkpoint/HoodieIncrSourceCheckpointValUtils.java
deleted file mode 100644
index 829c985aeb10..000000000000
--- a/hudi-common/src/main/java/org/apache/hudi/common/table/checkpoint/HoodieIncrSourceCheckpointValUtils.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.common.table.checkpoint;
-
-/**
- * Utility class providing methods to check if a string starts with specific resume-related prefixes.
- */
-public class HoodieIncrSourceCheckpointValUtils {
- public static final String RESET_CHECKPOINT_V2_SEPARATOR = ":";
- public static final String REQUEST_TIME_PREFIX = "resumeFromInstantRequestTime";
- public static final String COMPLETION_TIME_PREFIX = "resumeFromInstantCompletionTime";
-
- /**
- * For hoodie incremental source ingestion, if the target table is version 8 or higher, the checkpoint
- * key set by streamer config can be in either of the following format:
- * - resumeFromInstantRequestTime:[checkpoint value based on request time]
- * - resumeFromInstantCompletionTime:[checkpoint value based on completion time]
- *
- * StreamerCheckpointV2FromCfgCkp class itself captured the fact that this is version 8 and higher, plus
- * the checkpoint source is from streamer config override.
- *
- * When the checkpoint is consumed by individual data sources, we need to convert them to either vanilla
- * checkpoint v1 (request time based) or checkpoint v2 (completion time based).
- */
- public static Checkpoint resolveToActualCheckpointVersion(UnresolvedStreamerCheckpointBasedOnCfg checkpoint) {
- String[] parts = extractKeyValues(checkpoint);
- switch (parts[0]) {
- case REQUEST_TIME_PREFIX: {
- return new StreamerCheckpointV1(checkpoint).setCheckpointKey(parts[1]);
- }
- case COMPLETION_TIME_PREFIX: {
- return new StreamerCheckpointV2(checkpoint).setCheckpointKey(parts[1]);
- }
- default:
- throw new IllegalArgumentException("Unknown event ordering mode " + parts[0]);
- }
- }
-
- private static String [] extractKeyValues(UnresolvedStreamerCheckpointBasedOnCfg checkpoint) {
- String checkpointKey = checkpoint.getCheckpointKey();
- String[] parts = checkpointKey.split(RESET_CHECKPOINT_V2_SEPARATOR);
- if (parts.length != 2
- || (
- !parts[0].trim().equals(REQUEST_TIME_PREFIX)
- && !parts[0].trim().equals(COMPLETION_TIME_PREFIX)
- )) {
- throw new IllegalArgumentException(
- "Illegal checkpoint key override `" + checkpointKey + "`. Valid format is either `resumeFromInstantRequestTime:<checkpoint value>` or "
- + "`resumeFromInstantCompletionTime:<checkpoint value>`.");
- }
- parts[0] = parts[0].trim();
- parts[1] = parts[1].trim();
- return parts;
- }
-}
\ No newline at end of file
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/ActiveTimelineUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/ActiveTimelineUtils.java
deleted file mode 100644
index 06aaea75d8c6..000000000000
--- a/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/ActiveTimelineUtils.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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.common.table.timeline;
-
-public class ActiveTimelineUtils {
-
-}
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/TimelineUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/TimelineUtils.java
index 647cab77123d..fa87f85303da 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/TimelineUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/TimelineUtils.java
@@ -56,6 +56,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.function.BiFunction;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -659,15 +660,29 @@ public class TimelineUtils {
* {@link HoodieCommitMetadata}; {@link Option#empty()} if no matching instant is found
* @throws IOException if reading commit metadata fails
*/
- @SuppressWarnings("unchecked")
public static Option<Pair<String, HoodieCommitMetadata>> getLatestInstantAndCommitMetadataWithValidCheckpointInfo(
HoodieTimeline timeline, String... checkpointKeys) throws IOException {
- return (Option<Pair<String, HoodieCommitMetadata>>) timeline.getReverseOrderedInstants().map(instant -> {
+ return findLatestInCommitMetadata(timeline, (instant, commitMetadata) -> {
+ boolean hasCheckpointMetadata = Arrays.stream(checkpointKeys)
+ .anyMatch(key -> !StringUtils.isNullOrEmpty(commitMetadata.getMetadata(key)));
+ return hasCheckpointMetadata ? Option.of(Pair.of(instant.toString(), commitMetadata)) : Option.empty();
+ });
+ }
+
+ /**
+ * Scans the timeline's instants in reverse order, reading each instant's commit metadata,
+ * and returns the first non-empty result of the extractor.
+ *
+ * @param timeline timeline whose instants are scanned (callers filter as needed)
+ * @param extractor extracts a result from an instant and its commit metadata; return
+ * {@link Option#empty()} to continue scanning
+ * @return first non-empty extraction in reverse instant order; empty if none matches
+ */
+ public static <T> Option<T> findLatestInCommitMetadata(
+ HoodieTimeline timeline, BiFunction<HoodieInstant, HoodieCommitMetadata, Option<T>> extractor) {
+ return timeline.getReverseOrderedInstants().map(instant -> {
try {
- HoodieCommitMetadata commitMetadata = timeline.readCommitMetadata(instant);
- boolean hasCheckpointMetadata = Arrays.stream(checkpointKeys)
- .anyMatch(key -> !StringUtils.isNullOrEmpty(commitMetadata.getMetadata(key)));
- return hasCheckpointMetadata ? Option.of(Pair.of(instant.toString(), commitMetadata)) : Option.empty();
+ return extractor.apply(instant, timeline.readCommitMetadata(instant));
} catch (IOException e) {
throw new HoodieIOException("Failed to parse HoodieCommitMetadata for " + instant.toString(), e);
}
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/util/CollectionUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/util/CollectionUtils.java
index 755cb7c5489e..f400916c8c99 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/CollectionUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/util/CollectionUtils.java
@@ -115,6 +115,35 @@ public class CollectionUtils {
return ts[ts.length - 1];
}
+ /**
+ * An empty immutable {@code long} array.
+ */
+ public static final long[] EMPTY_LONG_ARRAY = new long[0];
+
+ /**
+ * <p>Converts an array of object Longs to primitives.</p>
+ *
+ * <p>This method returns {@code null} for a {@code null} input array.</p>
+ *
+ * NOTE : Adapted from org.apache.commons.lang3.ArrayUtils
+ *
+ * @param array a {@code Long} array, may be {@code null}
+ * @return a {@code long} array, {@code null} if null array input
+ * @throws NullPointerException if array content is {@code null}
+ */
+ public static long[] toPrimitive(Long[] array) {
+ if (array == null) {
+ return null;
+ } else if (array.length == 0) {
+ return EMPTY_LONG_ARRAY;
+ }
+ final long[] result = new long[array.length];
+ for (int i = 0; i < array.length; i++) {
+ result[i] = array[i].longValue();
+ }
+ return result;
+ }
+
/**
* Collects provided {@link Iterator} to a {@link Stream}
*/
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/util/CommitUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/util/CommitUtils.java
index 68fc67438222..98aacc4bf34c 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/CommitUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/util/CommitUtils.java
@@ -27,6 +27,7 @@ import org.apache.hudi.common.schema.HoodieSchema;
import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
import org.apache.hudi.common.table.timeline.HoodieInstant;
import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.table.timeline.TimelineUtils;
import org.apache.hudi.common.util.collection.Pair;
import org.apache.hudi.exception.HoodieException;
import org.apache.hudi.exception.HoodieIOException;
@@ -175,22 +176,13 @@ public class CommitUtils {
*/
public static Option<String> getValidCheckpointForCurrentWriter(HoodieTimeline timeline, String checkpointKey,
String keyToLookup) {
- return (Option<String>) timeline.getWriteTimeline().filterCompletedInstants().getReverseOrderedInstants()
- .map(instant -> {
- try {
- HoodieCommitMetadata commitMetadata = timeline.readCommitMetadata(instant);
- // process commits only with checkpoint entries
- String checkpointValue = commitMetadata.getMetadata(checkpointKey);
- if (StringUtils.nonEmpty(checkpointValue)) {
- // return if checkpoint for "keyForLookup" exists.
- return readCheckpointValue(checkpointValue, keyToLookup);
- } else {
- return Option.empty();
- }
- } catch (IOException e) {
- throw new HoodieIOException("Failed to parse HoodieCommitMetadata for " + instant.toString(), e);
- }
- }).filter(Option::isPresent).findFirst().orElse(Option.empty());
+ return TimelineUtils.findLatestInCommitMetadata(timeline.getWriteTimeline().filterCompletedInstants(),
+ (instant, commitMetadata) -> {
+ // process commits only with checkpoint entries
+ String checkpointValue = commitMetadata.getMetadata(checkpointKey);
+ // return if checkpoint for "keyForLookup" exists.
+ return StringUtils.nonEmpty(checkpointValue) ? readCheckpointValue(checkpointValue, keyToLookup) : Option.empty();
+ });
}
public static Option<String> readCheckpointValue(String value, String id) {
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/util/ConfigUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/util/ConfigUtils.java
index 4acc973217ed..0c49d621989e 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/ConfigUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/util/ConfigUtils.java
@@ -411,6 +411,32 @@ public class ConfigUtils {
return Option.empty();
}
+ /**
+ * Gets the raw value for a {@link ConfigProperty} config using a key mapping function. The key
+ * and alternative keys are used to fetch the config. Unlike
+ * {@link #getStringWithAltKeys(Function, ConfigProperty)}, this does not fall back to the
+ * config's default value when the config is not found.
+ *
+ * @param keyMapper Mapper function to map the key to values.
+ * @param configProperty {@link ConfigProperty} config to fetch.
+ * @return {@link Option} of value if the config exists; empty {@link Option} otherwise.
+ */
+ public static Option<Object> getRawValueWithAltKeys(Function<String, Object> keyMapper,
+ ConfigProperty<?> configProperty) {
+ Object value = keyMapper.apply(configProperty.key());
+ if (value != null) {
+ return Option.of(value);
+ }
+ for (String alternative : configProperty.getAlternatives()) {
+ Object altValue = keyMapper.apply(alternative);
+ if (altValue != null) {
+ deprecationWarning(alternative, configProperty);
+ return Option.of(altValue);
+ }
+ }
+ return Option.empty();
+ }
+
/**
* Gets the raw value for a {@link ConfigProperty<T>} config from properties with the option
* of using default value.
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/util/FileFormatUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/util/FileFormatUtils.java
index 2e32a568a5e6..aa386a58cf3c 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/FileFormatUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/util/FileFormatUtils.java
@@ -28,6 +28,7 @@ import org.apache.hudi.common.model.HoodieRecord;
import org.apache.hudi.common.schema.HoodieSchema;
import org.apache.hudi.common.schema.HoodieSchemaUtils;
import org.apache.hudi.common.util.collection.ClosableIterator;
+import org.apache.hudi.common.util.collection.CloseableMappingIterator;
import org.apache.hudi.common.util.collection.Pair;
import org.apache.hudi.exception.HoodieException;
import org.apache.hudi.keygen.BaseKeyGenerator;
@@ -52,6 +53,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -257,7 +259,9 @@ public abstract class FileFormatUtils {
* @param filePath the data file path.
* @return {@link List} of pairs of {@link HoodieKey} and position fetched from the data file.
*/
- public abstract ClosableIterator<Pair<HoodieKey, Long>> fetchRecordKeysWithPositions(HoodieStorage storage, StoragePath filePath);
+ public ClosableIterator<Pair<HoodieKey, Long>> fetchRecordKeysWithPositions(HoodieStorage storage, StoragePath filePath) {
+ return fetchRecordKeysWithPositions(storage, filePath, Option.empty(), Option.empty());
+ }
/**
* Provides a closable iterator for reading the given data file.
@@ -280,7 +284,9 @@ public abstract class FileFormatUtils {
* @param filePath the data file path.
* @return {@link ClosableIterator} of {@link HoodieKey}s for reading the file.
*/
- public abstract ClosableIterator<HoodieKey> getHoodieKeyIterator(HoodieStorage storage, StoragePath filePath);
+ public ClosableIterator<HoodieKey> getHoodieKeyIterator(HoodieStorage storage, StoragePath filePath) {
+ return getHoodieKeyIterator(storage, filePath, Option.empty(), Option.empty());
+ }
protected HoodieSchema getKeyIteratorSchema(HoodieStorage storage, StoragePath filePath, Option<BaseKeyGenerator> keyGeneratorOpt, Option<String> partitionPath) {
return keyGeneratorOpt
@@ -302,10 +308,14 @@ public abstract class FileFormatUtils {
* @param partitionPath optional partition path for the file, if provided only the record key is read from the file
* @return {@link Iterator} of pairs of {@link HoodieKey} and position fetched from the data file.
*/
- public abstract ClosableIterator<Pair<HoodieKey, Long>> fetchRecordKeysWithPositions(HoodieStorage storage,
- StoragePath filePath,
- Option<BaseKeyGenerator> keyGeneratorOpt,
- Option<String> partitionPath);
+ public ClosableIterator<Pair<HoodieKey, Long>> fetchRecordKeysWithPositions(HoodieStorage storage,
+ StoragePath filePath,
+ Option<BaseKeyGenerator> keyGeneratorOpt,
+ Option<String> partitionPath) {
+ AtomicLong position = new AtomicLong(0);
+ return new CloseableMappingIterator<>(getHoodieKeyIterator(storage, filePath, keyGeneratorOpt, partitionPath),
+ key -> Pair.of(key, position.getAndIncrement()));
+ }
/**
* Read the Avro schema of the data file.
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/util/CheckpointUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/util/KafkaCheckpointUtils.java
similarity index 99%
rename from hudi-common/src/main/java/org/apache/hudi/common/util/CheckpointUtils.java
rename to hudi-common/src/main/java/org/apache/hudi/common/util/KafkaCheckpointUtils.java
index e3faabe10db3..44ed8c326e7f 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/CheckpointUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/util/KafkaCheckpointUtils.java
@@ -54,7 +54,7 @@ import java.util.Map;
* Note: To be implemented in Phase 4
*/
@Slf4j
-public class CheckpointUtils {
+public class KafkaCheckpointUtils {
/**
* Supported checkpoint formats across engines and sources.
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/util/SpillableMapUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/util/SpillableMapUtils.java
index 1bcb335c99a1..7076752f73fc 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/SpillableMapUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/util/SpillableMapUtils.java
@@ -18,28 +18,13 @@
package org.apache.hudi.common.util;
-import org.apache.hudi.common.avro.HoodieAvroUtils;
import org.apache.hudi.common.fs.SizeAwareDataOutputStream;
-import org.apache.hudi.common.model.HoodieAvroRecord;
-import org.apache.hudi.common.model.HoodieKey;
-import org.apache.hudi.common.model.HoodieOperation;
-import org.apache.hudi.common.model.HoodieRecord;
-import org.apache.hudi.common.model.HoodieRecordPayload;
-import org.apache.hudi.common.schema.HoodieSchema;
import org.apache.hudi.common.util.collection.BitCaskDiskMap.FileEntry;
-import org.apache.hudi.common.util.collection.Pair;
import org.apache.hudi.exception.HoodieCorruptedDataException;
-import org.apache.avro.Schema;
-import org.apache.avro.generic.GenericData;
-import org.apache.avro.generic.GenericRecord;
-
-import javax.annotation.Nullable;
-
import java.io.IOException;
import java.io.RandomAccessFile;
-import static org.apache.hudi.common.avro.HoodieAvroUtils.getNullableValAsString;
import static org.apache.hudi.common.util.BinaryUtil.generateChecksum;
/**
@@ -108,73 +93,4 @@ public class SpillableMapUtils {
return valueSizeEstimator.sizeEstimate(value);
}
- /**
- * Utility method to convert bytes to HoodieRecord using schema and payload class.
- */
- public static <R> HoodieRecord<R> convertToHoodieRecordPayload(GenericRecord rec, String payloadClazz, String[] preCombineFields, boolean withOperationField) {
- return convertToHoodieRecordPayload(rec, payloadClazz, preCombineFields,
- Pair.of(HoodieRecord.RECORD_KEY_METADATA_FIELD, HoodieRecord.PARTITION_PATH_METADATA_FIELD),
- withOperationField, Option.empty(), Option.empty());
- }
-
- public static <R> HoodieRecord<R> convertToHoodieRecordPayload(GenericRecord record, String payloadClazz,
- String[] preCombineFields,
- boolean withOperationField,
- Option<String> partitionName,
- Option<HoodieSchema> schemaWithoutMetaFields) {
- return convertToHoodieRecordPayload(record, payloadClazz, preCombineFields,
- Pair.of(HoodieRecord.RECORD_KEY_METADATA_FIELD, HoodieRecord.PARTITION_PATH_METADATA_FIELD),
- withOperationField, partitionName, schemaWithoutMetaFields);
- }
-
- /**
- * Utility method to convert bytes to HoodieRecord using schema and payload class.
- */
- public static <R> HoodieRecord<R> convertToHoodieRecordPayload(GenericRecord record, String payloadClazz,
- String[] preCombineFields,
- Pair<String, String> recordKeyPartitionPathFieldPair,
- boolean withOperationField,
- Option<String> partitionName,
- Option<HoodieSchema> schemaWithoutMetaFields) {
- final String recKey = record.get(recordKeyPartitionPathFieldPair.getKey()).toString();
- final String partitionPath = (partitionName.isPresent() ? partitionName.get() :
- record.get(recordKeyPartitionPathFieldPair.getRight()).toString());
-
- Comparable preCombineVal = getPreCombineVal(record, preCombineFields);
- HoodieOperation operation = withOperationField
- ? HoodieOperation.fromName(getNullableValAsString(record, HoodieRecord.OPERATION_METADATA_FIELD)) : null;
-
- if (schemaWithoutMetaFields.isPresent()) {
- Schema schema = schemaWithoutMetaFields.get().toAvroSchema();
- GenericRecord recordWithoutMetaFields = new GenericData.Record(schema);
- for (Schema.Field f : schema.getFields()) {
- recordWithoutMetaFields.put(f.pos(), record.get(f.name()));
- }
- record = recordWithoutMetaFields;
- }
-
- HoodieRecord<? extends HoodieRecordPayload> hoodieRecord = new HoodieAvroRecord<>(new HoodieKey(recKey, partitionPath),
- HoodieRecordUtils.loadPayload(payloadClazz, record, preCombineVal), operation);
- return (HoodieRecord<R>) hoodieRecord;
- }
-
- /**
- * Returns the preCombine value with given field name.
- *
- * @param rec The avro record
- * @param preCombineFields The preCombine field names
- * @return the preCombine field value or 0 if the field does not exist in the avro schema
- */
- private static Comparable getPreCombineVal(GenericRecord rec, @Nullable String[] preCombineFields) {
- if (preCombineFields == null) {
- return OrderingValues.getDefault();
- }
- // keep consistent with writer side, using Java type for ordering value, see `DefaultHoodieRecordPayload`.
- return OrderingValues.create(
- preCombineFields,
- field -> {
- Object orderingValue = HoodieAvroUtils.getNestedFieldVal(rec, field, true, false);
- return orderingValue == null ? OrderingValues.getDefault() : (Comparable) orderingValue;
- });
- }
}
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/util/TablePathUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/util/TablePathUtils.java
index 293c1326442b..d87ea014954c 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/TablePathUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/util/TablePathUtils.java
@@ -102,14 +102,16 @@ public class TablePathUtils {
} else {
// Simply traverse directory structure until found .hoodie folder
StoragePath current = partitionPath;
- while (current != null) {
+ while (true) {
if (hasTableMetadataFolder(storage, current)) {
return Option.of(current);
}
+ if (current.depth() == 0) {
+ // reached the root without finding a table metadata folder
+ return Option.empty();
+ }
current = current.getParent();
}
-
- return Option.empty();
}
} catch (IOException ioe) {
throw new HoodieException("Error reading partition metadata for " + partitionPath, ioe);
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/util/TableServiceUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/util/TableServiceUtils.java
index 245fc0cac1b8..b5634d1cdc4e 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/TableServiceUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/util/TableServiceUtils.java
@@ -158,15 +158,4 @@ public class TableServiceUtils {
public static boolean isStale(long startTimeMs, long maxProcessingTimeMs, long currentTimeMs) {
return startTimeMs + maxProcessingTimeMs < currentTimeMs;
}
-
- /**
- * Check if an instant start time is stale based on max processing time, using current system time.
- *
- * @param startTimeMs the instant start time in milliseconds
- * @param maxProcessingTimeMs the max processing time threshold in milliseconds
- * @return true if the instant is stale, false otherwise
- */
- public static boolean isStale(long startTimeMs, long maxProcessingTimeMs) {
- return isStale(startTimeMs, maxProcessingTimeMs, System.currentTimeMillis());
- }
}
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/util/ThreadUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/util/ThreadUtils.java
deleted file mode 100644
index a61040c5ef51..000000000000
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/ThreadUtils.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.common.util;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Utils for Java threading.
- */
-public class ThreadUtils {
-
- /**
- * Fetches all active threads currently running in the JVM
- */
- public static List<Thread> collectActiveThreads() {
- ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
- while (threadGroup.getParent() != null) {
- threadGroup = threadGroup.getParent();
- }
-
- Thread[] activeThreads = new Thread[threadGroup.activeCount()];
- threadGroup.enumerate(activeThreads);
-
- return Arrays.asList(activeThreads);
- }
-
-}
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/util/VortexUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/util/VortexUtils.java
index e51ab8910a4c..6e7e970c4022 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/VortexUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/util/VortexUtils.java
@@ -45,31 +45,9 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
public class VortexUtils extends FileFormatUtils {
- @Override
- public ClosableIterator<Pair<HoodieKey, Long>> fetchRecordKeysWithPositions(HoodieStorage storage, StoragePath filePath) {
- return fetchRecordKeysWithPositions(storage, filePath, Option.empty(), Option.empty());
- }
-
- @Override
- public ClosableIterator<Pair<HoodieKey, Long>> fetchRecordKeysWithPositions(HoodieStorage storage,
- StoragePath filePath,
- Option<BaseKeyGenerator> keyGeneratorOpt,
- Option<String> partitionPath) {
- AtomicLong position = new AtomicLong(0);
- return new CloseableMappingIterator<>(
- getHoodieKeyIterator(storage, filePath, keyGeneratorOpt, partitionPath),
- key -> Pair.of(key, position.getAndIncrement()));
- }
-
- @Override
- public ClosableIterator<HoodieKey> getHoodieKeyIterator(HoodieStorage storage, StoragePath filePath) {
- return getHoodieKeyIterator(storage, filePath, Option.empty(), Option.empty());
- }
-
@Override
public ClosableIterator<HoodieKey> getHoodieKeyIterator(HoodieStorage storage,
StoragePath filePath,
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/util/collection/ArrayUtils.java b/hudi-common/src/main/java/org/apache/hudi/common/util/collection/ArrayUtils.java
deleted file mode 100644
index cc76c9d3d1f1..000000000000
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/collection/ArrayUtils.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.common.util.collection;
-
-/**
- * <p>Operations on arrays, primitive arrays (like {@code int[]}) and
- * primitive wrapper arrays (like {@code Integer[]}).</p>
- *
- * <p>This class tries to handle {@code null} input gracefully.
- * An exception will not be thrown for a {@code null}
- * array input. However, an Object array that contains a {@code null}
- * element may throw an exception. Each method documents its behaviour.</p>
- *
- * NOTE : Adapted from org.apache.commons.lang3.ArrayUtils
- */
-public class ArrayUtils {
-
- /**
- * An empty immutable {@code long} array.
- */
- public static final long[] EMPTY_LONG_ARRAY = new long[0];
-
- // Long array converters
- // ----------------------------------------------------------------------
- /**
- * <p>Converts an array of object Longs to primitives.</p>
- *
- * <p>This method returns {@code null} for a {@code null} input array.</p>
- *
- * @param array a {@code Long} array, may be {@code null}
- * @return a {@code long} array, {@code null} if null array input
- * @throws NullPointerException if array content is {@code null}
- */
- public static long[] toPrimitive(Long[] array) {
- if (array == null) {
- return null;
- } else if (array.length == 0) {
- return EMPTY_LONG_ARRAY;
- }
- final long[] result = new long[array.length];
- for (int i = 0; i < array.length; i++) {
- result[i] = array[i].longValue();
- }
- return result;
- }
-}
diff --git a/hudi-common/src/main/java/org/apache/hudi/core/index/secondary/SecondaryIndexUtils.java b/hudi-common/src/main/java/org/apache/hudi/core/index/secondary/SecondaryIndexDefinitionUtils.java
similarity index 94%
rename from hudi-common/src/main/java/org/apache/hudi/core/index/secondary/SecondaryIndexUtils.java
rename to hudi-common/src/main/java/org/apache/hudi/core/index/secondary/SecondaryIndexDefinitionUtils.java
index 8b70f1b66876..9045b7f971f8 100644
--- a/hudi-common/src/main/java/org/apache/hudi/core/index/secondary/SecondaryIndexUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/core/index/secondary/SecondaryIndexDefinitionUtils.java
@@ -36,7 +36,7 @@ import java.util.List;
/**
* Utils for secondary index.
*/
-public class SecondaryIndexUtils {
+public class SecondaryIndexDefinitionUtils {
/**
* Get secondary index metadata for this table
@@ -46,7 +46,7 @@ public class SecondaryIndexUtils {
*/
public static Option<List<HoodieSecondaryIndex>> getSecondaryIndexes(HoodieTableMetaClient metaClient) {
Option<String> indexesMetadata = metaClient.getTableConfig().getSecondaryIndexesMetadata();
- return indexesMetadata.map(SecondaryIndexUtils::fromJsonString);
+ return indexesMetadata.map(SecondaryIndexDefinitionUtils::fromJsonString);
}
/**
@@ -57,7 +57,7 @@ public class SecondaryIndexUtils {
*/
public static List<HoodieSecondaryIndex> fromJsonString(String jsonStr) {
try {
- return SecondaryIndexUtils.fromJsonString(jsonStr,
+ return SecondaryIndexDefinitionUtils.fromJsonString(jsonStr,
new TypeReference<List<HoodieSecondaryIndex>>() {
});
} catch (Exception e) {
diff --git a/hudi-common/src/main/java/org/apache/hudi/core/index/secondary/SecondaryIndexManager.java b/hudi-common/src/main/java/org/apache/hudi/core/index/secondary/SecondaryIndexManager.java
index a4eecd7b6e42..933ad91c5ee7 100644
--- a/hudi-common/src/main/java/org/apache/hudi/core/index/secondary/SecondaryIndexManager.java
+++ b/hudi-common/src/main/java/org/apache/hudi/core/index/secondary/SecondaryIndexManager.java
@@ -80,7 +80,7 @@ public class SecondaryIndexManager {
boolean ignoreIfExists,
LinkedHashMap<String, Map<String, String>> columns,
Map<String, String> options) {
- Option<List<HoodieSecondaryIndex>> secondaryIndexes = SecondaryIndexUtils.getSecondaryIndexes(metaClient);
+ Option<List<HoodieSecondaryIndex>> secondaryIndexes = SecondaryIndexDefinitionUtils.getSecondaryIndexes(metaClient);
Set<String> colNames = columns.keySet();
HoodieSchema schema;
try {
@@ -120,7 +120,7 @@ public class SecondaryIndexManager {
// Persistence secondary indexes' metadata to hoodie.properties file
Properties updatedProps = new Properties();
updatedProps.put(HoodieTableConfig.SECONDARY_INDEXES_METADATA.key(),
- SecondaryIndexUtils.toJsonString(newSecondaryIndexes));
+ SecondaryIndexDefinitionUtils.toJsonString(newSecondaryIndexes));
HoodieTableConfig.update(metaClient.getStorage(), metaClient.getMetaPath(), updatedProps);
log.info("Success to add secondary index metadata: {}", secondaryIndexToAdd);
@@ -136,7 +136,7 @@ public class SecondaryIndexManager {
* @param ignoreIfNotExists Whether ignore drop if the specific secondary index no exists
*/
public void drop(HoodieTableMetaClient metaClient, String indexName, boolean ignoreIfNotExists) {
- Option<List<HoodieSecondaryIndex>> secondaryIndexes = SecondaryIndexUtils.getSecondaryIndexes(metaClient);
+ Option<List<HoodieSecondaryIndex>> secondaryIndexes = SecondaryIndexDefinitionUtils.getSecondaryIndexes(metaClient);
if (!indexExists(secondaryIndexes, indexName, Option.empty(), Option.empty())) {
if (ignoreIfNotExists) {
return;
@@ -152,7 +152,7 @@ public class SecondaryIndexManager {
if (CollectionUtils.nonEmpty(secondaryIndexesToKeep)) {
Properties updatedProps = new Properties();
updatedProps.put(HoodieTableConfig.SECONDARY_INDEXES_METADATA.key(),
- SecondaryIndexUtils.toJsonString(secondaryIndexesToKeep));
+ SecondaryIndexDefinitionUtils.toJsonString(secondaryIndexesToKeep));
HoodieTableConfig.update(metaClient.getStorage(), metaClient.getMetaPath(), updatedProps);
} else {
HoodieTableConfig.delete(metaClient.getStorage(), metaClient.getMetaPath(),
@@ -171,7 +171,7 @@ public class SecondaryIndexManager {
* @return Indexes in this table
*/
public Option<List<HoodieSecondaryIndex>> show(HoodieTableMetaClient metaClient) {
- return SecondaryIndexUtils.getSecondaryIndexes(metaClient);
+ return SecondaryIndexDefinitionUtils.getSecondaryIndexes(metaClient);
}
/**
diff --git a/hudi-common/src/main/java/org/apache/hudi/core/io/storage/HoodieNativeAvroHFileReader.java b/hudi-common/src/main/java/org/apache/hudi/core/io/storage/HoodieNativeAvroHFileReader.java
index 77d9cd7bda1a..23e83474eb6d 100644
--- a/hudi-common/src/main/java/org/apache/hudi/core/io/storage/HoodieNativeAvroHFileReader.java
+++ b/hudi-common/src/main/java/org/apache/hudi/core/io/storage/HoodieNativeAvroHFileReader.java
@@ -63,7 +63,7 @@ import java.util.stream.Collectors;
import static org.apache.hudi.common.util.StringUtils.fromUTF8Bytes;
import static org.apache.hudi.common.util.TypeUtils.unsafeCast;
-import static org.apache.hudi.io.hfile.HFileUtils.isPrefixOfKey;
+import static org.apache.hudi.io.hfile.HFileByteUtils.isPrefixOfKey;
/**
* An implementation of {@link HoodieAvroHFileReaderImplBase} using native {@link HFileReader}.
diff --git a/hudi-common/src/test/java/org/apache/hudi/common/avro/TestHoodieAvroUtils.java b/hudi-common/src/test/java/org/apache/hudi/common/avro/TestHoodieAvroUtils.java
index 9e40c80b2145..fd5934616e65 100644
--- a/hudi-common/src/test/java/org/apache/hudi/common/avro/TestHoodieAvroUtils.java
+++ b/hudi-common/src/test/java/org/apache/hudi/common/avro/TestHoodieAvroUtils.java
@@ -61,9 +61,11 @@ import org.apache.hudi.common.model.HoodieAvroRecord;
import org.apache.hudi.common.model.HoodieKey;
import org.apache.hudi.common.model.HoodieRecord;
import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.common.model.OverwriteWithLatestAvroPayload;
import org.apache.hudi.common.model.RewriteAvroPayload;
import org.apache.hudi.common.schema.HoodieSchema;
import org.apache.hudi.common.schema.HoodieSchemaUtils;
+import org.apache.hudi.common.util.Option;
import org.apache.hudi.exception.HoodieException;
import org.apache.hudi.exception.SchemaCompatibilityException;
@@ -1151,4 +1153,42 @@ public class TestHoodieAvroUtils {
Arguments.of(HoodieCommitMetadata.class)
);
}
+
+ /**
+ * Verifies convertToRecord: key/partition extraction from meta fields, ordering value from the
+ * preCombine field, explicit partition-name override, and meta-field stripping via
+ * schemaWithoutMetaFields.
+ */
+ @Test
+ public void testConvertToRecord() throws IOException {
+ Schema schema = new Schema.Parser().parse(EXAMPLE_SCHEMA_WITH_META_FIELDS);
+ GenericRecord rec = new GenericData.Record(schema);
+ rec.put("_hoodie_commit_time", "001");
+ rec.put("_hoodie_commit_seqno", "001_1_1");
+ rec.put("_hoodie_record_key", "key1");
+ rec.put("_hoodie_partition_path", "2024/01/01");
+ rec.put("_hoodie_file_name", "f1");
+ rec.put("timestamp", 3.5);
+ rec.put("_row_key", "key1");
+ rec.put("non_pii_col", "val1");
+ rec.put("pii_col", "val2");
+
+ // key and partition come from the meta fields; ordering value from the preCombine field
+ HoodieRecord<OverwriteWithLatestAvroPayload> record = HoodieAvroUtils.convertToRecord(
+ rec, OverwriteWithLatestAvroPayload.class.getName(), new String[] {"timestamp"}, false);
+ assertEquals(new HoodieKey("key1", "2024/01/01"), record.getKey());
+ assertNull(record.getOperation());
+ assertEquals(3.5, ((Double) record.getData().getOrderingValue()).doubleValue());
+
+ // explicit partition name wins over the meta field; meta fields stripped from the payload
+ HoodieSchema schemaWithoutMetaFields = HoodieSchema.parse(EXAMPLE_SCHEMA);
+ HoodieRecord<OverwriteWithLatestAvroPayload> overridden = HoodieAvroUtils.convertToRecord(
+ rec, OverwriteWithLatestAvroPayload.class.getName(), new String[] {"timestamp"}, false,
+ Option.of("override_partition"), Option.of(schemaWithoutMetaFields));
+ assertEquals(new HoodieKey("key1", "override_partition"), overridden.getKey());
+ GenericRecord stripped =
+ (GenericRecord) overridden.getData().getInsertValue(schemaWithoutMetaFields.toAvroSchema()).get();
+ assertEquals(NUM_FIELDS_IN_EXAMPLE_SCHEMA, stripped.getSchema().getFields().size());
+ assertEquals("key1", stripped.get("_row_key").toString());
+ }
}
diff --git a/hudi-common/src/test/java/org/apache/hudi/common/table/checkpoint/TestCheckpointUtils.java b/hudi-common/src/test/java/org/apache/hudi/common/table/checkpoint/TestCheckpointUtils.java
index 876c8a53162a..5812ddb4cb4b 100644
--- a/hudi-common/src/test/java/org/apache/hudi/common/table/checkpoint/TestCheckpointUtils.java
+++ b/hudi-common/src/test/java/org/apache/hudi/common/table/checkpoint/TestCheckpointUtils.java
@@ -199,4 +199,52 @@ public class TestCheckpointUtils {
assertInstanceOf(StreamerCheckpointV1.class, checkpoint);
assertEquals(CHECKPOINT_TO_RESUME, checkpoint.getCheckpointKey());
}
+
+ @Test
+ public void testResolveToV1V2CheckpointWithRequestTime() {
+ String checkpoint = "20240301";
+ UnresolvedStreamerCheckpointBasedOnCfg mockCheckpoint = mock(UnresolvedStreamerCheckpointBasedOnCfg.class);
+ when(mockCheckpoint.getCheckpointKey()).thenReturn("resumeFromInstantRequestTime:" + checkpoint);
+
+ Checkpoint result = CheckpointUtils.resolveToActualCheckpointVersion(mockCheckpoint);
+
+ assertInstanceOf(StreamerCheckpointV1.class, result);
+ assertEquals(checkpoint, result.getCheckpointKey());
+ }
+
+ @Test
+ public void testResolveToV1V2CheckpointWithCompletionTime() {
+ String checkpoint = "20240302";
+ UnresolvedStreamerCheckpointBasedOnCfg mockCheckpoint = mock(UnresolvedStreamerCheckpointBasedOnCfg.class);
+ when(mockCheckpoint.getCheckpointKey()).thenReturn("resumeFromInstantCompletionTime:" + checkpoint);
+
+ Checkpoint result = CheckpointUtils.resolveToActualCheckpointVersion(mockCheckpoint);
+
+ assertInstanceOf(StreamerCheckpointV2.class, result);
+ assertEquals(checkpoint, result.getCheckpointKey());
+ }
+
+ @Test
+ public void testResolveToV1V2CheckpointWithInvalidPrefix() {
+ UnresolvedStreamerCheckpointBasedOnCfg mockCheckpoint = mock(UnresolvedStreamerCheckpointBasedOnCfg.class);
+ when(mockCheckpoint.getCheckpointKey()).thenReturn("invalidPrefix:20240303");
+
+ IllegalArgumentException exception = assertThrows(
+ IllegalArgumentException.class,
+ () -> CheckpointUtils.resolveToActualCheckpointVersion(mockCheckpoint)
+ );
+ assertTrue(exception.getMessage().contains("Illegal checkpoint key override"));
+ }
+
+ @Test
+ public void testResolveToV1V2CheckpointWithMalformedInput() {
+ UnresolvedStreamerCheckpointBasedOnCfg mockCheckpoint = mock(UnresolvedStreamerCheckpointBasedOnCfg.class);
+ when(mockCheckpoint.getCheckpointKey()).thenReturn("malformedInput");
+
+ IllegalArgumentException exception = assertThrows(
+ IllegalArgumentException.class,
+ () -> CheckpointUtils.resolveToActualCheckpointVersion(mockCheckpoint)
+ );
+ assertTrue(exception.getMessage().contains("Illegal checkpoint key override"));
+ }
}
diff --git a/hudi-common/src/test/java/org/apache/hudi/common/table/checkpoint/TestHoodieIncrSourceCheckpointValUtils.java b/hudi-common/src/test/java/org/apache/hudi/common/table/checkpoint/TestHoodieIncrSourceCheckpointValUtils.java
deleted file mode 100644
index 5e9f220d1135..000000000000
--- a/hudi-common/src/test/java/org/apache/hudi/common/table/checkpoint/TestHoodieIncrSourceCheckpointValUtils.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.common.table.checkpoint;
-
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class TestHoodieIncrSourceCheckpointValUtils {
-
- @Test
- public void testResolveToV1V2CheckpointWithRequestTime() {
- String checkpoint = "20240301";
- UnresolvedStreamerCheckpointBasedOnCfg mockCheckpoint = mock(UnresolvedStreamerCheckpointBasedOnCfg.class);
- when(mockCheckpoint.getCheckpointKey()).thenReturn("resumeFromInstantRequestTime:" + checkpoint);
-
- Checkpoint result = HoodieIncrSourceCheckpointValUtils.resolveToActualCheckpointVersion(mockCheckpoint);
-
- assertInstanceOf(StreamerCheckpointV1.class, result);
- assertEquals(checkpoint, result.getCheckpointKey());
- }
-
- @Test
- public void testResolveToV1V2CheckpointWithCompletionTime() {
- String checkpoint = "20240302";
- UnresolvedStreamerCheckpointBasedOnCfg mockCheckpoint = mock(UnresolvedStreamerCheckpointBasedOnCfg.class);
- when(mockCheckpoint.getCheckpointKey()).thenReturn("resumeFromInstantCompletionTime:" + checkpoint);
-
- Checkpoint result = HoodieIncrSourceCheckpointValUtils.resolveToActualCheckpointVersion(mockCheckpoint);
-
- assertInstanceOf(StreamerCheckpointV2.class, result);
- assertEquals(checkpoint, result.getCheckpointKey());
- }
-
- @Test
- public void testResolveToV1V2CheckpointWithInvalidPrefix() {
- UnresolvedStreamerCheckpointBasedOnCfg mockCheckpoint = mock(UnresolvedStreamerCheckpointBasedOnCfg.class);
- when(mockCheckpoint.getCheckpointKey()).thenReturn("invalidPrefix:20240303");
-
- IllegalArgumentException exception = assertThrows(
- IllegalArgumentException.class,
- () -> HoodieIncrSourceCheckpointValUtils.resolveToActualCheckpointVersion(mockCheckpoint)
- );
- assertTrue(exception.getMessage().contains("Illegal checkpoint key override"));
- }
-
- @Test
- public void testResolveToV1V2CheckpointWithMalformedInput() {
- UnresolvedStreamerCheckpointBasedOnCfg mockCheckpoint = mock(UnresolvedStreamerCheckpointBasedOnCfg.class);
- when(mockCheckpoint.getCheckpointKey()).thenReturn("malformedInput");
-
- IllegalArgumentException exception = assertThrows(
- IllegalArgumentException.class,
- () -> HoodieIncrSourceCheckpointValUtils.resolveToActualCheckpointVersion(mockCheckpoint)
- );
- assertTrue(exception.getMessage().contains("Illegal checkpoint key override"));
- }
-}
\ No newline at end of file
diff --git a/hudi-common/src/test/java/org/apache/hudi/common/util/TestCheckpointUtils.java b/hudi-common/src/test/java/org/apache/hudi/common/util/TestKafkaCheckpointUtils.java
similarity index 70%
rename from hudi-common/src/test/java/org/apache/hudi/common/util/TestCheckpointUtils.java
rename to hudi-common/src/test/java/org/apache/hudi/common/util/TestKafkaCheckpointUtils.java
index e71295543222..e9c2a770bf8d 100644
--- a/hudi-common/src/test/java/org/apache/hudi/common/util/TestCheckpointUtils.java
+++ b/hudi-common/src/test/java/org/apache/hudi/common/util/TestKafkaCheckpointUtils.java
@@ -19,7 +19,7 @@
package org.apache.hudi.common.util;
-import org.apache.hudi.common.util.CheckpointUtils.CheckpointFormat;
+import org.apache.hudi.common.util.KafkaCheckpointUtils.CheckpointFormat;
import org.junit.jupiter.api.Test;
@@ -31,14 +31,14 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
- * Tests for CheckpointUtils - Phase 1 core functionality.
+ * Tests for KafkaCheckpointUtils - Phase 1 core functionality.
*/
-public class TestCheckpointUtils {
+public class TestKafkaCheckpointUtils {
@Test
public void testParseSparkKafkaCheckpoint() {
String checkpoint = "test_topic,0:100,1:200,2:150";
- Map<Integer, Long> offsets = CheckpointUtils.parseCheckpoint(
+ Map<Integer, Long> offsets = KafkaCheckpointUtils.parseCheckpoint(
CheckpointFormat.SPARK_KAFKA, checkpoint);
assertEquals(3, offsets.size());
@@ -50,7 +50,7 @@ public class TestCheckpointUtils {
@Test
public void testParseSinglePartition() {
String checkpoint = "my_topic,0:1000";
- Map<Integer, Long> offsets = CheckpointUtils.parseCheckpoint(
+ Map<Integer, Long> offsets = KafkaCheckpointUtils.parseCheckpoint(
CheckpointFormat.SPARK_KAFKA, checkpoint);
assertEquals(1, offsets.size());
@@ -60,49 +60,49 @@ public class TestCheckpointUtils {
@Test
public void testParseInvalidFormat() {
assertThrows(IllegalArgumentException.class, () ->
- CheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, "invalid"));
+ KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, "invalid"));
assertThrows(IllegalArgumentException.class, () ->
- CheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, "topic"));
+ KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, "topic"));
assertThrows(IllegalArgumentException.class, () ->
- CheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, ""));
+ KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, ""));
assertThrows(IllegalArgumentException.class, () ->
- CheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, null));
+ KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, null));
}
@Test
public void testParseInvalidPartitionOffset() {
assertThrows(IllegalArgumentException.class, () ->
- CheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, "topic,0:abc"));
+ KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, "topic,0:abc"));
assertThrows(IllegalArgumentException.class, () ->
- CheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, "topic,abc:100"));
+ KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, "topic,abc:100"));
assertThrows(IllegalArgumentException.class, () ->
- CheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, "topic,0-100"));
+ KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.SPARK_KAFKA, "topic,0-100"));
}
@Test
public void testExtractTopicName() {
assertEquals("test_topic",
- CheckpointUtils.extractTopicName("test_topic,0:100,1:200"));
+ KafkaCheckpointUtils.extractTopicName("test_topic,0:100,1:200"));
assertEquals("my.topic.name",
- CheckpointUtils.extractTopicName("my.topic.name,0:1000"));
+ KafkaCheckpointUtils.extractTopicName("my.topic.name,0:1000"));
}
@Test
public void testExtractTopicNameInvalid() {
assertThrows(IllegalArgumentException.class, () ->
- CheckpointUtils.extractTopicName(""));
+ KafkaCheckpointUtils.extractTopicName(""));
assertThrows(IllegalArgumentException.class, () ->
- CheckpointUtils.extractTopicName(null));
+ KafkaCheckpointUtils.extractTopicName(null));
// Topic-only without partition data should be invalid
assertThrows(IllegalArgumentException.class, () ->
- CheckpointUtils.extractTopicName("just_topic"));
+ KafkaCheckpointUtils.extractTopicName("just_topic"));
}
@Test
@@ -111,7 +111,7 @@ public class TestCheckpointUtils {
String current = "topic,0:150,1:300";
// (150-100) + (300-200) = 50 + 100 = 150
- long diff = CheckpointUtils.calculateOffsetDifference(
+ long diff = KafkaCheckpointUtils.calculateOffsetDifference(
CheckpointFormat.SPARK_KAFKA, previous, current);
assertEquals(150L, diff);
}
@@ -121,7 +121,7 @@ public class TestCheckpointUtils {
String previous = "topic,0:100,1:200";
String current = "topic,0:100,1:200";
- long diff = CheckpointUtils.calculateOffsetDifference(
+ long diff = KafkaCheckpointUtils.calculateOffsetDifference(
CheckpointFormat.SPARK_KAFKA, previous, current);
assertEquals(0L, diff);
}
@@ -134,7 +134,7 @@ public class TestCheckpointUtils {
// Partition 0: 150-100 = 50
// Partition 1: new partition, skipped (start offset unknown)
// Total: 50
- long diff = CheckpointUtils.calculateOffsetDifference(
+ long diff = KafkaCheckpointUtils.calculateOffsetDifference(
CheckpointFormat.SPARK_KAFKA, previous, current);
assertEquals(50L, diff);
}
@@ -146,7 +146,7 @@ public class TestCheckpointUtils {
// Only partition 0 exists in both: 150-100 = 50
// Partition 1 ignored (not in current)
- long diff = CheckpointUtils.calculateOffsetDifference(
+ long diff = KafkaCheckpointUtils.calculateOffsetDifference(
CheckpointFormat.SPARK_KAFKA, previous, current);
assertEquals(50L, diff);
}
@@ -159,7 +159,7 @@ public class TestCheckpointUtils {
// When current < previous (offset reset), partition is skipped
// to avoid overcounting since start offset is unknown
- long diff = CheckpointUtils.calculateOffsetDifference(
+ long diff = KafkaCheckpointUtils.calculateOffsetDifference(
CheckpointFormat.SPARK_KAFKA, previous, current);
assertEquals(0L, diff);
}
@@ -172,29 +172,29 @@ public class TestCheckpointUtils {
// Partition 0: reset, skipped to avoid overcounting
// Partition 1: normal increment = 2500-2000 = 500
// Total: 500
- long diff = CheckpointUtils.calculateOffsetDifference(
+ long diff = KafkaCheckpointUtils.calculateOffsetDifference(
CheckpointFormat.SPARK_KAFKA, previous, current);
assertEquals(500L, diff);
}
@Test
public void testIsValidCheckpointFormat() {
- assertTrue(CheckpointUtils.isValidCheckpointFormat(
+ assertTrue(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.SPARK_KAFKA, "topic,0:100"));
- assertTrue(CheckpointUtils.isValidCheckpointFormat(
+ assertTrue(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.SPARK_KAFKA, "topic,0:100,1:200,2:300"));
- assertTrue(CheckpointUtils.isValidCheckpointFormat(
+ assertTrue(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.SPARK_KAFKA, "my.topic.name,0:1000"));
- assertFalse(CheckpointUtils.isValidCheckpointFormat(
+ assertFalse(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.SPARK_KAFKA, ""));
- assertFalse(CheckpointUtils.isValidCheckpointFormat(
+ assertFalse(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.SPARK_KAFKA, null));
- assertFalse(CheckpointUtils.isValidCheckpointFormat(
+ assertFalse(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.SPARK_KAFKA, "just_topic"));
- assertFalse(CheckpointUtils.isValidCheckpointFormat(
+ assertFalse(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.SPARK_KAFKA, "topic,invalid"));
- assertFalse(CheckpointUtils.isValidCheckpointFormat(
+ assertFalse(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.SPARK_KAFKA, "topic,0:abc"));
}
@@ -202,17 +202,17 @@ public class TestCheckpointUtils {
public void testUnsupportedFormats() {
// Pulsar format not yet implemented (Phase 4)
assertThrows(UnsupportedOperationException.class, () ->
- CheckpointUtils.parseCheckpoint(CheckpointFormat.PULSAR, "anystring"));
+ KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.PULSAR, "anystring"));
// Kinesis format not yet implemented (Phase 4)
assertThrows(UnsupportedOperationException.class, () ->
- CheckpointUtils.parseCheckpoint(CheckpointFormat.KINESIS, "anystring"));
+ KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.KINESIS, "anystring"));
}
@Test
public void testFlinkKafkaCheckpointParsing() {
// Flink Kafka format is now implemented (Phase 2)
- Map<Integer, Long> result = CheckpointUtils.parseCheckpoint(
+ Map<Integer, Long> result = KafkaCheckpointUtils.parseCheckpoint(
CheckpointFormat.FLINK_KAFKA,
"kafka_metadata%3Aevents%3A0:100;kafka_metadata%3Aevents%3A1:200");
assertEquals(2, result.size());
@@ -223,24 +223,24 @@ public class TestCheckpointUtils {
@Test
public void testCustomFormatThrows() {
assertThrows(IllegalArgumentException.class, () ->
- CheckpointUtils.parseCheckpoint(CheckpointFormat.CUSTOM, "anystring"));
+ KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.CUSTOM, "anystring"));
}
@Test
public void testIsValidCheckpointFormatUnsupported() {
// Unsupported formats should return false (caught internally)
- assertFalse(CheckpointUtils.isValidCheckpointFormat(
+ assertFalse(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.CUSTOM, "anystring"));
}
@Test
public void testIsValidCheckpointFormatFlinkKafka() {
// Flink Kafka format is now supported (Phase 2)
- assertTrue(CheckpointUtils.isValidCheckpointFormat(
+ assertTrue(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.FLINK_KAFKA,
"kafka_metadata%3Aevents%3A0:100;kafka_metadata%3Aevents%3A1:200"));
// Invalid Flink checkpoint should return false
- assertFalse(CheckpointUtils.isValidCheckpointFormat(
+ assertFalse(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.FLINK_KAFKA, ""));
}
}
diff --git a/hudi-common/src/test/java/org/apache/hudi/common/util/TestTableServiceUtils.java b/hudi-common/src/test/java/org/apache/hudi/common/util/TestTableServiceUtils.java
index 5f0b19e38032..889224b5dd84 100644
--- a/hudi-common/src/test/java/org/apache/hudi/common/util/TestTableServiceUtils.java
+++ b/hudi-common/src/test/java/org/apache/hudi/common/util/TestTableServiceUtils.java
@@ -73,17 +73,4 @@ public class TestTableServiceUtils {
assertFalse(TableServiceUtils.isStale(startTimeMs, maxProcessingTimeMs, currentTimeMs));
}
}
-
- @Test
- public void testIsStaleWithCurrentTime() {
- // Test the method that uses System.currentTimeMillis()
- long maxProcessingTimeMs = 60000L; // 1 minute
- // Using a start time far in the past should be stale
- long pastStartTime = System.currentTimeMillis() - 120000L; // 2 minutes ago
- assertTrue(TableServiceUtils.isStale(pastStartTime, maxProcessingTimeMs));
-
- // Using a start time very recently should not be stale
- long recentStartTime = System.currentTimeMillis() - 10000L; // 10 seconds ago
- assertFalse(TableServiceUtils.isStale(recentStartTime, maxProcessingTimeMs));
- }
}
diff --git a/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/clustering/ClusteringOperator.java b/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/clustering/ClusteringOperator.java
index 7cd952289c8f..b3763e115a4c 100644
--- a/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/clustering/ClusteringOperator.java
+++ b/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/clustering/ClusteringOperator.java
@@ -43,7 +43,7 @@ import org.apache.hudi.configuration.OptionsResolver;
import org.apache.hudi.core.io.storage.HoodieFileReaderFactory;
import org.apache.hudi.core.io.storage.HoodieIOFactory;
import org.apache.hudi.exception.HoodieClusteringException;
-import org.apache.hudi.io.IOUtils;
+import org.apache.hudi.io.MergeUtils;
import org.apache.hudi.metrics.FlinkClusteringMetrics;
import org.apache.hudi.sink.bulk.BulkInsertWriterHelper;
import org.apache.hudi.sink.bulk.sort.SortOperatorGen;
@@ -274,7 +274,7 @@ public class ClusteringOperator extends TableStreamOperator<ClusteringCommitEven
@SuppressWarnings("unchecked")
private Iterator<RowData> readRecordsForGroupWithLogs(List<ClusteringOperation> clusteringOps, String instantTime) {
List<ClosableIterator<RowData>> recordIterators = new ArrayList<>();
- long maxMemoryPerCompaction = IOUtils.getMaxMemoryPerCompaction(new FlinkTaskContextSupplier(null), writeConfig);
+ long maxMemoryPerCompaction = MergeUtils.getMaxMemoryPerCompaction(new FlinkTaskContextSupplier(null), writeConfig);
log.info("MaxMemoryPerCompaction run as part of clustering => {}", maxMemoryPerCompaction);
for (ClusteringOperation clusteringOp : clusteringOps) {
diff --git a/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/validator/FlinkKafkaOffsetValidator.java b/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/validator/FlinkKafkaOffsetValidator.java
index 88c9a4a6f877..b3376a2d3b24 100644
--- a/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/validator/FlinkKafkaOffsetValidator.java
+++ b/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/validator/FlinkKafkaOffsetValidator.java
@@ -21,7 +21,7 @@ package org.apache.hudi.sink.validator;
import org.apache.hudi.client.validator.StreamingOffsetValidator;
import org.apache.hudi.common.config.TypedProperties;
-import org.apache.hudi.common.util.CheckpointUtils.CheckpointFormat;
+import org.apache.hudi.common.util.KafkaCheckpointUtils.CheckpointFormat;
import org.apache.hudi.util.StreamerUtil;
/**
diff --git a/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/validator/TestFlinkKafkaCheckpointParsing.java b/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/validator/TestFlinkKafkaCheckpointParsing.java
index 24140289114a..18d112289453 100644
--- a/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/validator/TestFlinkKafkaCheckpointParsing.java
+++ b/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/validator/TestFlinkKafkaCheckpointParsing.java
@@ -19,8 +19,8 @@
package org.apache.hudi.sink.validator;
-import org.apache.hudi.common.util.CheckpointUtils;
-import org.apache.hudi.common.util.CheckpointUtils.CheckpointFormat;
+import org.apache.hudi.common.util.KafkaCheckpointUtils;
+import org.apache.hudi.common.util.KafkaCheckpointUtils.CheckpointFormat;
import org.junit.jupiter.api.Test;
@@ -32,14 +32,14 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
- * Tests for Flink Kafka checkpoint parsing in {@link CheckpointUtils}.
+ * Tests for Flink Kafka checkpoint parsing in {@link KafkaCheckpointUtils}.
*/
public class TestFlinkKafkaCheckpointParsing {
@Test
public void testParseSinglePartition() {
String checkpoint = "kafka_metadata%3Aevents%3A0:1000";
- Map<Integer, Long> offsets = CheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, checkpoint);
+ Map<Integer, Long> offsets = KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, checkpoint);
assertEquals(1, offsets.size());
assertEquals(1000L, offsets.get(0));
}
@@ -47,7 +47,7 @@ public class TestFlinkKafkaCheckpointParsing {
@Test
public void testParseMultiplePartitions() {
String checkpoint = "kafka_metadata%3Aevents%3A0:100;kafka_metadata%3Aevents%3A1:200;kafka_metadata%3Aevents%3A2:300";
- Map<Integer, Long> offsets = CheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, checkpoint);
+ Map<Integer, Long> offsets = KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, checkpoint);
assertEquals(3, offsets.size());
assertEquals(100L, offsets.get(0));
assertEquals(200L, offsets.get(1));
@@ -59,7 +59,7 @@ public class TestFlinkKafkaCheckpointParsing {
// Cluster metadata entry should be skipped (not a partition offset)
String checkpoint = "kafka_metadata%3Aevents%3A0:100;kafka_metadata%3Aevents%3A1:200"
+ ";kafka_metadata%3Akafka_cluster%3Aevents%3A:my-cluster";
- Map<Integer, Long> offsets = CheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, checkpoint);
+ Map<Integer, Long> offsets = KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, checkpoint);
assertEquals(2, offsets.size());
assertEquals(100L, offsets.get(0));
assertEquals(200L, offsets.get(1));
@@ -70,7 +70,7 @@ public class TestFlinkKafkaCheckpointParsing {
String prev = "kafka_metadata%3Aevents%3A0:100;kafka_metadata%3Aevents%3A1:200";
String curr = "kafka_metadata%3Aevents%3A0:300;kafka_metadata%3Aevents%3A1:500";
// Diff = (300-100) + (500-200) = 200 + 300 = 500
- long diff = CheckpointUtils.calculateOffsetDifference(CheckpointFormat.FLINK_KAFKA, prev, curr);
+ long diff = KafkaCheckpointUtils.calculateOffsetDifference(CheckpointFormat.FLINK_KAFKA, prev, curr);
assertEquals(500L, diff);
}
@@ -78,20 +78,20 @@ public class TestFlinkKafkaCheckpointParsing {
public void testCalculateOffsetDifferenceWithClusterMetadata() {
String prev = "kafka_metadata%3Aevents%3A0:100;kafka_metadata%3Akafka_cluster%3Aevents%3A:cluster1";
String curr = "kafka_metadata%3Aevents%3A0:200;kafka_metadata%3Akafka_cluster%3Aevents%3A:cluster1";
- long diff = CheckpointUtils.calculateOffsetDifference(CheckpointFormat.FLINK_KAFKA, prev, curr);
+ long diff = KafkaCheckpointUtils.calculateOffsetDifference(CheckpointFormat.FLINK_KAFKA, prev, curr);
assertEquals(100L, diff);
}
@Test
public void testIsValidFormat() {
- assertTrue(CheckpointUtils.isValidCheckpointFormat(
+ assertTrue(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.FLINK_KAFKA, "kafka_metadata%3Aevents%3A0:100"));
- assertFalse(CheckpointUtils.isValidCheckpointFormat(
+ assertFalse(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.FLINK_KAFKA, ""));
- assertFalse(CheckpointUtils.isValidCheckpointFormat(
+ assertFalse(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.FLINK_KAFKA, null));
// "invalid-format" is parsed without error (entries silently skipped), so it's "valid" format
- assertTrue(CheckpointUtils.isValidCheckpointFormat(
+ assertTrue(KafkaCheckpointUtils.isValidCheckpointFormat(
CheckpointFormat.FLINK_KAFKA, "invalid-format"));
}
@@ -99,7 +99,7 @@ public class TestFlinkKafkaCheckpointParsing {
public void testParseWithNoOffsets() {
// Only cluster metadata, no partition offsets
String checkpoint = "kafka_metadata%3Akafka_cluster%3Aevents%3A:my-cluster";
- Map<Integer, Long> offsets = CheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, checkpoint);
+ Map<Integer, Long> offsets = KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, checkpoint);
assertEquals(0, offsets.size());
}
@@ -109,14 +109,14 @@ public class TestFlinkKafkaCheckpointParsing {
String prev = "kafka_metadata%3Aevents%3A0:500;kafka_metadata%3Aevents%3A1:100";
String curr = "kafka_metadata%3Aevents%3A0:200;kafka_metadata%3Aevents%3A1:300";
// Partition 0: 200-500 = -300 (skipped). Partition 1: 300-100 = 200.
- long diff = CheckpointUtils.calculateOffsetDifference(CheckpointFormat.FLINK_KAFKA, prev, curr);
+ long diff = KafkaCheckpointUtils.calculateOffsetDifference(CheckpointFormat.FLINK_KAFKA, prev, curr);
assertEquals(200L, diff);
}
@Test
public void testParseInvalidFormatReturnsEmpty() {
// Missing %3A separators — entry is silently skipped (consistent with production parser)
- Map<Integer, Long> offsets = CheckpointUtils.parseCheckpoint(
+ Map<Integer, Long> offsets = KafkaCheckpointUtils.parseCheckpoint(
CheckpointFormat.FLINK_KAFKA, "invalid-no-separators");
assertEquals(0, offsets.size());
}
@@ -124,20 +124,20 @@ public class TestFlinkKafkaCheckpointParsing {
@Test
public void testParseNullThrows() {
assertThrows(IllegalArgumentException.class,
- () -> CheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, null));
+ () -> KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, null));
}
@Test
public void testParseEmptyStringThrows() {
assertThrows(IllegalArgumentException.class,
- () -> CheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, ""));
+ () -> KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, ""));
}
@Test
public void testParseWithEmptySemicolonEntries() {
// Extra semicolons should be handled gracefully
String checkpoint = ";kafka_metadata%3Aevents%3A0:100;;kafka_metadata%3Aevents%3A1:200;";
- Map<Integer, Long> offsets = CheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, checkpoint);
+ Map<Integer, Long> offsets = KafkaCheckpointUtils.parseCheckpoint(CheckpointFormat.FLINK_KAFKA, checkpoint);
assertEquals(2, offsets.size());
assertEquals(100L, offsets.get(0));
assertEquals(200L, offsets.get(1));
@@ -146,7 +146,7 @@ public class TestFlinkKafkaCheckpointParsing {
@Test
public void testZeroOffsetDifference() {
String checkpoint = "kafka_metadata%3Aevents%3A0:100;kafka_metadata%3Aevents%3A1:200";
- long diff = CheckpointUtils.calculateOffsetDifference(CheckpointFormat.FLINK_KAFKA, checkpoint, checkpoint);
+ long diff = KafkaCheckpointUtils.calculateOffsetDifference(CheckpointFormat.FLINK_KAFKA, checkpoint, checkpoint);
assertEquals(0L, diff);
}
@@ -155,7 +155,7 @@ public class TestFlinkKafkaCheckpointParsing {
// Test with large offset values to ensure no overflow
String prev = "kafka_metadata%3Aevents%3A0:" + Long.MAX_VALUE / 2;
String curr = "kafka_metadata%3Aevents%3A0:" + (Long.MAX_VALUE / 2 + 1000);
- long diff = CheckpointUtils.calculateOffsetDifference(CheckpointFormat.FLINK_KAFKA, prev, curr);
+ long diff = KafkaCheckpointUtils.calculateOffsetDifference(CheckpointFormat.FLINK_KAFKA, prev, curr);
assertEquals(1000L, diff);
}
@@ -165,7 +165,7 @@ public class TestFlinkKafkaCheckpointParsing {
String prev = "kafka_metadata%3Aevents%3A0:100";
String curr = "kafka_metadata%3Aevents%3A0:200;kafka_metadata%3Aevents%3A1:50";
// Only partition 0 diff counted: 200-100 = 100. Partition 1 skipped (new).
- long diff = CheckpointUtils.calculateOffsetDifference(CheckpointFormat.FLINK_KAFKA, prev, curr);
+ long diff = KafkaCheckpointUtils.calculateOffsetDifference(CheckpointFormat.FLINK_KAFKA, prev, curr);
assertEquals(100L, diff);
}
}
diff --git a/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/HadoopConfigUtils.java b/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/HadoopConfigUtils.java
index 021aecc4e705..18ec7641b56a 100644
--- a/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/HadoopConfigUtils.java
+++ b/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/HadoopConfigUtils.java
@@ -21,7 +21,6 @@ package org.apache.hudi.common.util;
import org.apache.hudi.common.config.ConfigProperty;
-import lombok.extern.slf4j.Slf4j;
import org.apache.hadoop.conf.Configuration;
import java.util.Properties;
@@ -29,7 +28,6 @@ import java.util.Properties;
/**
* Utils on Hadoop {@link Configuration}.
*/
-@Slf4j
public class HadoopConfigUtils {
/**
@@ -54,36 +52,6 @@ public class HadoopConfigUtils {
*/
public static Option<String> getRawValueWithAltKeys(Configuration conf,
ConfigProperty<?> configProperty) {
- String value = conf.get(configProperty.key());
- if (value != null) {
- return Option.of(value);
- }
- for (String alternative : configProperty.getAlternatives()) {
- String altValue = conf.get(alternative);
- if (altValue != null) {
- log.warn("The configuration key '{}' has been deprecated "
- + "and may be removed in the future. Please use the new key '{}' instead.",
- alternative, configProperty.key());
- return Option.of(altValue);
- }
- }
- return Option.empty();
- }
-
- /**
- * Gets the boolean value for a {@link ConfigProperty} config from Hadoop configuration. The key and
- * alternative keys are used to fetch the config. The default value of {@link ConfigProperty}
- * config, if exists, is returned if the config is not found in the configuration.
- *
- * @param conf Configs in Hadoop {@link Configuration}.
- * @param configProperty {@link ConfigProperty} config to fetch.
- * @return boolean value if the config exists; default boolean value if the config does not exist
- * and there is default value defined in the {@link ConfigProperty} config; {@code false} otherwise.
- */
- public static boolean getBooleanWithAltKeys(Configuration conf,
- ConfigProperty<?> configProperty) {
- Option<String> rawValue = getRawValueWithAltKeys(conf, configProperty);
- boolean defaultValue = configProperty.hasDefaultValue() && Boolean.parseBoolean(configProperty.defaultValue().toString());
- return rawValue.map(Boolean::parseBoolean).orElse(defaultValue);
+ return ConfigUtils.getRawValueWithAltKeys(conf::get, configProperty).map(Object::toString);
}
}
diff --git a/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/LanceUtils.java b/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/LanceUtils.java
index e247a64499a2..1d1aff2de610 100644
--- a/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/LanceUtils.java
+++ b/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/LanceUtils.java
@@ -52,31 +52,9 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
public class LanceUtils extends FileFormatUtils {
- @Override
- public ClosableIterator<Pair<HoodieKey, Long>> fetchRecordKeysWithPositions(HoodieStorage storage, StoragePath filePath) {
- return fetchRecordKeysWithPositions(storage, filePath, Option.empty(), Option.empty());
- }
-
- @Override
- public ClosableIterator<Pair<HoodieKey, Long>> fetchRecordKeysWithPositions(HoodieStorage storage,
- StoragePath filePath,
- Option<BaseKeyGenerator> keyGeneratorOpt,
- Option<String> partitionPath) {
- AtomicLong position = new AtomicLong(0);
- return new CloseableMappingIterator<>(
- getHoodieKeyIterator(storage, filePath, keyGeneratorOpt, partitionPath),
- key -> Pair.of(key, position.getAndIncrement()));
- }
-
- @Override
- public ClosableIterator<HoodieKey> getHoodieKeyIterator(HoodieStorage storage, StoragePath filePath) {
- return getHoodieKeyIterator(storage, filePath, Option.empty(), Option.empty());
- }
-
@Override
public ClosableIterator<HoodieKey> getHoodieKeyIterator(HoodieStorage storage,
StoragePath filePath,
diff --git a/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/OrcUtils.java b/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/OrcUtils.java
index fd0bbde4a4c9..b8abcde4eb32 100644
--- a/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/OrcUtils.java
+++ b/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/OrcUtils.java
@@ -75,18 +75,6 @@ import static org.apache.hudi.hadoop.fs.HadoopFSUtils.convertToHadoopPath;
*/
public class OrcUtils extends FileFormatUtils {
- /**
- * Provides a closable iterator for reading the given ORC file.
- *
- * @param storage {@link HoodieStorage} instance.
- * @param filePath The ORC file path
- * @return {@link ClosableIterator} of {@link HoodieKey}s for reading the ORC file
- */
- @Override
- public ClosableIterator<HoodieKey> getHoodieKeyIterator(HoodieStorage storage, StoragePath filePath) {
- return getHoodieKeyIterator(storage, filePath, Option.empty(), Option.empty());
- }
-
/**
* Fetch {@link HoodieKey}s from the given ORC file.
*
@@ -94,11 +82,6 @@ public class OrcUtils extends FileFormatUtils {
* @param filePath The ORC file path.
* @return {@link List} of {@link HoodieKey}s fetched from the ORC file
*/
- @Override
- public ClosableIterator<Pair<HoodieKey, Long>> fetchRecordKeysWithPositions(HoodieStorage storage, StoragePath filePath) {
- return fetchRecordKeysWithPositions(storage, filePath, Option.empty(), Option.empty());
- }
-
@Override
public ClosableIterator<Pair<HoodieKey, Long>> fetchRecordKeysWithPositions(HoodieStorage storage, StoragePath filePath, Option<BaseKeyGenerator> keyGeneratorOpt, Option<String> partitionPath) {
try {
diff --git a/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/ParquetUtils.java b/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/ParquetUtils.java
index 820756b1d1e6..835a8c2edf4c 100644
--- a/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/ParquetUtils.java
+++ b/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/ParquetUtils.java
@@ -28,7 +28,6 @@ import org.apache.hudi.common.model.HoodieRecord.HoodieRecordType;
import org.apache.hudi.common.schema.HoodieSchema;
import org.apache.hudi.common.schema.HoodieSchemaUtils;
import org.apache.hudi.common.util.collection.ClosableIterator;
-import org.apache.hudi.common.util.collection.CloseableMappingIterator;
import org.apache.hudi.common.util.collection.Pair;
import org.apache.hudi.core.io.storage.HoodieFileWriter;
import org.apache.hudi.core.io.storage.HoodieFileWriterFactory;
@@ -77,7 +76,6 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -182,23 +180,6 @@ public class ParquetUtils extends FileFormatUtils {
return CompressionCodecName.fromConf(StringUtils.isNullOrEmpty(codecName) ? null : codecName);
}
- /**
- * Fetch {@link HoodieKey}s with row positions from the given parquet file.
- *
- * @param storage {@link HoodieStorage} instance.
- * @param filePath The parquet file path.
- * @return {@link List} of pairs of {@link HoodieKey} and row position fetched from the parquet file
- */
- @Override
- public ClosableIterator<Pair<HoodieKey, Long>> fetchRecordKeysWithPositions(HoodieStorage storage, StoragePath filePath) {
- return fetchRecordKeysWithPositions(storage, filePath, Option.empty(), Option.empty());
- }
-
- @Override
- public ClosableIterator<HoodieKey> getHoodieKeyIterator(HoodieStorage storage, StoragePath filePath) {
- return getHoodieKeyIterator(storage, filePath, Option.empty(), Option.empty());
- }
-
/**
* Returns a closable iterator for reading the given parquet file.
*
@@ -233,12 +214,6 @@ public class ParquetUtils extends FileFormatUtils {
* @param partitionPath optional partition path for the file, if provided only the record key is read from the file
* @return {@link List} of pairs of {@link HoodieKey} and row position fetched from the parquet file
*/
- @Override
- public ClosableIterator<Pair<HoodieKey, Long>> fetchRecordKeysWithPositions(HoodieStorage storage, StoragePath filePath, Option<BaseKeyGenerator> keyGeneratorOpt, Option<String> partitionPath) {
- AtomicLong position = new AtomicLong(0);
- return new CloseableMappingIterator<>(getHoodieKeyIterator(storage, filePath, keyGeneratorOpt, partitionPath), key -> Pair.of(key, position.getAndIncrement()));
- }
-
/**
* Get the schema of the given parquet file.
*/
diff --git a/hudi-hadoop-common/src/main/java/org/apache/hudi/hadoop/fs/HadoopFSUtils.java b/hudi-hadoop-common/src/main/java/org/apache/hudi/hadoop/fs/HadoopFSUtils.java
index 00708a5e97ec..e16765780314 100644
--- a/hudi-hadoop-common/src/main/java/org/apache/hudi/hadoop/fs/HadoopFSUtils.java
+++ b/hudi-hadoop-common/src/main/java/org/apache/hudi/hadoop/fs/HadoopFSUtils.java
@@ -24,7 +24,6 @@ import org.apache.hudi.avro.model.HoodieFileStatus;
import org.apache.hudi.avro.model.HoodiePath;
import org.apache.hudi.common.engine.HoodieEngineContext;
import org.apache.hudi.common.fs.FSUtils;
-import org.apache.hudi.common.model.HoodieFileFormat;
import org.apache.hudi.common.util.collection.ImmutablePair;
import org.apache.hudi.common.util.collection.Pair;
import org.apache.hudi.exception.HoodieIOException;
@@ -51,10 +50,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -377,10 +374,6 @@ public class HadoopFSUtils {
}
}
- public static long getFileSize(FileSystem fs, Path path) throws IOException {
- return fs.getFileStatus(path).getLen();
- }
-
/**
* Given a base partition and a partition path, return relative path of partition path to the base path.
*/
@@ -403,16 +396,6 @@ public class HadoopFSUtils {
return FSUtils.getDeltaCommitTimeFromLogPath(new StoragePath(path.toUri()));
}
- /**
- * Check if the file is a base file of a log file. Then get the fileId appropriately.
- */
- public static String getFileIdFromFilePath(Path filePath) {
- if (isLogFile(filePath)) {
- return getFileIdFromLogPath(filePath);
- }
- return FSUtils.getFileId(filePath.getName());
- }
-
public static boolean isBaseFile(Path path) {
return FSUtils.isBaseFile(new StoragePath(path.toUri()));
}
@@ -428,29 +411,6 @@ public class HadoopFSUtils {
return isBaseFile(path) || isLogFile(path);
}
- /**
- * Get the names of all the base and log files in the given partition path.
- */
- public static FileStatus[] getAllDataFilesInPartition(FileSystem fs, Path partitionPath) throws IOException {
- final Set<String> validFileExtensions = Arrays.stream(HoodieFileFormat.values())
- .map(HoodieFileFormat::getFileExtension).collect(Collectors.toCollection(HashSet::new));
- final String logFileExtension = HoodieFileFormat.HOODIE_LOG.getFileExtension();
-
- try {
- return Arrays.stream(fs.listStatus(partitionPath, path -> {
- String extension = FSUtils.getFileExtension(path.getName());
- return validFileExtensions.contains(extension) || path.getName().contains(logFileExtension);
- })).filter(FileStatus::isFile).toArray(FileStatus[]::new);
- } catch (IOException e) {
- // return empty FileStatus if partition does not exist already
- if (!fs.exists(partitionPath)) {
- return new FileStatus[0];
- } else {
- throw e;
- }
- }
- }
-
/**
* When a file was opened and the task died without closing the stream, another task executor cannot open because the
* existing lease will be active. We will try to recover the lease, from HDFS. If a data node went down, it takes
diff --git a/hudi-hadoop-common/src/main/java/org/apache/hudi/hadoop/fs/inline/HadoopInLineFSUtils.java b/hudi-hadoop-common/src/main/java/org/apache/hudi/hadoop/fs/inline/HadoopInLineFSUtils.java
deleted file mode 100644
index ba252ef45ba0..000000000000
--- a/hudi-hadoop-common/src/main/java/org/apache/hudi/hadoop/fs/inline/HadoopInLineFSUtils.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.hadoop.fs.inline;
-
-import org.apache.hudi.storage.StorageConfiguration;
-import org.apache.hudi.storage.StoragePath;
-import org.apache.hudi.storage.inline.InLineFSUtils;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.Path;
-
-import static org.apache.hudi.hadoop.fs.HadoopFSUtils.convertToHadoopPath;
-import static org.apache.hudi.hadoop.fs.HadoopFSUtils.convertToStoragePath;
-
-/**
- * Utils to parse InLineFileSystem paths.
- * Inline FS format:
- * "inlinefs://<path_to_outer_file>/<outer_file_scheme>/?start_offset=start_offset>&length=<length>"
- * Eg: "inlinefs://<path_to_outer_file>/s3a/?start_offset=20&length=40"
- */
-public class HadoopInLineFSUtils extends InLineFSUtils {
-
- public static StorageConfiguration<Configuration> buildInlineConf(StorageConfiguration<Configuration> storageConf) {
- StorageConfiguration<Configuration> inlineConf = storageConf.newInstance();
- inlineConf.set("fs." + InLineFileSystem.SCHEME + ".impl", InLineFileSystem.class.getName());
- (inlineConf.unwrapAs(Configuration.class)).setClassLoader(InLineFileSystem.class.getClassLoader());
- return inlineConf;
- }
-
- /**
- * InlineFS Path format:
- * "inlinefs://path/to/outer/file/outer_file_scheme/?start_offset=start_offset>&length=<length>"
- * <p>
- * Outer File Path format:
- * "outer_file_scheme://path/to/outer/file"
- * <p>
- * Example
- * Input: "inlinefs://file1/s3a/?start_offset=20&length=40".
- * Output: "s3a://file1"
- *
- * @param inlineFSPath InLineFS Path to get the outer file Path
- * @return Outer file Path from the InLineFS Path
- */
- public static Path getOuterFilePathFromInlinePath(Path inlineFSPath) {
- StoragePath storagePath = convertToStoragePath(inlineFSPath);
- StoragePath outerFilePath = getOuterFilePathFromInlinePath(storagePath);
- return convertToHadoopPath(outerFilePath);
- }
-}
diff --git a/hudi-hadoop-common/src/main/java/org/apache/hudi/hadoop/fs/inline/InLineFileSystem.java b/hudi-hadoop-common/src/main/java/org/apache/hudi/hadoop/fs/inline/InLineFileSystem.java
index dab1bc9f90e3..8a3ca5d110c6 100644
--- a/hudi-hadoop-common/src/main/java/org/apache/hudi/hadoop/fs/inline/InLineFileSystem.java
+++ b/hudi-hadoop-common/src/main/java/org/apache/hudi/hadoop/fs/inline/InLineFileSystem.java
@@ -34,6 +34,7 @@ import org.apache.hadoop.util.Progressable;
import java.io.IOException;
import java.net.URI;
+import static org.apache.hudi.hadoop.fs.HadoopFSUtils.convertToHadoopPath;
import static org.apache.hudi.hadoop.fs.HadoopFSUtils.convertToStoragePath;
/**
@@ -93,11 +94,11 @@ public class InLineFileSystem extends FileSystem {
@Override
public FSDataInputStream open(Path inlinePath, int bufferSize) throws IOException {
- Path outerPath = HadoopInLineFSUtils.getOuterFilePathFromInlinePath(inlinePath);
+ Path outerPath = getOuterFilePath(inlinePath);
FileSystem outerFs = outerPath.getFileSystem(conf);
FSDataInputStream outerStream = outerFs.open(outerPath, bufferSize);
StoragePath inlineStoragePath = convertToStoragePath(inlinePath);
- return new InLineFsDataInputStream(HadoopInLineFSUtils.startOffset(inlineStoragePath), outerStream, HadoopInLineFSUtils.length(inlineStoragePath));
+ return new InLineFsDataInputStream(InLineFSUtils.startOffset(inlineStoragePath), outerStream, InLineFSUtils.length(inlineStoragePath));
}
@Override
@@ -111,10 +112,10 @@ public class InLineFileSystem extends FileSystem {
@Override
public FileStatus getFileStatus(Path inlinePath) throws IOException {
- Path outerPath = HadoopInLineFSUtils.getOuterFilePathFromInlinePath(inlinePath);
+ Path outerPath = getOuterFilePath(inlinePath);
FileSystem outerFs = outerPath.getFileSystem(conf);
FileStatus status = outerFs.getFileStatus(outerPath);
- FileStatus toReturn = new FileStatus(HadoopInLineFSUtils.length(convertToStoragePath(inlinePath)), status.isDirectory(), status.getReplication(), status.getBlockSize(),
+ FileStatus toReturn = new FileStatus(InLineFSUtils.length(convertToStoragePath(inlinePath)), status.isDirectory(), status.getReplication(), status.getBlockSize(),
status.getModificationTime(), status.getAccessTime(), status.getPermission(), status.getOwner(),
status.getGroup(), inlinePath);
return toReturn;
@@ -160,4 +161,8 @@ public class InLineFileSystem extends FileSystem {
public boolean mkdirs(Path path, FsPermission fsPermission) throws IOException {
throw new UnsupportedOperationException("Can't set working directory");
}
+
+ private static Path getOuterFilePath(Path inlineFSPath) {
+ return convertToHadoopPath(InLineFSUtils.getOuterFilePathFromInlinePath(convertToStoragePath(inlineFSPath)));
+ }
}
\ No newline at end of file
diff --git a/hudi-hadoop-common/src/main/java/org/apache/hudi/io/storage/hadoop/HoodieVariantReconstruction.java b/hudi-hadoop-common/src/main/java/org/apache/hudi/io/storage/hadoop/HoodieVariantReconstruction.java
index 381ac11b3914..25da535e0187 100644
--- a/hudi-hadoop-common/src/main/java/org/apache/hudi/io/storage/hadoop/HoodieVariantReconstruction.java
+++ b/hudi-hadoop-common/src/main/java/org/apache/hudi/io/storage/hadoop/HoodieVariantReconstruction.java
@@ -146,8 +146,8 @@ final class HoodieVariantReconstruction {
Schema[] unshreddedSubSchemas = new Schema[requestedFields.size()];
for (int i = 0; i < requestedFields.size(); i++) {
if (isTarget[i]) {
- shreddedSubSchemas[i] = unwrapNullable(fileSchema.getField(requestedFields.get(i).name()).get().schema()).getAvroSchema();
- unshreddedSubSchemas[i] = unwrapNullable(outputSchema.getFields().get(i).schema()).getAvroSchema();
+ shreddedSubSchemas[i] = fileSchema.getField(requestedFields.get(i).name()).get().schema().getNonNullType().getAvroSchema();
+ unshreddedSubSchemas[i] = outputSchema.getFields().get(i).schema().getNonNullType().getAvroSchema();
}
}
@@ -174,15 +174,11 @@ final class HoodieVariantReconstruction {
}
private static boolean isShreddedVariant(HoodieSchema schema) {
- HoodieSchema unwrapped = unwrapNullable(schema);
+ HoodieSchema unwrapped = schema.getNonNullType();
return unwrapped.getType() == HoodieSchemaType.VARIANT
&& ((HoodieSchema.Variant) unwrapped).isShredded();
}
- private static HoodieSchema unwrapNullable(HoodieSchema schema) {
- return schema.isNullable() ? schema.getNonNullType() : schema;
- }
-
private static VariantShreddingProvider loadProvider(HoodieStorage storage) {
String providerClass = storage.getConf()
.getString(HoodieStorageConfig.PARQUET_VARIANT_SHREDDING_PROVIDER_CLASS.key()).orElse(null);
diff --git a/hudi-hadoop-common/src/main/java/org/apache/hudi/storage/hadoop/HadoopStorageConfiguration.java b/hudi-hadoop-common/src/main/java/org/apache/hudi/storage/hadoop/HadoopStorageConfiguration.java
index ed7b24052472..42096c94fd1c 100644
--- a/hudi-hadoop-common/src/main/java/org/apache/hudi/storage/hadoop/HadoopStorageConfiguration.java
+++ b/hudi-hadoop-common/src/main/java/org/apache/hudi/storage/hadoop/HadoopStorageConfiguration.java
@@ -20,7 +20,7 @@
package org.apache.hudi.storage.hadoop;
import org.apache.hudi.common.util.Option;
-import org.apache.hudi.hadoop.fs.inline.HadoopInLineFSUtils;
+import org.apache.hudi.hadoop.fs.inline.InLineFileSystem;
import org.apache.hudi.storage.StorageConfiguration;
import org.apache.hadoop.conf.Configuration;
@@ -85,7 +85,12 @@ public class HadoopStorageConfiguration extends StorageConfiguration<Configurati
@Override
public StorageConfiguration<Configuration> getInline() {
- return HadoopInLineFSUtils.buildInlineConf(this);
+ // newInstance() copies this object's underlying Configuration, so caller-supplied
+ // configs (e.g. S3 credentials) carry over into the inline conf
+ StorageConfiguration<Configuration> inlineConf = newInstance();
+ inlineConf.set("fs." + InLineFileSystem.SCHEME + ".impl", InLineFileSystem.class.getName());
+ inlineConf.unwrapAs(Configuration.class).setClassLoader(InLineFileSystem.class.getClassLoader());
+ return inlineConf;
}
@Override
diff --git a/hudi-hadoop-common/src/test/java/org/apache/hudi/common/fs/TestFSUtils.java b/hudi-hadoop-common/src/test/java/org/apache/hudi/common/fs/TestFSUtils.java
index 7a3a5c2a9567..b876377b9508 100644
--- a/hudi-hadoop-common/src/test/java/org/apache/hudi/common/fs/TestFSUtils.java
+++ b/hudi-hadoop-common/src/test/java/org/apache/hudi/common/fs/TestFSUtils.java
@@ -34,9 +34,9 @@ import org.apache.hudi.exception.HoodieIOException;
import org.apache.hudi.exception.HoodieValidationException;
import org.apache.hudi.hadoop.fs.HadoopFSUtils;
import org.apache.hudi.hadoop.fs.HoodieWrapperFileSystem;
-import org.apache.hudi.hadoop.fs.inline.HadoopInLineFSUtils;
import org.apache.hudi.storage.HoodieStorage;
import org.apache.hudi.storage.StoragePath;
+import org.apache.hudi.storage.inline.InLineFSUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
@@ -323,7 +323,7 @@ public class TestFSUtils extends HoodieCommonTestHarness {
String fileName = UUID.randomUUID().toString();
String logFile = FSUtils.makeInlineLogFileName(fileName, ".log", "100", 2, "1-0-1");
StoragePath rlPath = new StoragePath(new StoragePath(partitionPath), logFile);
- StoragePath inlineFsPath = HadoopInLineFSUtils.getInlineFilePath(
+ StoragePath inlineFsPath = InLineFSUtils.getInlineFilePath(
new StoragePath(rlPath.toUri()), "file", 0, 100);
assertTrue(FSUtils.isLogFile(rlPath));
assertTrue(FSUtils.isLogFile(inlineFsPath));
diff --git a/hudi-hadoop-common/src/test/java/org/apache/hudi/common/fs/inline/TestInLineFileSystem.java b/hudi-hadoop-common/src/test/java/org/apache/hudi/common/fs/inline/TestInLineFileSystem.java
index 351f6046f28a..d4ae0912256c 100644
--- a/hudi-hadoop-common/src/test/java/org/apache/hudi/common/fs/inline/TestInLineFileSystem.java
+++ b/hudi-hadoop-common/src/test/java/org/apache/hudi/common/fs/inline/TestInLineFileSystem.java
@@ -20,9 +20,9 @@ package org.apache.hudi.common.fs.inline;
import org.apache.hudi.common.testutils.FileSystemTestUtils;
import org.apache.hudi.common.util.collection.Pair;
-import org.apache.hudi.hadoop.fs.inline.HadoopInLineFSUtils;
import org.apache.hudi.hadoop.fs.inline.InLineFileSystem;
import org.apache.hudi.storage.StoragePath;
+import org.apache.hudi.storage.inline.InLineFSUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
@@ -360,12 +360,12 @@ public class TestInLineFileSystem {
if (inputPath.toString().contains(":")) {
scheme = inputPath.toString().split(":")[0];
}
- final StoragePath actualInLineFSPath = HadoopInLineFSUtils.getInlineFilePath(
+ final StoragePath actualInLineFSPath = InLineFSUtils.getInlineFilePath(
new StoragePath(inputPath.toUri()), scheme, 10, 10);
assertEquals(expectedInLineFSPath, actualInLineFSPath);
final StoragePath actualOuterFilePath =
- HadoopInLineFSUtils.getOuterFilePathFromInlinePath(actualInLineFSPath);
+ InLineFSUtils.getOuterFilePathFromInlinePath(actualInLineFSPath);
assertEquals(expectedTransformedInputPath, actualOuterFilePath);
}
}
diff --git a/hudi-hadoop-common/src/test/java/org/apache/hudi/common/fs/inline/TestInLineFileSystemWithHFileReader.java b/hudi-hadoop-common/src/test/java/org/apache/hudi/common/fs/inline/TestInLineFileSystemWithHFileReader.java
index 755427cae024..c5af75ae7293 100644
--- a/hudi-hadoop-common/src/test/java/org/apache/hudi/common/fs/inline/TestInLineFileSystemWithHFileReader.java
+++ b/hudi-hadoop-common/src/test/java/org/apache/hudi/common/fs/inline/TestInLineFileSystemWithHFileReader.java
@@ -55,7 +55,7 @@ import static org.apache.hudi.common.testutils.FileSystemTestUtils.RANDOM;
import static org.apache.hudi.common.testutils.FileSystemTestUtils.getPhantomFile;
import static org.apache.hudi.common.testutils.FileSystemTestUtils.getRandomOuterFSPath;
import static org.apache.hudi.common.util.StringUtils.getUTF8Bytes;
-import static org.apache.hudi.io.hfile.HFileUtils.getValue;
+import static org.apache.hudi.io.hfile.HFileByteUtils.getValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
diff --git a/hudi-hadoop-common/src/test/java/org/apache/hudi/common/table/timeline/TestHoodieActiveTimeline.java b/hudi-hadoop-common/src/test/java/org/apache/hudi/common/table/timeline/TestHoodieActiveTimeline.java
index 466d2464017f..e3bd44c01b5a 100755
--- a/hudi-hadoop-common/src/test/java/org/apache/hudi/common/table/timeline/TestHoodieActiveTimeline.java
+++ b/hudi-hadoop-common/src/test/java/org/apache/hudi/common/table/timeline/TestHoodieActiveTimeline.java
@@ -769,7 +769,7 @@ public class TestHoodieActiveTimeline extends HoodieCommonTestHarness {
assertEquals(Option.empty(),
TimelineUtils.parseDateFromInstantTimeSafely(HoodieTimeline.INIT_INSTANT_TS + "001"));
- // Test a valid instant timestamp, should equal the same result as ActiveTimelineUtils.parseDateFromInstantTime
+ // Test a valid instant timestamp, should equal the same result as TimelineUtils.parseDateFromInstantTime
String testInstant = "20210101120101";
assertEquals(TimelineUtils.parseDateFromInstantTime(testInstant).getTime(),
TimelineUtils.parseDateFromInstantTimeSafely(testInstant).get().getTime());
diff --git a/hudi-hadoop-common/src/test/java/org/apache/hudi/common/util/TestHadoopConfigUtils.java b/hudi-hadoop-common/src/test/java/org/apache/hudi/common/util/TestHadoopConfigUtils.java
index 01733d1b75d4..df7d89ed58a7 100644
--- a/hudi-hadoop-common/src/test/java/org/apache/hudi/common/util/TestHadoopConfigUtils.java
+++ b/hudi-hadoop-common/src/test/java/org/apache/hudi/common/util/TestHadoopConfigUtils.java
@@ -22,7 +22,6 @@ package org.apache.hudi.common.util;
import org.apache.hadoop.conf.Configuration;
import org.junit.jupiter.api.Test;
-import static org.apache.hudi.common.util.HadoopConfigUtils.getBooleanWithAltKeys;
import static org.apache.hudi.common.util.HadoopConfigUtils.getRawValueWithAltKeys;
import static org.apache.hudi.common.util.TestConfigUtils.TEST_BOOLEAN_CONFIG_PROPERTY;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -43,21 +42,4 @@ public class TestHadoopConfigUtils {
assertEquals(Option.of(String.valueOf(setValue)),
getRawValueWithAltKeys(conf, TEST_BOOLEAN_CONFIG_PROPERTY));
}
-
- @Test
- public void testGetBooleanWithAltKeysFromHadoopConf() {
- Configuration conf = new Configuration();
- assertEquals(Boolean.parseBoolean(TEST_BOOLEAN_CONFIG_PROPERTY.defaultValue()),
- getBooleanWithAltKeys(conf, TEST_BOOLEAN_CONFIG_PROPERTY));
-
- boolean setValue = !Boolean.parseBoolean(TEST_BOOLEAN_CONFIG_PROPERTY.defaultValue());
- conf.setBoolean(TEST_BOOLEAN_CONFIG_PROPERTY.key(), setValue);
- assertEquals(setValue,
- getBooleanWithAltKeys(conf, TEST_BOOLEAN_CONFIG_PROPERTY));
-
- conf = new Configuration();
- conf.setBoolean(TEST_BOOLEAN_CONFIG_PROPERTY.getAlternatives().get(0), setValue);
- assertEquals(setValue,
- getBooleanWithAltKeys(conf, TEST_BOOLEAN_CONFIG_PROPERTY));
- }
}
diff --git a/hudi-hadoop-common/src/test/java/org/apache/hudi/common/util/TestTablePathUtils.java b/hudi-hadoop-common/src/test/java/org/apache/hudi/common/util/TestTablePathUtils.java
index 50b9b8a027b7..048826e30eb4 100644
--- a/hudi-hadoop-common/src/test/java/org/apache/hudi/common/util/TestTablePathUtils.java
+++ b/hudi-hadoop-common/src/test/java/org/apache/hudi/common/util/TestTablePathUtils.java
@@ -162,4 +162,18 @@ public final class TestTablePathUtils {
inferredTablePath = TablePathUtils.getTablePath(storage, filePath2);
assertEquals(tablePath, inferredTablePath.get());
}
+
+ /**
+ * Verifies the parent walk terminates with an empty Option (not an exception) when no
+ * table metadata folder exists anywhere up to the filesystem root.
+ */
+ @Test
+ void getTablePathReturnsEmptyForNonHudiPath() throws IOException {
+ setup();
+ URI nonHudiURI = Paths.get(tempDir.getAbsolutePath(), "not_a_table/some/dir").toUri();
+ assertTrue(new File(nonHudiURI).mkdirs());
+ Option<StoragePath> inferredTablePath =
+ TablePathUtils.getTablePath(storage, new StoragePath(nonHudiURI));
+ assertTrue(!inferredTablePath.isPresent());
+ }
}
diff --git a/hudi-hadoop-common/src/test/java/org/apache/hudi/storage/hadoop/TestHadoopStorageConfiguration.java b/hudi-hadoop-common/src/test/java/org/apache/hudi/storage/hadoop/TestHadoopStorageConfiguration.java
index 79658ccc4413..e044637422f8 100644
--- a/hudi-hadoop-common/src/test/java/org/apache/hudi/storage/hadoop/TestHadoopStorageConfiguration.java
+++ b/hudi-hadoop-common/src/test/java/org/apache/hudi/storage/hadoop/TestHadoopStorageConfiguration.java
@@ -19,13 +19,17 @@
package org.apache.hudi.storage.hadoop;
+import org.apache.hudi.hadoop.fs.inline.InLineFileSystem;
import org.apache.hudi.io.storage.BaseTestStorageConfiguration;
import org.apache.hudi.storage.StorageConfiguration;
import org.apache.hadoop.conf.Configuration;
+import org.junit.jupiter.api.Test;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
/**
* Tests {@link HadoopStorageConfiguration}.
*/
@@ -41,4 +45,25 @@ public class TestHadoopStorageConfiguration extends BaseTestStorageConfiguration
mapping.forEach(conf::set);
return conf;
}
+
+ /**
+ * Verifies getInline() derives from this object's underlying config (caller-supplied
+ * configs like S3 credentials carry over) as an independent copy, with the inline FS
+ * implementation registered.
+ */
+ @Test
+ public void testGetInlineCarriesOverExistingConfigs() {
+ Configuration conf = new Configuration();
+ conf.set("fs.s3a.access.key", "test-access-key");
+ StorageConfiguration<Configuration> storageConf = new HadoopStorageConfiguration(conf);
+
+ StorageConfiguration<Configuration> inlineConf = storageConf.getInline();
+ assertEquals("test-access-key", inlineConf.getString("fs.s3a.access.key").get());
+ assertEquals(InLineFileSystem.class.getName(),
+ inlineConf.getString("fs." + InLineFileSystem.SCHEME + ".impl").get());
+
+ // the inline conf is a copy; mutating it must not leak back into the source conf
+ inlineConf.set("fs.s3a.access.key", "mutated");
+ assertEquals("test-access-key", storageConf.getString("fs.s3a.access.key").get());
+ }
}
diff --git a/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/hive/HoodieCombineRealtimeFileSplit.java b/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/hive/HoodieCombineRealtimeFileSplit.java
index 5636339b4d22..1a13183b932d 100644
--- a/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/hive/HoodieCombineRealtimeFileSplit.java
+++ b/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/hive/HoodieCombineRealtimeFileSplit.java
@@ -18,8 +18,8 @@
package org.apache.hudi.hadoop.hive;
+import org.apache.hudi.common.util.CollectionUtils;
import org.apache.hudi.common.util.ReflectionUtils;
-import org.apache.hudi.common.util.collection.ArrayUtils;
import org.apache.hudi.exception.HoodieIOException;
import org.apache.hudi.hadoop.realtime.HoodieRealtimeFileSplit;
@@ -53,9 +53,9 @@ public class HoodieCombineRealtimeFileSplit extends CombineFileSplit {
super(jobConf, realtimeFileSplits.stream().map(p ->
p.getPath()).collect(Collectors.toList()).toArray(new
Path[realtimeFileSplits.size()]),
- ArrayUtils.toPrimitive(realtimeFileSplits.stream().map(p -> p.getStart())
+ CollectionUtils.toPrimitive(realtimeFileSplits.stream().map(p -> p.getStart())
.collect(Collectors.toList()).toArray(new Long[realtimeFileSplits.size()])),
- ArrayUtils.toPrimitive(realtimeFileSplits.stream().map(p -> p.getLength())
+ CollectionUtils.toPrimitive(realtimeFileSplits.stream().map(p -> p.getLength())
.collect(Collectors.toList()).toArray(new Long[realtimeFileSplits.size()])),
realtimeFileSplits.stream().map(p -> {
try {
diff --git a/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/realtime/RealtimeSplit.java b/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/realtime/RealtimeSplit.java
index e3a81cc02049..da4ca191360b 100644
--- a/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/realtime/RealtimeSplit.java
+++ b/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/realtime/RealtimeSplit.java
@@ -20,7 +20,6 @@ package org.apache.hudi.hadoop.realtime;
import org.apache.hudi.common.model.HoodieLogFile;
import org.apache.hudi.common.util.Option;
-import org.apache.hudi.hadoop.utils.InputSplitUtils;
import org.apache.hudi.storage.StoragePath;
import org.apache.hadoop.fs.Path;
@@ -33,6 +32,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
+import static org.apache.hudi.common.util.StringUtils.fromUTF8Bytes;
+import static org.apache.hudi.common.util.StringUtils.getUTF8Bytes;
+
/**
* Realtime Input Split Interface.
*/
@@ -93,56 +95,68 @@ public interface RealtimeSplit extends InputSplitWithLocationInfo {
void setVirtualKeyInfo(Option<HoodieVirtualKeyInfo> virtualKeyInfo);
default void writeToOutput(DataOutput out) throws IOException {
- InputSplitUtils.writeString(getBasePath(), out);
- InputSplitUtils.writeString(getMaxCommitTime(), out);
- InputSplitUtils.writeBoolean(getBelongsToIncrementalQuery(), out);
+ writeString(getBasePath(), out);
+ writeString(getMaxCommitTime(), out);
+ out.writeBoolean(getBelongsToIncrementalQuery());
out.writeInt(getDeltaLogFiles().size());
for (HoodieLogFile logFile : getDeltaLogFiles()) {
- InputSplitUtils.writeString(logFile.getPath().toString(), out);
+ writeString(logFile.getPath().toString(), out);
out.writeLong(logFile.getFileSize());
}
Option<HoodieVirtualKeyInfo> virtualKeyInfoOpt = getVirtualKeyInfo();
if (!virtualKeyInfoOpt.isPresent()) {
- InputSplitUtils.writeBoolean(false, out);
+ out.writeBoolean(false);
} else {
- InputSplitUtils.writeBoolean(true, out);
- InputSplitUtils.writeString(virtualKeyInfoOpt.get().getRecordKeyField(), out);
- InputSplitUtils.writeString(String.valueOf(virtualKeyInfoOpt.get().getRecordKeyFieldIndex()), out);
- InputSplitUtils.writeBoolean(virtualKeyInfoOpt.get().getPartitionPathField().isPresent(), out);
+ out.writeBoolean(true);
+ writeString(virtualKeyInfoOpt.get().getRecordKeyField(), out);
+ writeString(String.valueOf(virtualKeyInfoOpt.get().getRecordKeyFieldIndex()), out);
+ out.writeBoolean(virtualKeyInfoOpt.get().getPartitionPathField().isPresent());
if (virtualKeyInfoOpt.get().getPartitionPathField().isPresent()) {
- InputSplitUtils.writeString(virtualKeyInfoOpt.get().getPartitionPathField().get(), out);
- InputSplitUtils.writeString(String.valueOf(virtualKeyInfoOpt.get().getPartitionPathFieldIndex()), out);
+ writeString(virtualKeyInfoOpt.get().getPartitionPathField().get(), out);
+ writeString(String.valueOf(virtualKeyInfoOpt.get().getPartitionPathFieldIndex()), out);
}
}
}
default void readFromInput(DataInput in) throws IOException {
- setBasePath(InputSplitUtils.readString(in));
- setMaxCommitTime(InputSplitUtils.readString(in));
- setBelongsToIncrementalQuery(InputSplitUtils.readBoolean(in));
+ setBasePath(readString(in));
+ setMaxCommitTime(readString(in));
+ setBelongsToIncrementalQuery(in.readBoolean());
int totalLogFiles = in.readInt();
List<HoodieLogFile> deltaLogPaths = new ArrayList<>(totalLogFiles);
for (int i = 0; i < totalLogFiles; i++) {
- String logFilePath = InputSplitUtils.readString(in);
+ String logFilePath = readString(in);
long logFileSize = in.readLong();
deltaLogPaths.add(new HoodieLogFile(new StoragePath(logFilePath), logFileSize));
}
setDeltaLogFiles(deltaLogPaths);
- boolean hoodieVirtualKeyPresent = InputSplitUtils.readBoolean(in);
+ boolean hoodieVirtualKeyPresent = in.readBoolean();
if (hoodieVirtualKeyPresent) {
- String recordKeyField = InputSplitUtils.readString(in);
- int recordFieldIndex = Integer.parseInt(InputSplitUtils.readString(in));
- boolean isPartitionPathFieldPresent = InputSplitUtils.readBoolean(in);
- Option<String> partitionPathField = isPartitionPathFieldPresent ? Option.of(InputSplitUtils.readString(in)) : Option.empty();
- Option<Integer> partitionPathIndex = isPartitionPathFieldPresent ? Option.of(Integer.parseInt(InputSplitUtils.readString(in))) : Option.empty();
+ String recordKeyField = readString(in);
+ int recordFieldIndex = Integer.parseInt(readString(in));
+ boolean isPartitionPathFieldPresent = in.readBoolean();
+ Option<String> partitionPathField = isPartitionPathFieldPresent ? Option.of(readString(in)) : Option.empty();
+ Option<Integer> partitionPathIndex = isPartitionPathFieldPresent ? Option.of(Integer.parseInt(readString(in))) : Option.empty();
setVirtualKeyInfo(Option.of(new HoodieVirtualKeyInfo(recordKeyField, partitionPathField, recordFieldIndex, partitionPathIndex)));
}
}
+ static void writeString(String str, DataOutput out) throws IOException {
+ byte[] bytes = getUTF8Bytes(str);
+ out.writeInt(bytes.length);
+ out.write(bytes);
+ }
+
+ static String readString(DataInput in) throws IOException {
+ byte[] bytes = new byte[in.readInt()];
+ in.readFully(bytes);
+ return fromUTF8Bytes(bytes);
+ }
+
/**
* The file containing this split's data.
*/
diff --git a/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/utils/HoodieInputFormatUtils.java b/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/utils/HoodieInputFormatUtils.java
index 44f73d5a6b37..88e04c377bd9 100644
--- a/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/utils/HoodieInputFormatUtils.java
+++ b/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/utils/HoodieInputFormatUtils.java
@@ -25,7 +25,6 @@ import org.apache.hudi.common.fs.FSUtils;
import org.apache.hudi.common.model.HoodieBaseFile;
import org.apache.hudi.common.model.HoodieCommitMetadata;
import org.apache.hudi.common.model.HoodieFileFormat;
-import org.apache.hudi.common.model.HoodiePartitionMetadata;
import org.apache.hudi.common.table.HoodieTableMetaClient;
import org.apache.hudi.common.table.timeline.HoodieInstant;
import org.apache.hudi.common.table.timeline.HoodieTimeline;
@@ -76,6 +75,7 @@ import org.apache.hadoop.mapreduce.JobContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -91,7 +91,6 @@ import java.util.stream.Collectors;
import static org.apache.hudi.common.config.HoodieCommonConfig.INCREMENTAL_READ_HANDLE_HOLLOW_COMMIT;
import static org.apache.hudi.common.config.HoodieMetadataConfig.DEFAULT_METADATA_ENABLE_FOR_READERS;
import static org.apache.hudi.common.config.HoodieMetadataConfig.ENABLE;
-import static org.apache.hudi.common.table.HoodieTableMetaClient.METAFOLDER_NAME;
import static org.apache.hudi.common.table.timeline.TimelineUtils.handleHollowCommitIfNeeded;
import static org.apache.hudi.hadoop.fs.HadoopFSUtils.convertToStoragePath;
@@ -404,29 +403,21 @@ public class HoodieInputFormatUtils {
* Extract HoodieTableMetaClient from a partition path (not base path)
*/
public static HoodieTableMetaClient getTableMetaClientForBasePathUnchecked(Configuration conf, Path partitionPath) throws IOException {
- Path baseDir = partitionPath;
HoodieStorage storage = HoodieStorageUtils.getStorage(
partitionPath.toString(), HadoopFSUtils.getStorageConf(conf));
- StoragePath partitionStoragePath = convertToStoragePath(partitionPath);
- if (HoodiePartitionMetadata.hasPartitionMetadata(storage, partitionStoragePath)) {
- HoodiePartitionMetadata metadata = new HoodiePartitionMetadata(storage, partitionStoragePath);
- metadata.readFromFS();
- int levels = metadata.getPartitionDepth();
- baseDir = HoodieHiveUtils.getNthParent(partitionPath, levels);
- } else {
- for (int i = 0; i < partitionPath.depth(); i++) {
- if (storage.exists(new StoragePath(convertToStoragePath(baseDir), METAFOLDER_NAME))) {
- break;
- } else if (i == partitionPath.depth() - 1) {
- throw new TableNotFoundException(partitionPath.toString());
- } else {
- baseDir = baseDir.getParent();
- }
- }
+ Option<StoragePath> baseDir;
+ try {
+ baseDir = TablePathUtils.getTablePath(storage, convertToStoragePath(partitionPath));
+ } catch (FileNotFoundException e) {
+ // preserve the historical contract: a nonexistent input path surfaces as table-not-found
+ throw new TableNotFoundException(partitionPath.toString());
+ }
+ if (!baseDir.isPresent()) {
+ throw new TableNotFoundException(partitionPath.toString());
}
- LOG.info("Reading hoodie metadata from path {}", baseDir);
+ LOG.info("Reading hoodie metadata from path {}", baseDir.get());
return HoodieTableMetaClient.builder()
- .setConf(storage.getConf().newInstance()).setBasePath(baseDir.toString()).build();
+ .setConf(storage.getConf().newInstance()).setBasePath(baseDir.get().toString()).build();
}
public static FileStatus getFileStatus(HoodieBaseFile baseFile) throws IOException {
diff --git a/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/utils/InputSplitUtils.java b/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/utils/InputSplitUtils.java
deleted file mode 100644
index 38fefa1c4ed2..000000000000
--- a/hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/utils/InputSplitUtils.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.hadoop.utils;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-
-import static org.apache.hudi.common.util.StringUtils.fromUTF8Bytes;
-import static org.apache.hudi.common.util.StringUtils.getUTF8Bytes;
-
-public class InputSplitUtils {
-
- public static void writeString(String str, DataOutput out) throws IOException {
- byte[] bytes = getUTF8Bytes(str);
- out.writeInt(bytes.length);
- out.write(bytes);
- }
-
- public static String readString(DataInput in) throws IOException {
- byte[] bytes = new byte[in.readInt()];
- in.readFully(bytes);
- return fromUTF8Bytes(bytes);
- }
-
- public static void writeBoolean(Boolean valueToWrite, DataOutput out) throws IOException {
- out.writeBoolean(valueToWrite);
- }
-
- public static boolean readBoolean(DataInput in) throws IOException {
- return in.readBoolean();
- }
-}
diff --git a/hudi-hadoop-mr/src/test/java/org/apache/hudi/hadoop/TestInputPathHandler.java b/hudi-hadoop-mr/src/test/java/org/apache/hudi/hadoop/TestInputPathHandler.java
index 2a9380b32140..5d50a50b29a8 100644
--- a/hudi-hadoop-mr/src/test/java/org/apache/hudi/hadoop/TestInputPathHandler.java
+++ b/hudi-hadoop-mr/src/test/java/org/apache/hudi/hadoop/TestInputPathHandler.java
@@ -23,8 +23,10 @@ import org.apache.hudi.common.model.HoodieTableType;
import org.apache.hudi.common.table.HoodieTableConfig;
import org.apache.hudi.common.table.HoodieTableMetaClient;
import org.apache.hudi.common.testutils.minicluster.HdfsTestService;
+import org.apache.hudi.exception.TableNotFoundException;
import org.apache.hudi.hadoop.fs.HadoopFSUtils;
import org.apache.hudi.hadoop.utils.HoodieHiveUtils;
+import org.apache.hudi.hadoop.utils.HoodieInputFormatUtils;
import org.apache.hudi.storage.StoragePath;
import org.apache.hadoop.conf.Configuration;
@@ -44,6 +46,7 @@ import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestInputPathHandler {
@@ -226,4 +229,15 @@ public class TestInputPathHandler {
}
return true;
}
+
+ /**
+ * A nonexistent input path must surface as TableNotFoundException (historical contract),
+ * not as a raw FileNotFoundException from the underlying path lookup.
+ */
+ @Test
+ public void testNonExistentPathThrowsTableNotFound() {
+ Path nonExistent = new Path(basePathTable1 + "_does_not_exist/2024/01/01");
+ assertThrows(TableNotFoundException.class,
+ () -> HoodieInputFormatUtils.getTableMetaClientForBasePathUnchecked(dfs.getConf(), nonExistent));
+ }
}
diff --git a/hudi-io/src/main/java/org/apache/hudi/common/util/StringUtils.java b/hudi-io/src/main/java/org/apache/hudi/common/util/StringUtils.java
index a49a11362288..4f3a651d7914 100644
--- a/hudi-io/src/main/java/org/apache/hudi/common/util/StringUtils.java
+++ b/hudi-io/src/main/java/org/apache/hudi/common/util/StringUtils.java
@@ -168,11 +168,7 @@ public class StringUtils {
* @return {@code string} itself if it is nonempty; {@code null} if it is empty or null
*/
public static @Nullable String emptyToNull(@Nullable String string) {
- return stringIsNullOrEmpty(string) ? null : string;
- }
-
- private static boolean stringIsNullOrEmpty(@Nullable String string) {
- return string == null || string.isEmpty();
+ return isNullOrEmpty(string) ? null : string;
}
/**
diff --git a/hudi-io/src/main/java/org/apache/hudi/common/util/ValidationUtils.java b/hudi-io/src/main/java/org/apache/hudi/common/util/ValidationUtils.java
index 1cf2d977bccb..5896186fbe4e 100644
--- a/hudi-io/src/main/java/org/apache/hudi/common/util/ValidationUtils.java
+++ b/hudi-io/src/main/java/org/apache/hudi/common/util/ValidationUtils.java
@@ -81,10 +81,12 @@ public class ValidationUtils {
/**
* Ensures the truth of an expression, throwing the custom errorMessage otherwise.
+ *
+ * @throws IllegalStateException if {@code expression} is false
*/
public static void checkState(final boolean expression, final Supplier<String> errorMessageSupplier) {
if (!expression) {
- throw new IllegalArgumentException(errorMessageSupplier.get());
+ throw new IllegalStateException(errorMessageSupplier.get());
}
}
}
diff --git a/hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileUtils.java b/hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileByteUtils.java
similarity index 98%
rename from hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileUtils.java
rename to hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileByteUtils.java
index 1ded713c59d7..9a695e7aa376 100644
--- a/hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileUtils.java
+++ b/hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileByteUtils.java
@@ -26,7 +26,7 @@ import static org.apache.hudi.common.util.StringUtils.fromUTF8Bytes;
/**
* Util methods for reading and writing HFile.
*/
-public class HFileUtils {
+public class HFileByteUtils {
/**
* Reads the HFile major version from the input.
*
diff --git a/hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileReaderImpl.java b/hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileReaderImpl.java
index 3134647fa38b..bb04272a2883 100644
--- a/hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileReaderImpl.java
+++ b/hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileReaderImpl.java
@@ -38,7 +38,7 @@ import java.util.Queue;
import java.util.TreeMap;
import static org.apache.hudi.io.hfile.HFileBlock.HFILEBLOCK_HEADER_SIZE;
-import static org.apache.hudi.io.hfile.HFileUtils.readMajorVersion;
+import static org.apache.hudi.io.hfile.HFileByteUtils.readMajorVersion;
/**
* Base implementation of {@link HFileReader} without caching. This provides the core functionality for reading HFile format data.
diff --git a/hudi-io/src/main/java/org/apache/hudi/io/hfile/Key.java b/hudi-io/src/main/java/org/apache/hudi/io/hfile/Key.java
index f8e2c4b03a20..8d8aab1447d8 100644
--- a/hudi-io/src/main/java/org/apache/hudi/io/hfile/Key.java
+++ b/hudi-io/src/main/java/org/apache/hudi/io/hfile/Key.java
@@ -27,7 +27,7 @@ import lombok.ToString;
import static org.apache.hudi.common.util.StringUtils.fromUTF8Bytes;
import static org.apache.hudi.io.hfile.DataSize.SIZEOF_INT16;
-import static org.apache.hudi.io.hfile.HFileUtils.compareKeys;
+import static org.apache.hudi.io.hfile.HFileByteUtils.compareKeys;
import static org.apache.hudi.io.util.IOUtils.readShort;
/**
diff --git a/hudi-io/src/main/java/org/apache/hudi/io/util/IOUtils.java b/hudi-io/src/main/java/org/apache/hudi/io/util/IOUtils.java
index 274dfe6d8f90..68482c1a4740 100644
--- a/hudi-io/src/main/java/org/apache/hudi/io/util/IOUtils.java
+++ b/hudi-io/src/main/java/org/apache/hudi/io/util/IOUtils.java
@@ -20,11 +20,9 @@
package org.apache.hudi.io.util;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.nio.ByteBuffer;
/**
@@ -352,20 +350,6 @@ public class IOUtils {
return totalBytesRead;
}
- public static byte[] readAsByteArray(InputStream input, int outputSize) throws IOException {
- ByteArrayOutputStream bos = new ByteArrayOutputStream(outputSize);
- copy(input, bos);
- return bos.toByteArray();
- }
-
- public static void copy(InputStream inputStream, OutputStream outputStream) throws IOException {
- byte[] buffer = new byte[1024];
- int len;
- while ((len = inputStream.read(buffer)) != -1) {
- outputStream.write(buffer, 0, len);
- }
- }
-
/**
* @param byteBuffer {@link ByteBuffer} containing the bytes.
* @return {@link DataInputStream} based on the byte buffer.
diff --git a/hudi-io/src/test/java/org/apache/hudi/common/util/TestValidationUtils.java b/hudi-io/src/test/java/org/apache/hudi/common/util/TestValidationUtils.java
new file mode 100644
index 000000000000..3eb7e5c64da5
--- /dev/null
+++ b/hudi-io/src/test/java/org/apache/hudi/common/util/TestValidationUtils.java
@@ -0,0 +1,53 @@
+/*
+ * 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.common.util;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * Tests {@link ValidationUtils}: checkArgument throws {@link IllegalArgumentException} and
+ * checkState throws {@link IllegalStateException} across all overloads.
+ */
+public class TestValidationUtils {
+
+ @Test
+ public void testCheckArgumentThrowsIllegalArgumentException() {
+ assertDoesNotThrow(() -> ValidationUtils.checkArgument(true, "msg"));
+ assertThrows(IllegalArgumentException.class, () -> ValidationUtils.checkArgument(false));
+ assertEquals("msg", assertThrows(IllegalArgumentException.class,
+ () -> ValidationUtils.checkArgument(false, "msg")).getMessage());
+ assertEquals("supplied", assertThrows(IllegalArgumentException.class,
+ () -> ValidationUtils.checkArgument(false, () -> "supplied")).getMessage());
+ }
+
+ @Test
+ public void testCheckStateThrowsIllegalStateException() {
+ assertDoesNotThrow(() -> ValidationUtils.checkState(true, "msg"));
+ assertThrows(IllegalStateException.class, () -> ValidationUtils.checkState(false));
+ assertEquals("msg", assertThrows(IllegalStateException.class,
+ () -> ValidationUtils.checkState(false, "msg")).getMessage());
+ // supplier overload historically threw IllegalArgumentException by copy-paste mistake
+ assertEquals("supplied", assertThrows(IllegalStateException.class,
+ () -> ValidationUtils.checkState(false, () -> "supplied")).getMessage());
+ }
+}
diff --git a/hudi-io/src/test/java/org/apache/hudi/io/hfile/TestHFileReader.java b/hudi-io/src/test/java/org/apache/hudi/io/hfile/TestHFileReader.java
index 96c24a147ee6..31259dce1f71 100644
--- a/hudi-io/src/test/java/org/apache/hudi/io/hfile/TestHFileReader.java
+++ b/hudi-io/src/test/java/org/apache/hudi/io/hfile/TestHFileReader.java
@@ -39,12 +39,12 @@ import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;
+import static org.apache.hudi.io.hfile.HFileByteUtils.getValue;
import static org.apache.hudi.io.hfile.HFileReader.SEEK_TO_BEFORE_BLOCK_FIRST_KEY;
import static org.apache.hudi.io.hfile.HFileReader.SEEK_TO_BEFORE_FILE_FIRST_KEY;
import static org.apache.hudi.io.hfile.HFileReader.SEEK_TO_EOF;
import static org.apache.hudi.io.hfile.HFileReader.SEEK_TO_FOUND;
import static org.apache.hudi.io.hfile.HFileReader.SEEK_TO_IN_RANGE;
-import static org.apache.hudi.io.hfile.HFileUtils.getValue;
import static org.apache.hudi.io.util.FileIOUtils.readAsByteArray;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
diff --git a/hudi-io/src/test/java/org/apache/hudi/io/storage/TestHoodieStorageBase.java b/hudi-io/src/test/java/org/apache/hudi/io/storage/TestHoodieStorageBase.java
index ee66a3d366bd..090e3f956787 100644
--- a/hudi-io/src/test/java/org/apache/hudi/io/storage/TestHoodieStorageBase.java
+++ b/hudi-io/src/test/java/org/apache/hudi/io/storage/TestHoodieStorageBase.java
@@ -21,7 +21,7 @@ package org.apache.hudi.io.storage;
import org.apache.hudi.common.util.Option;
import org.apache.hudi.io.SeekableDataInputStream;
-import org.apache.hudi.io.util.IOUtils;
+import org.apache.hudi.io.util.FileIOUtils;
import org.apache.hudi.storage.HoodieInstantWriter;
import org.apache.hudi.storage.HoodieStorage;
import org.apache.hudi.storage.StoragePath;
@@ -406,7 +406,7 @@ public abstract class TestHoodieStorageBase {
if (!isDirectory) {
assertEquals(data.length, pathInfo.getLength());
try (InputStream stream = storage.open(path)) {
- assertArrayEquals(data, IOUtils.readAsByteArray(stream, data.length));
+ assertArrayEquals(data, FileIOUtils.readAsByteArray(stream, data.length));
}
}
assertTrue(pathInfo.getModificationTime() > 0);
diff --git a/hudi-io/src/test/java/org/apache/hudi/io/util/TestHFileUtils.java b/hudi-io/src/test/java/org/apache/hudi/io/util/TestHFileByteUtils.java
similarity index 92%
rename from hudi-io/src/test/java/org/apache/hudi/io/util/TestHFileUtils.java
rename to hudi-io/src/test/java/org/apache/hudi/io/util/TestHFileByteUtils.java
index e28fab8195e3..346298ce40d8 100644
--- a/hudi-io/src/test/java/org/apache/hudi/io/util/TestHFileUtils.java
+++ b/hudi-io/src/test/java/org/apache/hudi/io/util/TestHFileByteUtils.java
@@ -23,14 +23,14 @@ import org.apache.hudi.io.hfile.UTF8StringKey;
import org.junit.jupiter.api.Test;
-import static org.apache.hudi.io.hfile.HFileUtils.isPrefixOfKey;
+import static org.apache.hudi.io.hfile.HFileByteUtils.isPrefixOfKey;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
- * Tests {@link TestHFileUtils}.
+ * Tests {@link TestHFileByteUtils}.
*/
-public class TestHFileUtils {
+public class TestHFileByteUtils {
@Test
public void testIsPrefixOfKey() {
assertTrue(isPrefixOfKey(new UTF8StringKey(""), new UTF8StringKey("")));
diff --git a/hudi-kafka-connect/src/main/java/org/apache/hudi/connect/writers/BufferedConnectWriter.java b/hudi-kafka-connect/src/main/java/org/apache/hudi/connect/writers/BufferedConnectWriter.java
index 09b61ae608fa..31df747a8a8f 100644
--- a/hudi-kafka-connect/src/main/java/org/apache/hudi/connect/writers/BufferedConnectWriter.java
+++ b/hudi-kafka-connect/src/main/java/org/apache/hudi/connect/writers/BufferedConnectWriter.java
@@ -32,7 +32,7 @@ import org.apache.hudi.common.util.Option;
import org.apache.hudi.common.util.collection.ExternalSpillableMap;
import org.apache.hudi.config.HoodieWriteConfig;
import org.apache.hudi.exception.HoodieIOException;
-import org.apache.hudi.io.IOUtils;
+import org.apache.hudi.io.MergeUtils;
import org.apache.hudi.keygen.KeyGenerator;
import org.apache.hudi.schema.SchemaProvider;
@@ -71,7 +71,7 @@ public class BufferedConnectWriter extends AbstractConnectWriter {
private void init() {
try {
// Load and batch all incoming records in a map
- long memoryForMerge = IOUtils.getMaxMemoryPerPartitionMerge(context.getTaskContextSupplier(), config);
+ long memoryForMerge = MergeUtils.getMaxMemoryPerPartitionMerge(context.getTaskContextSupplier(), config);
log.info("MaxMemoryPerPartitionMerge => {}", memoryForMerge);
this.bufferedRecords = new ExternalSpillableMap<>(memoryForMerge,
config.getSpillableMapBasePath(),
diff --git a/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/HoodieFileGroupReaderBasedFileFormat.scala b/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/HoodieFileGroupReaderBasedFileFormat.scala
index 4b4918ad2a7c..175239d9d7c2 100644
--- a/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/HoodieFileGroupReaderBasedFileFormat.scala
+++ b/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/HoodieFileGroupReaderBasedFileFormat.scala
@@ -34,7 +34,7 @@ import org.apache.hudi.common.util.{Option => HOption}
import org.apache.hudi.common.util.collection.ClosableIterator
import org.apache.hudi.data.CloseableIteratorListener
import org.apache.hudi.exception.HoodieNotSupportedException
-import org.apache.hudi.io.IOUtils
+import org.apache.hudi.io.MergeUtils
import org.apache.hudi.io.storage.HoodieSparkParquetReader.ENABLE_LOGICAL_TIMESTAMP_REPAIR
import org.apache.hudi.io.storage.VectorConversionUtils
import org.apache.hudi.storage.StorageConfiguration
@@ -286,7 +286,7 @@ class HoodieFileGroupReaderBasedFileFormat(tablePath: String,
val fileIndexProps: TypedProperties = HoodieFileIndex.getConfigProperties(spark, options, null)
val engineContext = new HoodieSparkEngineContext(new JavaSparkContext(spark.sparkContext))
- val maxMemoryPerCompaction = IOUtils.getMaxMemoryPerCompaction(engineContext.getTaskContextSupplier, options.asJava)
+ val maxMemoryPerCompaction = MergeUtils.getMaxMemoryPerCompaction(engineContext.getTaskContextSupplier, options.asJava)
// Create metaclient on driver to avoid expensive operations on executors
val metaClient: HoodieTableMetaClient = HoodieTableMetaClient
diff --git a/hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/procedures/ShowInvalidParquetProcedure.scala b/hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/procedures/ShowInvalidParquetProcedure.scala
index 7fd8e40f3084..ef8f7a2c4f60 100644
--- a/hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/procedures/ShowInvalidParquetProcedure.scala
+++ b/hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/procedures/ShowInvalidParquetProcedure.scala
@@ -72,8 +72,7 @@ class ShowInvalidParquetProcedure extends BaseProcedure with ProcedureBuilder {
val partitionPaths: java.util.List[String] = metadata.getPartitionPathWithPathPrefixes(partitions.split(",").toList.asJava)
val instantsList = if (StringUtils.isNullOrEmpty(instants)) Array.empty[String] else instants.split(",")
val fileStatus = partitionPaths.asScala.flatMap(part => {
- val fs = HadoopFSUtils.getFs(new Path(srcPath), storageConf.unwrap())
- HadoopFSUtils.getAllDataFilesInPartition(fs, HadoopFSUtils.constructAbsolutePathInHadoopPath(srcPath, part))
+ FSUtils.getAllDataFilesInPartition(storage, FSUtils.constructAbsolutePath(srcPath, part)).asScala
}).toList
if (fileStatus.isEmpty) {
@@ -87,7 +86,7 @@ class ShowInvalidParquetProcedure extends BaseProcedure with ProcedureBuilder {
true
}
}).filter(status => {
- val filePath = status.getPath
+ val filePath = HadoopFSUtils.convertToHadoopPath(status.getPath)
var isInvalid = false
if (filePath.toString.endsWith(".parquet")) {
try ParquetFileReader.readFooter(storageConf.unwrap(), filePath, SKIP_ROW_GROUPS).getFileMetaData catch {
diff --git a/hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/functional/TestColStatsRecordWithMetadataRecord.java b/hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/functional/TestColStatsRecordWithMetadataRecord.java
index 4ef200e7ca29..0db982b7447a 100644
--- a/hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/functional/TestColStatsRecordWithMetadataRecord.java
+++ b/hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/functional/TestColStatsRecordWithMetadataRecord.java
@@ -23,6 +23,7 @@ import org.apache.hudi.avro.model.HoodieMetadataColumnStats;
import org.apache.hudi.client.SparkRDDWriteClient;
import org.apache.hudi.client.WriteClientTestUtils;
import org.apache.hudi.client.WriteStatus;
+import org.apache.hudi.common.avro.HoodieAvroUtils;
import org.apache.hudi.common.config.TypedProperties;
import org.apache.hudi.common.engine.EngineProperty;
import org.apache.hudi.common.engine.TaskContextSupplier;
@@ -38,7 +39,6 @@ import org.apache.hudi.common.testutils.InProcessTimeGenerator;
import org.apache.hudi.common.util.FileFormatUtils;
import org.apache.hudi.common.util.Functions;
import org.apache.hudi.common.util.Option;
-import org.apache.hudi.common.util.SpillableMapUtils;
import org.apache.hudi.common.util.collection.ClosableIterator;
import org.apache.hudi.common.util.collection.Pair;
import org.apache.hudi.config.HoodieWriteConfig;
@@ -219,7 +219,7 @@ public class TestColStatsRecordWithMetadataRecord extends HoodieSparkClientTestH
List<HoodieRecord<HoodieMetadataPayload>> allRecords = new ArrayList<>();
while (itr.hasNext()) {
GenericRecord genericRecord = (GenericRecord) ((HoodieRecord) itr.next()).getData();
- HoodieRecord<HoodieMetadataPayload> mdtRec = SpillableMapUtils.convertToHoodieRecordPayload(genericRecord,
+ HoodieRecord<HoodieMetadataPayload> mdtRec = HoodieAvroUtils.convertToRecord(genericRecord,
mdtWriteConfig.getPayloadClass(), new String[0],
Pair.of(mdtMetaClient.getTableConfig().getRecordKeyFieldProp(), mdtMetaClient.getTableConfig().getPartitionFieldProp()),
false, Option.of(COLUMN_STATS.getPartitionPath()), Option.empty());
diff --git a/hudi-spark-datasource/hudi-spark4-common/src/main/java/org/apache/hudi/variant/Spark4VariantShreddingProvider.java b/hudi-spark-datasource/hudi-spark4-common/src/main/java/org/apache/hudi/variant/Spark4VariantShreddingProvider.java
index 344ea7071f6d..efb62c23e101 100644
--- a/hudi-spark-datasource/hudi-spark4-common/src/main/java/org/apache/hudi/variant/Spark4VariantShreddingProvider.java
+++ b/hudi-spark-datasource/hudi-spark4-common/src/main/java/org/apache/hudi/variant/Spark4VariantShreddingProvider.java
@@ -45,6 +45,8 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
+import static org.apache.hudi.common.avro.HoodieAvroUtils.unwrapNullable;
+
/**
* Implementation of {@link VariantShreddingProvider} using Spark 4's variant parsing library.
*
@@ -250,17 +252,6 @@ public class Spark4VariantShreddingProvider implements VariantShreddingProvider
}
}
- private static Schema unwrapNullable(Schema schema) {
- if (schema.getType() == Schema.Type.UNION) {
- for (Schema type : schema.getTypes()) {
- if (type.getType() != Schema.Type.NULL) {
- return type;
- }
- }
- }
- return schema;
- }
-
private static byte[] toByteArray(ByteBuffer buffer) {
if (buffer.hasArray() && buffer.position() == 0
&& buffer.arrayOffset() == 0
diff --git a/hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/HoodieIncrSource.java b/hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/HoodieIncrSource.java
index 2a62bb64b543..5a642d713bb8 100644
--- a/hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/HoodieIncrSource.java
+++ b/hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/HoodieIncrSource.java
@@ -72,7 +72,7 @@ import static org.apache.hudi.DataSourceReadOptions.INCREMENTAL_READ_TABLE_VERSI
import static org.apache.hudi.DataSourceReadOptions.QUERY_TYPE;
import static org.apache.hudi.DataSourceReadOptions.QUERY_TYPE_INCREMENTAL_OPT_VAL;
import static org.apache.hudi.DataSourceReadOptions.START_COMMIT;
-import static org.apache.hudi.common.table.checkpoint.HoodieIncrSourceCheckpointValUtils.resolveToActualCheckpointVersion;
+import static org.apache.hudi.common.table.checkpoint.CheckpointUtils.resolveToActualCheckpointVersion;
import static org.apache.hudi.common.table.timeline.InstantComparison.LESSER_THAN_OR_EQUALS;
import static org.apache.hudi.common.table.timeline.InstantComparison.compareTimestamps;
import static org.apache.hudi.common.util.ConfigUtils.checkRequiredConfigProperties;
diff --git a/hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/PulsarSource.java b/hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/PulsarSource.java
index b2a416d24997..01a8662ecf71 100644
--- a/hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/PulsarSource.java
+++ b/hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/PulsarSource.java
@@ -57,7 +57,6 @@ import static org.apache.hudi.common.table.checkpoint.CheckpointUtils.createChec
import static org.apache.hudi.common.util.ConfigUtils.checkRequiredConfigProperties;
import static org.apache.hudi.common.util.ConfigUtils.getLongWithAltKeys;
import static org.apache.hudi.common.util.ConfigUtils.getStringWithAltKeys;
-import static org.apache.hudi.common.util.ThreadUtils.collectActiveThreads;
import static org.apache.hudi.utilities.config.PulsarSourceConfig.PULSAR_SOURCE_ADMIN_ENDPOINT_URL;
import static org.apache.hudi.utilities.config.PulsarSourceConfig.PULSAR_SOURCE_MAX_RECORDS_PER_BATCH_THRESHOLD;
import static org.apache.hudi.utilities.config.PulsarSourceConfig.PULSAR_SOURCE_OFFSET_AUTO_RESET_STRATEGY;
@@ -264,8 +263,22 @@ public class PulsarSource extends RowSource implements Closeable {
// properly (see above). To work this around we employ "nuclear" option of
// fetching all Pulsar client threads and interrupting them forcibly (to make them
// shutdown)
- collectActiveThreads().stream().sequential()
+ Arrays.stream(collectActiveThreads())
.filter(t -> t.getName().startsWith("pulsar-client-io"))
.forEach(Thread::interrupt);
}
+
+ /**
+ * Fetches all active threads currently running in the JVM.
+ */
+ private static Thread[] collectActiveThreads() {
+ ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
+ while (threadGroup.getParent() != null) {
+ threadGroup = threadGroup.getParent();
+ }
+
+ Thread[] activeThreads = new Thread[threadGroup.activeCount()];
+ threadGroup.enumerate(activeThreads);
+ return activeThreads;
+ }
}
diff --git a/hudi-utilities/src/main/java/org/apache/hudi/utilities/streamer/validator/SparkKafkaOffsetValidator.java b/hudi-utilities/src/main/java/org/apache/hudi/utilities/streamer/validator/SparkKafkaOffsetValidator.java
index 56e08755c43e..df3093b16681 100644
--- a/hudi-utilities/src/main/java/org/apache/hudi/utilities/streamer/validator/SparkKafkaOffsetValidator.java
+++ b/hudi-utilities/src/main/java/org/apache/hudi/utilities/streamer/validator/SparkKafkaOffsetValidator.java
@@ -21,7 +21,7 @@ package org.apache.hudi.utilities.streamer.validator;
import org.apache.hudi.client.validator.StreamingOffsetValidator;
import org.apache.hudi.common.config.TypedProperties;
-import org.apache.hudi.common.util.CheckpointUtils.CheckpointFormat;
+import org.apache.hudi.common.util.KafkaCheckpointUtils.CheckpointFormat;
/**
* Spark/HoodieStreamer-specific Kafka offset validator.
diff --git a/hudi-utilities/src/test/java/org/apache/hudi/utilities/streamer/TestHoodieIncrSourceE2EAutoUpgrade.java b/hudi-utilities/src/test/java/org/apache/hudi/utilities/streamer/TestHoodieIncrSourceE2EAutoUpgrade.java
index 52a6734ec331..cf0adda3f99a 100644
--- a/hudi-utilities/src/test/java/org/apache/hudi/utilities/streamer/TestHoodieIncrSourceE2EAutoUpgrade.java
+++ b/hudi-utilities/src/test/java/org/apache/hudi/utilities/streamer/TestHoodieIncrSourceE2EAutoUpgrade.java
@@ -53,8 +53,8 @@ import java.util.Map;
import java.util.Properties;
import static org.apache.hudi.common.model.HoodieTableType.COPY_ON_WRITE;
-import static org.apache.hudi.common.table.checkpoint.HoodieIncrSourceCheckpointValUtils.REQUEST_TIME_PREFIX;
-import static org.apache.hudi.common.table.checkpoint.HoodieIncrSourceCheckpointValUtils.RESET_CHECKPOINT_V2_SEPARATOR;
+import static org.apache.hudi.common.table.checkpoint.CheckpointUtils.REQUEST_TIME_PREFIX;
+import static org.apache.hudi.common.table.checkpoint.CheckpointUtils.RESET_CHECKPOINT_V2_SEPARATOR;
import static org.apache.hudi.common.table.checkpoint.StreamerCheckpointV1.STREAMER_CHECKPOINT_KEY_V1;
import static org.apache.hudi.common.table.checkpoint.StreamerCheckpointV2.STREAMER_CHECKPOINT_KEY_V2;
import static org.apache.hudi.common.table.checkpoint.StreamerCheckpointV2.STREAMER_CHECKPOINT_RESET_KEY_V2;