@@ -2290,17 +2290,15 @@ class DeltaQuerySuite extends QueryTest
22902290 checkAnswer(sql(" select count(*) from t" ), Row (100 ))
22912291 val table = catalog.loadTable(Identifier .of(Array (" default" ), " t" ))
22922292 assert(table.partitioning === Seq (IdentityTransform (FieldReference (" PART2" ))))
2293- val e1 = intercept[AnalysisException ](
2294- sql(" show partitions t" )
2295- ).getMessage
2296- assert(e1.contains(" Operation not allowed" ))
2293+ checkAnswer(sql(" show partitions t" ),
2294+ Seq (Row (" PART2=0" ), Row (" PART2=1" ), Row (" PART2=2" ), Row (" PART2=3" ), Row (" PART2=4" ))
2295+ )
22972296 }
22982297 }
22992298 }
23002299 }
23012300
2302- // todo
2303- ignore(" test show partitions for partitioned delta table" ) {
2301+ test(" test show partitions for partitioned delta table" ) {
23042302 withTable(" test1" , " test2" , " test3" , " test4" ) {
23052303 sql(" create table test1(id INT, num INT, name STRING) using parquet" )
23062304 sql(" insert into test1 values (1, 2, \" 1\" )" )
@@ -2335,30 +2333,30 @@ class DeltaQuerySuite extends QueryTest
23352333 )
23362334 val desc1 = sql(" DESCRIBE EXTENDED test3 PARTITION (name='1', CAL_DT='1')" ).collect()
23372335 assert(desc1.containsSlice(Seq (Row (" Partition Values" , " [name=1, CAL_DT=1]" , " " ))))
2338- checkKeywordsExist(
2339- sql(" SHOW TABLE EXTENDED LIKE 'test3' PARTITION(name='1', CAL_DT='1')" ),
2340- " Partition Values: [name=1, CAL_DT=1]"
2341- )
2336+ // checkKeywordsExist(
2337+ // sql("SHOW TABLE EXTENDED LIKE 'test3' PARTITION(name='1', CAL_DT='1')"),
2338+ // "Partition Values: [name=1, CAL_DT=1]"
2339+ // )
23422340 sql(
23432341 """
23442342 |CREATE TABLE test4 (id INT, name STRING, CAL_DT STRING)
23452343 |USING PARQUET
23462344 |PARTITIONED BY (name, CAL_DT)
23472345 |""" .stripMargin)
2348- sql(" convert to delta test4 partitioned by (name string, cal_dt string" )
2346+ sql(" convert to delta test4 partitioned by (name string, CAL_DT string) " )
23492347 sql(" INSERT INTO test4 SELECT id, name, name FROM test1" )
23502348 sql(" INSERT INTO test4 VALUES (2, \" 2\" , \" 2\" )" )
23512349 sql(" INSERT INTO test4 VALUES (3, \" 2\" , \" 2\" )" )
23522350 checkAnswer(
23532351 sql(" show partitions test4" ),
23542352 Row (" name=1/CAL_DT=1" ) :: Row (" name=2/CAL_DT=2" ) :: Nil
23552353 )
2356- val desc3 = sql(" DESCRIBE EXTENDED test4 PARTITION (name='2', CAL_DT='2')" ).collect()
2357- assert(desc3.containsSlice(Seq (Row (" Partition Values" , " [name=2, CAL_DT=2]" , " " ))))
2358- checkKeywordsExist(
2359- sql(" SHOW TABLE EXTENDED LIKE 'test4' PARTITION (name='2', CAL_DT='2')" ),
2360- " Partition Values: [name=2, CAL_DT=2]"
2361- )
2354+ // val desc3 = sql("DESCRIBE EXTENDED test4 PARTITION (name='2', CAL_DT='2')").collect()
2355+ // assert(desc3.containsSlice(Seq(Row("Partition Values", "[name=2, CAL_DT=2]", ""))))
2356+ // checkKeywordsExist(
2357+ // sql("SHOW TABLE EXTENDED LIKE 'test4' PARTITION (name='2', CAL_DT='2')"),
2358+ // "Partition Values: [name=2, CAL_DT=2]"
2359+ // )
23622360 sql(" DELETE FROM test4 WHERE id = 2" )
23632361 checkAnswer(
23642362 sql(" show partitions test4" ),
@@ -2369,21 +2367,21 @@ class DeltaQuerySuite extends QueryTest
23692367 sql(" show partitions test4" ),
23702368 Row (" name=1/CAL_DT=1" ) :: Nil
23712369 )
2372- val desc4 = sql(" DESCRIBE EXTENDED test4 PARTITION (name='1')" ).collect()
2373- assert(desc4.containsSlice(Seq (Row (" Partition Values" , " [name=1, CAL_DT=1]" , " " ))))
2374- checkKeywordsExist(
2375- sql(" SHOW TABLE EXTENDED LIKE 'test4' PARTITION (name='1')" ),
2376- " Partition Values: [name=1, CAL_DT=1]"
2377- )
2370+ // val desc4 = sql("DESCRIBE EXTENDED test4 PARTITION (name='1')").collect()
2371+ // assert(desc4.containsSlice(Seq(Row("Partition Values", "[name=1, CAL_DT=1]", ""))))
2372+ // checkKeywordsExist(
2373+ // sql("SHOW TABLE EXTENDED LIKE 'test4' PARTITION (name='1')"),
2374+ // "Partition Values: [name=1, CAL_DT=1]"
2375+ // )
23782376 // check nonexistent partition
2379- val e = intercept[NoSuchPartitionException ](
2380- sql(" DESCRIBE EXTENDED test4 PARTITION (name='2')" )
2381- ).getMessage
2382- assert(e.contains(" Partition not found" ))
2383- val e2 = intercept[NoSuchPartitionException ](
2384- sql(" SHOW TABLE EXTENDED LIKE 'test4' PARTITION (name='2')" )
2385- ).getMessage
2386- assert(e2.contains(" Partition not found" ))
2377+ // val e = intercept[NoSuchPartitionException](
2378+ // sql("DESCRIBE EXTENDED test4 PARTITION (name='2')")
2379+ // ).getMessage
2380+ // assert(e.contains("Partition not found"))
2381+ // val e2 = intercept[NoSuchPartitionException](
2382+ // sql("SHOW TABLE EXTENDED LIKE 'test4' PARTITION (name='2')")
2383+ // ).getMessage
2384+ // assert(e2.contains("Partition not found"))
23872385 }
23882386 }
23892387
@@ -4353,8 +4351,7 @@ class DeltaQuerySuite extends QueryTest
43534351 }
43544352 case _ => assert(false )
43554353 }
4356- // TODO: Uncomment this until command "show partitions" works on delta tables.
4357- // assert(sql("show partitions t").collect().length == 5)
4354+ assert(sql(" show partitions t" ).collect().length == 5 )
43584355 checkAnswer(sql(" select count(*) from t" ), Row (100 ))
43594356 }
43604357 }
@@ -4438,6 +4435,57 @@ class DeltaQuerySuite extends QueryTest
44384435 }
44394436 }
44404437
4438+ test(" CARMEL-6305: Support to show partitions for Delta table" ) {
4439+ withTable(" t1" , " t2" , " t3" ) {
4440+ sql(" CREATE TABLE t1 (a int, b string) USING delta partitioned by (a)" )
4441+ sql(" insert into t1(a, b) values (1, '11')" )
4442+ sql(" insert into t1(a, b) values (2, '22')" )
4443+ sql(" insert into t1(a, b) values (3, '33')" )
4444+ checkAnswer(sql(" show partitions t1" ),
4445+ Seq (Row (" a=1" ), Row (" a=2" ), Row (" a=3" ))
4446+ )
4447+ checkAnswer(sql(" show partitions t1 partition (a=1)" ),
4448+ Seq (Row (" a=1" ))
4449+ )
4450+ checkAnswer(sql(" show partitions t1 partition (a=null)" ),
4451+ Seq ()
4452+ )
4453+
4454+ sql(" CREATE TABLE t2 (a int, b string, c int) USING delta partitioned by (a, c)" )
4455+ sql(" insert into t2(a, b, c) values (1, '11', 111)" )
4456+ sql(" insert into t2(a, b, c) values (1, '12', 112)" )
4457+ sql(" insert into t2(a, b, c) values (1, '13', 111)" )
4458+ sql(" insert into t2(a, b, c) values (2, '22', 222)" )
4459+ sql(" insert into t2(a, b, c) values (2, '23', 222)" )
4460+ sql(" insert into t2(a, b, c) values (3, '33', 333)" )
4461+ checkAnswer(sql(" show partitions t2" ),
4462+ Seq (Row (" a=1/c=111" ), Row (" a=1/c=112" ), Row (" a=2/c=222" ), Row (" a=3/c=333" ))
4463+ )
4464+ checkAnswer(sql(" show partitions t2 partition (a=1)" ),
4465+ Seq (Row (" a=1/c=111" ), Row (" a=1/c=112" ))
4466+ )
4467+ checkAnswer(sql(" show partitions t2 partition (a=1, c=112)" ),
4468+ Seq (Row (" a=1/c=112" ))
4469+ )
4470+ checkAnswer(sql(" show partitions t2 partition (a=1, c=110)" ),
4471+ Seq ()
4472+ )
4473+ checkAnswer(sql(" show partitions t2 partition (c=222)" ),
4474+ Seq (Row (" a=2/c=222" ))
4475+ )
4476+ var msg = intercept[AnalysisException ] {
4477+ sql(" show partitions t2 partition (A=1)" )
4478+ }.getMessage
4479+ assert(msg.contains(" Non-partitioning column(s) [A] are specified for SHOW PARTITIONS" ))
4480+
4481+ sql(" CREATE TABLE t3 (a int, b string, c int) USING delta" )
4482+ msg = intercept[AnalysisException ] {
4483+ sql(" show partitions t3" )
4484+ }.getMessage
4485+ assert(msg.contains(" SHOW PARTITIONS is not allowed on a table that is not partitioned" ))
4486+ }
4487+ }
4488+
44414489 test(" Bucket scan in CDTAS with join disabled " +
44424490 " if PARALLEL_SIZE hint detected and BROADCAST." ) {
44434491 checkCDTASWithJoin(
0 commit comments