Class RewriteTablePathUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceClass providing engine-specific methods to read and write position delete files.static classRewrite result. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcombinePaths(String absolutePath, String relativePath) Combine a base path and a relative path.static StringReturns the file name of a path.static Stringstatic StringRewrite a path by replacing its source prefix with a target prefix.static Stringrelativize(String path, String prefix) Compute the relative path from a prefix to a given path.static TableMetadatareplacePaths(TableMetadata metadata, String sourcePrefix, String targetPrefix) Create a new table metadata object, replacing path referencesrewriteDataManifest(ManifestFile manifestFile, Set<Long> snapshotIds, OutputFile outputFile, FileIO io, int format, Map<Integer, PartitionSpec> specsById, String sourcePrefix, String targetPrefix) Rewrite a data manifest, replacing path references.rewriteDeleteManifest(ManifestFile manifestFile, Set<Long> snapshotIds, OutputFile outputFile, FileIO io, int format, Map<Integer, PartitionSpec> specsById, String sourcePrefix, String targetPrefix, String stagingLocation) Deprecated.since 1.12.0, will be removed in 1.13.0; use the overload that accepts the map of rewritten position delete file sizes.rewriteDeleteManifest(ManifestFile manifestFile, Set<Long> snapshotIds, OutputFile outputFile, FileIO io, int format, Map<Integer, PartitionSpec> specsById, String sourcePrefix, String targetPrefix, String stagingLocation, Map<String, Long> rewrittenDeleteFileSizes) Rewrite a delete manifest, replacing path references.rewriteManifestList(Snapshot snapshot, FileIO io, TableMetadata tableMetadata, Map<String, Long> rewrittenManifestLengths, String sourcePrefix, String targetPrefix, String stagingDir, String outputPath) Rewrite a manifest list representing a snapshot, replacing path references.static longrewritePositionDelete(DeleteFile deleteFile, OutputFile outputFile, FileIO io, PartitionSpec spec, String sourcePrefix, String targetPrefix, RewriteTablePathUtil.PositionDeleteReaderWriter posDeleteReaderWriter) Rewrite a position delete file, replacing path references, and return the size of the rewritten file.static voidrewritePositionDeleteFile(DeleteFile deleteFile, OutputFile outputFile, FileIO io, PartitionSpec spec, String sourcePrefix, String targetPrefix, RewriteTablePathUtil.PositionDeleteReaderWriter posDeleteReaderWriter) Deprecated.since 1.12.0, will be removed in 1.13.0; userewritePositionDelete(org.apache.iceberg.DeleteFile, org.apache.iceberg.io.OutputFile, org.apache.iceberg.io.FileIO, org.apache.iceberg.PartitionSpec, java.lang.String, java.lang.String, org.apache.iceberg.RewriteTablePathUtil.PositionDeleteReaderWriter)which returns the size of the rewritten file so callers can record an accuratefile_size_in_bytes.static StringstagingPath(String originalPath, String sourcePrefix, String stagingDir) Construct a staging path under a given staging directory, preserving relative directory structure to avoid conflicts when multiple files have the same name but different paths.
-
Field Details
-
FILE_SEPARATOR
- See Also:
-
-
Method Details
-
replacePaths
public static TableMetadata replacePaths(TableMetadata metadata, String sourcePrefix, String targetPrefix) Create a new table metadata object, replacing path references- Parameters:
metadata- source table metadatasourcePrefix- source prefix that will be replacedtargetPrefix- target prefix that will replace it- Returns:
- copy of table metadata with paths replaced
-
rewriteManifestList
public static RewriteTablePathUtil.RewriteResult<ManifestFile> rewriteManifestList(Snapshot snapshot, FileIO io, TableMetadata tableMetadata, Map<String, Long> rewrittenManifestLengths, String sourcePrefix, String targetPrefix, String stagingDir, String outputPath) Rewrite a manifest list representing a snapshot, replacing path references.- Parameters:
snapshot- snapshot represented by the manifest listio- file iotableMetadata- metadata of tablerewrittenManifestLengths- byte length of each manifest rewritten by this run, keyed by source manifest path. Only these manifests are rewritten; any other manifest in the snapshot keeps the length recorded in the source table.sourcePrefix- source prefix that will be replacedtargetPrefix- target prefix that will replace itstagingDir- staging directoryoutputPath- location to write the manifest list- Returns:
- a copy plan for manifest files whose metadata were contained in the rewritten manifest list
-
rewriteDataManifest
public static RewriteTablePathUtil.RewriteResult<DataFile> rewriteDataManifest(ManifestFile manifestFile, Set<Long> snapshotIds, OutputFile outputFile, FileIO io, int format, Map<Integer, PartitionSpec> specsById, String sourcePrefix, String targetPrefix) throws IOExceptionRewrite a data manifest, replacing path references.- Parameters:
manifestFile- source manifest file to rewritesnapshotIds- snapshot ids for filtering returned data manifest entriesoutputFile- output file to rewrite manifest file toio- file ioformat- format of the manifest filespecsById- map of partition specs by idsourcePrefix- source prefix that will be replacedtargetPrefix- target prefix that will replace it- Returns:
- a copy plan of content files in the manifest that was rewritten, recording the rewritten manifest's byte length
- Throws:
IOException
-
rewriteDeleteManifest
@Deprecated public static RewriteTablePathUtil.RewriteResult<DeleteFile> rewriteDeleteManifest(ManifestFile manifestFile, Set<Long> snapshotIds, OutputFile outputFile, FileIO io, int format, Map<Integer, PartitionSpec> specsById, String sourcePrefix, String targetPrefix, String stagingLocation) throws IOExceptionDeprecated.since 1.12.0, will be removed in 1.13.0; use the overload that accepts the map of rewritten position delete file sizes. This overload records the originalfile_size_in_bytes, which can be inconsistent with the rewritten file size on disk once embedded data file paths change length.Rewrite a delete manifest, replacing path references.- Parameters:
manifestFile- source delete manifest to rewritesnapshotIds- snapshot ids for filtering returned delete manifest entriesoutputFile- output file to rewrite manifest file toio- file ioformat- format of the manifest filespecsById- map of partition specs by idsourcePrefix- source prefix that will be replacedtargetPrefix- target prefix that will replace itstagingLocation- staging location for rewritten files (referred delete file will be rewritten here)- Returns:
- a copy plan of content files in the manifest that was rewritten
- Throws:
IOException
-
rewriteDeleteManifest
public static RewriteTablePathUtil.RewriteResult<DeleteFile> rewriteDeleteManifest(ManifestFile manifestFile, Set<Long> snapshotIds, OutputFile outputFile, FileIO io, int format, Map<Integer, PartitionSpec> specsById, String sourcePrefix, String targetPrefix, String stagingLocation, Map<String, throws IOExceptionLong> rewrittenDeleteFileSizes) Rewrite a delete manifest, replacing path references.This is a metadata-only operation: position delete file content is rewritten separately (see
rewritePositionDelete(org.apache.iceberg.DeleteFile, org.apache.iceberg.io.OutputFile, org.apache.iceberg.io.FileIO, org.apache.iceberg.PartitionSpec, java.lang.String, java.lang.String, org.apache.iceberg.RewriteTablePathUtil.PositionDeleteReaderWriter)). The actual sizes of those rewritten files are supplied viarewrittenDeleteFileSizesand recorded in the manifest so thatfile_size_in_bytesstays consistent with the rewritten file on disk.- Parameters:
manifestFile- source delete manifest to rewritesnapshotIds- snapshot ids for filtering returned delete manifest entriesoutputFile- output file to rewrite manifest file toio- file ioformat- format of the manifest filespecsById- map of partition specs by idsourcePrefix- source prefix that will be replacedtargetPrefix- target prefix that will replace itstagingLocation- staging location for rewritten position delete filesrewrittenDeleteFileSizes- map from source position delete file path to the actual size of the rewritten file; entries absent from the map keep their original size- Returns:
- a copy plan of content files in the manifest that was rewritten, recording the rewritten manifest's byte length
- Throws:
IOException
-
rewritePositionDeleteFile
@Deprecated public static void rewritePositionDeleteFile(DeleteFile deleteFile, OutputFile outputFile, FileIO io, PartitionSpec spec, String sourcePrefix, String targetPrefix, RewriteTablePathUtil.PositionDeleteReaderWriter posDeleteReaderWriter) throws IOException Deprecated.since 1.12.0, will be removed in 1.13.0; userewritePositionDelete(org.apache.iceberg.DeleteFile, org.apache.iceberg.io.OutputFile, org.apache.iceberg.io.FileIO, org.apache.iceberg.PartitionSpec, java.lang.String, java.lang.String, org.apache.iceberg.RewriteTablePathUtil.PositionDeleteReaderWriter)which returns the size of the rewritten file so callers can record an accuratefile_size_in_bytes.Rewrite a position delete file, replacing path references.- Parameters:
deleteFile- source delete file to be rewrittenoutputFile- output file to rewrite delete file toio- file iospec- spec of delete filesourcePrefix- source prefix that will be replacedtargetPrefix- target prefix to replace itposDeleteReaderWriter- class to read and write position delete files- Throws:
IOException
-
rewritePositionDelete
public static long rewritePositionDelete(DeleteFile deleteFile, OutputFile outputFile, FileIO io, PartitionSpec spec, String sourcePrefix, String targetPrefix, RewriteTablePathUtil.PositionDeleteReaderWriter posDeleteReaderWriter) throws IOException Rewrite a position delete file, replacing path references, and return the size of the rewritten file.The size is measured from the writer after it is closed (rather than via a separate
getLength()/HEAD call), so it is accurate even on file systems where the length of an in-progress write underreports. Callers record this size asfile_size_in_bytesin the rewritten manifest.- Parameters:
deleteFile- source position delete file to rewriteoutputFile- output file to write the rewritten delete file toio- file iospec- spec of delete filesourcePrefix- source prefix that will be replacedtargetPrefix- target prefix to replace itposDeleteReaderWriter- class to read and write position delete files- Returns:
- the size in bytes of the rewritten file
- Throws:
IOException
-
newPath
Rewrite a path by replacing its source prefix with a target prefix.If the path equals the source prefix (representing a directory location), the result will be the target prefix with a trailing separator.
Trailing separators are normalized: "/a" and "/a/" are treated as equivalent for both path and sourcePrefix.
- Parameters:
path- absolute path to rewritesourcePrefix- source prefix that will be replacedtargetPrefix- target prefix that will replace it- Returns:
- new path with source prefix replaced by target prefix
- Throws:
IllegalArgumentException- if path is not under or equal to sourcePrefix
-
combinePaths
Combine a base path and a relative path.If the relative path is empty, returns the absolute path unchanged. Otherwise, ensures a separator between the base and relative path.
- Parameters:
absolutePath- the base pathrelativePath- the relative path to append (may be empty)- Returns:
- the combined path, or absolutePath unchanged if relativePath is empty
-
fileName
Returns the file name of a path. -
relativize
Compute the relative path from a prefix to a given path.If the path is under the prefix, returns the portion after the prefix. If the path equals the prefix (representing the root directory itself), returns an empty string.
Trailing separators are normalized: "/a" and "/a/" are treated as equivalent for both path and prefix. This allows flexibility when paths come from different sources that may or may not include trailing separators.
- Parameters:
path- absolute path to relativizeprefix- prefix path to remove- Returns:
- relative path from prefix to path, or empty string if path equals prefix
- Throws:
IllegalArgumentException- if path is not under or equal to prefix
-
maybeAppendFileSeparator
-
stagingPath
Construct a staging path under a given staging directory, preserving relative directory structure to avoid conflicts when multiple files have the same name but different paths.- Parameters:
originalPath- source pathsourcePrefix- source prefix to be replacedstagingDir- staging directory- Returns:
- a staging path under the staging directory that preserves the relative path structure
-