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
39 changes: 0 additions & 39 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4596,45 +4596,6 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
sql("SELECT /*+ hash(t2) */ * FROM t1 join t2 on c1 = c2")
}
}

test("SPARK-41538: Metadata column should be appended at the end of project") {
val tableName = "table_1"
val viewName = "view_1"
withTable(tableName) {
withView(viewName) {
sql(s"CREATE TABLE $tableName (a ARRAY<STRING>, s STRUCT<id: STRING>) USING parquet")
val id = "id1"
sql(s"INSERT INTO $tableName values(ARRAY('a'), named_struct('id', '$id'))")
sql(
s"""
|CREATE VIEW $viewName (id)
|AS WITH source AS (
| SELECT * FROM $tableName
|),
|renamed AS (
| SELECT s.id FROM source
|)
|SELECT id FROM renamed
|""".stripMargin)
val query =
s"""
|with foo AS (
| SELECT '$id' as id
|),
|bar AS (
| SELECT '$id' as id
|)
|SELECT
| 1
|FROM foo
|FULL OUTER JOIN bar USING(id)
|FULL OUTER JOIN $viewName USING(id)
|WHERE foo.id IS NOT NULL
|""".stripMargin
checkAnswer(sql(query), Row(1))
}
}
}
}

case class Foo(bar: Option[String])
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,45 @@ class MetadataColumnSuite extends DatasourceV2SQLBase {
assert(df.union(fieldNameMismatchDf).queryExecution.analyzed.metadataOutput.isEmpty)
}
}

test("SPARK-41538: Metadata column should be appended at the end of project") {
val tableName = "table_1"
val viewName = "view_1"
withTable(tableName) {
withView(viewName) {
sql(s"CREATE TABLE $tableName (a ARRAY<STRING>, s STRUCT<id: STRING>) USING parquet")
val id = "id1"
sql(s"INSERT INTO $tableName values(ARRAY('a'), named_struct('id', '$id'))")
sql(
s"""
|CREATE VIEW $viewName (id)
|AS WITH source AS (
| SELECT * FROM $tableName
|),
|renamed AS (
| SELECT s.id FROM source
|)
|SELECT id FROM renamed
|""".stripMargin)
val query =
s"""
|with foo AS (
| SELECT '$id' as id
|),
|bar AS (
| SELECT '$id' as id
|)
|SELECT
| 1
|FROM foo
|FULL OUTER JOIN bar USING(id)
|FULL OUTER JOIN $viewName USING(id)
|WHERE foo.id IS NOT NULL
|""".stripMargin
checkAnswer(sql(query), Row(1))
}
}
}
}

class MetadataTestTable(
Expand Down