You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by an...@apache.org on 2017/04/18 23:05:56 UTC

[3/4] incubator-trafodion git commit: [TRAFODION-2584] Add support to register hive objects in traf metadata

[TRAFODION-2584] Add support to register hive objects in traf metadata

Syntax:
  register hive table/view [if not exists] <object-name> [cascade]
  unregister hive table/view  [if exists] <object-name> [cascade]
  cascade option: register/unregister all underlying objects that are
                  part of the specified view

update statistics, grant/revoke, traf views or external table creation
on hive objects will automatically and internally register those objects
in trafodion metadata.

invoke/showddl will show if this object is registered and whether
that registration was internal or explicit.

Get command extensions:
  get hive registered tables/view/objects in catalog trafodion;
  get hive external tables in catalog trafodion;

Cleanup command extensions:
  cleanup metadata command will clean up  inconsistent hive objects
   (underlying hive object is missing but object is registered or
    an external table exists)

   cleanup [hive table | hive view] on <object-name>;

Existing hive objects that had implicit or explicit external tables
created prior to this checkin will have no change in behavior.
ObjectUID of those external tables will continue to be used for
relevant operations.
One can drop those external tables and explicitly register them,
or a subsequent operation(upd stats, grant, etc) that needs objectUID will
automatically register them.

minor changes based on review comments of previous checkin

get all objects   command on hive metadata no longer fails.
get views on objects   return 3-part name that could be used to
  differentiate between a traf and hive view.

regress/hive/TEST007 has been extended.

TBD: Add register/unregister privileges


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/9c58649f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/9c58649f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/9c58649f

Branch: refs/heads/master
Commit: 9c58649f930a799f03a2703d012371e4e66fa1a2
Parents: d14bfb5
Author: Anoop Sharma <an...@esgyn.com>
Authored: Fri Apr 14 19:38:18 2017 +0000
Committer: Anoop Sharma <an...@esgyn.com>
Committed: Fri Apr 14 19:38:18 2017 +0000

----------------------------------------------------------------------
 core/sql/bin/SqlciErrors.txt              |   7 +-
 core/sql/comexe/ComTdbExeUtil.h           |   4 +
 core/sql/common/ComMisc.cpp               |  14 +-
 core/sql/common/ComMisc.h                 |   7 +-
 core/sql/common/ComSmallDefs.h            |   1 +
 core/sql/common/OperTypeEnum.h            |   1 +
 core/sql/executor/ExExeUtil.h             |   2 +-
 core/sql/executor/ExExeUtilGet.cpp        | 329 ++++++++---
 core/sql/generator/GenRelExeUtil.cpp      |  50 +-
 core/sql/generator/GenRelMisc.cpp         |   8 +-
 core/sql/optimizer/BindItemExpr.cpp       |   9 +-
 core/sql/optimizer/BindRelExpr.cpp        |   2 +
 core/sql/optimizer/NATable.cpp            | 209 +++++--
 core/sql/optimizer/NATable.h              |  21 +-
 core/sql/optimizer/RelExeUtil.cpp         |  32 +-
 core/sql/parser/AllStmtDDL.h              |   1 +
 core/sql/parser/BindStmtDDL.cpp           |  23 +
 core/sql/parser/ElemDDLNode.cpp           |   6 +
 core/sql/parser/ElemDDLNode.h             |   6 +-
 core/sql/parser/ParAll.cpp                |   1 +
 core/sql/parser/ParKeyWords.cpp           |   1 +
 core/sql/parser/StmtDDLCleanupObjects.h   |   2 +
 core/sql/parser/StmtDDLMisc.cpp           |   2 +
 core/sql/parser/StmtDDLRegOrUnregHive.cpp |  97 ++++
 core/sql/parser/StmtDDLRegOrUnregHive.h   | 134 +++++
 core/sql/parser/sqlparser.y               |  99 ++++
 core/sql/regress/charsets/EXPECTED004     |   6 +-
 core/sql/regress/hive/EXPECTED007         | 466 ++++++++++++++--
 core/sql/regress/hive/EXPECTED009         |  30 +-
 core/sql/regress/hive/FILTER007           |  40 ++
 core/sql/regress/hive/TEST007             | 108 +++-
 core/sql/regress/privs1/EXPECTED133       | Bin 27095 -> 27095 bytes
 core/sql/regress/privs1/EXPECTED137       |  28 +
 core/sql/regress/seabase/EXPECTED012      |   8 +-
 core/sql/regress/seabase/EXPECTED026      |  35 +-
 core/sql/regress/seabase/EXPECTED027      | 106 ++--
 core/sql/regress/seabase/EXPECTED031      |   4 +-
 core/sql/sqlcomp/CmpDescribe.cpp          |  70 +++
 core/sql/sqlcomp/CmpSeabaseDDL.h          |  68 ++-
 core/sql/sqlcomp/CmpSeabaseDDLcleanup.cpp | 214 ++++++-
 core/sql/sqlcomp/CmpSeabaseDDLcleanup.h   |   9 +
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp  | 173 ++++--
 core/sql/sqlcomp/CmpSeabaseDDLincludes.h  |   1 +
 core/sql/sqlcomp/CmpSeabaseDDLmd.h        |   8 +-
 core/sql/sqlcomp/CmpSeabaseDDLtable.cpp   | 735 +++++++++++++++++++++++--
 core/sql/sqlcomp/CmpSeabaseDDLview.cpp    |  32 +-
 core/sql/sqlcomp/DefaultConstants.h       |  19 +-
 core/sql/sqlcomp/PrivMgr.cpp              |  14 +-
 core/sql/sqlcomp/PrivMgrCommands.cpp      |   7 +-
 core/sql/sqlcomp/PrivMgrDefs.h            |   2 +
 core/sql/sqlcomp/PrivMgrDesc.cpp          |   4 +
 core/sql/sqlcomp/nadefaults.cpp           |   6 +-
 core/sql/ustat/hs_la.cpp                  |  48 +-
 53 files changed, 2868 insertions(+), 441 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/bin/SqlciErrors.txt
----------------------------------------------------------------------
diff --git a/core/sql/bin/SqlciErrors.txt b/core/sql/bin/SqlciErrors.txt
index 21e4b46..569979e 100644
--- a/core/sql/bin/SqlciErrors.txt
+++ b/core/sql/bin/SqlciErrors.txt
@@ -1000,7 +1000,7 @@ $1~String1 --------------------------------
 3243 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Duplicate ENFORCED clauses were specified.
 3244 ZZZZZ 99999 BEGINNER MAJOR DBADMIN The NOT ENFORCED constraint attribute is allowed only in a Referential Integrity constraint.
 3250 42000 99999 BEGINNER MAJOR DBADMIN The specified blocksize is not valid. Blocksize of 32768 is used instead.
-
+3251 ZZZZZ 99999 BEGINNER MAJOR DBADMIN $0~String0 operation could not be completed.$1~string1
 3260 ZZZZZ 99999 BEGINNER MAJOR DBADMIN A syntax error occurred. The formal parameter list may not appear in in definition of universal user defined function.
 3261 ZZZZZ 99999 BEGINNER MAJOR DBADMIN A syntax error occurred. The RETURN[S] clause may not appear in the definition of procedure.
 3262 ZZZZZ 99999 BEGINNER MAJOR DBADMIN A syntax error occurred. Only OUT parameter mode can appear within the RETURN[S] clause in the defintion of a procedure..
@@ -1198,7 +1198,7 @@ $1~String1 --------------------------------
 4126 42000 99999 BEGINNER MAJOR DBADMIN The row value constructors in a VALUES clause must be of equal degree.
 4127 42000 99999 BEGINNER MAJOR DBADMIN Type $0~String0 cannot be assigned to type $1~String1.
 4128 42000 99999 BEGINNER MAJOR DBADMIN Default volume and subvolume information could not be retrieved from =_DEFAULTS define - DEFINEINFO error $0~int0.
-4129 ZZZZZ 99999 BEGINNER MAJOR DBADMIN The character-typed result of the function $0~String0 is longer than max supported size.
+4129 ZZZZZ 99999 BEGINNER MAJOR DBADMIN The character-typed result of the function $0~String0 is longer than the maximum supported size.
 4130 ZZZZZ 99999 BEGINNER MAJOR DBADMIN $0~string0 is a read-only DEFAULTS attribute and cannot be updated.
 4131 42000 99999 BEGINNER MAJOR DBADMIN Current_time, current_date, or current_timestamp is not allowed in a check constraint.
 4132 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Current_user, session_user, or system_user is not allowed in a check constraint.
@@ -1310,7 +1310,8 @@ $1~String1 --------------------------------
 4259 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Primary Key clause must be specified for an HBase mapped table.
 4260 ZZZZZ 99999 BEGINNER MAJOR DBADMIN HBase table($0~String0) to be mapped as an external table does not exist.
 4261 ZZZZZ 99999 BEGINNER MAJOR DBADMIN The schema name $0~SchemaName is reserved for HBase mapped tables and cannot be explicitly specified.
-4262 ZZZZZ 99999 BEGINNER MINOR DBADMIN Object $0~String0 has invalid state and cannot be accessed. It has an external table but the correponding hive table does not exist. Use 'drop external table' command to drop the external table.
+4262 ZZZZZ 99999 BEGINNER MINOR DBADMIN Object $0~String0 has invalid state and cannot be accessed. It has an external table but the correponding hive table does not exist. Use 'cleanup hive table' command to cleanup this table.
+4263 ZZZZZ 99999 BEGINNER MINOR DBADMIN Object $0~String0 has invalid state and cannot be accessed. It is registered in trafodion metadata but the correponding hive object does not exist. Use 'cleanup hive table/view' command to cleanup this object.
 4300 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Use of procedure $0~TableName was not valid - a UDR was invoked within a trigger.
 4301 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Use of routine $0~TableName was not valid - return of result sets is not allowed within a trigger.
 4302 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Procedure $0~TableName expects $1~Int0 parameters but was called with $1~int1 parameters.

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/comexe/ComTdbExeUtil.h
----------------------------------------------------------------------
diff --git a/core/sql/comexe/ComTdbExeUtil.h b/core/sql/comexe/ComTdbExeUtil.h
index 404a8fd..664736a 100644
--- a/core/sql/comexe/ComTdbExeUtil.h
+++ b/core/sql/comexe/ComTdbExeUtil.h
@@ -2479,6 +2479,10 @@ public:
     SEQUENCES_IN_CATALOG_,
     TABLES_IN_CATALOG_,
     OBJECTS_IN_CATALOG_,
