Skip to content

Commit

Permalink
Spark 3.4: Remove use of File.Separator in RewriteTablePath (apache#…
Browse files Browse the repository at this point in the history
  • Loading branch information
manuzhang authored Feb 7, 2025
1 parent e91655b commit 44aca93
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.iceberg.spark.actions;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -182,9 +181,13 @@ private void validateInputs() {
validateAndSetStartVersion();

if (stagingDir == null) {
stagingDir = getMetadataLocation(table) + "copy-table-staging-" + UUID.randomUUID() + "/";
} else if (!stagingDir.endsWith("/")) {
stagingDir = stagingDir + "/";
stagingDir =
getMetadataLocation(table)
+ "copy-table-staging-"
+ UUID.randomUUID()
+ RewriteTablePathUtil.FILE_SEPARATOR;
} else {
stagingDir = RewriteTablePathUtil.maybeAppendFileSeparator(stagingDir);
}
}

Expand Down Expand Up @@ -365,7 +368,8 @@ private Pair<String, String> rewriteVersionFile(TableMetadata metadata, String v
TableMetadata newTableMetadata =
RewriteTablePathUtil.replacePaths(metadata, sourcePrefix, targetPrefix);
TableMetadataParser.overwrite(newTableMetadata, table.io().newOutputFile(stagingPath));
return Pair.of(stagingPath, newPath(versionFilePath, sourcePrefix, targetPrefix));
return Pair.of(
stagingPath, RewriteTablePathUtil.newPath(versionFilePath, sourcePrefix, targetPrefix));
}

/**
Expand Down Expand Up @@ -396,7 +400,9 @@ private RewriteResult<ManifestFile> rewriteManifestList(

result.append(rewriteResult);
// add the manifest list copy plan itself to the result
result.copyPlan().add(Pair.of(outputPath, newPath(path, sourcePrefix, targetPrefix)));
result
.copyPlan()
.add(Pair.of(outputPath, RewriteTablePathUtil.newPath(path, sourcePrefix, targetPrefix)));
return result;
}

Expand Down Expand Up @@ -684,15 +690,10 @@ private boolean fileExist(String path) {
return table.io().newInputFile(path).exists();
}

private static String newPath(String path, String sourcePrefix, String targetPrefix) {
return RewriteTablePathUtil.combinePaths(
targetPrefix, RewriteTablePathUtil.relativize(path, sourcePrefix));
}

private String getMetadataLocation(Table tbl) {
String currentMetadataPath =
((HasTableOperations) tbl).operations().current().metadataFileLocation();
int lastIndex = currentMetadataPath.lastIndexOf(File.separator);
int lastIndex = currentMetadataPath.lastIndexOf(RewriteTablePathUtil.FILE_SEPARATOR);
String metadataDir = "";
if (lastIndex != -1) {
metadataDir = currentMetadataPath.substring(0, lastIndex + 1);
Expand Down

0 comments on commit 44aca93

Please sign in to comment.