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
4 changes: 2 additions & 2 deletions docs/sql-ref-syntax-dml-insert-overwrite-directory.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ USING file_format [ OPTIONS ( key = val [ , ... ] ) ]
* **query**

A query that produces the rows to be inserted. It can be in one of following formats:
* a `SELECT` statement
* a `TABLE` statement
* a [SELECT](sql-ref-syntax-qry-select.html) statement
* a [Inline Table](sql-ref-syntax-qry-select-inline-table.html) statement
* a `FROM` statement

### Examples
Expand Down
4 changes: 2 additions & 2 deletions docs/sql-ref-syntax-dml-insert-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ INSERT [ INTO | OVERWRITE ] [ TABLE ] table_identifier [ partition_spec ] [ ( co
* **query**

A query that produces the rows to be inserted. It can be in one of following formats:
* a `SELECT` statement
* a `TABLE` statement
* a [SELECT](sql-ref-syntax-qry-select.html) statement
* a [Inline Table](sql-ref-syntax-qry-select-inline-table.html) statement
* a `FROM` statement

### Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,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