{"record":{"id":"e20561c90cc714ad","repo":"apache/iceberg","slug":"expected-delete-file-to-be-under-the-source-prefix","errorCode":null,"errorMessage":"Expected delete file to be under the source prefix:  but was ","messagePattern":"Expected delete file to be under the source prefix:  but was ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/RewriteTablePathUtil.java","lineNumber":611,"sourceCode":"      case ADDED:\n        writer.add(file);\n        break;\n      case EXISTING:\n        writer.existing(\n            file, entry.snapshotId(), entry.dataSequenceNumber(), entry.fileSequenceNumber());\n        break;\n      case DELETED:\n        writer.delete(file, entry.dataSequenceNumber(), entry.fileSequenceNumber());\n        break;\n    }\n  }\n\n  private static DeleteFile newEqualityDeleteEntry(\n      DeleteFile file, PartitionSpec spec, String sourcePrefix, String targetPrefix) {\n    String path = file.location();\n\n    if (!path.startsWith(sourcePrefix)) {\n      throw new UnsupportedOperationException(\n          \"Expected delete file to be under the source prefix: \"\n              + sourcePrefix\n              + \" but was \"\n              + path);\n    }\n    int[] equalityFieldIds = file.equalityFieldIds().stream().mapToInt(Integer::intValue).toArray();\n    String newPath = newPath(path, sourcePrefix, targetPrefix);\n    return FileMetadata.deleteFileBuilder(spec)\n        .ofEqualityDeletes(equalityFieldIds)\n        .copy(file)\n        .withPath(newPath)\n        .withSplitOffsets(file.splitOffsets())\n        .build();\n  }\n\n  private static DeleteFile newPositionDeleteEntry(\n      DeleteFile file,\n      PartitionSpec spec,","sourceCodeStart":593,"sourceCodeEnd":629,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/RewriteTablePathUtil.java#L593-L629","documentation":"Thrown by RewriteTablePathUtil.newEqualityDeleteEntry when rewriting a table's metadata at a new location: an equality delete file's location does not start with the expected source prefix, so it cannot be remapped to the target prefix. The utility can only rewrite files that lived under the original table location.","triggerScenarios":"Calling RewriteTablePathUtil to rewrite table path metadata when a DeleteFile (equality delete) references a location outside sourcePrefix — e.g. the table was moved, imported from another location, or a stale/custom table location is supplied.","commonSituations":"Migrating a table between buckets/paths where delete files were written under an older location; supplying a wrong sourcePrefix to the rewrite utility; tables copied or registered from a different filesystem location.","solutions":["Verify sourcePrefix matches the actual location prefix of all delete files in the table metadata.","Ensure the table being rewritten was not relocated/imported without updating its data/delete file paths; rewrite data first or use a prefix that covers all files.","Locate the offending delete file path (printed in the message) and manually relocate it under the source prefix or fix the metadata."],"exampleFix":"// before\nRewriteTablePathUtil.rewrite(toTable, fromTable, \"s3://old-bucket/wrong-prefix\", \"s3://new-bucket/table\");\n// after\nRewriteTablePathUtil.rewrite(toTable, fromTable, \"s3://old-bucket/warehouse/db/table\", \"s3://new-bucket/table\");","handlingStrategy":"validation","validationCode":"DeleteFile f = ...;\nif (!f.location().startsWith(sourcePrefix)) {\n  throw new IllegalStateException(\"Delete file outside source prefix: \" + f.location());\n}","typeGuard":"boolean isUnderPrefix(String path, String prefix) { return path != null && prefix != null && path.startsWith(prefix); }","tryCatchPattern":"try { rewriteTablePath(...); } catch (UnsupportedOperationException e) { /* inspect path in message, fix sourcePrefix */ }","preventionTips":["Always derive sourcePrefix from the source table's actual location","Audit delete file locations before rewriting table paths","Keep data and delete files under one table location"],"tags":["iceberg","rewrite-table-path","prefix-mismatch","delete-file"],"backgroundTag":"invalid-argument-value","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}