+    HIVE_REG_TABLES_IN_CATALOG_,
+    HIVE_REG_VIEWS_IN_CATALOG_,
+    HIVE_REG_OBJECTS_IN_CATALOG_,
+    HIVE_EXT_TABLES_IN_CATALOG_,
 
     TABLES_IN_SCHEMA_,
     INDEXES_IN_SCHEMA_,

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/common/ComMisc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/common/ComMisc.cpp b/core/sql/common/ComMisc.cpp
index 07f6912..e04aa6c 100644
--- a/core/sql/common/ComMisc.cpp
+++ b/core/sql/common/ComMisc.cpp
@@ -103,7 +103,8 @@ NABoolean ComIsTrafodionReservedSchemaName(
 // schema names of pattern "_HV_ ... _" and "_HB_ ... _" are reserved to store
 // external hive and hbase tables
 NABoolean ComIsTrafodionExternalSchemaName (
-                                    const NAString &schName)
+     const NAString &schName,
+     NABoolean * isHive)
 {
   Int32 len (schName.length());
 
@@ -117,13 +118,20 @@ NABoolean ComIsTrafodionExternalSchemaName (
       len = len - 2;
     }
 
+  if (isHive)
+    *isHive = FALSE;
+
   // check for HIVE
   Int32 prefixLen = sizeof(HIVE_EXT_SCHEMA_PREFIX);
   if (len > prefixLen && 
       (schName((quoted ? 1 : 0), prefixLen-1) == HIVE_EXT_SCHEMA_PREFIX && 
        schName((quoted ? 1 : 0) + len-1) == '_' ))
-    return TRUE;
-  
+    {
+      if (isHive)
+        *isHive = TRUE;
+      return TRUE;
+    }
+
   // check for HBASE
   prefixLen = sizeof(HBASE_EXT_SCHEMA_PREFIX);
   if (len > prefixLen && 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/common/ComMisc.h
----------------------------------------------------------------------
diff --git a/core/sql/common/ComMisc.h b/core/sql/common/ComMisc.h
index ec078e2..450eb61 100644
--- a/core/sql/common/ComMisc.h
+++ b/core/sql/common/ComMisc.h
@@ -51,9 +51,12 @@ NABoolean ComIsTrafodionReservedSchema(
                                        const NAString &schName);
 
 // schema names of pattern "_HV_ ... _" and "_HB_ ... _" are reserved to store
-// external hive and hbase tables
+// external hive and hbase tables.
+// If isHive is passed in, then it is set to TRUE if this is a hive schema,
+// and set to FALSE otherwise.
 NABoolean ComIsTrafodionExternalSchemaName (
-                                            const NAString &schName);
+     const NAString &schName,
+     NABoolean * isHive = NULL);
 
 NABoolean ComIsHbaseMappedSchemaName (const NAString &schName);
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/common/ComSmallDefs.h
----------------------------------------------------------------------
diff --git a/core/sql/common/ComSmallDefs.h b/core/sql/common/ComSmallDefs.h
index f20799c..f930f55 100644
--- a/core/sql/common/ComSmallDefs.h
+++ b/core/sql/common/ComSmallDefs.h
@@ -103,6 +103,7 @@ typedef NABoolean               ComBoolean;
 #define COM_PUBLIC_ACCESS_SCHEMA "PUBLIC_ACCESS_SCHEMA"
 
 #define HIVE_SYSTEM_CATALOG          "HIVE"
+#define HIVE_SYSTEM_CATALOG_LC       "hive"
 #define HIVE_SYSTEM_SCHEMA           "HIVE"
 #define HIVE_SYSTEM_SCHEMA_LC        "hive"
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/common/OperTypeEnum.h
----------------------------------------------------------------------
diff --git a/core/sql/common/OperTypeEnum.h b/core/sql/common/OperTypeEnum.h
index 4e29496..698310f 100644
--- a/core/sql/common/OperTypeEnum.h
+++ b/core/sql/common/OperTypeEnum.h
@@ -956,6 +956,7 @@ enum OperatorTypeEnum {
                         DDL_REGISTER_COMPONENT,
                         DDL_UNREGISTER_CATALOG,
                         DDL_REGISTER_USER,
+                        DDL_REG_OR_UNREG_HIVE,
                         DDL_REINITIALIZE_SQL,
                         DDL_REVOKE,
                         DDL_REVOKE_COMPONENT_PRIVILEGE,

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/executor/ExExeUtil.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtil.h b/core/sql/executor/ExExeUtil.h
index 541ac08..b67e956 100755
--- a/core/sql/executor/ExExeUtil.h
+++ b/core/sql/executor/ExExeUtil.h
@@ -2415,7 +2415,7 @@ public:
 protected:
   enum
   {
-    NUM_MAX_PARAMS_ = 20
+    NUM_MAX_PARAMS_ = 25
   };
 
   enum Step

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/executor/ExExeUtilGet.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilGet.cpp b/core/sql/executor/ExExeUtilGet.cpp
index 5e2d70a..d342f0a 100644
--- a/core/sql/executor/ExExeUtilGet.cpp
+++ b/core/sql/executor/ExExeUtilGet.cpp
@@ -201,6 +201,7 @@ static const QueryString getPrivsForAuthsQuery[] =
   {"      else '-' end as privs "},
   {" from %s.\"%s\".%s "},
   {" where grantee_id %s "},
+
   {" union "},
   {"  (select translate(rtrim(object_name) using ucs2toutf8) || ' <Column> ' || "},
   {"          translate(rtrim(column_name) using ucs2toutf8), "},
@@ -221,7 +222,37 @@ static const QueryString getPrivsForAuthsQuery[] =
   {"   from %s.\"%s\".%s p, %s.\"%s\".%s c "},
   {"   where p.object_uid = c.object_uid "},
   {"     and p.column_number = c.column_number "},
-  {"     and grantee_id %s )"},
+  {"     and grantee_id %s ) "},
+
+  {" union "}, // for privileges on hive objects
+  {"  (select translate(rtrim(o.catalog_name) using ucs2toutf8) || '.' || "},
+  {"          translate(rtrim(o.schema_name) using ucs2toutf8) || '.'  || "},
+  {"          translate(rtrim(o.object_name) using ucs2toutf8) || '.'  || "},
+  {"                        ' <Column> ' ||                    "},
+  {"          translate(rtrim(column_name) using ucs2toutf8), "},
+  {"    case when bitextract(privileges_bitmap,63,1) = 1 then 'S' "},
+  {"      else '-' end || "},
+  {"     case when bitextract(privileges_bitmap,62,1) = 1 then 'I' "},
+  {"      else '-' end || "},
+  {"     case when bitextract(privileges_bitmap,61,1) = 1 then 'D' "},
+  {"      else '-' end || "},
+  {"     case when bitextract(privileges_bitmap,60,1) = 1 then 'U' "},
+  {"      else '-' end || "},
+  {"     case when bitextract(privileges_bitmap,59,1) = 1 then 'G' "},
+  {"      else '-' end || "},
+  {"     case when bitextract(privileges_bitmap,58,1) = 1 then 'R' "},
+  {"      else '-' end || "},
+  {"     case when bitextract(privileges_bitmap,57,1) = 1 then 'E' "},
+  {"      else '-' end as privs "},
+  {"   from %s.\"%s\".%s p, %s.\"%s\".%s o,                        "},
+  {"        table(hivemd(columns)) c                               "},
+  {"   where p.object_uid = o.object_uid "},
+  {"         and o.catalog_name = upper(c.catalog_name) "},
+  {"         and o.schema_name = upper(c.schema_name) "},
+  {"         and o.object_name = upper(c.table_name) "},
+  {"     and p.column_number = c.column_number "},
+  {"     and grantee_id %s ) "},
+
   {" union "},
   {"  (select translate(rtrim(schema_name) using ucs2toutf8), "},
   {"    case when bitextract(privileges_bitmap,63,1) = 1 then 'S' "},
@@ -239,7 +270,7 @@ static const QueryString getPrivsForAuthsQuery[] =
   {"     case when bitextract(privileges_bitmap,57,1) = 1 then 'E' "},
   {"      else '-' end as privs "},
   {"   from %s.\"%s\".%s "},
-  {"   where grantee_id %s )"},
+  {"   where grantee_id %s ) "},
   {" order by 1 "},
   {" ; "}
 };
@@ -434,7 +465,7 @@ static const QueryString getTrafObjectsInViewQuery[] =
 
 static const QueryString getTrafViewsOnObjectQuery[] =
 {
-  {" select trim(T.schema_name) || '.' || trim(T.object_name) from "},
+  {" select trim(T.catalog_name) || '.' || trim(T.schema_name) || '.' || trim(T.object_name) from "},
   {"   %s.\"%s\".%s T "},
   {"   where T.object_uid in "},
   {"   (select using_view_uid from  %s.\"%s\".%s VU "},
@@ -490,6 +521,43 @@ static const QueryString getTrafRoles[] =
   {" order by 1 "},
   {"  ; "}
 };
+
+static const QueryString getHiveRegObjectsInCatalogQuery[] =
+{
+  {" select trim(O.a) ||  "                                    },
+  {" case when G.b is null then ' (inconsistent)' else '' end "},
+  {" from "                                                    },
+  {"  (select lower(trim(catalog_name) || '.' || "             },
+  {"    trim(schema_name) || '.' || trim(object_name)) "       },
+  {"   from %s.\"%s\".%s where catalog_name = 'HIVE' and "     },
+  {"                           %s) O(a) "                      },
+  {"  left join "                                              },
+  {"   (select '%s' || '.' || trim(y) from "                   },
+  {"    (get %s in catalog %s, no header) x(y)) G(b)"          },
+  {"   on O.a = G.b  "                                         },
+  {" order by 1 "                                              },
+  {"; "                                                        }
+};
+
+static const QueryString getHiveExtTablesInCatalogQuery[] =
+{
+  {" select trim(O.a) ||  "                                    },
+  {" case when G.b is null then ' (inconsistent)' else '' end "},
+  {" from "                                                    },
+  {"  (select '%s' || '.' || "                                 },
+  {"   lower(trim(substring(schema_name, 5, "                  },
+  {"                char_length(schema_name)-5))) "            },
+  {"    || '.' || lower(trim(object_name)) "                   },
+  {"   from %s.\"%s\".%s where object_type = '%s' "            },
+  {"    and schema_name like '|_HV|_%%|_' escape '|') O(a)   " },
+  {"  left join "                                              },
+  {"   (select '%s' || '.' || trim(y) from "                   },
+  {"    (get %s in catalog %s, no header) x(y)) G(b) "         },
+  {"   on O.a = G.b  "                                         },
+  {" order by 1 "                                              },
+  {"; "                                                        }
+};
+
 Lng32 ExExeUtilGetMetadataInfoTcb::getUsingView(Queue * infoList,
 					       NABoolean isShorthandView,
 					       char* &viewName, Lng32 &len)
@@ -850,6 +918,34 @@ short ExExeUtilGetMetadataInfoTcb::displayHeading()
       }
     break;
 
