new COMMENT-ON SQL statement: review change - add support for sequence and 
columns of view

1. add comment support for sequence generator
2. add comment support for columns of view
3. wrong comments and spellings


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

Branch: refs/heads/master
Commit: 4127e1c0e639a3d5eb71010095a82376348b089b
Parents: cc8f68f
Author: eedy <cqlc...@gmail.com>
Authored: Sun Nov 5 08:26:52 2017 +0800
Committer: eedy <cqlc...@gmail.com>
Committed: Sun Nov 5 08:26:52 2017 +0800

----------------------------------------------------------------------
 core/sql/parser/BindStmtDDL.cpp             |  4 +-
 core/sql/parser/StmtDDLCommentOn.h          |  5 ++-
 core/sql/parser/StmtDDLCreate.cpp           |  6 ++-
 core/sql/parser/sqlparser.y                 |  4 ++
 core/sql/sqlcomp/CmpDescribe.cpp            | 13 ++++++-
 core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp | 47 +++++++++++++-----------
 core/sql/sqlcomp/CmpSeabaseDDLschema.cpp    |  2 +-
 core/sql/sqlcomp/CmpSeabaseDDLtable.cpp     | 10 ++---
 core/sql/sqlcomp/PrivMgr.cpp                |  2 +-
 9 files changed, 59 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4127e1c0/core/sql/parser/BindStmtDDL.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/BindStmtDDL.cpp b/core/sql/parser/BindStmtDDL.cpp
index f0e01e4..2294b45 100644
--- a/core/sql/parser/BindStmtDDL.cpp
+++ b/core/sql/parser/BindStmtDDL.cpp
@@ -2577,7 +2577,7 @@ StmtDDLAlterUser::bindNode(BindWA * pBindWA)
 }
 
 // -----------------------------------------------------------------------
-// definition of method bindNode() for class StmtDDLCreateLibrary
+// definition of method bindNode() for class StmtDDLCommentOn
 // -----------------------------------------------------------------------
 
 ExprNode *
@@ -2611,6 +2611,8 @@ StmtDDLCommentOn::bindNode(BindWA * pBindWA)
               return this;
             }
 
+          isViewCol_ = (naTable->getViewText() ? TRUE : FALSE);
+
           const NAColumnArray &nacolArr = naTable->getNAColumnArray();
           const NAColumn * nacol = nacolArr.getColumn(getColName());
           if (! nacol)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4127e1c0/core/sql/parser/StmtDDLCommentOn.h
----------------------------------------------------------------------
diff --git a/core/sql/parser/StmtDDLCommentOn.h 
b/core/sql/parser/StmtDDLCommentOn.h
index cec13f6..57b3542 100644
--- a/core/sql/parser/StmtDDLCommentOn.h
+++ b/core/sql/parser/StmtDDLCommentOn.h
@@ -65,6 +65,7 @@ public:
     COMMENT_ON_TYPE_LIBRARY,
     COMMENT_ON_TYPE_PROCEDURE,
     COMMENT_ON_TYPE_FUNCTION,
+    COMMENT_ON_TYPE_SEQUENCE,
     COMMENT_ON_TYPE_UNKNOWN
   };
 
@@ -100,6 +101,7 @@ public:
   inline const NAString getObjectName() const;
   inline const NAString &getComment() const { return comment_; }
   inline const NAString &getColName() const { return 
colRef_->getColRefNameObj().getColName(); }
+  inline NABoolean getIsViewCol() { return isViewCol_; }
 
 
   inline Int32 getVersion() {return 1;}
@@ -116,7 +118,8 @@ private:
 
   enum COMMENT_ON_TYPES  type_;
   QualifiedName          objectName_;
