-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-37517][SQL] Keep consistent order of columns with user specify for v1 table #34780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -258,7 +258,9 @@ case class CatalogTable( | |
| * schema of this table's partition columns | ||
| */ | ||
| def partitionSchema: StructType = { | ||
| val partitionFields = schema.takeRight(partitionColumnNames.length) | ||
| val partitionFields = partitionColumnNames.map { partCol => | ||
| schema.find(_.name == partCol).get | ||
| } | ||
| assert(partitionFields.map(_.name) == partitionColumnNames) | ||
|
|
||
| StructType(partitionFields) | ||
|
|
@@ -268,7 +270,9 @@ case class CatalogTable( | |
| * schema of this table's data columns | ||
| */ | ||
| def dataSchema: StructType = { | ||
| val dataFields = schema.dropRight(partitionColumnNames.length) | ||
| val dataFields = schema.filterNot { i => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. I will change it. Thank you. |
||
| partitionColumnNames.contains(i.name) | ||
| } | ||
| StructType(dataFields) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -226,6 +226,27 @@ abstract class ShowCreateTableSuite extends QueryTest with SQLTestUtils { | |
| } | ||
| } | ||
|
|
||
| test("SPARK-37517: Keep consistent columns order with user specified") { | ||
| val t = "SPARK_37517" | ||
| withTable(t) { | ||
| sql( | ||
| s""" | ||
| |CREATE TABLE $t ( | ||
| | a bigint NOT NULL, | ||
|
||
| | b bigint NOT NULL, | ||
| | c ARRAY<INT>, | ||
| | d STRUCT<x: INT, y: ARRAY<BOOLEAN>> | ||
| |) | ||
| |USING PARQUET | ||
| |PARTITIONED BY (a) | ||
| """.stripMargin) | ||
| val expected = s"CREATE TABLE `default`.`$t` (" + | ||
| s" `a` BIGINT NOT NULL, `b` BIGINT, `c` ARRAY<INT>," + | ||
| s" `d` STRUCT<`x`: INT, `y`: ARRAY<BOOLEAN>>) USING PARQUET PARTITIONED BY (a)" | ||
| assert(getShowDDL(s"SHOW CREATE TABLE $t") == expected) | ||
| } | ||
| } | ||
|
|
||
| protected def getShowDDL(showCreateTableSql: String): String = { | ||
| sql(showCreateTableSql).head().getString(0).split("\n").map(_.trim).mkString(" ") | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this safe? Is there any Exception of
None.gethere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this consistent with the result of
?