@@ -1588,56 +1588,71 @@ class HiveDDLSuite
15881588 }
15891589 }
15901590
1591- test(" refresh non-cached table after alter the location" ) {
1592- withTable(" t" , " t1" , " t2" , " t3" ) {
1593- withTempDir { dir =>
1594- spark.sql(
1595- """
1596- |CREATE TABLE t(a string)
1597- |USING parquet
1598- """ .stripMargin)
1599- spark.sql(" INSERT INTO TABLE t SELECT 1" )
1600- checkAnswer(spark.table(" t" ), Row (" 1" ) :: Nil )
1601- spark.sql(s " ALTER TABLE t SET LOCATION ' $dir' " )
1602- checkAnswer(spark.table(" t" ), Nil )
1603- }
1591+ Seq (true , false ).foreach { shouldCache =>
1592+ val testName = if (shouldCache) " cached" else " non-cached"
1593+ test(s " refresh $testNames table after alter the location " ) {
1594+ withTable(" t" , " t1" , " t2" , " t3" ) {
1595+ withTempDir { dir =>
1596+ spark.sql(
1597+ """
1598+ |CREATE TABLE t(a string)
1599+ |USING parquet
1600+ """ .stripMargin)
1601+ spark.sql(" INSERT INTO TABLE t SELECT 1" )
1602+ if (shouldCache) {
1603+ spark.catalog.cacheTable(" t" )
1604+ }
1605+ checkAnswer(spark.table(" t" ), Row (" 1" ) :: Nil )
1606+ spark.sql(s " ALTER TABLE t SET LOCATION ' $dir' " )
1607+ checkAnswer(spark.table(" t" ), Nil )
1608+ }
16041609
1605- withTempDir { dir =>
1606- spark.sql(
1607- """
1608- |CREATE TABLE t1(a string, b string)
1609- |USING parquet
1610- |PARTITIONED BY(b)
1611- """ .stripMargin)
1612- spark.sql(" INSERT INTO TABLE t1 PARTITION(b=1) SELECT 2" )
1613- checkAnswer(spark.table(" t1" ), Row (" 2" , " 1" ) :: Nil )
1614- spark.sql(s " ALTER TABLE t1 PARTITION(b=1)SET LOCATION ' $dir' " )
1615- checkAnswer(spark.table(" t1" ), Nil )
1616- }
1610+ withTempDir { dir =>
1611+ spark.sql(
1612+ """
1613+ |CREATE TABLE t1(a string, b string)
1614+ |USING parquet
1615+ |PARTITIONED BY(b)
1616+ """ .stripMargin)
1617+ spark.sql(" INSERT INTO TABLE t1 PARTITION(b=1) SELECT 2" )
1618+ if (shouldCache) {
1619+ spark.catalog.cacheTable(" t" )
1620+ }
1621+ checkAnswer(spark.table(" t1" ), Row (" 2" , " 1" ) :: Nil )
1622+ spark.sql(s " ALTER TABLE t1 PARTITION(b=1)SET LOCATION ' $dir' " )
1623+ checkAnswer(spark.table(" t1" ), Nil )
1624+ }
16171625
1618- withTempDir { dir =>
1619- spark.sql(
1620- """
1621- |CREATE TABLE t2(a string)
1622- |USING hive
1623- """ .stripMargin)
1624- spark.sql(" INSERT INTO TABLE t2 SELECT 1" )
1625- checkAnswer(spark.table(" t2" ), Row (" 1" ) :: Nil )
1626- spark.sql(s " ALTER TABLE t2 SET LOCATION ' $dir' " )
1627- checkAnswer(spark.table(" t2" ), Nil )
1628- }
1626+ withTempDir { dir =>
1627+ spark.sql(
1628+ """
1629+ |CREATE TABLE t2(a string)
1630+ |USING hive
1631+ """ .stripMargin)
1632+ spark.sql(" INSERT INTO TABLE t2 SELECT 1" )
1633+ if (shouldCache) {
1634+ spark.catalog.cacheTable(" t" )
1635+ }
1636+ checkAnswer(spark.table(" t2" ), Row (" 1" ) :: Nil )
1637+ spark.sql(s " ALTER TABLE t2 SET LOCATION ' $dir' " )
1638+ checkAnswer(spark.table(" t2" ), Nil )
1639+ }
16291640
1630- withTempDir { dir =>
1631- spark.sql(
1632- """
1633- |CREATE TABLE t3(a string, b string)
1634- |USING hive
1635- |PARTITIONED BY(b)
1636- """ .stripMargin)
1637- spark.sql(" INSERT INTO TABLE t3 PARTITION(b=1) SELECT 2" )
1638- checkAnswer(spark.table(" t3" ), Row (" 2" , " 1" ) :: Nil )
1639- spark.sql(s " ALTER TABLE t3 PARTITION(b=1)SET LOCATION ' $dir' " )
1640- checkAnswer(spark.table(" t3" ), Nil )
1641+ withTempDir { dir =>
1642+ spark.sql(
1643+ """
1644+ |CREATE TABLE t3(a string, b string)
1645+ |USING hive
1646+ |PARTITIONED BY(b)
1647+ """ .stripMargin)
1648+ spark.sql(" INSERT INTO TABLE t3 PARTITION(b=1) SELECT 2" )
1649+ if (shouldCache) {
1650+ spark.catalog.cacheTable(" t" )
1651+ }
1652+ checkAnswer(spark.table(" t3" ), Row (" 2" , " 1" ) :: Nil )
1653+ spark.sql(s " ALTER TABLE t3 PARTITION(b=1)SET LOCATION ' $dir' " )
1654+ checkAnswer(spark.table(" t3" ), Nil )
1655+ }
16411656 }
16421657 }
16431658 }
0 commit comments