Class SparkDistributedDataScan

java.lang.Object
org.apache.iceberg.SnapshotScan<ThisT,T,G>
org.apache.iceberg.SparkDistributedDataScan
All Implemented Interfaces:
org.apache.iceberg.BatchScan, org.apache.iceberg.Scan<org.apache.iceberg.BatchScan,org.apache.iceberg.ScanTask,org.apache.iceberg.ScanTaskGroup<org.apache.iceberg.ScanTask>>

public class SparkDistributedDataScan extends org.apache.iceberg.SnapshotScan<ThisT,T,G>
A batch data scan that can utilize Spark cluster resources for planning.

This scan remotely filters manifests, fetching only the relevant data and delete files to the driver. The delete file assignment is done locally after the remote filtering step. Such approach is beneficial if the remote parallelism is much higher than the number of driver cores.

This scan is best suited for queries with selective filters on lower/upper bounds across all partitions, or against poorly clustered metadata. This allows job planning to benefit from highly concurrent remote filtering while not incurring high serialization and data transfer costs. This class is also useful for full table scans over large tables but the cost of bringing data and delete file details to the driver may become noticeable. Make sure to follow the performance tips below in such cases.

Ensure the filtered metadata size doesn't exceed the driver's max result size. For large table scans, consider increasing `spark.driver.maxResultSize` to avoid job failures.

