-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-34203][SQL][3.0] Convert null partition values to __HIVE_DEFAULT_PARTITION__ in v1 In-Memory catalog
#31326
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 | ||
|---|---|---|---|---|
|
|
@@ -34,6 +34,7 @@ import org.apache.spark.sql.catalyst.catalog._ | |||
| import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec | ||||
| import org.apache.spark.sql.connector.catalog.CatalogManager | ||||
| import org.apache.spark.sql.connector.catalog.SupportsNamespaces.PROP_OWNER | ||||
| import org.apache.spark.sql.execution.datasources.PartitioningUtils | ||||
| import org.apache.spark.sql.internal.SQLConf | ||||
| import org.apache.spark.sql.internal.StaticSQLConf.CATALOG_IMPLEMENTATION | ||||
| import org.apache.spark.sql.test.{SharedSparkSession, SQLTestUtils} | ||||
|
|
@@ -1734,9 +1735,8 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils { | |||
|
|
||||
| // null partition values | ||||
| createTablePartition(catalog, Map("a" -> null, "b" -> null), tableIdent) | ||||
| val nullPartValue = if (isUsingHiveMetastore) "__HIVE_DEFAULT_PARTITION__" else null | ||||
| assert(catalog.listPartitions(tableIdent).map(_.spec).toSet == | ||||
| Set(Map("a" -> nullPartValue, "b" -> nullPartValue))) | ||||
| Set(Map("a" -> "__HIVE_DEFAULT_PARTITION__", "b" -> "__HIVE_DEFAULT_PARTITION__"))) | ||||
|
Member
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. Now, the
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. shall we do it in master branch as well?
Member
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. In master, we already have common settings in unified tests: Line 36 in 861f8bb
|
||||
| sql("ALTER TABLE tab1 DROP PARTITION (a = null, b = null)") | ||||
| assert(catalog.listPartitions(tableIdent).isEmpty) | ||||
| } | ||||
|
|
@@ -3091,6 +3091,35 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils { | |||
| assert(sql(s"SHOW TABLE EXTENDED LIKE '$t' PARTITION(a = 1)").count() === 1) | ||||
| } | ||||
| } | ||||
|
|
||||
| test("SPARK-33591, SPARK-34203: insert and drop partitions with null values") { | ||||
| def checkPartitions(t: String, expected: Map[String, String]*): Unit = { | ||||
| val partitions = sql(s"SHOW PARTITIONS $t") | ||||
| .collect() | ||||
| .toSet | ||||
| .map((row: Row) => row.getString(0)) | ||||
| .map(PartitioningUtils.parsePathFragment) | ||||
| assert(partitions === expected.toSet) | ||||
| } | ||||
| val defaultUsing = "USING " + (if (isUsingHiveMetastore) "hive" else "parquet") | ||||
| def insertAndDropNullPart(t: String, insertCmd: String): Unit = { | ||||
| sql(s"CREATE TABLE $t (col1 INT, p1 STRING) $defaultUsing PARTITIONED BY (p1)") | ||||
| sql(insertCmd) | ||||
| checkPartitions(t, Map("p1" -> ExternalCatalogUtils.DEFAULT_PARTITION_NAME)) | ||||
| sql(s"ALTER TABLE $t DROP PARTITION (p1 = null)") | ||||
| checkPartitions(t) | ||||
| } | ||||
|
|
||||
| withTable("tbl") { | ||||
| insertAndDropNullPart("tbl", s"INSERT INTO TABLE tbl PARTITION (p1 = null) SELECT 0") | ||||
| } | ||||
|
|
||||
| withSQLConf("hive.exec.dynamic.partition.mode" -> "nonstrict") { | ||||
| withTable("tbl") { | ||||
| insertAndDropNullPart("tbl", s"INSERT OVERWRITE TABLE tbl VALUES (0, null)") | ||||
| } | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
||||
| object FakeLocalFsFileSystem { | ||||
|
|
||||
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.
A simpler way is to test DROP PARTITION here.
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.
New test covers both v1 In-Memory and Hive external catalogs because it runs as a part of
InMemoryCatalogedDDLSuiteandHiveCatalogedDDLSuite.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.
OK, then please forward port the new test to branch-3.1, as I used this smaller change while backporting.
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.
Here it is #31331