YannByron commented on code in PR #2314:
URL: https://github.com/apache/fluss/pull/2314#discussion_r2681057025
##########
fluss-spark/fluss-spark-ut/src/test/scala/org/apache/fluss/spark/SparkCatalogTest.scala:
##########
@@ -190,4 +190,55 @@ class FlussCatalogTest extends FlussSparkTestBase {
admin.dropDatabase(dbName, true, true).get()
checkAnswer(sql("SHOW DATABASES"), Row(DEFAULT_DATABASE) :: Nil)
}
+
+ test("show partitions") {
+ withTable("t") {
+ sql(s"CREATE TABLE t (id int, name string, pt1 string, pt2 int)
PARTITIONED BY (pt1, pt2)")
+ sql(s"INSERT INTO t values(1, 'a', 'a', 1), (2, 'b', 'a', 2), (3, 'c',
'c', 3)")
+
+ var expect = Seq(Row("pt1=a/pt2=1"), Row("pt1=a/pt2=2"),
Row("pt1=c/pt2=3"))
+ checkAnswer(sql(s"SHOW PARTITIONS t"), expect)
+ expect = Seq(Row("pt1=a/pt2=1"), Row("pt1=a/pt2=2"))
+ checkAnswer(sql(s"SHOW PARTITIONS t PARTITION (pt1 = 'a')"), expect)
+ }
+ }
+
+ test("add partition") {
+ withTable("t") {
+ sql("CREATE TABLE t (id int, name string, pt1 string, pt2 int)
PARTITIONED BY (pt1, pt2)")
+
+ // add from sparksql
+ sql(s"ALTER TABLE t ADD PARTITION (pt1 = 'b', pt2 = 1)")
+ var expect = Seq(Row("pt1=b/pt2=1"))
+ checkAnswer(sql(s"SHOW PARTITIONS t"), expect)
+ sql(s"ALTER TABLE t ADD IF NOT EXISTS PARTITION (pt1 = 'b', pt2 = 1)")
+ checkAnswer(sql(s"SHOW PARTITIONS t"), expect)
+
+ // add from fluss
+ val map = Map("pt1" -> "b", "pt2" -> "2")
+ admin.createPartition(createTablePath("t"), new
PartitionSpec(map.asJava), false).get()
+ expect = Seq(Row("pt1=b/pt2=1"), Row("pt1=b/pt2=2"))
+ checkAnswer(sql(s"SHOW PARTITIONS t"), expect)
+ }
+ }
+
+ test("drop partition") {
+ withTable("t") {
+ sql("CREATE TABLE t (id int, name string, pt1 string, pt2 int)
PARTITIONED BY (pt1, pt2)")
+ sql(s"INSERT INTO t values(1, 'a', 'a', 1), (2, 'b', 'a', 2), (3, 'c',
'c', 3)")
+
+ // drop from sparksql
+ sql(s"ALTER TABLE t DROP PARTITION (pt1 = 'a', pt2 = 2)")
+ var expect = Seq(Row("pt1=a/pt2=1"), Row("pt1=c/pt2=3"))
+ checkAnswer(sql(s"SHOW PARTITIONS t"), expect)
+ sql(s"ALTER TABLE t DROP IF EXISTS PARTITION (pt1 = 'a', pt2 = 2)")
+ checkAnswer(sql(s"SHOW PARTITIONS t"), expect)
+
+ // drop from fluss
+ val map = Map("pt1" -> "c", "pt2" -> "3")
Review Comment:
please add at least 1 test: to drop partitions with partial partition, like
`pt1 = 'a'`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]