Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ final class DataFrameWriter private[sql](df: DataFrame) {
CreateTableUsingAsSelect(
tableIdent,
source,
temporary = false,
partitioningColumns.map(_.toArray).getOrElse(Array.empty[String]),
getBucketSpec,
mode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,19 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
// Get the backing query.
val query = plan(ctx.query)

if (temp) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you please rename this to temporary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw operationNotAllowed("CREATE TEMPORARY TABLE ... USING ... AS query", ctx)
}

// Determine the storage mode.
val mode = if (ifNotExists) {
SaveMode.Ignore
} else if (temp) {
SaveMode.Overwrite
} else {
SaveMode.ErrorIfExists
}

CreateTableUsingAsSelect(
table, provider, temp, partitionColumnNames, bucketSpec, mode, options, query)
table, provider, partitionColumnNames, bucketSpec, mode, options, query)
} else {
val struct = Option(ctx.colTypeList()).map(createStructType)
CreateTableUsing(
Expand Down Expand Up @@ -960,7 +962,6 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
CreateTableUsingAsSelect(
tableIdent = tableDesc.identifier,
provider = conf.defaultDataSourceName,
temporary = false,
partitionColumns = tableDesc.partitionColumnNames.toArray,
bucketSpec = None,
mode = mode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,7 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] {
throw new AnalysisException(
"allowExisting should be set to false when creating a temporary table.")

case c: CreateTableUsingAsSelect if c.temporary && c.partitionColumns.nonEmpty =>
sys.error("Cannot create temporary partitioned table.")

case c: CreateTableUsingAsSelect if c.temporary =>
val cmd = CreateTempTableUsingAsSelectCommand(
c.tableIdent, c.provider, Array.empty[String], c.mode, c.options, c.child)
ExecutedCommandExec(cmd) :: Nil

case c: CreateTableUsingAsSelect if !c.temporary =>
case c: CreateTableUsingAsSelect =>
val cmd =
CreateDataSourceTableAsSelectCommand(
c.tableIdent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ case class CreateTableUsing(
case class CreateTableUsingAsSelect(
tableIdent: TableIdentifier,
provider: String,
temporary: Boolean,
partitionColumns: Array[String],
bucketSpec: Option[BucketSpec],
mode: SaveMode,
Expand Down Expand Up @@ -91,37 +90,6 @@ case class CreateTempTableUsing(
}
}

case class CreateTempTableUsingAsSelectCommand(
tableIdent: TableIdentifier,
provider: String,
partitionColumns: Array[String],
mode: SaveMode,
options: Map[String, String],
query: LogicalPlan) extends RunnableCommand {

if (tableIdent.database.isDefined) {
throw new AnalysisException(
s"Temporary table '$tableIdent' should not have specified a database")
}

override def run(sparkSession: SparkSession): Seq[Row] = {
val df = Dataset.ofRows(sparkSession, query)
val dataSource = DataSource(
sparkSession,
className = provider,
partitionColumns = partitionColumns,
bucketSpec = None,
options = options)
val result = dataSource.write(mode, df)
sparkSession.sessionState.catalog.createTempView(
tableIdent.table,
Dataset.ofRows(sparkSession, LogicalRelation(result)).logicalPlan,
overrideIfExists = true)

Seq.empty[Row]
}
}

case class RefreshTable(tableIdent: TableIdentifier)
extends RunnableCommand {

Expand Down
Loading