szehon-ho commented on code in PR #50538: URL: https://github.com/apache/spark/pull/50538#discussion_r2035985013
########## 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: Nit: can skip lazy val here and just use the expression to match directly? catalog.getCachedPlan ... match { ########## 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) + cachedPlan match { + case LogicalRelationWithTable( + HadoopFsRelation(_, _, _, _, _, options), _) => + import scala.jdk.CollectionConverters._ Review Comment: Nit: can we import this at the top of file with other imports? ########## 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), Review Comment: Wondering, do we not need this logic anymore? -- 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