Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[SPARK-36980][SQL] Insert support query with CTE
  • Loading branch information
AngersZhuuuu committed Oct 12, 2021
commit 8a1b4e404c03e83602de16aac44dda2ccdb2f298
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ resource
;

dmlStatementNoWith
: insertInto queryTerm queryOrganization #singleInsertQuery
: insertInto query #singleInsertQuery
| fromClause multiInsertQueryBody+ #multiInsertQuery
| DELETE FROM multipartIdentifier tableAlias whereClause? #deleteFromTable
| UPDATE multipartIdentifier tableAlias setClause whereClause? #updateTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
*/
override def visitSingleInsertQuery(
ctx: SingleInsertQueryContext): LogicalPlan = withOrigin(ctx) {
withInsertInto(
ctx.insertInto(),
plan(ctx.queryTerm).optionalMap(ctx.queryOrganization)(withQueryResultClauses))
withInsertInto(ctx.insertInto(), visitQuery(ctx.query))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,14 @@ class InsertSuite extends DataSourceTest with SharedSparkSession {
}
}
}

test("SPARK-36980: Insert support query with CTE") {
withTable("t") {
sql("CREATE TABLE t(i int, part1 int, part2 int) using parquet")
sql("INSERT INTO t WITH v1(c1) as (values (1)) select 1, 2,3 from v1")
checkAnswer(spark.table("t"), Row(1, 2, 3))
}
}
}

class FileExistingTestFileSystem extends RawLocalFileSystem {
Expand Down