szehon-ho commented on code in PR #50538:
URL: https://github.com/apache/spark/pull/50538#discussion_r2036146614


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala:
##########
@@ -256,20 +256,32 @@ class FindDataSourceTable(sparkSession: SparkSession) 
extends Rule[LogicalPlan]
       QualifiedTableName(table.identifier.catalog.get, table.database, 
table.identifier.table)
     val catalog = sparkSession.sessionState.catalog
     val dsOptions = DataSourceUtils.generateDatasourceOptions(extraOptions, 
table)
-    catalog.getCachedPlan(qualifiedTableName, () => {
+    lazy val newPlan = {
       val dataSource =
         DataSource(
           sparkSession,
-          // In older version(prior to 2.1) of Spark, the table schema can be 
empty and should be
-          // inferred at runtime. We should still support it.
-          userSpecifiedSchema = if (table.schema.isEmpty) None else 
Some(table.schema),
+          className = table.provider.get,
+          userSpecifiedSchema = Some(table.schema),
           partitionColumns = table.partitionColumnNames,
           bucketSpec = table.bucketSpec,
-          className = table.provider.get,
           options = dsOptions,
           catalogTable = Some(table))
       LogicalRelation(dataSource.resolveRelation(checkFilesExist = false), 
table)
-    })
+    }
+    lazy val cachedPlan = catalog.getCachedPlan(qualifiedTableName, () => 
newPlan)

Review Comment:
   Sorry , clarifying one possible way (from discussion offline) 
   
   catalog.getCachedPlan(...) match {
      case LogicalRelation(HadoopFsRelation(... options)) if diff(options, 
dsOptions) => newPlan
      case cachedPlan => cachedPlan
    }
    
   Its slightly clearer to me, but optional. 
   
   If we use a val though, I think we dont need lazy val as it wasnt lazy val 
before this change?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to