You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by rm...@apache.org on 2016/08/12 00:59:14 UTC

[01/10] incubator-trafodion git commit: [TRAFODION-1882]: Column Privilege: a user can grant column privilege to ... [TRAFODION-1788]: Grant and Revoke on table columns with referencing views ...

Repository: incubator-trafodion
Updated Branches:
  refs/heads/master a5b2b95b3 -> 8f538986c


[TRAFODION-1882]: Column Privilege: a user can grant column privilege to ...
[TRAFODION-1788]: Grant and Revoke on table columns with referencing views ...

The main issue is that the view-col <=> referenced-col usages were not available
from the metadata.
-- create view was changed to add view-col <=> referenced-col usages to the
   TEXT table.  This allows NATable and privilege management to retrieve this
   information. No upgrade is required
-- Privilege management was changed to see if views could still exist based
   only on column level privileges.
-- Grants and revokes on referenced columns for objects are now  propagated to
   to referencing views
-- Fixed an issue during column grants where column ordinals were not checked
   correctly [TRAFODION-1882]
-- Fixed an issue where DB__ROOT, acting as schema owner, was able to grant
   privileges that the schema owner was not able to grant,


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

Branch: refs/heads/master
Commit: a71d832f20e7db3be70969b75d87a45f02072dea
Parents: 7ad34b1
Author: Roberta Marton <rm...@edev07.esgyn.local>
Authored: Sat Jul 16 00:22:43 2016 +0000
Committer: Roberta Marton <rm...@edev07.esgyn.local>
Committed: Sat Jul 16 00:22:43 2016 +0000

----------------------------------------------------------------------
 core/sql/comexe/ComTdb.h                |   1 +
 core/sql/common/ComSmallDefs.h          |   3 +-
 core/sql/common/ComViewColUsage.h       |  89 ++++
 core/sql/generator/Generator.cpp        |   8 +
 core/sql/optimizer/NATable.cpp          |  26 +
 core/sql/optimizer/NATable.h            |   3 +
 core/sql/sqlcat/ReadTableDef.cpp        |   1 +
 core/sql/sqlcat/desc.h                  |   1 +
 core/sql/sqlcomp/CmpSeabaseDDL.h        |   5 +
 core/sql/sqlcomp/CmpSeabaseDDLtable.cpp |  12 +
 core/sql/sqlcomp/CmpSeabaseDDLview.cpp  | 168 ++++++-
 core/sql/sqlcomp/PrivMgr.h              |   9 +-
 core/sql/sqlcomp/PrivMgrMD.cpp          | 132 +++++
 core/sql/sqlcomp/PrivMgrMD.h            |  38 ++
 core/sql/sqlcomp/PrivMgrPrivileges.cpp  | 713 ++++++++++++++++++---------
 core/sql/sqlcomp/PrivMgrPrivileges.h    |  16 +
 16 files changed, 967 insertions(+), 258 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/comexe/ComTdb.h
----------------------------------------------------------------------
diff --git a/core/sql/comexe/ComTdb.h b/core/sql/comexe/ComTdb.h
index 96a55c4..0a2c375 100644
--- a/core/sql/comexe/ComTdb.h
+++ b/core/sql/comexe/ComTdb.h
@@ -1053,6 +1053,7 @@ class ComTdbVirtTableViewInfo : ComTdbVirtTableBase
   char * viewName;
   char * viewText;
   char * viewCheckText;
