Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.apache.iceberg.actions.ImmutableRewriteTablePath;
import org.apache.iceberg.actions.RewriteTablePath;
import org.apache.iceberg.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An implementation of {@link RewriteTablePath} for Apache Ozone backed Iceberg tables.
Expand All @@ -50,6 +52,9 @@
*/
public class RewriteTablePathOzoneAction implements RewriteTablePath {

private static final Logger LOG =
LoggerFactory.getLogger(RewriteTablePathOzoneAction.class);

private String sourcePrefix;
private String targetPrefix;
private String startVersionName;
Expand Down Expand Up @@ -129,6 +134,9 @@ private Result doExecute() {
}

private void validateInputs() {
RewriteTablePathOzoneUtils.checkNonNullNonEmpty(sourcePrefix, "Source prefix");
RewriteTablePathOzoneUtils.checkNonNullNonEmpty(targetPrefix, "Target prefix");

if (sourcePrefix.equals(targetPrefix)) {
throw new IllegalArgumentException(
String.format(
Expand Down Expand Up @@ -241,7 +249,7 @@ private Set<Pair<String, String>> rewriteVersionFile(TableMetadata metadata, Str
Set<Pair<String, String>> result = new HashSet<>();
String stagingPath = RewriteTablePathUtil.stagingPath(versionFilePath, sourcePrefix, stagingDir);

System.out.println("Processing version file " + versionFilePath);
LOG.debug("Processing version file {}", versionFilePath);
TableMetadata newTableMetadata = RewriteTablePathUtil.replacePaths(metadata, sourcePrefix, targetPrefix);
TableMetadataParser.overwrite(newTableMetadata, table.io().newOutputFile(stagingPath));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.ozone.iceberg;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.BufferedReader;
Expand Down Expand Up @@ -188,6 +189,51 @@ void tablePathRewriteForStartAndEndVersionProvided() throws Exception {
assertAllInternalPathsRewritten(csvPairs, targetPrefix);
}

@Test
void executeRejectsMissingLocationPrefix() {
NullPointerException exception = assertThrows(NullPointerException.class,
() -> new RewriteTablePathOzoneAction(table)
.stagingLocation(stagingDir.toString() + "/")
.execute());

assertEquals("Source prefix is null", exception.getMessage());
}
Comment on lines +192 to +200
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not need to be checked because when we add the CLI HDDS-14946 the source and target prefix would be required fields so they can not be missing.
And once the CLI is added , the source and target prefix will be set before calling the action.
rewriteLocationPrefix is always called by the CLI before execute(), then sourcePrefix will never be null in practice, and the test adds no real value to it.

Copy link
Copy Markdown
Contributor

@sreejasahithi sreejasahithi May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating my earlier comment: while the CLI will enforce that source and target prefixes are set, I think it would be fine to keep this null check and the test as a defensive safeguard. It protects against misuse outside the CLI path and makes the contract of execute() clearer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sreejasahithi That makes sense. I kept this as a defensive check for possible non-CLI callers, and to make the execute() contract a bit clearer.


@Test
void rewriteLocationPrefixRejectsSameSourceAndTarget() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new RewriteTablePathOzoneAction(table)
.rewriteLocationPrefix(sourcePrefix, sourcePrefix)
.execute());

assertEquals("Source prefix cannot be the same as target prefix (" +
sourcePrefix + ")", exception.getMessage());
}

@Test
void startVersionRejectsUnknownVersion() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new RewriteTablePathOzoneAction(table)
.rewriteLocationPrefix(sourcePrefix, targetPrefix)
.startVersion("missing.metadata.json")
.execute());

assertEquals("Cannot find provided version file missing.metadata.json " +
"in metadata log.", exception.getMessage());
}

@Test
void endVersionRejectsUnknownVersion() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new RewriteTablePathOzoneAction(table)
.rewriteLocationPrefix(sourcePrefix, targetPrefix)
.endVersion("missing.metadata.json")
.execute());

assertEquals("Cannot find provided version file missing.metadata.json " +
"in metadata log.", exception.getMessage());
}

/**
* For every staged metadata JSON file in the CSV, parses the file and asserts that:
* - The table location starts with target
Expand Down