+    case ComTdbExeUtilGetMetadataInfo::HIVE_REG_TABLES_IN_CATALOG_:
+      {
+	str_sprintf(headingBuf_, "Hive Registered Tables in Catalog %s",
+		    getMItdb().getCat());
+      }
+    break;
+
+    case ComTdbExeUtilGetMetadataInfo::HIVE_REG_VIEWS_IN_CATALOG_:
+      {
+	str_sprintf(headingBuf_, "Hive Registered Views in Catalog %s",
+		    getMItdb().getCat());
+      }
+    break;
+
+    case ComTdbExeUtilGetMetadataInfo::HIVE_REG_OBJECTS_IN_CATALOG_:
+      {
+	str_sprintf(headingBuf_, "Hive Registered Objects in Catalog %s",
+		    getMItdb().getCat());
+      }
+    break;
+
+    case ComTdbExeUtilGetMetadataInfo::HIVE_EXT_TABLES_IN_CATALOG_:
+      {
+	str_sprintf(headingBuf_, "Hive External Tables in Catalog %s",
+		    getMItdb().getCat());
+      }
+    break;
+
     case ComTdbExeUtilGetMetadataInfo::TABLES_IN_SCHEMA_:
       {
 	str_sprintf(headingBuf_, "Tables in Schema %s.%s",
@@ -1564,6 +1660,9 @@ short ExExeUtilGetMetadataInfoTcb::work()
             char componentPrivileges[100];
             char routine[100];
             char library_usage[100];
+            char hiveObjType[100];
+            char hiveGetType[10];
+            char hiveSysCat[10];
 
 	    cliInterface()->getCQDval("SEABASE_CATALOG", cat);
 
@@ -1585,6 +1684,7 @@ short ExExeUtilGetMetadataInfoTcb::work()
             strcpy(componentPrivileges, "COMPONENT_PRIVILEGES");
             strcpy(routine, SEABASE_ROUTINES);
             strcpy(library_usage, SEABASE_LIBRARIES_USAGE);
+            strcpy(hiveSysCat, HIVE_SYSTEM_CATALOG_LC);
 
             // Determine if need to restrict data to user visable data only.
             NABoolean doPrivCheck = checkUserPrivs(currContext, getMItdb().queryType_);  
@@ -1685,6 +1785,63 @@ short ExExeUtilGetMetadataInfoTcb::work()
 		}
 	      break;
 	      
+	      case ComTdbExeUtilGetMetadataInfo::HIVE_REG_TABLES_IN_CATALOG_:
+	      case ComTdbExeUtilGetMetadataInfo::HIVE_REG_VIEWS_IN_CATALOG_:
+	      case ComTdbExeUtilGetMetadataInfo::HIVE_REG_OBJECTS_IN_CATALOG_:
+		{
+		  qs = getHiveRegObjectsInCatalogQuery;
+		  sizeOfqs = sizeof(getHiveRegObjectsInCatalogQuery);
+
+                  if (getMItdb().queryType_ == ComTdbExeUtilGetMetadataInfo::HIVE_REG_TABLES_IN_CATALOG_)
+                    {
+                      strcpy(hiveGetType, "tables");
+                      str_sprintf(hiveObjType, " (object_type = '%s') ",
+                                  COM_BASE_TABLE_OBJECT_LIT);
+                    }
+                  else if (getMItdb().queryType_ == ComTdbExeUtilGetMetadataInfo::HIVE_REG_VIEWS_IN_CATALOG_)
+                    {
+                      strcpy(hiveGetType, "views");
+                      str_sprintf(hiveObjType, " (object_type = '%s') ",
+                                  COM_VIEW_OBJECT_LIT);
+                    }
+                  else
+                    {
+                      strcpy(hiveGetType, "objects");
+                      str_sprintf(hiveObjType, " (object_type = '%s' or object_type = '%s') ",
+                                  COM_BASE_TABLE_OBJECT_LIT, 
+                                  COM_VIEW_OBJECT_LIT);
+                    }
+                    
+		  param_[0] = cat;
+		  param_[1] = sch;
+		  param_[2] = tab;
+		  param_[3] = hiveObjType;
+		  param_[4] = hiveSysCat;
+                  param_[5] = hiveGetType, 
+		  param_[6] = hiveSysCat;
+		}
+	      break;
+	      
+	      case ComTdbExeUtilGetMetadataInfo::HIVE_EXT_TABLES_IN_CATALOG_:
+		{
+		  qs = getHiveExtTablesInCatalogQuery;
+		  sizeOfqs = sizeof(getHiveExtTablesInCatalogQuery);
+
+                  strcpy(hiveObjType, COM_BASE_TABLE_OBJECT_LIT);
+                  strcpy(hiveGetType, "tables");
+
+		  param_[0] = hiveSysCat;
+		  param_[1] = cat;
+		  param_[2] = sch;
+		  param_[3] = tab;
+		  param_[4] = hiveObjType;
+		  param_[5] = hiveSysCat;
+                  param_[6] = hiveGetType, 
+		  param_[7] = hiveSysCat;
+
+		}
+	      break;
+	      
 	      case ComTdbExeUtilGetMetadataInfo::VIEWS_IN_SCHEMA_:
 		{
 		  qs = getTrafViewsInSchemaQuery;
@@ -2061,6 +2218,7 @@ short ExExeUtilGetMetadataInfoTcb::work()
                   param_[1] = pmsch;
                   param_[2] = objPrivs;
                   param_[3] = (char *) privWhereClause.data();
+
                   param_[4] = cat;
                   param_[5] = pmsch;
                   param_[6] = colPrivs;
@@ -2068,10 +2226,19 @@ short ExExeUtilGetMetadataInfoTcb::work()
                   param_[8] = sch;
                   param_[9] = col;
                   param_[10] = (char *) privWhereClause.data();
+
                   param_[11] = cat;
                   param_[12] = pmsch;
-                  param_[13] = schPrivs;
-                  param_[14] = (char *) privWhereClause.data();
+                  param_[13] = colPrivs;
+                  param_[14] = cat;
+                  param_[15] = sch;
+                  param_[16] = tab;
+                  param_[17] = (char *) privWhereClause.data();
+
+                  param_[18] = cat;
+                  param_[19] = pmsch;
+                  param_[20] = schPrivs;
+                  param_[21] = (char *) privWhereClause.data();
 
                   numOutputEntries_ = 2;
                 }
@@ -2248,7 +2415,9 @@ short ExExeUtilGetMetadataInfoTcb::work()
 	     str_sprintf(queryBuf_, gluedQuery,
 			 param_[0], param_[1], param_[2], param_[3], param_[4],
 			 param_[5], param_[6], param_[7], param_[8], param_[9],
-			 param_[10], param_[11], param_[12], param_[13], param_[14], param_[15]);
+			 param_[10], param_[11], param_[12], param_[13], param_[14], param_[15],
+                         param_[16], param_[17], param_[18], param_[19], param_[20],
+                         param_[21]);
              NADELETEBASIC(gluedQuery, getMyHeap());	     
 	     step_ = FETCH_ALL_ROWS_;
 	  }
@@ -2345,7 +2514,7 @@ short ExExeUtilGetMetadataInfoTcb::work()
 		(vi->get(1) && (strcmp(vi->get(1), "VI") != 0)))
 	      exprRetCode = ex_expr::EXPR_FALSE;
 	    else if ((getMItdb().queryType_ == ComTdbExeUtilGetMetadataInfo::MVS_IN_MV_) &&
-		(vi->get(1) && (strcmp(vi->get(1), "MV") != 0)))
+                     (vi->get(1) && (strcmp(vi->get(1), "MV") != 0)))
 	      exprRetCode = ex_expr::EXPR_FALSE;
 
 	    if (exprRetCode == ex_expr::EXPR_TRUE)
@@ -2948,29 +3117,6 @@ short ExExeUtilGetMetadataInfoComplexTcb::work()
 		rowsFound = TRUE;
 	      }
 
-	    // Get indexes in schema
-	    str_sprintf(queryBuf_, "get indexes in schema \"%s\".\"%s\" %s",
-			getMItdb().getCat(), getMItdb().getSch(),
-			patternStr_);
-
-	    retcode = 100;
-	    if (NOT systemObjs)
-	      {
-		if (fetchAllRows(infoList_, queryBuf_, 1, FALSE, retcode) < 0)
-		  {
-		    step_ = HANDLE_ERROR_;
-
-		    break;
-		  }
-	      }
-
-	    // insert a NULL entry, this will cause a blank row to be returned
-	    if (retcode != 100) // some rows were found
-	      {
-		infoList_->insert((new(getHeap()) OutputInfo(1)));
-		rowsFound = TRUE;
-	      }
-
 	    // Get views in schema
 	    str_sprintf(queryBuf_, "get views in schema \"%s\".\"%s\" %s",
 			getMItdb().getCat(), getMItdb().getSch(),
@@ -2994,63 +3140,90 @@ short ExExeUtilGetMetadataInfoComplexTcb::work()
 		rowsFound = TRUE;
 	      }
 
-	    // Get mvs in schema
-	    str_sprintf(queryBuf_, "get mvs in schema \"%s\".\"%s\" %s",
-			getMItdb().getCat(), getMItdb().getSch(),
-			patternStr_);
-
-	    retcode = 100;
-	    if (NOT systemObjs)
-	      {
-		if (fetchAllRows(infoList_, queryBuf_, 1, FALSE, retcode) < 0)
-		  {
-                    // if error is 4222 (command not supported), ignore it.
-                    if (getDiagsArea()->mainSQLCODE() != -4222)
+            // get indexes, mvs, synonyms for trafodion catalog
+            if (strcmp(getMItdb().getCat(), TRAFODION_SYSCAT_LIT) == 0)
+              {
+                // Get indexes in schema
+                str_sprintf(queryBuf_, "get indexes in schema \"%s\".\"%s\" %s",
+                            getMItdb().getCat(), getMItdb().getSch(),
+                            patternStr_);
+                
+                retcode = 100;
+                if (NOT systemObjs)
+                  {
+                    if (fetchAllRows(infoList_, queryBuf_, 1, FALSE, retcode) < 0)
                       {
                         step_ = HANDLE_ERROR_;
                         
                         break;
                       }
+                  }
+                
+                // insert a NULL entry, this will cause a blank row to be returned
+                if (retcode != 100) // some rows were found
+                  {
+                    infoList_->insert((new(getHeap()) OutputInfo(1)));
+                    rowsFound = TRUE;
+                  }
 
-                    getDiagsArea()->clear();
-		  }
-	      }
-
-	    // insert a NULL entry, this will cause a blank row to be returned
-	    if (retcode != 100) // some rows were found
-	      {
-		infoList_->insert((new(getHeap()) OutputInfo(1)));
-		rowsFound = TRUE;
-	      }
-
-	    // Get synonyms in schema
-	    str_sprintf(queryBuf_, "get synonyms in schema \"%s\".\"%s\" %s",
-			getMItdb().getCat(), getMItdb().getSch(),
-			patternStr_);
-
-	    retcode = 100;
-	    if (NOT systemObjs)
-	      {
-		if (fetchAllRows(infoList_, queryBuf_, 1, FALSE, retcode) < 0)
-		  {
-                    // if error is 4222 (command not supported), ignore it.
-                    if (getDiagsArea()->mainSQLCODE() != -4222)
+                // Get mvs in schema
+                str_sprintf(queryBuf_, "get mvs in schema \"%s\".\"%s\" %s",
+                            getMItdb().getCat(), getMItdb().getSch(),
+                            patternStr_);
+                
+                retcode = 100;
+                if (NOT systemObjs)
+                  {
+                    if (fetchAllRows(infoList_, queryBuf_, 1, FALSE, retcode) < 0)
                       {
-                        step_ = HANDLE_ERROR_;
+                        // if error is 4222 (command not supported), ignore it.
+                        if (getDiagsArea()->mainSQLCODE() != -4222)
+                          {
+                            step_ = HANDLE_ERROR_;
+                            
+                            break;
+                          }
                         
-                        break;
+                        getDiagsArea()->clear();
                       }
-
-                    getDiagsArea()->clear();
-		  }
-	      }
-
-	    // insert a NULL entry, this will cause a blank row to be returned
-	    if (retcode != 100) // some rows were found
-	      {
-		infoList_->insert((new(getHeap()) OutputInfo(1)));
-		rowsFound = TRUE;
-	      }
+                  }
+                
+                // insert a NULL entry, this will cause a blank row to be returned
+                if (retcode != 100) // some rows were found
+                  {
+                    infoList_->insert((new(getHeap()) OutputInfo(1)));
+                    rowsFound = TRUE;
+                  }
+                
+                // Get synonyms in schema
+                str_sprintf(queryBuf_, "get synonyms in schema \"%s\".\"%s\" %s",
+                            getMItdb().getCat(), getMItdb().getSch(),
+                            patternStr_);
+                
+                retcode = 100;
+                if (NOT systemObjs)
+                  {
+                    if (fetchAllRows(infoList_, queryBuf_, 1, FALSE, retcode) < 0)
+                      {
+                        // if error is 4222 (command not supported), ignore it.
+                        if (getDiagsArea()->mainSQLCODE() != -4222)
+                          {
+                            step_ = HANDLE_ERROR_;
+                            
+                            break;
+                          }
+                        
+                        getDiagsArea()->clear();
+                      }
+                  }
+                
+                // insert a NULL entry, this will cause a blank row to be returned
+                if (retcode != 100) // some rows were found
+                  {
+                    infoList_->insert((new(getHeap()) OutputInfo(1)));
+                    rowsFound = TRUE;
+                  }
+              } // not HIVE catalog
 
 	    if (rowsFound)
 	      infoList_->removeTail();

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/generator/GenRelExeUtil.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenRelExeUtil.cpp b/core/sql/generator/GenRelExeUtil.cpp
index 735cc88..a078974 100644
--- a/core/sql/generator/GenRelExeUtil.cpp
+++ b/core/sql/generator/GenRelExeUtil.cpp
@@ -1591,7 +1591,7 @@ short ExeUtilGetMetadataInfo::codeGen(Generator * generator)
     {  "SYSTEM", "SCHEMAS",   "",      "",         1,      0,        0,      0,      ComTdbExeUtilGetMetadataInfo::SCHEMAS_IN_CATALOG_ },
     {  "ALL",    "SCHEMAS",   "",      "",         1,      0,        0,      0,      ComTdbExeUtilGetMetadataInfo::SCHEMAS_IN_CATALOG_ },
 
