You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ct...@apache.org on 2016/12/14 21:05:25 UTC

hive git commit: HIVE-15410: WebHCat supports get/set table property with its name containing period and hyphen (Chaoyu Tang, reviewed by Thejas M Nair)

Repository: hive
Updated Branches:
  refs/heads/master 44a81d588 -> 5c325f7e0


HIVE-15410: WebHCat supports get/set table property with its name containing period and hyphen (Chaoyu Tang, reviewed by Thejas M Nair)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/5c325f7e
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/5c325f7e
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/5c325f7e

Branch: refs/heads/master
Commit: 5c325f7e02e3b2eacdc24eb487590cbf48a3eeda
Parents: 44a81d5
Author: Chaoyu Tang <ct...@cloudera.com>
Authored: Wed Dec 14 16:05:15 2016 -0500
Committer: Chaoyu Tang <ct...@cloudera.com>
Committed: Wed Dec 14 16:05:15 2016 -0500

----------------------------------------------------------------------
 .../apache/hive/hcatalog/templeton/Server.java  | 21 ++++++++++++--
 .../hive/hcatalog/templeton/TestServer.java     | 30 ++++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/5c325f7e/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java
----------------------------------------------------------------------
diff --git a/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java b/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java
index 77c8610..2da0204 100644
--- a/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java
+++ b/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java
@@ -363,7 +363,7 @@ public class Server {
     verifyUser();
     verifyDdlParam(db, ":db");
     verifyDdlParam(table, ":table");
-    verifyDdlParam(property, ":property");
+    verifyPropertyParam(property, ":property");
 
     HcatDelegator d = new HcatDelegator(appConf, execService);
     return d.descTableProperty(getDoAsUser(), db, table, property);
@@ -402,7 +402,7 @@ public class Server {
     verifyUser();
     verifyDdlParam(db, ":db");
     verifyDdlParam(table, ":table");
-    verifyDdlParam(property, ":property");
+    verifyPropertyParam(property, ":property");
     desc.name = property;
 
     HcatDelegator d = new HcatDelegator(appConf, execService);
@@ -1119,6 +1119,8 @@ public class Server {
   }
 
   public static final Pattern DDL_ID = Pattern.compile("[a-zA-Z]\\w*");
+  public static final Pattern PROPERTY_ID =
+      Pattern.compile("[a-zA-Z0-9][\\w\\.\\-]*(?<!\\-)(?<!\\.)(?<!\\_)$");
 
   /**
    * Verify that the parameter exists and is a simple DDL identifier
@@ -1134,6 +1136,21 @@ public class Server {
       throw new BadParam("Invalid DDL identifier " + name);
     }
   }
+
+  /**
+   * Verify that the parameter exists and is a valid property
+   * name.  Throw an exception if invalid.
+   *
+   */
+  public void verifyPropertyParam(String param, String name)
+    throws BadParam {
+    verifyParam(param, name);
+    Matcher m = PROPERTY_ID.matcher(param);
+    if (!m.matches()) {
+      throw new BadParam("Invalid property name " + name);
+    }
+  }
+
   /**
    * Get the user name from the security context, i.e. the user making the HTTP request.
    * With simple/pseudo security mode this should return the

http://git-wip-us.apache.org/repos/asf/hive/blob/5c325f7e/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestServer.java
----------------------------------------------------------------------
diff --git a/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestServer.java b/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestServer.java
index cf02c76..e9148a8 100644
--- a/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestServer.java
+++ b/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestServer.java
@@ -51,4 +51,34 @@ public class TestServer extends TestCase {
     assertEquals(1, server.requestFormats().size());
     assertEquals( ((List)server.requestFormats().get("responseTypes")).get(0), "application/json");
   }
+
+  public void testVerifyPropertyParam() {
+    // HIVE-15410: Though there are not restrictions to Hive table property key and it could be any
+    // combination of the letters, digits and even punctuations, we support conventional property
+    // name in WebHCat (e.g. prepery name starting with a letter or digit probably with period (.),
+    // underscore (_) and hyphen (-) only in the middle like auto.purge, last_modified_by etc)
+    String [] validTblProperties = {"abcd", "Abcd", "1Abcd", "abc1d", "Abcd.efgh", "Abcd-efgh",
+        "Abcd_efgh", "A", "b", "1"};
+    for (String propertyKey : validTblProperties) {
+      try {
+        server.verifyPropertyParam(propertyKey, ":property");
+      } catch (Exception e) {
+        fail(propertyKey + " should be a valid table property name in WebHCat.");
+      }
+    }
+
+    String [] invalidTblProperties = {".abcd", "-Abcd", "_1Abcd", "abc1d.", "Abcd_", "Abcd-",
+    "Abcd ", " Abcd", ".", "-", "_", " ", "$"};
+    for (String propertyKey : invalidTblProperties) {
+      boolean throwException = false;
+      try {
+        server.verifyPropertyParam(propertyKey, ":property");
+      } catch (Exception e) {
+        throwException = true;
+      }
+      if (!throwException) {
+        fail(propertyKey + " should not be a valid table property name in WebHCat.");
+      }
+    }
+  }
 }