MaxGekk opened a new pull request #31651:
URL: https://github.com/apache/spark/pull/31651


   ### What changes were proposed in this pull request?
   Preprocess the partition spec passed to the V1 `ALTER TABLE .. SET LOCATION` 
implementation `AlterTableSetLocationCommand`, and normalize the passed spec 
according to the partition columns w.r.t the case sensitivity flag  
**spark.sql.caseSensitive**.
   
   ### Why are the changes needed?
   V1 `ALTER TABLE .. SET LOCATION` is case sensitive in fact, and doesn't 
respect the SQL config **spark.sql.caseSensitive** which is false by default, 
for instance:
   ```sql
   spark-sql> CREATE TABLE tbl (id INT, part INT) PARTITIONED BY (part);
   spark-sql> INSERT INTO tbl PARTITION (part=0) SELECT 0;
   spark-sql> SHOW TABLE EXTENDED LIKE 'tbl' PARTITION (part=0);
   Location: 
file:/Users/maximgekk/proj/set-location-case-sense/spark-warehouse/tbl/part=0
   spark-sql> ALTER TABLE tbl ADD PARTITION (part=1);
   spark-sql> SELECT * FROM tbl;
   0    0
   ```
   Create new partition folder in the file system:
   ```
   $ cp -r 
/Users/maximgekk/proj/set-location-case-sense/spark-warehouse/tbl/part=0 
/Users/maximgekk/proj/set-location-case-sense/spark-warehouse/tbl/aaa
   ```
   Set new location for the partition part=1:
   ```sql
   spark-sql> ALTER TABLE tbl PARTITION (part=1) SET LOCATION 
'/Users/maximgekk/proj/set-location-case-sense/spark-warehouse/tbl/aaa';
   spark-sql> SELECT * FROM tbl;
   0    0
   0    1
   spark-sql> ALTER TABLE tbl ADD PARTITION (PART=2);
   spark-sql> SELECT * FROM tbl;
   0    0
   0    1
   ```
   Set location for a partition in the upper case:
   ```
   $ cp -r 
/Users/maximgekk/proj/set-location-case-sense/spark-warehouse/tbl/part=0 
/Users/maximgekk/proj/set-location-case-sense/spark-warehouse/tbl/bbb
   ```
   ```sql
   spark-sql> ALTER TABLE tbl PARTITION (PART=2) SET LOCATION 
'/Users/maximgekk/proj/set-location-case-sense/spark-warehouse/tbl/bbb';
   Error in query: Partition spec is invalid. The spec (PART) must match the 
partition spec (part) defined in table '`default`.`tbl`'
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   Yes. After the changes, the command above works as expected:
   ```sql
   spark-sql> ALTER TABLE tbl PARTITION (PART=2) SET LOCATION 
'/Users/maximgekk/proj/set-location-case-sense/spark-warehouse/tbl/bbb';
   spark-sql> SELECT * FROM tbl;
   0    0
   0    1
   0    2
   ```
   
   ### How was this patch tested?
   By running the modified test suite:
   ```
   $ build/sbt -Phive-2.3 -Phive-thriftserver "test:testOnly *CatalogedDDLSuite"
   ```


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to