-    {  "USER",    "SEQUENCES",   "",      "",         1,      0,        0,      0,      ComTdbExeUtilGetMetadataInfo::SEQUENCES_IN_CATALOG_ },
+    {  "USER",   "SEQUENCES",   "",      "",         1,      0,        0,      0,      ComTdbExeUtilGetMetadataInfo::SEQUENCES_IN_CATALOG_ },
     {  "ALL",    "SEQUENCES",   "",      "",         1,      0,        0,      0,      ComTdbExeUtilGetMetadataInfo::SEQUENCES_IN_CATALOG_ },
 
     {  "USER",   "TABLES",    "",      "",         1,      0,        0,      0,      ComTdbExeUtilGetMetadataInfo::TABLES_IN_SCHEMA_ },
@@ -1634,13 +1634,17 @@ short ExeUtilGetMetadataInfo::codeGen(Generator * generator)
     {  "USER",   "SCHEMAS",   "IN",    "CATALOG",  1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::SCHEMAS_IN_CATALOG_ },
     {  "SYSTEM", "SCHEMAS",   "IN",    "CATALOG",  1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::SCHEMAS_IN_CATALOG_ },
     {  "ALL",    "SCHEMAS",   "IN",    "CATALOG",  1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::SCHEMAS_IN_CATALOG_ },
-    {  "ALL",   "VIEWS",   "IN",      "CATALOG",         1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::VIEWS_IN_CATALOG_ },
-    {  "USER",   "VIEWS",   "IN",      "CATALOG",         1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::VIEWS_IN_CATALOG_ },
-    {  "ALL",   "INVALID_VIEWS",   "IN",      "CATALOG",         1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::INVALID_VIEWS_IN_CATALOG_ },
-    {  "USER",   "SEQUENCES",   "IN",    "CATALOG",  1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::SEQUENCES_IN_CATALOG_ },
-    {  "ALL", "SEQUENCES",   "IN",    "CATALOG",  1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::SEQUENCES_IN_CATALOG_ },
-    {  "USER",   "TABLES",   "IN",    "CATALOG",  1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::TABLES_IN_CATALOG_ },
+    {  "ALL",    "VIEWS",     "IN",    "CATALOG",         1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::VIEWS_IN_CATALOG_ },
+    {  "USER",   "VIEWS",     "IN",    "CATALOG",         1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::VIEWS_IN_CATALOG_ },
+    {  "ALL",    "INVALID_VIEWS",   "IN",      "CATALOG",         1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::INVALID_VIEWS_IN_CATALOG_ },
+    {  "USER",   "SEQUENCES", "IN",    "CATALOG",  1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::SEQUENCES_IN_CATALOG_ },
+    {  "ALL",    "SEQUENCES", "IN",    "CATALOG",  1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::SEQUENCES_IN_CATALOG_ },
+    {  "USER",   "TABLES",    "IN",    "CATALOG",  1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::TABLES_IN_CATALOG_ },
     {  "USER",   "OBJECTS",   "IN",    "CATALOG",  1,      1,        0,      0,      ComTdbExeUtilGetMetadataInfo::OBJECTS_IN_CATALOG_ },
+    {  "USER",   "HIVE_REG_TABLES","IN", "CATALOG",  1,      1,        0,      0,    ComTdbExeUtilGetMetadataInfo::HIVE_REG_TABLES_IN_CATALOG_ },
+    {  "USER",   "HIVE_REG_VIEWS", "IN", "CATALOG",  1,      1,        0,      0,    ComTdbExeUtilGetMetadataInfo::HIVE_REG_VIEWS_IN_CATALOG_ },
+    {  "USER",   "HIVE_REG_OBJECTS", "IN", "CATALOG",  1,      1,        0,      0,  ComTdbExeUtilGetMetadataInfo::HIVE_REG_OBJECTS_IN_CATALOG_ },
+    {  "USER",   "HIVE_EXT_TABLES","IN", "CATALOG",  1,      1,        0,      0,    ComTdbExeUtilGetMetadataInfo::HIVE_EXT_TABLES_IN_CATALOG_ },
 
     {  "USER",   "TABLES",    "IN",    "SCHEMA",   1,      2,        0,      0,      ComTdbExeUtilGetMetadataInfo::TABLES_IN_SCHEMA_ },
     {  "SYSTEM", "TABLES",    "IN",    "SCHEMA",   1,      2,        0,      0,      ComTdbExeUtilGetMetadataInfo::TABLES_IN_SCHEMA_ },
@@ -1899,10 +1903,32 @@ short ExeUtilGetMetadataInfo::codeGen(Generator * generator)
   NAString hiveDefSchName = "";
   CmpCommon::getDefault(HIVE_DEFAULT_SCHEMA, hiveDefSchName, FALSE);
   hiveDefSchName.toUpper();
-  
+
+  //  if ((catName.isNull() && schName.isNull()) &&
+  if ((catName.isNull()) &&
+      (generator->currentCmpContext()->schemaDB_->getDefaultSchema().
+       getCatalogName() == HIVE_SYSTEM_CATALOG) &&
+      ((queryType == ComTdbExeUtilGetMetadataInfo::TABLES_IN_SCHEMA_) ||
+       (queryType == ComTdbExeUtilGetMetadataInfo::OBJECTS_IN_SCHEMA_) ||
+       (queryType == ComTdbExeUtilGetMetadataInfo::VIEWS_IN_SCHEMA_)))
+    {
+      catName = 
+        generator->currentCmpContext()->schemaDB_->getDefaultSchema().
+        getCatalogName();
+
+      if (schName.isNull())
+        schName = 
+          generator->currentCmpContext()->schemaDB_->getDefaultSchema().
+          getSchemaName();
+    }
+
   if (((catName == hiveDefCatName) ||
        (catName == HIVE_SYSTEM_CATALOG)) &&
-      (queryType != ComTdbExeUtilGetMetadataInfo::VIEWS_ON_TABLE_))
+      ((queryType != ComTdbExeUtilGetMetadataInfo::VIEWS_ON_TABLE_) &&
+       (queryType != ComTdbExeUtilGetMetadataInfo::VIEWS_ON_VIEW_) &&
+       (queryType != ComTdbExeUtilGetMetadataInfo::VIEWS_IN_VIEW_) &&
+       (queryType != ComTdbExeUtilGetMetadataInfo::TABLES_IN_VIEW_) &&
+       (queryType != ComTdbExeUtilGetMetadataInfo::OBJECTS_IN_VIEW_)))
     {
       setHiveObjects(TRUE);
     }
@@ -1939,6 +1965,9 @@ short ExeUtilGetMetadataInfo::codeGen(Generator * generator)
               (queryType == ComTdbExeUtilGetMetadataInfo::VIEWS_IN_CATALOG_) ||
               (queryType == ComTdbExeUtilGetMetadataInfo::OBJECTS_IN_CATALOG_) ||
               (queryType == ComTdbExeUtilGetMetadataInfo::VIEWS_ON_TABLE_) ||
