Skip to content
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

[spark] Support spark DropPartition with sync metastore #4339

Merged
merged 11 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,21 @@ trait PaimonPartitionManagement extends SupportsAtomicPartitionManagement {
case fileStoreTable: FileStoreTable =>
val partitions = toPaimonPartitions(rows).map(_.asInstanceOf[JMap[String, String]])
val commit: FileStoreCommit = fileStoreTable.store.newCommit(UUID.randomUUID.toString)
var metastoreClient: MetastoreClient = null
val clientFactory = fileStoreTable.catalogEnvironment().metastoreClientFactory
try {
commit.dropPartitions(partitions.toSeq.asJava, BatchWriteBuilder.COMMIT_IDENTIFIER)
// syn to metastore with delete partitions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sync

if (clientFactory != null) {
Copy link
Contributor

@JingsongLi JingsongLi Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should check metastore.partitioned-table. (Please add case for disabled metastore.partitioned-table table too)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,had added a check for metastore.partitioned-table and case. Thanks @JingsongLi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also for createPartitions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

metastoreClient = clientFactory.create()
toPaimonPartitions(rows).foreach(metastoreClient.deletePartition)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete excess blank line

} finally {
commit.close()
if (metastoreClient != null) {
metastoreClient.close()
}
}
true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,50 @@ abstract class DDLWithHiveCatalogTestBase extends PaimonHiveTestBase {
}
}

test("Paimon DDL with hive catalog: drop partition for paimon table sparkCatalogName") {
Seq(paimonHiveCatalogName).foreach {
catalogName =>
spark.sql(s"USE $catalogName")
withTempDir {
dBLocation =>
withDatabase("paimon_db") {
val comment = "this is a test comment"
spark.sql(
s"CREATE DATABASE paimon_db LOCATION '${dBLocation.getCanonicalPath}' COMMENT '$comment'")
Assertions.assertEquals(getDatabaseLocation("paimon_db"), dBLocation.getCanonicalPath)
Assertions.assertEquals(getDatabaseComment("paimon_db"), comment)

withTable("paimon_db.paimon_tbl") {
spark.sql(s"""
|CREATE TABLE paimon_db.paimon_tbl (id STRING, name STRING, pt STRING)
|USING PAIMON
|PARTITIONED BY (name, pt)
|TBLPROPERTIES('metastore.partitioned-table' = 'true')
|""".stripMargin)
Assertions.assertEquals(
getTableLocation("paimon_db.paimon_tbl"),
s"${dBLocation.getCanonicalPath}/paimon_tbl")
spark.sql("insert into paimon_db.paimon_tbl select '1', 'n', 'cc'")
spark.sql("insert into paimon_db.paimon_tbl select '1', 'n1', 'aa'")
spark.sql("insert into paimon_db.paimon_tbl select '1', 'n2', 'bb'")

spark.sql("show partitions paimon_db.paimon_tbl")
checkAnswer(
spark.sql("show partitions paimon_db.paimon_tbl"),
Row("name=n/pt=cc") :: Row("name=n1/pt=aa") :: Row("name=n2/pt=bb") :: Nil)
spark.sql(
"alter table paimon_db.paimon_tbl drop partition (name='n1', `pt`='aa'), partition (name='n2', `pt`='bb')")
spark.sql("show partitions paimon_db.paimon_tbl")
checkAnswer(
spark.sql("show partitions paimon_db.paimon_tbl"),
Row("name=n/pt=cc") :: Nil)

}
}
}
}
}

test("Paimon DDL with hive catalog: create partition for paimon table sparkCatalogName") {
Seq(paimonHiveCatalogName).foreach {
catalogName =>
Expand Down
Loading