{"record":{"id":"b5e0e8acb795865f","repo":"apache/iceberg","slug":"cannot-incrementally-scan-table-of-type-s","errorCode":null,"errorMessage":"Cannot incrementally scan table of type %s","messagePattern":"Cannot incrementally scan table of type (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/BaseMetadataTableScan.java","lineNumber":50,"sourceCode":"  protected BaseMetadataTableScan(\n      Table table, Schema schema, MetadataTableType tableType, TableScanContext context) {\n    super(table, schema, context);\n    this.tableType = tableType;\n  }\n\n  /**\n   * Type of scan being performed, such as {@link MetadataTableType#ALL_DATA_FILES} when scanning a\n   * table's {@link org.apache.iceberg.AllDataFilesTable}.\n   *\n   * <p>Used for logging and error messages.\n   */\n  protected MetadataTableType tableType() {\n    return tableType;\n  }\n\n  @Override\n  public TableScan appendsBetween(long fromSnapshotId, long toSnapshotId) {\n    throw new UnsupportedOperationException(\n        String.format(\"Cannot incrementally scan table of type %s\", tableType()));\n  }\n\n  @Override\n  public TableScan appendsAfter(long fromSnapshotId) {\n    throw new UnsupportedOperationException(\n        String.format(\"Cannot incrementally scan table of type %s\", tableType()));\n  }\n\n  @Override\n  public long targetSplitSize() {\n    long tableValue =\n        ((BaseTable) table())\n            .operations()\n            .current()\n            .propertyAsLong(\n                TableProperties.METADATA_SPLIT_SIZE, TableProperties.METADATA_SPLIT_SIZE_DEFAULT);\n    return PropertyUtil.propertyAsLong(options(), TableProperties.SPLIT_SIZE, tableValue);","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/BaseMetadataTableScan.java#L32-L68","documentation":"appendsBetween is only implemented by the incremental-scan metadata table (MetadataTableType.ENTRIES-based IncrementalAppendScan). BaseMetadataTableScan is the shared base for all metadata table scans, and most types (files, history, partitions, refs, etc.) cannot answer incremental append queries, so they throw UnsupportedOperationException.","triggerScenarios":"Calling ((IncrementalScan) MetadataTableUtils.createMetadataTableInstance(...)).appendsBetween(...) on a metadata table that is not the incremental-append table, e.g. loading table.references() then calling appendsBetween.","commonSituations":"Generic code that takes a Table and unconditionally calls appendsBetween assuming any table (including metadata tables) supports it.","solutions":["Only call appendsBetween on the incremental append metadata table (TableIdentifier with name 'append-scan' style usage) or the data table's createIncrementalScan","Guard with instanceof TableScanIncrementalAppend/feature checks before invoking","Compute appends manually from history/entries metadata tables if the type lacks support"],"exampleFix":"// before\nMetadataTableType type = ...; // e.g. FILES\nTable meta = MetadataTableUtils.createMetadataTableInstance(ops, ..., type);\nmeta.newScan().appendsBetween(from, to); // throws\n// after\nTable meta = MetadataTableUtils.createMetadataTableInstance(ops, ..., MetadataTableType.INCREMENTAL_APPEND_SCAN);\nmeta.newScan().appendsBetween(from, to);","handlingStrategy":"type-guard","validationCode":"boolean supportsIncremental = table instanceof IncrementalAppendScan || table.name().endsWith(\"incremental-append-scan\");","typeGuard":"if (scan instanceof IncrementalAppendScan) { ((IncrementalAppendScan) scan).appendsBetween(from, to); } else { /* unsupported */ }","tryCatchPattern":"try { return scan.appendsBetween(from, to); } catch (UnsupportedOperationException e) { return manualIncrementalFromHistory(table, from, to); }","preventionTips":["Only request incremental scans on the data table or the incremental-append metadata table","Check metadata table type before invoking appendsBetween","Centralize incremental-scan access behind a capability-checked helper"],"tags":["metadata-table","incremental-scan","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}