@@ -418,8 +418,18 @@ public boolean supportsFileCache() {
418418 */
419419 @ Override
420420 public List <ConnectorScanRange > planScan (ConnectorSession session , ConnectorScanRequest request ) {
421- return planScanInternal (session , request .getTableHandle (), request .getColumns (),
422- request .getFilter (), request .isCountPushdown ());
421+ IcebergTableHandle handle = (IcebergTableHandle ) request .getTableHandle ();
422+ try {
423+ return planScanInternal (session , handle , request .getColumns (),
424+ request .getFilter (), request .isCountPushdown ());
425+ } catch (RuntimeException e ) {
426+ // Normal data scans and native position_deletes run on File Scanner V2. Keep the serialized JNI
427+ // system-table route untouched because its deferred reads belong to the V1 scanner contract.
428+ if (!handle .isSystemTable () || isPositionDeletesSysTable (handle )) {
429+ throw IcebergExceptionUtils .wrapMetadataReadFailure (handle , e );
430+ }
431+ throw e ;
432+ }
423433 }
424434
425435 /**
@@ -465,8 +475,10 @@ public long streamingSplitEstimate(ConnectorSession session, ConnectorTableHandl
465475 fileCount += (added == null ? 0 : added ) + (existing == null ? 0 : existing );
466476 }
467477 } catch (IOException e ) {
468- throw new RuntimeException ("Failed to count iceberg manifest files for batch decision, error message is:"
469- + e .getMessage (), e );
478+ throw IcebergExceptionUtils .wrapTableLoadFailure (iceHandle , e ,
479+ "Failed to count iceberg manifest files for batch decision, error message is:" );
480+ } catch (RuntimeException e ) {
481+ throw IcebergExceptionUtils .wrapMetadataReadFailure (iceHandle , e );
470482 }
471483 return fileCount >= threshold ? fileCount : -1 ;
472484 }
@@ -501,9 +513,15 @@ public ConnectorSplitSource streamSplits(ConnectorSession session, ConnectorTabl
501513 long fileSplitSize = sessionLong (session , FILE_SPLIT_SIZE , 0L );
502514 long sliceSize = fileSplitSize > 0 ? fileSplitSize
503515 : sessionLong (session , MAX_FILE_SPLIT_SIZE , DEFAULT_MAX_FILE_SPLIT_SIZE );
504- CloseableIterable <FileScanTask > tasks = streamingFileScanTasks (scan , session , table , filter , sliceSize );
505- return new IcebergStreamingSplitSource (tasks , table , formatVersion , partitioned ,
506- orderedPartitionKeys , zone , uriNormalizer , sliceSize , iceHandle .getRewriteFileScope ());
516+ try {
517+ CloseableIterable <FileScanTask > tasks = streamingFileScanTasks (
518+ scan , session , table , filter , sliceSize );
519+ return new IcebergStreamingSplitSource (tasks , table , formatVersion , partitioned ,
520+ orderedPartitionKeys , zone , uriNormalizer , sliceSize ,
521+ iceHandle .getRewriteFileScope (), iceHandle );
522+ } catch (RuntimeException e ) {
523+ throw IcebergExceptionUtils .wrapMetadataReadFailure (iceHandle , e );
524+ }
507525 }
508526
509527 private static ConnectorSplitSource emptySplitSource () {
@@ -564,6 +582,7 @@ private final class IcebergStreamingSplitSource implements ConnectorSplitSource
564582 private final UnaryOperator <String > uriNormalizer ;
565583 private final long sliceSize ;
566584 private final Set <String > rewriteScope ;
585+ private final IcebergTableHandle handle ;
567586 // Lazily opened on first hasNext() so the ctor never throws — iceberg's ParallelIterable submits
568587 // manifest readers in tasks.iterator(), which can fail; opening it eagerly here would throw out of
569588 // streamSplits() BEFORE the source is returned, leaking the planFiles() iterable (the engine pump's
@@ -578,7 +597,8 @@ private final class IcebergStreamingSplitSource implements ConnectorSplitSource
578597
579598 IcebergStreamingSplitSource (CloseableIterable <FileScanTask > tasks , Table table , int formatVersion ,
580599 boolean partitioned , List <String > orderedPartitionKeys , ZoneId zone ,
581- UnaryOperator <String > uriNormalizer , long sliceSize , Set <String > rewriteScope ) {
600+ UnaryOperator <String > uriNormalizer , long sliceSize , Set <String > rewriteScope ,
601+ IcebergTableHandle handle ) {
582602 this .tasks = tasks ;
583603 this .table = table ;
584604 this .formatVersion = formatVersion ;
@@ -588,25 +608,31 @@ private final class IcebergStreamingSplitSource implements ConnectorSplitSource
588608 this .uriNormalizer = uriNormalizer ;
589609 this .sliceSize = sliceSize ;
590610 this .rewriteScope = rewriteScope ;
611+ this .handle = handle ;
591612 }
592613
593614 @ Override
594615 public boolean hasNext () {
595- if (buffered != null ) {
596- return true ;
597- }
598- if (iterator == null ) {
599- iterator = tasks .iterator ();
600- }
601- while (iterator .hasNext ()) {
602- IcebergScanRange range = buildRangeForTask (iterator .next (), table , formatVersion , partitioned ,
603- orderedPartitionKeys , zone , uriNormalizer , sliceSize , rewriteScope , null , scratch );
604- if (range != null ) {
605- buffered = range ;
616+ try {
617+ if (buffered != null ) {
606618 return true ;
607619 }
620+ if (iterator == null ) {
621+ iterator = tasks .iterator ();
622+ }
623+ while (iterator .hasNext ()) {
624+ IcebergScanRange range = buildRangeForTask (iterator .next (), table , formatVersion , partitioned ,
625+ orderedPartitionKeys , zone , uriNormalizer , sliceSize , rewriteScope , null , scratch );
626+ if (range != null ) {
627+ buffered = range ;
628+ return true ;
629+ }
630+ }
631+ return false ;
632+ } catch (RuntimeException e ) {
633+ // Lazy manifest opening happens on the split-pump thread, after streamSplits has returned.
634+ throw IcebergExceptionUtils .wrapMetadataReadFailure (handle , e );
608635 }
609- return false ;
610636 }
611637
612638 @ Override
@@ -1606,7 +1632,11 @@ public Map<String, String> getScanNodeProperties(
16061632 if (!systemTable ) {
16071633 scanSchema = pinnedSchema (table , iceHandle );
16081634 exactScan = buildScan (table , iceHandle , filter , session );
1609- applicableEqualityDeleteFieldIds = cachedApplicableEqualityDeleteFieldIds (table , exactScan );
1635+ try {
1636+ applicableEqualityDeleteFieldIds = cachedApplicableEqualityDeleteFieldIds (table , exactScan );
1637+ } catch (RuntimeException e ) {
1638+ throw IcebergExceptionUtils .wrapMetadataReadFailure (iceHandle , e );
1639+ }
16101640 hasApplicableEqualityDeletes = !applicableEqualityDeleteFieldIds .isEmpty ();
16111641 Optional <Map <Integer , List <String >>> nameMapping = IcebergSchemaUtils .extractNameMapping (table );
16121642 if (requiresCurrentScanSemantics (
@@ -1625,11 +1655,17 @@ public Map<String, String> getScanNodeProperties(
16251655 // PERF-03: the non-system format resolution falls back to an unfiltered whole-table planFiles() when the
16261656 // table sets neither write-format nor write.format.default; memoize that inference per (table, snapshot)
16271657 // across queries via formatCache (pure metadata, no credential gate). Null cache (offline) resolves live.
1628- props .put (ScanNodePropertyKeys .FILE_FORMAT_TYPE ,
1629- systemTable ? "jni"
1630- : IcebergWriterHelper .getFileFormat (table ,
1658+ String fileFormatType = "jni" ;
1659+ if (!systemTable ) {
1660+ try {
1661+ fileFormatType = IcebergWriterHelper .getFileFormat (table ,
16311662 TableIdentifier .of (iceHandle .getDbName (), iceHandle .getTableName ()), formatCache )
1632- .name ().toLowerCase (Locale .ROOT ));
1663+ .name ().toLowerCase (Locale .ROOT );
1664+ } catch (RuntimeException e ) {
1665+ throw IcebergExceptionUtils .wrapMetadataReadFailure (iceHandle , e );
1666+ }
1667+ }
1668+ props .put (ScanNodePropertyKeys .FILE_FORMAT_TYPE , fileFormatType );
16331669 // [D-065] System (metadata) tables ($snapshots/$files/...) read via the JNI serialized-split path
16341670 // (planSystemTableScan): the metadata-table schema travels INSIDE the serialized FileScanTask, so BE
16351671 // needs neither the base-table path_partition_keys (a metadata table is not base-spec partitioned ->
0 commit comments