-  ColReference        * colRef_;
+  ColReference         * colRef_;
+  NABoolean              isViewCol_;
 
   const NAString       & comment_;
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4127e1c0/core/sql/parser/StmtDDLCreate.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/StmtDDLCreate.cpp 
b/core/sql/parser/StmtDDLCreate.cpp
index 4537f72..ff39634 100644
--- a/core/sql/parser/StmtDDLCreate.cpp
+++ b/core/sql/parser/StmtDDLCreate.cpp
@@ -7179,7 +7179,8 @@ StmtDDLCommentOn::StmtDDLCommentOn(COMMENT_ON_TYPES 
objType, const QualifiedName
     type_(objType),
     objectName_(objName, heap),
     comment_(commentStr),
-    colRef_(NULL)
+    colRef_(NULL),
+    isViewCol_(FALSE)
 {
       
 }
@@ -7190,7 +7191,8 @@ StmtDDLCommentOn::StmtDDLCommentOn(COMMENT_ON_TYPES 
objType, const QualifiedName
     type_(objType),
     objectName_(objName, heap),
     colRef_(colRef),
-    comment_(commentStr)
+    comment_(commentStr),
+    isViewCol_(FALSE)
 {
       
 }

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4127e1c0/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 1b43b02..df4cc2e 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -33266,6 +33266,10 @@ comment_on_object_types : TOK_TABLE
                {
                  $$ = StmtDDLCommentOn::COMMENT_ON_TYPE_FUNCTION;
                }
+             | TOK_SEQUENCE
+               {
+                 $$ = StmtDDLCommentOn::COMMENT_ON_TYPE_SEQUENCE;
+               }
                
                
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4127e1c0/core/sql/sqlcomp/CmpDescribe.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpDescribe.cpp b/core/sql/sqlcomp/CmpDescribe.cpp
index af9503f..fed0087 100644
--- a/core/sql/sqlcomp/CmpDescribe.cpp
+++ b/core/sql/sqlcomp/CmpDescribe.cpp
@@ -3062,7 +3062,7 @@ short CmpDescribeSeabaseTable (
       outputLongLine(*space, viewtext, 0);
 
       //display comment for VIEW
-      if (objectUID > 0/* && COMMENT_CQD*/)
+      if (objectUID > 0)
         {
           if (cmpSBD.switchCompiler())
             {
@@ -3086,6 +3086,17 @@ short CmpDescribeSeabaseTable (
                              objCommentInfo->objectComment);
                 outputLine(*space, buf, 0);
               }
+
+              //display Column COMMENT statements
+              outputLine(*space, "", 0);
+              for (int idx = 0; idx < objCommentInfo->numColumnComment; idx++)
+                {
+                  sprintf(buf,  "COMMENT ON COLUMN %s.%s IS '%s' ;",
+                           tableName.data(),
+                           objCommentInfo->columnCommentArray[idx].columnName,
+                           
objCommentInfo->columnCommentArray[idx].columnComment);
+                   outputLine(*space, buf, 0);
+                }
             }
 
           cmpSBD.switchBackCompiler();

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4127e1c0/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp 
b/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp
index 83fc83f..95b589f 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp
@@ -74,7 +74,7 @@ void  CmpSeabaseDDL::doSeabaseCommentOn(StmtDDLCommentOn   
*commentOnNode,
   Lng32 retcode;
 
   enum ComObjectType enMDObjType = COM_UNKNOWN_OBJECT;
-  
+
   ComObjectName objectName(commentOnNode->getObjectName());
   ComAnsiNamePart currCatAnsiName(currCatName);
   ComAnsiNamePart currSchAnsiName(currSchName);
@@ -87,9 +87,16 @@ void  CmpSeabaseDDL::doSeabaseCommentOn(StmtDDLCommentOn   
*commentOnNode,
         case StmtDDLCommentOn::COMMENT_ON_TYPE_TABLE:
             enMDObjType = COM_BASE_TABLE_OBJECT;
             break;
-    
+
         case StmtDDLCommentOn::COMMENT_ON_TYPE_COLUMN:
-            enMDObjType = COM_BASE_TABLE_OBJECT;
+            if (TRUE == commentOnNode->getIsViewCol())
+              {
+                enMDObjType = COM_VIEW_OBJECT;
+              }
+            else
+              {
+                enMDObjType = COM_BASE_TABLE_OBJECT;
+              }
             break;
 
         case StmtDDLCommentOn::COMMENT_ON_TYPE_INDEX:
@@ -113,6 +120,9 @@ void  CmpSeabaseDDL::doSeabaseCommentOn(StmtDDLCommentOn   
*commentOnNode,
             enMDObjType = COM_USER_DEFINED_ROUTINE_OBJECT;
             break;
 
+        case StmtDDLCommentOn::COMMENT_ON_TYPE_SEQUENCE:
+            enMDObjType = COM_SEQUENCE_GENERATOR_OBJECT;
+
         default:
             break;
 
@@ -127,26 +137,10 @@ void  CmpSeabaseDDL::doSeabaseCommentOn(StmtDDLCommentOn  
 *commentOnNode,
   ExeCliInterface cliInterface(STMTHEAP, NULL, NULL,
                                        
CmpCommon::context()->sqlSession()->getParentQid());
   Int64 objUID = 0;
-  Int32 objectOwnerID = SUPER_USER;
-  Int32 schemaOwnerID = SUPER_USER;
+  Int32 objectOwnerID = ROOT_USER_ID;
+  Int32 schemaOwnerID = ROOT_USER_ID;
   Int64 objectFlags = 0;
 
-  // Verify that the requester has COMMENT privilege.
-  if (isAuthorizationEnabled() && !ComUser::isRootUserID())
-    {
-      NAString privMgrMDLoc;
-      CONCAT_CATSCH(privMgrMDLoc, getSystemCatalog(), SEABASE_PRIVMGR_SCHEMA);
-
-      PrivMgrComponentPrivileges 
componentPrivileges(std::string(privMgrMDLoc.data()), CmpCommon::diags());
-
-      if (!componentPrivileges.hasSQLPriv(ComUser::getCurrentUser(), 
SQLOperation::COMMENT, true))
-      {
-         *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED);
-         processReturn ();
-         return;
-      }
-    }
-
   //get UID of object
   objUID = getObjectInfo(&cliInterface,
                               catalogNamePart.data(), schemaNamePart.data(), 
objNamePart.data(), 
@@ -163,6 +157,16 @@ void  CmpSeabaseDDL::doSeabaseCommentOn(StmtDDLCommentOn   
*commentOnNode,
       return;
     }
 
+  // Verify that the requester has COMMENT privilege.
+  if (!isDDLOperationAuthorized(SQLOperation::COMMENT, schemaOwnerID, 
schemaOwnerID))
+    {
+      *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED);
+      processReturn ();
+      return;
+    }
+
+  //check for overflow, but how i can get type size of COMMENT column?
+
   // add, remove, change comment of object/column
   const NAString & comment = commentOnNode->getComment();
   char * query = new(STMTHEAP) char[comment.length()+1024];
@@ -187,7 +191,6 @@ void  CmpSeabaseDDL::doSeabaseCommentOn(StmtDDLCommentOn   
*commentOnNode,
       cliRC = cliInterface.executeImmediate(query);
     }
 
-
   NADELETEBASIC(query, STMTHEAP);
   if (cliRC < 0)
     {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4127e1c0/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp 
b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
index 3cc4c93..021a605 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
@@ -453,7 +453,7 @@ Int16 status = 
ComUser::getAuthNameFromAuthID(objectOwner,username,
    
    outlines.push_back(output.data());
    
-   // Disaply Comment of schema
+   // Display Comment of schema
     {
       ComTdbVirtObjCommentInfo * objCommentInfo = NULL;
       cmpSBD.getSeabaseObjectComment(schemaUID, objectType, objCommentInfo);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4127e1c0/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp 
b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
index 4924c14..5fd5794 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
@@ -12948,12 +12948,9 @@ short CmpSeabaseDDL::getSeabaseObjectComment(Int64 
object_uid,
   Lng32 cliRC = 0;
 
   char query[4000];
-
   comment_info = NULL;
 
-
-  ExeCliInterface cliInterface(STMTHEAP, 
-                               NULL, NULL, 
+  ExeCliInterface cliInterface(STMTHEAP, NULL, NULL, 
                                
CmpCommon::context()->sqlSession()->getParentQid());
 
   //get object comment
@@ -12973,7 +12970,7 @@ short CmpSeabaseDDL::getSeabaseObjectComment(Int64 
object_uid,
   if (objQueue->numEntries() == 1)
     {
       objQueue->position();
-      
+
       OutputInfo * vi = (OutputInfo*)objQueue->getNext(); 
 
       comment_info = new(STMTHEAP) ComTdbVirtObjCommentInfo[1];
@@ -13033,7 +13030,10 @@ short CmpSeabaseDDL::getSeabaseObjectComment(Int64 
object_uid,
             indexComment.indexComment = (char*) oi->get(1);
           }
        }
+    }
 
+  if (COM_BASE_TABLE_OBJECT == object_type || COM_VIEW_OBJECT == object_type)
+    {
       //get column comment of table
       str_sprintf(query, "select COLUMN_NAME, COMMENT from %s.\"%s\".%s where 
OBJECT_UID = %ld and comment <> '' order by COLUMN_NUMBER ;",
               getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS, 
object_uid);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4127e1c0/core/sql/sqlcomp/PrivMgr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgr.cpp b/core/sql/sqlcomp/PrivMgr.cpp
index f9811c0..c8a1a20 100644
--- a/core/sql/sqlcomp/PrivMgr.cpp
+++ b/core/sql/sqlcomp/PrivMgr.cpp
@@ -483,7 +483,7 @@ const char * PrivMgr::getSQLOperationCode(SQLOperation 
operation)
       case SQLOperation::SHOW: return "SW";
       case SQLOperation::UNREGISTER_HIVE_OBJECT: return "UH";
       case SQLOperation::USE_ALTERNATE_SCHEMA: return "UA";
-         case SQLOperation::COMMENT: return "CO";
+      case SQLOperation::COMMENT: return "CO";
       default:
          return "  ";   
    }

Reply via email to