HIVE-19372: Add table ownerType to JDO/SQL and ObjectStore (Sergio Pena, 
reviewed by Vihang Karajgaonkar)


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

Branch: refs/heads/branch-2
Commit: 72f75d37675cad605e7b8fd1f2255470255395ce
Parents: 117c3b4
Author: Sergio Pena <[email protected]>
Authored: Thu May 24 17:02:49 2018 -0500
Committer: Sergio Pena <[email protected]>
Committed: Wed May 30 08:21:12 2018 -0500

----------------------------------------------------------------------
 .../metastore/hbase/TestHBaseSchemaTool.java     |  8 ++++----
 .../upgrade/derby/041-HIVE-19372.derby.sql       |  1 +
 .../upgrade/derby/hive-schema-2.4.0.derby.sql    |  2 +-
 .../derby/upgrade-2.3.0-to-2.4.0.derby.sql       |  2 ++
 .../upgrade/mssql/026-HIVE-19372.mssql.sql       |  1 +
 .../upgrade/mssql/hive-schema-2.4.0.mssql.sql    |  1 +
 .../mssql/upgrade-2.3.0-to-2.4.0.mssql.sql       |  2 ++
 .../upgrade/mysql/041-HIVE-19372.mysql.sql       |  1 +
 .../upgrade/mysql/hive-schema-2.4.0.mysql.sql    |  1 +
 .../mysql/upgrade-2.3.0-to-2.4.0.mysql.sql       |  2 ++
 .../upgrade/oracle/041-HIVE-19372.oracle.sql     |  1 +
 .../upgrade/oracle/hive-schema-2.4.0.oracle.sql  |  1 +
 .../oracle/upgrade-2.3.0-to-2.4.0.oracle.sql     |  1 +
 .../upgrade/postgres/040-HIVE-19372.postgres.sql |  1 +
 .../postgres/hive-schema-2.4.0.postgres.sql      |  1 +
 .../postgres/upgrade-2.3.0-to-2.4.0.postgres.sql |  1 +
 .../hadoop/hive/metastore/ObjectStore.java       | 16 +++++++++++++++-
 .../hadoop/hive/metastore/model/MTable.java      | 19 ++++++++++++++++++-
 metastore/src/model/package.jdo                  |  3 +++
 .../hadoop/hive/metastore/TestObjectStore.java   | 10 ++++++++++
 20 files changed, 68 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseSchemaTool.java
----------------------------------------------------------------------
diff --git 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseSchemaTool.java
 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseSchemaTool.java
index c98911a..68ed10c 100644
--- 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseSchemaTool.java
+++ 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseSchemaTool.java
@@ -455,7 +455,7 @@ public class TestHBaseSchemaTool extends 
HBaseIntegrationTests {
         "\"createTime\":0,\"lastAccessTime\":0,\"retention\":0," +
         
"\"partitionKeys\":[{\"name\":\"pcol1\",\"type\":\"string\",\"comment\":\"\"}," 
+
         
"{\"name\":\"pcol2\",\"type\":\"string\",\"comment\":\"\"}],\"parameters\":{}," 
+
-        "\"tableType\":\"\",\"rewriteEnabled\":0} sdHash: 
qQTgZAi5VzgpozzFGmIVTQ stats:" + lsep,
+        "\"tableType\":\"\",\"rewriteEnabled\":0,\"ownerType\":1} sdHash: 
qQTgZAi5VzgpozzFGmIVTQ stats:" + lsep,
         outStr.toString());
 
     outStr = new ByteArrayOutputStream();
