From 36995d991a79d1f00195b0199961d67fe401fcd9 Mon Sep 17 00:00:00 2001 From: Sumeet Varma Date: Mon, 23 Sep 2024 16:02:00 -0700 Subject: [PATCH] [Storage] Add Javadoc for CoordinatedCommitsUtils::getCoordinatorName (#3711) #### Which Delta project/connector is this regarding? - [ ] Spark - [ ] Standalone - [ ] Flink - [ ] Kernel - [x] Other (Storage) ## Description This is a simple cleanup PR for improving documentation of getCoordinatorName 1. Return an Optional to indicate the method may return null if no coordinator is set 2. Rename the method from getCoordinator -> getCoordinatorName ## How was this patch tested? Build ## Does this PR introduce _any_ user-facing changes? No --- .../storage/commit/CoordinatedCommitsUtils.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/storage/src/main/java/io/delta/storage/commit/CoordinatedCommitsUtils.java b/storage/src/main/java/io/delta/storage/commit/CoordinatedCommitsUtils.java index bb27823a5f..cdd03d5ed7 100644 --- a/storage/src/main/java/io/delta/storage/commit/CoordinatedCommitsUtils.java +++ b/storage/src/main/java/io/delta/storage/commit/CoordinatedCommitsUtils.java @@ -68,9 +68,9 @@ public static boolean isCoordinatedCommitsToFSConversion( Long commitVersion, UpdatedActions updatedActions) { boolean oldMetadataHasCoordinatedCommits = - !getCoordinator(updatedActions.getOldMetadata()).isEmpty(); + getCoordinatorName(updatedActions.getOldMetadata()).isPresent(); boolean newMetadataHasCoordinatedCommits = - !getCoordinator(updatedActions.getNewMetadata()).isEmpty(); + getCoordinatorName(updatedActions.getNewMetadata()).isPresent(); return oldMetadataHasCoordinatedCommits && !newMetadataHasCoordinatedCommits && commitVersion > 0; } @@ -120,10 +120,17 @@ public static Path commitDirPath(Path logPath) { return new Path(logPath, COMMIT_SUBDIR); } - public static String getCoordinator(AbstractMetadata metadata) { + /** + * Retrieves the coordinator name from the provided abstract metadata. + * If no coordinator is set, an empty optional is returned. + * + * @param metadata The abstract metadata from which to retrieve the coordinator name. + * @return The coordinator name if set, otherwise an empty optional. + */ + public static Optional getCoordinatorName(AbstractMetadata metadata) { String coordinator = metadata .getConfiguration() .get(COORDINATED_COMMITS_COORDINATOR_NAME_KEY); - return coordinator != null ? coordinator : ""; + return Optional.ofNullable(coordinator); } }