-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-18572][SQL] Add a method listPartitionNames to ExternalCatalog
#15998
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
826dee6
54171ad
93cee97
27dc672
2a7b062
d183946
9c71521
b9dd303
28563d4
860d985
fc57f23
37fc595
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 |
|---|---|---|
|
|
@@ -748,6 +748,26 @@ class SessionCatalog( | |
| externalCatalog.getPartition(db, table, spec) | ||
| } | ||
|
|
||
| /** | ||
| * List the names of all partitions that belong to the specified table, assuming it exists. | ||
| * | ||
| * A partial partition spec may optionally be provided to filter the partitions returned. | ||
| * For instance, if there exist partitions (a='1', b='2'), (a='1', b='3') and (a='2', b='4'), | ||
| * then a partial spec of (a='1') will return the first two only. | ||
| */ | ||
| def listPartitionNames( | ||
| tableName: TableIdentifier, | ||
| partialSpec: Option[TablePartitionSpec] = None): Seq[String] = { | ||
| val db = formatDatabaseName(tableName.database.getOrElse(getCurrentDatabase)) | ||
| val table = formatTableName(tableName.table) | ||
| requireDbExists(db) | ||
| requireTableExists(TableIdentifier(table, Option(db))) | ||
|
||
| partialSpec.foreach { spec => | ||
| requirePartialMatchedPartitionSpec(Seq(spec), getTableMetadata(tableName)) | ||
| } | ||
| externalCatalog.listPartitionNames(db, table, partialSpec) | ||
| } | ||
|
|
||
| /** | ||
| * List the metadata of all partitions that belong to the specified table, assuming it exists. | ||
| * | ||
|
|
@@ -762,6 +782,9 @@ class SessionCatalog( | |
| val table = formatTableName(tableName.table) | ||
| requireDbExists(db) | ||
| requireTableExists(TableIdentifier(table, Option(db))) | ||
| partialSpec.foreach { spec => | ||
| requirePartialMatchedPartitionSpec(Seq(spec), getTableMetadata(tableName)) | ||
| } | ||
| externalCatalog.listPartitions(db, table, partialSpec) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -346,6 +346,31 @@ abstract class ExternalCatalogSuite extends SparkFunSuite with BeforeAndAfterEac | |
| assert(new Path(partitionLocation) == defaultPartitionLocation) | ||
| } | ||
|
|
||
| test("list partition names") { | ||
| val catalog = newBasicCatalog() | ||
| val newPart = CatalogTablePartition(Map("a" -> "1", "b" -> "%="), storageFormat) | ||
| catalog.createPartitions("db2", "tbl2", Seq(newPart), ignoreIfExists = false) | ||
|
|
||
| val partitionNames = catalog.listPartitionNames("db2", "tbl2") | ||
| assert(partitionNames == Seq("a=1/b=%25%3D", "a=1/b=2", "a=3/b=4")) | ||
|
||
| } | ||
|
|
||
| test("list partition names with partial partition spec") { | ||
| val catalog = newBasicCatalog() | ||
| val newPart = CatalogTablePartition(Map("a" -> "1", "b" -> "%="), storageFormat) | ||
| catalog.createPartitions("db2", "tbl2", Seq(newPart), ignoreIfExists = false) | ||
|
|
||
| val partitionNames1 = catalog.listPartitionNames("db2", "tbl2", Some(Map("a" -> "1"))) | ||
| assert(partitionNames1 == Seq("a=1/b=%25%3D", "a=1/b=2")) | ||
|
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. cc @gatorsmile @ericl is it same with Hive? It looks weird to me that we return the "weird" value to users.
Member
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. Yeah, I tried Hive 1.2. It actually returns the weird value.
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. ok, maybe we should consider diverging from Hive here... |
||
|
|
||
| // Partial partition specs including "weird" partition values should use the unescaped values | ||
| val partitionNames2 = catalog.listPartitionNames("db2", "tbl2", Some(Map("b" -> "%="))) | ||
| assert(partitionNames2 == Seq("a=1/b=%25%3D")) | ||
|
|
||
| val partitionNames3 = catalog.listPartitionNames("db2", "tbl2", Some(Map("b" -> "%25%3D"))) | ||
| assert(partitionNames3.isEmpty) | ||
| } | ||
|
|
||
| test("list partitions with partial partition spec") { | ||
| val catalog = newBasicCatalog() | ||
| val parts = catalog.listPartitions("db2", "tbl2", Some(Map("a" -> "1"))) | ||
|
|
||
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.
As mentioned above,
PartitioningUtilsis not available here so I went ahead withescapePathNameitself.