Performance tips:

  • Enable Kryo serialization (`spark.serializer`)
  • Increase the number of driver cores (`spark.driver.cores`)
  • Tune the number of threads used to fetch task results (`spark.resultGetter.threads`)
  • Field Details

    • SCAN_COLUMNS

      protected static final List<String> SCAN_COLUMNS
    • SCAN_WITH_STATS_COLUMNS

      protected static final List<String> SCAN_WITH_STATS_COLUMNS
    • DELETE_SCAN_COLUMNS

      protected static final List<String> DELETE_SCAN_COLUMNS
    • DELETE_SCAN_WITH_STATS_COLUMNS

      protected static final List<String> DELETE_SCAN_WITH_STATS_COLUMNS
    • PLAN_SCANS_WITH_WORKER_POOL

      protected static final boolean PLAN_SCANS_WITH_WORKER_POOL
  • Constructor Details

    • SparkDistributedDataScan

      public SparkDistributedDataScan(org.apache.spark.sql.SparkSession spark, org.apache.iceberg.Table table, SparkReadConf readConf)
  • Method Details

    • newRefinedScan

      protected org.apache.iceberg.BatchScan newRefinedScan(org.apache.iceberg.Table newTable, org.apache.iceberg.Schema newSchema, org.apache.iceberg.TableScanContext newContext)
    • remoteParallelism

      protected int remoteParallelism()
    • dataPlanningMode

      protected org.apache.iceberg.PlanningMode dataPlanningMode()
    • shouldCopyRemotelyPlannedDataFiles

      protected boolean shouldCopyRemotelyPlannedDataFiles()
    • planDataRemotely

      protected Iterable<org.apache.iceberg.io.CloseableIterable<org.apache.iceberg.DataFile>> planDataRemotely(List<org.apache.iceberg.ManifestFile> dataManifests, boolean withColumnStats)
    • deletePlanningMode

      protected org.apache.iceberg.PlanningMode deletePlanningMode()
    • planDeletesRemotely

      protected org.apache.iceberg.DeleteFileIndex planDeletesRemotely(List<org.apache.iceberg.ManifestFile> deleteManifests)
    • doPlanFiles

      protected org.apache.iceberg.io.CloseableIterable<org.apache.iceberg.ScanTask> doPlanFiles()
      Specified by:
      doPlanFiles in class org.apache.iceberg.SnapshotScan<org.apache.iceberg.BatchScan,org.apache.iceberg.ScanTask,org.apache.iceberg.ScanTaskGroup<org.apache.iceberg.ScanTask>>
    • planTasks

      public org.apache.iceberg.io.CloseableIterable<org.apache.iceberg.ScanTaskGroup<org.apache.iceberg.ScanTask>> planTasks()
      Specified by:
      planTasks in interface org.apache.iceberg.Scan<org.apache.iceberg.BatchScan,org.apache.iceberg.ScanTask,org.apache.iceberg.ScanTaskGroup<org.apache.iceberg.ScanTask>>
    • useSnapshotSchema

      protected boolean useSnapshotSchema()
      Overrides:
      useSnapshotSchema in class org.apache.iceberg.SnapshotScan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • newManifestGroup

      protected org.apache.iceberg.ManifestGroup newManifestGroup(List<org.apache.iceberg.ManifestFile> arg0, List<org.apache.iceberg.ManifestFile> arg1)
    • newManifestGroup

      protected org.apache.iceberg.ManifestGroup newManifestGroup(List<org.apache.iceberg.ManifestFile> arg0, boolean arg1)
    • newManifestGroup

      protected org.apache.iceberg.ManifestGroup newManifestGroup(List<org.apache.iceberg.ManifestFile> arg0, List<org.apache.iceberg.ManifestFile> arg1, boolean arg2)
    • table

      public org.apache.iceberg.Table table()
    • io

      @Deprecated protected org.apache.iceberg.io.FileIO io()
      Deprecated.
    • fileIO

      public Supplier<org.apache.iceberg.io.FileIO> fileIO()
      Specified by:
      fileIO in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • tableSchema

      protected org.apache.iceberg.Schema tableSchema()
    • schemas

      protected Map<Integer,org.apache.iceberg.Schema> schemas()
    • context

      protected org.apache.iceberg.TableScanContext context()
    • options

      protected Map<String,String> options()
    • scanColumns

      protected List<String> scanColumns()
    • shouldReturnColumnStats

      protected boolean shouldReturnColumnStats()
    • columnsToKeepStats

      protected Set<Integer> columnsToKeepStats()
    • shouldIgnoreResiduals

      protected boolean shouldIgnoreResiduals()
    • residualFilter

      protected org.apache.iceberg.expressions.Expression residualFilter()
    • shouldPlanWithExecutor

      protected boolean shouldPlanWithExecutor()
    • planExecutor

      protected ExecutorService planExecutor()
    • option

      public org.apache.iceberg.BatchScan option(String arg0, String arg1)
      Specified by:
      option in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • project

      public org.apache.iceberg.BatchScan project(org.apache.iceberg.Schema arg0)
      Specified by:
      project in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • caseSensitive

      public org.apache.iceberg.BatchScan caseSensitive(boolean arg0)
      Specified by:
      caseSensitive in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • isCaseSensitive

      public boolean isCaseSensitive()
      Specified by:
      isCaseSensitive in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • includeColumnStats

      public org.apache.iceberg.BatchScan includeColumnStats()
      Specified by:
      includeColumnStats in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • includeColumnStats

      public org.apache.iceberg.BatchScan includeColumnStats(Collection<String> arg0)
      Specified by:
      includeColumnStats in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • select

      public org.apache.iceberg.BatchScan select(Collection<String> arg0)
      Specified by:
      select in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • filter

      public org.apache.iceberg.BatchScan filter(org.apache.iceberg.expressions.Expression arg0)
      Specified by:
      filter in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • filter

      public org.apache.iceberg.expressions.Expression filter()
      Specified by:
      filter in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • ignoreResiduals

      public org.apache.iceberg.BatchScan ignoreResiduals()
      Specified by:
      ignoreResiduals in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • planWith

      public org.apache.iceberg.BatchScan planWith(ExecutorService arg0)
      Specified by:
      planWith in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • schema

      public org.apache.iceberg.Schema schema()
      Specified by:
      schema in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • targetSplitSize

      public long targetSplitSize()
      Specified by:
      targetSplitSize in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • splitLookback

      public int splitLookback()
      Specified by:
      splitLookback in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • splitOpenFileCost

      public long splitOpenFileCost()
      Specified by:
      splitOpenFileCost in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • metricsReporter

      public org.apache.iceberg.BatchScan metricsReporter(org.apache.iceberg.metrics.MetricsReporter arg0)
      Specified by:
      metricsReporter in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>
    • minRowsRequested

      public org.apache.iceberg.BatchScan minRowsRequested(long arg0)
      Specified by:
      minRowsRequested in interface org.apache.iceberg.Scan<ThisT extends Object,T extends org.apache.iceberg.ScanTask,G extends org.apache.iceberg.ScanTaskGroup<T>>