@@ -465,7 +465,7 @@ public class TestHBaseSchemaTool extends 
HBaseIntegrationTests {
         "\"createTime\":0,\"lastAccessTime\":0,\"retention\":0," +
         
"\"partitionKeys\":[{\"name\":\"pcol1\",\"type\":\"string\",\"comment\":\"\"}," 
+
         
"{\"name\":\"pcol2\",\"type\":\"string\",\"comment\":\"\"}],\"parameters\":{\"COLUMN_STATS_ACCURATE\":\"{\\\"COLUMN_STATS\\\":{\\\"col1\\\":\\\"true\\\",\\\"col2\\\":\\\"true\\\"}}\"},"
 +
-            "\"tableType\":\"\",\"rewriteEnabled\":0} sdHash: 
qQTgZAi5VzgpozzFGmIVTQ stats: column " +
+            "\"tableType\":\"\",\"rewriteEnabled\":0,\"ownerType\":1} sdHash: 
qQTgZAi5VzgpozzFGmIVTQ stats: column " +
             "col1: {\"colName\":\"col1\",\"colType\":\"int\"," +
             
"\"statsData\":{\"longStats\":{\"lowValue\":-95,\"highValue\":95,\"numNulls\":1,"
 +
             "\"numDVs\":2,\"bitVectors\":\"\"}}} column col2: 
{\"colName\":\"col2\",\"colType\":\"varchar(32)\"," +
@@ -474,12 +474,12 @@ public class TestHBaseSchemaTool extends 
HBaseIntegrationTests {
         
"{\"tableName\":\"tab1\",\"dbName\":\"db0\",\"owner\":\"me\",\"createTime\":0," 
+
         
"\"lastAccessTime\":0,\"retention\":0,\"partitionKeys\":[{\"name\":\"pcol1\"," +
             
"\"type\":\"string\",\"comment\":\"\"},{\"name\":\"pcol2\",\"type\":\"string\","
 +
-            
"\"comment\":\"\"}],\"parameters\":{},\"tableType\":\"\",\"rewriteEnabled\":0} 
sdHash: " +
+            
"\"comment\":\"\"}],\"parameters\":{},\"tableType\":\"\",\"rewriteEnabled\":0,\"ownerType\":1}
 sdHash: " +
             "qQTgZAi5VzgpozzFGmIVTQ stats:" + lsep +
         
"{\"tableName\":\"tab2\",\"dbName\":\"db0\",\"owner\":\"me\",\"createTime\":0," 
+
         
"\"lastAccessTime\":0,\"retention\":0,\"partitionKeys\":[{\"name\":\"pcol1\"," +
         
"\"type\":\"string\",\"comment\":\"\"},{\"name\":\"pcol2\",\"type\":\"string\","
 +
-        
"\"comment\":\"\"}],\"parameters\":{},\"tableType\":\"\",\"rewriteEnabled\":0} 
sdHash: " +
+        
"\"comment\":\"\"}],\"parameters\":{},\"tableType\":\"\",\"rewriteEnabled\":0,\"ownerType\":1}
 sdHash: " +
         "qQTgZAi5VzgpozzFGmIVTQ stats:" + lsep, outStr.toString());
 
     List<List<String>> partVals = Arrays.asList(Arrays.asList("a", "b"), 
Arrays.asList("c", "d"));

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/derby/041-HIVE-19372.derby.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/derby/041-HIVE-19372.derby.sql 
b/metastore/scripts/upgrade/derby/041-HIVE-19372.derby.sql
new file mode 100644
index 0000000..4119607
--- /dev/null
+++ b/metastore/scripts/upgrade/derby/041-HIVE-19372.derby.sql
@@ -0,0 +1 @@
+ALTER TABLE "APP"."TBLS" ADD COLUMN "OWNER_TYPE" VARCHAR(10);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/derby/hive-schema-2.4.0.derby.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/derby/hive-schema-2.4.0.derby.sql 
b/metastore/scripts/upgrade/derby/hive-schema-2.4.0.derby.sql
index 8e69b4c..f30b5b4 100644
--- a/metastore/scripts/upgrade/derby/hive-schema-2.4.0.derby.sql
+++ b/metastore/scripts/upgrade/derby/hive-schema-2.4.0.derby.sql
@@ -60,7 +60,7 @@ CREATE TABLE "APP"."COLUMNS" ("SD_ID" BIGINT NOT NULL, 
"COMMENT" VARCHAR(256), "
 
 CREATE TABLE "APP"."ROLES" ("ROLE_ID" BIGINT NOT NULL, "CREATE_TIME" INTEGER 
NOT NULL, "OWNER_NAME" VARCHAR(128), "ROLE_NAME" VARCHAR(128));
 
-CREATE TABLE "APP"."TBLS" ("TBL_ID" BIGINT NOT NULL, "CREATE_TIME" INTEGER NOT 
NULL, "DB_ID" BIGINT, "LAST_ACCESS_TIME" INTEGER NOT NULL, "OWNER" 
VARCHAR(767), "RETENTION" INTEGER NOT NULL, "SD_ID" BIGINT, "TBL_NAME" 
VARCHAR(256), "TBL_TYPE" VARCHAR(128), "VIEW_EXPANDED_TEXT" LONG VARCHAR, 
"VIEW_ORIGINAL_TEXT" LONG VARCHAR, "IS_REWRITE_ENABLED" CHAR(1) NOT NULL);
+CREATE TABLE "APP"."TBLS" ("TBL_ID" BIGINT NOT NULL, "CREATE_TIME" INTEGER NOT 
NULL, "DB_ID" BIGINT, "LAST_ACCESS_TIME" INTEGER NOT NULL, "OWNER" 
VARCHAR(767), "OWNER_TYPE" VARCHAR(10), "RETENTION" INTEGER NOT NULL, "SD_ID" 
BIGINT, "TBL_NAME" VARCHAR(256), "TBL_TYPE" VARCHAR(128), "VIEW_EXPANDED_TEXT" 
LONG VARCHAR, "VIEW_ORIGINAL_TEXT" LONG VARCHAR, "IS_REWRITE_ENABLED" CHAR(1) 
NOT NULL);
 
 CREATE TABLE "APP"."PARTITION_KEYS" ("TBL_ID" BIGINT NOT NULL, "PKEY_COMMENT" 
VARCHAR(4000), "PKEY_NAME" VARCHAR(128) NOT NULL, "PKEY_TYPE" VARCHAR(767) NOT 
NULL, "INTEGER_IDX" INTEGER NOT NULL);
 

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/derby/upgrade-2.3.0-to-2.4.0.derby.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/derby/upgrade-2.3.0-to-2.4.0.derby.sql 
b/metastore/scripts/upgrade/derby/upgrade-2.3.0-to-2.4.0.derby.sql
index 4bb473f..58dde50 100644
--- a/metastore/scripts/upgrade/derby/upgrade-2.3.0-to-2.4.0.derby.sql
+++ b/metastore/scripts/upgrade/derby/upgrade-2.3.0-to-2.4.0.derby.sql
@@ -1,3 +1,5 @@
 -- Upgrade MetaStore schema from 2.3.0 to 2.4.0
 
+RUN '041-HIVE-19372.derby.sql';
+
 UPDATE "APP".VERSION SET SCHEMA_VERSION='2.4.0', VERSION_COMMENT='Hive release 
version 2.4.0' where VER_ID=1;

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/mssql/026-HIVE-19372.mssql.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/mssql/026-HIVE-19372.mssql.sql 
b/metastore/scripts/upgrade/mssql/026-HIVE-19372.mssql.sql
new file mode 100644
index 0000000..4119607
--- /dev/null
+++ b/metastore/scripts/upgrade/mssql/026-HIVE-19372.mssql.sql
@@ -0,0 +1 @@
+ALTER TABLE "APP"."TBLS" ADD COLUMN "OWNER_TYPE" VARCHAR(10);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/mssql/hive-schema-2.4.0.mssql.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/mssql/hive-schema-2.4.0.mssql.sql 
b/metastore/scripts/upgrade/mssql/hive-schema-2.4.0.mssql.sql
index 20f6be0..c6c733e 100644
--- a/metastore/scripts/upgrade/mssql/hive-schema-2.4.0.mssql.sql
+++ b/metastore/scripts/upgrade/mssql/hive-schema-2.4.0.mssql.sql
@@ -353,6 +353,7 @@ CREATE TABLE TBLS
     DB_ID bigint NULL,
     LAST_ACCESS_TIME int NOT NULL,
     OWNER nvarchar(767) NULL,
+    OWNER_TYPE nvarchar(10) NULL,
     RETENTION int NOT NULL,
     SD_ID bigint NULL,
     TBL_NAME nvarchar(256) NULL,

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/mssql/upgrade-2.3.0-to-2.4.0.mssql.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/mssql/upgrade-2.3.0-to-2.4.0.mssql.sql 
b/metastore/scripts/upgrade/mssql/upgrade-2.3.0-to-2.4.0.mssql.sql
index 6877315..b3cceea 100644
--- a/metastore/scripts/upgrade/mssql/upgrade-2.3.0-to-2.4.0.mssql.sql
+++ b/metastore/scripts/upgrade/mssql/upgrade-2.3.0-to-2.4.0.mssql.sql
@@ -1,4 +1,6 @@
 SELECT 'Upgrading MetaStore schema from 2.3.0 to 2.4.0' AS MESSAGE;
 
+:r 026-HIVE-19372.mssql.sql
+
 UPDATE VERSION SET SCHEMA_VERSION='2.4.0', VERSION_COMMENT='Hive release 
version 2.4.0' where VER_ID=1;
 SELECT 'Finished upgrading MetaStore schema from 2.3.0 to 2.4.0' AS MESSAGE;

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/mysql/041-HIVE-19372.mysql.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/mysql/041-HIVE-19372.mysql.sql 
b/metastore/scripts/upgrade/mysql/041-HIVE-19372.mysql.sql
new file mode 100644
index 0000000..da4aff7
--- /dev/null
+++ b/metastore/scripts/upgrade/mysql/041-HIVE-19372.mysql.sql
@@ -0,0 +1 @@
+ALTER TABLE `TBLS` ADD COLUMN `OWNER_TYPE` VARCHAR(10) CHARACTER SET latin1 
COLLATE latin1_bin DEFAULT NULL;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/mysql/hive-schema-2.4.0.mysql.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/mysql/hive-schema-2.4.0.mysql.sql 
b/metastore/scripts/upgrade/mysql/hive-schema-2.4.0.mysql.sql
index 2f9aff2..7aed5a8 100644
--- a/metastore/scripts/upgrade/mysql/hive-schema-2.4.0.mysql.sql
+++ b/metastore/scripts/upgrade/mysql/hive-schema-2.4.0.mysql.sql
@@ -581,6 +581,7 @@ CREATE TABLE IF NOT EXISTS `TBLS` (
   `DB_ID` bigint(20) DEFAULT NULL,
   `LAST_ACCESS_TIME` int(11) NOT NULL,
   `OWNER` varchar(767) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
+  `OWNER_TYPE` varchar(10) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT 
NULL,
   `RETENTION` int(11) NOT NULL,
   `SD_ID` bigint(20) DEFAULT NULL,
   `TBL_NAME` varchar(256) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/mysql/upgrade-2.3.0-to-2.4.0.mysql.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/mysql/upgrade-2.3.0-to-2.4.0.mysql.sql 
b/metastore/scripts/upgrade/mysql/upgrade-2.3.0-to-2.4.0.mysql.sql
index 68db617..d85b30b 100644
--- a/metastore/scripts/upgrade/mysql/upgrade-2.3.0-to-2.4.0.mysql.sql
+++ b/metastore/scripts/upgrade/mysql/upgrade-2.3.0-to-2.4.0.mysql.sql
@@ -1,5 +1,7 @@
 SELECT 'Upgrading MetaStore schema from 2.3.0 to 2.4.0' AS ' ';
 
+SOURCE 041-HIVE-19372.mysql.sql;
+
 UPDATE VERSION SET SCHEMA_VERSION='2.4.0', VERSION_COMMENT='Hive release 
version 2.4.0' where VER_ID=1;
 SELECT 'Finished upgrading MetaStore schema from 2.3.0 to 2.4.0' AS ' ';
 

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/oracle/041-HIVE-19372.oracle.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/oracle/041-HIVE-19372.oracle.sql 
b/metastore/scripts/upgrade/oracle/041-HIVE-19372.oracle.sql
new file mode 100644
index 0000000..98264f3
--- /dev/null
+++ b/metastore/scripts/upgrade/oracle/041-HIVE-19372.oracle.sql
@@ -0,0 +1 @@
+ALTER TABLE TBLS ADD OWNER_TYPE VARCHAR2(10) NULL;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/oracle/hive-schema-2.4.0.oracle.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/oracle/hive-schema-2.4.0.oracle.sql 
b/metastore/scripts/upgrade/oracle/hive-schema-2.4.0.oracle.sql
index c07ca79..94d1221 100644
--- a/metastore/scripts/upgrade/oracle/hive-schema-2.4.0.oracle.sql
+++ b/metastore/scripts/upgrade/oracle/hive-schema-2.4.0.oracle.sql
@@ -370,6 +370,7 @@ CREATE TABLE TBLS
     DB_ID NUMBER NULL,
     LAST_ACCESS_TIME NUMBER (10) NOT NULL,
     OWNER VARCHAR2(767) NULL,
+    OWNER_TYPE VARCHAR2(10) NULL,
     RETENTION NUMBER (10) NOT NULL,
     SD_ID NUMBER NULL,
     TBL_NAME VARCHAR2(256) NULL,

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/oracle/upgrade-2.3.0-to-2.4.0.oracle.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/oracle/upgrade-2.3.0-to-2.4.0.oracle.sql 
b/metastore/scripts/upgrade/oracle/upgrade-2.3.0-to-2.4.0.oracle.sql
index 45a274a..3b4e273 100644
--- a/metastore/scripts/upgrade/oracle/upgrade-2.3.0-to-2.4.0.oracle.sql
+++ b/metastore/scripts/upgrade/oracle/upgrade-2.3.0-to-2.4.0.oracle.sql
@@ -1,6 +1,7 @@
 SELECT 'Upgrading MetaStore schema from 2.3.0 to 2.4.0' AS Status from dual;
 
 @040-HIVE-16399.oracle.sql;
[email protected];
 
 UPDATE VERSION SET SCHEMA_VERSION='2.4.0', VERSION_COMMENT='Hive release 
version 2.4.0' where VER_ID=1;
 SELECT 'Finished upgrading MetaStore schema from 2.3.0 to 2.4.0' AS Status 
from dual;

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/postgres/040-HIVE-19372.postgres.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/postgres/040-HIVE-19372.postgres.sql 
b/metastore/scripts/upgrade/postgres/040-HIVE-19372.postgres.sql
new file mode 100644
index 0000000..dfa469c
--- /dev/null
+++ b/metastore/scripts/upgrade/postgres/040-HIVE-19372.postgres.sql
@@ -0,0 +1 @@
+ALTER TABLE "TBLS" ADD COLUMN "OWNER_TYPE" character varying(10) DEFAULT 
NULL::character varying;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/postgres/hive-schema-2.4.0.postgres.sql
----------------------------------------------------------------------
diff --git a/metastore/scripts/upgrade/postgres/hive-schema-2.4.0.postgres.sql 
b/metastore/scripts/upgrade/postgres/hive-schema-2.4.0.postgres.sql
index c54d9e7..ffa29cf 100644
--- a/metastore/scripts/upgrade/postgres/hive-schema-2.4.0.postgres.sql
+++ b/metastore/scripts/upgrade/postgres/hive-schema-2.4.0.postgres.sql
@@ -367,6 +367,7 @@ CREATE TABLE "TBLS" (
     "DB_ID" bigint,
     "LAST_ACCESS_TIME" bigint NOT NULL,
     "OWNER" character varying(767) DEFAULT NULL::character varying,
+    "OWNER_TYPE" character varying(10) DEFAULT NULL::character varying,
     "RETENTION" bigint NOT NULL,
     "SD_ID" bigint,
     "TBL_NAME" character varying(256) DEFAULT NULL::character varying,

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/scripts/upgrade/postgres/upgrade-2.3.0-to-2.4.0.postgres.sql
----------------------------------------------------------------------
diff --git 
a/metastore/scripts/upgrade/postgres/upgrade-2.3.0-to-2.4.0.postgres.sql 
b/metastore/scripts/upgrade/postgres/upgrade-2.3.0-to-2.4.0.postgres.sql
index 5e34d96..1b2a52a 100644
--- a/metastore/scripts/upgrade/postgres/upgrade-2.3.0-to-2.4.0.postgres.sql
+++ b/metastore/scripts/upgrade/postgres/upgrade-2.3.0-to-2.4.0.postgres.sql
@@ -1,6 +1,7 @@
 SELECT 'Upgrading MetaStore schema from 2.3.0 to 2.4.0';
 
 \i 039-HIVE-16399.postgres.sql;
+\i 040-HIVE-19372.postgres.sql;
 
 UPDATE "VERSION" SET "SCHEMA_VERSION"='2.4.0', "VERSION_COMMENT"='Hive release 
version 2.4.0' where "VER_ID"=1;
 SELECT 'Finished upgrading MetaStore schema from 2.3.0 to 2.4.0';

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
----------------------------------------------------------------------
diff --git 
a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java 
b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
index d85a001..ba46e63 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
@@ -56,6 +56,7 @@ import javax.jdo.Transaction;
 import javax.jdo.datastore.DataStoreCache;
 import javax.jdo.identity.IntIdentity;
 
+import com.google.common.base.Strings;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.hadoop.conf.Configurable;
 import org.apache.hadoop.conf.Configuration;
@@ -1445,6 +1446,15 @@ public class ObjectStore implements RawStore, 
Configurable {
             .getRetention(), convertToStorageDescriptor(mtbl.getSd()),
             convertToFieldSchemas(mtbl.getPartitionKeys()), 
convertMap(mtbl.getParameters()),
             mtbl.getViewOriginalText(), mtbl.getViewExpandedText(), tableType);
+
+    if (Strings.isNullOrEmpty(mtbl.getOwnerType())) {
+      // Before the ownerType exists in an old Hive schema, USER was the 
default type for owner.
+      // Let's set the default to USER to keep backward compatibility.
+      table.setOwnerType(PrincipalType.USER);
+    } else {
+      table.setOwnerType(PrincipalType.valueOf(mtbl.getOwnerType()));
+    }
+
     table.setRewriteEnabled(mtbl.isRewriteEnabled());
     return table;
   }
@@ -1478,9 +1488,12 @@ public class ObjectStore implements RawStore, 
Configurable {
       }
     }
 
+    PrincipalType ownerPrincipalType = tbl.getOwnerType();
+    String ownerType = (ownerPrincipalType == null) ? 
PrincipalType.USER.name() : ownerPrincipalType.name();
+
     // A new table is always created with a new column descriptor
     return new MTable(HiveStringUtils.normalizeIdentifier(tbl.getTableName()), 
mdb,
-        convertToMStorageDescriptor(tbl.getSd()), tbl.getOwner(), tbl
+        convertToMStorageDescriptor(tbl.getSd()), tbl.getOwner(), ownerType, 
tbl
         .getCreateTime(), tbl.getLastAccessTime(), tbl.getRetention(),
         convertToMFieldSchemas(tbl.getPartitionKeys()), tbl.getParameters(),
         tbl.getViewOriginalText(), tbl.getViewExpandedText(), 
tbl.isRewriteEnabled(),
@@ -3463,6 +3476,7 @@ public class ObjectStore implements RawStore, 
Configurable {
       
oldt.setTableName(HiveStringUtils.normalizeIdentifier(newt.getTableName()));
       oldt.setParameters(newt.getParameters());
       oldt.setOwner(newt.getOwner());
+      oldt.setOwnerType(newt.getOwnerType());
       // Fully copy over the contents of the new SD into the old SD,
       // so we don't create an extra SD in the metastore db that has no 
references.
       copyMSD(newt.getSd(), oldt.getSd());

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/src/model/org/apache/hadoop/hive/metastore/model/MTable.java
----------------------------------------------------------------------
diff --git 
a/metastore/src/model/org/apache/hadoop/hive/metastore/model/MTable.java 
b/metastore/src/model/org/apache/hadoop/hive/metastore/model/MTable.java
index 6cc7157..0fd8bf0 100644
--- a/metastore/src/model/org/apache/hadoop/hive/metastore/model/MTable.java
+++ b/metastore/src/model/org/apache/hadoop/hive/metastore/model/MTable.java
@@ -27,6 +27,7 @@ public class MTable {
   private MDatabase database;
   private MStorageDescriptor sd;
   private String owner;
+  private String ownerType;
   private int createTime;
   private int lastAccessTime;
   private int retention;
@@ -44,6 +45,7 @@ public class MTable {
    * @param database
    * @param sd
    * @param owner
+   * @param ownerType
    * @param createTime
    * @param lastAccessTime
    * @param retention
@@ -53,7 +55,7 @@ public class MTable {
    * @param viewExpandedText
    * @param tableType
    */
-  public MTable(String tableName, MDatabase database, MStorageDescriptor sd, 
String owner,
+  public MTable(String tableName, MDatabase database, MStorageDescriptor sd, 
String owner, String ownerType,
       int createTime, int lastAccessTime, int retention, List<MFieldSchema> 
partitionKeys,
       Map<String, String> parameters, String viewOriginalText, String 
viewExpandedText,
       boolean rewriteEnabled, String tableType) {
@@ -61,6 +63,7 @@ public class MTable {
     this.database = database;
     this.sd = sd;
     this.owner = owner;
+    this.ownerType = ownerType;
     this.createTime = createTime;
     this.setLastAccessTime(lastAccessTime);
     this.retention = retention;
@@ -73,6 +76,20 @@ public class MTable {
   }
 
   /**
+   * @return the owner type
+   */
+  public String getOwnerType() {
+    return ownerType;
+  }
+
+  /**
+   * @param ownerType the owner type to set
+   */
+  public void setOwnerType(String ownerType) {
+    this.ownerType = ownerType;
+  }
+
+  /**
    * @return the tableName
    */
   public String getTableName() {

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/src/model/package.jdo
----------------------------------------------------------------------
diff --git a/metastore/src/model/package.jdo b/metastore/src/model/package.jdo
index bdecd2a..b272456 100644
--- a/metastore/src/model/package.jdo
+++ b/metastore/src/model/package.jdo
@@ -152,6 +152,9 @@
       <field name="owner">
         <column name="OWNER" length="767" jdbc-type="VARCHAR"/>
       </field>
+      <field name="ownerType">
+        <column name="OWNER_TYPE" length="10" jdbc-type="VARCHAR" 
allows-null="true"/>
+      </field>
       <field name="createTime">
         <column name="CREATE_TIME" jdbc-type="integer"/>
       </field>

http://git-wip-us.apache.org/repos/asf/hive/blob/72f75d37/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java
----------------------------------------------------------------------
diff --git 
a/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java 
b/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java
index 4ba1a03..27dda1f 100644
--- a/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java
+++ b/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java
@@ -234,11 +234,21 @@ public class TestObjectStore {
     Assert.assertEquals(TABLE1, tables.get(0));
 
     Table newTbl1 = new Table("new" + TABLE1, DB1, "owner", 1, 2, 3, sd, null, 
params, null, null, "MANAGED_TABLE");
+
+    // Change different fields and verify they were altered
+    newTbl1.setOwner("role1");
+    newTbl1.setOwnerType(PrincipalType.ROLE);
+
     objectStore.alterTable(DB1, TABLE1, newTbl1);
     tables = objectStore.getTables(DB1, "new*");
     Assert.assertEquals(1, tables.size());
     Assert.assertEquals("new" + TABLE1, tables.get(0));
 
+    // Verify fields were altered during the alterTable operation
+    Table alteredTable = objectStore.getTable(DB1, "new" + TABLE1);
+    Assert.assertEquals("Owner of table was not altered", newTbl1.getOwner(), 
alteredTable.getOwner());
+    Assert.assertEquals("Owner type of table was not altered", 
newTbl1.getOwnerType(), alteredTable.getOwnerType());
+
     objectStore.dropTable(DB1, "new" + TABLE1);
     tables = objectStore.getAllTables(DB1);
     Assert.assertEquals(0, tables.size());

Reply via email to