+  char * viewColUsages;
   Lng32 isUpdatable;
   Lng32 isInsertable;
 };

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/common/ComSmallDefs.h
----------------------------------------------------------------------
diff --git a/core/sql/common/ComSmallDefs.h b/core/sql/common/ComSmallDefs.h
index 19c7dde..66759ae 100644
--- a/core/sql/common/ComSmallDefs.h
+++ b/core/sql/common/ComSmallDefs.h
@@ -637,7 +637,8 @@ enum ComTextType {COM_VIEW_TEXT = 0,
                   COM_TABLE_COMMENT_TEXT = 3,
                   COM_COMPUTED_COL_TEXT = 4,
                   COM_HBASE_COL_FAMILY_TEXT = 5,
-                  COM_HBASE_SPLIT_TEXT = 6
+                  COM_HBASE_SPLIT_TEXT = 6,
+                  COM_VIEW_REF_COLS_TEXT = 7
 };
 
 enum ComColumnDirection { COM_UNKNOWN_DIRECTION

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/common/ComViewColUsage.h
----------------------------------------------------------------------
diff --git a/core/sql/common/ComViewColUsage.h b/core/sql/common/ComViewColUsage.h
new file mode 100644
index 0000000..811be07
--- /dev/null
+++ b/core/sql/common/ComViewColUsage.h
@@ -0,0 +1,89 @@
+// @@@ 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:         ComViewColUsage.h
+ * Description:  Defines the referenced object (table or view) column 
+ *               relationship to the corresponding view column.
+ *               
+ * Created:      7/15/16
+ * Language:     C++
+ *
+ *****************************************************************************
+ */
+
+#ifndef COMVIEWCOLUSAGE_H
+#define COMVIEWCOLUSAGE_H
+
+#include "ComSmallDefs.h"
+#include "str.h"
+
+class ComViewColUsage
+{
+  Int64 viewUID_;
+  Int32 viewColNumber_;
+  Int64 refdUID_;
+  Int32 refdColNumber_;
+  ComObjectType refdObjectType_;
+
+public:
+  virtual ~ComViewColUsage()
+  {};
+
+  Int64 getViewUID () { return viewUID_; }
+  void setViewUID(Int64 viewUID) { viewUID_ = viewUID; }
+
+  Int32 getViewColNumber () { return viewColNumber_; }
+  void setViewColNumber(Int32 viewColNumber) { viewColNumber_ = viewColNumber; }
+
+  Int64 getRefdUID () { return refdUID_; }
+  void setRefdUID(Int64 refdUID) { refdUID_ = refdUID; }
+
+  Int32 getRefdColNumber () { return refdColNumber_; }
+  void setRefdColNumber(Int32 refdColNumber) { refdColNumber_ = refdColNumber; }
+
+  Int32 getRefdObjectType () { return refdObjectType_; }
+  void setRefdObjectType(ComObjectType refdObjectType) { refdObjectType_ = refdObjectType; }
+
+  void packUsage (NAString &viewColUsageStr)
+  {
+      char buf[sizeof(Int64)*2 + sizeof(Int32)*3 + 100];
+      str_sprintf(buf, "viewUID: %Ld viewCol: %d refUID: %Ld refCol: %d refType: %d;",
+                  viewUID_, viewColNumber_,
+                  refdUID_, refdColNumber_, refdObjectType_);
+      viewColUsageStr = buf;
+  }
+
+  void unpackUsage (const char *viewColUsageStr)
+  {
+      Int32 theRefdObjectType;
+      sscanf(viewColUsageStr, "viewUID: %Ld viewCol: %d refUID: %Ld refCol: %d refType: %d%*s",
+             (long long int *)&viewUID_, &viewColNumber_, 
+             (long long int *)&refdUID_, &refdColNumber_, &theRefdObjectType);
+
+      refdObjectType_ = (ComObjectType) theRefdObjectType;
+  }
+};
+
+#endif  // COMVIEWCOLUSAGE_H
+

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/generator/Generator.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/Generator.cpp b/core/sql/generator/Generator.cpp
index c244c5a..77e4e35 100644
--- a/core/sql/generator/Generator.cpp
+++ b/core/sql/generator/Generator.cpp
@@ -2079,6 +2079,14 @@ desc_struct * Generator::createVirtualTableDesc(
       else
 	view_desc->body.view_desc.viewchecktext = NULL;
 
+      if (viewInfo[0].viewColUsages)
+	{
+	  view_desc->body.view_desc.viewcolusages = new HEAP char[strlen(viewInfo[0].viewColUsages)+1];
+	  strcpy(view_desc->body.view_desc.viewcolusages, viewInfo[0].viewColUsages);
+	}
+      else
+	view_desc->body.view_desc.viewcolusages = NULL;
+
       view_desc->body.view_desc.updatable = viewInfo[0].isUpdatable;
       view_desc->body.view_desc.insertable = viewInfo[0].isInsertable;
     }

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/optimizer/NATable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NATable.cpp b/core/sql/optimizer/NATable.cpp
index 827aaca..8e15127 100644
--- a/core/sql/optimizer/NATable.cpp
+++ b/core/sql/optimizer/NATable.cpp
@@ -4997,6 +4997,7 @@ NATable::NATable(BindWA *bindWA,
     viewTextInNAWchars_(heap),
     viewTextCharSet_(CharInfo::UnknownCharSet),
     viewCheck_(NULL),
+    viewColUsages_(NULL),
     flags_(IS_INSERTABLE | IS_UPDATABLE),
     insertMode_(COM_REGULAR_TABLE_INSERT_MODE),
     isSynonymTranslationDone_(FALSE),
@@ -5310,6 +5311,21 @@ NATable::NATable(BindWA *bindWA,
         memcpy(viewCheck_, view_desc->body.view_desc.viewchecktext,
                viewCheckLength);
       }
+
+      viewColUsages_ = NULL;
+      if(view_desc->body.view_desc.viewcolusages){
+        viewColUsages_ = new (heap_) NAList<ComViewColUsage *>; //initialize empty list
+        char * beginStr (view_desc->body.view_desc.viewcolusages);
+        char * endStr = strchr(beginStr, ';');
+        while (endStr != NULL) {
+          ComViewColUsage *colUsage = new (heap_) ComViewColUsage;
+          NAString currentUsage(beginStr, endStr - beginStr + 1); 
+          colUsage->unpackUsage (currentUsage.data());
+          viewColUsages_->insert(colUsage);
+          beginStr = endStr+1;
+          endStr = strchr(beginStr, ';');
+        }
+      }
       setUpdatable(view_desc->body.view_desc.updatable);
       setInsertable(view_desc->body.view_desc.insertable);
 
@@ -6971,6 +6987,16 @@ NATable::~NATable()
      NADELETEBASIC(viewCheck_, heap_);
      viewCheck_ = NULL;
   } 
+  if (viewColUsages_ != NULL)
+  {
+     for(Int32 i = 0; i < viewColUsages_->entries(); i++)
+     {
+        ComViewColUsage *pUsage = viewColUsages_->operator[](i);
+        NADELETEBASIC(pUsage, heap_);
+     }
+     NADELETEBASIC(viewColUsages_, heap_);
+     viewColUsages_ = NULL;
+  } 
   if (viewFileName_ != NULL)
   {
      NADELETEBASIC(viewFileName_, heap_);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/optimizer/NATable.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NATable.h b/core/sql/optimizer/NATable.h
index 7a87344..9c18589 100644
--- a/core/sql/optimizer/NATable.h
+++ b/core/sql/optimizer/NATable.h
@@ -45,6 +45,7 @@
 #include "ExpLOBexternal.h"
 #include "ComSecurityKey.h"
 #include "ExpHbaseDefs.h"
+#include "ComViewColUsage.h"
 
 //forward declaration(s)
 // -----------------------------------------------------------------------
@@ -565,6 +566,7 @@ public:
   Int32   getViewTextLenInNAWchars() const   { return viewTextInNAWchars_.length(); }
 
   const char *getViewCheck() const              { return viewCheck_; }
+  const NAList<ComViewColUsage*> *getViewColUsages() const  { return viewColUsages_; }
 
   NABoolean hasSaltedColumn(Lng32 * saltColPos = NULL);
   NABoolean hasDivisioningColumn(Lng32 * divColPos = NULL);
@@ -1085,6 +1087,7 @@ private:
   NAWString viewTextInNAWchars_;
   CharInfo::CharSet viewTextCharSet_;
   char *viewCheck_;
+  NAList<ComViewColUsage *> *viewColUsages_;
 
   // ---------------------------------------------------------------------
   // Flags

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/sqlcat/ReadTableDef.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcat/ReadTableDef.cpp b/core/sql/sqlcat/ReadTableDef.cpp
index c6b3ecb..df0efbc 100644
--- a/core/sql/sqlcat/ReadTableDef.cpp
+++ b/core/sql/sqlcat/ReadTableDef.cpp
@@ -381,6 +381,7 @@ void ReadTableDef::displayTreeMX(const desc_struct * top,
         COUT(view, viewname);
         COUT_STRING(view, viewtext);
         COUT_STRING(view, viewchecktext);
+        COUT_STRING(view, viewcolusages);
         COUT(view, updatable);
         COUT(view, insertable);
       }

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/sqlcat/desc.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcat/desc.h b/core/sql/sqlcat/desc.h
index f6b8beb..89c270d 100644
--- a/core/sql/sqlcat/desc.h
+++ b/core/sql/sqlcat/desc.h
@@ -158,6 +158,7 @@ struct view_desc_struct {
   char * viewfilename;    // the physical file, to be Opened for auth-cking.
   char * viewtext;
   char * viewchecktext;
+  char * viewcolusages;
   Int32 updatable;
   Int32 insertable;
   CharInfo::CharSet viewtextcharset;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/sqlcomp/CmpSeabaseDDL.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDL.h b/core/sql/sqlcomp/CmpSeabaseDDL.h
index 970a6cf..4d71dff 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDL.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDL.h
@@ -800,6 +800,10 @@ protected:
   short buildViewColInfo(StmtDDLCreateView * createViewParseNode,
 			 ElemDDLColDefArray * colDefArray);
   
+  short buildViewTblColUsage(const StmtDDLCreateView * createViewParseNode,
+                             const ComTdbVirtTableColumnInfo * colInfoArray,
+                             const Int64 viewObjUID, NAString &viewColUsageText);
+
   short buildColInfoArray(ElemDDLParamDefArray *paramArray,
                           ComTdbVirtTableColumnInfo * colInfoArray);
   
@@ -822,6 +826,7 @@ protected:
   short gatherViewPrivileges (const StmtDDLCreateView * createViewParseNode,
                               ExeCliInterface * cliInterface,
                               NABoolean viewCreator,
+                              Int32 schemaID,
                               PrivMgrBitmap &privilegesBitmap,
                               PrivMgrBitmap &grantableBitmap);
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
index b8b05da..e2f2366 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
@@ -10864,6 +10864,18 @@ desc_struct * CmpSeabaseDDL::getSeabaseUserTableDesc(const NAString &catName,
 
       viewInfoArray[0].viewText = new(STMTHEAP) char[viewText.length() + 1];
       strcpy(viewInfoArray[0].viewText, viewText.data());
+
+      // get view col usages from TEXT table
+      NAString viewColUsages;
+      if (getTextFromMD(&cliInterface, objUID, COM_VIEW_REF_COLS_TEXT, 0, viewColUsages))
+        {
+          processReturn();
+          
+          return NULL;
+        }
+
+      viewInfoArray[0].viewColUsages = new(STMTHEAP) char[viewColUsages.length() + 1];
+      strcpy(viewInfoArray[0].viewColUsages, viewColUsages.data());
     }
 
   ComTdbVirtTableSequenceInfo * seqInfo = NULL;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLview.cpp b/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
index 3cb7bbb..8211b4a 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
@@ -40,6 +40,7 @@
 
 #include "ComObjectName.h"
 #include "ComUser.h"
+#include "ComViewColUsage.h"
 
 #include "StmtDDLCreateView.h"
 #include "StmtDDLDropView.h"
@@ -67,6 +68,7 @@ static bool checkAccessPrivileges(
    const ParTableUsageList & vtul,
    const ParViewColTableColsUsageList & vctcul,
    NABoolean viewCreator,
+   Int32 schemaID,
    PrivMgrBitmap & privilegesBitmap,
    PrivMgrBitmap & grantableBitmap);
 
@@ -248,6 +250,65 @@ short CmpSeabaseDDL::buildViewColInfo(StmtDDLCreateView * createViewParseNode,
   return 0;
 }
 
+// Build view column usages -> relate view-col <=> referenced-col
+// This relationship is a string of values that gets stored in the TEXT table
+short CmpSeabaseDDL::buildViewTblColUsage(const StmtDDLCreateView * createViewParseNode,
+                                          const ComTdbVirtTableColumnInfo * colInfoArray,
+                                          const Int64 objUID, NAString &viewColUsageText)
+{
+  const ParViewUsages &vu = createViewParseNode->getViewUsages();
+  const ParViewColTableColsUsageList &vctcul = vu.getViewColTableColsUsageList();
+  BindWA bindWA(ActiveSchemaDB(),CmpCommon::context(),FALSE/*inDDL*/);
+
+  for (size_t i = 0; i < vctcul.entries(); i++)
+  {
+     const ParViewColTableColsUsage &vctcu = vctcul[i];
+     int32_t usingColNum = vctcu.getUsingViewColumnNumber();
+
+     // Get column name for view
+     const ComTdbVirtTableColumnInfo * colInfo = &colInfoArray[usingColNum];
+
+     // Get column number for referenced table
+     const ColRefName &usedColRef = vctcu.getUsedObjectColumnName();
+     ComObjectName usedObjName;
+     usedObjName = usedColRef.getCorrNameObj().getQualifiedNameObj().
+                   getQualifiedNameAsAnsiString();
+
+     const NAString catalogNamePart = usedObjName.getCatalogNamePartAsAnsiString();
+     const NAString schemaNamePart = usedObjName.getSchemaNamePartAsAnsiString(TRUE);
+     const NAString objectNamePart = usedObjName.getObjectNamePartAsAnsiString(TRUE);
+     CorrName cn(objectNamePart,STMTHEAP,schemaNamePart,catalogNamePart);
+
+     NATable *naTable = bindWA.getNATable(cn);
+     if (naTable == NULL)
+     {
+        SEABASEDDL_INTERNAL_ERROR("Bad NATable pointer in createSeabaseView");
+        return -1;
+     }
+
+     const NAColumnArray &nacolArr = naTable->getNAColumnArray();
+     ComString usedObjColName(usedColRef.getColName());
+     const NAColumn * naCol = nacolArr.getColumn(usedObjColName);
+     if (naCol == NULL)
+     {
+       *CmpCommon::diags() << DgSqlCode(-CAT_COLUMN_DOES_NOT_EXIST_ERROR)
+                           << DgColumnName(usedObjColName);
+        return -1;
+     }
+
+     ComViewColUsage colUsage;
+     colUsage.setViewUID (objUID);
+     colUsage.setViewColNumber (usingColNum);
+     colUsage.setRefdUID (naTable->objectUid().get_value());
+     colUsage.setRefdColNumber (naCol->getPosition());
+     colUsage.setRefdObjectType (naTable->getObjectType());
+     NAString viewColUsageStr;
+     colUsage.packUsage(viewColUsageStr);
+     viewColUsageText += viewColUsageStr;
+  }
+  return 0;
+}
+
 const char *
 CmpSeabaseDDL::computeCheckOption(StmtDDLCreateView * createViewParseNode) 
 {
@@ -368,6 +429,8 @@ short CmpSeabaseDDL::updateViewUsage(StmtDDLCreateView * createViewParseNode,
 //    createViewNode - for list of objects and isUpdatable/isInsertable flags
 //    cliInterface - used to get UID of referenced object
 //    viewCreator - determines which authID to use to gather privs
+//    schemaID - schemaID to use when root is performing operations on behalf 
+//      of another user.
 //    privilegeBitmap - returns privileges this user has on the view
 //    grantableBitmap - returns privileges this user can grant
 //
@@ -378,6 +441,7 @@ short CmpSeabaseDDL::updateViewUsage(StmtDDLCreateView * createViewParseNode,
 short CmpSeabaseDDL::gatherViewPrivileges (const StmtDDLCreateView * createViewNode,
 				           ExeCliInterface * cliInterface,
                                            NABoolean viewCreator,
+                                           Int32 schemaID,
                                            PrivMgrBitmap &privilegesBitmap,
                                            PrivMgrBitmap &grantableBitmap)
 {
@@ -395,8 +459,7 @@ short CmpSeabaseDDL::gatherViewPrivileges (const StmtDDLCreateView * createViewN
   const ParViewColTableColsUsageList &vctcul = vu.getViewColTableColsUsageList();
 
   // If DB__ROOT, no need to gather privileges
-  if (!ComUser::isRootUserID() && 
-      !checkAccessPrivileges(vtul,vctcul,viewCreator,privilegesBitmap,grantableBitmap))
+  if (!checkAccessPrivileges(vtul,vctcul,viewCreator,schemaID,privilegesBitmap,grantableBitmap))
     return -1;
 
   // If view is not updatable or insertable, turn off privs in bitmaps
@@ -726,11 +789,17 @@ void CmpSeabaseDDL::createSeabaseView(
     ((schemaClass == COM_SCHEMA_CLASS_SHARED) ? TRUE : 
       ((ComUser::getCurrentUser() == schemaOwnerID) ? TRUE : FALSE));
  
+  // If DB ROOT is running command on behalf of another user, then the view
+  // owner is the same of the view creator
+  if (ComUser::isRootUserID() && (ComUser::getRootUserID() != schemaOwnerID))
+    viewOwnerIsViewCreator = TRUE;
+
   // Gather privileges for the view creator
   NABoolean viewCreator = TRUE;
   if (gatherViewPrivileges(createViewNode, 
                            &cliInterface, 
                            viewCreator,
+                           schemaOwnerID,
                            privilegesBitmap, 
                            grantableBitmap))
     {
@@ -746,7 +815,7 @@ void CmpSeabaseDDL::createSeabaseView(
 
   // If view owner is the same as view creator, owner and creator privileges
   // are the same
-  if (viewOwnerIsViewCreator)
+  if (viewOwnerIsViewCreator) 
     {
       ownerPrivBitmap = privilegesBitmap;
       ownerGrantableBitmap = grantableBitmap; 
@@ -759,6 +828,7 @@ void CmpSeabaseDDL::createSeabaseView(
       if (gatherViewPrivileges(createViewNode, 
                                &cliInterface, 
                                !viewCreator,
+                               schemaOwnerID,
                                ownerPrivBitmap, 
                                ownerGrantableBitmap))
         {
@@ -832,6 +902,14 @@ void CmpSeabaseDDL::createSeabaseView(
         return;
       }
 
+  NAString viewColUsageText;
+  if (buildViewTblColUsage(createViewNode, colInfoArray, objUID,  viewColUsageText))
+    {
+      deallocEHI(ehi); 
+      processReturn();
+      return;
+    }
+
   // grant privileges for view
   if (isAuthorizationEnabled())
     {
@@ -844,6 +922,8 @@ void CmpSeabaseDDL::createSeabaseView(
       // Calculate the view owner (grantee)
       int32_t grantee = (viewOwnerIsViewCreator) 
          ? ComUser::getCurrentUser() : schemaOwnerID;
+      if (ComUser::isRootUserID() && (ComUser::getRootUserID() != schemaOwnerID))
+        grantee = schemaOwnerID;
       
       // Grant view ownership - grantor is the SYSTEM
       retcode = privInterface.grantObjectPrivilege 
@@ -921,6 +1001,13 @@ void CmpSeabaseDDL::createSeabaseView(
       return;
     }
 
+  if (updateTextTable(&cliInterface, objUID, COM_VIEW_REF_COLS_TEXT, 0, viewColUsageText))
+    {
+      deallocEHI(ehi);
+      processReturn();
+      return;
+    }
+
   if (updateViewUsage(createViewNode, objUID, &cliInterface))
     {
       deallocEHI(ehi); 
@@ -1468,6 +1555,7 @@ static bool checkAccessPrivileges(
    const ParTableUsageList & vtul,
    const ParViewColTableColsUsageList & vctcul,
    NABoolean viewCreator,
+   Int32 schemaID,
    PrivMgrBitmap & privilegesBitmap,
    PrivMgrBitmap & grantableBitmap)
    
@@ -1508,13 +1596,34 @@ static bool checkAccessPrivileges(
 
       PrivMgrUserPrivs privs;
       PrivMgrUserPrivs *pPrivInfo = NULL;
+      PrivStatus retcode = STATUS_GOOD;
 
       // If gathering privileges for the view creator, the NATable structure
       // contains the privileges we want to use to create bitmaps
       if (viewCreator)
       {
-        pPrivInfo = naTable->getPrivInfo();
-        CMPASSERT(pPrivInfo != NULL);
+        // If the viewCreator is not the current user (DB__ROOT running request)
+        // on behalf of the schema owner), get actual owner privs.
+        if (ComUser::isRootUserID() &&
+            ComUser::getRootUserID() != naTable->getSchemaOwner())
+        {
+          retcode = privInterface.getPrivileges((int64_t)naTable->objectUid().get_value(),
+                                                 naTable->getObjectType(),
+                                                 schemaID,
+                                                 privs);
+
+          if (retcode == STATUS_ERROR)
+          {         
+             *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_RETRIEVE_PRIVS);
+             return false;
+          }
+          pPrivInfo = &privs;
+        }
+        else
+        {
+          pPrivInfo = naTable->getPrivInfo();
+          CMPASSERT(pPrivInfo != NULL);
+        }
       }
       
       // If the view owner is not the view creator, then we need to get schema
@@ -1546,22 +1655,22 @@ static bool checkAccessPrivileges(
       grantableBitmap &= pPrivInfo->getGrantableBitmap();
    }
    
-   //  To create a view you need at least select privilege, noSelectPriv
+   PrivColumnBitmap colPrivBitmap;
+   PrivColumnBitmap colGrantableBitmap;
+
+   PrivMgrPrivileges::setColumnPrivs(colPrivBitmap);
+   PrivMgrPrivileges::setColumnPrivs(colGrantableBitmap);
+
+   //  To create a view you need at least select privilege, missingPrivilege
    //  is true if the auth ID does not have select privilege at the object
    //  level.  The view can still be created if select exists at the column
    //  level.
    bool noObjPriv = missingPrivilege;
    missingPrivilege = false;   
-      
+
    // Gather column level privs to attach to the bitmap.
    // Even though privileges are granted on the column, they show up as
    // object privileges on the view.
-   PrivColumnBitmap colPrivBitmap;
-   PrivColumnBitmap colGrantableBitmap;
-
-   PrivMgrPrivileges::setColumnPrivs(colPrivBitmap);
-   PrivMgrPrivileges::setColumnPrivs(colGrantableBitmap);
-
    for (size_t i = 0; i < vctcul.entries(); i++)
    {
       const ParViewColTableColsUsage &vctcu = vctcul[i];
@@ -1599,14 +1708,35 @@ static bool checkAccessPrivileges(
      
       PrivMgrUserPrivs privs;
       PrivMgrUserPrivs *pPrivInfo = NULL;
+      PrivStatus retcode = STATUS_GOOD;
       if (viewCreator)
-        pPrivInfo = naTable->getPrivInfo();
+      {
+        // If the viewCreator is not the current user (DB__ROOT running request)
+        // on behalf of the schema owner), get actual owner privs.
+        if (ComUser::isRootUserID() &&
+            ComUser::getRootUserID() != naTable->getSchemaOwner())
+        {
+          retcode = privInterface.getPrivileges((int64_t)naTable->objectUid().get_value(),
+                                                 naTable->getObjectType(),
+                                                 schemaID,
+                                                 privs);
+
+          if (retcode == STATUS_ERROR)
+          {         
+             *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_RETRIEVE_PRIVS);
+             return false;
+          }
+          pPrivInfo = &privs;
+        }
+        else
+          pPrivInfo = naTable->getPrivInfo();
+      }
       else
       {
-        PrivStatus retcode = privInterface.getPrivileges((int64_t)naTable->objectUid().get_value(),
-                                                           naTable->getObjectType(),
-                                                           naTable->getOwner(),
-                                                           privs);
+        retcode = privInterface.getPrivileges((int64_t)naTable->objectUid().get_value(),
+                                                naTable->getObjectType(),
+                                                naTable->getOwner(),
+                                                privs);
 
         if (retcode == STATUS_ERROR)
         {
@@ -1633,7 +1763,7 @@ static bool checkAccessPrivileges(
       colPrivBitmap &= pPrivInfo->getColumnPrivBitmap(usedColNumber);
       colGrantableBitmap &= pPrivInfo->getColumnGrantableBitmap(usedColNumber);
    }
-  
+
    if (noObjPriv && missingPrivilege)
      {
         *CmpCommon::diags() << DgSqlCode(-4481)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/sqlcomp/PrivMgr.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgr.h b/core/sql/sqlcomp/PrivMgr.h
index da7145e..fb3c1aa 100644
--- a/core/sql/sqlcomp/PrivMgr.h
+++ b/core/sql/sqlcomp/PrivMgr.h
@@ -68,9 +68,12 @@ class PrivMgr
                           };
 
     enum PrivCommand { GRANT_OBJECT           = 30,
-                       REVOKE_OBJECT_RESTRICT = 31,
-                       REVOKE_OBJECT_CASCADE  = 32,
-                       UNKNOWN_PRIV_COMMAND   = 33
+                       GRANT_COLUMN           = 31,
+                       REVOKE_OBJECT_RESTRICT = 32,
+                       REVOKE_OBJECT_CASCADE  = 33,
+                       REVOKE_COLUMN_RESTRICT = 34,
+                       REVOKE_COLUMN_CASCADE  = 35,
+                       UNKNOWN_PRIV_COMMAND   = 36
                      };
 
     // -------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/sqlcomp/PrivMgrMD.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrMD.cpp b/core/sql/sqlcomp/PrivMgrMD.cpp
index df0ca1c..4f64517 100644
--- a/core/sql/sqlcomp/PrivMgrMD.cpp
+++ b/core/sql/sqlcomp/PrivMgrMD.cpp
@@ -630,6 +630,138 @@ bool PrivMgrMDAdmin::isAuthorized (void)
 }
 
 // ****************************************************************************
+// method:  getColumnReferences
+//
+//  This method stores the list of columns for the object in the 
+//  ObjectReference. 
+// **************************************************************************** 
+PrivStatus PrivMgrMDAdmin::getColumnReferences (ObjectReference *objectRef)
+{
+  std::string objectMDTable = trafMetadataLocation_ + ".OBJECTS o";
+  std::string colMDTable = trafMetadataLocation_ + ".COLUMNS c";
+
+  // Select column details for object 
+  std::string selectStmt = "select c.column_number from ";
+  selectStmt += objectMDTable;
+  selectStmt += ", ";
+  selectStmt += colMDTable;
+  selectStmt += " where o.object_uid = ";
+  selectStmt += UIDToString(objectRef->objectUID);
+  selectStmt += " and o.object_uid = c.object_uid";
+  selectStmt += " order by column_number";
+
+  ExeCliInterface cliInterface(STMTHEAP, NULL, NULL,
+  CmpCommon::context()->sqlSession()->getParentQid());
+  Queue * objectsQueue = NULL;
+
+  int32_t cliRC =  cliInterface.fetchAllRows(objectsQueue, (char *)selectStmt.c_str(), 0, FALSE, FALSE, TRUE);
+  if (cliRC < 0)
+  {
+    cliInterface.retrieveSQLDiagnostics(pDiags_);
+    return STATUS_ERROR;
+  }
+
+  if (cliRC == 100) // did not find the row
+  {
+    std::string message ("No columns found for referenced object");
+    PRIVMGR_INTERNAL_ERROR(message.c_str());
+    return STATUS_ERROR;
+  }
+
+  char * ptr = NULL;
+  Int32 len = 0;
+
+  objectRef->columnReferences = new std::vector<ColumnReference *>;
+
+  // For each row, create a ColumnReference and add it to the objectRef
+  objectsQueue->position();
+  for (int idx = 0; idx < objectsQueue->numEntries(); idx++)
+  {
+    OutputInfo * pCliRow = (OutputInfo*)objectsQueue->getNext();
+    ColumnReference *columnReference = new ColumnReference;
+
+    // column 0:  columnNumber
+    pCliRow->get(0,ptr,len);
+    columnReference->columnOrdinal = *(reinterpret_cast<int32_t*>(ptr));
+
+    objectRef->columnReferences->push_back(columnReference);
+  }
+  return STATUS_GOOD;
+}
+
+// ****************************************************************************
+// method:  getViewColUsages
+//
+//  This method reads the TEXT table to obtain the view-col <=> referenced-col
+//  relationship.
+//
+//  This relationship is stored in one or more text records with the text_type
+//  COM_VIEW_REF_COLS_TEXT (7) see ComSmallDefs.h 
+//
+//  The text rows are concatenated together and saved in the ViewUsage.
+// **************************************************************************** 
+PrivStatus PrivMgrMDAdmin::getViewColUsages (ViewUsage &viewUsage)
+{
+  std::string objectMDTable = trafMetadataLocation_ + ".OBJECTS o";
+  std::string textMDTable = trafMetadataLocation_ + ".TEXT t";
+
+  // Select text rows describing view <=> object column relationships
+  std::string selectStmt = "select text from ";
+  selectStmt += objectMDTable;
+  selectStmt += ", ";
+  selectStmt += textMDTable;
+  selectStmt += " where o.object_uid = ";
+  selectStmt += UIDToString(viewUsage.viewUID);
+  selectStmt += "and o.object_uid = t.text_uid and t.text_type = 7";
+  selectStmt += " order by seq_num";
+  
+  ExeCliInterface cliInterface(STMTHEAP, NULL, NULL,
+  CmpCommon::context()->sqlSession()->getParentQid());
+  Queue * objectsQueue = NULL;
+  
+  int32_t cliRC =  cliInterface.fetchAllRows(objectsQueue, (char *)selectStmt.c_str(), 0, FALSE, FALSE, TRUE);
+  if (cliRC < 0)
+  { 
+    cliInterface.retrieveSQLDiagnostics(pDiags_);
+    return STATUS_ERROR;
+  }
+  
+  // View prior to column privilege support do not store view <=> object column
+  // relationships.  These views were not created based on column privileges
+  // so just return.
+  if (cliRC == 100) // did not find the row
+  { 
+    return STATUS_GOOD;
+  }
+  
+  char * ptr = NULL;
+  Int32 len = 0;
+
+  // the text column length in the TEXT table is 10000
+  char value[10000 + 1];
+  
+  // For each row, add it to the existing viewColUsages string
+  objectsQueue->position();
+  for (int idx = 0; idx < objectsQueue->numEntries(); idx++)
+  { 
+    OutputInfo * pCliRow = (OutputInfo*)objectsQueue->getNext();
+    ColumnReference *columnReference = new ColumnReference;
+
+    // column 0: text 
+    pCliRow->get(0,ptr,len);
+    strncpy(value, ptr, len);
+    value[len] = 0;
+    viewUsage.viewColUsagesStr += value;
+  }
+
+  return STATUS_GOOD;
+} 
+
+
+
+
+
+// ****************************************************************************
 // method:  getViewsThatReferenceObject
 //
 //  this method gets the list of views associated with the passed in 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/sqlcomp/PrivMgrMD.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrMD.h b/core/sql/sqlcomp/PrivMgrMD.h
index c52a635..783dbe5 100644
--- a/core/sql/sqlcomp/PrivMgrMD.h
+++ b/core/sql/sqlcomp/PrivMgrMD.h
@@ -31,6 +31,7 @@
 #include "PrivMgrDesc.h"
 #include "PrivMgrMDTable.h"
 #include "ComSmallDefs.h"
+#include "ComViewColUsage.h"
 #include "CmpSeabaseDDLauth.h"
 
 // following includes needed for cli interface
@@ -87,6 +88,7 @@ typedef struct {
   std::string viewName;
   bool isUpdatable;
   bool isInsertable;
+  std::string viewColUsagesStr;
   PrivMgrDesc originalPrivs;
   PrivMgrDesc updatedPrivs;
 
@@ -99,6 +101,8 @@ typedef struct {
     details += viewName;
     details += ", viewOwner is ";
     details += to_string((long long int) viewOwner);
+    details += ", viewColUsagesStr is ";
+    details += viewColUsagesStr;
     details += (isUpdatable) ? ", isUpdatable is Y " : "isUpdateable is N"; 
     details += (isInsertable) ? ", isInsertable is Y " : "isInsertable is N"; 
   }
@@ -138,6 +142,17 @@ class ObjectReference
   std::vector<ColumnReference *> *columnReferences;
   PrivMgrDesc updatedPrivs;
 
+  ColumnReference * find (int32_t columnOrdinal)
+  {
+    for (size_t i = 0; i < columnReferences->size(); i++)
+    {
+      ColumnReference *pColRef = (*columnReferences)[i];
+      if (pColRef->columnOrdinal == columnOrdinal)
+        return pColRef;
+    }
+    return NULL;
+  }
+
   void describe (std::string &details) const
   {
     details = "object reference - type is ";
@@ -187,6 +202,25 @@ class ObjectUsage
   PrivMgrDesc originalPrivs;
   PrivMgrDesc updatedPrivs;
 
+  void copyColumnReferences(const std::vector<ColumnReference *> *refsToCopy)
+  {
+    if (refsToCopy == NULL)
+      columnReferences = NULL;
+    else
+    {
+      columnReferences = new std::vector<ColumnReference *>;
+      for (int i = 0; i < refsToCopy->size(); i++)
+      {
+        ColumnReference *newRef = new ColumnReference;
+        const ColumnReference *oldRef = (*refsToCopy)[i];
+        newRef->columnOrdinal = oldRef->columnOrdinal;
+        newRef->originalPrivs = oldRef->originalPrivs;
+        newRef->updatedPrivs = oldRef->updatedPrivs;
+        columnReferences->push_back(newRef);
+      }
+    }
+  }
+
   ColumnReference * findColumn (int32_t columnOrdinal)
   {
     if (columnReferences == NULL)
@@ -260,6 +294,8 @@ class PrivMgrMDAdmin : public PrivMgr
     inline void setMetadataLocation (const std::string metadataLocation)
       {metadataLocation_ = metadataLocation;};
 
+    PrivStatus getColumnReferences (ObjectReference *objectRef);
+
     bool getConstraintName(
       const int64_t referencedTableUID,
       const int64_t referencingTableUID, 
@@ -278,6 +314,8 @@ class PrivMgrMDAdmin : public PrivMgr
       const ObjectUsage &objectUsage,
       std::vector<ObjectReference *> &objectReferences );
 
+    PrivStatus getViewColUsages (ViewUsage &viewUsage);
+
     PrivStatus getViewsThatReferenceObject(
       const ObjectUsage &objectUsage, 
       std::vector<ViewUsage> &viewUsages);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/sqlcomp/PrivMgrPrivileges.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrPrivileges.cpp b/core/sql/sqlcomp/PrivMgrPrivileges.cpp
index 335f736..65a2354 100644
--- a/core/sql/sqlcomp/PrivMgrPrivileges.cpp
+++ b/core/sql/sqlcomp/PrivMgrPrivileges.cpp
@@ -36,6 +36,7 @@
 #include <cstdio>
 #include <algorithm>
 #include <iterator>
+#include <vector>
 #include "sqlcli.h"
 #include "ComSmallDefs.h"
 #include "ExExeUtilCli.h"
@@ -633,16 +634,19 @@ void PrivMgrPrivileges::getColRowsForGranteeOrdinal(
     ColumnPrivsMDRow &row = static_cast<ColumnPrivsMDRow &> (*columnRowList_[i]);
     ColPrivEntry colPrivGrant;
 
-    if (row.granteeID_ == granteeID && row.columnOrdinal_ == columnOrdinal)
+    if (row.columnOrdinal_ == columnOrdinal)
     {
-       ColumnPrivsMDRow *pRow = new ColumnPrivsMDRow();
-       *pRow = row;
-       rowList.push_back(pRow);
+      if (row.granteeID_ == granteeID || 
+          std::find(roleIDs.begin(), roleIDs.end(), row.granteeID_) != roleIDs.end()) 
+      {
+         ColumnPrivsMDRow *pRow = new ColumnPrivsMDRow();
+         *pRow = row;
+         rowList.push_back(pRow);
+      }
     }
   }
 }
 
-
 // *****************************************************************************
 // * Method: getPrivRowsForObject                                
 // *                                                       
@@ -1050,18 +1054,12 @@ PrivStatus PrivMgrPrivileges::grantColumnPrivileges(
   
   log (__FILE__, "Checking column privileges", -1);
 
-  // generate the list of column privileges granted to the object and store in 
-  // class (columnRowList_)
-  if (generateColumnRowList() == STATUS_ERROR)
-   return STATUS_ERROR;
-
   // get roleIDs for the grantor
   std::vector<int_32> roleIDs;
   privStatus = getRoleIDsForUserID(grantorID_,roleIDs);
   if (privStatus == STATUS_ERROR)
     return privStatus;
 
-
   // Grantor may have WGO from two sources, object-level grants on the object,
   // and column-level grants.  hasColumnWGO checks both
   if (!hasColumnWGO(colPrivsArrayIn,roleIDs,privStatus))
@@ -1076,6 +1074,14 @@ PrivStatus PrivMgrPrivileges::grantColumnPrivileges(
   // Grantor has authority to grant all privileges requested.  See if some of
   // the grants are already present. (may be adding WGO)
    
+  // Note, object level grants goes ahead and grants privileges on those object
+  // that the grantor has WGO.  Column level grants return an error if the
+  // grantor does not have WGO on all columns - this is different behavior and
+  // should confer with ANSI SQL standard for which is correct.
+
+  // Object level grants check for a circular dependency.  Should column level
+  // grants to the same? Or should the check be removed from object grants.
+
   // Get existing column grants from grantor to the specified grantee.
   std::vector<ColPrivEntry> grantedColPrivs;
   getColRowsForGranteeGrantor(columnRowList_,
@@ -1135,6 +1141,12 @@ PrivStatus PrivMgrPrivileges::grantColumnPrivileges(
     
   ColumnPrivsMDTable columnPrivsTable(columnTableName_,pDiags_);
 
+  // Get privileges on the object - needed for checks later
+  ObjectPrivsMDRow objRow;
+  privStatus = getGrantedPrivs(granteeID, objRow);
+ if (privStatus == STATUS_ERROR)
+    return privStatus;
+
   for (size_t i = 0; i < colPrivsToGrant.size(); i++)
   {
     ColPrivEntry &colPrivToGrant = colPrivsToGrant[i];
@@ -1193,23 +1205,44 @@ PrivStatus PrivMgrPrivileges::grantColumnPrivileges(
     if (skipOperation)
       continue;
       
-    // TBD:  need to get the list of referencing views that need to have this
-    // privilege progated.
-    //
-    // SQL ANSI general rules state 
-    // 
-    // - When granting INSERT, UPDATE, or DELETE object or column privilege to
-    //   a table that is referenced by one or more views, then the privilege  
-    //   should be propagated to any updatable views that reference the table. 
-    //   The grant request to the these views should be executed as though the 
-    //   current user is _SYSTEM.
-    //
-    // - If the table already has SELECT privilege and a new grant is 
-    //   performed that adds the WITH GRANT OPTION, then the WITH GRANT OPTION 
-    //   is to be propagated to referencing views.  The grant request should
-    //   be executed as though the current user is _SYSTEM.
+    // Create an ObjectUsage to propagate the privilege change to dependent
+    // objects
+    ObjectUsage objectUsage;
+    objectUsage.objectUID = objectUID_;
+    objectUsage.granteeID = granteeID;
+    objectUsage.objectName = objectName_;
+    objectUsage.objectType = objectType;
+
+    PrivMgrCoreDesc currentPrivs; // creates an empty descriptor
+    PrivMgrCoreDesc tempPrivs(objRow.privsBitmap_, objRow.grantableBitmap_);
+    objectUsage.originalPrivs.setTablePrivs(tempPrivs);
+    objectUsage.updatedPrivs.setTablePrivs(tempPrivs); 
+
+    // Create list of ColumnReferences
+    objectUsage.columnReferences = new std::vector<ColumnReference *>;
+    for (size_t i = 0; i < colPrivsToGrant.size(); i++)
+    {
+       ColPrivEntry &colPrivToGrant = colPrivsToGrant[i];
+       ColPrivEntry *grantedColPriv = findColumnEntry(grantedColPrivs, colPrivToGrant.getColumnOrdinal());
 
+       ColumnReference *adjustedCol = new ColumnReference;
+       adjustedCol->columnOrdinal = colPrivToGrant.getColumnOrdinal();
+
+       PrivMgrCoreDesc adjustedPrivs;
+       if (grantedColPriv)
+          adjustedPrivs = grantedColPriv->getPrivDesc();
+
+       adjustedCol->originalPrivs = adjustedPrivs;
+       adjustedPrivs.unionOfPrivs(colPrivToGrant.getPrivDesc());
+       adjustedCol->updatedPrivs = adjustedPrivs;
+       objectUsage.columnReferences->push_back(adjustedCol);
+    }
+
+    // Propagate the privilege change to dependent objects
+    if (updateDependentObjects(objectUsage, PrivCommand::GRANT_COLUMN) == STATUS_ERROR)
+      return STATUS_ERROR;
 
+    // Update the COLUMN_PRIVILEGES table with new privileges
     // Prepare for the insert or update request
     ColumnPrivsMDRow row;  
        
@@ -1492,67 +1525,8 @@ PrivStatus PrivMgrPrivileges::grantObjectPriv(
     objectUsage.originalPrivs = originalPrivs;
     objectUsage.updatedPrivs = privsToGrant;
   
-    // get list of all objects that need to change, the table object and 
-    // views
-    std::vector<ObjectUsage *> listOfObjects;
-    PrivCommand command = PrivCommand::GRANT_OBJECT;
-    retcode = getAffectedObjects(objectUsage, command, listOfObjects);
-    if (retcode == STATUS_ERROR)
-    {
-      deleteListOfAffectedObjects(listOfObjects);
-      return retcode;
-    }
-
-    traceMsg = "updating all affected objects, number of objects is ";
-    traceMsg += to_string((long long int)listOfObjects.size());
-    log (__FILE__, traceMsg, -1);
-
-    // update the OBJECT_PRIVILEGES row for each effected object
-    for (size_t i = 0; i < listOfObjects.size(); i++)
-    {
-      ObjectUsage *pObjectUsage = listOfObjects[i];
-
-      pObjectUsage->describe(traceMsg);
-      log (__FILE__, traceMsg, i);
-
-      // Determine the grantor:
-      // SQL ANSI general rules state 
-      // 
-      // - When granting INSERT, UPDATE, or DELETE object or column privilege to
-      //   a table that is referenced by one or more views, then the privilege  
-      //   should be propagated to any updatable views that reference the table. 
-      //   The grant request to the these views should be executed as though the 
-      //   current user is _SYSTEM.
-      //
-      // - If the table already has SELECT privilege and a new grant is 
-      //   performed that adds the WITH GRANT OPTION, then the WITH GRANT OPTION 
-      //   is to be propagated to referencing views.  The grant request should
-      //   be executed as though the current user is _SYSTEM.
-      //
-      //  The listOfObjects contains referencing views that meet the above 
-      //  criteria.
-      int32_t theGrantor = (pObjectUsage->grantorIsSystem) ? SYSTEM_USER : grantorID_;
-      int32_t theGrantee = pObjectUsage->granteeID;
-      int64_t theUID = pObjectUsage->objectUID;
-      PrivMgrCoreDesc thePrivs = pObjectUsage->updatedPrivs.getTablePrivs();
-  
-      sprintf(buf, "where grantee_id = %d and grantor_id =  %d and object_uid = %ld",
-              theGrantee, theGrantor, theUID);
-      std::string whereClause (buf);
-
-      sprintf(buf, "set privileges_bitmap  = %ld, grantable_bitmap =  %ld",
-              thePrivs.getPrivBitmap().to_ulong(),
-              thePrivs.getWgoBitmap().to_ulong());
-      std::string setClause (buf);
-      // update the row
-      retcode = objectPrivsTable.updateWhere(setClause, whereClause);
-      if (retcode == STATUS_ERROR)
-      {
-        deleteListOfAffectedObjects(listOfObjects);
-        return retcode;
-      }
-    }
-    deleteListOfAffectedObjects(listOfObjects);
+    if (updateDependentObjects(objectUsage, PrivCommand::GRANT_OBJECT) == STATUS_ERROR)
+      return STATUS_ERROR;
   }
   else
   {
@@ -1851,7 +1825,7 @@ PrivStatus PrivMgrPrivileges::dealWithConstraints(
 
     // get the summarized original and current privs for the referencing table 
     // current privs contains any adjustments due to the privilege change
-    retcode = summarizeCurrentAndOriginalPrivs(pObjectRef->objectUID,
+    retcode = summarizeCurrentAndOriginalPrivs(objectUsage.objectUID,
                                                pObjectRef->objectOwner,
                                                roleIDs,
                                                listOfAffectedObjects,
@@ -1868,7 +1842,7 @@ PrivStatus PrivMgrPrivileges::dealWithConstraints(
       // no longer have REFERENCES privilege on the table, 
       // see if privileges are granted on all required columns
       std::vector<ColumnReference *> summarizedColRefs;
-      summarizeColPrivs(*pObjectRef, roleIDs, listOfAffectedObjects, summarizedColRefs);
+      summarizeColPrivs(*pObjectRef, pObjectRef->objectOwner, roleIDs, listOfAffectedObjects, summarizedColRefs);
 
       // check summarized privileges to see if still have priv through other privs
       std::vector<ColumnReference *> neededColRefs = *pObjectRef->columnReferences;
@@ -2066,7 +2040,7 @@ PrivStatus PrivMgrPrivileges::dealWithViews(
     // this method recreates privileges for the view based on the original
     // and the current.  Updated descriptors are stored in the viewUsage
     // structure.
-    retcode = gatherViewPrivileges(viewUsage, listOfAffectedObjects);
+    retcode = gatherViewPrivileges(viewUsage, command, listOfAffectedObjects);
     traceMsg = "gathered view privs: retcode is ";
     traceMsg += privStatusEnumToLit(retcode);
     log (__FILE__, traceMsg, -1);
@@ -2112,6 +2086,80 @@ PrivStatus PrivMgrPrivileges::dealWithViews(
 }
 
 // ----------------------------------------------------------------------------
+// method: gatherViewColUsages
+//
+// This method gathers the view-col <=> referenced-col usages and creates a
+// list of ComViewColUsage's for the referenced object. Each ComViewColUsage 
+// is identified the view column number, and the related UID and column number 
+// of the referenced object.
+//
+// parameters:
+//   objectRef - description of the referenced object 
+//   viewUsage - description of the view
+//   viewColUsages - list of view column, referenced column usages
+//
+// Returns: PrivStatus                                               
+//                                                                    
+// STATUS_GOOD: Operation successful
+//           *: Unable to gather usages, see diags.     
+//                                                                 
+// ----------------------------------------------------------------------------
+PrivStatus PrivMgrPrivileges::gatherViewColUsages(
+  ObjectReference *objectRef,
+  ViewUsage &viewUsage,
+  std::vector<ComViewColUsage> &viewColUsages)
+{
+  std::string traceMsg;
+  PrivStatus retcode;
+
+  PrivMgrMDAdmin admin(trafMetadataLocation_, metadataLocation_, pDiags_);
+
+  // Get columns for referenced object if they are  not already present
+  if (objectRef->columnReferences == NULL)
+  {
+    retcode = admin.getColumnReferences(objectRef);
+    if (objectRef->columnReferences)
+    {
+      traceMsg += "getting column references: number references found ";
+      traceMsg += to_string((long long int)objectRef->columnReferences->size());
+    }
+    traceMsg += ", retcode is ";
+    traceMsg += privStatusEnumToLit(retcode);
+    log (__FILE__, traceMsg, -1);
+    if (retcode == STATUS_ERROR)
+      return retcode;
+  }
+
+  // Extract view <=> object column relationship from the TEXT table 
+  // and add it to the viewUsage
+  if (viewUsage.viewColUsagesStr.empty())
+  {
+    retcode = admin.getViewColUsages(viewUsage);
+    traceMsg += "getting view column usages";
+    traceMsg += ", retcode is ";
+    traceMsg += privStatusEnumToLit(retcode);
+    log (__FILE__, traceMsg, -1);
+    if (retcode == STATUS_ERROR)
+      return retcode;
+  }
+
+  // Setup the view column to referenced column relationship
+  char * beginStr  = (char *)viewUsage.viewColUsagesStr.c_str();
+  char * endStr = strchr(beginStr, ';');
+  while (endStr != NULL)
+  {
+    ComViewColUsage colUsage;
+    std::string currentUsage(beginStr, endStr - beginStr + 1);
+    colUsage.unpackUsage (currentUsage.c_str());
+    viewColUsages.push_back(colUsage);
+    beginStr = endStr+1;
+    endStr = strchr(beginStr, ';');
+  }
+ 
+  return STATUS_GOOD;
+}
+
+// ----------------------------------------------------------------------------
 // method: gatherViewPrivileges
 //
 // This method gathers privileges for the view both the original and current
@@ -2128,6 +2176,7 @@ PrivStatus PrivMgrPrivileges::dealWithViews(
 // ----------------------------------------------------------------------------
 PrivStatus PrivMgrPrivileges::gatherViewPrivileges(
   ViewUsage &viewUsage,
+  const PrivCommand command,
   const std::vector<ObjectUsage *> listOfAffectedObjects)
 {
   PrivStatus retcode = STATUS_GOOD;
@@ -2154,28 +2203,24 @@ PrivStatus PrivMgrPrivileges::gatherViewPrivileges(
   if (retcode == STATUS_ERROR)
     return retcode;
 
-
   // For each referenced object, summarize the original and current
   // privileges
   PrivMgrDesc originalPrivs;
   PrivMgrDesc currentPrivs;
   int32_t lastObjectOwnerID = 0;
+
   std::vector<int32_t> roleIDs;
+  retcode = getRoleIDsForUserID(viewUsage.viewOwner,roleIDs);
+  if (retcode == STATUS_ERROR)
+    return retcode;
  
+  // First gather privileges on the object
   for (size_t i = 0; i < objectList.size(); i++)
   {
     ObjectReference *pObjectRef = objectList[i];
-
     pObjectRef->describe(traceMsg);
     log (__FILE__, traceMsg, i);
 
-    if (lastObjectOwnerID != pObjectRef->objectOwner)
-    {
-      roleIDs.clear();
-      retcode = getRoleIDsForUserID(pObjectRef->objectOwner,roleIDs);
-      if (retcode == STATUS_ERROR)
-        return retcode;
-    }
     // get the summarized original and current privs for the 
     // referenced object that have been granted to the view owner
     // listOfAffectedObjects contain the privilege adjustments needed
@@ -2189,29 +2234,139 @@ PrivStatus PrivMgrPrivileges::gatherViewPrivileges(
     if (retcode != STATUS_GOOD)
       return retcode;
 
-    // If user no longer has select privilege on referenced object
-    // returns an error
-    // When cascade is supported, then referenced objects will be removed
-    //if (command == PrivCommand::REVOKE_OBJECT_RESTRICT )
-    //{
+    // If the referenced object is a sequence generator, then the grantee
+    // must still have the USAGE_PRIV.  The USAGE_PRIV is not a column
+    // level privilege so no column level check is necessary.
+    if (pObjectRef->objectType == COM_SEQUENCE_GENERATOR_OBJECT)
+    {
       PrivMgrCoreDesc thePrivs = currentPrivs.getTablePrivs();
-      if (!thePrivs.getPriv(SELECT_PRIV))
+      if (!thePrivs.getPriv(USAGE_PRIV))
       {
          *pDiags_ << DgSqlCode (-CAT_DEPENDENT_OBJECTS_EXIST)
                   << DgString0 (viewUsage.viewName.c_str());
          return STATUS_ERROR;
       }
-    //}
+    }
 
-    // add the returned privilege to the summarized privileges
+    // "and" the returned privilege to the summarized privileges
     // for all objects
     summarizedOriginalPrivs.intersectionOfPrivs(originalPrivs);
     summarizedCurrentPrivs.intersectionOfPrivs(currentPrivs);
 
+    // reset to prepare for next object
     originalPrivs.resetTablePrivs();
     currentPrivs.resetTablePrivs();
   }
 
+  // If the object has no granted column level privileges, skip column checks
+  if (columnRowList_.empty())
+  {
+    if (!summarizedCurrentPrivs.getTablePrivs().getPriv(SELECT_PRIV))
+    {
+      *pDiags_ << DgSqlCode (-CAT_DEPENDENT_OBJECTS_EXIST)
+               << DgString0 (viewUsage.viewName.c_str());
+      return STATUS_ERROR;
+    }
+    return STATUS_GOOD;
+  }
+  
+  // If view has all grantable column privileges already, return
+  bool checkCols = false;
+  PrivMgrCoreDesc thePrivs = summarizedCurrentPrivs.getTablePrivs();
+  for (size_t i = FIRST_DML_COL_PRIV; i <= LAST_DML_COL_PRIV; i++ )
+  {
+    PrivType privType = PrivType(i);
+    if (thePrivs.getPriv(privType) && thePrivs.getWgo(privType))
+      continue;
+    checkCols = true;
+    break;
+  }
+
+  if (!checkCols)
+    return STATUS_GOOD;
+
+  // Turn on bits to prepare for intersecting with object privileges
+  originalPrivs.setAllTableGrantPrivileges(setWGOtrue);
+  currentPrivs.setAllTableGrantPrivileges(setWGOtrue);
+
+  std::vector<ColumnReference *> summarizedColRefs;
+
+  // Gather column privileges on all objects referencing the view.
+  //   for grants, a view might gain privs 
+  //   for revokes, a view might lose privs
+  // For example:
+  //   as user1:
+  //     create table sch1.t1 (c1 int, c2 int, ....);
+  //     grant select on sch1.t1 to user2;
+  //     grant insert (c1) on sch1.t1 to user2
+  //   as user2:
+  //     create view sch2.v1 as select c1 from sch1.t1;
+  //   view sch2.v1 gains the insert privilege since all columns that 
+  //     sch2.v1 references have granted user2 the insert privilege.
+  for (size_t i = 0; i < objectList.size(); i++)
+  {
+    ObjectReference *pObjectRef = objectList[i];
+
+    // gather the view-col <=> referenced-col usages
+    std::vector <ComViewColUsage> viewColUsages;
+    retcode = gatherViewColUsages(pObjectRef, viewUsage, viewColUsages);
+    if (retcode == STATUS_ERROR)
+      return retcode;
+
+    // gather the updated summarized column privileges on the referenced object
+    summarizeColPrivs(*pObjectRef, 
+                      viewUsage.viewOwner, 
+                      roleIDs, 
+                      listOfAffectedObjects, 
+                      summarizedColRefs);
+
+    // For each view column, get the corresponding referenced column priv
+    for (size_t j = 0; j < viewColUsages.size(); j++)
+    {
+      ComViewColUsage colUsage = viewColUsages[j];
+
+      // See if the referenced object contains the associated view column
+      if (colUsage.getRefdUID() != pObjectRef->objectUID) 
+        continue;
+
+      // Get the referenced column, if NULL then something is wrong
+      ColumnReference *neededColRef = pObjectRef->find(colUsage.getRefdColNumber());
+      if (neededColRef == NULL)
+      {
+         PRIVMGR_INTERNAL_ERROR("View column to referenced column relationship wrong");
+         return STATUS_ERROR;
+      }
+
+      // Find and update the current bitmaps for column
+      for (size_t k = 0; k < summarizedColRefs.size(); k++)
+      {
+        ColumnReference *existingRef = summarizedColRefs[k];
+        if (existingRef->columnOrdinal == neededColRef->columnOrdinal)
+        {
+          originalPrivs.intersectionOfPrivs(existingRef->originalPrivs);
+          currentPrivs.intersectionOfPrivs(existingRef->updatedPrivs);
+          break;
+        }
+      }
+    }
+  }
+
+  // Union or "or" the returned privileges to the summarized privileges
+  // for all columns. The privilege is set in currentPrivs only if all
+  // columns in the view have the privilege.
+  summarizedOriginalPrivs.unionOfPrivs(originalPrivs);
+  summarizedCurrentPrivs.unionOfPrivs(currentPrivs);
+
+  // If user no longer has select privilege on referenced object
+  // returns an error
+  // When cascade is supported, then referenced objects will be removed
+  if (!summarizedCurrentPrivs.getTablePrivs().getPriv(SELECT_PRIV))
+  {
+    *pDiags_ << DgSqlCode (-CAT_DEPENDENT_OBJECTS_EXIST)
+             << DgString0 (viewUsage.viewName.c_str());
+    return STATUS_ERROR;
+  }
+
   // Update view usage with summarized privileges
   viewUsage.originalPrivs = summarizedOriginalPrivs;
   viewUsage.updatedPrivs = summarizedCurrentPrivs;
@@ -2273,23 +2428,54 @@ PrivStatus PrivMgrPrivileges::generateColumnRowList()
 // ****************************************************************************
 PrivStatus PrivMgrPrivileges::generateObjectRowList()
 {
+  std::vector<PrivMgrMDRow *> objectRows;
+  PrivStatus privStatus = getObjectRowList(objectUID_, objectRows);
+  if (privStatus == STATUS_ERROR)
+    return privStatus;
+  objectRowList_ = objectRows;
+  return STATUS_GOOD;
+}
+
+// ****************************************************************************
+// method: getObjectRowList
+//
+// generate the list of privileges granted to the passed in objectUID and 
+// returns in the objectRows parameter
+//
+// The list is ordered by grantor/grantee
+//
+// Returns:
+//   STATUS_GOOD     - list of rows was generated
+//   STATUS_NOTFOUND - in most cases, there should be at least one row in the
+//                     OBJECT_PRIVILEGES table.  But there is at least one case
+//                     where this is not true - trying to get privilege info
+//                     for indexes when using the table (index_table) syntax.
+//   STATUS_ERROR    - the diags area is populated with any errors
+// ****************************************************************************
+PrivStatus PrivMgrPrivileges::getObjectRowList(
+   const int64_t objectUID, 
+   std::vector<PrivMgrMDRow *> &objectRows)
+{ 
   std::string whereClause ("where object_uid = ");
-  whereClause += UIDToString(objectUID_);
+  whereClause += UIDToString(objectUID);
   std::string orderByClause(" order by grantor_id, grantee_id ");
 
   ObjectPrivsMDTable objectPrivsTable(objectTableName_,pDiags_);
   PrivStatus privStatus = 
-    objectPrivsTable.selectWhere(whereClause, orderByClause, objectRowList_);
+    objectPrivsTable.selectWhere(whereClause, orderByClause, objectRows);
+  if (privStatus == STATUS_ERROR)
+    return privStatus;
+
   std::string traceMsg ("getting object privileges, number privleges is ");
-  traceMsg += to_string((long long int)objectRowList_.size());
+  traceMsg += to_string((long long int)objectRows.size());
   log (__FILE__, traceMsg, -1);
-  for (size_t i = 0; i < objectRowList_.size(); i++)
+  for (size_t i = 0; i < objectRows.size(); i++)
   {
-    ObjectPrivsMDRow privRow = static_cast<ObjectPrivsMDRow &> (*objectRowList_[i]);
+    ObjectPrivsMDRow privRow = static_cast<ObjectPrivsMDRow &> (*objectRows[i]);
     privRow.describeRow(traceMsg);
     log (__FILE__, traceMsg, i);
   }
-  return privStatus;
+  return STATUS_GOOD;
 }
 
 
@@ -2322,13 +2508,13 @@ PrivStatus PrivMgrPrivileges::getAffectedObjects(
   pUsage->objectType = objectUsage.objectType;
   pUsage->originalPrivs = objectUsage.originalPrivs;
   pUsage->updatedPrivs = objectUsage.updatedPrivs;
-  pUsage->columnReferences = objectUsage.columnReferences;
+  pUsage->copyColumnReferences(objectUsage.columnReferences);
 
   listOfAffectedObjects.push_back(pUsage); 
 
 
   // Find list of affected constraints
-  if (command != PrivCommand::GRANT_OBJECT)  
+  if (command != PrivCommand::GRANT_OBJECT && command != PrivCommand::GRANT_COLUMN)  
   {
     // TBD optimization: if no "references" privilege has been revoked, skip
     retcode = dealWithConstraints (objectUsage, listOfAffectedObjects);
@@ -2661,16 +2847,8 @@ PrivStatus PrivMgrPrivileges::revokeColumnPrivileges(
      objectUsage.updatedPrivs.setTablePrivs(coreDesc); 
    }
    
-   std::vector<ObjectUsage *> listOfObjects;
-   privStatus = getAffectedObjects(objectUsage,
-                                PrivCommand::REVOKE_OBJECT_RESTRICT,
-                                listOfObjects);
-   if (privStatus == STATUS_ERROR)
-   {
-     deleteListOfAffectedObjects(listOfObjects);
-     return privStatus;
-   }
-
+   if ( updateDependentObjects(objectUsage, PrivCommand::REVOKE_COLUMN_RESTRICT) == STATUS_ERROR)
+     return STATUS_ERROR;
    
    // At this point we have an array of privsToRevoke with column ordinal and 
    // priv bitmap.
@@ -3005,90 +3183,16 @@ PrivStatus PrivMgrPrivileges::revokeObjectPriv (const ComObjectType objectType,
   objectUsage.grantorIsSystem = false;
   objectUsage.objectName = row.objectName_;
   objectUsage.objectType = row.objectType_;
+  objectUsage.columnReferences = NULL;
 
   PrivMgrDesc originalPrivs (row.granteeID_);
   originalPrivs.setTablePrivs(savedOriginalPrivs);
   objectUsage.originalPrivs = originalPrivs;
   objectUsage.updatedPrivs = privsToRevoke;
 
-  // get list of dependent objects that need to change 
-  std::vector<ObjectUsage *> listOfObjects;
-  retcode = getAffectedObjects(objectUsage, 
-                               PrivCommand::REVOKE_OBJECT_RESTRICT, 
-                               listOfObjects);
-  if (retcode == STATUS_ERROR)
-  {
-    deleteListOfAffectedObjects(listOfObjects);
-    return retcode;
-  }
-
-  char buf[1000];
-  ObjectPrivsMDTable objectPrivsTable (objectTableName_, pDiags_);
-  ColumnPrivsMDTable columnPrivsTable(columnTableName_,pDiags_);
-
-  // update the OBJECT_PRIVILEGES row for each effected object
-  for (size_t i = 0; i < listOfObjects.size(); i++)
-  {
-    ObjectUsage *pObjectUsage = listOfObjects[i];
-    PrivMgrCoreDesc thePrivs = pObjectUsage->updatedPrivs.getTablePrivs();
-
-    // Determine the grantor:
-    // SQL ANSI general rules state 
-    // 
-    // - When revoking INSERT, UPDATE, or DELETE object or column privilege from
-    //   a table that is referenced by one or more views, then the privilege  
-    //   should be revoked on any updatable views that reference the table. 
-    //   The revoke request to the these views should be executed as though the 
-    //   current user is _SYSTEM.
-    //
-    // - If the revoke is performed that removes the WITH GRANT OPTION, then 
-    //   the WITH GRANT OPTION is to be removed frome referencing views.  The 
-    //   revoke request should be executed as though the current user is _SYSTEM.
-    //
-    //  The listOfObjects contains referencing views that meet the above 
-    //  criteria.
-    int32_t theGrantor = (pObjectUsage->grantorIsSystem) ? SYSTEM_USER : grantorID_;
-    int32_t theGrantee = pObjectUsage->granteeID;
-    int64_t theUID = pObjectUsage->objectUID;
-
-    sprintf(buf, "where grantee_id = %d and grantor_id =  %d and object_uid = %ld",
-            theGrantee, theGrantor, theUID);
-    std::string whereClause (buf);
-
-    if (thePrivs.isNull())
-    {
-      pObjectUsage->describe(traceMsg);
-      traceMsg.insert (0, "deleted object usage ");
-
-      // delete the row
-      retcode = objectPrivsTable.deleteWhere(whereClause);
-      if (retcode == STATUS_ERROR)
-      {
-        deleteListOfAffectedObjects(listOfObjects);
-        return retcode;
-      }
-    }
-    else
-    {
-      sprintf(buf, "set privileges_bitmap  = %ld, grantable_bitmap =  %ld",
-              thePrivs.getPrivBitmap().to_ulong(),
-              thePrivs.getWgoBitmap().to_ulong());
-      std::string setClause (buf);
+  if (updateDependentObjects(objectUsage, PrivCommand::REVOKE_OBJECT_RESTRICT) == STATUS_ERROR)
+    return STATUS_ERROR;
 
-      pObjectUsage->describe(traceMsg);
-      traceMsg.insert (0, "updated object usage ");
-      // update the row
-      retcode = objectPrivsTable.updateWhere(setClause, whereClause);
-      if (retcode == STATUS_ERROR)
-      {
-        deleteListOfAffectedObjects(listOfObjects);
-        return retcode;
-      }
-    }
-  }
-  
-  deleteListOfAffectedObjects(listOfObjects);
-  
   // Go rebuild the privilege tree to see if it is broken
   // If it is broken, return an error
   if (checkRevokeRestrict (row, objectRowList_))
@@ -3140,6 +3244,8 @@ PrivStatus PrivMgrPrivileges::revokeObjectPriv ()
   // delete all the rows for this object
   ObjectPrivsMDTable objectPrivsTable (objectTableName_, pDiags_);
   retcode = objectPrivsTable.deleteWhere(whereClause);
+  ColumnPrivsMDTable columnPrivsTable (objectTableName_, pDiags_);
+  retcode = columnPrivsTable.deleteWhere(whereClause);
 
   return retcode;
 }
@@ -4132,14 +4238,23 @@ PrivStatus PrivMgrPrivileges::getRowsForGrantee(
   }
 #endif
 
-  // create the list of row pointers from the cached list
+  // create the list of row pointers 
   std::vector<int32_t> authIDs = roleIDs;
   authIDs.push_back(granteeID);
   authIDs.push_back(PUBLIC_USER);
   std::vector<int32_t>::iterator it;
   std::vector<PrivMgrMDRow *> privRowList;
   if (isObjectTable)
-    privRowList = objectRowList_;
+  {
+    if (objectUID == objectUID_)
+      privRowList = objectRowList_;
+    else
+    {
+      retcode = getObjectRowList(objectUID, privRowList);
+      if (retcode == STATUS_ERROR)
+        return retcode;
+    }
+  }
   else
     privRowList = columnRowList_;
 
@@ -4187,6 +4302,7 @@ PrivStatus PrivMgrPrivileges::getRowsForGrantee(
 // ****************************************************************************
 void PrivMgrPrivileges::summarizeColPrivs(
   const ObjectReference &objReference,
+  const int32_t granteeID,
   const std::vector<int32_t> &roleIDs,
   const std::vector<ObjectUsage *> &listOfAffectedObjects,
   std::vector<ColumnReference *> &summarizedColRefs)
@@ -4196,7 +4312,7 @@ void PrivMgrPrivileges::summarizeColPrivs(
   traceMsg.insert (0, "summarizing column privileges ");
   log (__FILE__, traceMsg, -1);
 
-  // objReference.columnReferences is the list of columns for RI constraints
+  // objReference.columnReferences is the list of columns 
   // referencing the referenced table
   std::vector<ColumnReference *> *colRefs = objReference.columnReferences;
   for (size_t i = 0; i < colRefs->size(); i++)
@@ -4208,7 +4324,7 @@ void PrivMgrPrivileges::summarizeColPrivs(
     // get COLUMN_PRIVILEGES rows where the grantee for the column has received 
     // privileges -  the row list is in memory so this does not require I/O
     std::vector<PrivMgrMDRow *> rowList;
-    getColRowsForGranteeOrdinal(objReference.objectOwner,
+    getColRowsForGranteeOrdinal(granteeID,
                                 colRef->columnOrdinal,
                                 roleIDs,
                                 rowList);
@@ -4217,34 +4333,49 @@ void PrivMgrPrivileges::summarizeColPrivs(
     // We do a union operation to capture privileges from all grantors
     ColumnReference *summarized = new ColumnReference; 
     summarized->columnOrdinal = colRef->columnOrdinal;
-    for (int32_t i = 0; i < rowList.size();++i)
-    {
-      ColumnPrivsMDRow &row = static_cast<ColumnPrivsMDRow &> (*rowList[i]);
-      PrivMgrCoreDesc originalPrivs(row.privsBitmap_, row.grantableBitmap_);
 
-      ColumnReference ref;
-      ref.columnOrdinal = row.columnOrdinal_;
-      ref.originalPrivs = originalPrivs;
-      ref.updatedPrivs = originalPrivs;
-      
-      // Update if privileges have been changed by request
-      for (size_t j = 0; j < listOfAffectedObjects.size(); j++)
+    if (rowList.size() > 0)
+    {
+      for (int32_t j = 0; j < rowList.size();++j)
       {
-        ObjectUsage *currentObj = listOfAffectedObjects[j];
-        if (currentObj->objectUID == row.objectUID_ &&
-            grantorID_ == row.grantorID_ &&
-            objReference.objectOwner == row.granteeID_ )
+        ColumnPrivsMDRow &row = static_cast<ColumnPrivsMDRow &> (*rowList[j]);
+        PrivMgrCoreDesc originalPrivs(row.privsBitmap_, row.grantableBitmap_);
+        PrivMgrCoreDesc original = originalPrivs;
+        PrivMgrCoreDesc updated = originalPrivs;
+
+        // Update if privileges have been changed by request
+        for (size_t k = 0; k < listOfAffectedObjects.size(); k++)
         {
-          ColumnReference *changedRef = currentObj->findColumn(row.columnOrdinal_);
-          if (changedRef)
-            ref.updatedPrivs = changedRef->updatedPrivs;
+          ObjectUsage *currentObj = listOfAffectedObjects[k];
+          if (currentObj->objectUID == row.objectUID_ &&
+              grantorID_ == row.grantorID_ &&
+              currentObj->granteeID == row.granteeID_ )
+          {
+            ColumnReference *changedRef = currentObj->findColumn(row.columnOrdinal_);
+            if (changedRef)
+              updated = changedRef->updatedPrivs;
+          }
         }
+        summarized->originalPrivs.unionOfPrivs(original);
+        summarized->updatedPrivs.unionOfPrivs(updated);
       }
-      
-      summarized->originalPrivs.unionOfPrivs(ref.originalPrivs);
-      summarized->updatedPrivs.unionOfPrivs(ref.updatedPrivs);
     }
-
+    else
+    {
+      // For grants, this may be the first column privs added, adjust to
+      // include new privs
+      PrivMgrCoreDesc updated;
+      for (size_t k = 0; k < listOfAffectedObjects.size(); k++)
+      {
+        ObjectUsage *currentObj = listOfAffectedObjects[k];
+        ColumnReference *changedRef = currentObj->findColumn(colRef->columnOrdinal);
+        if (changedRef)
+          updated = changedRef->updatedPrivs;
+      }
+      // There are no originalPrivs
+      summarized->updatedPrivs.unionOfPrivs(updated);
+    }
+      
     // Add column ref to the list
     summarizedColRefs.push_back(summarized);
   }
@@ -4309,6 +4440,114 @@ PrivStatus PrivMgrPrivileges::summarizeCurrentAndOriginalPrivs(
   return STATUS_GOOD;
 }
 
+// *****************************************************************************
+// * Method: updateDependentObjects
+// *                                                       
+// * This code gets the list of dependent objects that have had their privileges
+// * changed because of the ongoing grant/revoke request.  It then updates
+// * the object privileges table to change any dependencies.
+// *
+// * SQL ANSI general rules state 
+// *
+// * - When granting INSERT, UPDATE, or DELETE object or column privilege to
+// *   a table that is referenced by one or more views, then the privilege  
+// *   should be propagated to any updatable views that reference the table. 
+// *   The grant request to the these views should be executed as though the 
+// *   current user is _SYSTEM.
+// *
+// * - If the table already has SELECT privilege and a new grant is 
+// *   performed that adds the WITH GRANT OPTION, then the WITH GRANT OPTION 
+// *   is to be propagated to referencing views.  The grant request should
+// *   be executed as though the current user is _SYSTEM.
+// *
+// * - When revoking INSERT, UPDATE, or DELETE object or column privilege from
+// *   a table that is referenced by one or more views, then the privilege  
+// *   should be revoked on any updatable views that reference the table. 
+// *   The revoke request to the these views should be executed as though the 
+// *   current user is _SYSTEM.
+// *
+// * - If the revoke is performed that removes the WITH GRANT OPTION, then 
+// *   the WITH GRANT OPTION is to be removed frome referencing views.  The 
+// *   revoke request should be executed as though the current user is _SYSTEM.
+// *
+// *****************************************************************************
+PrivStatus PrivMgrPrivileges::updateDependentObjects(
+  const ObjectUsage &objectUsage,
+  const PrivCommand command)
+{
+  std::string traceMsg;
+
+  // get list of any objects that need to change because of the grant/revoke
+  std::vector<ObjectUsage *> listOfObjects;
+  PrivStatus privStatus = getAffectedObjects(objectUsage, command, listOfObjects);
+  if (privStatus == STATUS_ERROR)
+  {
+    deleteListOfAffectedObjects(listOfObjects);
+    return privStatus;
+  }
+
+  traceMsg = "list of dependent objects, number of objects is ";
+  traceMsg += to_string((long long int)listOfObjects.size());
+  log (__FILE__, traceMsg, -1);
+
+  char buf [1000];
+  ObjectPrivsMDTable objectPrivsTable (objectTableName_, pDiags_);
+
+  // update the OBJECT_PRIVILEGES row for each effected object
+  // Starting index is 1 for column requests
+  size_t i = 0;
+  if (command == PrivCommand::GRANT_COLUMN ||
+      command == PrivCommand::REVOKE_COLUMN_RESTRICT )
+    i = 1;
+  for (i; i < listOfObjects.size(); i++)
+  {
+    ObjectUsage *pObjectUsage = listOfObjects[i];
+
+    pObjectUsage->describe(traceMsg);
+    log (__FILE__, traceMsg, i);
+
+    // Determine row contents
+    int32_t theGrantor = (pObjectUsage->grantorIsSystem) ? SYSTEM_USER : grantorID_;
+    int32_t theGrantee = pObjectUsage->granteeID;
+    int64_t theUID = pObjectUsage->objectUID;
+    PrivMgrCoreDesc thePrivs = pObjectUsage->updatedPrivs.getTablePrivs();
+    sprintf(buf, "where grantee_id = %d and grantor_id =  %d and object_uid = %ld",
+            theGrantee, theGrantor, theUID);
+    std::string whereClause (buf);
+
+    if (thePrivs.isNull())
+    {
+      pObjectUsage->describe(traceMsg);
+      traceMsg.insert (0, "deleted object usage ");
+
+      // delete the row
+      privStatus = objectPrivsTable.deleteWhere(whereClause);
+      if (privStatus == STATUS_ERROR)
+      {
+        deleteListOfAffectedObjects(listOfObjects);
+        return privStatus;
+      }
+    }
+    else
+    {
+      sprintf(buf, "set privileges_bitmap  = %ld, grantable_bitmap =  %ld",
+              thePrivs.getPrivBitmap().to_ulong(),
+              thePrivs.getWgoBitmap().to_ulong());
+      std::string setClause (buf);
+      privStatus = objectPrivsTable.updateWhere(setClause, whereClause);
+
+      if (privStatus == STATUS_ERROR)
+      {
+        deleteListOfAffectedObjects(listOfObjects);
+        return privStatus;
+      }
+    }
+  }
+  deleteListOfAffectedObjects(listOfObjects);
+  return STATUS_GOOD;
+}
+
+
 
 // *****************************************************************************
 // * Method: isAuthIDGrantedPrivs                                
@@ -4348,8 +4587,9 @@ bool PrivMgrPrivileges::isAuthIDGrantedPrivs(const int32_t authID)
 
    if ((privStatus == STATUS_GOOD || privStatus == STATUS_WARNING) &&
         rowCount > 0)
-      return true;
+     return true;
       
+   // TBD - check for granted column level privs
    pDiags_->rewind(diagsMark);
    return false;
 
@@ -5307,13 +5547,17 @@ std::vector<ColPrivSpec> &colPrivsArray =
       // See if the grantor has been granted WGO at column-level for priv.  
       for (size_t j = 0; j < colRowList.size(); j++)
       {
-         ColumnPrivsMDRow &columnRow = static_cast<ColumnPrivsMDRow &> (*colRowList[i]);
-         if (columnRow.grantableBitmap_.test(colPrivSpec.privType))
-         {
-            colPrivSpec.grantorHasWGO = true;
-            break;
+          ColumnPrivsMDRow &columnRow = static_cast<ColumnPrivsMDRow &> (*colRowList[i]);
+          if (columnRow.columnOrdinal_ == colPrivSpec.columnOrdinal)
+          {
+             if (columnRow.grantableBitmap_.test(colPrivSpec.privType))
+             {
+                colPrivSpec.grantorHasWGO = true;
+                break;
+             }
          }
       }
+
       // If the grantor does not have an object-level or column-level WGO
       // for one of the privs to grant, return an error.
       if (!colPrivSpec.grantorHasWGO)
@@ -5329,7 +5573,6 @@ std::vector<ColPrivSpec> &colPrivsArray =
 //*************************** End of hasColumnWGO ******************************
 
 
-
    
 // *****************************************************************************
 // *                                                                           *

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a71d832f/core/sql/sqlcomp/PrivMgrPrivileges.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrPrivileges.h b/core/sql/sqlcomp/PrivMgrPrivileges.h
index c62c0e4..73590fc 100644
--- a/core/sql/sqlcomp/PrivMgrPrivileges.h
+++ b/core/sql/sqlcomp/PrivMgrPrivileges.h
@@ -29,6 +29,7 @@
 #include "PrivMgrMDTable.h"
 #include "PrivMgrDesc.h"
 #include "ComSmallDefs.h"
+#include "ComViewColUsage.h"
 
 #include <string>
 #include <bitset>
@@ -340,8 +341,14 @@ private:
     ObjectUsage &constraintUsage,
     const std::vector<ObjectUsage *> listOfAffectedObjects);
 
+  PrivStatus gatherViewColUsages(
+    ObjectReference *objectRef,
+    ViewUsage &viewUsage,
+    std::vector<ComViewColUsage> &viewColUsages);
+
   PrivStatus gatherViewPrivileges(
     ViewUsage &viewUsage,
+    const PrivCommand command,
     const std::vector<ObjectUsage *> listOfAffectedObjects);
 
   PrivStatus generateColumnRowList();
@@ -352,6 +359,10 @@ private:
     const PrivCommand command,
     std::vector<ObjectUsage *> &listOfAffectedObjects);
 
+  PrivStatus getObjectRowList(
+    const int64_t objectUID, 
+    std::vector<PrivMgrMDRow *> &objectRows);
+
   void getColRowsForGranteeOrdinal(
     const int32_t granteeID,
     const int32_t columnOrdinal,
@@ -410,6 +421,7 @@ private:
 
   void summarizeColPrivs(
     const ObjectReference &objRef,
+    const int32_t granteeID,
     const std::vector<int32_t> &roleIDs,
     const std::vector<ObjectUsage *> &listOfAffectedObjects,
     std::vector<ColumnReference *> &columnReferences);
@@ -422,6 +434,10 @@ private:
     PrivMgrDesc &summarizedOriginalPrivs,
     PrivMgrDesc &summarizedCurrentPrivs);
 
+  PrivStatus updateDependentObjects(
+    const ObjectUsage &objectUsage,
+    const PrivCommand command);
+
 // -------------------------------------------------------------------
 // Data Members:
 // -------------------------------------------------------------------


[08/10] incubator-trafodion git commit: Fix regression failures for views that contains unions in select text plus buf size limit too small for ComViewColUsage.

Posted by rm...@apache.org.
Fix regression failures for views that contains unions in select
text plus buf size limit too small for ComViewColUsage.


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

Branch: refs/heads/master
Commit: d4c0448fe74111b7065a796fe3d9934e62cd653d
Parents: 0857372
Author: Roberta Marton <rm...@edev07.esgyn.local>
Authored: Thu Aug 11 00:20:07 2016 +0000
Committer: Roberta Marton <rm...@edev07.esgyn.local>
Committed: Thu Aug 11 00:20:07 2016 +0000

----------------------------------------------------------------------
 core/sql/common/ComViewColUsage.h      |  4 ++--
 core/sql/sqlcomp/CmpSeabaseDDLview.cpp | 13 ++++++++-----
 core/sql/sqlcomp/PrivMgrPrivileges.cpp | 16 ++++++++++++++++
 3 files changed, 26 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d4c0448f/core/sql/common/ComViewColUsage.h
----------------------------------------------------------------------
diff --git a/core/sql/common/ComViewColUsage.h b/core/sql/common/ComViewColUsage.h
index 7d061c7..1ec12c6 100644
--- a/core/sql/common/ComViewColUsage.h
+++ b/core/sql/common/ComViewColUsage.h
@@ -88,9 +88,9 @@ public:
 
   void packUsage (NAString &viewColUsageStr)
   {
-      // usage contains 2 int64 and 3 int32, 100 chars is big enough to hold 
+      // usage contains 2 int64 and 3 int32, 200 chars is big enough to hold 
       // the string representation
-      char buf[100];
+      char buf[200];
       str_sprintf(buf, "viewUID: %Ld viewCol: %d refUID: %Ld refCol: %d refType: %d;",
                   viewUID_, viewColNumber_,
                   refdUID_, refdColNumber_, refdObjectType_);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d4c0448f/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLview.cpp b/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
index aaeb0d3..31bf68a 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
@@ -265,7 +265,7 @@ short CmpSeabaseDDL::buildViewTblColUsage(const StmtDDLCreateView * createViewPa
      int32_t usingColNum = vctcu.getUsingViewColumnNumber();
 
      // Get column name for view
-     const ComTdbVirtTableColumnInfo * colInfo = &colInfoArray[usingColNum];
+     //const ComTdbVirtTableColumnInfo * colInfo = &colInfoArray[usingColNum];
 
      // Get column number for referenced table
      const ColRefName &usedColRef = vctcu.getUsedObjectColumnName();
@@ -998,11 +998,14 @@ void CmpSeabaseDDL::createSeabaseView(
       return;
     }
 
-  if (updateTextTable(&cliInterface, objUID, COM_VIEW_REF_COLS_TEXT, 0, viewColUsageText))
+  if (!viewColUsageText.isNull())
     {
-      deallocEHI(ehi);
-      processReturn();
-      return;
+      if (updateTextTable(&cliInterface, objUID, COM_VIEW_REF_COLS_TEXT, 0, viewColUsageText))
+        {
+          deallocEHI(ehi);
+          processReturn();
+          return;
+        }
     }
 
   if (updateViewUsage(createViewNode, objUID, &cliInterface))

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d4c0448f/core/sql/sqlcomp/PrivMgrPrivileges.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrPrivileges.cpp b/core/sql/sqlcomp/PrivMgrPrivileges.cpp
index c3b116a..a1af7cb 100644
--- a/core/sql/sqlcomp/PrivMgrPrivileges.cpp
+++ b/core/sql/sqlcomp/PrivMgrPrivileges.cpp
@@ -1127,6 +1127,22 @@ PrivStatus PrivMgrPrivileges::grantColumnPrivileges(
     }
   }
 
+  // Verify that view-col <=> referenced_col relationship exists
+  if (objectType == COM_VIEW_OBJECT)
+  {
+    ViewUsage myUsage;
+    myUsage.viewUID = objectUID_;
+    PrivMgrMDAdmin admin(trafMetadataLocation_, metadataLocation_, pDiags_);
+    if (admin.getViewColUsages(myUsage) == STATUS_ERROR)
+      return STATUS_ERROR;
+    if (myUsage.viewColUsagesStr.empty())
+    {
+      *pDiags_ << DgSqlCode (-CAT_COLUMN_PRIVILEGE_NOT_ALLOWED)
+               << DgTableName (objectName_.c_str());
+       return STATUS_ERROR;
+    }
+  }
+
   // Walk the list of column privileges to grant, and either insert a new
   // row in the COLUMN_PRIVILEGES table or update an existing row.  
 


[09/10] incubator-trafodion git commit: Merge branch 'master' into trafodion-1788

Posted by rm...@apache.org.
Merge branch 'master' into trafodion-1788

Conflicts:
	core/sql/regress/privs1/EXPECTED141


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

Branch: refs/heads/master
Commit: 6046671e2b3d0834cc80d689db05db98701ff52b
Parents: d4c0448 a5b2b95
Author: Roberta Marton <rm...@edev07.esgyn.local>
Authored: Thu Aug 11 22:20:14 2016 +0000
Committer: Roberta Marton <rm...@edev07.esgyn.local>
Committed: Thu Aug 11 22:20:14 2016 +0000

----------------------------------------------------------------------
 .../org/trafodion/jdbc/t4/TrafT4Connection.java |   48 +-
 .../jdbc/t4/TrafT4PreparedStatement.java        |    2 +-
 .../odbc/src/odbc/nsksrvrcore/srvrothers.cpp    |   77 +-
 core/sqf/export/include/stfs/stfslib.h          |   19 +-
 core/sqf/sql/scripts/genms                      |    2 +-
 core/sqf/sql/scripts/keepHBaseUp.py             |  113 ++
 .../transactional/TransactionManager.java       |  520 +++--
 core/sqf/src/stfs/stfs_stub.cpp                 |   82 +-
 core/sqf/src/tm/tmlogging.cpp                   |  138 +-
 core/sqf/src/tm/tmlogging.h                     |    2 -
 core/sql/bin/SqlciErrors.txt                    |   12 +-
 core/sql/comexe/ComResourceInfo.cpp             |  259 +--
 core/sql/comexe/ComResourceInfo.h               |   98 +-
 core/sql/comexe/ComTdbExeUtil.cpp               |    3 +-
 core/sql/comexe/ComTdbExeUtil.h                 |   89 +-
 core/sql/common/CharType.cpp                    |    4 +-
 core/sql/common/ComSmallDefs.h                  |    4 +
 core/sql/common/NAString.cpp                    |    7 +
 core/sql/common/OperTypeEnum.h                  |    1 +
 core/sql/common/arkcmp_proc.cpp                 |    4 +-
 core/sql/common/str.cpp                         |   23 +-
 core/sql/executor/ExExeUtil.h                   |   48 +-
 core/sql/executor/ExExeUtilCommon.cpp           |   31 +
 core/sql/executor/ExExeUtilGet.cpp              |  396 +++-
 core/sql/executor/ExExplain.cpp                 |   26 +-
 core/sql/executor/ExHdfsScan.cpp                |   52 +-
 core/sql/executor/HBaseClient_JNI.cpp           |   48 +-
 core/sql/executor/HBaseClient_JNI.h             |    2 +
 core/sql/executor/cluster.cpp                   |    8 +-
 core/sql/executor/ex_sort.cpp                   |    8 +-
 core/sql/exp/ExpHbaseInterface.cpp              |   20 +
 core/sql/exp/ExpHbaseInterface.h                |    3 +
 core/sql/exp/ExpLOBaccess.cpp                   |    2 +-
 core/sql/generator/GenRelExeUtil.cpp            |   39 +-
 core/sql/generator/GenRelScan.cpp               |   13 +-
 core/sql/generator/GenResources.cpp             |  187 +-
 core/sql/generator/GenResources.h               |    2 +-
 core/sql/optimizer/BindRelExpr.cpp              |  131 +-
 core/sql/optimizer/EncodedKeyValue.cpp          |   18 +-
 core/sql/optimizer/OptRange.cpp                 |   17 +-
 core/sql/optimizer/RelExeUtil.cpp               |    9 +-
 core/sql/optimizer/RelExeUtil.h                 |   23 +-
 core/sql/optimizer/RelExpr.cpp                  |   17 +
 core/sql/optimizer/RelSample.cpp                |    1 -
 core/sql/optimizer/RelSet.h                     |   23 +
 core/sql/parser/sqlparser.y                     |   40 +-
 core/sql/regress/compGeneral/EXPECTED001.SB     |   10 +
 core/sql/regress/compGeneral/EXPECTED006.SB     |   29 -
 core/sql/regress/compGeneral/EXPECTED023        |  559 ++++++
 core/sql/regress/compGeneral/EXPECTED042        |    8 +-
 core/sql/regress/compGeneral/FILTER023          |   36 +
 core/sql/regress/compGeneral/TEST001            |    1 +
 core/sql/regress/compGeneral/TEST006            |    8 -
 core/sql/regress/compGeneral/TEST023            |  273 +++
 core/sql/regress/core/EXPECTED116               |    3 +
 core/sql/regress/executor/EXPECTED130           |    1 +
 core/sql/regress/hive/EXPECTED002               |    4 +-
 core/sql/regress/hive/EXPECTED009               |    1 +
 core/sql/regress/privs1/EXPECTED132             |    5 +
 core/sql/regress/privs1/EXPECTED133             |  Bin 26390 -> 27095 bytes
 core/sql/regress/privs1/EXPECTED141             |  Bin 93407 -> 100853 bytes
 core/sql/regress/privs1/TEST132                 |    2 +-
 core/sql/regress/privs2/EXPECTED138             |   24 +-
 core/sql/regress/privs2/EXPECTED140             |   25 +-
 core/sql/regress/seabase/EXPECTED002            |  224 ++-
 core/sql/regress/seabase/EXPECTED012            |    1 +
 core/sql/regress/seabase/EXPECTED026            |   24 +-
 core/sql/regress/seabase/EXPECTED031            |  124 +-
 core/sql/regress/seabase/FILTER002              |    4 +-
 core/sql/regress/seabase/TEST002                |   38 +-
 core/sql/regress/seabase/TEST031                |   19 +
 core/sql/regress/tools/runregr_compGeneral.ksh  |    2 +-
 core/sql/sort/DiskPool_base.h                   |    6 +-
 core/sql/sort/DiskPool_sq.h                     |    6 +-
 core/sql/sort/ScratchFileMap.cpp                |    4 +-
 core/sql/sort/ScratchFileMap.h                  |    2 +-
 core/sql/sort/ScratchFile_sq.h                  |    2 +-
 core/sql/sort/ScratchSpace.cpp                  |   51 +-
 core/sql/sort/ScratchSpace.h                    |   58 +-
 core/sql/sort/SortUtil.cpp                      |    8 +-
 core/sql/sort/SortUtilCfg.cpp                   |    8 +-
 core/sql/sort/SortUtilCfg.h                     |   59 +-
 core/sql/sort/diskpool_sq.cpp                   |    4 -
 core/sql/sort/scratchfile_sq.cpp                |   55 +-
 core/sql/sqlcat/TrafDDLdesc.cpp                 |    2 +
 core/sql/sqlcat/TrafDDLdesc.h                   |    8 +-
 core/sql/sqlcomp/CmpSeabaseDDL.h                |   10 +-
 core/sql/sqlcomp/CmpSeabaseDDLcleanup.cpp       |    5 +-
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp        |  198 +-
 core/sql/sqlcomp/CmpSeabaseDDLmd.h              |   25 +
 core/sql/sqlcomp/CmpSeabaseDDLschema.cpp        |    2 +-
 core/sql/sqlcomp/CmpSeabaseDDLtable.cpp         |   40 +-
 core/sql/sqlcomp/CmpSeabaseDDLview.cpp          |    5 +-
 core/sql/sqlcomp/DefaultConstants.h             |   16 +-
 core/sql/sqlcomp/DefaultValidator.cpp           |  348 +---
 core/sql/sqlcomp/DefaultValidator.h             |   96 +-
 core/sql/sqlcomp/nadefaults.cpp                 |  140 +-
 .../java/org/trafodion/sql/HBaseClient.java     |  124 +-
 .../java/org/trafodion/sql/TrafRegionStats.java |  118 +-
 core/sql/ustat/hs_auto.h                        |    4 +-
 core/sql/ustat/hs_cli.cpp                       |  831 ++++----
 core/sql/ustat/hs_cli.h                         |   81 +-
 core/sql/ustat/hs_const.h                       |   11 +-
 core/sql/ustat/hs_globals.cpp                   | 1822 ++++++++++++------
 core/sql/ustat/hs_globals.h                     |  110 +-
 core/sql/ustat/hs_la.cpp                        |   24 +
 core/sql/ustat/hs_la.h                          |   24 +-
 core/sql/ustat/hs_log.h                         |   21 +-
 core/sql/ustat/hs_parser.cpp                    |    4 +
 core/sql/ustat/hs_update.cpp                    |    3 -
 core/sql/ustat/hs_yacc.y                        |   65 +-
 .../trafodion/jdbc_test/TestGetIndexInfo.java   |  196 ++
 .../src/asciidoc/_chapters/sql_statements.adoc  |   13 +-
 113 files changed, 5552 insertions(+), 3153 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6046671e/core/sql/bin/SqlciErrors.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6046671e/core/sql/common/ComSmallDefs.h
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6046671e/core/sql/regress/privs1/EXPECTED141
----------------------------------------------------------------------
diff --cc core/sql/regress/privs1/EXPECTED141
index fb37c5e,308aae9..b846af7
Binary files differ

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6046671e/core/sql/sqlcat/TrafDDLdesc.cpp
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6046671e/core/sql/sqlcat/TrafDDLdesc.h
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6046671e/core/sql/sqlcomp/CmpSeabaseDDL.h
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6046671e/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6046671e/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
----------------------------------------------------------------------
diff --cc core/sql/sqlcomp/CmpSeabaseDDLview.cpp
index 31bf68a,b423d9b..50be2fe
--- a/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
@@@ -249,63 -247,6 +249,60 @@@ short CmpSeabaseDDL::buildViewColInfo(S
    return 0;
  }
  
 +// Build view column usages -> relate view-col <=> referenced-col
 +// This relationship is a string of values that gets stored in the TEXT table
 +short CmpSeabaseDDL::buildViewTblColUsage(const StmtDDLCreateView * createViewParseNode,
 +                                          const ComTdbVirtTableColumnInfo * colInfoArray,
 +                                          const Int64 objUID, NAString &viewColUsageText)
 +{
 +  const ParViewUsages &vu = createViewParseNode->getViewUsages();
 +  const ParViewColTableColsUsageList &vctcul = vu.getViewColTableColsUsageList();
 +  BindWA bindWA(ActiveSchemaDB(),CmpCommon::context(),FALSE/*inDDL*/);
 +
 +  for (size_t i = 0; i < vctcul.entries(); i++)
 +  {
 +     const ParViewColTableColsUsage &vctcu = vctcul[i];
 +     int32_t usingColNum = vctcu.getUsingViewColumnNumber();
 +
-      // Get column name for view
-      //const ComTdbVirtTableColumnInfo * colInfo = &colInfoArray[usingColNum];
- 
 +     // Get column number for referenced table
 +     const ColRefName &usedColRef = vctcu.getUsedObjectColumnName();
 +     ComObjectName usedObjName;
 +     usedObjName = usedColRef.getCorrNameObj().getQualifiedNameObj().
 +                   getQualifiedNameAsAnsiString();
 +
 +     const NAString catalogNamePart = usedObjName.getCatalogNamePartAsAnsiString();
 +     const NAString schemaNamePart = usedObjName.getSchemaNamePartAsAnsiString(TRUE);
 +     const NAString objectNamePart = usedObjName.getObjectNamePartAsAnsiString(TRUE);
 +     CorrName cn(objectNamePart,STMTHEAP,schemaNamePart,catalogNamePart);
 +
 +     NATable *naTable = bindWA.getNATable(cn);
 +     if (naTable == NULL)
 +     {
 +        SEABASEDDL_INTERNAL_ERROR("Bad NATable pointer in createSeabaseView");
 +        return -1;
 +     }
 +
 +     const NAColumnArray &nacolArr = naTable->getNAColumnArray();
 +     ComString usedObjColName(usedColRef.getColName());
 +     const NAColumn * naCol = nacolArr.getColumn(usedObjColName);
 +     if (naCol == NULL)
 +     {
 +       *CmpCommon::diags() << DgSqlCode(-CAT_COLUMN_DOES_NOT_EXIST_ERROR)
 +                           << DgColumnName(usedObjColName);
 +        return -1;
 +     }
 +
 +     ComViewColUsage colUsage(objUID, usingColNum, 
 +                              naTable->objectUid().get_value(),
 +                              naCol->getPosition(),
 +                              naTable->getObjectType());
 +     NAString viewColUsageStr;
 +     colUsage.packUsage(viewColUsageStr);
 +     viewColUsageText += viewColUsageStr;
 +  }
 +  return 0;
 +}
 +
  const char *
  CmpSeabaseDDL::computeCheckOption(StmtDDLCreateView * createViewParseNode) 
  {
@@@ -998,16 -920,6 +995,18 @@@ void CmpSeabaseDDL::createSeabaseView
        return;
      }
  
++  // Views that contain UNION clauses do not have col usages available so 
++  // viewColUsageText could be null - see TRAFODION-2153
 +  if (!viewColUsageText.isNull())
 +    {
 +      if (updateTextTable(&cliInterface, objUID, COM_VIEW_REF_COLS_TEXT, 0, viewColUsageText))
 +        {
 +          deallocEHI(ehi);
 +          processReturn();
 +          return;
 +        }
 +    }
 +
    if (updateViewUsage(createViewNode, objUID, &cliInterface))
      {
        deallocEHI(ehi); 


[06/10] incubator-trafodion git commit: [TRAFODION-1882]: Column Privilege: a user can grant column privilege to ... [TRAFODION-1788]: Grant and Revoke on table columns with referencing views ...

Posted by rm...@apache.org.
[TRAFODION-1882]: Column Privilege: a user can grant column privilege to ...
[TRAFODION-1788]: Grant and Revoke on table columns with referencing views ...

This delivery fixes several issues related to object and columnn privileges.
This should fix remaining issues with column level privileges so we can
officially support them.

-- When creating views, column level privileges were only considered if the
   SELECT privilege was not found at the object level.  Column level privs are
   now always considered, if the view owner has a privilege on all the columns
   that make up the view, then the view is granted the privilege.

-- When granting or revoking privileges, the code needs to verify if a user has
   a privilege at the column level.  In order to to this, the code needs the
   view-col <=> referenced-col usages.  This information is current not
   available.  Create view was changed to add view-col <=> referenced-col usages
   to the TEXT table.  This allows NATable and privilege management to retrieve
   this information. Views created prior to the change will not allow column
   privileges to be granted.  These views have to be dropped and recreated.

-- Grants and revokes on referenced columns for objects are now  propagated to
   to referencing view.  Propagation is performed to the immediate child views
   only.

-- Added some code to prepare for CASCADE.  This code processes the chain of
   views that exist looking for objects that may be affected by the grant or
   revoke.

-- The DB__ROOT user can perform operations on behalf on the schema owner.
   There were some situations where privileges were based on DB__ROOT instead
   of the schema_owner.  So a user that should not be granted a privileges was
   granted the privileges.  Changes were made to make sure the schema owner
   privileges were used in this situation.

-- Fixed an issue during column grants where column ordinals were not checked
   for views that reference an object.

-- Fixed an issue where insertable view info was not set up properly.

-- Fixed a problem where role usages was not considered when getting the list
   correctly [TRAFODION-1882]

-- Add new regression test privs2/TEST143 and moved the view propagation
   test from privs1/TEST141 to TEST143.


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

Branch: refs/heads/master
Commit: 5edd6b1eac080689c2dfe4ddb40a6113312cb21a
Parents: cd3d7e7
Author: Roberta Marton <rm...@edev07.esgyn.local>
Authored: Fri Aug 5 21:25:19 2016 +0000
Committer: Roberta Marton <rm...@edev07.esgyn.local>
Committed: Fri Aug 5 21:25:19 2016 +0000

----------------------------------------------------------------------
 core/sql/sqlcomp/PrivMgrPrivileges.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5edd6b1e/core/sql/sqlcomp/PrivMgrPrivileges.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrPrivileges.cpp b/core/sql/sqlcomp/PrivMgrPrivileges.cpp
index 732b65f..5c5b21c 100644
--- a/core/sql/sqlcomp/PrivMgrPrivileges.cpp
+++ b/core/sql/sqlcomp/PrivMgrPrivileges.cpp
@@ -2615,7 +2615,7 @@ PrivStatus PrivMgrPrivileges::getAffectedObjects(
 
 
   // Find list of affected constraints
-  if (command != PrivCommand::GRANT_OBJECT && command != PrivCommand::GRANT_COLUMN)  
+  if (isGrantCommand(command))
   {
     // TBD optimization: if no "references" privilege has been revoked, skip
     retcode = dealWithConstraints (objectUsage, listOfAffectedObjects);


[10/10] incubator-trafodion git commit: Merge [TRAFODION-1788] PR 644 grant and revoke on table columns ... not works

Posted by rm...@apache.org.
Merge [TRAFODION-1788] PR 644 grant and revoke on table columns ... not works


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

Branch: refs/heads/master
Commit: 8f538986c045e1872fda2b2cd62f6e5a624b1fcf
Parents: a5b2b95 6046671
Author: Roberta Marton <ro...@apache.org>
Authored: Fri Aug 12 00:58:25 2016 +0000
Committer: Roberta Marton <ro...@apache.org>
Committed: Fri Aug 12 00:58:25 2016 +0000

----------------------------------------------------------------------
 core/sql/bin/SqlciErrors.txt            |    2 +-
 core/sql/comexe/ComTdb.h                |    1 +
 core/sql/common/ComSmallDefs.h          |    3 +-
 core/sql/common/ComViewColUsage.h       |  112 +++
 core/sql/generator/Generator.cpp        |    8 +
 core/sql/optimizer/NATable.cpp          |   28 +
 core/sql/optimizer/NATable.h            |    3 +
 core/sql/regress/privs1/EXPECTED141     |  Bin 123489 -> 100853 bytes
 core/sql/regress/privs1/TEST141         |   52 --
 core/sql/regress/privs2/EXPECTED143     |  Bin 0 -> 59462 bytes
 core/sql/regress/privs2/TEST143         |  457 +++++++++++
 core/sql/sqlcat/ReadTableDef.cpp        |    1 -
 core/sql/sqlcat/TrafDDLdesc.cpp         |    2 +
 core/sql/sqlcat/TrafDDLdesc.h           |    1 +
 core/sql/sqlcomp/CmpDDLCatErrorCodes.h  |    2 +-
 core/sql/sqlcomp/CmpSeabaseDDL.h        |    5 +
 core/sql/sqlcomp/CmpSeabaseDDLtable.cpp |   12 +
 core/sql/sqlcomp/CmpSeabaseDDLview.cpp  |  294 ++++---
 core/sql/sqlcomp/PrivMgr.h              |   22 +-
 core/sql/sqlcomp/PrivMgrMD.cpp          |  132 +++-
 core/sql/sqlcomp/PrivMgrMD.h            |   49 ++
 core/sql/sqlcomp/PrivMgrPrivileges.cpp  | 1063 ++++++++++++++++++--------
 core/sql/sqlcomp/PrivMgrPrivileges.h    |   29 +
 23 files changed, 1799 insertions(+), 479 deletions(-)
----------------------------------------------------------------------



[03/10] incubator-trafodion git commit: Merge branch 'master' into trafodion-1788

Posted by rm...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/sqlcat/ReadTableDef.cpp
----------------------------------------------------------------------
diff --cc core/sql/sqlcat/ReadTableDef.cpp
index df0efbc,31bafb7..be64096
--- a/core/sql/sqlcat/ReadTableDef.cpp
+++ b/core/sql/sqlcat/ReadTableDef.cpp
@@@ -157,345 -93,4 +93,3 @@@ ReadTableDef::~ReadTableDef(
    // end any transactions started by "me"
  }
  
- 
- 
- //------------------------------------------------------------------------
- // displayTreeMX()
- //------------------------------------------------------------------------
- void ReadTableDef::displayTree(const desc_struct * top) const
- {
-   displayTreeMX(top, "");
- }
- 
- void ReadTableDef::displayTreeMX(const desc_struct * top,
-                                   const char * caller) const
- {
-   if (top == NULL) return;
- 
-   char title[50];
-   snprintf(title, sizeof(title),
-           ", type %d, address %p, parent %s\n",
-           top->NODETYPE_MX, (void *)top, caller);
-   #undef  TITLE
-   #define TITLE(XXX)    cout << "### " << XXX << title;         \
-                         strcpy(title, XXX)
- 
-   cout.setf(ios::right);
- 
-   switch (top->NODETYPE_MX)
-     {
-     case TYPEMX(CHECK_CONSTRNTS):
-       {
-         TITLE("CHECK_CONSTRNTS");
-         CASTMX(check_constrnts);
-         COUT(check_constrnts, seqnumber);
-         COUT_STRING(check_constrnts, constrnt_text);
-       }
-       break;
- 
-     case TYPEMX(COLUMNS):
-       {
-         TITLE("COLUMNS");
-         CASTMX(columns);
-         COUT(columns, tablename);
-         COUT(columns, colname);
-         COUT(columns, colnumber);
-         COUT(columns, datatype);
-         COUT(columns, length);
-         COUT(columns, scale);
-         COUT(columns, precision);
-         COUT_ENUM(columns, datetimestart);
-         COUT_ENUM(columns, datetimeend);
-         COUT(columns, datetimefractprec);
-         COUT(columns, intervalleadingprec);
-         COUT(columns, offset);
-         COUT(columns, null_flag);
-         COUT(columns, upshift);
-         COUT(columns, colclass);
-         COUT(columns, uec);
-         COUT_STRING(columns, highval);
-         COUT_STRING(columns, lowval);
- 
-         Int32 defaultValueInLocaleLen = 
- #pragma nowarn(1506)   // warning elimination 
-               NAWstrlen((NAWchar*)(columns->defaultvalue));
- #pragma warn(1506)  // warning elimination 
-         char* defaultValueInLocale = new HEAP char[defaultValueInLocaleLen+1];
- 
-         CharInfo::CharSet mapCharSet = SqlParser_ISO_MAPPING;
- 
-         Int32 x = UnicodeStringToLocale(mapCharSet,
-                  (NAWchar*)(columns->defaultvalue), defaultValueInLocaleLen,
-                  defaultValueInLocale, defaultValueInLocaleLen+1
-                              );
-         if (columns->defaultvalue)  {
-           cout << "  " << setw(20) << "defaultvalue"
-                << "  " << defaultValueInLocale << endl;
-         } else {
-           cout << "  " << setw(20) << "defaultvalue" << " is null" << endl;
-         }
-         NADELETEBASIC(defaultValueInLocale, HEAP);
-       }
-       break;
- 
-     case TYPEMX(CONSTRNTS):
-       {
-         TITLE("CONSTRNTS");
-         CASTMX(constrnts);
-         COUT(constrnts, constrntname);
-         COUT(constrnts, tablename);
-         COUT_ENUM(constrnts, type);
-         COUT(constrnts, colcount);
-         COUT_STRING(constrnts, indexname);
-         displayTreeMX(constrnts->check_constrnts_desc, title);
-         displayTreeMX(constrnts->constr_key_cols_desc, title);
-         displayTreeMX(constrnts->referenced_constrnts_desc, title);
-         displayTreeMX(constrnts->referencing_constrnts_desc, title);
-       }
-       break;
- 
-     case TYPEMX(CONSTRNT_KEY_COLS):
-       {
-         TITLE("CONSTRNT_KEY_COLS");
-         CASTMX(constrnt_key_cols);
-         COUT(constrnt_key_cols, colname);
-         COUT(constrnt_key_cols, position);
-       }
-       break;
- 
-     case TYPEMX(FILES):
-       {
-         TITLE("FILES");
-         CASTMX(files);
-         COUT_ENUM(files, fileorganization);
-         COUT(files, audit);
-         COUT(files, auditcompress);
-         COUT(files, compressed);
-         displayTreeMX(files->partns_desc, title);
-       }
-       break;
- 
-     case TYPEMX(HISTOGRAM):
-       {
-         TITLE("HISTOGRAM");
-         CASTMX(histogram);
-         COUT(histogram, tablename);
-         COUT(histogram, tablecolnumber);
-         COUT(histogram, histid);
-         COUT(histogram, colposition);
-         COUT(histogram, rowcount);
-         COUT(histogram, uec);
-         COUT_STRING(histogram, highval);
-         COUT_STRING(histogram, lowval);
-         displayTreeMX(histogram->hist_interval_desc, title);
-       }
-       break;
- 
-     case TYPEMX(HIST_INTERVAL):
-       {
-         TITLE("HIST_INTERVAL");
-         CASTMX(hist_interval);
-         COUT(hist_interval, histid);
-         COUT(hist_interval, intnum);
-         COUT(hist_interval, intboundary);
-         COUT(hist_interval, rowcount);
-         COUT(hist_interval, uec);
-       }
-       break;
- 
-     case TYPEMX(INDEXES):
-       {
-         TITLE("INDEXES");
-         CASTMX(indexes);
-         COUT(indexes, tablename);
-         COUT(indexes, indexname);
-         COUT(indexes, keytag);
-         COUT(indexes, record_length);
-         COUT(indexes, colcount);
-         COUT(indexes, unique);
-         displayTreeMX(indexes->files_desc, title);
-         displayTreeMX(indexes->keys_desc, title);
-     displayTreeMX(indexes->non_keys_desc, title);
-       }
-       break;
- 
-     case TYPEMX(KEYS):
-       {
-         TITLE("KEYS");
-         CASTMX(keys);
-         COUT(keys, indexname);
-         COUT(keys, keyseqnumber);
-         COUT(keys, tablecolnumber);
-         COUT(keys, ordering);
-       }
-       break;
- 
-     case TYPEMX(PARTNS):
-       {
-         TITLE("PARTNS");
-         CASTMX(partns);
-         COUT(partns, tablename);
-         COUT(partns, primarypartition);
-         COUT(partns, partitionname);
-         COUT_STRING(partns, firstkey);
-       }
-       break;
- 
-     case TYPEMX(REF_CONSTRNTS):
-       {
-         TITLE("REF_CONSTRNTS");
-         CASTMX(ref_constrnts);
-         COUT(ref_constrnts, constrntname);
-         COUT(ref_constrnts, tablename);
-       }
-       break;
- 
-     case TYPEMX(TABLE):
-       {
-         TITLE("TABLE");
-         CASTMX(table);
-         COUT_LARGEINT(table, createtime);
-         COUT_LARGEINT(table, redeftime);
-         COUT(table, tablename);
-         COUT(table, record_length);
-         COUT(table, colcount);
-         COUT(table, constr_count);
-         COUT(table, rowcount);
-         displayTreeMX(table->files_desc, title);
-         displayTreeMX(table->columns_desc, title);
-         displayTreeMX(table->views_desc, title);
-         displayTreeMX(table->indexes_desc, title);
-         displayTreeMX(table->constrnts_desc, title);
-         if (table->constrnts_tables_desc != top)
-           displayTreeMX(table->constrnts_tables_desc, title);
-         displayTreeMX(table->referenced_tables_desc, title);
-         displayTreeMX(table->referencing_tables_desc, title);
-         displayTreeMX(table->histograms_desc, title);
-       }
-       break;
- 
-     case TYPEMX(VIEW):
-       {
-         TITLE("VIEW");
-         CASTMX(view);
-         COUT(view, viewname);
-         COUT_STRING(view, viewtext);
-         COUT_STRING(view, viewchecktext);
-         COUT_STRING(view, viewcolusages);
-         COUT(view, updatable);
-         COUT(view, insertable);
-       }
-       break;
- 
-     default:
-       {
-         TITLE("??? UNKNOWN ???");
-       }
-       break;
-     }  // switch
- 
-   displayTreeMX (top->header.next, title);
- 
- } // displayTreeMX
- 
- 
- //------------------------------------------------------------------------
- // deleteTreeMX()
- //------------------------------------------------------------------------
- void ReadTableDef::deleteTree(desc_struct * top) const
- {
-   deleteTreeMX(top);
- }
- 
- void ReadTableDef::deleteTreeMX(desc_struct * top) const
- {
-   if (top == NULL) return;
- 
-   switch (top->NODETYPE_MX)
-     {
-     case TYPEMX(CHECK_CONSTRNTS):
-       break;
- 
-     case TYPEMX(COLUMNS):
-       break;
- 
-     case TYPEMX(CONSTRNTS):
-       {
- 	CASTMX(constrnts);
- 	deleteTreeMX(constrnts->check_constrnts_desc);
- 	deleteTreeMX(constrnts->constr_key_cols_desc);
- 	deleteTreeMX(constrnts->referenced_constrnts_desc);
- 	deleteTreeMX(constrnts->referencing_constrnts_desc);
-       }
-       break;
- 
-     case TYPEMX(CONSTRNT_KEY_COLS):
-       break;
- 
-     case TYPEMX(FILES):
-       {
- 	CASTMX(files);
- 	deleteTreeMX(files->partns_desc);
-       }
-       break;
- 
-     case TYPEMX(HISTOGRAM):
-       {
- 	CASTMX(histogram);
- 	deleteTreeMX(histogram->hist_interval_desc);
-       }
-       break;
- 
-     case TYPEMX(HIST_INTERVAL):
-       break;
- 
-     case TYPEMX(INDEXES):
-       {
- 	CASTMX(indexes);
- 	deleteTreeMX(indexes->keys_desc);
-     deleteTreeMX(indexes->non_keys_desc);
- 	deleteTreeMX(indexes->files_desc);
-       }
-       break;
- 
-     case TYPEMX(KEYS):
-       break;
- 
-     case TYPEMX(PARTNS):
-       break;
- 
-     case TYPEMX(REF_CONSTRNTS):
-       break;
- 
-     case TYPEMX(TABLE):
-       {
- 	CASTMX(table);
- 	deleteTreeMX(table->columns_desc);
- 	deleteTreeMX(table->views_desc);
- 	deleteTreeMX(table->files_desc);
- 	deleteTreeMX(table->indexes_desc);
- 	deleteTreeMX(table->constrnts_desc);
- 	if (table->constrnts_tables_desc != top)
- 	  deleteTreeMX(table->constrnts_tables_desc);
- 	deleteTreeMX(table->referenced_tables_desc);
- 	deleteTreeMX(table->referencing_tables_desc);
- 	deleteTreeMX(table->histograms_desc);
-       }
-       break;
- 
-     case TYPEMX(VIEW):
-       break;
- 
-     default:
-       {
- 	cerr << "ReadTableDef: memory leak at node type " << top->NODETYPE_MX
- 	     << endl;
-       }
-       break;
-     }  // switch
- 
-   deleteTreeMX (top->header.next);
-   NADELETEBASIC(top, HEAP);
- 
- } // deleteTreeWMX
--

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/sqlcat/TrafDDLdesc.cpp
----------------------------------------------------------------------
diff --cc core/sql/sqlcat/TrafDDLdesc.cpp
index 0000000,112bfac..977be16
mode 000000,100644..100644
--- a/core/sql/sqlcat/TrafDDLdesc.cpp
+++ b/core/sql/sqlcat/TrafDDLdesc.cpp
@@@ -1,0 -1,617 +1,619 @@@
+ /**********************************************************************
+ // @@@ 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 @@@
+ //
+ **********************************************************************/
+ 
+ #include "TrafDDLdesc.h"
+ #include "CmpCommon.h"
+ 
+ // -----------------------------------------------------------------------
+ // Allocate one of the primitive structs and initialize to all zeroes.
+ // Uses HEAP (StatementHeap) of CmpCommon or space.
+ // -----------------------------------------------------------------------
+ TrafDesc *TrafAllocateDDLdesc(desc_nodetype nodetype, Space * space)
+ {
+   size_t size = 0;
+   TrafDesc * desc_ptr = NULL;
+ 
+   switch (nodetype)
+     {
+     case DESC_CHECK_CONSTRNTS_TYPE:
+       desc_ptr = new GENHEAP(space) TrafCheckConstrntsDesc();
+       break;
+     case DESC_COLUMNS_TYPE:
+       desc_ptr = new GENHEAP(space) TrafColumnsDesc();
+       break;
+     case DESC_CONSTRNTS_TYPE:
+       desc_ptr = new GENHEAP(space) TrafConstrntsDesc();
+       break;
+     case DESC_CONSTRNT_KEY_COLS_TYPE:
+       desc_ptr = new GENHEAP(space) TrafConstrntKeyColsDesc();
+       break;
+     case DESC_FILES_TYPE:
+       desc_ptr = new GENHEAP(space) TrafFilesDesc();
+       break;
+     case DESC_HBASE_RANGE_REGION_TYPE:
+       desc_ptr = new GENHEAP(space) TrafHbaseRegionDesc();
+       break;
+     case DESC_HISTOGRAM_TYPE:
+       desc_ptr = new GENHEAP(space) TrafHistogramDesc();
+       break;
+     case DESC_HIST_INTERVAL_TYPE:
+       desc_ptr = new GENHEAP(space) TrafHistIntervalDesc();
+       break;
+     case DESC_INDEXES_TYPE:
+       desc_ptr = new GENHEAP(space) TrafIndexesDesc();
+       break;
+     case DESC_KEYS_TYPE:
+       desc_ptr = new GENHEAP(space) TrafKeysDesc();
+       break;
+     case DESC_LIBRARY_TYPE:
+       desc_ptr = new GENHEAP(space) TrafLibraryDesc();
+       break;
+      case DESC_PARTNS_TYPE:
+       desc_ptr = new GENHEAP(space) TrafPartnsDesc();
+       break;
+     case DESC_REF_CONSTRNTS_TYPE:
+       desc_ptr = new GENHEAP(space) TrafRefConstrntsDesc();
+       break;
+     case DESC_ROUTINE_TYPE:
+       desc_ptr = new GENHEAP(space) TrafRoutineDesc();
+       break;
+     case DESC_SEQUENCE_GENERATOR_TYPE:   
+       desc_ptr = new GENHEAP(space) TrafSequenceGeneratorDesc();
+       break;
+     case DESC_TABLE_TYPE:
+       desc_ptr = new GENHEAP(space) TrafTableDesc();
+       break;
+     case DESC_VIEW_TYPE:
+       desc_ptr = new GENHEAP(space) TrafViewDesc();
+       break;	       
+     case DESC_USING_MV_TYPE: 
+       desc_ptr = new GENHEAP(space) TrafUsingMvDesc();
+       break;
+     default:
+       assert(FALSE);
+       break;
+     }
+ 
+   // if not being allocated from space, memset all bytes to 0.
+   // If allocated from space, it will be set to 0 during space allocation.
+   if (! space)
+     memset((char*)desc_ptr+sizeof(TrafDesc), 0, 
+            desc_ptr->getClassSize()-sizeof(TrafDesc));
+ 
+   return desc_ptr;
+ 
+ }
+ 
+ TrafDesc::TrafDesc(UInt16 nodeType) 
+   : NAVersionedObject(nodeType),
+     nodetype(nodeType),
+     version(CURR_VERSION),
+     descFlags(0),
+     next(NULL)
+ {}
+ 
+ Lng32 TrafDesc::validateSize()
+ {
+   if (getImageSize() != getClassSize())
+     return -1;
+ 
+   return 0;
+ }
+ 
+ Lng32 TrafDesc::validateVersion()
+ {
+   if (version != CURR_VERSION)
+     return -1;
+ 
+   return 0;
+ }
+ 
+ Lng32 TrafDesc::migrateToNewVersion(
+      NAVersionedObject *&newImage)
+ {
+   short tempimagesize = getClassSize();
+   // -----------------------------------------------------------------
+   // The base class implementation of migrateToNewVersion() is only
+   // called with newImage == NULL when the same function is not
+   // redefined at the subclass. That means no new version of that
+   // subclass has been invented yet.
+   // -----------------------------------------------------------------
+   if (newImage == NULL)
+     {
+       if (validateSize())
+         return -1;
+ 
+       if (validateVersion())
+         return -1;
+     }
+ 
+   return NAVersionedObject::migrateToNewVersion(newImage);
+ }
+ 
+ char *TrafDesc::findVTblPtr(short classID)
+ {
+   char *vtblptr = NULL;
+ 
+   switch (classID)
+     {
+     case DESC_CHECK_CONSTRNTS_TYPE:
+       GetVTblPtr(vtblptr, TrafCheckConstrntsDesc);
+       break;
+     case DESC_COLUMNS_TYPE:
+       GetVTblPtr(vtblptr, TrafColumnsDesc);
+       break;
+     case DESC_CONSTRNTS_TYPE:
+       GetVTblPtr(vtblptr, TrafConstrntsDesc);
+       break;
+     case DESC_CONSTRNT_KEY_COLS_TYPE:
+       GetVTblPtr(vtblptr, TrafConstrntKeyColsDesc);
+       break;
+     case DESC_FILES_TYPE:
+       GetVTblPtr(vtblptr, TrafFilesDesc);
+       break;
+     case DESC_HBASE_RANGE_REGION_TYPE:
+       GetVTblPtr(vtblptr, TrafHbaseRegionDesc);
+       break;
+     case DESC_HISTOGRAM_TYPE:
+       GetVTblPtr(vtblptr, TrafHistogramDesc);
+       break;
+     case DESC_HIST_INTERVAL_TYPE:
+       GetVTblPtr(vtblptr, TrafHistIntervalDesc);
+       break;
+     case DESC_INDEXES_TYPE:
+       GetVTblPtr(vtblptr, TrafIndexesDesc);
+       break;
+     case DESC_KEYS_TYPE:
+       GetVTblPtr(vtblptr, TrafKeysDesc);
+       break;
+     case DESC_LIBRARY_TYPE:
+       GetVTblPtr(vtblptr, TrafLibraryDesc);
+       break;
+      case DESC_PARTNS_TYPE:
+       GetVTblPtr(vtblptr, TrafPartnsDesc);
+       break;
+     case DESC_REF_CONSTRNTS_TYPE:
+       GetVTblPtr(vtblptr, TrafRefConstrntsDesc);
+       break;
+     case DESC_ROUTINE_TYPE:
+       GetVTblPtr(vtblptr, TrafRoutineDesc);
+       break;
+     case DESC_SEQUENCE_GENERATOR_TYPE:   
+       GetVTblPtr(vtblptr, TrafSequenceGeneratorDesc);
+       break;
+     case DESC_TABLE_TYPE:
+       GetVTblPtr(vtblptr, TrafTableDesc);
+       break;
+     case DESC_VIEW_TYPE:
+       GetVTblPtr(vtblptr, TrafViewDesc);
+       break;	       
+     case DESC_USING_MV_TYPE: 
+       GetVTblPtr(vtblptr, TrafUsingMvDesc);
+       break;
+     default:
+       assert(FALSE);
+       break;
+     }
+ 
+   return vtblptr;
+ }
+ 
+ // pack and unpack methods for various descriptor structs
+ 
+ Long TrafDesc::pack(void * space)
+ {
+   next.pack(space);
+ 
+   return NAVersionedObject::pack(space);
+ }
+ 
+ Lng32 TrafDesc::unpack(void * base, void * reallocator)
+ {
+   if(next.unpack(base, reallocator)) return -1;
+ 
+   return NAVersionedObject::unpack(base, reallocator);
+ }
+ 
+ Long TrafCheckConstrntsDesc::pack(void * space)
+ {
+   constrnt_text = (constrnt_text ? (char*)(((Space*)space)->convertToOffset(constrnt_text)) : NULL);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafCheckConstrntsDesc::unpack(void * base, void * reallocator)
+ {
+   constrnt_text = (constrnt_text ? (char*)((char*)base - (Long)constrnt_text) : NULL);
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafColumnsDesc::pack(void * space)
+ {
+   colname = (colname ? (char*)(((Space*)space)->convertToOffset(colname)) : NULL);
+ 
+   pictureText = (pictureText ? (char*)(((Space*)space)->convertToOffset(pictureText)) : NULL);
+ 
+   defaultvalue = (defaultvalue ? (char*)(((Space*)space)->convertToOffset(defaultvalue)) : NULL);
+   heading = (heading ? (char*)(((Space*)space)->convertToOffset(heading)) : NULL);
+   computed_column_text = (computed_column_text ? (char*)(((Space*)space)->convertToOffset(computed_column_text)) : NULL);
+ 
+   hbaseColFam = (hbaseColFam ? (char*)(((Space*)space)->convertToOffset(hbaseColFam)) : NULL);
+   hbaseColQual = (hbaseColQual ? (char*)(((Space*)space)->convertToOffset(hbaseColQual)) : NULL);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafColumnsDesc::unpack(void * base, void * reallocator)
+ {
+   colname = (colname ? (char*)((char*)base - (Long)colname) : NULL);
+ 
+   pictureText = (pictureText ? (char*)((char*)base - (Long)pictureText) : NULL);
+ 
+   defaultvalue = (defaultvalue ? (char*)((char*)base - (Long)defaultvalue) : NULL);
+   heading = (heading ? (char*)((char*)base - (Long)heading) : NULL);
+   computed_column_text = (computed_column_text ? (char*)((char*)base - (Long)computed_column_text) : NULL);
+ 
+   hbaseColFam = (hbaseColFam ? (char*)((char*)base - (Long)hbaseColFam) : NULL);
+   hbaseColQual = (hbaseColQual ? (char*)((char*)base - (Long)hbaseColQual) : NULL);
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafConstrntsDesc::pack(void * space)
+ {
+   constrntname = (constrntname ? (char*)(((Space*)space)->convertToOffset(constrntname)) : NULL);
+   tablename = (tablename ? (char*)(((Space*)space)->convertToOffset(tablename)) : NULL);
+   
+   check_constrnts_desc.pack(space);
+   constr_key_cols_desc.pack(space);
+   referenced_constrnts_desc.pack(space);
+   referencing_constrnts_desc.pack(space);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafConstrntsDesc::unpack(void * base, void * reallocator)
+ {
+   constrntname = (constrntname ? (char*)((char*)base - (Long)constrntname) : NULL);
+   tablename = (tablename ? (char*)((char*)base - (Long)tablename) : NULL);
+ 
+   if (check_constrnts_desc.unpack(base, reallocator)) return -1;
+   if (constr_key_cols_desc.unpack(base, reallocator)) return -1;
+   if (referenced_constrnts_desc.unpack(base, reallocator)) return -1;
+   if (referencing_constrnts_desc.unpack(base, reallocator)) return -1;
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafConstrntKeyColsDesc::pack(void * space)
+ {
+   colname = (colname ? (char*)(((Space*)space)->convertToOffset(colname)) : NULL);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafConstrntKeyColsDesc::unpack(void * base, void * reallocator)
+ {
+   colname = (colname ? (char*)((char*)base - (Long)colname) : NULL);
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ 
+ Long TrafFilesDesc::pack(void * space)
+ {
+   partns_desc.pack(space);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafFilesDesc::unpack(void * base, void * reallocator)
+ {
+   if (partns_desc.unpack(base, reallocator)) return -1;
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafHbaseRegionDesc::pack(void * space)
+ {
+   beginKey = (beginKey ? (char*)(((Space*)space)->convertToOffset(beginKey)) : NULL);
+   endKey = (endKey ? (char*)(((Space*)space)->convertToOffset(endKey)) : NULL);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafHbaseRegionDesc::unpack(void * base, void * reallocator)
+ {
+   beginKey = (beginKey ? (char*)((char*)base - (Long)beginKey) : NULL);
+   endKey = (endKey ? (char*)((char*)base - (Long)endKey) : NULL);
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafHistogramDesc::pack(void * space)
+ {
+   tablename = (tablename ? (char*)(((Space*)space)->convertToOffset(tablename)) : NULL);
+   histid = (histid ? (char*)(((Space*)space)->convertToOffset(histid)) : NULL);
+   highval = (highval ? (char*)(((Space*)space)->convertToOffset(highval)) : NULL);
+   lowval = (lowval ? (char*)(((Space*)space)->convertToOffset(lowval)) : NULL);
+ 
+   hist_interval_desc.pack(space);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafHistogramDesc::unpack(void * base, void * reallocator)
+ {
+   tablename = (tablename ? (char*)((char*)base - (Long)tablename) : NULL);
+   histid = (histid ? (char*)((char*)base - (Long)histid) : NULL);
+   highval = (highval ? (char*)((char*)base - (Long)highval) : NULL);
+   lowval = (lowval ? (char*)((char*)base - (Long)lowval) : NULL);
+ 
+   if (hist_interval_desc.unpack(base, reallocator)) return -1;
+   
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafHistIntervalDesc::pack(void * space)
+ {
+   histid = (histid ? (char*)(((Space*)space)->convertToOffset(histid)) : NULL);
+   intboundary = (intboundary ? (char*)(((Space*)space)->convertToOffset(intboundary)) : NULL);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafHistIntervalDesc::unpack(void * base, void * reallocator)
+ {
+   histid = (histid ? (char*)((char*)base - (Long)histid) : NULL);
+   intboundary = (intboundary ? (char*)((char*)base - (Long)intboundary) : NULL);
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafIndexesDesc::pack(void * space)
+ {
+   tablename = (tablename ? (char*)(((Space*)space)->convertToOffset(tablename)) : NULL);
+   indexname = (indexname ? (char*)(((Space*)space)->convertToOffset(indexname)) : NULL);
+   hbaseCreateOptions = (hbaseCreateOptions ? (char*)(((Space*)space)->convertToOffset(hbaseCreateOptions)) : NULL);
+ 
+   files_desc.pack(space);
+   keys_desc.pack(space);
+   non_keys_desc.pack(space);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafIndexesDesc::unpack(void * base, void * reallocator)
+ {
+   tablename = (tablename ? (char*)((char*)base - (Long)tablename) : NULL);
+   indexname = (indexname ? (char*)((char*)base - (Long)indexname) : NULL);
+   hbaseCreateOptions = (hbaseCreateOptions ? (char*)((char*)base - (Long)hbaseCreateOptions) : NULL);
+ 
+   if (files_desc.unpack(base, reallocator)) return -1;
+   if (keys_desc.unpack(base, reallocator)) return -1;
+   if (non_keys_desc.unpack(base, reallocator)) return -1;
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafKeysDesc::pack(void * space)
+ {
+   keyname = (keyname ? (char*)(((Space*)space)->convertToOffset(keyname)) : NULL);
+   hbaseColFam = (hbaseColFam ? (char*)(((Space*)space)->convertToOffset(hbaseColFam)) : NULL);
+   hbaseColQual = (hbaseColQual ? (char*)(((Space*)space)->convertToOffset(hbaseColQual)) : NULL);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafKeysDesc::unpack(void * base, void * reallocator)
+ {
+   keyname = (keyname ? (char*)((char*)base - (Long)keyname) : NULL);
+   hbaseColFam = (hbaseColFam ? (char*)((char*)base - (Long)hbaseColFam) : NULL);
+   hbaseColQual = (hbaseColQual ? (char*)((char*)base - (Long)hbaseColQual) : NULL);
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafLibraryDesc::pack(void * space)
+ {
+   libraryName = (libraryName ? (char*)(((Space*)space)->convertToOffset(libraryName)) : NULL);
+   libraryFilename = (libraryFilename ? (char*)(((Space*)space)->convertToOffset(libraryFilename)) : NULL);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafLibraryDesc::unpack(void * base, void * reallocator)
+ {
+   libraryName = (libraryName ? (char*)((char*)base - (Long)libraryName) : NULL);
+   libraryFilename = (libraryFilename ? (char*)((char*)base - (Long)libraryFilename) : NULL);
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafPartnsDesc::pack(void * space)
+ {
+   tablename = (tablename ? (char*)(((Space*)space)->convertToOffset(tablename)) : NULL);
+   partitionname = (partitionname ? (char*)(((Space*)space)->convertToOffset(partitionname)) : NULL);
+   logicalpartitionname = (logicalpartitionname ? (char*)(((Space*)space)->convertToOffset(logicalpartitionname)) : NULL);
+   firstkey = (firstkey ? (char*)(((Space*)space)->convertToOffset(firstkey)) : NULL);
+   encodedkey = (encodedkey ? (char*)(((Space*)space)->convertToOffset(encodedkey)) : NULL);
+   lowKey = (lowKey ? (char*)(((Space*)space)->convertToOffset(lowKey)) : NULL);
+   highKey = (highKey ? (char*)(((Space*)space)->convertToOffset(highKey)) : NULL);
+   givenname = (givenname ? (char*)(((Space*)space)->convertToOffset(givenname)) : NULL);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafPartnsDesc::unpack(void * base, void * reallocator)
+ {
+   tablename = (tablename ? (char*)((char*)base - (Long)tablename) : NULL);
+   partitionname = (partitionname ? (char*)((char*)base - (Long)partitionname) : NULL);
+   logicalpartitionname = (logicalpartitionname ? (char*)((char*)base - (Long)logicalpartitionname) : NULL);
+   firstkey = (firstkey ? (char*)((char*)base - (Long)firstkey) : NULL);
+   encodedkey = (encodedkey ? (char*)((char*)base - (Long)encodedkey) : NULL);
+   lowKey = (lowKey ? (char*)((char*)base - (Long)lowKey) : NULL);
+   highKey = (highKey ? (char*)((char*)base - (Long)highKey) : NULL);
+   givenname = (givenname ? (char*)((char*)base - (Long)givenname) : NULL);
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafRefConstrntsDesc::pack(void * space)
+ {
+   constrntname = (constrntname ? (char*)(((Space*)space)->convertToOffset(constrntname)) : NULL);
+   tablename = (tablename ? (char*)(((Space*)space)->convertToOffset(tablename)) : NULL);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafRefConstrntsDesc::unpack(void * base, void * reallocator)
+ {
+   constrntname = (constrntname ? (char*)((char*)base - (Long)constrntname) : NULL);
+   tablename = (tablename ? (char*)((char*)base - (Long)tablename) : NULL);
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafRoutineDesc::pack(void * space)
+ {
+   routineName = (routineName ? (char*)(((Space*)space)->convertToOffset(routineName)) : NULL);
+   externalName = (externalName ? (char*)(((Space*)space)->convertToOffset(externalName)) : NULL);
+   librarySqlName = (librarySqlName ? (char*)(((Space*)space)->convertToOffset(librarySqlName)) : NULL);
+   libraryFileName = (libraryFileName ? (char*)(((Space*)space)->convertToOffset(libraryFileName)) : NULL);
+   signature = (signature ? (char*)(((Space*)space)->convertToOffset(signature)) : NULL);
+ 
+   params.pack(space);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafRoutineDesc::unpack(void * base, void * reallocator)
+ {
+   routineName = (routineName ? (char*)((char*)base - (Long)routineName) : NULL);
+   externalName = (externalName ? (char*)((char*)base - (Long)externalName) : NULL);
+   librarySqlName = (librarySqlName ? (char*)((char*)base - (Long)librarySqlName) : NULL);
+   libraryFileName = (libraryFileName ? (char*)((char*)base - (Long)libraryFileName) : NULL);
+   signature = (signature ? (char*)((char*)base - (Long)signature) : NULL);
+ 
+   if (params.unpack(base, reallocator)) return -1;
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafSequenceGeneratorDesc::pack(void * space)
+ {
+   sgLocation = (sgLocation ? (char*)(((Space*)space)->convertToOffset(sgLocation)) : NULL);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafSequenceGeneratorDesc::unpack(void * base, void * reallocator)
+ {
+   sgLocation = (sgLocation ? (char*)((char*)base - (Long)sgLocation) : NULL);
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafTableDesc::pack(void * space)
+ {
+   tablename = (tablename ? (char*)(((Space*)space)->convertToOffset(tablename)) : NULL);
+   snapshotName = (snapshotName ? (char*)(((Space*)space)->convertToOffset(snapshotName)) : NULL);
+   default_col_fam = (default_col_fam ? (char*)(((Space*)space)->convertToOffset(default_col_fam)) : NULL);
+   all_col_fams = (all_col_fams ? (char*)(((Space*)space)->convertToOffset(all_col_fams)) : NULL);
+ 
+   columns_desc.pack(space);
+   indexes_desc.pack(space);
+   constrnts_desc.pack(space);
+   views_desc.pack(space);
+   constrnts_tables_desc.pack(space);
+   referenced_tables_desc.pack(space);
+   referencing_tables_desc.pack(space);
+   histograms_desc.pack(space);
+   files_desc.pack(space);
+   hbase_regionkey_desc.pack(space);
+   sequence_generator_desc.pack(space);
+ 
+   return TrafDesc::pack(space);  
+ }
+ 
+ Lng32 TrafTableDesc::unpack(void * base, void * reallocator)
+ {
+   tablename = (tablename ? (char*)((char*)base - (Long)tablename) : NULL);
+   snapshotName = (snapshotName ? (char*)((char*)base - (Long)snapshotName) : NULL);
+   default_col_fam = (default_col_fam ? (char*)((char*)base - (Long)default_col_fam) : NULL);
+   all_col_fams = (all_col_fams ? (char*)((char*)base - (Long)all_col_fams) : NULL);
+ 
+   if (columns_desc.unpack(base, reallocator)) return -1;
+   if (indexes_desc.unpack(base, reallocator)) return -1;
+   if (constrnts_desc.unpack(base, reallocator)) return -1;
+   if (views_desc.unpack(base, reallocator)) return -1;
+   if (constrnts_tables_desc.unpack(base, reallocator)) return -1;
+   if (referenced_tables_desc.unpack(base, reallocator)) return -1;
+   if (referencing_tables_desc.unpack(base, reallocator)) return -1;
+   if (histograms_desc.unpack(base, reallocator)) return -1;
+   if (files_desc.unpack(base, reallocator)) return -1;
+   if (hbase_regionkey_desc.unpack(base, reallocator)) return -1;
+   if (sequence_generator_desc.unpack(base, reallocator)) return -1;
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafUsingMvDesc::pack(void * space)
+ {
+   mvName = (mvName ? (char*)(((Space*)space)->convertToOffset(mvName)) : NULL);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafUsingMvDesc::unpack(void * base, void * reallocator)
+ {
+   mvName = (mvName ? (char*)((char*)base - (Long)mvName) : NULL);
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }
+ 
+ Long TrafViewDesc::pack(void * space)
+ {
+   viewname = (viewname ? (char*)(((Space*)space)->convertToOffset(viewname)) : NULL);
+   viewfilename = (viewfilename ? (char*)(((Space*)space)->convertToOffset(viewfilename)) : NULL);
+ 
+   viewtext = (viewtext ? (char*)(((Space*)space)->convertToOffset(viewtext)) : NULL);
+   viewchecktext = (viewchecktext ? (char*)(((Space*)space)->convertToOffset(viewchecktext)) : NULL);
++  viewcolusages = (viewcolusages ? (char*)(((Space*)space)->convertToOffset(viewcolusages)) : NULL);
+ 
+   return TrafDesc::pack(space);
+ }
+ 
+ Lng32 TrafViewDesc::unpack(void * base, void * reallocator)
+ {
+   viewname = (viewname ? (char*)((char*)base - (Long)viewname) : NULL);
+   viewfilename = (viewfilename ? (char*)((char*)base - (Long)viewfilename) : NULL);
+ 
+   viewtext = (viewtext ? (char*)((char*)base - (Long)viewtext) : NULL);
+   viewchecktext = (viewchecktext ? (char*)((char*)base - (Long)viewchecktext) : NULL);
++  viewcolusages = (viewcolusages ? (char*)((char*)base - (Long)viewcolusages) : NULL);
+ 
+   return TrafDesc::unpack(base, reallocator);
+ }

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/sqlcat/TrafDDLdesc.h
----------------------------------------------------------------------
diff --cc core/sql/sqlcat/TrafDDLdesc.h
index 0000000,3a599e6..3b99c16
mode 000000,100644..100644
--- a/core/sql/sqlcat/TrafDDLdesc.h
+++ b/core/sql/sqlcat/TrafDDLdesc.h
@@@ -1,0 -1,1120 +1,1121 @@@
+ /**********************************************************************
+ // @@@ 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 @@@
+ //
+ **********************************************************************/
+ #ifndef TRAF_DDL_DESC_H
+ #define TRAF_DDL_DESC_H
+ 
+ #include "Platform.h"
+ #include "NAVersionedObject.h"
+ #include "charinfo.h"
+ #include "ComSmallDefs.h"
+ 
+ #define GENHEAP(h)    (h ? (NAMemory*)h : CmpCommon::statementHeap())
+ 
+ enum ConstraintType { UNIQUE_CONSTRAINT, PRIMARY_KEY_CONSTRAINT, REF_CONSTRAINT,
+ 		      CHECK_CONSTRAINT
+ 		    };
+ 
+ enum desc_nodetype {
+   DESC_UNKNOWN_TYPE = 0,
+   DESC_CHECK_CONSTRNTS_TYPE,
+   DESC_COLUMNS_TYPE,
+   DESC_CONSTRNTS_TYPE,
+   DESC_CONSTRNT_KEY_COLS_TYPE,
+   DESC_FILES_TYPE,
+   DESC_HBASE_RANGE_REGION_TYPE,
+   DESC_HISTOGRAM_TYPE,
+   DESC_HIST_INTERVAL_TYPE,
+   DESC_INDEXES_TYPE,
+   DESC_KEYS_TYPE,
+   DESC_PARTNS_TYPE,
+   DESC_REF_CONSTRNTS_TYPE,
+   DESC_TABLE_TYPE,
+   DESC_USING_MV_TYPE,  // MV  -- marks an MV using this object
+   DESC_VIEW_TYPE,
+   DESC_SCHEMA_LABEL_TYPE,
+   DESC_SEQUENCE_GENERATOR_TYPE,
+   DESC_ROUTINE_TYPE,
+   DESC_LIBRARY_TYPE
+ };
+ 
+ class TrafDesc;
+ typedef NAVersionedObjectPtrTempl<TrafDesc> DescStructPtr;
+ 
+ class TrafCheckConstrntsDesc;
+ class TrafColumnsDesc;
+ class TrafConstrntsDesc;
+ class TrafConstrntKeyColsDesc;
+ class TrafHbaseRegionDesc;
+ class TrafHistogramDesc;
+ class TrafHistIntervalDesc;
+ class TrafFilesDesc;
+ class TrafKeysDesc;
+ class TrafIndexesDesc;
+ class TrafLibraryDesc;
+ class TrafPartnsDesc;
+ class TrafRefConstrntsDesc;
+ class TrafRoutineDesc;
+ class TrafSequenceGeneratorDesc;
+ class TrafTableDesc;
+ class TrafUsingMvDesc;
+ class TrafViewDesc;
+ 
+ class TrafDesc : public NAVersionedObject {
+ public:
+   enum {CURR_VERSION = 1};
+ 
+   TrafDesc(UInt16 nodeType);
+   TrafDesc() : NAVersionedObject(-1) {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafDesc); }
+ 
+   virtual Lng32 migrateToNewVersion(NAVersionedObject *&newImage);
+ 
+   virtual char *findVTblPtr(short classID);
+ 
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   Lng32 validateSize();
+   Lng32 validateVersion();
+  
+   UInt16 nodetype;
+   UInt16 version;
+   UInt32 descFlags;
+   DescStructPtr next;
+   char* descExtension; // extension of descriptor, if it needs to be extended
+ 
+   virtual TrafCheckConstrntsDesc *checkConstrntsDesc() const { return NULL; }
+   virtual TrafColumnsDesc *columnsDesc() const { return NULL; }
+   virtual TrafConstrntsDesc *constrntsDesc() const { return NULL; }
+   virtual TrafConstrntKeyColsDesc *constrntKeyColsDesc() const { return NULL; }
+   virtual TrafFilesDesc *filesDesc() const { return NULL; }
+   virtual TrafHbaseRegionDesc *hbaseRegionDesc() const { return NULL; }
+   virtual TrafHistogramDesc *histogramDesc() const { return NULL; }
+   virtual TrafHistIntervalDesc *histIntervalDesc() const { return NULL; }
+   virtual TrafKeysDesc *keysDesc() const { return NULL; }
+   virtual TrafIndexesDesc *indexesDesc() const { return NULL; }
+   virtual TrafLibraryDesc *libraryDesc() const { return NULL; }
+   virtual TrafPartnsDesc *partnsDesc() const { return NULL; }
+   virtual TrafRefConstrntsDesc *refConstrntsDesc() const { return NULL; }
+   virtual TrafRoutineDesc *routineDesc() const { return NULL; }
+   virtual TrafSequenceGeneratorDesc *sequenceGeneratorDesc() const { return NULL; }
+   virtual TrafTableDesc *tableDesc() const { return NULL; }
+   virtual TrafUsingMvDesc *usingMvDesc() const { return NULL; }
+   virtual TrafViewDesc *viewDesc() const { return NULL; }
+ 
+ };
+ 
+ class TrafCheckConstrntsDesc : public TrafDesc {
+ public:
+   TrafCheckConstrntsDesc() : TrafDesc(DESC_CHECK_CONSTRNTS_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafCheckConstrntsDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafCheckConstrntsDesc *checkConstrntsDesc() const { return (TrafCheckConstrntsDesc*)this; }
+ 
+   char* constrnt_text;
+   char filler[16];
+ };
+ 
+ class TrafColumnsDesc : public TrafDesc {
+ public:
+   TrafColumnsDesc() : TrafDesc(DESC_COLUMNS_TYPE) 
+   {};
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafColumnsDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafColumnsDesc *columnsDesc() const { return (TrafColumnsDesc*)this; }
+ 
+   enum ColumnsDescFlags
+     { 
+       NULLABLE           = 0x0001,  
+       ADDED              = 0x0002,
+       UPSHIFTED          = 0x0004,
+       CASEINSENSITIVE    = 0x0008,
+       OPTIONAL           = 0x0010
+     };
+ 
+   void setNullable(NABoolean v) 
+   {(v ? columnsDescFlags |= NULLABLE : columnsDescFlags &= ~NULLABLE); };
+   NABoolean isNullable() { return (columnsDescFlags & NULLABLE) != 0; };
+ 
+   void setAdded(NABoolean v) 
+   {(v ? columnsDescFlags |= ADDED : columnsDescFlags &= ~ADDED); };
+   NABoolean isAdded() { return (columnsDescFlags & ADDED) != 0; };
+ 
+   void setUpshifted(NABoolean v) 
+   {(v ? columnsDescFlags |= UPSHIFTED : columnsDescFlags &= ~UPSHIFTED); };
+   NABoolean isUpshifted() { return (columnsDescFlags & UPSHIFTED) != 0; };
+ 
+   void setCaseInsensitive(NABoolean v) 
+   {(v ? columnsDescFlags |= CASEINSENSITIVE : columnsDescFlags &= ~CASEINSENSITIVE); };
+   NABoolean isCaseInsensitive() { return (columnsDescFlags & CASEINSENSITIVE) != 0; };
+ 
+   void setOptional(NABoolean v) 
+   {(v ? columnsDescFlags |= OPTIONAL : columnsDescFlags &= ~OPTIONAL); };
+   NABoolean isOptional() { return (columnsDescFlags & OPTIONAL) != 0; };
+ 
+   rec_datetime_field datetimeStart() 
+   { return (rec_datetime_field)datetimestart;}
+   rec_datetime_field datetimeEnd() 
+   { return (rec_datetime_field)datetimeend;}
+ 
+   ComColumnDefaultClass defaultClass() 
+   { return (ComColumnDefaultClass)defaultClass_;}
+   void setDefaultClass(ComColumnDefaultClass v)
+   { defaultClass_ = (Int16)v;}
+ 
+   CharInfo::CharSet characterSet() 
+   { return (CharInfo::CharSet)character_set;}
+   CharInfo::CharSet encodingCharset() 
+   { return (CharInfo::CharSet)encoding_charset;}
+   CharInfo::Collation  collationSequence()
+   {return (CharInfo::Collation)collation_sequence; }
+ 
+   ComParamDirection paramDirection() 
+   { return (ComParamDirection)paramDirection_;}
+   void setParamDirection(ComParamDirection v)
+   {paramDirection_ = (Int16)v; }
+ 
+   char* colname;
+ 
+   Int32 colnumber;
+   Int32 datatype;
+ 
+   Int32 offset;
+   Lng32 length;
+ 
+   Lng32 scale;
+   Lng32 precision;
+ 
+   Int16/*rec_datetime_field*/ datetimestart, datetimeend;
+   Int16 datetimefractprec, intervalleadingprec;
+ 
+   Int16/*ComColumnDefaultClass*/ defaultClass_;
+   Int16/*CharInfo::CharSet*/     character_set;
+   Int16/*CharInfo::CharSet*/     encoding_charset;
+   Int16/*CharInfo::Collation*/   collation_sequence;
+ 
+   ULng32 hbaseColFlags;
+   Int16/*ComParamDirection*/ paramDirection_;
+   char colclass; // 'S' -- system generated, 'U' -- user created
+   char filler0;
+ 
+   Int64 colFlags;
+   Int64 columnsDescFlags; // my flags
+ 
+   char* pictureText;
+   char* defaultvalue;
+   char* heading;
+   char* computed_column_text;
+   char* hbaseColFam;
+   char* hbaseColQual;
+ 
+   char filler[24];
+ };
+ 
+ class TrafConstrntKeyColsDesc : public TrafDesc {
+ public:
+   TrafConstrntKeyColsDesc() : TrafDesc(DESC_CONSTRNT_KEY_COLS_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafConstrntKeyColsDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafConstrntKeyColsDesc *constrntKeyColsDesc() const { return (TrafConstrntKeyColsDesc*)this; }
+ 
+   char* colname;
+   Int32  position;
+ 
+   Int64 constrntKeyColsDescFlags; // my flags
+ 
+   char filler[16];
+ };
+ 
+ class TrafConstrntsDesc : public TrafDesc {
+ public:
+   TrafConstrntsDesc() : TrafDesc(DESC_CONSTRNTS_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafConstrntsDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafConstrntsDesc *constrntsDesc() const { return (TrafConstrntsDesc*)this; }
+ 
+   enum ConstrntsDescFlags
+     { 
+       ENFORCED           = 0x0001
+     };
+ 
+   void setEnforced(NABoolean v) 
+   {(v ? constrntsDescFlags |= ENFORCED : constrntsDescFlags &= ~ENFORCED); };
+   NABoolean isEnforced() { return (constrntsDescFlags & ENFORCED) != 0; };
+ 
+   char* constrntname;
+   char* tablename;
+ 
+   Int16 /*ConstraintType*/ type;
+   Int16 fillerInt16;
+   Int32  colcount;
+ 
+   Int64 constrntsDescFlags; // my flags
+ 
+   DescStructPtr check_constrnts_desc;
+   DescStructPtr constr_key_cols_desc;
+   DescStructPtr referenced_constrnts_desc;
+   DescStructPtr referencing_constrnts_desc;
+ 
+   char filler[24];
+ };
+ 
+ class TrafFilesDesc : public TrafDesc {
+ public:
+   TrafFilesDesc() : TrafDesc(DESC_FILES_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafFilesDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafFilesDesc *filesDesc() const { return (TrafFilesDesc*)this; }
+ 
+   enum FilesDescFlags
+     { 
+       AUDITED           = 0x0001
+     };
+ 
+   void setAudited(NABoolean v) 
+   {(v ? filesDescFlags |= AUDITED : filesDescFlags &= ~AUDITED); };
+   NABoolean isAudited() { return (filesDescFlags & AUDITED) != 0; };
+ 
+   Int64 filesDescFlags; // my flags
+   DescStructPtr partns_desc;
+ };
+ 
+ class TrafHbaseRegionDesc : public TrafDesc {
+ public:
+   TrafHbaseRegionDesc() : TrafDesc(DESC_HBASE_RANGE_REGION_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafHbaseRegionDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafHbaseRegionDesc *hbaseRegionDesc() const { return (TrafHbaseRegionDesc*)this; }
+ 
+   Int64  hbaseRegionDescFlags; // my flags
+ 
+   Lng32  beginKeyLen;
+   Lng32  endKeyLen;
+ 
+   char*  beginKey;
+   char*  endKey;
+ 
+   char filler[16];
+ };
+ 
+ class TrafHistogramDesc : public TrafDesc {
+ public:
+   TrafHistogramDesc() : TrafDesc(DESC_HISTOGRAM_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafHistogramDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafHistogramDesc *histogramDesc() const { return (TrafHistogramDesc*)this; }
+ 
+   char*   tablename;
+   char*   histid;
+ 
+   Int32   tablecolnumber;
+   Int32   colposition;
+ 
+   Float32 rowcount;
+   Float32 uec;
+ 
+   char*   highval;
+   char*   lowval;
+ 
+   Int64 histogramDescFlags; // my flags
+ 
+   DescStructPtr hist_interval_desc;
+ 
+   char filler[24];
+ };
+ 
+ class TrafHistIntervalDesc : public TrafDesc {
+ public:
+   TrafHistIntervalDesc() : TrafDesc(DESC_HIST_INTERVAL_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafHistIntervalDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafHistIntervalDesc *histIntervalDesc() const { return (TrafHistIntervalDesc*)this; }
+ 
+   char*   histid;
+   char*   intboundary;
+ 
+   Float32  rowcount;
+   Float32  uec;
+ 
+   Int32   intnum;
+   Int32   fillerInt32;
+ 
+   Int64 histIntervalDescFlags; // my flags
+ 
+   char filler[16];
+ };
+ 
+ class TrafIndexesDesc : public TrafDesc {
+ public:
+   TrafIndexesDesc() : TrafDesc(DESC_INDEXES_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafIndexesDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafIndexesDesc *indexesDesc() const { return (TrafIndexesDesc*)this; }
+ 
+   enum IndexesDescFlags
+     { 
+       SYSTEM_TABLE_CODE = 0x0001,  
+       EXPLICIT          = 0x0002,
+       VOLATILE          = 0x0004,
+       IN_MEM_OBJ        = 0x0008,
+       UNIQUE            = 0x0010
+     };
+ 
+   void setSystemTableCode(NABoolean v) 
+   {(v ? indexesDescFlags |= SYSTEM_TABLE_CODE : indexesDescFlags &= ~SYSTEM_TABLE_CODE); };
+   NABoolean isSystemTableCode() { return (indexesDescFlags & SYSTEM_TABLE_CODE) != 0; };
+ 
+   void setExplicit(NABoolean v) 
+   {(v ? indexesDescFlags |= EXPLICIT : indexesDescFlags &= ~EXPLICIT); };
+   NABoolean isExplicit() { return (indexesDescFlags & EXPLICIT) != 0; };
+ 
+   void setVolatile(NABoolean v) 
+   {(v ? indexesDescFlags |= VOLATILE : indexesDescFlags &= ~VOLATILE); };
+   NABoolean isVolatile() { return (indexesDescFlags & VOLATILE) != 0; };
+ 
+   void setInMemoryObject(NABoolean v) 
+   {(v ? indexesDescFlags |= IN_MEM_OBJ : indexesDescFlags &= ~IN_MEM_OBJ); };
+   NABoolean isInMemoryObject() { return (indexesDescFlags & IN_MEM_OBJ) != 0; };
+ 
+   void setUnique(NABoolean v) 
+   {(v ? indexesDescFlags |= UNIQUE : indexesDescFlags &= ~UNIQUE); };
+   NABoolean isUnique() { return (indexesDescFlags & UNIQUE) != 0; };
+ 
+   ComPartitioningScheme partitioningScheme() 
+   { return (ComPartitioningScheme)partitioningScheme_; }
+   void setPartitioningScheme(ComPartitioningScheme v) 
+   { partitioningScheme_ = (Int16)v; }
+   ComRowFormat rowFormat() { return (ComRowFormat)rowFormat_; }
+   void setRowFormat(ComRowFormat v) { rowFormat_ = (Int16)v; }
+ 
+   char* tablename;  // name of the base table
+   char* indexname;  // physical name of index. Different from ext_indexname
+                     // for ARK tables.
+   Int64 indexUID;
+ 
+   Int32 keytag;
+   Int32 record_length;
+   Int32 colcount;
+   Int32 blocksize;
+ 
+   Int16 /*ComPartitioningScheme*/ partitioningScheme_; 
+   Int16 /*ComRowFormat*/          rowFormat_;
+   Lng32 numSaltPartns; // number of salted partns created for a seabase table.
+ 
+   Int64 indexesDescFlags; // my flags
+ 
+   char*  hbaseCreateOptions;
+ 
+   DescStructPtr files_desc;
+ 
+   // Clustering keys columns
+   DescStructPtr keys_desc;
+ 
+   // Columns that are not part of the clustering key.
+   // Used specially for vertical partition column(s).
+   DescStructPtr non_keys_desc;
+ 
+   char filler[24];
+ };
+ 
+ class TrafKeysDesc : public TrafDesc {
+ public:
+   TrafKeysDesc() : TrafDesc(DESC_KEYS_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafKeysDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafKeysDesc *keysDesc() const { return (TrafKeysDesc*)this; }
+ 
+   enum KeysDescFlags
+     { 
+       DESCENDING           = 0x0001
+     };
+ 
+   void setDescending(NABoolean v) 
+   {(v ? keysDescFlags |= DESCENDING : keysDescFlags &= ~DESCENDING); };
+   NABoolean isDescending() { return (keysDescFlags & DESCENDING) != 0; };
+ 
+   char* keyname;
+   Int32 keyseqnumber;
+   Int32 tablecolnumber;
+ 
+   Int64 keysDescFlags; // my flags
+ 
+   char* hbaseColFam;
+   char* hbaseColQual;
+ 
+   char filler[16];
+ };
+ 
+ class TrafLibraryDesc : public TrafDesc {
+ public:
+   TrafLibraryDesc() : TrafDesc(DESC_LIBRARY_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafLibraryDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafLibraryDesc *libraryDesc() const { return (TrafLibraryDesc*)this; }
+ 
+   char* libraryName;
+   char* libraryFilename;
+   Int64 libraryUID;
+   Int32 libraryVersion;
+   Int32 libraryOwnerID;
+   Int32 librarySchemaOwnerID;
+ 
+   char filler[20];
+ };
+ 
+ class TrafPartnsDesc : public TrafDesc {
+ public:
+   TrafPartnsDesc() : TrafDesc(DESC_PARTNS_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafPartnsDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafPartnsDesc *partnsDesc() const { return (TrafPartnsDesc*)this; }
+ 
+   char*  tablename;
+   Int32 primarypartition;
+   char*  partitionname;
+   char*  logicalpartitionname;
+   char*  firstkey;
+   Lng32 firstkeylen;         //soln:10-031112-1256
+   Lng32 encodedkeylen;
+   char*  encodedkey;
+   char*  lowKey;
+   char*  highKey;
+   Int32    indexlevel;
+   Int32  priExt;
+   Int32  secExt;
+   Int32  maxExt;
+   char*  givenname;
+ };
+ 
+ class TrafRefConstrntsDesc : public TrafDesc {
+ public:
+   TrafRefConstrntsDesc() : TrafDesc(DESC_REF_CONSTRNTS_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafRefConstrntsDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafRefConstrntsDesc *refConstrntsDesc() const { return (TrafRefConstrntsDesc*)this; }
+ 
+   Int64 refConstrntsDescFlags; // my flags
+   char* constrntname;
+   char* tablename;
+ 
+   char filler[16];
+ };
+ 
+ class TrafRoutineDesc : public TrafDesc {
+ public:
+   TrafRoutineDesc() : TrafDesc(DESC_ROUTINE_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafRoutineDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafRoutineDesc *routineDesc() const { return (TrafRoutineDesc*)this; }
+ 
+   Int64 objectUID;
+   char* routineName;
+   char* externalName;
+   char* librarySqlName;
+   char* libraryFileName;
+   char* signature;
+   ComSInt32 paramsCount;
+   DescStructPtr params;
+   ComRoutineLanguage language;
+   ComRoutineType UDRType;
+   ComRoutineSQLAccess sqlAccess;
+   ComRoutineTransactionAttributes transactionAttributes;
+   ComSInt32 maxResults;
+   ComRoutineParamStyle paramStyle;
+   NABoolean isDeterministic;
+   NABoolean isCallOnNull;
+   NABoolean isIsolate;
+   ComRoutineExternalSecurity externalSecurity;
+   ComRoutineExecutionMode executionMode;
+   Int32 stateAreaSize;
+   ComRoutineParallelism parallelism;
+   Int32 owner;
+   Int32 schemaOwner;
+ 
+   Int64 routineDescFlags; // my flags
+ 
+   char filler[24];
+ };
+ 
+ class TrafSequenceGeneratorDesc : public TrafDesc {
+ public:
+   TrafSequenceGeneratorDesc() : TrafDesc(DESC_SEQUENCE_GENERATOR_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafSequenceGeneratorDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafSequenceGeneratorDesc *sequenceGeneratorDesc() const { return (TrafSequenceGeneratorDesc*)this; }
+ 
+   ComSequenceGeneratorType sgType() 
+   { return (ComSequenceGeneratorType)sgType_; }
+   void setSgType(ComSequenceGeneratorType v) 
+   { sgType_ = (Int16)v; }
+ 
+   Int64                     startValue;
+   Int64                     increment;
+ 
+   Int16 /*ComSequenceGeneratorType*/  sgType_;
+   Int16 /*ComSQLDataType*/  sqlDataType;
+   Int16 /*ComFSDataType*/   fsDataType;
+   Int16                     cycleOption;
+ 
+   Int64                     maxValue;
+   Int64                     minValue;
+   Int64                     cache;
+   Int64                     objectUID;
+   char*                     sgLocation;
+   Int64                     nextValue;
+   Int64                     redefTime;
+ 
+   Int64 sequenceGeneratorDescFlags; // my flags
+ 
+   char filler[16];
+ };
+ 
+ class TrafTableDesc : public TrafDesc {
+ public:
+   TrafTableDesc() : TrafDesc(DESC_TABLE_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafTableDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafTableDesc *tableDesc() const { return (TrafTableDesc*)this; }
+ 
+   enum TableDescFlags
+     { 
+       SYSTEM_TABLE_CODE = 0x0001,  
+       UMD_TABLE         = 0x0002,
+       MV_TABLE          = 0x0004,
+       IUD_LOG           = 0x0008,
+       MV_MD_OBJECT      = 0x0010,
+       SYN_TRANS_DONE    = 0x0020,
+       VOLATILE          = 0x0040,
+       IN_MEM_OBJ        = 0x0080,
+       DROPPABLE         = 0x0100,
+       INSERT_ONLY       = 0x0200
+     };
+ 
+   void setSystemTableCode(NABoolean v) 
+   {(v ? tableDescFlags |= SYSTEM_TABLE_CODE : tableDescFlags &= ~SYSTEM_TABLE_CODE); };
+   NABoolean isSystemTableCode() { return (tableDescFlags & SYSTEM_TABLE_CODE) != 0; };
+ 
+   void setUMDTable(NABoolean v) 
+   {(v ? tableDescFlags |= UMD_TABLE : tableDescFlags &= ~UMD_TABLE); };
+   NABoolean isUMDTable() { return (tableDescFlags & UMD_TABLE) != 0; };
+ 
+   void setMVTable(NABoolean v) 
+   {(v ? tableDescFlags |= MV_TABLE : tableDescFlags &= ~MV_TABLE); };
+   NABoolean isMVTable() { return (tableDescFlags & MV_TABLE) != 0; };
+ 
+   void setIUDLog(NABoolean v) 
+   {(v ? tableDescFlags |= IUD_LOG : tableDescFlags &= ~IUD_LOG); };
+   NABoolean isIUDLog() { return (tableDescFlags & IUD_LOG) != 0; };
+ 
+   void setMVMetadataObject(NABoolean v) 
+   {(v ? tableDescFlags |= MV_MD_OBJECT : tableDescFlags &= ~MV_MD_OBJECT); };
+   NABoolean isMVMetadataObject() { return (tableDescFlags & MV_MD_OBJECT) != 0; };
+ 
+   void setSynonymTranslationDone(NABoolean v) 
+   {(v ? tableDescFlags |= SYN_TRANS_DONE : tableDescFlags &= ~SYN_TRANS_DONE); };
+   NABoolean isSynonymTranslationDone() { return (tableDescFlags & SYN_TRANS_DONE) != 0; };
+ 
+   void setVolatileTable(NABoolean v) 
+   {(v ? tableDescFlags |= VOLATILE : tableDescFlags &= ~VOLATILE); };
+   NABoolean isVolatileTable() { return (tableDescFlags & VOLATILE) != 0; };
+ 
+   void setInMemoryObject(NABoolean v) 
+   {(v ? tableDescFlags |= IN_MEM_OBJ : tableDescFlags &= ~IN_MEM_OBJ); };
+   NABoolean isInMemoryObject() { return (tableDescFlags & IN_MEM_OBJ) != 0; };
+ 
+   void setDroppable(NABoolean v) 
+   {(v ? tableDescFlags |= DROPPABLE : tableDescFlags &= ~DROPPABLE); };
+   NABoolean isDroppable() { return (tableDescFlags & DROPPABLE) != 0; };
+ 
+   void setInsertOnly(NABoolean v) 
+   {(v ? tableDescFlags |= INSERT_ONLY : tableDescFlags &= ~INSERT_ONLY); };
+   NABoolean isInsertOnly() { return (tableDescFlags & INSERT_ONLY) != 0; };
+ 
+   ComInsertMode insertMode() { return (ComInsertMode)insertMode_;}
+   void setInsertMode(ComInsertMode v) {insertMode_ = (Int16)v;}
+ 
+   ComPartitioningScheme partitioningScheme() 
+   { return (ComPartitioningScheme)partitioningScheme_; }
+   void setPartitioningScheme(ComPartitioningScheme v) 
+   { partitioningScheme_ = (Int16)v; }
+   ComRowFormat rowFormat() { return (ComRowFormat)rowFormat_; }
+   void setRowFormat(ComRowFormat v) { rowFormat_ = (Int16)v; }
+   ComObjectType objectType() { return (ComObjectType)objectType_; }
+   void setObjectType(ComObjectType v) { objectType_ = (Int16)v; }
+ 
+   char* tablename;
+ 
+   Int64 createTime;
+   Int64 redefTime;
+   Int64 cacheTime;
+ 
+   Int32 mvAttributesBitmap;
+   Int32 record_length;
+   Int32 colcount;
+   Int32 constr_count;
+ 
+   Int16 /*ComInsertMode*/ insertMode_;
+   Int16 /*ComPartitioningScheme*/ partitioningScheme_; 
+   Int16 /*ComRowFormat*/  rowFormat_;
+   Int16 /*ComObjectType*/ objectType_; 
+ 
+   Int64 catUID;
+   Int64 schemaUID;
+   Int64 objectUID;
+ 
+   Lng32 owner;
+   Lng32 schemaOwner;
+ 
+   char*  snapshotName;
+   char*  default_col_fam;
+   char*  all_col_fams;
+   Int64 objectFlags;
+   Int64 tablesFlags;
+ 
+   Int64 tableDescFlags; // my flags
+ 
+   DescStructPtr columns_desc;
+   DescStructPtr indexes_desc;
+   DescStructPtr constrnts_desc;
+   DescStructPtr views_desc;
+   DescStructPtr constrnts_tables_desc;
+   DescStructPtr referenced_tables_desc;
+   DescStructPtr referencing_tables_desc;
+   DescStructPtr histograms_desc;
+   DescStructPtr files_desc;
+ 
+   // for hbase's region keys
+   DescStructPtr hbase_regionkey_desc;
+   DescStructPtr sequence_generator_desc;
+ 
+   char filler[32];
+ };
+ 
+ class TrafUsingMvDesc : public TrafDesc {
+ public:
+   TrafUsingMvDesc() : TrafDesc(DESC_USING_MV_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafUsingMvDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafUsingMvDesc *usingMvDesc() const { return (TrafUsingMvDesc*)this; }
+ 
+   ComMVRefreshType refreshType() { return (ComMVRefreshType)refreshType_;}
+   void setRefreshType(ComMVRefreshType v) 
+   { refreshType_ = (Int16)v;}
+ 
+   char* mvName;
+   Int32  rewriteEnabled;
+   Int32  isInitialized;
+   Int16 /*ComMVRefreshType*/ refreshType_; // unknown here means "non incremental"
+ 
+   char filler[14];
+ };
+ 
+ class TrafViewDesc : public TrafDesc {
+ public:
+   TrafViewDesc() : TrafDesc(DESC_VIEW_TYPE)
+   {}
+ 
+   // ---------------------------------------------------------------------
+   // Redefine virtual functions required for Versioning.
+   //----------------------------------------------------------------------
+   virtual unsigned char getClassVersionID()
+   {
+     return 1;
+   }
+ 
+   virtual void populateImageVersionIDArray()
+   {
+     setImageVersionID(0,getClassVersionID());
+   }
+ 
+   virtual short getClassSize()      { return (short)sizeof(TrafViewDesc); }
+  
+   virtual Long pack(void *space);
+   virtual Lng32 unpack(void * base, void * reallocator);
+ 
+   virtual TrafViewDesc *viewDesc() const { return (TrafViewDesc*)this; }
+ 
+   enum ViewDescFlags
+     { 
+       UPDATABLE           = 0x0001,
+       INSERTABLE          = 0x0002
+     };
+ 
+   void setUpdatable(NABoolean v) 
+   {(v ? viewDescFlags |= UPDATABLE : viewDescFlags &= ~UPDATABLE); };
+   NABoolean isUpdatable() { return (viewDescFlags & UPDATABLE) != 0; };
+ 
+   void setInsertable(NABoolean v) 
+   {(v ? viewDescFlags |= INSERTABLE : viewDescFlags &= ~INSERTABLE); };
+   NABoolean isInsertable() { return (viewDescFlags & INSERTABLE) != 0; };
+ 
+   char*  viewname;
+   char*  viewfilename;    // the physical file, to be Opened for auth-cking.
+   char*  viewtext;
+   char*  viewchecktext;
++  char*  viewcolusages;
+ 
+   Int64 viewDescFlags; // my flags
+ 
+   Int16 /*CharInfo::CharSet*/ viewtextcharset;
+ 
+   char filler[22];
+ };
+ 
+ // if space is passed in, use it. Otherwise use HEAP of CmpCommon
+ TrafDesc *TrafAllocateDDLdesc(desc_nodetype nodetype, 
+                                  Space *space);
+ 
+ TrafDesc *TrafMakeColumnDesc
+ (
+      const char *tablename,
+      const char *colname,
+      Lng32 &colnumber,		  // INOUT
+      Int32 datatype,
+      Lng32 length,
+      Lng32 &offset,		  // INOUT
+      NABoolean null_flag,
+      SQLCHARSET_CODE datacharset, // i.e., use CharInfo::DefaultCharSet;
+      Space * space
+  );
+ 
+ #endif

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/sqlcomp/CmpDDLCatErrorCodes.h
----------------------------------------------------------------------
diff --cc core/sql/sqlcomp/CmpDDLCatErrorCodes.h
index d79bf2a,25f439c..55d0468
--- a/core/sql/sqlcomp/CmpDDLCatErrorCodes.h
+++ b/core/sql/sqlcomp/CmpDDLCatErrorCodes.h
@@@ -59,7 -59,7 +59,7 @@@ enum CatErrorCode { CAT_FIRST_ERROR = 1
                    , CAT_FS_ERROR                                  = 1024
                    , CAT_DEPENDENT_OBJECTS_EXIST                   = 1025
                    , CAT_SCHEMA_ID_AND_USER_ID_DO_NOT_MATCH        = 1026
--                  , CAT_DEFINITION_SCHEMA_CAN_NOT_BE_DROPPED_BY_USER
++                  , CAT_COLUMN_PRIVILEGE_NOT_ALLOWED              = 1027
                    , CAT_SCHEMA_IS_NOT_EMPTY                       = 1028
                    , CAT_UNABLE_TO_CREATE_OBJECT                   = 1029
                    , CAT_HBASE_NAME_TOO_LONG                       = 1030

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/sqlcomp/CmpSeabaseDDL.h
----------------------------------------------------------------------
diff --cc core/sql/sqlcomp/CmpSeabaseDDL.h
index 4d71dff,3b583e7..594a9eb
--- a/core/sql/sqlcomp/CmpSeabaseDDL.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDL.h
@@@ -826,7 -852,6 +856,7 @@@ protected
    short gatherViewPrivileges (const StmtDDLCreateView * createViewParseNode,
                                ExeCliInterface * cliInterface,
                                NABoolean viewCreator,
-                               Int32 schemaID,
++                              Int32 userID,
                                PrivMgrBitmap &privilegesBitmap,
                                PrivMgrBitmap &grantableBitmap);
  

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
----------------------------------------------------------------------
diff --cc core/sql/sqlcomp/CmpSeabaseDDLview.cpp
index 8211b4a,b423d9b..f9c5c33
--- a/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
@@@ -68,7 -66,6 +67,7 @@@ static bool checkAccessPrivileges
     const ParTableUsageList & vtul,
     const ParViewColTableColsUsageList & vctcul,
     NABoolean viewCreator,
-    Int32 schemaID,
++   Int32 userID,
     PrivMgrBitmap & privilegesBitmap,
     PrivMgrBitmap & grantableBitmap);
  
@@@ -429,8 -367,6 +428,8 @@@ short CmpSeabaseDDL::updateViewUsage(St
  //    createViewNode - for list of objects and isUpdatable/isInsertable flags
  //    cliInterface - used to get UID of referenced object
  //    viewCreator - determines which authID to use to gather privs
- //    schemaID - schemaID to use when root is performing operations on behalf 
++//    userID - userID to use when root is performing operations on behalf 
 +//      of another user.
  //    privilegeBitmap - returns privileges this user has on the view
  //    grantableBitmap - returns privileges this user can grant
  //
@@@ -441,7 -377,6 +440,7 @@@
  short CmpSeabaseDDL::gatherViewPrivileges (const StmtDDLCreateView * createViewNode,
  				           ExeCliInterface * cliInterface,
                                             NABoolean viewCreator,
-                                            Int32 schemaID,
++                                           Int32 userID,
                                             PrivMgrBitmap &privilegesBitmap,
                                             PrivMgrBitmap &grantableBitmap)
  {
@@@ -459,7 -394,8 +458,7 @@@
    const ParViewColTableColsUsageList &vctcul = vu.getViewColTableColsUsageList();
  
    // If DB__ROOT, no need to gather privileges
-   if (!checkAccessPrivileges(vtul,vctcul,viewCreator,schemaID,privilegesBitmap,grantableBitmap))
 -  if (!ComUser::isRootUserID() && 
 -      !checkAccessPrivileges(vtul,vctcul,viewCreator,privilegesBitmap,grantableBitmap))
++  if (!checkAccessPrivileges(vtul,vctcul,viewCreator,userID,privilegesBitmap,grantableBitmap))
      return -1;
  
    // If view is not updatable or insertable, turn off privs in bitmaps
@@@ -1534,6 -1457,6 +1544,10 @@@ short CmpSeabaseDDL::dropMetadataViews(
  // *    If TRUE, gather privileges for the view creator, if FALSE,             *
  // *    gather privileges for the view owner                                   *
  // *                                                                           *
++// *  <userID>               Int32                                  In         *
++// *     userID to use when root is performing operations on behalf            *
++// *     of another user.                                                      *
++// *                                                                           *
  // *  <privilegesBitmap>       PrivMgrBitmap &                        Out      *
  // *    passes back the union of privileges the user has on the referenced     *
  // *    objects.                                                               *
@@@ -1555,21 -1478,20 +1569,20 @@@ static bool checkAccessPrivileges
     const ParTableUsageList & vtul,
     const ParViewColTableColsUsageList & vctcul,
     NABoolean viewCreator,
-    Int32 schemaID,
++   Int32 userID,
     PrivMgrBitmap & privilegesBitmap,
     PrivMgrBitmap & grantableBitmap)
     
  {
    BindWA bindWA(ActiveSchemaDB(),CmpCommon::context(),FALSE/*inDDL*/);
--  bool missingPrivilege = false;
--  NAString extUsedObjName;
++  PrivStatus retcode = STATUS_GOOD;
  
    NAString privMgrMDLoc;
    CONCAT_CATSCH(privMgrMDLoc,CmpSeabaseDDL::getSystemCatalogStatic(),SEABASE_PRIVMGR_SCHEMA);
    PrivMgrCommands privInterface(std::string(privMgrMDLoc.data()),
                                  CmpCommon::diags());
  
--  // generate the lists of privileges and grantable privileges
++  // generate the list of privileges and grantable privileges to assign to the view
    // a side effect is to return an error if basic privileges are not granted
     for (CollIndex i = 0; i < vtul.entries(); i++)
     {
@@@ -1579,7 -1501,7 +1592,7 @@@
        const NAString catalogNamePart = usedObjName.getCatalogNamePartAsAnsiString();
        const NAString schemaNamePart = usedObjName.getSchemaNamePartAsAnsiString(TRUE);
        const NAString objectNamePart = usedObjName.getObjectNamePartAsAnsiString(TRUE);
--      NAString extUsedObjName = usedObjName.getExternalName(TRUE);
++      NAString refdUsedObjName = usedObjName.getExternalName(TRUE);
        CorrName cn(objectNamePart,STMTHEAP, schemaNamePart,catalogNamePart);
   
        // If a sequence, set correct type to get a valid NATable entry
@@@ -1590,7 -1512,7 +1603,7 @@@
        NATable *naTable = bindWA.getNATable(cn);
        if (naTable == NULL)
        {
--          SEABASEDDL_INTERNAL_ERROR("Bad NATable pointer in checkAccessPrivileges");
++         SEABASEDDL_INTERNAL_ERROR("Bad NATable pointer in checkAccessPrivileges");
           return false; 
        }
  
@@@ -1602,28 -1523,8 +1614,28 @@@
        // contains the privileges we want to use to create bitmaps
        if (viewCreator)
        {
 -        pPrivInfo = naTable->getPrivInfo();
 -        CMPASSERT(pPrivInfo != NULL);
 +        // If the viewCreator is not the current user (DB__ROOT running request)
 +        // on behalf of the schema owner), get actual owner privs.
 +        if (ComUser::isRootUserID() &&
 +            ComUser::getRootUserID() != naTable->getSchemaOwner())
 +        {
 +          retcode = privInterface.getPrivileges((int64_t)naTable->objectUid().get_value(),
 +                                                 naTable->getObjectType(),
-                                                  schemaID,
++                                                 userID,
 +                                                 privs);
 +
 +          if (retcode == STATUS_ERROR)
 +          {         
 +             *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_RETRIEVE_PRIVS);
 +             return false;
 +          }
 +          pPrivInfo = &privs;
 +        }
 +        else
 +        {
 +          pPrivInfo = naTable->getPrivInfo();
 +          CMPASSERT(pPrivInfo != NULL);
 +        }
        }
        
        // If the view owner is not the view creator, then we need to get schema
@@@ -1645,140 -1546,119 +1657,78 @@@
  
        // Requester must have at least select privilege
        // For sequence generators USAGE is needed instead of SELECT
++      bool noObjRequiredPriv = true;
        if  (isSeq)
--        missingPrivilege = !pPrivInfo->hasUsagePriv() ? true : false;
++        noObjRequiredPriv = !pPrivInfo->hasUsagePriv() ? true : false;
        else  
--        missingPrivilege = !pPrivInfo->hasSelectPriv() ? true : false; 
++        noObjRequiredPriv = !pPrivInfo->hasSelectPriv() ? true : false; 
  
        // Summarize privileges
        privilegesBitmap &= pPrivInfo->getObjectBitmap();
        grantableBitmap &= pPrivInfo->getGrantableBitmap();
--   }
     
-    PrivColumnBitmap colPrivBitmap;
-    PrivColumnBitmap colGrantableBitmap;
- 
-    PrivMgrPrivileges::setColumnPrivs(colPrivBitmap);
-    PrivMgrPrivileges::setColumnPrivs(colGrantableBitmap);
- 
-    //  To create a view you need at least select privilege, missingPrivilege
 -   //  To create a view you need at least select privilege, noSelectPriv
--   //  is true if the auth ID does not have select privilege at the object
--   //  level.  The view can still be created if select exists at the column
--   //  level.
--   bool noObjPriv = missingPrivilege;
--   missingPrivilege = false;   
- 
 -      
--   // Gather column level privs to attach to the bitmap.
--   // Even though privileges are granted on the column, they show up as
--   // object privileges on the view.
 -   PrivColumnBitmap colPrivBitmap;
 -   PrivColumnBitmap colGrantableBitmap;
 -
 -   PrivMgrPrivileges::setColumnPrivs(colPrivBitmap);
 -   PrivMgrPrivileges::setColumnPrivs(colGrantableBitmap);
 -
--   for (size_t i = 0; i < vctcul.entries(); i++)
--   {
--      const ParViewColTableColsUsage &vctcu = vctcul[i];
--      int32_t usingColNum = vctcu.getUsingViewColumnNumber();
--      const ColRefName &usedColRef = vctcu.getUsedObjectColumnName();
--      
--      ComObjectName usedObjName;
--
--      usedObjName = usedColRef.getCorrNameObj().getQualifiedNameObj().
--                    getQualifiedNameAsAnsiString();
--
--      const NAString catalogNamePart = usedObjName.getCatalogNamePartAsAnsiString();
--      const NAString schemaNamePart = usedObjName.getSchemaNamePartAsAnsiString(TRUE);
--      const NAString objectNamePart = usedObjName.getObjectNamePartAsAnsiString(TRUE);
--      extUsedObjName = usedObjName.getExternalName(TRUE);
--      CorrName cn(objectNamePart,STMTHEAP,schemaNamePart,catalogNamePart);
--
--      NATable *naTable = bindWA.getNATable(cn);
--      if (naTable == NULL)
-       {
-          SEABASEDDL_INTERNAL_ERROR("Bad NATable pointer in checkAccessPrivileges");
-          return -1; 
-       }
- 
-       const NAColumnArray &nacolArr = naTable->getNAColumnArray();
-       ComString usedObjColName(usedColRef.getColName());
-       const NAColumn * naCol = nacolArr.getColumn(usedObjColName);
-       if (naCol == NULL)
++      // Gather column level privs to attach to the bitmap.
++      // Even though privileges are granted on the column, they show up as
++      // object privileges on the view.
++      PrivColumnBitmap colPrivBitmap;
++      PrivColumnBitmap colGrantableBitmap;
++
++      PrivMgrPrivileges::setColumnPrivs(colPrivBitmap);
++      PrivMgrPrivileges::setColumnPrivs(colGrantableBitmap);
++
++      // Check for column privileges on each view column 
++      // This loop is performed for each object referenced by the view.
++      // Only those columns that belong to the referenced object have their
++      // privileges summarized.
++      for (size_t i = 0; i < vctcul.entries(); i++)
        {
 -         SEABASEDDL_INTERNAL_ERROR("Bad NATable pointer in checkAccessPrivileges");
 -         return -1; 
 -      }
 -
 -      const NAColumnArray &nacolArr = naTable->getNAColumnArray();
 -      ComString usedObjColName(usedColRef.getColName());
 -      const NAColumn * naCol = nacolArr.getColumn(usedObjColName);
 -      if (naCol == NULL)
 -      {
--         *CmpCommon::diags() << DgSqlCode(-CAT_COLUMN_DOES_NOT_EXIST_ERROR)
--                             << DgColumnName(usedObjColName);
--         return false;
--      }
--      int32_t usedColNumber = naCol->getPosition();
++         const ParViewColTableColsUsage &vctcu = vctcul[i];
++         const ColRefName &usedColRef = vctcu.getUsedObjectColumnName();
++         ComObjectName usedObjName = 
++            usedColRef.getCorrNameObj().getQualifiedNameObj().getQualifiedNameAsAnsiString();
++         NAString colUsedObjName = usedObjName.getExternalName(TRUE);
++
++         // If column is part of the used object, summarize column privs
++         if (colUsedObjName == refdUsedObjName)
++         {
++            // Get the refd object details
++            const NAColumnArray &nacolArr = naTable->getNAColumnArray();
++            ComString usedObjColName(usedColRef.getColName());
++            const NAColumn * naCol = nacolArr.getColumn(usedObjColName);
++            if (naCol == NULL)
++            {
++               *CmpCommon::diags() << DgSqlCode(-CAT_COLUMN_DOES_NOT_EXIST_ERROR)
++                                   << DgColumnName(usedObjColName);
++               return false;
++            }
++            int32_t usedColNumber = naCol->getPosition();
       
--      PrivMgrUserPrivs privs;
--      PrivMgrUserPrivs *pPrivInfo = NULL;
-       PrivStatus retcode = STATUS_GOOD;
--      if (viewCreator)
-       {
-         // If the viewCreator is not the current user (DB__ROOT running request)
-         // on behalf of the schema owner), get actual owner privs.
-         if (ComUser::isRootUserID() &&
-             ComUser::getRootUserID() != naTable->getSchemaOwner())
-         {
-           retcode = privInterface.getPrivileges((int64_t)naTable->objectUid().get_value(),
-                                                  naTable->getObjectType(),
-                                                  schemaID,
-                                                  privs);
- 
-           if (retcode == STATUS_ERROR)
-           {         
-              *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_RETRIEVE_PRIVS);
-              return false;
-           }
-           pPrivInfo = &privs;
-         }
-         else
-           pPrivInfo = naTable->getPrivInfo();
-       }
 -        pPrivInfo = naTable->getPrivInfo();
--      else
--      {
-         retcode = privInterface.getPrivileges((int64_t)naTable->objectUid().get_value(),
-                                                 naTable->getObjectType(),
-                                                 naTable->getOwner(),
-                                                 privs);
 -        PrivStatus retcode = privInterface.getPrivileges((int64_t)naTable->objectUid().get_value(),
 -                                                           naTable->getObjectType(),
 -                                                           naTable->getOwner(),
 -                                                           privs);
--
--        if (retcode == STATUS_ERROR)
--        {
--           *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_RETRIEVE_PRIVS);
--           return false;
--        }
--        pPrivInfo = &privs;
--      }
--
--      if (pPrivInfo == NULL) 
--      {         
--         *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_RETRIEVE_PRIVS);
--         return false;
--      }
--
--      // If the user is missing SELECT at the object level and on at least one 
--      // column-level privilege, view cannot be created.  No need to proceed.
--      if (noObjPriv && !pPrivInfo->hasColSelectPriv(usedColNumber))
--      {
--         missingPrivilege = true;
--         break;
--      }        
++            // If the user is missing SELECT at the object level and on at least one 
++            // column, view cannot be created.  No need to proceed.
++            // Can't have sequences on views, so only need to check for SELECT
++            if (noObjRequiredPriv && !pPrivInfo->hasColSelectPriv(usedColNumber))
++            {
++              *CmpCommon::diags() << DgSqlCode(-4481)
++                                  << DgString0("SELECT")
++                                  << DgString1(colUsedObjName.data());
++              return false;
++            }        
        
--      colPrivBitmap &= pPrivInfo->getColumnPrivBitmap(usedColNumber);
--      colGrantableBitmap &= pPrivInfo->getColumnGrantableBitmap(usedColNumber);
--   }
- 
 -  
--   if (noObjPriv && missingPrivilege)
--     {
--        *CmpCommon::diags() << DgSqlCode(-4481)
--                            << DgString0("SELECT")
--                            << DgString1(extUsedObjName.data());
--        return false;
--     }
--  
--   for (size_t i = FIRST_DML_COL_PRIV; i <= LAST_DML_COL_PRIV; i++ )
--   {
--      if (colPrivBitmap.test(PrivType(i)))
--         privilegesBitmap.set(PrivType(i));   
++            colPrivBitmap &= pPrivInfo->getColumnPrivBitmap(usedColNumber);
++            colGrantableBitmap &= pPrivInfo->getColumnGrantableBitmap(usedColNumber);
++         } // done with current view col 
++      } // done checking privs for all view cols
++
++      // Add summarize column privileges to the official bitmaps, bit is only
++      // set if all cols have priv set.
++      for (size_t i = FIRST_DML_COL_PRIV; i <= LAST_DML_COL_PRIV; i++ )
++      {
++         if (colPrivBitmap.test(PrivType(i)))
++            privilegesBitmap.set(PrivType(i));   
   
--      if (colGrantableBitmap.test(PrivType(i)))
--         grantableBitmap.set(PrivType(i));   
++         if (colGrantableBitmap.test(PrivType(i)))
++            grantableBitmap.set(PrivType(i));   
++      }
     }
     
     return true;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/sqlcomp/PrivMgr.h
----------------------------------------------------------------------
diff --cc core/sql/sqlcomp/PrivMgr.h
index fb3c1aa,da7145e..e7f412e
--- a/core/sql/sqlcomp/PrivMgr.h
+++ b/core/sql/sqlcomp/PrivMgr.h
@@@ -68,14 -68,11 +68,27 @@@ class PrivMg
                            };
  
      enum PrivCommand { GRANT_OBJECT           = 30,
 -                       REVOKE_OBJECT_RESTRICT = 31,
 -                       REVOKE_OBJECT_CASCADE  = 32,
 -                       UNKNOWN_PRIV_COMMAND   = 33
 +                       GRANT_COLUMN           = 31,
 +                       REVOKE_OBJECT_RESTRICT = 32,
 +                       REVOKE_OBJECT_CASCADE  = 33,
 +                       REVOKE_COLUMN_RESTRICT = 34,
 +                       REVOKE_COLUMN_CASCADE  = 35,
 +                       UNKNOWN_PRIV_COMMAND   = 36
                       };
  
++    bool isRevokeCommand (const PrivCommand command)
++    {
++      return (command == REVOKE_OBJECT_RESTRICT ||
++              command == REVOKE_OBJECT_CASCADE ||
++              command == REVOKE_COLUMN_RESTRICT ||
++              command == REVOKE_COLUMN_CASCADE);
++    }
++
++    bool isGrantCommand (const PrivCommand command)
++    {
++      return (command == GRANT_OBJECT || command == GRANT_COLUMN);
++    }
++
      // -------------------------------------------------------------------
      // Static functions:
      // -------------------------------------------------------------------



[02/10] incubator-trafodion git commit: Merge branch 'master' into trafodion-1788

Posted by rm...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/sqlcomp/PrivMgrMD.cpp
----------------------------------------------------------------------
diff --cc core/sql/sqlcomp/PrivMgrMD.cpp
index 4f64517,df0ca1c..2ece65b
--- a/core/sql/sqlcomp/PrivMgrMD.cpp
+++ b/core/sql/sqlcomp/PrivMgrMD.cpp
@@@ -630,138 -630,6 +630,138 @@@ bool PrivMgrMDAdmin::isAuthorized (void
  }
  
  // ****************************************************************************
 +// method:  getColumnReferences
 +//
 +//  This method stores the list of columns for the object in the 
 +//  ObjectReference. 
 +// **************************************************************************** 
 +PrivStatus PrivMgrMDAdmin::getColumnReferences (ObjectReference *objectRef)
 +{
 +  std::string objectMDTable = trafMetadataLocation_ + ".OBJECTS o";
 +  std::string colMDTable = trafMetadataLocation_ + ".COLUMNS c";
 +
 +  // Select column details for object 
 +  std::string selectStmt = "select c.column_number from ";
 +  selectStmt += objectMDTable;
 +  selectStmt += ", ";
 +  selectStmt += colMDTable;
 +  selectStmt += " where o.object_uid = ";
 +  selectStmt += UIDToString(objectRef->objectUID);
 +  selectStmt += " and o.object_uid = c.object_uid";
 +  selectStmt += " order by column_number";
 +
 +  ExeCliInterface cliInterface(STMTHEAP, NULL, NULL,
 +  CmpCommon::context()->sqlSession()->getParentQid());
 +  Queue * objectsQueue = NULL;
 +
 +  int32_t cliRC =  cliInterface.fetchAllRows(objectsQueue, (char *)selectStmt.c_str(), 0, FALSE, FALSE, TRUE);
 +  if (cliRC < 0)
 +  {
 +    cliInterface.retrieveSQLDiagnostics(pDiags_);
 +    return STATUS_ERROR;
 +  }
 +
 +  if (cliRC == 100) // did not find the row
 +  {
 +    std::string message ("No columns found for referenced object");
 +    PRIVMGR_INTERNAL_ERROR(message.c_str());
 +    return STATUS_ERROR;
 +  }
 +
 +  char * ptr = NULL;
 +  Int32 len = 0;
 +
 +  objectRef->columnReferences = new std::vector<ColumnReference *>;
 +
 +  // For each row, create a ColumnReference and add it to the objectRef
 +  objectsQueue->position();
 +  for (int idx = 0; idx < objectsQueue->numEntries(); idx++)
 +  {
 +    OutputInfo * pCliRow = (OutputInfo*)objectsQueue->getNext();
 +    ColumnReference *columnReference = new ColumnReference;
 +
 +    // column 0:  columnNumber
 +    pCliRow->get(0,ptr,len);
 +    columnReference->columnOrdinal = *(reinterpret_cast<int32_t*>(ptr));
 +
 +    objectRef->columnReferences->push_back(columnReference);
 +  }
 +  return STATUS_GOOD;
 +}
 +
 +// ****************************************************************************
 +// method:  getViewColUsages
 +//
 +//  This method reads the TEXT table to obtain the view-col <=> referenced-col
 +//  relationship.
 +//
 +//  This relationship is stored in one or more text records with the text_type
 +//  COM_VIEW_REF_COLS_TEXT (7) see ComSmallDefs.h 
 +//
 +//  The text rows are concatenated together and saved in the ViewUsage.
 +// **************************************************************************** 
 +PrivStatus PrivMgrMDAdmin::getViewColUsages (ViewUsage &viewUsage)
 +{
 +  std::string objectMDTable = trafMetadataLocation_ + ".OBJECTS o";
 +  std::string textMDTable = trafMetadataLocation_ + ".TEXT t";
 +
 +  // Select text rows describing view <=> object column relationships
 +  std::string selectStmt = "select text from ";
 +  selectStmt += objectMDTable;
 +  selectStmt += ", ";
 +  selectStmt += textMDTable;
 +  selectStmt += " where o.object_uid = ";
 +  selectStmt += UIDToString(viewUsage.viewUID);
-   selectStmt += "and o.object_uid = t.text_uid and t.text_type = 7";
++  selectStmt += "and o.object_uid = t.text_uid and t.text_type = 8";
 +  selectStmt += " order by seq_num";
 +  
 +  ExeCliInterface cliInterface(STMTHEAP, NULL, NULL,
 +  CmpCommon::context()->sqlSession()->getParentQid());
 +  Queue * objectsQueue = NULL;
 +  
 +  int32_t cliRC =  cliInterface.fetchAllRows(objectsQueue, (char *)selectStmt.c_str(), 0, FALSE, FALSE, TRUE);
 +  if (cliRC < 0)
 +  { 
 +    cliInterface.retrieveSQLDiagnostics(pDiags_);
 +    return STATUS_ERROR;
 +  }
 +  
 +  // View prior to column privilege support do not store view <=> object column
 +  // relationships.  These views were not created based on column privileges
 +  // so just return.
 +  if (cliRC == 100) // did not find the row
 +  { 
-     return STATUS_GOOD;
++    return STATUS_NOTFOUND;
 +  }
 +  
 +  char * ptr = NULL;
 +  Int32 len = 0;
 +
 +  // the text column length in the TEXT table is 10000
 +  char value[10000 + 1];
 +  
 +  // For each row, add it to the existing viewColUsages string
 +  objectsQueue->position();
 +  for (int idx = 0; idx < objectsQueue->numEntries(); idx++)
 +  { 
 +    OutputInfo * pCliRow = (OutputInfo*)objectsQueue->getNext();
 +    ColumnReference *columnReference = new ColumnReference;
 +
 +    // column 0: text 
 +    pCliRow->get(0,ptr,len);
 +    strncpy(value, ptr, len);
 +    value[len] = 0;
 +    viewUsage.viewColUsagesStr += value;
 +  }
 +
 +  return STATUS_GOOD;
 +} 
 +
 +
 +
 +
 +
 +// ****************************************************************************
  // method:  getViewsThatReferenceObject
  //
  //  this method gets the list of views associated with the passed in 
@@@ -797,6 -665,6 +797,12 @@@ PrivStatus PrivMgrMDAdmin::getViewsThat
    selectStmt += " where grantee_id = ";
    selectStmt += UIDToString(objectUsage.granteeID);
  
++  // for role owners, get list of users granted role
++  selectStmt += " ) or o.object_owner in (select grantee_id from ";
++  selectStmt += roleUsageMDTable;
++  selectStmt += " where role_id = ";
++  selectStmt += UIDToString(objectUsage.granteeID);
++
    selectStmt += ")) order by o.create_time ";
  
    ExeCliInterface cliInterface(STMTHEAP, NULL, NULL, 
@@@ -864,7 -732,7 +870,7 @@@ int32_t diagsMark = pDiags_->mark()
  
      // column 5: is insertable
      pCliRow->get(5,ptr,len);
--    viewUsage.isInsertable = (ptr == 0) ? false : true;
++    viewUsage.isInsertable = (*ptr == 0) ? false : true;
  
      // column 6: is updatable
      pCliRow->get(6,ptr,len);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/sqlcomp/PrivMgrPrivileges.cpp
----------------------------------------------------------------------
diff --cc core/sql/sqlcomp/PrivMgrPrivileges.cpp
index 65a2354,335f736..732b65f
--- a/core/sql/sqlcomp/PrivMgrPrivileges.cpp
+++ b/core/sql/sqlcomp/PrivMgrPrivileges.cpp
@@@ -619,6 -618,6 +619,7 @@@ PrivStatus PrivMgrPrivileges::getColPri
  //                                                                         
  //  <granteeID> is the authID granted the privileges.                              
  //  <columnOrdinal> is the column number to gather privileges
++//  <columnRowList> is the list of column privs for the object
  //  <roleIDs> is the list of roles assigned the granteeID
  //  <rowList> the privileges granted to <granteeID> on <columnOrdinal>.  
  //                                                                          
@@@ -626,23 -625,19 +627,24 @@@
  void PrivMgrPrivileges::getColRowsForGranteeOrdinal(
    const int32_t granteeID,
    const int32_t columnOrdinal,
++  const std::vector <PrivMgrMDRow *> &columnRowList,
    const std::vector<int32_t> &roleIDs,
    std::vector<PrivMgrMDRow *> &rowList)
  {
--  for (size_t i = 0; i < columnRowList_.size(); ++i)
++  for (size_t i = 0; i < columnRowList.size(); ++i)
    {
--    ColumnPrivsMDRow &row = static_cast<ColumnPrivsMDRow &> (*columnRowList_[i]);
++    ColumnPrivsMDRow &row = static_cast<ColumnPrivsMDRow &> (*columnRowList[i]);
      ColPrivEntry colPrivGrant;
  
 -    if (row.granteeID_ == granteeID && row.columnOrdinal_ == columnOrdinal)
 +    if (row.columnOrdinal_ == columnOrdinal)
      {
 -       ColumnPrivsMDRow *pRow = new ColumnPrivsMDRow();
 -       *pRow = row;
 -       rowList.push_back(pRow);
 +      if (row.granteeID_ == granteeID || 
 +          std::find(roleIDs.begin(), roleIDs.end(), row.granteeID_) != roleIDs.end()) 
 +      {
 +         ColumnPrivsMDRow *pRow = new ColumnPrivsMDRow();
 +         *pRow = row;
 +         rowList.push_back(pRow);
 +      }
      }
    }
  }
@@@ -1482,20 -1449,20 +1484,23 @@@ PrivStatus PrivMgrPrivileges::grantObje
  
    // There is something to grant, update/insert metadata
  
--  // set up row if it does not exist
++  // set up row if it does not exist and add it to the objectRowList
    if (!foundRow)
    {
--    row.objectUID_ = objectUID_;
--    row.objectName_ = objectName_;
--    row.objectType_ = objectType;
--    row.granteeID_ = granteeID;
--    row.granteeName_ = granteeName;
--    row.granteeType_ = USER_GRANTEE_LIT;
--    row.grantorID_ = grantorID_;
--    row.grantorName_ = grantorName;
--    row.grantorType_ = USER_GRANTOR_LIT;
--    row.privsBitmap_ = privsToGrant.getTablePrivs().getPrivBitmap();
--    row.grantableBitmap_ = privsToGrant.getTablePrivs().getWgoBitmap();
++    ObjectPrivsMDRow *pRow = new ObjectPrivsMDRow();
++    pRow->objectUID_ = objectUID_;
++    pRow->objectName_ = objectName_;
++    pRow->objectType_ = objectType;
++    pRow->granteeID_ = granteeID;
++    pRow->granteeName_ = granteeName;
++    pRow->granteeType_ = USER_GRANTEE_LIT;
++    pRow->grantorID_ = grantorID_;
++    pRow->grantorName_ = grantorName;
++    pRow->grantorType_ = USER_GRANTOR_LIT;
++    pRow->privsBitmap_.reset();
++    pRow->grantableBitmap_.reset(); 
++    objectRowList_.push_back(pRow);
++    row = *pRow;
    }
  
    // combine privsToGrant with existing privs
@@@ -1506,30 -1473,89 +1511,37 @@@
      row.grantableBitmap_ = privsToGrant.getTablePrivs().getWgoBitmap();
    }
  
--  ObjectPrivsMDTable objectPrivsTable (objectTableName_, pDiags_);
--  ColumnPrivsMDTable columnPrivsTable(columnTableName_,pDiags_);
--  char buf[1000];
++  // Update dependent objects
++  ObjectUsage objectUsage;
++  objectUsage.objectUID = objectUID_;
++  objectUsage.granteeID = granteeID;
++  objectUsage.grantorIsSystem = false;
++  objectUsage.objectName = row.objectName_;
++  objectUsage.objectType = row.objectType_;
++  objectUsage.columnReferences = NULL;
  
 -  if (foundRow)
 -  {
 -    ObjectUsage objectUsage;
 -    objectUsage.objectUID = objectUID_;
 -    objectUsage.granteeID = granteeID;
 -    objectUsage.grantorIsSystem = false;
 -    objectUsage.objectName = row.objectName_;
 -    objectUsage.objectType = row.objectType_;
 -    objectUsage.columnReferences = NULL;
 -
 -    PrivMgrDesc originalPrivs (row.granteeID_);
 -    originalPrivs.setTablePrivs(savedOriginalPrivs);
 -    objectUsage.originalPrivs = originalPrivs;
 -    objectUsage.updatedPrivs = privsToGrant;
++  PrivMgrDesc originalPrivs (row.granteeID_);
++  originalPrivs.setTablePrivs(savedOriginalPrivs);
++  objectUsage.originalPrivs = originalPrivs;
++  objectUsage.updatedPrivs = privsToGrant;
+   
 -    // get list of all objects that need to change, the table object and 
 -    // views
 -    std::vector<ObjectUsage *> listOfObjects;
 -    PrivCommand command = PrivCommand::GRANT_OBJECT;
 -    retcode = getAffectedObjects(objectUsage, command, listOfObjects);
 -    if (retcode == STATUS_ERROR)
 -    {
 -      deleteListOfAffectedObjects(listOfObjects);
 -      return retcode;
 -    }
++  if (updateDependentObjects(objectUsage, PrivCommand::GRANT_OBJECT) == STATUS_ERROR)
++    return STATUS_ERROR;
+ 
 -    traceMsg = "updating all affected objects, number of objects is ";
 -    traceMsg += to_string((long long int)listOfObjects.size());
++  ObjectPrivsMDTable objectPrivsTable (objectTableName_, pDiags_);
 +  if (foundRow)
 +  {
-     ObjectUsage objectUsage;
-     objectUsage.objectUID = objectUID_;
-     objectUsage.granteeID = granteeID;
-     objectUsage.grantorIsSystem = false;
-     objectUsage.objectName = row.objectName_;
-     objectUsage.objectType = row.objectType_;
-     objectUsage.columnReferences = NULL;
- 
-     PrivMgrDesc originalPrivs (row.granteeID_);
-     originalPrivs.setTablePrivs(savedOriginalPrivs);
-     objectUsage.originalPrivs = originalPrivs;
-     objectUsage.updatedPrivs = privsToGrant;
-   
-     if (updateDependentObjects(objectUsage, PrivCommand::GRANT_OBJECT) == STATUS_ERROR)
-       return STATUS_ERROR;
++    row.describeRow(traceMsg);
++    traceMsg.insert(0, "updating existing privilege row ");
+     log (__FILE__, traceMsg, -1);
+ 
 -    // update the OBJECT_PRIVILEGES row for each effected object
 -    for (size_t i = 0; i < listOfObjects.size(); i++)
 -    {
 -      ObjectUsage *pObjectUsage = listOfObjects[i];
 -
 -      pObjectUsage->describe(traceMsg);
 -      log (__FILE__, traceMsg, i);
 -
 -      // Determine the grantor:
 -      // SQL ANSI general rules state 
 -      // 
 -      // - When granting INSERT, UPDATE, or DELETE object or column privilege to
 -      //   a table that is referenced by one or more views, then the privilege  
 -      //   should be propagated to any updatable views that reference the table. 
 -      //   The grant request to the these views should be executed as though the 
 -      //   current user is _SYSTEM.
 -      //
 -      // - If the table already has SELECT privilege and a new grant is 
 -      //   performed that adds the WITH GRANT OPTION, then the WITH GRANT OPTION 
 -      //   is to be propagated to referencing views.  The grant request should
 -      //   be executed as though the current user is _SYSTEM.
 -      //
 -      //  The listOfObjects contains referencing views that meet the above 
 -      //  criteria.
 -      int32_t theGrantor = (pObjectUsage->grantorIsSystem) ? SYSTEM_USER : grantorID_;
 -      int32_t theGrantee = pObjectUsage->granteeID;
 -      int64_t theUID = pObjectUsage->objectUID;
 -      PrivMgrCoreDesc thePrivs = pObjectUsage->updatedPrivs.getTablePrivs();
 -  
 -      sprintf(buf, "where grantee_id = %d and grantor_id =  %d and object_uid = %ld",
 -              theGrantee, theGrantor, theUID);
 -      std::string whereClause (buf);
 -
 -      sprintf(buf, "set privileges_bitmap  = %ld, grantable_bitmap =  %ld",
 -              thePrivs.getPrivBitmap().to_ulong(),
 -              thePrivs.getWgoBitmap().to_ulong());
 -      std::string setClause (buf);
 -      // update the row
 -      retcode = objectPrivsTable.updateWhere(setClause, whereClause);
 -      if (retcode == STATUS_ERROR)
 -      {
 -        deleteListOfAffectedObjects(listOfObjects);
 -        return retcode;
 -      }
 -    }
 -    deleteListOfAffectedObjects(listOfObjects);
++    // update the row
++    retcode = objectPrivsTable.updateRow(row);
    }
    else
    {
++    row.privsBitmap_ = privsToGrant.getTablePrivs().getPrivBitmap();
++    row.grantableBitmap_ = privsToGrant.getTablePrivs().getWgoBitmap();
      row.describeRow(traceMsg);
      traceMsg.insert(0, "adding new privilege row ");
      log (__FILE__, traceMsg, -1);
@@@ -1825,8 -1851,8 +1837,9 @@@ PrivStatus PrivMgrPrivileges::dealWithC
  
      // get the summarized original and current privs for the referencing table 
      // current privs contains any adjustments due to the privilege change
 -    retcode = summarizeCurrentAndOriginalPrivs(pObjectRef->objectUID,
 +    retcode = summarizeCurrentAndOriginalPrivs(objectUsage.objectUID,
                                                 pObjectRef->objectOwner,
++                                               grantorID_,
                                                 roleIDs,
                                                 listOfAffectedObjects,
                                                 originalPrivs,
@@@ -1842,7 -1868,7 +1855,12 @@@
        // no longer have REFERENCES privilege on the table, 
        // see if privileges are granted on all required columns
        std::vector<ColumnReference *> summarizedColRefs;
-       summarizeColPrivs(*pObjectRef, pObjectRef->objectOwner, roleIDs, listOfAffectedObjects, summarizedColRefs);
 -      summarizeColPrivs(*pObjectRef, roleIDs, listOfAffectedObjects, summarizedColRefs);
++      summarizeColPrivs(*pObjectRef, 
++                        pObjectRef->objectOwner, 
++                        grantorID_,
++                        roleIDs, 
++                        listOfAffectedObjects, 
++                        summarizedColRefs); 
  
        // check summarized privileges to see if still have priv through other privs
        std::vector<ColumnReference *> neededColRefs = *pObjectRef->columnReferences;
@@@ -1957,6 -1983,6 +1975,7 @@@ PrivStatus PrivMgrPrivileges::dealWithU
      // current privs contains any adjustments
      retcode = summarizeCurrentAndOriginalPrivs(objectUsage.objectUID,
                                                 objectUsage.granteeID,
++                                               grantorID_,
                                                 roleIDs,
                                                 listOfAffectedObjects,
                                                 originalPrivs,
@@@ -2004,6 -2030,6 +2023,7 @@@
  PrivStatus PrivMgrPrivileges::dealWithViews(
    const ObjectUsage &objectUsage,
    const PrivCommand command,
++  const int32_t grantorID,
    std::vector<ObjectUsage *> &listOfAffectedObjects)
  {
    PrivStatus retcode = STATUS_GOOD;
@@@ -2027,40 -2053,40 +2047,38 @@@
    if (retcode != STATUS_GOOD && retcode != STATUS_WARNING)
      return retcode;
  
--  // for each entry in the viewUsages list calculate the changed
--  // privileges and call dealWithViews recursively
++  // for each entry in the viewUsages list calculate the changed privileges
++  // if privileges change, add viewUsage to listOfAffectedObjects 
    for (size_t i = 0; i < viewUsages.size(); i++)
    {
--   
      ViewUsage viewUsage = viewUsages[i];
  
      viewUsage.describe(traceMsg);
      log (__FILE__, traceMsg, i);
  
--    // this method recreates privileges for the view based on the original
--    // and the current.  Updated descriptors are stored in the viewUsage
--    // structure.
-     retcode = gatherViewPrivileges(viewUsage, command, listOfAffectedObjects);
 -    retcode = gatherViewPrivileges(viewUsage, listOfAffectedObjects);
++    // gatherViewPrivileges recreates privileges for the view based on changes
++    // requested by the current grant/revoke request
++    // Updated priv descriptors are stored in the viewUsage structure.
++    retcode = gatherViewPrivileges(viewUsage, command, grantorID, listOfAffectedObjects);
      traceMsg = "gathered view privs: retcode is ";
      traceMsg += privStatusEnumToLit(retcode);
      log (__FILE__, traceMsg, -1);
  
      if (retcode != STATUS_GOOD && retcode != STATUS_WARNING)
--    {
        return retcode;
--    }
  
      // check to see if privileges changed
      if (viewUsage.originalPrivs == viewUsage.updatedPrivs)
--    {}
++      continue;
      else
      {
--      // this view is affected by the grant/revoke request, add to list
--      // and check to see if anything down stream needs to change
--      // We already have select privilege on the view.  So only adjust
--      // view for other privileges if it is updatable and insertable
--      if (viewUsage.isUpdatable && viewUsage.isInsertable)
++      // This view privs have been changed by the grant/revoke request
++      // However, only INSERT, DELETE, and UPDATE privs can be propagated
++      // If the view is not updatable or insertable then, we are done with
++      // this viewUsage
++      if (viewUsage.isUpdatable || viewUsage.isInsertable)
        {
++        // Add viewUsage to list of affected objects
          ObjectUsage *pUsage = new (ObjectUsage);
          pUsage->objectUID = viewUsage.viewUID;
          pUsage->granteeID = viewUsage.viewOwner;
@@@ -2075,91 -2101,17 +2093,114 @@@
          pUsage->describe(traceMsg);
          log (__FILE__, traceMsg, i);
  
--        retcode = dealWithViews(*pUsage, command, listOfAffectedObjects);
--        if (retcode != STATUS_GOOD && retcode != STATUS_WARNING)
--          return retcode;
--      }
--    }
--  } 
++#if 0
++        // When cascade is supported, the list of down stream views must be 
++        // included in the list of affected objects.
++        // Also, need to understand ANSI SQL rules for propagating view privs,
++        // that is, should down stream views be updated if it parent view
++        // privs are changed  and the parent has WGO specified.
++
++        // get list of grantee ID's that have been granted privileges on the
++        // current view.  
++        std::set<int32_t> granteeList;
++        if (getGranteesForViewUsage(viewUsage, granteeList) == STATUS_ERROR)
++        {
++          PRIVMGR_INTERNAL_ERROR("Error while getting grantees for down stream views");
++          return STATUS_ERROR;
++        }
++
++        // Call dealWithViews to see if the down stream views should be adjusted.
++        for (std::set<int32_t>::iterator it = granteeList.begin(); it!= granteeList.end(); ++it)
++        {
++          pUsage->granteeID = *it;
++          retcode = dealWithViews(*pUsage, command, viewUsage.viewOwner, listOfAffectedObjects);
++          if (retcode != STATUS_GOOD && retcode != STATUS_WARNING)
++            return retcode;
++        }
++        pUsage->granteeID = viewUsage.viewOwner;
++#endif
++      } // updatable views 
++    } // view privs changed
++  } // list of view usages
    
    return STATUS_GOOD;
  }
  
  // ----------------------------------------------------------------------------
 +// method: gatherViewColUsages
 +//
 +// This method gathers the view-col <=> referenced-col usages and creates a
 +// list of ComViewColUsage's for the referenced object. Each ComViewColUsage 
 +// is identified the view column number, and the related UID and column number 
 +// of the referenced object.
 +//
 +// parameters:
 +//   objectRef - description of the referenced object 
 +//   viewUsage - description of the view
 +//   viewColUsages - list of view column, referenced column usages
 +//
 +// Returns: PrivStatus                                               
 +//                                                                    
 +// STATUS_GOOD: Operation successful
 +//           *: Unable to gather usages, see diags.     
 +//                                                                 
 +// ----------------------------------------------------------------------------
 +PrivStatus PrivMgrPrivileges::gatherViewColUsages(
 +  ObjectReference *objectRef,
 +  ViewUsage &viewUsage,
 +  std::vector<ComViewColUsage> &viewColUsages)
 +{
 +  std::string traceMsg;
 +  PrivStatus retcode;
 +
 +  PrivMgrMDAdmin admin(trafMetadataLocation_, metadataLocation_, pDiags_);
 +
 +  // Get columns for referenced object if they are  not already present
 +  if (objectRef->columnReferences == NULL)
 +  {
 +    retcode = admin.getColumnReferences(objectRef);
 +    if (objectRef->columnReferences)
 +    {
 +      traceMsg += "getting column references: number references found ";
 +      traceMsg += to_string((long long int)objectRef->columnReferences->size());
 +    }
 +    traceMsg += ", retcode is ";
 +    traceMsg += privStatusEnumToLit(retcode);
 +    log (__FILE__, traceMsg, -1);
 +    if (retcode == STATUS_ERROR)
 +      return retcode;
 +  }
 +
 +  // Extract view <=> object column relationship from the TEXT table 
 +  // and add it to the viewUsage
 +  if (viewUsage.viewColUsagesStr.empty())
 +  {
 +    retcode = admin.getViewColUsages(viewUsage);
 +    traceMsg += "getting view column usages";
 +    traceMsg += ", retcode is ";
 +    traceMsg += privStatusEnumToLit(retcode);
 +    log (__FILE__, traceMsg, -1);
-     if (retcode == STATUS_ERROR)
++    if (retcode != STATUS_GOOD)
 +      return retcode;
 +  }
 +
 +  // Setup the view column to referenced column relationship
 +  char * beginStr  = (char *)viewUsage.viewColUsagesStr.c_str();
 +  char * endStr = strchr(beginStr, ';');
 +  while (endStr != NULL)
 +  {
 +    ComViewColUsage colUsage;
 +    std::string currentUsage(beginStr, endStr - beginStr + 1);
 +    colUsage.unpackUsage (currentUsage.c_str());
 +    viewColUsages.push_back(colUsage);
 +    beginStr = endStr+1;
 +    endStr = strchr(beginStr, ';');
 +  }
 + 
 +  return STATUS_GOOD;
 +}
 +
 +// ----------------------------------------------------------------------------
  // method: gatherViewPrivileges
  //
  // This method gathers privileges for the view both the original and current
@@@ -2176,7 -2128,6 +2217,8 @@@
  // ----------------------------------------------------------------------------
  PrivStatus PrivMgrPrivileges::gatherViewPrivileges(
    ViewUsage &viewUsage,
 +  const PrivCommand command,
++  const int32_t grantorID,
    const std::vector<ObjectUsage *> listOfAffectedObjects)
  {
    PrivStatus retcode = STATUS_GOOD;
@@@ -2227,6 -2182,6 +2269,7 @@@
      //   to generate the current privs
      retcode = summarizeCurrentAndOriginalPrivs(pObjectRef->objectUID,
                                                 viewUsage.viewOwner, 
++                                               grantorID,
                                                 roleIDs,
                                                 listOfAffectedObjects,
                                                 originalPrivs,
@@@ -2234,21 -2189,21 +2277,24 @@@
      if (retcode != STATUS_GOOD)
        return retcode;
  
 -    // If user no longer has select privilege on referenced object
 -    // returns an error
 -    // When cascade is supported, then referenced objects will be removed
 -    //if (command == PrivCommand::REVOKE_OBJECT_RESTRICT )
 -    //{
 -      PrivMgrCoreDesc thePrivs = currentPrivs.getTablePrivs();
 -      if (!thePrivs.getPriv(SELECT_PRIV))
 +    // If the referenced object is a sequence generator, then the grantee
 +    // must still have the USAGE_PRIV.  The USAGE_PRIV is not a column
 +    // level privilege so no column level check is necessary.
-     if (pObjectRef->objectType == COM_SEQUENCE_GENERATOR_OBJECT)
++    if (isRevokeCommand(command))
 +    {
-       PrivMgrCoreDesc thePrivs = currentPrivs.getTablePrivs();
-       if (!thePrivs.getPriv(USAGE_PRIV))
++      if (pObjectRef->objectType == COM_SEQUENCE_GENERATOR_OBJECT)
        {
--         *pDiags_ << DgSqlCode (-CAT_DEPENDENT_OBJECTS_EXIST)
--                  << DgString0 (viewUsage.viewName.c_str());
--         return STATUS_ERROR;
++        PrivMgrCoreDesc thePrivs = currentPrivs.getTablePrivs();
++        if (!thePrivs.getPriv(USAGE_PRIV))
++        {
++           *pDiags_ << DgSqlCode (-CAT_DEPENDENT_OBJECTS_EXIST)
++                    << DgString0 (viewUsage.viewName.c_str());
++           return STATUS_ERROR;
++        }
        }
 -    //}
 +    }
  
 -    // add the returned privilege to the summarized privileges
 +    // "and" the returned privilege to the summarized privileges
      // for all objects
      summarizedOriginalPrivs.intersectionOfPrivs(originalPrivs);
      summarizedCurrentPrivs.intersectionOfPrivs(currentPrivs);
@@@ -2258,115 -2212,6 +2304,149 @@@
      currentPrivs.resetTablePrivs();
    }
  
-   // If the object has no granted column level privileges, skip column checks
-   if (columnRowList_.empty())
-   {
-     if (!summarizedCurrentPrivs.getTablePrivs().getPriv(SELECT_PRIV))
-     {
-       *pDiags_ << DgSqlCode (-CAT_DEPENDENT_OBJECTS_EXIST)
-                << DgString0 (viewUsage.viewName.c_str());
-       return STATUS_ERROR;
-     }
-     return STATUS_GOOD;
-   }
-   
-   // If view has all grantable column privileges already, return
++  // If view has all grantable col privs already, no need to check further
 +  bool checkCols = false;
 +  PrivMgrCoreDesc thePrivs = summarizedCurrentPrivs.getTablePrivs();
 +  for (size_t i = FIRST_DML_COL_PRIV; i <= LAST_DML_COL_PRIV; i++ )
 +  {
 +    PrivType privType = PrivType(i);
 +    if (thePrivs.getPriv(privType) && thePrivs.getWgo(privType))
 +      continue;
 +    checkCols = true;
 +    break;
 +  }
 +
++  // No need to check col privs, return with summarized privs
 +  if (!checkCols)
++  {
++    // Update view usage with summarized privileges
++    viewUsage.originalPrivs = summarizedOriginalPrivs;
++    viewUsage.updatedPrivs = summarizedCurrentPrivs;
 +    return STATUS_GOOD;
++  }
 +
 +  // Turn on bits to prepare for intersecting with object privileges
 +  originalPrivs.setAllTableGrantPrivileges(setWGOtrue);
 +  currentPrivs.setAllTableGrantPrivileges(setWGOtrue);
 +
 +  std::vector<ColumnReference *> summarizedColRefs;
 +
 +  // Gather column privileges on all objects referencing the view.
 +  //   for grants, a view might gain privs 
 +  //   for revokes, a view might lose privs
 +  // For example:
 +  //   as user1:
 +  //     create table sch1.t1 (c1 int, c2 int, ....);
 +  //     grant select on sch1.t1 to user2;
 +  //     grant insert (c1) on sch1.t1 to user2
 +  //   as user2:
 +  //     create view sch2.v1 as select c1 from sch1.t1;
 +  //   view sch2.v1 gains the insert privilege since all columns that 
 +  //     sch2.v1 references have granted user2 the insert privilege.
 +  for (size_t i = 0; i < objectList.size(); i++)
 +  {
 +    ObjectReference *pObjectRef = objectList[i];
 +
 +    // gather the view-col <=> referenced-col usages
 +    std::vector <ComViewColUsage> viewColUsages;
 +    retcode = gatherViewColUsages(pObjectRef, viewUsage, viewColUsages);
 +    if (retcode == STATUS_ERROR)
 +      return retcode;
 +
++    // The view-col <=> referenced_col relationship is not found
++    // No need to proceed further.
++    // If this is a grant of a column privilege, return an error
++    // User needs to drop and recreate view
++    // The view-col <=> referenced-col usages are only being started in 
++    // metadata after column privileges are officially supported.  Any views
++    // create before this time, do not have this information, so column privs
++    // either do not exist (revoke) or cannot be added (grant).  The view needs
++    // to be dropped and recreated (or add a fixup procedure).
++    if (retcode == STATUS_NOTFOUND)
++    {
++      if (command == GRANT_COLUMN) 
++      {
++         *pDiags_ << DgSqlCode (-CAT_COLUMN_PRIVILEGE_NOT_ALLOWED)
++                  << DgTableName (viewUsage.viewName.c_str());
++         return STATUS_ERROR;
++       }
++       return STATUS_GOOD;
++    }
++
++    
 +    // gather the updated summarized column privileges on the referenced object
 +    summarizeColPrivs(*pObjectRef, 
 +                      viewUsage.viewOwner, 
++                      grantorID,
 +                      roleIDs, 
 +                      listOfAffectedObjects, 
-                       summarizedColRefs);
++                      summarizedColRefs); 
 +
 +    // For each view column, get the corresponding referenced column priv
 +    for (size_t j = 0; j < viewColUsages.size(); j++)
 +    {
 +      ComViewColUsage colUsage = viewColUsages[j];
 +
 +      // See if the referenced object contains the associated view column
 +      if (colUsage.getRefdUID() != pObjectRef->objectUID) 
 +        continue;
 +
 +      // Get the referenced column, if NULL then something is wrong
 +      ColumnReference *neededColRef = pObjectRef->find(colUsage.getRefdColNumber());
 +      if (neededColRef == NULL)
 +      {
 +         PRIVMGR_INTERNAL_ERROR("View column to referenced column relationship wrong");
 +         return STATUS_ERROR;
 +      }
 +
 +      // Find and update the current bitmaps for column
 +      for (size_t k = 0; k < summarizedColRefs.size(); k++)
 +      {
 +        ColumnReference *existingRef = summarizedColRefs[k];
 +        if (existingRef->columnOrdinal == neededColRef->columnOrdinal)
 +        {
 +          originalPrivs.intersectionOfPrivs(existingRef->originalPrivs);
 +          currentPrivs.intersectionOfPrivs(existingRef->updatedPrivs);
 +          break;
 +        }
 +      }
 +    }
 +  }
 +
 +  // Union or "or" the returned privileges to the summarized privileges
 +  // for all columns. The privilege is set in currentPrivs only if all
 +  // columns in the view have the privilege.
 +  summarizedOriginalPrivs.unionOfPrivs(originalPrivs);
 +  summarizedCurrentPrivs.unionOfPrivs(currentPrivs);
 +
 +  // If user no longer has select privilege on referenced object
 +  // returns an error
 +  // When cascade is supported, then referenced objects will be removed
-   if (!summarizedCurrentPrivs.getTablePrivs().getPriv(SELECT_PRIV))
++  if (isRevokeCommand(command))
 +  {
-     *pDiags_ << DgSqlCode (-CAT_DEPENDENT_OBJECTS_EXIST)
-              << DgString0 (viewUsage.viewName.c_str());
-     return STATUS_ERROR;
++    if (!summarizedCurrentPrivs.getTablePrivs().getPriv(SELECT_PRIV))
++    {
++      *pDiags_ << DgSqlCode (-CAT_DEPENDENT_OBJECTS_EXIST)
++               << DgString0 (viewUsage.viewName.c_str());
++      return STATUS_ERROR;
++    }
 +  }
 +
++  // If view is not updatable or insertable, turn off privs in bitmaps
++  if (!viewUsage.isUpdatable)
++    {
++      summarizedCurrentPrivs.getTablePrivs().setPriv(UPDATE_PRIV,false);
++      summarizedCurrentPrivs.getTablePrivs().setPriv(UPDATE_PRIV, false);
++      summarizedCurrentPrivs.getTablePrivs().setPriv(DELETE_PRIV,false);
++      summarizedCurrentPrivs.getTablePrivs().setPriv(DELETE_PRIV, false);
++    }
++
++  if (!viewUsage.isInsertable)
++    {
++      summarizedCurrentPrivs.getTablePrivs().setPriv(INSERT_PRIV,false);
++      summarizedCurrentPrivs.getTablePrivs().setPriv(INSERT_PRIV, false);
++    }
++
    // Update view usage with summarized privileges
    viewUsage.originalPrivs = summarizedOriginalPrivs;
    viewUsage.updatedPrivs = summarizedCurrentPrivs;
@@@ -2380,8 -2225,8 +2460,6 @@@
  // generate the list of privileges granted to columns of the object and 
  // store in columnRowList_ class member
  //
--// The list is ordered by grantor/grantee/column_number
--//
  // Returns:
  //   STATUS_GOOD     - list of rows was generated
  //   STATUS_NOTFOUND - no column privileges were found
@@@ -2389,20 -2234,20 +2467,47 @@@
  // ****************************************************************************
  PrivStatus PrivMgrPrivileges::generateColumnRowList()
  {
++  PrivStatus privStatus = getColumnRowList(objectUID_, columnRowList_);
++  if (privStatus == STATUS_ERROR)
++    return privStatus;
++  return STATUS_GOOD;
++}
++ 
++// ****************************************************************************
++// method: getColumnRowList
++//
++// generate the list of privileges granted to the passed in objectUID and 
++// returns in the columnRowList parameter
++//
++// The list is ordered by grantor/grantee/column_number
++//
++// Returns:
++//   STATUS_GOOD     - list of rows was generated
++//   STATUS_NOTFOUND - in most cases, there should be at least one row in the
++//                     OBJECT_PRIVILEGES table.  But there is at least one case
++//                     where this is not true - trying to get privilege info
++//                     for indexes when using the table (index_table) syntax.
++//   STATUS_ERROR    - the diags area is populated with any errors
++// ****************************************************************************
++
++PrivStatus PrivMgrPrivileges::getColumnRowList(
++   const int64_t objectUID,
++   std::vector<PrivMgrMDRow *> &columnRowList)
++{
    std::string whereClause ("where object_uid = ");
--  whereClause += UIDToString(objectUID_);
++  whereClause += UIDToString(objectUID);
    std::string orderByClause (" order by grantor_id, grantee_id, column_number ");
  
    ColumnPrivsMDTable columnPrivsTable(columnTableName_,pDiags_);
    PrivStatus privStatus = 
--   columnPrivsTable.selectWhere(whereClause, orderByClause, columnRowList_);
++   columnPrivsTable.selectWhere(whereClause, orderByClause, columnRowList);
  
    std::string traceMsg ("getting column privileges, number privileges is ");
--  traceMsg += to_string((long long int)columnRowList_.size());
++  traceMsg += to_string((long long int)columnRowList.size());
    log (__FILE__, traceMsg, -1);
--  for (size_t i = 0; i < columnRowList_.size(); i++)
++  for (size_t i = 0; i < columnRowList.size(); i++)
    {
--    ColumnPrivsMDRow privRow = static_cast<ColumnPrivsMDRow &> (*columnRowList_[i]);
++    ColumnPrivsMDRow privRow = static_cast<ColumnPrivsMDRow &> (*columnRowList[i]);
      privRow.describeRow(traceMsg);
      log (__FILE__, traceMsg, i);
    }
@@@ -2416,8 -2261,8 +2521,6 @@@
  // generate the list of privileges granted to the object and 
  // store in objectRowList_ class member
  //
--// The list is ordered by grantor/grantee
--//
  // Returns:
  //   STATUS_GOOD     - list of rows was generated
  //   STATUS_NOTFOUND - in most cases, there should be at least one row in the
@@@ -2428,50 -2273,19 +2531,48 @@@
  // ****************************************************************************
  PrivStatus PrivMgrPrivileges::generateObjectRowList()
  {
-   std::vector<PrivMgrMDRow *> objectRows;
-   PrivStatus privStatus = getObjectRowList(objectUID_, objectRows);
++  PrivStatus privStatus = getObjectRowList(objectUID_, objectRowList_);
 +  if (privStatus == STATUS_ERROR)
 +    return privStatus;
-   objectRowList_ = objectRows;
 +  return STATUS_GOOD;
 +}
 +
 +// ****************************************************************************
 +// method: getObjectRowList
 +//
 +// generate the list of privileges granted to the passed in objectUID and 
- // returns in the objectRows parameter
++// returns in the objectRowList parameter
 +//
 +// The list is ordered by grantor/grantee
 +//
 +// Returns:
 +//   STATUS_GOOD     - list of rows was generated
 +//   STATUS_NOTFOUND - in most cases, there should be at least one row in the
 +//                     OBJECT_PRIVILEGES table.  But there is at least one case
 +//                     where this is not true - trying to get privilege info
 +//                     for indexes when using the table (index_table) syntax.
 +//   STATUS_ERROR    - the diags area is populated with any errors
 +// ****************************************************************************
 +PrivStatus PrivMgrPrivileges::getObjectRowList(
 +   const int64_t objectUID, 
-    std::vector<PrivMgrMDRow *> &objectRows)
++   std::vector<PrivMgrMDRow *> &objectRowList)
 +{ 
    std::string whereClause ("where object_uid = ");
 -  whereClause += UIDToString(objectUID_);
 +  whereClause += UIDToString(objectUID);
    std::string orderByClause(" order by grantor_id, grantee_id ");
  
    ObjectPrivsMDTable objectPrivsTable(objectTableName_,pDiags_);
    PrivStatus privStatus = 
-     objectPrivsTable.selectWhere(whereClause, orderByClause, objectRows);
 -    objectPrivsTable.selectWhere(whereClause, orderByClause, objectRowList_);
++    objectPrivsTable.selectWhere(whereClause, orderByClause, objectRowList);
 +  if (privStatus == STATUS_ERROR)
 +    return privStatus;
 +
    std::string traceMsg ("getting object privileges, number privleges is ");
-   traceMsg += to_string((long long int)objectRows.size());
 -  traceMsg += to_string((long long int)objectRowList_.size());
++  traceMsg += to_string((long long int)objectRowList.size());
    log (__FILE__, traceMsg, -1);
-   for (size_t i = 0; i < objectRows.size(); i++)
 -  for (size_t i = 0; i < objectRowList_.size(); i++)
++  for (size_t i = 0; i < objectRowList.size(); i++)
    {
-     ObjectPrivsMDRow privRow = static_cast<ObjectPrivsMDRow &> (*objectRows[i]);
 -    ObjectPrivsMDRow privRow = static_cast<ObjectPrivsMDRow &> (*objectRowList_[i]);
++    ObjectPrivsMDRow privRow = static_cast<ObjectPrivsMDRow &> (*objectRowList[i]);
      privRow.describeRow(traceMsg);
      log (__FILE__, traceMsg, i);
    }
@@@ -2529,7 -2343,7 +2630,7 @@@ PrivStatus PrivMgrPrivileges::getAffect
    }
  
    // Find list of affected views
--  retcode = dealWithViews (objectUsage, command, listOfAffectedObjects);
++  retcode = dealWithViews (objectUsage, command, grantorID_, listOfAffectedObjects);
    if (retcode != STATUS_GOOD && retcode != STATUS_WARNING)
      return retcode;
  
@@@ -2570,6 -2384,6 +2671,66 @@@ PrivStatus PrivMgrPrivileges::getGrante
  }
   
  // ----------------------------------------------------------------------------
++// method: getGranteesForViewUsage
++//
++// returns the list of grantees that have been granted privileges by the view
++// owner
++//
++// input:  viewUsage
++// output: a unique list of grantees
++//
++//  Returns: PrivStatus                                               
++//                                                                   
++//   STATUS_GOOD: list was generated
++//  STATUS_ERROR: unexpected error occurred
++// ----------------------------------------------------------------------------
++PrivStatus PrivMgrPrivileges::getGranteesForViewUsage (
++  const ViewUsage &viewUsage,
++  std::set<int32_t> &granteeList)
++{
++  PrivStatus privStatus = STATUS_GOOD;
++
++  std::string whereClause ("where object_uid = ");
++  whereClause += UIDToString(viewUsage.viewUID);
++  whereClause += " and grantor_id <> -2 ";
++  std::string orderByClause("order by grantee_id");
++  std::vector<PrivMgrMDRow *> rowList;
++  
++  // get list of grantees from object_privileges
++  ObjectPrivsMDTable objectPrivsTable(objectTableName_,pDiags_);
++  privStatus = objectPrivsTable.selectWhere(whereClause,orderByClause,rowList);
++  if (privStatus == STATUS_ERROR)
++  {
++    deleteRowList(rowList);
++    return privStatus;
++  }
++
++  for (size_t i = 0; i < rowList.size(); i++)
++  {
++    ObjectPrivsMDRow &currentRow = static_cast<ObjectPrivsMDRow &> (*rowList[i]);
++    granteeList.insert(currentRow.granteeID_);
++  }
++  deleteRowList(rowList);
++    
++  // get list of grantees for column_privileges
++  ColumnPrivsMDTable columnPrivsTable(columnTableName_,pDiags_);
++  privStatus = columnPrivsTable.selectWhere(whereClause, orderByClause, rowList);
++  if (privStatus == STATUS_ERROR)
++  {
++    deleteRowList(rowList);
++    return privStatus;
++  }
++
++  for (size_t i = 0; i < rowList.size(); i++)
++  {
++    ColumnPrivsMDRow &currentRow = static_cast<ColumnPrivsMDRow &> (*rowList[i]);
++    granteeList.insert(currentRow.granteeID_);
++  }
++  deleteRowList(rowList);
++  return STATUS_GOOD;
++}
++
++// ----------------------------------------------------------------------------
  // method: getGrantorDetailsForObject
  //
  // returns the effective grantor ID and grantor name for grant and revoke
@@@ -2800,11 -2614,11 +2961,18 @@@ PrivStatus PrivMgrPrivileges::revokeCol
           ColPrivEntry colPrivToRevoke;
           
           colPrivToRevoke.setColumnOrdinal(columnOrdinal);   
--         colPrivToRevoke.setPriv(privType,true);
--        
--         // if revoking a privilege and auth ID has WGO, then revoke 
--         // the WGO bit also
--         colPrivToRevoke.setGrantable(privType, metadataEntry->getGrantableBitmap().test(privType));
++         if (isWGOSpecified)
++         {
++           colPrivToRevoke.setPriv(privType,false);
++           colPrivToRevoke.setGrantable(privType, true);
++         }
++         else
++         {
++           colPrivToRevoke.setPriv(privType,true);
++           // if revoking a privilege and auth ID has WGO, then revoke 
++           // the WGO bit also
++           colPrivToRevoke.setGrantable(privType, metadataEntry->getGrantableBitmap().test(privType));
++         }
  
           colPrivsToRevoke.push_back(colPrivToRevoke);
        }
@@@ -2898,7 -2720,7 +3066,8 @@@
           // Found row with grant for this column.
           
           // Verify privilege(s) being revoked was/were granted.  If not, internal error.
--         if ((colPrivToRevoke.getPrivBitmap() & grantedColPriv->getPrivBitmap()) == 0)
++         if (!isWGOSpecified && 
++             ((colPrivToRevoke.getPrivBitmap() & grantedColPriv->getPrivBitmap()) == 0))
           {
              PRIVMGR_INTERNAL_ERROR("Privilege to revoke not found");
              return STATUS_ERROR;
@@@ -3190,14 -3011,89 +3359,34 @@@ PrivStatus PrivMgrPrivileges::revokeObj
    objectUsage.originalPrivs = originalPrivs;
    objectUsage.updatedPrivs = privsToRevoke;
  
 -  // get list of dependent objects that need to change 
 -  std::vector<ObjectUsage *> listOfObjects;
 -  retcode = getAffectedObjects(objectUsage, 
 -                               PrivCommand::REVOKE_OBJECT_RESTRICT, 
 -                               listOfObjects);
 -  if (retcode == STATUS_ERROR)
 -  {
 -    deleteListOfAffectedObjects(listOfObjects);
 -    return retcode;
 -  }
 +  if (updateDependentObjects(objectUsage, PrivCommand::REVOKE_OBJECT_RESTRICT) == STATUS_ERROR)
 +    return STATUS_ERROR;
  
 -  char buf[1000];
 -  ObjectPrivsMDTable objectPrivsTable (objectTableName_, pDiags_);
 -  ColumnPrivsMDTable columnPrivsTable(columnTableName_,pDiags_);
 +  // Go rebuild the privilege tree to see if it is broken
 +  // If it is broken, return an error
 +  if (checkRevokeRestrict (row, objectRowList_))
 +    return STATUS_ERROR;
  
 -  // update the OBJECT_PRIVILEGES row for each effected object
 -  for (size_t i = 0; i < listOfObjects.size(); i++)
++  ObjectPrivsMDTable objectPrivsTable (objectTableName_, pDiags_);
++  if (privsToRevoke.isNull())
+   {
 -    ObjectUsage *pObjectUsage = listOfObjects[i];
 -    PrivMgrCoreDesc thePrivs = pObjectUsage->updatedPrivs.getTablePrivs();
 -
 -    // Determine the grantor:
 -    // SQL ANSI general rules state 
 -    // 
 -    // - When revoking INSERT, UPDATE, or DELETE object or column privilege from
 -    //   a table that is referenced by one or more views, then the privilege  
 -    //   should be revoked on any updatable views that reference the table. 
 -    //   The revoke request to the these views should be executed as though the 
 -    //   current user is _SYSTEM.
 -    //
 -    // - If the revoke is performed that removes the WITH GRANT OPTION, then 
 -    //   the WITH GRANT OPTION is to be removed frome referencing views.  The 
 -    //   revoke request should be executed as though the current user is _SYSTEM.
 -    //
 -    //  The listOfObjects contains referencing views that meet the above 
 -    //  criteria.
 -    int32_t theGrantor = (pObjectUsage->grantorIsSystem) ? SYSTEM_USER : grantorID_;
 -    int32_t theGrantee = pObjectUsage->granteeID;
 -    int64_t theUID = pObjectUsage->objectUID;
 -
 -    sprintf(buf, "where grantee_id = %d and grantor_id =  %d and object_uid = %ld",
 -            theGrantee, theGrantor, theUID);
 -    std::string whereClause (buf);
 -
 -    if (thePrivs.isNull())
 -    {
 -      pObjectUsage->describe(traceMsg);
 -      traceMsg.insert (0, "deleted object usage ");
++    row.describeRow(traceMsg);
++    traceMsg.insert(0, "deleting privilege row ");
++    log (__FILE__, traceMsg, -1);
+ 
 -      // delete the row
 -      retcode = objectPrivsTable.deleteWhere(whereClause);
 -      if (retcode == STATUS_ERROR)
 -      {
 -        deleteListOfAffectedObjects(listOfObjects);
 -        return retcode;
 -      }
 -    }
 -    else
 -    {
 -      sprintf(buf, "set privileges_bitmap  = %ld, grantable_bitmap =  %ld",
 -              thePrivs.getPrivBitmap().to_ulong(),
 -              thePrivs.getWgoBitmap().to_ulong());
 -      std::string setClause (buf);
++    // delete the row
++    retcode = objectPrivsTable.deleteRow(row);
++  }
++  else
++  {
++    row.describeRow(traceMsg);
++    traceMsg.insert(0, "updating existing privilege row ");
++    log (__FILE__, traceMsg, -1);
+ 
 -      pObjectUsage->describe(traceMsg);
 -      traceMsg.insert (0, "updated object usage ");
 -      // update the row
 -      retcode = objectPrivsTable.updateWhere(setClause, whereClause);
 -      if (retcode == STATUS_ERROR)
 -      {
 -        deleteListOfAffectedObjects(listOfObjects);
 -        return retcode;
 -      }
 -    }
++    // update the row
++    retcode = objectPrivsTable.updateRow(row);
+   }
 -  
 -  deleteListOfAffectedObjects(listOfObjects);
 -  
 -  // Go rebuild the privilege tree to see if it is broken
 -  // If it is broken, return an error
 -  if (checkRevokeRestrict (row, objectRowList_))
 -    return STATUS_ERROR;
+ 
    // Send a message to the Trafodion RMS process about the revoke operation.
    // RMS will contact all master executors and ask that cached privilege 
    // information be re-calculated
@@@ -4302,7 -4187,6 +4491,8 @@@ PrivStatus PrivMgrPrivileges::getRowsFo
  // ****************************************************************************
  void PrivMgrPrivileges::summarizeColPrivs(
    const ObjectReference &objReference,
 +  const int32_t granteeID,
++  const int32_t grantorID,
    const std::vector<int32_t> &roleIDs,
    const std::vector<ObjectUsage *> &listOfAffectedObjects,
    std::vector<ColumnReference *> &summarizedColRefs)
@@@ -4324,8 -4208,8 +4514,9 @@@
      // get COLUMN_PRIVILEGES rows where the grantee for the column has received 
      // privileges -  the row list is in memory so this does not require I/O
      std::vector<PrivMgrMDRow *> rowList;
 -    getColRowsForGranteeOrdinal(objReference.objectOwner,
 +    getColRowsForGranteeOrdinal(granteeID,
                                  colRef->columnOrdinal,
++                                columnRowList_,
                                  roleIDs,
                                  rowList);
      
@@@ -4333,49 -4217,34 +4524,49 @@@
      // We do a union operation to capture privileges from all grantors
      ColumnReference *summarized = new ColumnReference; 
      summarized->columnOrdinal = colRef->columnOrdinal;
 -    for (int32_t i = 0; i < rowList.size();++i)
 -    {
 -      ColumnPrivsMDRow &row = static_cast<ColumnPrivsMDRow &> (*rowList[i]);
 -      PrivMgrCoreDesc originalPrivs(row.privsBitmap_, row.grantableBitmap_);
  
 -      ColumnReference ref;
 -      ref.columnOrdinal = row.columnOrdinal_;
 -      ref.originalPrivs = originalPrivs;
 -      ref.updatedPrivs = originalPrivs;
 -      
 -      // Update if privileges have been changed by request
 -      for (size_t j = 0; j < listOfAffectedObjects.size(); j++)
 +    if (rowList.size() > 0)
 +    {
 +      for (int32_t j = 0; j < rowList.size();++j)
        {
 -        ObjectUsage *currentObj = listOfAffectedObjects[j];
 -        if (currentObj->objectUID == row.objectUID_ &&
 -            grantorID_ == row.grantorID_ &&
 -            objReference.objectOwner == row.granteeID_ )
 +        ColumnPrivsMDRow &row = static_cast<ColumnPrivsMDRow &> (*rowList[j]);
 +        PrivMgrCoreDesc originalPrivs(row.privsBitmap_, row.grantableBitmap_);
 +        PrivMgrCoreDesc original = originalPrivs;
 +        PrivMgrCoreDesc updated = originalPrivs;
 +
 +        // Update if privileges have been changed by request
 +        for (size_t k = 0; k < listOfAffectedObjects.size(); k++)
          {
 -          ColumnReference *changedRef = currentObj->findColumn(row.columnOrdinal_);
 -          if (changedRef)
 -            ref.updatedPrivs = changedRef->updatedPrivs;
 +          ObjectUsage *currentObj = listOfAffectedObjects[k];
 +          if (currentObj->objectUID == row.objectUID_ &&
-               grantorID_ == row.grantorID_ &&
++              grantorID == row.grantorID_ &&
 +              currentObj->granteeID == row.granteeID_ )
 +          {
 +            ColumnReference *changedRef = currentObj->findColumn(row.columnOrdinal_);
 +            if (changedRef)
 +              updated = changedRef->updatedPrivs;
 +          }
          }
 +        summarized->originalPrivs.unionOfPrivs(original);
 +        summarized->updatedPrivs.unionOfPrivs(updated);
        }
 -      
 -      summarized->originalPrivs.unionOfPrivs(ref.originalPrivs);
 -      summarized->updatedPrivs.unionOfPrivs(ref.updatedPrivs);
      }
 -
 +    else
 +    {
 +      // For grants, this may be the first column privs added, adjust to
 +      // include new privs
 +      PrivMgrCoreDesc updated;
 +      for (size_t k = 0; k < listOfAffectedObjects.size(); k++)
 +      {
 +        ObjectUsage *currentObj = listOfAffectedObjects[k];
 +        ColumnReference *changedRef = currentObj->findColumn(colRef->columnOrdinal);
 +        if (changedRef)
 +          updated = changedRef->updatedPrivs;
 +      }
 +      // There are no originalPrivs
 +      summarized->updatedPrivs.unionOfPrivs(updated);
 +    }
 +      
      // Add column ref to the list
      summarizedColRefs.push_back(summarized);
    }
@@@ -4403,6 -4272,6 +4594,7 @@@
  PrivStatus PrivMgrPrivileges::summarizeCurrentAndOriginalPrivs(
     const int64_t objectUID,
     const int32_t granteeID,
++   const int32_t grantorID,
     const std::vector<int32_t> & roleIDs,
     const std::vector<ObjectUsage *> listOfChangedPrivs,
     PrivMgrDesc &summarizedOriginalPrivs,
@@@ -4422,128 -4291,21 +4614,126 @@@
    {
      ObjectPrivsMDRow &row = static_cast<ObjectPrivsMDRow &> (*rowList[i]);
      PrivMgrCoreDesc original(row.privsBitmap_, row.grantableBitmap_);
--    PrivMgrCoreDesc current = original;
++    PrivMgrCoreDesc updated = original;
      for (size_t j = 0; j < listOfChangedPrivs.size(); j++)
      {
        ObjectUsage *pObjectUsage = listOfChangedPrivs[j];
        if (pObjectUsage->objectUID == row.objectUID_ &&
--          grantorID_ == row.grantorID_ &&
--          pObjectUsage->granteeID == row.granteeID_ )
++        grantorID == row.grantorID_ &&
++        pObjectUsage->granteeID == row.granteeID_ )
        {
--        current = pObjectUsage->updatedPrivs.getTablePrivs();
++        updated = pObjectUsage->updatedPrivs.getTablePrivs();
        }
      }
      summarizedOriginalPrivs.unionOfPrivs(original);
--    summarizedCurrentPrivs.unionOfPrivs(current);
++    summarizedCurrentPrivs.unionOfPrivs(updated);
 +  }
 +
 +  return STATUS_GOOD;
 +}
 +
 +// *****************************************************************************
 +// * Method: updateDependentObjects
 +// *                                                       
 +// * This code gets the list of dependent objects that have had their privileges
 +// * changed because of the ongoing grant/revoke request.  It then updates
 +// * the object privileges table to change any dependencies.
 +// *
 +// * SQL ANSI general rules state 
 +// *
 +// * - When granting INSERT, UPDATE, or DELETE object or column privilege to
 +// *   a table that is referenced by one or more views, then the privilege  
 +// *   should be propagated to any updatable views that reference the table. 
 +// *   The grant request to the these views should be executed as though the 
 +// *   current user is _SYSTEM.
 +// *
 +// * - If the table already has SELECT privilege and a new grant is 
 +// *   performed that adds the WITH GRANT OPTION, then the WITH GRANT OPTION 
 +// *   is to be propagated to referencing views.  The grant request should
 +// *   be executed as though the current user is _SYSTEM.
 +// *
 +// * - When revoking INSERT, UPDATE, or DELETE object or column privilege from
 +// *   a table that is referenced by one or more views, then the privilege  
 +// *   should be revoked on any updatable views that reference the table. 
 +// *   The revoke request to the these views should be executed as though the 
 +// *   current user is _SYSTEM.
 +// *
 +// * - If the revoke is performed that removes the WITH GRANT OPTION, then 
 +// *   the WITH GRANT OPTION is to be removed frome referencing views.  The 
 +// *   revoke request should be executed as though the current user is _SYSTEM.
 +// *
 +// *****************************************************************************
 +PrivStatus PrivMgrPrivileges::updateDependentObjects(
 +  const ObjectUsage &objectUsage,
 +  const PrivCommand command)
 +{
 +  std::string traceMsg;
 +
 +  // get list of any objects that need to change because of the grant/revoke
 +  std::vector<ObjectUsage *> listOfObjects;
 +  PrivStatus privStatus = getAffectedObjects(objectUsage, command, listOfObjects);
 +  if (privStatus == STATUS_ERROR)
 +  {
 +    deleteListOfAffectedObjects(listOfObjects);
 +    return privStatus;
    }
  
 +  traceMsg = "list of dependent objects, number of objects is ";
 +  traceMsg += to_string((long long int)listOfObjects.size());
 +  log (__FILE__, traceMsg, -1);
 +
 +  char buf [1000];
 +  ObjectPrivsMDTable objectPrivsTable (objectTableName_, pDiags_);
 +
 +  // update the OBJECT_PRIVILEGES row for each effected object
-   // Starting index is 1 for column requests
-   size_t i = 0;
-   if (command == PrivCommand::GRANT_COLUMN ||
-       command == PrivCommand::REVOKE_COLUMN_RESTRICT )
-     i = 1;
++  // Starting index is 1  - the first entry is the original row that is
++  // updated as part of the grant/revoke request
++  size_t i = 1;
 +  for (i; i < listOfObjects.size(); i++)
 +  {
 +    ObjectUsage *pObjectUsage = listOfObjects[i];
 +
 +    pObjectUsage->describe(traceMsg);
 +    log (__FILE__, traceMsg, i);
 +
 +    // Determine row contents
 +    int32_t theGrantor = (pObjectUsage->grantorIsSystem) ? SYSTEM_USER : grantorID_;
 +    int32_t theGrantee = pObjectUsage->granteeID;
 +    int64_t theUID = pObjectUsage->objectUID;
 +    PrivMgrCoreDesc thePrivs = pObjectUsage->updatedPrivs.getTablePrivs();
 +    sprintf(buf, "where grantee_id = %d and grantor_id =  %d and object_uid = %ld",
 +            theGrantee, theGrantor, theUID);
 +    std::string whereClause (buf);
 +
 +    if (thePrivs.isNull())
 +    {
 +      pObjectUsage->describe(traceMsg);
 +      traceMsg.insert (0, "deleted object usage ");
 +
 +      // delete the row
 +      privStatus = objectPrivsTable.deleteWhere(whereClause);
 +      if (privStatus == STATUS_ERROR)
 +      {
 +        deleteListOfAffectedObjects(listOfObjects);
 +        return privStatus;
 +      }
 +    }
 +    else
 +    {
 +      sprintf(buf, "set privileges_bitmap  = %ld, grantable_bitmap =  %ld",
 +              thePrivs.getPrivBitmap().to_ulong(),
 +              thePrivs.getWgoBitmap().to_ulong());
 +      std::string setClause (buf);
 +      privStatus = objectPrivsTable.updateWhere(setClause, whereClause);
 +
 +      if (privStatus == STATUS_ERROR)
 +      {
 +        deleteListOfAffectedObjects(listOfObjects);
 +        return privStatus;
 +      }
 +    }
 +  }
 +  deleteListOfAffectedObjects(listOfObjects);
    return STATUS_GOOD;
  }
  

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/sqlcomp/PrivMgrPrivileges.h
----------------------------------------------------------------------
diff --cc core/sql/sqlcomp/PrivMgrPrivileges.h
index 73590fc,c62c0e4..1239c7a
--- a/core/sql/sqlcomp/PrivMgrPrivileges.h
+++ b/core/sql/sqlcomp/PrivMgrPrivileges.h
@@@ -328,6 -327,6 +328,7 @@@ private
    PrivStatus dealWithViews (
      const ObjectUsage &objectUsage,
      const PrivCommand command,
++    const int32_t grantorID,
      std::vector<ObjectUsage *> &listOfAffectedObjects);
  
    void deleteListOfAffectedObjects(
@@@ -341,14 -340,8 +342,15 @@@
      ObjectUsage &constraintUsage,
      const std::vector<ObjectUsage *> listOfAffectedObjects);
  
 +  PrivStatus gatherViewColUsages(
 +    ObjectReference *objectRef,
 +    ViewUsage &viewUsage,
 +    std::vector<ComViewColUsage> &viewColUsages);
 +
    PrivStatus gatherViewPrivileges(
      ViewUsage &viewUsage,
 +    const PrivCommand command,
++    const int32_t grantorID,
      const std::vector<ObjectUsage *> listOfAffectedObjects);
  
    PrivStatus generateColumnRowList();
@@@ -362,17 -355,13 +364,26 @@@
    void getColRowsForGranteeOrdinal(
      const int32_t granteeID,
      const int32_t columnOrdinal,
++    const std::vector<PrivMgrMDRow *> &columnRows,
      const std::vector<int32_t> &roleIDs,
      std::vector<PrivMgrMDRow *> &rowList);
  
++  PrivStatus getColumnRowList(
++    const int64_t objectUID,
++   std::vector<PrivMgrMDRow *> &columnRows);
++
    PrivStatus getGrantedPrivs(
      const int32_t granteeID,
      PrivMgrMDRow &row);
  
++  PrivStatus getGranteesForViewUsage (
++    const ViewUsage &viewUsage,
++    std::set<int32_t> &granteeList);
++
++  PrivStatus getObjectRowList(
++    const int64_t objectUID, 
++    std::vector<PrivMgrMDRow *> &objectRows);
++
    PrivStatus getRoleIDsForUserID(
       int32_t userID,
       std::vector<int32_t> & roleIDs);
@@@ -421,7 -410,6 +432,8 @@@
  
    void summarizeColPrivs(
      const ObjectReference &objRef,
 +    const int32_t granteeID,
++    const int32_t grantorID,
      const std::vector<int32_t> &roleIDs,
      const std::vector<ObjectUsage *> &listOfAffectedObjects,
      std::vector<ColumnReference *> &columnReferences);
@@@ -429,6 -417,6 +441,7 @@@
    PrivStatus summarizeCurrentAndOriginalPrivs(
      const int64_t objectUID,
      const int32_t granteeID,
++    const int32_t grantorID,
      const std::vector<int32_t> & roleIDs,
      const std::vector<ObjectUsage *> listOfChangedPrivs,
      PrivMgrDesc &summarizedOriginalPrivs,


[05/10] incubator-trafodion git commit: Merge branch 'master' into trafodion-1788

Posted by rm...@apache.org.
Merge branch 'master' into trafodion-1788

Conflicts:
	core/sql/common/ComSmallDefs.h
	core/sql/generator/Generator.cpp
	core/sql/optimizer/NATable.cpp
	core/sql/sqlcat/ReadTableDef.cpp
	core/sql/sqlcat/desc.h


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

Branch: refs/heads/master
Commit: cd3d7e7b69c4e387f4a0e9219672bc62b6204ade
Parents: a71d832 2a0a301
Author: Roberta Marton <rm...@edev07.esgyn.local>
Authored: Fri Aug 5 21:17:30 2016 +0000
Committer: Roberta Marton <rm...@edev07.esgyn.local>
Committed: Fri Aug 5 21:17:30 2016 +0000

----------------------------------------------------------------------
 .gitignore                                      |    1 +
 .rat-excludes                                   |    1 +
 README.md                                       |   58 +
 core/conn/Makefile                              |   14 +-
 core/conn/jdbcT4/pom.xml                        |    6 +
 .../trafodion/jdbc/t4/InterfaceResultSet.java   |   20 +-
 .../trafodion/jdbc/t4/InterfaceUtilities.java   |   11 +-
 .../trafodion/jdbc/t4/T4DatabaseMetaData.java   |    6 +-
 core/conn/jdbc_type2/Makefile                   |    2 +-
 core/conn/odb/Makefile                          |    2 +-
 core/conn/odb/src/odb.c                         |    7 +-
 core/conn/odbc/src/odbc/Common/Global.h         |    5 +-
 core/conn/odbc/src/odbc/Common/PubQueryStats.h  |   11 +-
 core/conn/odbc/src/odbc/nsksrvr/SrvrConnect.cpp |  143 +-
 .../odbc/nsksrvrcore/ResStatisticsSession.cpp   |   95 +-
 .../src/odbc/nsksrvrcore/ResStatisticsSession.h |    1 +
 .../odbc/nsksrvrcore/ResStatisticsStatement.cpp |    3 +-
 .../odbc/src/odbc/nsksrvrcore/sqlinterface.cpp  |   41 +
 .../odbc/src/odbc/nsksrvrcore/srvrothers.cpp    |  274 +-
 core/conn/trafci/.gitignore                     |    1 +
 .../unixcli/DrvrManager/drvrmanager.cpp         |  136 +-
 .../odbc/odbcclient/unixcli/cli/cdatasource.cpp |    6 +-
 .../odbcclient/unixcli/cli/cdatasource_drvr.cpp |    4 +-
 .../odbc/odbcclient/unixcli/cli/cdesc.cpp       |   27 +-
 .../odbc/odbcclient/unixcli/cli/cstmt.cpp       |    9 +-
 core/sqf/.gitignore                             |    2 +
 core/sqf/Makefile                               |   17 +-
 core/sqf/conf/install_features                  |    2 +
 .../export/include/common/evl_sqlog_eventnum.h  |    1 +
 core/sqf/sqenvcom.sh                            |   51 +-
 .../sql/scripts/install_hadoop_regr_test_env    |  369 ++-
 core/sqf/sql/scripts/install_local_hadoop       |   48 +-
 core/sqf/sql/scripts/restcheck                  |    1 -
 core/sqf/sql/scripts/sqcheck                    |   66 +-
 core/sqf/sql/scripts/sqstart                    |   43 +
 core/sqf/src/seatrans/hbase-trx/Makefile        |   87 +-
 core/sqf/src/seatrans/hbase-trx/pom.xml.apache  |  336 ---
 .../sqf/src/seatrans/hbase-trx/pom.xml.apache10 |  336 +++
 .../sqf/src/seatrans/hbase-trx/pom.xml.apache11 |  336 +++
 core/sqf/src/seatrans/hbase-trx/pom.xml.cdh     |  332 ---
 core/sqf/src/seatrans/hbase-trx/pom.xml.cdh54   |  332 +++
 core/sqf/src/seatrans/hbase-trx/pom.xml.cdh55   |  332 +++
 core/sqf/src/seatrans/hbase-trx/pp.awk          |   40 +-
 .../hbase/client/ClientScanner98.java.tmpl      |   26 +-
 .../hbase/client/PatchClientScanner.java.tmpl   |    2 +-
 .../client/TrafParallelClientScanner.java.tmpl  |   10 +-
 .../CommitUnsuccessfulException.java            |    3 +-
 .../HBaseBackedTransactionLogger.java           |   44 +-
 .../OutOfOrderProtocolException.java            |    3 +-
 .../hbase/client/transactional/RMInterface.java |   54 +-
 .../transactional/SsccTransactionalTable.java   |   30 +-
 .../SsccUpdateConflictException.java            |    3 +-
 .../hbase/client/transactional/TmDDL.java       |   91 +-
 .../transactional/TransactionManager.java       |  479 ++--
 .../client/transactional/TransactionState.java  |   22 +-
 .../TransactionalAggregationClient.java         |   19 +-
 .../transactional/TransactionalTable.java       |   35 +-
 .../transactional/TransactionalTableClient.java |    3 +-
 .../transactional/UnsuccessfulDDLException.java |    3 +-
 .../transactional/SsccRegionEndpoint.java.tmpl  |    4 +-
 .../transactional/TrxRegionEndpoint.java.tmpl   |   80 +-
 .../transactional/TrxRegionObserver.java.tmpl   |   16 +-
 .../generated/TrxRegionProtos.java              | 2629 ++++++++++++++----
 .../CleanOldTransactionsChore.java.tmpl         |    6 +-
 .../hbase/regionserver/transactional/IdTm.java  |    2 +-
 .../transactional/KeyValueListScanner.java.tmpl |    2 +-
 .../transactional/MemoryUsageChore.java.tmpl    |    6 +-
 .../transactional/TrxTransactionState.java.tmpl |   14 +-
 .../hbase-trx/src/main/protobuf/TrxRegion.proto |   26 +-
 core/sqf/src/seatrans/tm/hbasetmlib2/Makefile   |    2 +-
 .../sqf/src/seatrans/tm/hbasetmlib2/hbasetm.cpp |  222 +-
 .../src/seatrans/tm/hbasetmlib2/hbasetmglob.h   |    2 +-
 .../seatrans/tm/hbasetmlib2/hbasetmlogging.h    |   33 -
 core/sqf/src/seatrans/tm/hbasetmlib2/idtm.cpp   |    2 +
 .../src/seatrans/tm/hbasetmlib2/idtmclicom.h    |  138 +-
 .../tm/hbasetmlib2/javaobjectinterfacetm.cpp    |  124 +-
 .../tm/hbasetmlib2/javaobjectinterfacetm.h      |    7 +
 .../trafodion/dtm/HBaseAuditControlPoint.java   |  173 +-
 .../main/java/org/trafodion/dtm/HBaseTmZK.java  |   22 +-
 .../java/org/trafodion/dtm/HBaseTxClient.java   |  570 ++--
 .../java/org/trafodion/dtm/TmAuditTlog.java     |  370 +--
 .../main/java/org/trafodion/dtm/TrafInfo.java   |   23 +-
 .../sqf/src/seatrans/tm/hbasetmlib2/testrun.cpp |    4 +-
 core/sqf/src/seatrans/tm/macros.gmk             |    2 +-
 core/sqf/src/tm/Makefile                        |   11 +-
 core/sqf/src/tm/idtmsrv.cpp                     |   13 +-
 core/sqf/src/tm/javaobjectinterfacetm.cpp       |  355 ---
 core/sqf/src/tm/javaobjectinterfacetm.h         |  154 -
 core/sqf/src/tm/tminfo.cpp                      |    1 -
 core/sqf/src/tm/tmlib.cpp                       |   34 +-
 core/sqf/src/tm/tmlogging.cpp                   |  108 +-
 core/sqf/src/tm/tmlogging.h                     |    8 +-
 core/sqf/src/tm/tmlogginglib.cpp                |   55 -
 core/sqf/src/tm/tools/Makefile                  |   10 +-
 core/sqf/src/tm/xarmlogging.cpp                 |  261 --
 core/sql/arkcmp/CmpStoredProc.cpp               |   96 +-
 core/sql/arkcmp/CmpStoredProc.h                 |   21 +-
 core/sql/bin/SqlciErrors.txt                    |   17 +-
 core/sql/cli/Cli.cpp                            |   18 +-
 core/sql/cli/Cli.h                              |    3 +-
 core/sql/cli/CliExtern.cpp                      |    3 +-
 core/sql/cli/Context.cpp                        |   61 +-
 core/sql/cli/Context.h                          |   17 +-
 core/sql/cli/Descriptor.cpp                     |    8 +
 core/sql/cli/Statement.cpp                      |    4 +
 core/sql/cli/sqlcli.h                           |    5 +
 core/sql/comexe/ComTdb.h                        |    5 +-
 core/sql/common/BaseTypes.cpp                   |   37 +
 core/sql/common/BigNumHelper.cpp                |   27 +-
 core/sql/common/BigNumHelper.h                  |    6 +-
 core/sql/common/CmpCommon.h                     |    1 +
 core/sql/common/ComSmallDefs.h                  |   23 +-
 core/sql/common/ComSysUtils.h                   |   21 +
 core/sql/common/Int64.cpp                       |   20 +
 core/sql/common/Int64.h                         |   12 +
 core/sql/common/MiscType.cpp                    |  150 +-
 core/sql/common/MiscType.h                      |  112 +-
 core/sql/common/NAType.cpp                      |   12 +
 core/sql/common/NAType.h                        |    5 +
 core/sql/common/NumericType.cpp                 |  148 +-
 core/sql/common/NumericType.h                   |   54 +-
 core/sql/common/OperTypeEnum.h                  |    2 +
 core/sql/common/SQLTypeDefs.h                   |    3 +
 core/sql/common/dfs2rec.h                       |   16 +-
 core/sql/common/str.cpp                         |   40 +-
 core/sql/common/str.h                           |   12 +-
 core/sql/common/swscanf.cpp                     |   15 +-
 core/sql/common/swsprintf.cpp                   |   16 +-
 core/sql/executor/ExExeUtil.h                   |    3 +-
 core/sql/executor/ExExeUtilCli.cpp              |    4 +-
 core/sql/executor/ExExeUtilGet.cpp              |   10 +-
 core/sql/executor/ExExeUtilLoad.cpp             |   63 +-
 core/sql/executor/ExExeUtilMisc.cpp             |    5 +-
 core/sql/executor/ExFastTransport.cpp           |    8 +-
 core/sql/executor/ExHbaseAccess.cpp             |   26 +-
 core/sql/executor/ExHbaseAccess.h               |    4 +-
 core/sql/executor/ExHbaseIUD.cpp                |   28 +-
 core/sql/executor/ExHdfsScan.cpp                |  101 +-
 core/sql/executor/ExHdfsScan.h                  |    2 +-
 core/sql/executor/HBaseClient_JNI.cpp           |   44 -
 core/sql/executor/HBaseClient_JNI.h             |    5 +-
 core/sql/executor/JavaObjectInterface.cpp       |    4 +-
 core/sql/executor/SequenceFileReader.cpp        |  287 +-
 core/sql/executor/SequenceFileReader.h          |    2 -
 core/sql/executor/ex_globals.cpp                |   14 +-
 core/sql/executor/ex_globals.h                  |    4 +-
 core/sql/executor/ex_root.cpp                   |    9 +-
 core/sql/executor/ex_split_bottom.cpp           |    2 +-
 core/sql/executor/hiveHook.cpp                  |    4 +-
 core/sql/exp/ExpError.cpp                       |   25 +
 core/sql/exp/ExpError.h                         |    5 +
 core/sql/exp/ExpErrorEnums.h                    |    2 +
 core/sql/exp/ExpLOB.cpp                         |  107 +-
 core/sql/exp/ExpLOB.h                           |   18 +-
 core/sql/exp/ExpLOBaccess.cpp                   |  232 +-
 core/sql/exp/ExpLOBaccess.h                     |   17 +-
 core/sql/exp/ExpLOBinterface.cpp                |  165 +-
 core/sql/exp/ExpLOBinterface.h                  |    7 +-
 core/sql/exp/ExpPCode.cpp                       |   68 +-
 core/sql/exp/ExpPCodeClauseGen.cpp              |  398 ++-
 core/sql/exp/ExpPCodeExpGen.cpp                 |    5 +-
 core/sql/exp/ExpPCodeInstruction.h              |   41 +-
 core/sql/exp/ExpPCodeOptimizations.cpp          |  103 +-
 core/sql/exp/ExpPCodeOptsConstProp.cpp          |    8 +-
 core/sql/exp/exp_arith.cpp                      |    6 +-
 core/sql/exp/exp_attrs.cpp                      |    3 +
 core/sql/exp/exp_bignum.cpp                     |   12 +-
 core/sql/exp/exp_clause.cpp                     |    3 +-
 core/sql/exp/exp_clause_derived.h               |   86 +-
 core/sql/exp/exp_comp.cpp                       |  151 +-
 core/sql/exp/exp_conv.cpp                       | 1033 +++++--
 core/sql/exp/exp_datetime.cpp                   |  178 +-
 core/sql/exp/exp_eval.cpp                       |  222 +-
 core/sql/exp/exp_expr.cpp                       |    2 -
 core/sql/exp/exp_expr.h                         |   23 +-
 core/sql/exp/exp_fixup.cpp                      |  131 +-
 core/sql/exp/exp_function.cpp                   |   95 +-
 core/sql/exp/exp_math_func.cpp                  |   18 +-
 core/sql/generator/GenExpGenerator.cpp          |  111 +-
 core/sql/generator/GenExpGenerator.h            |    3 +
 core/sql/generator/GenExplain.cpp               |   99 +-
 core/sql/generator/GenItemExpr.cpp              |   19 +
 core/sql/generator/GenPreCode.cpp               |  156 +-
 core/sql/generator/GenRelExeUtil.cpp            |   43 +-
 core/sql/generator/GenRelJoin.cpp               |    7 +-
 core/sql/generator/GenRelMisc.cpp               |  132 +-
 core/sql/generator/GenRelScan.cpp               |   41 +-
 core/sql/generator/GenUdr.cpp                   |    4 +-
 core/sql/generator/Generator.cpp                |  805 +++---
 core/sql/generator/Generator.h                  |   99 +-
 core/sql/nskgmake/sqlcat/Makefile               |    1 +
 core/sql/optimizer/BindItemExpr.cpp             |   32 +-
 core/sql/optimizer/BindRI.cpp                   |   28 +-
 core/sql/optimizer/BindRelExpr.cpp              |  240 +-
 core/sql/optimizer/BindWA.h                     |    6 +-
 core/sql/optimizer/ControlDB.cpp                |   10 +-
 core/sql/optimizer/EncodedKeyValue.cpp          |   77 +-
 core/sql/optimizer/EncodedKeyValue.h            |   21 +-
 core/sql/optimizer/EncodedValue.cpp             |    7 +
 core/sql/optimizer/HDFSHook.cpp                 |   31 +-
 core/sql/optimizer/ItemArith.h                  |   32 +
 core/sql/optimizer/ItemConstr.h                 |    5 +-
 core/sql/optimizer/ItemExpr.cpp                 |   52 +-
 core/sql/optimizer/NAColumn.cpp                 |  207 +-
 core/sql/optimizer/NAColumn.h                   |    4 +-
 core/sql/optimizer/NAFileSet.cpp                |    2 +-
 core/sql/optimizer/NAFileSet.h                  |   10 +-
 core/sql/optimizer/NARoutine.cpp                |   66 +-
 core/sql/optimizer/NARoutine.h                  |    2 +-
 core/sql/optimizer/NATable.cpp                  | 2176 ++++++++-------
 core/sql/optimizer/NATable.h                    |   14 +-
 core/sql/optimizer/NormItemExpr.cpp             |    2 +-
 core/sql/optimizer/NormRelExpr.cpp              |   42 +-
 core/sql/optimizer/OptRange.cpp                 |   24 +-
 core/sql/optimizer/RelExeUtil.cpp               |   30 +-
 core/sql/optimizer/RelExeUtil.h                 |   27 +-
 core/sql/optimizer/RelMisc.h                    |    2 +-
 core/sql/optimizer/RelRoutine.cpp               |   15 +-
 core/sql/optimizer/RelRoutine.h                 |   28 +-
 core/sql/optimizer/RelScan.h                    |   10 +-
 core/sql/optimizer/RelStoredProc.cpp            |    2 +-
 core/sql/optimizer/SynthType.cpp                |   70 +-
 core/sql/optimizer/UdfDllInteraction.cpp        |   23 +
 core/sql/optimizer/ValueDesc.cpp                |   61 +-
 core/sql/parser/AllStmtDDL.h                    |    1 +
 core/sql/parser/AllStmtDDLAlterTable.h          |    1 +
 core/sql/parser/BindStmtDDL.cpp                 |   31 +
 core/sql/parser/ElemDDLNode.cpp                 |   12 +
 core/sql/parser/ElemDDLNode.h                   |    4 +
 core/sql/parser/ParKeyWords.cpp                 |    5 +-
 core/sql/parser/SqlParserAux.cpp                |   28 +-
 core/sql/parser/StmtDDLAlter.cpp                |   91 +
 core/sql/parser/StmtDDLAlterSchema.h            |  177 ++
 core/sql/parser/StmtDDLAlterTableStoredDesc.h   |  102 +
 core/sql/parser/StmtDDLCreate.cpp               |    1 +
 core/sql/parser/sqlparser.y                     |  319 ++-
 core/sql/parser/ulexer.cpp                      |    3 +-
 core/sql/regress/compGeneral/EXPECTED001.SB     |  105 +-
 core/sql/regress/compGeneral/EXPECTED004.SB     |    4 +-
 core/sql/regress/compGeneral/EXPECTED005        |  111 +-
 core/sql/regress/compGeneral/EXPECTED042        |   32 +-
 core/sql/regress/compGeneral/EXPECTED071        |    4 +-
 core/sql/regress/compGeneral/TEST001            |   51 +-
 core/sql/regress/compGeneral/TEST005            |   35 +-
 core/sql/regress/core/EXPECTED000.SB            |    2 +-
 core/sql/regress/core/EXPECTED037.SB            |   16 +-
 core/sql/regress/core/EXPECTED038.LINUX         |   24 +-
 core/sql/regress/core/EXPECTEDRTS               |   32 +-
 core/sql/regress/core/FILTERRTS                 |   11 +-
 core/sql/regress/core/TEST000                   |    2 +-
 core/sql/regress/core/TEST037                   |    5 +-
 core/sql/regress/executor/EXPECTED002.SB        |   68 +-
 core/sql/regress/executor/EXPECTED012           |   36 +-
 core/sql/regress/executor/EXPECTED013.SB        |    2 +
 core/sql/regress/executor/EXPECTED022.SB        |  168 +-
 core/sql/regress/executor/EXPECTED050           |    4 +-
 core/sql/regress/executor/EXPECTED063           |  166 +-
 core/sql/regress/executor/EXPECTED140           |   60 +-
 core/sql/regress/executor/TEST012               |   15 +-
 core/sql/regress/executor/TEST122               |    6 +
 core/sql/regress/fullstack2/EXPECTED062         |    6 +
 core/sql/regress/fullstack2/EXPECTED062.RELEASE |    6 +
 core/sql/regress/hive/EXPECTED005               |   38 +-
 core/sql/regress/hive/EXPECTED009               |   16 +-
 core/sql/regress/hive/EXPECTED015               |   60 +-
 core/sql/regress/hive/EXPECTED018               |  211 +-
 core/sql/regress/hive/FILTER018                 |    2 +
 core/sql/regress/hive/TEST005                   |    2 +-
 core/sql/regress/hive/TEST005_a.hive.sql        |   12 +-
 core/sql/regress/hive/TEST009                   |    2 +-
 core/sql/regress/hive/TEST018                   |   25 +-
 core/sql/regress/hive/tbl_type.data             |    2 +-
 core/sql/regress/privs1/DIFF133.KNOWN           |   39 +-
 core/sql/regress/privs1/EXPECTED141             |  Bin 113222 -> 93407 bytes
 core/sql/regress/privs1/TEST141                 |   52 -
 core/sql/regress/privs2/EXPECTED143             |  Bin 0 -> 59462 bytes
 core/sql/regress/privs2/TEST143                 |  456 +++
 core/sql/regress/qat/eqatdml12                  |   98 +-
 core/sql/regress/qat/eqatdml13                  |   98 +-
 core/sql/regress/seabase/EXPECTED003            | 2159 +++++++++++++-
 core/sql/regress/seabase/EXPECTED010            |  378 +--
 core/sql/regress/seabase/EXPECTED011            |    9 +-
 core/sql/regress/seabase/EXPECTED020            |    8 +-
 core/sql/regress/seabase/EXPECTED030            |   20 +-
 core/sql/regress/seabase/EXPECTED031            |  342 ++-
 core/sql/regress/seabase/TEST003                |  282 +-
 core/sql/regress/seabase/TEST030                |    2 +
 core/sql/regress/seabase/TEST031                |   61 +-
 core/sql/regress/tools/regrhive.ksh             |    2 +-
 core/sql/regress/tools/runregr_hive.ksh         |    4 +-
 core/sql/regress/tools/runregr_seabase.ksh      |    7 +-
 core/sql/regress/tools/sbdefs                   |    2 +
 core/sql/regress/udr/EXPECTED001                |   30 +-
 core/sql/regress/udr/TEST001                    |    7 +
 core/sql/sqlcat/ReadTableDef.cpp                |  406 ---
 core/sql/sqlcat/ReadTableDef.h                  |   17 -
 core/sql/sqlcat/TrafDDLdesc.cpp                 |  619 +++++
 core/sql/sqlcat/TrafDDLdesc.h                   | 1121 ++++++++
 core/sql/sqlcat/desc.h                          |  474 +---
 core/sql/sqlcat/readRealArk.cpp                 |  146 +-
 core/sql/sqlcat/readRealArk.h                   |    1 -
 core/sql/sqlci/Formatter.cpp                    |   10 +
 core/sql/sqlci/Param.cpp                        |    2 +
 core/sql/sqlci/SqlciEnv.cpp                     |   11 +-
 core/sql/sqlci/SqlciEnv.h                       |    2 +-
 core/sql/sqlci/sqlci_lex.ll                     |    1 +
 core/sql/sqlci/sqlci_yacc.y                     |    2 +
 core/sql/sqlcomp/CmpDDLCatErrorCodes.h          |    3 +-
 core/sql/sqlcomp/CmpDescribe.cpp                |   23 +-
 core/sql/sqlcomp/CmpSeabaseDDL.h                |   99 +-
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp        |  417 ++-
 core/sql/sqlcomp/CmpSeabaseDDLincludes.h        |   12 +-
 core/sql/sqlcomp/CmpSeabaseDDLindex.cpp         |   40 +-
 core/sql/sqlcomp/CmpSeabaseDDLmd.h              |  500 +++-
 core/sql/sqlcomp/CmpSeabaseDDLrepos.cpp         |  238 +-
 core/sql/sqlcomp/CmpSeabaseDDLrepos.h           |  492 +++-
 core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp       |    9 +-
 core/sql/sqlcomp/CmpSeabaseDDLschema.cpp        |  246 ++
 core/sql/sqlcomp/CmpSeabaseDDLtable.cpp         |  746 +++--
 core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp       |  235 +-
 core/sql/sqlcomp/CmpSeabaseDDLupgrade.h         |  270 +-
 core/sql/sqlcomp/CmpSeabaseDDLutil.cpp          |    2 +
 core/sql/sqlcomp/CmpSeabaseDDLview.cpp          |  222 +-
 core/sql/sqlcomp/DefaultConstants.h             |   23 +
 core/sql/sqlcomp/PrivMgr.h                      |   13 +
 core/sql/sqlcomp/PrivMgrMD.cpp                  |   12 +-
 core/sql/sqlcomp/PrivMgrPrivileges.cpp          |  420 ++-
 core/sql/sqlcomp/PrivMgrPrivileges.h            |   21 +-
 core/sql/sqlcomp/nadefaults.cpp                 |   19 +-
 core/sql/sqlcomp/parser.cpp                     |    9 +
 core/sql/sqlcomp/parser.h                       |   21 +
 .../java/org/trafodion/sql/HBaseClient.java     |  138 +-
 .../java/org/trafodion/sql/HBulkLoadClient.java |   93 +-
 .../java/org/trafodion/sql/HTableClient.java    |   60 +-
 .../java/org/trafodion/sql/OrcFileReader.java   |   52 +-
 .../org/trafodion/sql/SequenceFileWriter.java   |  115 +-
 .../java/org/trafodion/sql/TrafRegionStats.java |   16 +-
 core/sql/ustat/hs_cli.cpp                       |   14 +
 core/sql/ustat/hs_faststats.cpp                 |    9 +-
 core/sql/ustat/hs_globals.cpp                   |   66 +
 core/sql/ustat/hs_update.cpp                    |   14 +
 docs/client_install/pom.xml                     |    1 +
 docs/command_interface/pom.xml                  |    1 +
 docs/cqd_reference/pom.xml                      |    1 +
 docs/jdbct4ref_guide/pom.xml                    |    1 +
 .../src/asciidoc/_chapters/introduction.adoc    |    2 +-
 docs/load_transform/pom.xml                     |    1 +
 docs/load_transform/src/asciidoc/index.adoc     |    1 +
 docs/messages_guide/pom.xml                     |    1 +
 .../src/asciidoc/_chapters/introduction.adoc    |    2 +-
 docs/odb_user/pom.xml                           |    1 +
 docs/odb_user/src/asciidoc/_chapters/about.adoc |    2 +-
 docs/provisioning_guide/pom.xml                 |    1 +
 .../src/asciidoc/_chapters/about.adoc           |    6 +-
 .../src/asciidoc/_chapters/activate.adoc        |    1 +
 .../src/asciidoc/_chapters/enable_security.adoc |  251 +-
 .../src/asciidoc/_chapters/introduction.adoc    |  142 +-
 .../src/asciidoc/_chapters/prepare.adoc         |   84 +-
 .../src/asciidoc/_chapters/quickstart.adoc      |  597 ++++
 .../src/asciidoc/_chapters/requirements.adoc    |   38 +-
 .../src/asciidoc/_chapters/script_install.adoc  |  376 ++-
 .../src/asciidoc/_chapters/script_upgrade.adoc  |  266 +-
 docs/provisioning_guide/src/asciidoc/index.adoc |    1 +
 docs/shared/license.txt                         |    5 +
 docs/shared/revisions.txt                       |    3 +-
 docs/spj_guide/pom.xml                          |    1 +
 docs/sql_reference/pom.xml                      |    1 +
 .../src/asciidoc/_chapters/sql_statements.adoc  |   14 +-
 docs/src/site/markdown/download.md              |   24 +-
 docs/src/site/markdown/index.md                 |   22 +-
 docs/src/site/markdown/release-notes-2-0-1.md   |   10 +-
 docs/src/site/resources/css/site.css            |    1 +
 .../site/resources/images/carousel/meetup.png   |  Bin 0 -> 81640 bytes
 docs/src/site/site.xml                          |   12 +-
 install/.gitignore                              |    1 +
 install/Makefile                                |    7 +-
 install/installer/addNode_packages              |   89 +
 install/installer/addNode_reservePorts          |   81 +
 install/installer/addNode_step1                 |  294 ++
 install/installer/addNode_step2                 |  372 +++
 install/installer/dcs_installer                 |    4 +
 install/installer/parseHBaseSite.py             |    5 +
 install/installer/rest_installer                |    4 +
 install/installer/tools/ambari_setup            |    2 +-
 install/installer/traf_apache_mods              |   15 +-
 install/installer/traf_cloudera_mods            |   34 +-
 install/installer/traf_config                   |   11 +
 install/installer/traf_config_check             |  102 +-
 install/installer/traf_config_setup             |   33 +-
 install/installer/traf_hortonworks_mods         |   63 +-
 install/installer/traf_sqconfig                 |    8 +
 install/installer/traf_start                    |   30 +-
 install/installer/trafodion_config_default      |    7 +
 install/installer/trafodion_install             |   29 +-
 licenses/Makefile                               |    5 +-
 licenses/lic-server-src                         |   17 +-
 win-odbc64/odbcclient/drvr35/cdesc.cpp          |   51 +-
 win-odbc64/odbcclient/drvr35/cstmt.cpp          |  119 +-
 398 files changed, 25321 insertions(+), 11177 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/bin/SqlciErrors.txt
----------------------------------------------------------------------
diff --cc core/sql/bin/SqlciErrors.txt
index 2be1bc5,f21cf09..09943f9
--- a/core/sql/bin/SqlciErrors.txt
+++ b/core/sql/bin/SqlciErrors.txt
@@@ -26,7 -26,7 +26,7 @@@
  1024 ZZZZZ 99999 BEGINNER MINOR DBADMIN File system error $0~NSKCode occurred on $1~String0. $2~String1
  1025 ZZZZZ 99999 BEGINNER MINOR DBADMIN Request failed.  Dependent object $0~string0 exists.
  1026 ZZZZZ 99999 BEGINNER MINOR DBADMIN Only the schema owner or super ID can drop a schema.
--1027 ZZZZZ 99999 BEGINNER MINOR DBADMIN The definition schema $0~SchemaName is dropped when its catalog is dropped.
++1027 ZZZZZ 99999 BEGINNER MINOR DBADMIN The view $0~TableName was created before column privileges was supported. To grant column privileges, please recreate the view.
  1028 ZZZZZ 99999 BEGINNER MINOR DBADMIN The schema must be empty.  It contains at least one object $0~TableName.
  1029 ZZZZZ 99999 BEGINNER MINOR DBADMIN Object $0~TableName could not be created.
  1030 ZZZZZ 99999 BEGINNER MINOR DBADMIN The HBase name has a length of $0~Int0 which is too long. Maximum length supported is $1~Int1.  

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/comexe/ComTdb.h
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/common/ComSmallDefs.h
----------------------------------------------------------------------
diff --cc core/sql/common/ComSmallDefs.h
index 66759ae,5a25b62..1563524
--- a/core/sql/common/ComSmallDefs.h
+++ b/core/sql/common/ComSmallDefs.h
@@@ -638,7 -642,7 +642,8 @@@ enum ComTextType {COM_VIEW_TEXT = 0
                    COM_COMPUTED_COL_TEXT = 4,
                    COM_HBASE_COL_FAMILY_TEXT = 5,
                    COM_HBASE_SPLIT_TEXT = 6,
-                   COM_VIEW_REF_COLS_TEXT = 7
 -                  COM_STORED_DESC_TEXT = 7
++                  COM_STORED_DESC_TEXT = 7,
++                  COM_VIEW_REF_COLS_TEXT = 8
  };
  
  enum ComColumnDirection { COM_UNKNOWN_DIRECTION

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cd3d7e7b/core/sql/generator/Generator.cpp
----------------------------------------------------------------------
diff --cc core/sql/generator/Generator.cpp
index 77e4e35,6530a3a..9f2be03
--- a/core/sql/generator/Generator.cpp
+++ b/core/sql/generator/Generator.cpp
@@@ -2073,44 -2147,36 +2147,44 @@@ TrafDesc * Generator::createVirtualTabl
  
        if (viewInfo[0].viewCheckText)
  	{
- 	  view_desc->body.view_desc.viewchecktext = new HEAP char[strlen(viewInfo[0].viewCheckText)+1];
- 	  strcpy(view_desc->body.view_desc.viewchecktext, viewInfo[0].viewCheckText);
+ 	  view_desc->viewDesc()->viewchecktext = new GENHEAP(space) char[strlen(viewInfo[0].viewCheckText)+1];
+ 	  strcpy(view_desc->viewDesc()->viewchecktext, viewInfo[0].viewCheckText);
  	}
        else
- 	view_desc->body.view_desc.viewchecktext = NULL;
+ 	view_desc->viewDesc()->viewchecktext = NULL;
  
 +      if (viewInfo[0].viewColUsages)
 +	{
- 	  view_desc->body.view_desc.viewcolusages = new HEAP char[strlen(viewInfo[0].viewColUsages)+1];
- 	  strcpy(view_desc->body.view_desc.viewcolusages, viewInfo[0].viewColUsages);
++	  view_desc->viewDesc()->viewcolusages = new GENHEAP(space) char[strlen(viewInfo[0].viewColUsages)+1];
++	  strcpy(view_desc->viewDesc()->viewcolusages, viewInfo[0].viewColUsages);
 +	}
 +      else
- 	view_desc->body.view_desc.viewcolusages = NULL;
++	view_desc->viewDesc()->viewcolusages = NULL;
 +
-       view_desc->body.view_desc.updatable = viewInfo[0].isUpdatable;
-       view_desc->body.view_desc.insertable = viewInfo[0].isInsertable;
+       view_desc->viewDesc()->setUpdatable(viewInfo[0].isUpdatable);
+       view_desc->viewDesc()->setInsertable(viewInfo[0].isInsertable);
      }
  
-   desc_struct * seq_desc = NULL;
+   TrafDesc * seq_desc = NULL;
    if (seqInfo)
      {
-       seq_desc = readtabledef_allocate_desc(DESC_SEQUENCE_GENERATOR_TYPE);
+       seq_desc = TrafAllocateDDLdesc(DESC_SEQUENCE_GENERATOR_TYPE, space);
        
-       seq_desc->body.sequence_generator_desc.sgType = (ComSequenceGeneratorType)seqInfo->seqType;
+       seq_desc->sequenceGeneratorDesc()->setSgType((ComSequenceGeneratorType)seqInfo->seqType);
  
-       seq_desc->body.sequence_generator_desc.fsDataType = (ComFSDataType)seqInfo->datatype;
-       seq_desc->body.sequence_generator_desc.startValue = seqInfo->startValue;
-       seq_desc->body.sequence_generator_desc.increment = seqInfo->increment;
+       seq_desc->sequenceGeneratorDesc()->fsDataType = (ComFSDataType)seqInfo->datatype;
+       seq_desc->sequenceGeneratorDesc()->startValue = seqInfo->startValue;
+       seq_desc->sequenceGeneratorDesc()->increment = seqInfo->increment;
  
-       seq_desc->body.sequence_generator_desc.maxValue = seqInfo->maxValue;
-       seq_desc->body.sequence_generator_desc.minValue = seqInfo->minValue;
-       seq_desc->body.sequence_generator_desc.cycleOption = 
+       seq_desc->sequenceGeneratorDesc()->maxValue = seqInfo->maxValue;
+       seq_desc->sequenceGeneratorDesc()->minValue = seqInfo->minValue;
+       seq_desc->sequenceGeneratorDesc()->cycleOption = 
  	(seqInfo->cycleOption ? TRUE : FALSE);
-       seq_desc->body.sequence_generator_desc.cache = seqInfo->cache;      
-       seq_desc->body.sequence_generator_desc.objectUID = seqInfo->seqUID;
+       seq_desc->sequenceGeneratorDesc()->cache = seqInfo->cache;      
+       seq_desc->sequenceGeneratorDesc()->objectUID = seqInfo->seqUID;
        
-       seq_desc->body.sequence_generator_desc.nextValue = seqInfo->nextValue;
-       seq_desc->body.sequence_generator_desc.redefTime = seqInfo->redefTime;
+       seq_desc->sequenceGeneratorDesc()->nextValue = seqInfo->nextValue;
+       seq_desc->sequenceGeneratorDesc()->redefTime = seqInfo->redefTime;
      }
  
    // cannot simply point to same files desc as the table one,


[07/10] incubator-trafodion git commit: Fixed a couple of issues with TRAFODION-1788 delivery

Posted by rm...@apache.org.
Fixed a couple of issues with TRAFODION-1788 delivery


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

Branch: refs/heads/master
Commit: 08573725a75f8a1168ca6da6a7727b6f6a6f8900
Parents: 5edd6b1
Author: Roberta Marton <rm...@edev07.esgyn.local>
Authored: Wed Aug 10 14:30:46 2016 +0000
Committer: Roberta Marton <rm...@edev07.esgyn.local>
Committed: Wed Aug 10 14:30:46 2016 +0000

----------------------------------------------------------------------
 core/sql/bin/SqlciErrors.txt           |  2 +-
 core/sql/common/ComViewColUsage.h      | 29 ++++++++++++++++++++++++++---
 core/sql/regress/privs2/TEST143        |  1 +
 core/sql/sqlcomp/CmpSeabaseDDLview.cpp | 10 ++++------
 core/sql/sqlcomp/PrivMgrMD.cpp         | 16 ++++------------
 core/sql/sqlcomp/PrivMgrMD.h           | 19 +++++++++++++++----
 core/sql/sqlcomp/PrivMgrPrivileges.cpp | 10 +++++-----
 7 files changed, 56 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/08573725/core/sql/bin/SqlciErrors.txt
----------------------------------------------------------------------
diff --git a/core/sql/bin/SqlciErrors.txt b/core/sql/bin/SqlciErrors.txt
index 09943f9..0851346 100644
--- a/core/sql/bin/SqlciErrors.txt
+++ b/core/sql/bin/SqlciErrors.txt
@@ -26,7 +26,7 @@
 1024 ZZZZZ 99999 BEGINNER MINOR DBADMIN File system error $0~NSKCode occurred on $1~String0. $2~String1
 1025 ZZZZZ 99999 BEGINNER MINOR DBADMIN Request failed.  Dependent object $0~string0 exists.
 1026 ZZZZZ 99999 BEGINNER MINOR DBADMIN Only the schema owner or super ID can drop a schema.
-1027 ZZZZZ 99999 BEGINNER MINOR DBADMIN The view $0~TableName was created before column privileges was supported. To grant column privileges, please recreate the view.
+1027 ZZZZZ 99999 BEGINNER MINOR DBADMIN The view $0~TableName was created before column privileges were supported. To grant column privileges, please recreate the view.
 1028 ZZZZZ 99999 BEGINNER MINOR DBADMIN The schema must be empty.  It contains at least one object $0~TableName.
 1029 ZZZZZ 99999 BEGINNER MINOR DBADMIN Object $0~TableName could not be created.
 1030 ZZZZZ 99999 BEGINNER MINOR DBADMIN The HBase name has a length of $0~Int0 which is too long. Maximum length supported is $1~Int1.  

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/08573725/core/sql/common/ComViewColUsage.h
----------------------------------------------------------------------
diff --git a/core/sql/common/ComViewColUsage.h b/core/sql/common/ComViewColUsage.h
index 811be07..7d061c7 100644
--- a/core/sql/common/ComViewColUsage.h
+++ b/core/sql/common/ComViewColUsage.h
@@ -47,6 +47,27 @@ class ComViewColUsage
   ComObjectType refdObjectType_;
 
 public:
+  ComViewColUsage ()
+  : viewUID_ (0),
+    viewColNumber_ (-1),
+    refdUID_(0),
+    refdColNumber_(-1),
+    refdObjectType_(COM_UNKNOWN_OBJECT)
+  {}
+
+  ComViewColUsage (
+   Int64 viewUID,
+   Int32 viewColNumber,
+   Int64 refdUID,
+   Int32 refdColNumber,
+   ComObjectType refdObjectType)
+ : viewUID_ (viewUID),
+   viewColNumber_ (viewColNumber),
+   refdUID_ (refdUID),
+   refdColNumber_ (refdColNumber),
+   refdObjectType_ (refdObjectType)
+{}
+
   virtual ~ComViewColUsage()
   {};
 
@@ -67,7 +88,9 @@ public:
 
   void packUsage (NAString &viewColUsageStr)
   {
-      char buf[sizeof(Int64)*2 + sizeof(Int32)*3 + 100];
+      // usage contains 2 int64 and 3 int32, 100 chars is big enough to hold 
+      // the string representation
+      char buf[100];
       str_sprintf(buf, "viewUID: %Ld viewCol: %d refUID: %Ld refCol: %d refType: %d;",
                   viewUID_, viewColNumber_,
                   refdUID_, refdColNumber_, refdObjectType_);
@@ -77,10 +100,10 @@ public:
   void unpackUsage (const char *viewColUsageStr)
   {
       Int32 theRefdObjectType;
-      sscanf(viewColUsageStr, "viewUID: %Ld viewCol: %d refUID: %Ld refCol: %d refType: %d%*s",
+      Int32 retcode = sscanf(viewColUsageStr, "viewUID: %Ld viewCol: %d refUID: %Ld refCol: %d refType: %d%*s" ,
              (long long int *)&viewUID_, &viewColNumber_, 
              (long long int *)&refdUID_, &refdColNumber_, &theRefdObjectType);
-
+      assert (retcode == 5);
       refdObjectType_ = (ComObjectType) theRefdObjectType;
   }
 };

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/08573725/core/sql/regress/privs2/TEST143
----------------------------------------------------------------------
diff --git a/core/sql/regress/privs2/TEST143 b/core/sql/regress/privs2/TEST143
index 2bb2ad8..98a6005 100755
--- a/core/sql/regress/privs2/TEST143
+++ b/core/sql/regress/privs2/TEST143
@@ -47,6 +47,7 @@ drop schema if exists t143_udr cascade;
 drop schema if exists t143_user1 cascade;
 drop schema if exists t143_user2 cascade;
 drop schema if exists t143_user3 cascade;
+drop schema if exists t143_user5 cascade;
 
 revoke role user2_role from sql_user2;
 revoke role user3_role from sql_user3;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/08573725/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLview.cpp b/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
index f9c5c33..aaeb0d3 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLview.cpp
@@ -295,12 +295,10 @@ short CmpSeabaseDDL::buildViewTblColUsage(const StmtDDLCreateView * createViewPa
         return -1;
      }
 
-     ComViewColUsage colUsage;
-     colUsage.setViewUID (objUID);
-     colUsage.setViewColNumber (usingColNum);
-     colUsage.setRefdUID (naTable->objectUid().get_value());
-     colUsage.setRefdColNumber (naCol->getPosition());
-     colUsage.setRefdObjectType (naTable->getObjectType());
+     ComViewColUsage colUsage(objUID, usingColNum, 
+                              naTable->objectUid().get_value(),
+                              naCol->getPosition(),
+                              naTable->getObjectType());
      NAString viewColUsageStr;
      colUsage.packUsage(viewColUsageStr);
      viewColUsageText += viewColUsageStr;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/08573725/core/sql/sqlcomp/PrivMgrMD.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrMD.cpp b/core/sql/sqlcomp/PrivMgrMD.cpp
index 2ece65b..4af666c 100644
--- a/core/sql/sqlcomp/PrivMgrMD.cpp
+++ b/core/sql/sqlcomp/PrivMgrMD.cpp
@@ -637,17 +637,13 @@ bool PrivMgrMDAdmin::isAuthorized (void)
 // **************************************************************************** 
 PrivStatus PrivMgrMDAdmin::getColumnReferences (ObjectReference *objectRef)
 {
-  std::string objectMDTable = trafMetadataLocation_ + ".OBJECTS o";
   std::string colMDTable = trafMetadataLocation_ + ".COLUMNS c";
 
   // Select column details for object 
   std::string selectStmt = "select c.column_number from ";
-  selectStmt += objectMDTable;
-  selectStmt += ", ";
   selectStmt += colMDTable;
-  selectStmt += " where o.object_uid = ";
+  selectStmt += " where c.object_uid = ";
   selectStmt += UIDToString(objectRef->objectUID);
-  selectStmt += " and o.object_uid = c.object_uid";
   selectStmt += " order by column_number";
 
   ExeCliInterface cliInterface(STMTHEAP, NULL, NULL,
@@ -696,23 +692,20 @@ PrivStatus PrivMgrMDAdmin::getColumnReferences (ObjectReference *objectRef)
 //  relationship.
 //
 //  This relationship is stored in one or more text records with the text_type
-//  COM_VIEW_REF_COLS_TEXT (7) see ComSmallDefs.h 
+//  COM_VIEW_REF_COLS_TEXT (8) see ComSmallDefs.h 
 //
 //  The text rows are concatenated together and saved in the ViewUsage.
 // **************************************************************************** 
 PrivStatus PrivMgrMDAdmin::getViewColUsages (ViewUsage &viewUsage)
 {
-  std::string objectMDTable = trafMetadataLocation_ + ".OBJECTS o";
   std::string textMDTable = trafMetadataLocation_ + ".TEXT t";
 
   // Select text rows describing view <=> object column relationships
   std::string selectStmt = "select text from ";
-  selectStmt += objectMDTable;
-  selectStmt += ", ";
   selectStmt += textMDTable;
-  selectStmt += " where o.object_uid = ";
+  selectStmt += " where t.text_uid = ";
   selectStmt += UIDToString(viewUsage.viewUID);
-  selectStmt += "and o.object_uid = t.text_uid and t.text_type = 8";
+  selectStmt += "and t.text_type = 8";
   selectStmt += " order by seq_num";
   
   ExeCliInterface cliInterface(STMTHEAP, NULL, NULL,
@@ -745,7 +738,6 @@ PrivStatus PrivMgrMDAdmin::getViewColUsages (ViewUsage &viewUsage)
   for (int idx = 0; idx < objectsQueue->numEntries(); idx++)
   { 
     OutputInfo * pCliRow = (OutputInfo*)objectsQueue->getNext();
-    ColumnReference *columnReference = new ColumnReference;
 
     // column 0: text 
     pCliRow->get(0,ptr,len);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/08573725/core/sql/sqlcomp/PrivMgrMD.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrMD.h b/core/sql/sqlcomp/PrivMgrMD.h
index 783dbe5..4180db1 100644
--- a/core/sql/sqlcomp/PrivMgrMD.h
+++ b/core/sql/sqlcomp/PrivMgrMD.h
@@ -74,6 +74,15 @@ struct ColumnReference {
     originalPrivs(),
     updatedPrivs(){};
 
+  ColumnReference & operator=(const ColumnReference& other)
+  {
+    columnOrdinal = other.columnOrdinal;
+    originalPrivs = other.originalPrivs;
+    updatedPrivs = other.updatedPrivs;
+
+    return *this;
+  }
+
   void describe (std::string &details) const
   {
     details = "column usage - column number is ";
@@ -191,6 +200,7 @@ class ObjectUsage
         delete columnReferences->back(), columnReferences->pop_back();
       delete columnReferences;
     }
+    columnReferences = NULL;
   }
 
   int64_t objectUID;
@@ -204,6 +214,9 @@ class ObjectUsage
 
   void copyColumnReferences(const std::vector<ColumnReference *> *refsToCopy)
   {
+    if (columnReferences != NULL)
+      delete columnReferences;
+
     if (refsToCopy == NULL)
       columnReferences = NULL;
     else
@@ -212,10 +225,8 @@ class ObjectUsage
       for (int i = 0; i < refsToCopy->size(); i++)
       {
         ColumnReference *newRef = new ColumnReference;
-        const ColumnReference *oldRef = (*refsToCopy)[i];
-        newRef->columnOrdinal = oldRef->columnOrdinal;
-        newRef->originalPrivs = oldRef->originalPrivs;
-        newRef->updatedPrivs = oldRef->updatedPrivs;
+        ColumnReference *copyRef = (*refsToCopy)[i];
+        newRef->operator=(*copyRef);
         columnReferences->push_back(newRef);
       }
     }

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/08573725/core/sql/sqlcomp/PrivMgrPrivileges.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrPrivileges.cpp b/core/sql/sqlcomp/PrivMgrPrivileges.cpp
index 5c5b21c..c3b116a 100644
--- a/core/sql/sqlcomp/PrivMgrPrivileges.cpp
+++ b/core/sql/sqlcomp/PrivMgrPrivileges.cpp
@@ -2163,8 +2163,9 @@ PrivStatus PrivMgrPrivileges::gatherViewColUsages(
     {
       traceMsg += "getting column references: number references found ";
       traceMsg += to_string((long long int)objectRef->columnReferences->size());
+      traceMsg += ", ";
     }
-    traceMsg += ", retcode is ";
+    traceMsg += "retcode is ";
     traceMsg += privStatusEnumToLit(retcode);
     log (__FILE__, traceMsg, -1);
     if (retcode == STATUS_ERROR)
@@ -2176,7 +2177,7 @@ PrivStatus PrivMgrPrivileges::gatherViewColUsages(
   if (viewUsage.viewColUsagesStr.empty())
   {
     retcode = admin.getViewColUsages(viewUsage);
-    traceMsg += "getting view column usages";
+    traceMsg = "getting view column usages";
     traceMsg += ", retcode is ";
     traceMsg += privStatusEnumToLit(retcode);
     log (__FILE__, traceMsg, -1);
@@ -2615,7 +2616,7 @@ PrivStatus PrivMgrPrivileges::getAffectedObjects(
 
 
   // Find list of affected constraints
-  if (isGrantCommand(command))
+  if (isRevokeCommand(command))
   {
     // TBD optimization: if no "references" privilege has been revoked, skip
     retcode = dealWithConstraints (objectUsage, listOfAffectedObjects);
@@ -4531,7 +4532,6 @@ void PrivMgrPrivileges::summarizeColPrivs(
       {
         ColumnPrivsMDRow &row = static_cast<ColumnPrivsMDRow &> (*rowList[j]);
         PrivMgrCoreDesc originalPrivs(row.privsBitmap_, row.grantableBitmap_);
-        PrivMgrCoreDesc original = originalPrivs;
         PrivMgrCoreDesc updated = originalPrivs;
 
         // Update if privileges have been changed by request
@@ -4547,7 +4547,7 @@ void PrivMgrPrivileges::summarizeColPrivs(
               updated = changedRef->updatedPrivs;
           }
         }
-        summarized->originalPrivs.unionOfPrivs(original);
+        summarized->originalPrivs.unionOfPrivs(originalPrivs);
         summarized->updatedPrivs.unionOfPrivs(updated);
       }
     }