+              (queryType == ComTdbExeUtilGetMetadataInfo::VIEWS_ON_VIEW_) ||
+              (queryType == ComTdbExeUtilGetMetadataInfo::VIEWS_IN_VIEW_) ||
+              (queryType == ComTdbExeUtilGetMetadataInfo::TABLES_IN_VIEW_) ||
               (queryType == ComTdbExeUtilGetMetadataInfo::SCHEMAS_IN_CATALOG_)))
 	{
 	  *CmpCommon::diags() << DgSqlCode(-4219);
@@ -2043,7 +2072,8 @@ short ExeUtilGetMetadataInfo::codeGen(Generator * generator)
       if (((catName == hiveDefCatName) ||
            (catName == HIVE_SYSTEM_CATALOG)) &&
           ((queryType == ComTdbExeUtilGetMetadataInfo::VIEWS_ON_TABLE_) &&
-           (naTable && naTable->hasExternalTable())))
+           (naTable && (NOT naTable->isRegistered()) &&
+            naTable->hasExternalTable())))
         {
           // Convert the native name to its Trafodion form
           NAString tabName = ComConvertNativeNameToTrafName

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/generator/GenRelMisc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenRelMisc.cpp b/core/sql/generator/GenRelMisc.cpp
index 99eaa85..c165ad7 100644
--- a/core/sql/generator/GenRelMisc.cpp
+++ b/core/sql/generator/GenRelMisc.cpp
@@ -3045,13 +3045,13 @@ short Sort::generateTdb(Generator * generator,
   
   CostScalar bufferSize = getDefault(GEN_SORT_MAX_BUFFER_SIZE);
 
-  UInt32 bufferSize_as_ulong = 
+  UInt32 bufferSize_as_uint32 = 
     (UInt32)(MINOF(CostScalar(UINT_MAX), bufferSize)).getValue(); 
 
   // allocate buffer to hold atlease one row
-  bufferSize_as_ulong = MAXOF(bufferSize_as_ulong, sortRecLen);
+  bufferSize_as_uint32 = MAXOF(bufferSize_as_uint32, sortRecLen);
 
-  GenAssert(sortRecLen <= bufferSize_as_ulong, 
+  GenAssert(sortRecLen <= bufferSize_as_uint32, 
       "Record Len greater than GEN_SORT_MAX_BUFFER_SIZE");
   
   ComTdbSort * sort_tdb = 0;
@@ -3209,7 +3209,7 @@ short Sort::generateTdb(Generator * generator,
 	       (queue_index)getDefault(GEN_SORT_SIZE_UP),
 	       (Cardinality) (getInputCardinality() * getEstRowsUsed()).getValue(),
 	       numBuffers,
-	       bufferSize_as_ulong,
+	       bufferSize_as_uint32,
 	       max_num_buffers,
 	       sort_options,
            sortGrowthPercent);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/optimizer/BindItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindItemExpr.cpp b/core/sql/optimizer/BindItemExpr.cpp
index f89e416..952b9f7 100644
--- a/core/sql/optimizer/BindItemExpr.cpp
+++ b/core/sql/optimizer/BindItemExpr.cpp
@@ -5882,10 +5882,13 @@ ItemExpr *BiArith::bindNode(BindWA *bindWA)
 	       (naType1->getTypeQualifier() == NA_DATETIME_TYPE) &&
                (getOperatorType() == ITM_MINUS))
 	{
-          // Column of DATE datatype is internally created as TIMESTAMP(0).
-          // timestamp(0) - date               =  diff in days
+          // timestamp(0) - date          =  diff in days
+          // date - date                  = diff in days
+          //
+          // In mode_special_4,
+          // Column of DATE datatype is internally created as TIMESTAMP(0)
+          // and their diff is in days.
           // timestamp(0) - timestamp(0)  = diff in days
-          // date - date                            = diff in days
 	  const DatetimeType* datetime1 = (DatetimeType*)naType0;
 	  const DatetimeType* datetime2 = (DatetimeType*)naType1;
           if (((datetime1->getSubtype() == DatetimeType::SUBTYPE_SQLTimestamp) ||

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/optimizer/BindRelExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindRelExpr.cpp b/core/sql/optimizer/BindRelExpr.cpp
index 5f003c3..d35d4ad 100644
--- a/core/sql/optimizer/BindRelExpr.cpp
+++ b/core/sql/optimizer/BindRelExpr.cpp
@@ -5351,6 +5351,8 @@ RelExpr *RelRoot::bindNode(BindWA *bindWA)
 		       (naTable->getObjectType() == COM_INDEX_OBJECT)) &&
 		      ((naTable->isSeabaseTable()) ||
                        ((naTable->isHiveTable()) &&
+                        (NOT naTable->isView()) &&
+                        (naTable->getClusteringIndex()) &&
                         (naTable->getClusteringIndex()->getHHDFSTableStats()->isOrcFile()))))
 		    {
 		      Aggregate * agg = 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/optimizer/NATable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NATable.cpp b/core/sql/optimizer/NATable.cpp
index a4e02c1..2e62c09 100644
--- a/core/sql/optimizer/NATable.cpp
+++ b/core/sql/optimizer/NATable.cpp
@@ -4744,8 +4744,10 @@ NABoolean createNAFileSets(TrafDesc * table_desc       /*IN*/,
  //
  // ----------------------------------------------------------------------------      
  static Int64 lookupObjectUidByName( const QualifiedName& qualName
-                                   , ComObjectType objectType
-                                   , NABoolean reportError
+                                     , ComObjectType objectType
+                                     , NABoolean reportError
+                                     , Int64 *objectFlags = NULL
+                                     , Int64 *createTime = NULL
                                    )
  {
    ExeCliInterface cliInterface(STMTHEAP);
@@ -4760,43 +4762,145 @@ NABoolean createNAFileSets(TrafDesc * table_desc       /*IN*/,
        return -1;
      }
 
-   objectUID = cmpSBD.getObjectUID(&cliInterface,
-                                   qualName.getCatalogName().data(),
-                                   qualName.getSchemaName().data(),
-                                   qualName.getObjectName().data(),
-                                   comObjectTypeLit(objectType),
-                                   NULL,
-                                   NULL,
-                                   FALSE,
-                                   reportError);
+   Int32 objectOwner, schemaOwner;
+   Int64 l_objFlags = 0;
+   Int64 l_createTime = -1;
+   objectUID = cmpSBD.getObjectInfo(&cliInterface,
+                                    qualName.getCatalogName().data(),
+                                    qualName.getSchemaName().data(),
+                                    qualName.getObjectName().data(),
+                                    objectType,
+                                    objectOwner,
+                                    schemaOwner,
+                                    l_objFlags,
+                                    reportError,
+                                    FALSE,
+                                    &l_createTime);
+
+   if (objectFlags)
+     *objectFlags = l_objFlags;
+
+   if (createTime)
+     *createTime = l_createTime;
 
    cmpSBD.switchBackCompiler();
 
    return objectUID;
  }
 
- NABoolean NATable::fetchObjectUIDForNativeTable(const CorrName& corrName)
+// Object UID for hive tables. 
+// 3 cases:
+// case 1: external hive table has an object uid in metadata but the hive
+//         table itself is not registered.
+//         This is the case for external tables created prior to the
+//         hive registration change.
+//         Return object UID for external table.
+// case 2: hive table is registered but there is no external table.
+//         Return object UID for the registered table.
+// case 3: UIDs for external and registered tables exist in metadata.
+//         This can happen if an external table is created with the new
+//         change where hive table is automatically registered before
+//         creating the external table.
+//         Or it can happen if an older external table is explicitly registered
+//         with the new code.
+//         Return the object UID that was created earlier.
+// 
+// case 4: For external hbase tables. Get external object uid.
+// 
+// Set my objectUID_ with the object uid determined based on the previous steps.
+NABoolean NATable::fetchObjectUIDForNativeTable(const CorrName& corrName,
+                                                NABoolean isView)
  {
-    NAString adjustedName = ComConvertNativeNameToTrafName
-          (corrName.getQualifiedNameObj().getCatalogName(),
-           corrName.getQualifiedNameObj().getUnqualifiedSchemaNameAsAnsiString(),
-           corrName.getQualifiedNameObj().getUnqualifiedObjectNameAsAnsiString());
-    QualifiedName extObjName (adjustedName, 3, STMTHEAP);
-
-    objectUID_ = lookupObjectUidByName(extObjName, COM_BASE_TABLE_OBJECT, FALSE);
-
-    // If the objectUID is not found, then the table is not externally defined
-    // in Trafodion, set the objectUID to 0
-    // If an unexpected error occurs, then return with the error
-    if (objectUID_ <= 0)
-      {
-        if (CmpCommon::diags()->mainSQLCODE() < 0)
-          return FALSE;
-        else
-          objectUID_ = 0;
-      }
+   objectUID_ = 0;
+
+   // get uid if this hive table has been registered in traf metadata.
+   Int64 regCreateTime = -1;
+   Int64 extCreateTime = -1;
+   Int64 regObjectUID = -1;
+   Int64 extObjectUID = -1;
+   if (corrName.isHive())
+     {
+       // first get uid for the registered table/view.
+       Int64 objectFlags = 0;
+       regObjectUID = lookupObjectUidByName(corrName.getQualifiedNameObj(),
+                                            (isView ? COM_VIEW_OBJECT :
+                                             COM_BASE_TABLE_OBJECT), FALSE,
+                                            &objectFlags,
+                                            &regCreateTime);
+       
+       if (NOT isView)
+         {
+           // then get uid for corresponding external table.
+           NAString adjustedName = ComConvertNativeNameToTrafName
+             (corrName.getQualifiedNameObj().getCatalogName(),
+              corrName.getQualifiedNameObj().getUnqualifiedSchemaNameAsAnsiString(),
+              corrName.getQualifiedNameObj().getUnqualifiedObjectNameAsAnsiString());
+           QualifiedName extObjName (adjustedName, 3, STMTHEAP);
+           extObjectUID = lookupObjectUidByName(extObjName, 
+                                                COM_BASE_TABLE_OBJECT, FALSE,
+                                                NULL, &extCreateTime);
+         }
 
-    return TRUE;
+       if ((regObjectUID <= 0) && (extObjectUID > 0))
+         {
+           // case 1
+           objectUID_ = extObjectUID;
+         }
+       else if ((extObjectUID <= 0) && (regObjectUID > 0))
+         {
+           // case 2
+           objectUID_ = regObjectUID;
+         }
+       else if ((regObjectUID > 0) && (extObjectUID > 0))
+         {
+           // case 3
+           if (regCreateTime < extCreateTime)
+             objectUID_ = regObjectUID;
+           else
+             objectUID_ = extObjectUID;
+         }
+
+       if (regObjectUID > 0) // hive table is registered
+         {
+           setIsRegistered(TRUE);
+           
+           if (CmpSeabaseDDL::isMDflagsSet(objectFlags, MD_OBJECTS_HIVE_INTERNAL_REGISTER))
+             setIsInternalRegistered(TRUE);
+         }
+
+       if (extObjectUID > 0)
+         {
+           setHasExternalTable(TRUE);
+         }
+     } // is hive
+   else 
+     {
+       // case 4. external hbase table.
+       NAString adjustedName = ComConvertNativeNameToTrafName
+         (corrName.getQualifiedNameObj().getCatalogName(),
+          corrName.getQualifiedNameObj().getUnqualifiedSchemaNameAsAnsiString(),
+          corrName.getQualifiedNameObj().getUnqualifiedObjectNameAsAnsiString());
+       QualifiedName extObjName (adjustedName, 3, STMTHEAP);
+       
+       objectUID_ = lookupObjectUidByName(extObjName, 
+                                          COM_BASE_TABLE_OBJECT, FALSE,
+                                          NULL, &extCreateTime);
+       if (objectUID_ > 0)
+         setHasExternalTable(TRUE);
+     }
+
+   // If the objectUID is not found, then the table is not registered or 
+   // externally defined in Trafodion. Set the objectUID to 0
+   // If an unexpected error occurs, then return with the error
+   if (objectUID_ <= 0)
+     {
+       if (CmpCommon::diags()->mainSQLCODE() < 0)
+         return FALSE;
+       else
+         objectUID_ = 0;
+     }
+   
+   return TRUE;
  }
 
  // -----------------------------------------------------------------------
@@ -5047,11 +5151,8 @@ NABoolean createNAFileSets(TrafDesc * table_desc       /*IN*/,
    // been defined in Trafodion use this value, otherwise, set to 0
    if (isHbaseCell_ || isHbaseRow_)
      {
-       if ( !fetchObjectUIDForNativeTable(corrName) )
+       if ( !fetchObjectUIDForNativeTable(corrName, FALSE) )
          return;
-
-       if (objectUID_ > 0 )
-         setHasExternalTable(TRUE);
      }
 
    if (table_desc->tableDesc()->owner)
@@ -5078,7 +5179,7 @@ NABoolean createNAFileSets(TrafDesc * table_desc       /*IN*/,
      {
        setIsExternalTable(TRUE);
 
-       if (table_desc->tableDesc()->objectFlags & SEABASE_OBJECT_IS_IMPLICIT_EXTERNAL_HIVE)   
+       if (table_desc->tableDesc()->objectFlags & SEABASE_OBJECT_IS_IMPLICIT_EXTERNAL)
          setIsImplicitExternalTable(TRUE);
      }
 
@@ -5711,11 +5812,9 @@ NATable::NATable(BindWA *bindWA,
   // If the HIVE table has been registered in Trafodion, get the objectUID
   // from Trafodion, otherwise, set it to 0.
   // TBD - does getQualifiedNameObj handle delimited names correctly?
-  if ( !fetchObjectUIDForNativeTable(corrName) )
-    return;
 
-  if ( objectUID_ > 0 )
-    setHasExternalTable(TRUE);
+  if ( !fetchObjectUIDForNativeTable(corrName, htbl->isView()) )
+    return;
 
   // for HIVE objects, the schema owner and table owner is HIVE_ROLE_ID
   if (CmpCommon::context()->isAuthorizationEnabled())
@@ -8354,7 +8453,8 @@ NATable * NATableDB::get(CorrName& corrName, BindWA * bindWA,
                     qn.getCatalogName(),
                     qn.getSchemaName(),
                     qn.getObjectName(),
-                    COM_BASE_TABLE_OBJECT);
+                    COM_BASE_TABLE_OBJECT,
+                    TRUE);
                
                if (table && etDesc)
                  {
@@ -8398,6 +8498,18 @@ NATable * NATableDB::get(CorrName& corrName, BindWA * bindWA,
                 qn.getObjectName(),
                 COM_BASE_TABLE_OBJECT);
            
+           // find out if this table is registered in traf metadata
+           Int64 regObjUid = 0;
+           // is this a base table
+           regObjUid = lookupObjectUidByName(corrName.getQualifiedNameObj(),
+                                             COM_BASE_TABLE_OBJECT, FALSE);
+           if (regObjUid <= 0)
+             {
+               // is this a view
+               regObjUid = lookupObjectUidByName(corrName.getQualifiedNameObj(),
+                                                 COM_VIEW_OBJECT, FALSE);
+             }
+
            // if this is to drop an external table and underlying hive
            // tab doesn't exist, return NATable for external table.
            if ((etDesc) &&
@@ -8418,6 +8530,12 @@ NATable * NATableDB::get(CorrName& corrName, BindWA * bindWA,
                          << DgSqlCode(-4262)
                          << DgString0(corrName.getExposedNameAsAnsiString());
                      }
+                   else if (regObjUid > 0) // is registered
+                     {
+                       *CmpCommon::diags()
+                         << DgSqlCode(-4263)
+                         << DgString0(corrName.getExposedNameAsAnsiString());
+                     }
                    else
                      {
                        *CmpCommon::diags()
@@ -9009,8 +9127,13 @@ NATableDB::free_entries_with_QI_key(Int32 numKeys, SQL_QIKEY* qiKeyArray)
   {
     NATable * currTable = cachedTableList_[currIndx];
 
-    // Only need to remove seabase tables and external Hive/hbase tables
-    if (!currTable->isSeabaseTable() && !currTable->hasExternalTable())
+    // Only need to remove seabase, hive or external Hive/hbase tables
+    NABoolean toRemove = FALSE;
+    if ((currTable->isSeabaseTable()) ||
+        (currTable->isHiveTable()) ||
+        (currTable->hasExternalTable()))
+      toRemove = TRUE;
+    if (! toRemove)
     {
       currIndx++;
       continue;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/optimizer/NATable.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NATable.h b/core/sql/optimizer/NATable.h
index 5c2da66..3d4b96e 100644
--- a/core/sql/optimizer/NATable.h
+++ b/core/sql/optimizer/NATable.h
@@ -531,8 +531,8 @@ public:
   // table object (if any) for a native table.
   // Set objectUID_ to 0 if no such external table exists;
   // set objectUID_ to -1 if there is error during the fetch operation;
-  NABoolean fetchObjectUIDForNativeTable(const CorrName& corrName);
-
+  NABoolean fetchObjectUIDForNativeTable(const CorrName& corrName,
+                                         NABoolean isView);
 
   Int64 lookupObjectUid();  // Used to look up uid on demand for metadata tables.
                             // On return, the "Object Not Found" error (-1389) 
@@ -562,6 +562,7 @@ public:
   { return viewTextInNAWchars_.length() > 0 ? viewTextInNAWchars_.data() : NULL; }
   const NAWString &getViewTextAsNAWString() const     { return viewTextInNAWchars_; }
   CharInfo::CharSet getViewTextCharSet() const    { return viewTextCharSet_; }
+  NABoolean isView() const { return (viewText_ != NULL); }
 
   // getViewLen is needed to compute buffer len for a parseDML call
   // locale-to-unicode conversion in parseDML requires buffer len (tcr)
@@ -772,6 +773,18 @@ public:
   {  value ? flags_ |= HIVE_EXT_KEY_ATTRS : flags_ &= ~HIVE_EXT_KEY_ATTRS; }
   NABoolean hiveExtKeyAttrs() const
   {  return (flags_ & HIVE_EXT_KEY_ATTRS) != 0; }
+
+  void setIsRegistered( NABoolean value )
+  {  value ? flags_ |= IS_REGISTERED : flags_ &= ~IS_REGISTERED; }
+
+  NABoolean isRegistered() const
+  {  return (flags_ & IS_REGISTERED) != 0; }
+
+  void setIsInternalRegistered( NABoolean value )
+  {  value ? flags_ |= IS_INTERNAL_REGISTERED : flags_ &= ~IS_INTERNAL_REGISTERED; }
+
+  NABoolean isInternalRegistered() const
+  {  return (flags_ & IS_INTERNAL_REGISTERED) != 0; }
  
   const CheckConstraintList &getCheckConstraints() const
                                                 { return checkConstraints_; }
@@ -997,7 +1010,9 @@ private:
     HAS_HIVE_EXT_TABLE        = 0x01000000,
     HIVE_EXT_COL_ATTRS        = 0x02000000,
     HIVE_EXT_KEY_ATTRS        = 0x04000000,
-    IS_IMPLICIT_EXTERNAL_TABLE= 0x08000000
+    IS_IMPLICIT_EXTERNAL_TABLE= 0x08000000,
+    IS_REGISTERED             = 0x10000000,
+    IS_INTERNAL_REGISTERED    = 0x20000000
   };
     
   UInt32 flags_;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/optimizer/RelExeUtil.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/RelExeUtil.cpp b/core/sql/optimizer/RelExeUtil.cpp
index fd398dc..4282500 100644
--- a/core/sql/optimizer/RelExeUtil.cpp
+++ b/core/sql/optimizer/RelExeUtil.cpp
@@ -82,6 +82,7 @@
 #include "StmtDDLDropRoutine.h"
 #include "StmtDDLCleanupObjects.h"
 #include "StmtDDLAlterLibrary.h"
+#include "StmtDDLRegOrUnregHive.h"
 
 #include <cextdecs/cextdecs.h>
 #include "wstr.h"
@@ -941,6 +942,7 @@ RelExpr * ExeUtilHiveQuery::bindNode(BindWA *bindWA)
   if (NOT ((hiveQuery_.index("CREATE", 0, NAString::ignoreCase) == 0) ||
            (hiveQuery_.index("DROP", 0, NAString::ignoreCase) == 0) ||
            (hiveQuery_.index("ALTER", 0, NAString::ignoreCase) == 0) ||
+           //           (hiveQuery_.index("INSERT", 0, NAString::ignoreCase) == 0) ||
            (hiveQuery_.index("TRUNCATE", 0, NAString::ignoreCase) == 0)))
     {
       // error case
@@ -4037,6 +4039,7 @@ RelExpr * DDLExpr::bindNode(BindWA *bindWA)
   NABoolean alterLibrary = FALSE;
   NABoolean externalTable = FALSE;
   NABoolean isVolatile = FALSE;
+  NABoolean isRegister = FALSE;
 
   returnStatus_ = FALSE;
 
@@ -4497,6 +4500,13 @@ RelExpr * DDLExpr::bindNode(BindWA *bindWA)
       returnStatus_ = 
         getExprNode()->castToStmtDDLNode()->castToStmtDDLCleanupObjects()->getStatus();
     }
+    else if (getExprNode()->castToStmtDDLNode()->castToStmtDDLRegOrUnregHive())
+    {
+      isRegister = TRUE;
+
+      qualObjName_ = getExprNode()->castToStmtDDLNode()->
+        castToStmtDDLRegOrUnregHive()->getObjNameAsQualifiedName();
+    }
 
     if (isCleanup_)
       {
@@ -4504,9 +4514,9 @@ RelExpr * DDLExpr::bindNode(BindWA *bindWA)
           hbaseDDLNoUserXn_ = TRUE;
       }
 
-    if ((isCreateSchema || isDropSchema || isAlterSchema) ||
+    if ((isCreateSchema || isDropSchema || isAlterSchema) || isRegister ||
         ((isTable_ || isIndex_ || isView_ || isRoutine_ || isLibrary_ || isSeq) &&
-         (isCreate_ || isDrop_ || purgedataHbase_ ||
+         (isCreate_ || isDrop_ || purgedataHbase_ || 
           (isAlter_ && (alterAddCol || alterDropCol || alterDisableIndex || alterEnableIndex || 
 			alterAddConstr || alterDropConstr || alterRenameTable ||
                         alterStoredDesc ||
@@ -4536,7 +4546,21 @@ RelExpr * DDLExpr::bindNode(BindWA *bindWA)
 	    bindWA->setErrStatus();
 	    return NULL;
 	  }
-	
+
+        if (isRegister)
+          {
+            if (NOT qualObjName_.isHive())
+              {
+                *CmpCommon::diags() << DgSqlCode(-3242) << 
+                  DgString0("Register/Unregister statement must specify a hive object.");
+                
+                bindWA->setErrStatus();
+                return NULL;
+              }
+
+            isHbase_ = TRUE;
+          }
+
 	// if a user ddl operation, it cannot run under a user transaction.
 	// If an internal ddl request, like a CREATE internally issued onbehalf
 	// of a CREATE LIKE, then allow it to run under a user Xn.
@@ -4564,7 +4588,7 @@ RelExpr * DDLExpr::bindNode(BindWA *bindWA)
         bindWA->setErrStatus();
         return NULL;
       }
-    }
+  }
 
   RelExpr * boundExpr = GenericUtilExpr::bindNode(bindWA);
   if (bindWA->errStatus())

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/parser/AllStmtDDL.h
----------------------------------------------------------------------
diff --git a/core/sql/parser/AllStmtDDL.h b/core/sql/parser/AllStmtDDL.h
index 7427f21..873c3bf 100644
--- a/core/sql/parser/AllStmtDDL.h
+++ b/core/sql/parser/AllStmtDDL.h
@@ -63,6 +63,7 @@
 #include "StmtDDLReInitializeSQL.h"
 #include "StmtDDLRegisterComponent.h"
 #include "StmtDDLRegisterUser.h"
+#include "StmtDDLRegOrUnregHive.h"
 #include "StmtDDLCreateRole.h"
 #include "StmtDDLRoleGrant.h"
 #include "StmtDDLCleanupObjects.h"

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/parser/BindStmtDDL.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/BindStmtDDL.cpp b/core/sql/parser/BindStmtDDL.cpp
index 2163d83..b81b317 100644
--- a/core/sql/parser/BindStmtDDL.cpp
+++ b/core/sql/parser/BindStmtDDL.cpp
@@ -2485,6 +2485,29 @@ StmtDDLRegisterUser::bindNode(BindWA * pBindWA)
 }
 
 // -----------------------------------------------------------------------
+// bindNode() for class StmtDDLRegOrUnregHive
+// -----------------------------------------------------------------------
+//
+////
+// a virtual function for performing name
+// binding within the Register hive tree.
+//
+ExprNode *
+StmtDDLRegOrUnregHive::bindNode(BindWA * pBindWA)
+{
+  ComASSERT(pBindWA);
+
+  if (applyDefaultsAndValidateObject(pBindWA, &objQualName_))
+    {
+      pBindWA->setErrStatus();
+      return this;
+    }
+
+  markAsBound();
+  return this;
+}
+
+// -----------------------------------------------------------------------
 // bindNode() for class StmtDDLRoleGrant
 // -----------------------------------------------------------------------
 //

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/parser/ElemDDLNode.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/ElemDDLNode.cpp b/core/sql/parser/ElemDDLNode.cpp
index 4284c08..fe917b4 100644
--- a/core/sql/parser/ElemDDLNode.cpp
+++ b/core/sql/parser/ElemDDLNode.cpp
@@ -1827,6 +1827,12 @@ ElemDDLNode::castToStmtDDLRegisterUser()
   return NULL;
 }
 
+StmtDDLRegOrUnregHive *
+ElemDDLNode::castToStmtDDLRegOrUnregHive()
+{
+  return NULL;
+}
+
 StmtDDLCreateRole *
 ElemDDLNode::castToStmtDDLCreateRole()
 {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/parser/ElemDDLNode.h
----------------------------------------------------------------------
diff --git a/core/sql/parser/ElemDDLNode.h b/core/sql/parser/ElemDDLNode.h
index 94dc54a..e24ce22 100644
--- a/core/sql/parser/ElemDDLNode.h
+++ b/core/sql/parser/ElemDDLNode.h
@@ -346,6 +346,7 @@ class StmtDDLCreateExceptionTable;
 class StmtDDLDropExceptionTable;
 class StmtDDLRegisterComponent;
 class StmtDDLRegisterUser;
+class StmtDDLRegOrUnregHive;
 class StmtDDLCreateRole;
 class StmtDDLRoleGrant;
 class StmtDDLCleanupObjects;
@@ -685,9 +686,10 @@ public:
   virtual StmtDDLDropExceptionTable     * castToStmtDDLDropExceptionTable();
   virtual StmtDDLRegisterComponent      * castToStmtDDLRegisterComponent();
   virtual StmtDDLRegisterUser           * castToStmtDDLRegisterUser();
+  virtual StmtDDLRegOrUnregHive         * castToStmtDDLRegOrUnregHive();
   virtual StmtDDLCreateRole             * castToStmtDDLCreateRole();
-  virtual StmtDDLRoleGrant             * castToStmtDDLRoleGrant();
-  virtual StmtDDLCleanupObjects          * castToStmtDDLCleanupObjects();
+  virtual StmtDDLRoleGrant              * castToStmtDDLRoleGrant();
+  virtual StmtDDLCleanupObjects         * castToStmtDDLCleanupObjects();
 
   //
   // operator

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/parser/ParAll.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/ParAll.cpp b/core/sql/parser/ParAll.cpp
index e73ac87..daf55bc 100644
--- a/core/sql/parser/ParAll.cpp
+++ b/core/sql/parser/ParAll.cpp
@@ -62,6 +62,7 @@
 #include "StmtDMLSetTransaction.cpp" 
 #include "StmtNode.cpp"
 #include "StmtDDLRegisterUser.cpp"
+#include "StmtDDLRegOrUnregHive.cpp"
 #include "StmtDDLCreateRole.cpp"
 #include "StmtDDLRoleGrant.cpp"
 #include "StmtDDLMisc.cpp"

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/parser/ParKeyWords.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/ParKeyWords.cpp b/core/sql/parser/ParKeyWords.cpp
index 19589a8..c94b8fb 100644
--- a/core/sql/parser/ParKeyWords.cpp
+++ b/core/sql/parser/ParKeyWords.cpp
@@ -876,6 +876,7 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("REGEXP",             TOK_REGEXP,      NONRESTOKEN_),
   ParKeyWord("REGION",             TOK_REGION,      NONRESTOKEN_),
   ParKeyWord("REGISTER",           TOK_REGISTER,    NONRESTOKEN_),
+  ParKeyWord("REGISTERED",         TOK_REGISTERED,  NONRESTOKEN_),
   ParKeyWord("REINITIALIZE",       TOK_REINITIALIZE, FIRST_|NONRESTOKEN_),
   ParKeyWord("RELATED",            TOK_RELATED,     NONRESTOKEN_),
   ParKeyWord("RELATEDNESS",        TOK_RELATEDNESS, NONRESTOKEN_),

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/parser/StmtDDLCleanupObjects.h
----------------------------------------------------------------------
diff --git a/core/sql/parser/StmtDDLCleanupObjects.h b/core/sql/parser/StmtDDLCleanupObjects.h
index 3f33826..d8b15f5 100644
--- a/core/sql/parser/StmtDDLCleanupObjects.h
+++ b/core/sql/parser/StmtDDLCleanupObjects.h
@@ -68,6 +68,8 @@ public:
     SEQUENCE_,
     SCHEMA_PRIVATE_,
     SCHEMA_SHARED_,
+    HIVE_TABLE_,
+    HIVE_VIEW_,
     UNKNOWN_,
     OBSOLETE_
   };

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/parser/StmtDDLMisc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/StmtDDLMisc.cpp b/core/sql/parser/StmtDDLMisc.cpp
index 095c7a9..211ca00 100644
--- a/core/sql/parser/StmtDDLMisc.cpp
+++ b/core/sql/parser/StmtDDLMisc.cpp
@@ -97,6 +97,8 @@ StmtDDLCleanupObjects::bindNode(BindWA * pBindWA)
       (type_ == VIEW_) ||
       (type_ == SCHEMA_PRIVATE_) ||
       (type_ == SCHEMA_SHARED_) ||
+      (type_ == HIVE_TABLE_) ||
+      (type_ == HIVE_VIEW_) ||
       (type_ == UNKNOWN_))
     {
       ComObjectName tableName(param1_);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/parser/StmtDDLRegOrUnregHive.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/StmtDDLRegOrUnregHive.cpp b/core/sql/parser/StmtDDLRegOrUnregHive.cpp
new file mode 100644
index 0000000..ba133b0
--- /dev/null
+++ b/core/sql/parser/StmtDDLRegOrUnregHive.cpp
@@ -0,0 +1,97 @@
+/* -*-C++-*-
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+ ****************************************************************************
+ *
+ * File:         StmtDDLRegOrUnregHive.cpp
+ * Description:  Methods for classes representing DDL (Un)Register Hive Objs
+ *
+ * Language:     C++
+ *
+ *
+ *
+ *****************************************************************************
+ */
+
+#define   SQLPARSERGLOBALS_FLAGS	// must precede all #include's
+
+#include <stdlib.h>
+#ifndef NDEBUG
+#include <iostream>
+#endif
+#include "StmtDDLRegOrUnregHive.h"
+#include "BaseTypes.h"
+#include "ComDiags.h"
+#ifndef   SQLPARSERGLOBALS_CONTEXT_AND_DIAGS
+#define   SQLPARSERGLOBALS_CONTEXT_AND_DIAGS
+#endif
+
+#include "SqlParserGlobals.h"	// must be last #include
+
+
+// -----------------------------------------------------------------------
+// methods for class StmtDDLRegOrUnregHive
+// -----------------------------------------------------------------------
+
+//
+// constructor
+//
+// constructor used for REGISTER/UNREGISTER HIVE objects
+StmtDDLRegOrUnregHive::StmtDDLRegOrUnregHive(const QualifiedName & origObjName,
+                                             const NABoolean isRegister,
+                                             const ComObjectType objType,
+                                             const NABoolean existsOption,
+                                             const NABoolean isInternal,
+                                             const NABoolean cascade,
+                                             const NABoolean cleanup,
+                                             CollHeap * heap)
+  : StmtDDLNode(DDL_REG_OR_UNREG_HIVE),
+    origObjName_(origObjName, PARSERHEAP()),
+    objQualName_(origObjName, PARSERHEAP()),
+    isRegister_(isRegister),
+    objType_(objType),
+    existsOption_(existsOption),
+    isInternal_(isInternal),
+    cascade_(cascade),
+    cleanup_(cleanup)
+{
+}
+
+//
+// virtual destructor
+//
+StmtDDLRegOrUnregHive::~StmtDDLRegOrUnregHive()
+{
+}
+
+//
+// cast
+//
+StmtDDLRegOrUnregHive *
+StmtDDLRegOrUnregHive::castToStmtDDLRegOrUnregHive()
+{
+  return this;
+}
+
+//
+// End of File
+//
+

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/parser/StmtDDLRegOrUnregHive.h
----------------------------------------------------------------------
diff --git a/core/sql/parser/StmtDDLRegOrUnregHive.h b/core/sql/parser/StmtDDLRegOrUnregHive.h
new file mode 100644
index 0000000..0e244ec
--- /dev/null
+++ b/core/sql/parser/StmtDDLRegOrUnregHive.h
@@ -0,0 +1,134 @@
+#ifndef STMTDDLREGORUNREGHIVE_H
+#define STMTDDLREGORUNREGHIVE_H
+//******************************************************************************
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+//******************************************************************************
+/* -*-C++-*-
+ *****************************************************************************
+ *
+ * File:         StmtDDLRegOrUnregHive.h
+ * Description:  class for parse nodes representing register and unregister
+ *               of hive objects in traf metadata.
+ *
+ * Created:      
+ * Language:     C++
+ *
+ *****************************************************************************
+ */
+
+#include "ComLocationNames.h"
+#include "ElemDDLLocation.h"
+#include "ComSmallDefs.h"
+#include "StmtDDLNode.h"
+#include "ElemDDLAuthSchema.h"
+
+// -----------------------------------------------------------------------
+// contents of this file
+// -----------------------------------------------------------------------
+class StmtDDLRegOrUnregHive;
+
+// -----------------------------------------------------------------------
+// forward references
+// -----------------------------------------------------------------------
+// None
+
+// -----------------------------------------------------------------------
+// Register and unregister hive statements
+// -----------------------------------------------------------------------
+class StmtDDLRegOrUnregHive : public StmtDDLNode
+{
+public:
+
+  // constructors
+  // register hive
+  StmtDDLRegOrUnregHive(const QualifiedName & origObjName,
+                        const NABoolean isRegister, // true, register. false, unregister
+                        const ComObjectType objType,
+                        const NABoolean existsOption,
+                        const NABoolean isInternal,
+                        const NABoolean cascade,
+                        const NABoolean cleanup,
+                        CollHeap * heap);
+
+  // virtual destructor
+  virtual ~StmtDDLRegOrUnregHive();
+
+  // cast
+  virtual StmtDDLRegOrUnregHive * castToStmtDDLRegOrUnregHive();
+
+  // for binding
+  ExprNode * bindNode(BindWA *bindWAPtr);
+
+  // accessors
+
+  const QualifiedName & getOrigObjNameAsQualifiedName() const
+  {return origObjName_;}
+  QualifiedName & getOrigObjNameAsQualifiedName()
+  {return origObjName_;}
+  const QualifiedName & getObjNameAsQualifiedName() const
+  {return objQualName_;}
+  QualifiedName   getObjNameAsQualifiedName()
+  {return objQualName_;}  
+  const NABoolean &isRegister() const { return isRegister_; }
+  const ComObjectType &objType() const { return objType_; }
+  const NABoolean &existsOption() const { return existsOption_; }
+
+  const NABoolean &isInternal() const { return isInternal_; }
+
+  const NABoolean &cascade() const { return cascade_; }
+  const NABoolean &cleanup() const { return cleanup_; }
+
+  // for tracing
+
+private:
+
+  // ---------------------------------------------------------------------
+  // private data members
+  // ---------------------------------------------------------------------
+
+  // the tablename specified by user in the register/unregister stmt.
+  // This name is not fully qualified during bind phase.
+  QualifiedName origObjName_;
+  QualifiedName objQualName_;
+
+  NABoolean isRegister_; // TRUE, register. FALSE, unregister
+  ComObjectType objType_;
+
+  // For register operation:
+  //   true, register only if not already registered.
+  //   false, return error if already registered.
+  // For unregister operation:
+  //   true, unregister if registered.
+  //   false, return error if not registered.
+  NABoolean existsOption_;
+
+  // true if this object was registered internally by trafodion
+  NABoolean isInternal_;
+
+  // set to true if all objects in a hive view are to be reg/unreg
+  NABoolean cascade_;
+
+  // set to true if cleanup option is specified with unregister
+  NABoolean cleanup_;
+}; // class StmtDDLRegOrUnregHive
+
+#endif // STMTDDLREGORUNREGHIVE_H

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index ef4d7e6..622ca79 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -1371,6 +1371,7 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %token <tokval> TOK_REGEXP
 %token <tokval> TOK_REGION
 %token <tokval> TOK_REGISTER            /* Tandem extension */
+%token <tokval> TOK_REGISTERED
 %token <tokval> TOK_UNREGISTER          /* Tandem extension */
 %token <tokval> TOK_RENAME              /* Tandem extension */
 %token <tokval> TOK_REPLICATE           /* Tandem extension non-reserved word*/
@@ -2433,8 +2434,11 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %type <pStmtDDL>                drop_component_privilege_stmt
 %type <pStmtDDL>                register_component_statement
 %type <pStmtDDL>                register_user_statement
+%type <pStmtDDL>                register_hive_statement
+%type <boolean>                 optional_internal_clause
 %type <pStmtDDL>                unregister_component_statement
 %type <pStmtDDL>		unregister_user_statement
+%type <pStmtDDL>		unregister_hive_statement
 %type <pElemDDL>  		privileges
 %type <pElemDDL>  		privilege_action_list
 %type <pElemDDL>  		privilege_action
@@ -14463,6 +14467,12 @@ sql_schema_definition_statement :
               | cleanup_objects_statement
                                 {
                                 }
+              | register_hive_statement
+                                {
+                                }
+              | unregister_hive_statement
+                                {
+                                }
 
 /* type pStmtDDL */
 sql_schema_manipulation_statement :
@@ -15841,6 +15851,10 @@ objects_identifier :
                   | TOK_INVALID TOK_VIEWS { $$ = new (PARSERHEAP()) NAString("INVALID_VIEWS"); }
                   | TOK_FUNCTIONS { $$ = new (PARSERHEAP()) NAString("FUNCTIONS"); }
                   | TOK_TABLE_MAPPING TOK_FUNCTIONS { $$ = new (PARSERHEAP()) NAString("TABLE_FUNCTIONS"); }
+                  | TOK_HIVE TOK_REGISTERED TOK_TABLES { $$ = new (PARSERHEAP()) NAString("HIVE_REG_TABLES"); }
+                  | TOK_HIVE TOK_REGISTERED TOK_VIEWS { $$ = new (PARSERHEAP()) NAString("HIVE_REG_VIEWS"); }
+                  | TOK_HIVE TOK_REGISTERED TOK_OBJECTS { $$ = new (PARSERHEAP()) NAString("HIVE_REG_OBJECTS"); }
+                  | TOK_HIVE TOK_EXTERNAL TOK_TABLES { $$ = new (PARSERHEAP()) NAString("HIVE_EXT_TABLES"); }
 
 privileges_identifier :
                     TOK_PRIVILEGES { $$ = new (PARSERHEAP()) NAString("PRIVILEGES"); }
@@ -30276,6 +30290,10 @@ cleanup_objects_statement : TOK_CLEANUP cleanup_object_identifier ddl_qualified_
                    ot = StmtDDLCleanupObjects::SCHEMA_PRIVATE_;
                  else if (*$2 == "SCHEMA_S")
                    ot = StmtDDLCleanupObjects::SCHEMA_SHARED_;
+                 else if (*$2 == "HIVE_TABLE")
+                   ot = StmtDDLCleanupObjects::HIVE_TABLE_;
+                 else if (*$2 == "HIVE_VIEW")
+                   ot = StmtDDLCleanupObjects::HIVE_VIEW_;
                  else if (*$2 == "OBJECT")
                    ot = StmtDDLCleanupObjects::UNKNOWN_;
                  else
@@ -30394,6 +30412,8 @@ cleanup_object_identifier : object_identifier
                        | TOK_PRIVATE TOK_SCHEMA   { $$ = new (PARSERHEAP()) NAString("SCHEMA_P"); }
                        | TOK_SHARED TOK_SCHEMA   { $$ = new (PARSERHEAP()) NAString("SCHEMA_S"); }
                        | TOK_OBJECT { $$ = new (PARSERHEAP()) NAString("OBJECT");}
+                       | TOK_HIVE TOK_TABLE { $$ = new (PARSERHEAP()) NAString("HIVE_TABLE");}
+                       | TOK_HIVE TOK_VIEW { $$ = new (PARSERHEAP()) NAString("HIVE_VIEW");}
 
 /* type boolean */
 optional_cleanup_return_details : empty
@@ -32988,6 +33008,84 @@ nsk_node_name: BACKSLASH_SYSTEM_NAME
                 delete $1;
                }
 
+/* type pStmtDDL */
+// Syntax: 
+// register [internal] hive {table|view|schema} 
+//          [if not exists] <obj-name> [cascade]
+//
+register_hive_statement : TOK_REGISTER optional_internal_clause TOK_HIVE object_identifier optional_if_not_exists_clause ddl_qualified_name optional_cascade
+                          {
+                            if (NOT ((*$4 == "TABLE") ||
+                                     (*$4 == "VIEW") ||
+                                     (*$4 == "SCHEMA")))
+                              {
+                                YYERROR;
+                              }
+      
+                            if ($7 && (*$4 != "VIEW"))
+                              {
+                                YYERROR;
+                              }
+
+                            $$ = new (PARSERHEAP())
+                              StmtDDLRegOrUnregHive(
+                                   *$6,
+                                   TRUE, // register
+                                   (*$4 == "TABLE" ? COM_BASE_TABLE_OBJECT
+                                    : (*$4 == "VIEW" ? COM_VIEW_OBJECT
+                                       : COM_SHARED_SCHEMA_OBJECT)),
+                                   $5, // if not exists?
+                                   $2, // is internal registration?
+                                   $7, // is cascade?
+                                   FALSE,
+                                   PARSERHEAP());
+                            delete $6;
+                          }
+
+// Syntax: 
+// unregister [internal] hive {table|view|schema} 
+//            [if exists] <obj-name> [cascade]
+//
+unregister_hive_statement : TOK_UNREGISTER optional_internal_clause TOK_HIVE object_identifier optional_if_exists_clause ddl_qualified_name optional_cascade optional_cleanup
+                              {
+                                if (NOT ((*$4 == "TABLE") ||
+                                         (*$4 == "VIEW") ||
+                                         (*$4 == "SCHEMA")))
+                                  {
+                                    YYERROR;
+                                  }
+                                
+                                if ($7 &&
+                                    (*$4 != "VIEW"))
+                                  {
+                                    YYERROR;
+                                  }
+                                
+                                $$ = new (PARSERHEAP())
+                                  StmtDDLRegOrUnregHive(
+                                       *$6,
+                                       FALSE, // unregister
+                                       (*$4 == "TABLE" ? COM_BASE_TABLE_OBJECT
+                                        : (*$4 == "VIEW" ? COM_VIEW_OBJECT
+                                           : COM_SHARED_SCHEMA_OBJECT)),
+                                       $5, // if exists?
+                                       $2, // is internal unregister?
+                                       $7, // is cascade?
+                                       $8, // is cleanup?
+                                       PARSERHEAP());
+                                delete $6;
+                              }
+
+/* type boolean */
+optional_internal_clause : empty
+                  {
+                    $$ = FALSE;
+                  }
+                  | TOK_INTERNAL
+                  {
+		    $$ = TRUE;
+		  }
+
 /*CREATE ROLE*/
 create_role_statement : TOK_CREATE TOK_ROLE authorization_identifier
                              optional_with_admin_clause
@@ -33739,6 +33837,7 @@ nonreserved_word :      TOK_ABORT
                       | TOK_REFRESH // MV
                       | TOK_REGION
                       | TOK_REGISTER
+                      | TOK_REGISTERED
                       | TOK_REINITIALIZE
                       | TOK_RELATED
                       | TOK_RELATEDNESS     // Versioning

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9c58649f/core/sql/regress/charsets/EXPECTED004
----------------------------------------------------------------------
diff --git a/core/sql/regress/charsets/EXPECTED004 b/core/sql/regress/charsets/EXPECTED004
index b740bf8..2ad74db 100755
--- a/core/sql/regress/charsets/EXPECTED004
+++ b/core/sql/regress/charsets/EXPECTED004
@@ -435,7 +435,7 @@ select _ucs2 x'0a$#' from (values(1))x;
 >>--large length values should not cause core-dump (case 10-040218-2346)
 >>select space(2147483647,ucs2) from (values (1)) as x;
 
-*** ERROR[4129] The character-typed result of the function REPEAT is longer than max supported size.
+*** ERROR[4129] The character-typed result of the function REPEAT is longer than the maximum supported size.
 
 *** ERROR[4062] The preceding error actually occurred in function SPACE.
 
@@ -443,13 +443,13 @@ select _ucs2 x'0a$#' from (values(1))x;
 
 >>select rpad(N'test',2147483647,N'T') from (values(1)) as x;
 
-*** ERROR[4129] The character-typed result of the function RPAD is longer than max supported size.
+*** ERROR[4129] The character-typed result of the function RPAD is longer than the maximum supported size.
 
 *** ERROR[8822] The statement was not prepared.
 
 >>select lpad(N'test',2147483647,N'T') from (values(1)) as x;
 
-*** ERROR[4129] The character-typed result of the function REPEAT is longer than max supported size.
+*** ERROR[4129] The character-typed result of the function REPEAT is longer than the maximum supported size.
 
 *** ERROR[4062] The preceding error actually occurred in function LPAD.