baifachuan opened a new pull request #3009:
URL: https://github.com/apache/hive/pull/3009


   ### What changes were proposed in this pull request?
   
   modify the HMSHandler. create_table_core function add this check:
   
   ```
   if (!MetaStoreUtils.validateTblStorage(tbl.getSd())) {
       throw new InvalidObjectException(tbl.getTableName()
           + " location must not be root path");
   }
   ```
   If the path.getParent() is NULL we can be sure the location is ROOT path.  
   
   the validateTblStorage implements:
   
   ```
   /*
     * Check the table storage location must not be root path.
     */
    static public boolean validateTblStorage(StorageDescriptor sd) {
      return !(StringUtils.isNotBlank(sd.getLocation())
              && new Path(sd.getLocation()).getParent() == null);
    }
   ```
   
   I add a test for this feature:
   
   ```
     @Test
     public void throwFailExceptionWithHDFSStorageIsRootPath() {
       StorageDescriptor sd = new StorageDescriptor();
       sd.setLocation("hdfs://localhost:8020");
       Assert.assertFalse(MetaStoreUtils.validateTblStorage(sd));
   
       sd.setLocation("hdfs://localhost:8020/other_path");
       Assert.assertTrue(MetaStoreUtils.validateTblStorage(sd));
     }
   
     @Test
     public void throwFailExceptionWithS3StorageIsRootPath() {
       StorageDescriptor sd = new StorageDescriptor();
       sd.setLocation("s3a://bucket/");
       Assert.assertFalse(MetaStoreUtils.validateTblStorage(sd));
   
       sd.setLocation("s3a://bucket");
       Assert.assertFalse(MetaStoreUtils.validateTblStorage(sd));
   
       sd.setLocation("s3a://bucket/other_path");
       Assert.assertTrue(MetaStoreUtils.validateTblStorage(sd));
     }
   ```
   
   ### Why are the changes needed?
   If I create an external table using the ROOT path, the table was created 
successfully, but when I drop the table throw the NPE.  So I can't drop the 
table forever.
   
   This is not a good phenomenon.
   
   ### Does this PR introduce _any_ user-facing change?
   no
   
   
   ### How was this patch tested?
   
   
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/TestMetaStoreServerUtils.java
   
   test func is: throwFailExceptionWithS3StorageIsRootPath and 
throwFailExceptionWithHDFSStorageIsRootPath
   
   mvn test -Dtest=SomeTest --pl common
   


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

To unsubscribe, e-mail: [email protected]

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