File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
sql/core/src/test/scala/org/apache/spark/sql/execution/command Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1818package org .apache .spark .sql .execution .command
1919
2020import java .io .File
21+ import java .net .URI
2122
2223import org .apache .hadoop .fs .Path
2324import org .scalatest .BeforeAndAfterEach
@@ -1787,4 +1788,31 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
17871788 val rows : Seq [Row ] = df.toLocalIterator().asScala.toSeq
17881789 assert(rows.length > 0 )
17891790 }
1791+
1792+ test(" SET LOCATION for managed table" ) {
1793+ withTable(" src" ) {
1794+ withTempDir { dir =>
1795+ sql(" CREATE TABLE tbl(i INT) USING parquet" )
1796+ sql(" INSERT INTO tbl SELECT 1" )
1797+ checkAnswer(spark.table(" tbl" ), Row (1 ))
1798+ val defaultTablePath = spark.sessionState.catalog
1799+ .getTableMetadata(TableIdentifier (" tbl" )).storage.locationUri.get
1800+
1801+ sql(s " ALTER TABLE tbl SET LOCATION ' ${dir.getCanonicalPath}' " )
1802+ // SET LOCATION won't move data from previous table path to new table path.
1803+ assert(spark.table(" tbl" ).count() == 0 )
1804+ // the previous table path should be still there.
1805+ assert(new File (new URI (defaultTablePath)).exists())
1806+
1807+ sql(" INSERT INTO tbl SELECT 2" )
1808+ checkAnswer(spark.table(" tbl" ), Row (2 ))
1809+ // newly inserted data will go to the new table path.
1810+ assert(dir.listFiles().nonEmpty)
1811+
1812+ sql(" DROP TABLE tbl" )
1813+ // the new table path will be removed after DROP TABLE.
1814+ assert(! dir.exists())
1815+ }
1816+ }
1817+ }
17901818}
You can’t perform that action at this time.
0 commit comments