Github user attilapiros commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20249#discussion_r161480210
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala 
---
    @@ -1869,6 +1869,65 @@ abstract class DDLSuite extends QueryTest with 
SQLTestUtils {
         }
       }
     
    +  test("SPARK-23057: SET LOCATION for managed table with partition") {
    +    withTable("tbl_partition") {
    +      withTempDir { dir =>
    +        sql("CREATE TABLE tbl_partition(col1 INT, col2 INT) USING parquet 
PARTITIONED BY (col1)")
    +        sql("INSERT INTO tbl_partition PARTITION(col1=1) SELECT 11")
    +        sql("INSERT INTO tbl_partition PARTITION(col1=2) SELECT 22")
    +        checkAnswer(spark.table("tbl_partition"), Seq(Row(11, 1), Row(22, 
2)))
    +        val defaultTablePath = spark.sessionState.catalog
    +          
.getTableMetadata(TableIdentifier("tbl_partition")).storage.locationUri.get
    +        try {
    +          // before set location of partition col1 =1 and 2
    +          checkPath(defaultTablePath.toString, Map("col1" -> "1"), 
"tbl_partition")
    +          checkPath(defaultTablePath.toString, Map("col1" -> "2"), 
"tbl_partition")
    +          val path = dir.getCanonicalPath
    +
    +          // set location of partition col1 =1
    +          sql(s"ALTER TABLE tbl_partition PARTITION (col1='1') SET 
LOCATION '$path'")
    +          checkPath(dir.getCanonicalPath, Map("col1" -> "1"), 
"tbl_partition")
    --- End diff --
    
    Consider using the "path" val here for calling "checkPath" method instead 
"dir.getCanonicalPath" to be as close to your ALTER as possible when you are 
checking its effect or remove the "path" val and use "dir.getCanonicalPath" 
everywhere (so avoid unnecessary indirection).
    
    If reason of introducing "path" was the line length restriction then you 
can even use multiline string interpolation.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to