@@ -142,19 +142,24 @@ case class CometScanRule(session: SparkSession) extends Rule[SparkPlan] with Com
142142 conf.getConfString(" parquet.crypto.factory.class" , " " ).nonEmpty &&
143143 conf.getConfString(" parquet.encryption.kms.client.class" , " " ).nonEmpty
144144
145- var scanImpl = COMET_NATIVE_SCAN_IMPL .get()
146-
147- // if scan is auto then pick the best available scan
148- if (scanImpl == SCAN_AUTO ) {
149- if (encryptionEnabled) {
150- logInfo(
151- s " Auto scan mode falling back to $SCAN_NATIVE_COMET because " +
152- s " $SCAN_NATIVE_ICEBERG_COMPAT does not support reading encrypted Parquet files " )
153- scanImpl = SCAN_NATIVE_COMET
154- } else {
155- scanImpl = selectScan(scanExec, r.partitionSchema)
145+ // Derive scan mode and save it to session level to avoid recomputation
146+ val scanImpl = CometScanRule .currentScanImplementation.getOrElse({
147+ var scanModeImpl = COMET_NATIVE_SCAN_IMPL .get()
148+ // if scan is auto then pick the best available scan
149+ if (scanModeImpl == SCAN_AUTO ) {
150+ if (encryptionEnabled) {
151+ logInfo(
152+ s " Auto scan mode falling back to $SCAN_NATIVE_COMET because " +
153+ s " $SCAN_NATIVE_ICEBERG_COMPAT does not support reading encrypted Parquet files " )
154+ scanModeImpl = SCAN_NATIVE_COMET
155+ } else {
156+ scanModeImpl = selectScan(scanExec, r.partitionSchema)
157+ }
156158 }
157- }
159+
160+ CometScanRule .currentScanImplementation = Some (scanModeImpl)
161+ scanModeImpl
162+ })
158163
159164 if (scanImpl == SCAN_NATIVE_DATAFUSION && ! COMET_EXEC_ENABLED .get()) {
160165 fallbackReasons +=
@@ -409,7 +414,13 @@ object CometScanRule extends Logging {
409414 * session, but we reset the cache once it reaches a fixed size to prevent it growing
410415 * indefinitely.
411416 */
412- val configValidityMapMaxSize = 1024
417+ private val configValidityMapMaxSize = 1024
418+
419+ // Comet derives on fly scan implementation approach and this variable to access the selected value
420+ private var currentScanImplementation : Option [String ] = None
421+
422+ // Current selected scan implementation
423+ def getCurrentScanImplementation : Option [String ] = currentScanImplementation
413424
414425 def validateObjectStoreConfig (
415426 filePath : String ,
@@ -450,6 +461,5 @@ object CometScanRule extends Logging {
450461 throw e
451462 }
452463 }
453-
454464 }
455465}
0 commit comments