{"record":{"id":"d38678b3ddf26e06","repo":"apache/iceberg","slug":"expected-delete-file-s-to-start-with-prefix-s","errorCode":null,"errorMessage":"Expected delete file %s to start with prefix: %s","messagePattern":"Expected delete file (.+?) to start with prefix: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/RewriteTablePathUtil.java","lineNumber":748,"sourceCode":"   * @param io file io\n   * @param spec spec of delete file\n   * @param sourcePrefix source prefix that will be replaced\n   * @param targetPrefix target prefix to replace it\n   * @param posDeleteReaderWriter class to read and write position delete files\n   * @return the size in bytes of the rewritten file\n   */\n  public static long rewritePositionDelete(\n      DeleteFile deleteFile,\n      OutputFile outputFile,\n      FileIO io,\n      PartitionSpec spec,\n      String sourcePrefix,\n      String targetPrefix,\n      PositionDeleteReaderWriter posDeleteReaderWriter)\n      throws IOException {\n    String path = deleteFile.location();\n    if (!path.startsWith(sourcePrefix)) {\n      throw new UnsupportedOperationException(\n          String.format(\"Expected delete file %s to start with prefix: %s\", path, sourcePrefix));\n    }\n\n    // DV files (Puffin format for v3+) need special handling to rewrite internal blob metadata\n    if (ContentFileUtil.isDV(deleteFile)) {\n      return rewriteDVFile(deleteFile, outputFile, io, sourcePrefix, targetPrefix);\n    }\n\n    // For non-DV position delete files (v2), rewrite using the reader/writer\n    InputFile sourceFile = io.newInputFile(path);\n    try (CloseableIterable<Record> reader =\n        posDeleteReaderWriter.reader(sourceFile, deleteFile.format(), spec)) {\n      Record record = null;\n      CloseableIterator<Record> recordIt = reader.iterator();\n\n      if (recordIt.hasNext()) {\n        record = recordIt.next();\n      }","sourceCodeStart":730,"sourceCodeEnd":766,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/RewriteTablePathUtil.java#L730-L766","documentation":"Thrown by RewriteTablePathUtil.rewritePositionDelete when a position delete file's location does not start with sourcePrefix. The rewriter must map every delete file path from the old table location to the new one and cannot handle files outside the source prefix.","triggerScenarios":"Rewriting table path metadata when deleteFile.location() (a position delete file or DV) does not start with the given sourcePrefix — typically due to a wrong prefix argument or files left over from a prior table location.","commonSituations":"Table relocation/clone where delete files were written under an older path; typo in sourcePrefix; table registered from external location then rewritten.","solutions":["Correct the sourcePrefix argument so it matches the actual delete file locations.","Check the delete file path in the message and relocate it under the source prefix before rewriting.","Expire/delete orphan delete files referencing stale locations before the rewrite."],"exampleFix":"// before\nString prefix = \"s3://bucket/db/table\"; // delete files actually under s3://bucket/warehouse/db/table\n// after\nString prefix = \"s3://bucket/warehouse/db/table\";","handlingStrategy":"validation","validationCode":"for (DeleteFile f : allDeleteFiles(table)) {\n  Preconditions.checkArgument(f.location().startsWith(sourcePrefix), \"outside prefix: \" + f.location());\n}","typeGuard":"boolean underPrefix(String loc, String prefix) { return loc != null && loc.startsWith(prefix); }","tryCatchPattern":"try { rewritePositionDelete(...); } catch (UnsupportedOperationException e) { /* correct prefix and retry */ }","preventionTips":["Verify sourcePrefix equals the source table location","Expire stale delete files before migration","Log delete file locations during relocation planning"],"tags":["iceberg","rewrite-table-path","prefix-mismatch","position-delete"],"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"}