Skip to content

Commit 95a7c71

Browse files
committed
Fix bug when handling IF NOT EXISTS clause in a CREATE TEMPORARY TABLE statement.
1 parent d37b19c commit 95a7c71

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

  • sql/core/src/main/scala/org/apache/spark/sql/sources

sql/core/src/main/scala/org/apache/spark/sql/sources/ddl.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ private [sql] case class CreateTempTableUsing(
262262
allowExisting: Boolean) extends RunnableCommand {
263263

264264
def run(sqlContext: SQLContext) = {
265-
if (!sqlContext.catalog.tableExists(Seq(tableName))) {
265+
// The semantic of allowExisting for CREATE TEMPORARY TABLE is if allowExisting is true
266+
// and the table already exists, we will do nothing. If allowExisting is false,
267+
// and the table already exists, we will overwrite it.
268+
val alreadyExists = sqlContext.catalog.tableExists(Seq(tableName))
269+
if (!(alreadyExists && allowExisting)) {
266270
val resolved = ResolvedDataSource(sqlContext, userSpecifiedSchema, provider, options)
267271
sqlContext.registerRDDAsTable(
268272
new DataFrame(sqlContext, LogicalRelation(resolved.relation)), tableName)

0 commit comments

Comments
 (0)