-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-41713][SQL] Make CTAS hold a nested execution for data writing #39220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,13 +20,11 @@ package org.apache.spark.sql.execution.command | |
| import java.net.URI | ||
|
|
||
| import org.apache.spark.sql._ | ||
| import org.apache.spark.sql.catalyst.analysis.UnresolvedAttribute | ||
| import org.apache.spark.sql.catalyst.catalog._ | ||
| import org.apache.spark.sql.catalyst.expressions.{Attribute, SortOrder} | ||
| import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
| import org.apache.spark.sql.catalyst.util.CharVarcharUtils | ||
| import org.apache.spark.sql.errors.QueryCompilationErrors | ||
| import org.apache.spark.sql.execution.{CommandExecutionMode, SparkPlan} | ||
| import org.apache.spark.sql.execution.CommandExecutionMode | ||
| import org.apache.spark.sql.execution.datasources._ | ||
| import org.apache.spark.sql.sources.BaseRelation | ||
| import org.apache.spark.sql.types.StructType | ||
|
|
@@ -143,29 +141,11 @@ case class CreateDataSourceTableAsSelectCommand( | |
| mode: SaveMode, | ||
| query: LogicalPlan, | ||
| outputColumnNames: Seq[String]) | ||
| extends V1WriteCommand { | ||
|
|
||
| override def fileFormatProvider: Boolean = { | ||
| table.provider.forall { provider => | ||
| classOf[FileFormat].isAssignableFrom(DataSource.providingClass(provider, conf)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we revert the change in |
||
| } | ||
| } | ||
|
|
||
| override lazy val partitionColumns: Seq[Attribute] = { | ||
| val unresolvedPartitionColumns = table.partitionColumnNames.map(UnresolvedAttribute.quoted) | ||
| DataSource.resolvePartitionColumns( | ||
| unresolvedPartitionColumns, | ||
| outputColumns, | ||
| query, | ||
| SparkSession.active.sessionState.conf.resolver) | ||
| } | ||
|
|
||
| override def requiredOrdering: Seq[SortOrder] = { | ||
| val options = table.storage.properties | ||
| V1WritesUtils.getSortOrder(outputColumns, partitionColumns, table.bucketSpec, options) | ||
| } | ||
| extends LeafRunnableCommand { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the key change. now ctas is not a v1 write command. |
||
| assert(query.resolved) | ||
| override def innerChildren: Seq[LogicalPlan] = query :: Nil | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we put the EXPLAIN result of a CTAS in the PR description as an example?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, updated |
||
|
|
||
cloud-fan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| override def run(sparkSession: SparkSession, child: SparkPlan): Seq[Row] = { | ||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| assert(table.tableType != CatalogTableType.VIEW) | ||
| assert(table.provider.isDefined) | ||
|
|
||
|
|
@@ -187,7 +167,7 @@ case class CreateDataSourceTableAsSelectCommand( | |
| } | ||
|
|
||
| saveDataIntoTable( | ||
| sparkSession, table, table.storage.locationUri, child, SaveMode.Append, tableExists = true) | ||
| sparkSession, table, table.storage.locationUri, SaveMode.Append, tableExists = true) | ||
| } else { | ||
| table.storage.locationUri.foreach { p => | ||
| DataWritingCommand.assertEmptyRootPath(p, mode, sparkSession.sessionState.newHadoopConf) | ||
|
|
@@ -200,7 +180,7 @@ case class CreateDataSourceTableAsSelectCommand( | |
| table.storage.locationUri | ||
| } | ||
| val result = saveDataIntoTable( | ||
| sparkSession, table, tableLocation, child, SaveMode.Overwrite, tableExists = false) | ||
| sparkSession, table, tableLocation, SaveMode.Overwrite, tableExists = false) | ||
| val tableSchema = CharVarcharUtils.getRawSchema(result.schema, sessionState.conf) | ||
| val newTable = table.copy( | ||
| storage = table.storage.copy(locationUri = tableLocation), | ||
|
|
@@ -232,7 +212,6 @@ case class CreateDataSourceTableAsSelectCommand( | |
| session: SparkSession, | ||
| table: CatalogTable, | ||
| tableLocation: Option[URI], | ||
| physicalPlan: SparkPlan, | ||
| mode: SaveMode, | ||
| tableExists: Boolean): BaseRelation = { | ||
| // Create the relation based on the input logical plan: `query`. | ||
|
|
@@ -246,14 +225,11 @@ case class CreateDataSourceTableAsSelectCommand( | |
| catalogTable = if (tableExists) Some(table) else None) | ||
|
|
||
| try { | ||
| dataSource.writeAndRead(mode, query, outputColumnNames, physicalPlan, metrics) | ||
| dataSource.writeAndRead(mode, query, outputColumnNames) | ||
| } catch { | ||
| case ex: AnalysisException => | ||
| logError(s"Failed to write to table ${table.identifier.unquotedString}", ex) | ||
| throw ex | ||
| } | ||
| } | ||
|
|
||
| override protected def withNewChildInternal(newChild: LogicalPlan): LogicalPlan = | ||
| copy(query = newChild) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.