Repository: incubator-trafodion Updated Branches: refs/heads/master 087bb5d0d -> b03aa4fd6
new COMMENT-ON SQL statement: init 1. new SQL syntax: COMMENT ON 2. new component privilege: SQL_OPERATIONS::COMMENT 3. MD table changes: add new column for tables "_MD_".OBJECTS and "_MD_".COLUMNS 4. SHOWDDL changes: add COMMENT-ON output for each object 5. new build-in views: "_MD_".OBJECT_COMMENT_VIEW and "_MD_".COLUMN_COMMENT_VIEW Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/078ed10c Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/078ed10c Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/078ed10c Branch: refs/heads/master Commit: 078ed10cc8d5d4024b3a2dd2ff965cac46f38c9f Parents: 68fe67f Author: eedy <cqlc...@gmail.com> Authored: Thu Nov 2 17:17:31 2017 +0800 Committer: eedy <cqlc...@gmail.com> Committed: Thu Nov 2 17:17:31 2017 +0800 ---------------------------------------------------------------------- core/sql/comexe/ComTdb.h | 55 ++++++ core/sql/common/OperTypeEnum.h | 1 + core/sql/nskgmake/sqlcomp/Makefile | 1 + core/sql/optimizer/RelExeUtil.cpp | 11 +- core/sql/parser/AllStmtDDLCreate.h | 1 + core/sql/parser/BindStmtDDL.cpp | 54 ++++++ core/sql/parser/ElemDDLNode.cpp | 8 + core/sql/parser/ElemDDLNode.h | 3 + core/sql/parser/StmtDDLCommentOn.h | 148 +++++++++++++++++ core/sql/parser/StmtDDLCreate.cpp | 45 +++++ core/sql/parser/sqlparser.y | 105 +++++++++++- core/sql/parser/ulexer.cpp | 1 + core/sql/regress/privs1/EXPECTED133 | Bin 27095 -> 27095 bytes core/sql/regress/privs1/EXPECTED137 | 14 ++ core/sql/sqlcomp/CmpDescribe.cpp | 159 +++++++++++++++++- core/sql/sqlcomp/CmpSeabaseDDL.h | 8 + core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp | 202 +++++++++++++++++++++++ core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 18 +- core/sql/sqlcomp/CmpSeabaseDDLincludes.h | 1 + core/sql/sqlcomp/CmpSeabaseDDLmd.h | 40 ++++- core/sql/sqlcomp/CmpSeabaseDDLschema.cpp | 28 +++- core/sql/sqlcomp/CmpSeabaseDDLtable.cpp | 146 +++++++++++++++- core/sql/sqlcomp/CmpSeabaseDDLupgrade.h | 23 ++- core/sql/sqlcomp/CmpSeabaseDDLview.cpp | 19 +++ core/sql/sqlcomp/PrivMgr.cpp | 3 + core/sql/sqlcomp/PrivMgrDefs.h | 3 +- 26 files changed, 1062 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/comexe/ComTdb.h ---------------------------------------------------------------------- diff --git a/core/sql/comexe/ComTdb.h b/core/sql/comexe/ComTdb.h index 62b7550..73fa28a 100644 --- a/core/sql/comexe/ComTdb.h +++ b/core/sql/comexe/ComTdb.h @@ -1128,6 +1128,61 @@ class ComTdbVirtTableLibraryInfo : public ComTdbVirtTableBase Int32 schema_owner_id; }; + +class ComTdbVirtIndexCommentInfo : public ComTdbVirtTableBase +{ + public: + ComTdbVirtIndexCommentInfo() + : ComTdbVirtTableBase() + { + init(); + } + + virtual Int32 size() { return sizeof(ComTdbVirtIndexCommentInfo);} + + const char *indexFullName; + const char *indexComment; +}; + + +class ComTdbVirtColumnCommentInfo : public ComTdbVirtTableBase +{ + public: + ComTdbVirtColumnCommentInfo() + : ComTdbVirtTableBase() + { + init(); + } + + virtual Int32 size() { return sizeof(ComTdbVirtColumnCommentInfo);} + + const char *columnName; + const char *columnComment; +}; + +class ComTdbVirtObjCommentInfo : public ComTdbVirtTableBase +{ + public: + ComTdbVirtObjCommentInfo() + : ComTdbVirtTableBase() + { + init(); + } + + virtual Int32 size() { return sizeof(ComTdbVirtObjCommentInfo);} + + Int64 objectUid; + const char *objectComment; + + Int32 numColumnComment; + ComTdbVirtColumnCommentInfo * columnCommentArray; + + Int32 numIndexComment; + ComTdbVirtIndexCommentInfo * indexCommentArray; +}; + + + #endif /* COMTDB_H */ http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/common/OperTypeEnum.h ---------------------------------------------------------------------- diff --git a/core/sql/common/OperTypeEnum.h b/core/sql/common/OperTypeEnum.h index bbf064c..c581fa9 100644 --- a/core/sql/common/OperTypeEnum.h +++ b/core/sql/common/OperTypeEnum.h @@ -963,6 +963,7 @@ enum OperatorTypeEnum { DDL_CLEANUP_OBJECTS, DDL_LAST_STMT_OP, DDL_INITIALIZE_SECURITY, + DDL_COMMENT_ON, // // Elements in DDL statements http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/nskgmake/sqlcomp/Makefile ---------------------------------------------------------------------- diff --git a/core/sql/nskgmake/sqlcomp/Makefile b/core/sql/nskgmake/sqlcomp/Makefile index ff2dc65..c579ea6 100755 --- a/core/sql/nskgmake/sqlcomp/Makefile +++ b/core/sql/nskgmake/sqlcomp/Makefile @@ -33,6 +33,7 @@ CPPSRC := CmpDescribe.cpp \ CmpSeabaseDDLtable.cpp \ CmpSeabaseDDLupgrade.cpp \ CmpSeabaseDDLview.cpp \ + CmpSeabaseDDLcommentOn.cpp \ PrivMgr.cpp \ PrivMgrCommands.cpp \ PrivMgrDesc.cpp \ http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/optimizer/RelExeUtil.cpp ---------------------------------------------------------------------- diff --git a/core/sql/optimizer/RelExeUtil.cpp b/core/sql/optimizer/RelExeUtil.cpp index 9cf45a9..71c0421 100644 --- a/core/sql/optimizer/RelExeUtil.cpp +++ b/core/sql/optimizer/RelExeUtil.cpp @@ -83,6 +83,7 @@ #include "StmtDDLCleanupObjects.h" #include "StmtDDLAlterLibrary.h" #include "StmtDDLRegOrUnregHive.h" +#include "StmtDDLCommentOn.h" #include <cextdecs/cextdecs.h> #include "wstr.h" @@ -4083,6 +4084,7 @@ RelExpr * DDLExpr::bindNode(BindWA *bindWA) NABoolean externalTable = FALSE; NABoolean isVolatile = FALSE; NABoolean isRegister = FALSE; + NABoolean isCommentOn = FALSE; returnStatus_ = FALSE; @@ -4550,6 +4552,13 @@ RelExpr * DDLExpr::bindNode(BindWA *bindWA) qualObjName_ = getExprNode()->castToStmtDDLNode()-> castToStmtDDLRegOrUnregObject()->getObjNameAsQualifiedName(); } + else if (getExprNode()->castToStmtDDLNode()->castToStmtDDLCommentOn()) + { + isCommentOn = TRUE; + + qualObjName_ = getExprNode()->castToStmtDDLNode()-> + castToStmtDDLCommentOn()->getObjectNameAsQualifiedName(); + } if (isCleanup_) { @@ -4557,7 +4566,7 @@ RelExpr * DDLExpr::bindNode(BindWA *bindWA) hbaseDDLNoUserXn_ = TRUE; } - if ((isCreateSchema || isDropSchema || isAlterSchema) || isRegister || + if ((isCreateSchema || isDropSchema || isAlterSchema) || isRegister || isCommentOn || ((isTable_ || isIndex_ || isView_ || isRoutine_ || isLibrary_ || isSeq) && (isCreate_ || isDrop_ || purgedata() || (isAlter_ && (alterAddCol || alterDropCol || alterDisableIndex || alterEnableIndex || http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/parser/AllStmtDDLCreate.h ---------------------------------------------------------------------- diff --git a/core/sql/parser/AllStmtDDLCreate.h b/core/sql/parser/AllStmtDDLCreate.h index 706ba2a..6a76125 100644 --- a/core/sql/parser/AllStmtDDLCreate.h +++ b/core/sql/parser/AllStmtDDLCreate.h @@ -54,6 +54,7 @@ #include "StmtDDLCreateSynonym.h" #include "StmtDDLCreateExceptionTable.h" #include "StmtDDLPopulateIndex.h" +#include "StmtDDLCommentOn.h" // // End of File http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/parser/BindStmtDDL.cpp ---------------------------------------------------------------------- diff --git a/core/sql/parser/BindStmtDDL.cpp b/core/sql/parser/BindStmtDDL.cpp index d564d41..f0e01e4 100644 --- a/core/sql/parser/BindStmtDDL.cpp +++ b/core/sql/parser/BindStmtDDL.cpp @@ -2576,6 +2576,60 @@ StmtDDLAlterUser::bindNode(BindWA * pBindWA) } +// ----------------------------------------------------------------------- +// definition of method bindNode() for class StmtDDLCreateLibrary +// ----------------------------------------------------------------------- + +ExprNode * +StmtDDLCommentOn::bindNode(BindWA * pBindWA) +{ + ComASSERT(pBindWA); + + objectName_.applyDefaults(pBindWA->getDefaultSchema()); + if (pBindWA->violateAccessDefaultSchemaOnly(objectName_)) + return this; + + if (this->type_ == COMMENT_ON_TYPE_COLUMN) + { + if (NULL == colRef_) + { + ComASSERT(pBindWA); + } + else + { + ActiveSchemaDB()->getNATableDB()->useCache(); + + CorrName cn(objectName_, STMTHEAP); + + NATable *naTable = pBindWA->getNATable(cn); + if (naTable == NULL || pBindWA->errStatus()) + { + *CmpCommon::diags() + << DgSqlCode(-4082) + << DgTableName(cn.getExposedNameAsAnsiString()); + + return this; + } + + const NAColumnArray &nacolArr = naTable->getNAColumnArray(); + const NAColumn * nacol = nacolArr.getColumn(getColName()); + if (! nacol) + { + // column doesnt exist. Error. + *CmpCommon::diags() << DgSqlCode(-1009) + << DgColumnName(getColName()); + + return this; + } + + } + } + + markAsBound(); + return this; +} + + // // End of File // http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/parser/ElemDDLNode.cpp ---------------------------------------------------------------------- diff --git a/core/sql/parser/ElemDDLNode.cpp b/core/sql/parser/ElemDDLNode.cpp index 5c7b602..78225af 100644 --- a/core/sql/parser/ElemDDLNode.cpp +++ b/core/sql/parser/ElemDDLNode.cpp @@ -1543,6 +1543,14 @@ ElemDDLNode::castToStmtDDLCreateLibrary() return NULL; } +StmtDDLCommentOn * +ElemDDLNode::castToStmtDDLCommentOn() +{ + return NULL; +} + + + StmtDDLCreateRoutine * ElemDDLNode::castToStmtDDLCreateRoutine() { http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/parser/ElemDDLNode.h ---------------------------------------------------------------------- diff --git a/core/sql/parser/ElemDDLNode.h b/core/sql/parser/ElemDDLNode.h index 1c8b039..fb10591 100644 --- a/core/sql/parser/ElemDDLNode.h +++ b/core/sql/parser/ElemDDLNode.h @@ -350,6 +350,7 @@ class StmtDDLRegOrUnregObject; class StmtDDLCreateRole; class StmtDDLRoleGrant; class StmtDDLCleanupObjects; +class StmtDDLCommentOn; class QualifiedName; @@ -690,6 +691,8 @@ public: virtual StmtDDLCreateRole * castToStmtDDLCreateRole(); virtual StmtDDLRoleGrant * castToStmtDDLRoleGrant(); virtual StmtDDLCleanupObjects * castToStmtDDLCleanupObjects(); + virtual StmtDDLCommentOn * castToStmtDDLCommentOn(); + // // operator http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/parser/StmtDDLCommentOn.h ---------------------------------------------------------------------- diff --git a/core/sql/parser/StmtDDLCommentOn.h b/core/sql/parser/StmtDDLCommentOn.h new file mode 100644 index 0000000..cec13f6 --- /dev/null +++ b/core/sql/parser/StmtDDLCommentOn.h @@ -0,0 +1,148 @@ +/********************************************************************** +// @@@ 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 STMTDDLCOMMENTON_H +#define STMTDDLCOMMENTON_H +/* -*-C++-*- + ***************************************************************************** + * + * File: StmtDDLCommentOn.h + * Description: class for Comment On Statement (parser node) + * + * + * Created: 8/2/17 + * Language: C++ + * + * + * + * + ***************************************************************************** + */ + +#include "ComSmallDefs.h" +#include "StmtDDLNode.h" + + + +// ----------------------------------------------------------------------- +// forward references +// ----------------------------------------------------------------------- +// None + +// ----------------------------------------------------------------------- +// Comment On statement +// ----------------------------------------------------------------------- +class StmtDDLCommentOn : public StmtDDLNode +{ + +public: + + enum COMMENT_ON_TYPES { + COMMENT_ON_TYPE_TABLE = 10, + COMMENT_ON_TYPE_COLUMN, + COMMENT_ON_TYPE_SCHEMA, + COMMENT_ON_TYPE_VIEW, + COMMENT_ON_TYPE_INDEX, + COMMENT_ON_TYPE_LIBRARY, + COMMENT_ON_TYPE_PROCEDURE, + COMMENT_ON_TYPE_FUNCTION, + COMMENT_ON_TYPE_UNKNOWN + }; + + + // (default) constructor + StmtDDLCommentOn(COMMENT_ON_TYPES objType, const QualifiedName & objName, const NAString & commentStr, CollHeap * heap); + StmtDDLCommentOn(COMMENT_ON_TYPES objType, const QualifiedName & objName, const NAString & commentStr, ColReference * colRef, CollHeap * heap); + + // virtual destructor + virtual ~StmtDDLCommentOn(); + + // cast + virtual StmtDDLCommentOn * castToStmtDDLCommentOn(); + + // --------------------------------------------------------------------- + // accessors + // --------------------------------------------------------------------- + + // methods relating to parse tree + //virtual Int32 getArity() const; + //virtual ExprNode * getChild(Lng32 index); + + // method for binding + ExprNode * bindNode(BindWA *bindWAPtr); + + +// accessors + + inline QualifiedName & getObjectNameAsQualifiedName(); + inline const QualifiedName & getObjectNameAsQualifiedName() const ; + + inline const enum COMMENT_ON_TYPES getObjectType() { return type_; } + inline const NAString getObjectName() const; + inline const NAString &getComment() const { return comment_; } + inline const NAString &getColName() const { return colRef_->getColRefNameObj().getColName(); } + + + inline Int32 getVersion() {return 1;} + +// for tracing + +/* virtual const NAString displayLabel1() const; + virtual const NAString displayLabel2() const; + virtual NATraceList getDetailInfo() const; + virtual const NAString getText() const; +*/ + +private: + + enum COMMENT_ON_TYPES type_; + QualifiedName objectName_; + ColReference * colRef_; + + const NAString & comment_; + +}; // class StmtDDLCreateTable + + +inline const NAString StmtDDLCommentOn::getObjectName() const +{ + NAString objectName = objectName_.getQualifiedNameAsAnsiString(); + + return objectName; +} + +inline QualifiedName & +StmtDDLCommentOn::getObjectNameAsQualifiedName() +{ + return objectName_; +} + +inline const QualifiedName & +StmtDDLCommentOn::getObjectNameAsQualifiedName() const +{ + return objectName_; +} + + + +#endif // STMTDDLCREATETABLE_H + http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/parser/StmtDDLCreate.cpp ---------------------------------------------------------------------- diff --git a/core/sql/parser/StmtDDLCreate.cpp b/core/sql/parser/StmtDDLCreate.cpp index 9a9c4df..4537f72 100644 --- a/core/sql/parser/StmtDDLCreate.cpp +++ b/core/sql/parser/StmtDDLCreate.cpp @@ -78,6 +78,7 @@ #include "StmtDDLCreateSynonym.h" #include "ElemDDLMVFileAttrClause.h" #include "StmtDDLCreateExceptionTable.h" +#include "StmtDDLCommentOn.h" #include "MVInfo.h" #include "NumericType.h" @@ -7161,6 +7162,50 @@ ViewUsages::insertUsedTableName(const QualifiedName &tableName) *****************************************************/ + + + +// ----------------------------------------------------------------------- +// Methods for class StmtDDLCommentOn +// ----------------------------------------------------------------------- + +// +// Constructor +// + + +StmtDDLCommentOn::StmtDDLCommentOn(COMMENT_ON_TYPES objType, const QualifiedName & objName, const NAString & commentStr, CollHeap * heap) + : StmtDDLNode(DDL_COMMENT_ON), + type_(objType), + objectName_(objName, heap), + comment_(commentStr), + colRef_(NULL) +{ + +} + + +StmtDDLCommentOn::StmtDDLCommentOn(COMMENT_ON_TYPES objType, const QualifiedName & objName, const NAString & commentStr, ColReference * colRef, CollHeap * heap) + : StmtDDLNode(DDL_COMMENT_ON), + type_(objType), + objectName_(objName, heap), + colRef_(colRef), + comment_(commentStr) +{ + +} + + +StmtDDLCommentOn::~StmtDDLCommentOn() +{ + +} + +StmtDDLCommentOn * StmtDDLCommentOn::castToStmtDDLCommentOn() +{ + return this; +} + // // End of File // http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/parser/sqlparser.y ---------------------------------------------------------------------- diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y index e019918..1b43b02 100755 --- a/core/sql/parser/sqlparser.y +++ b/core/sql/parser/sqlparser.y @@ -1676,6 +1676,7 @@ static void enableMakeQuotedStringISO88591Mechanism() ComMvsAllowed mvsAllowedType; ComMvAuditType mvAuditType; MvInitializationType mvInitType; + enum StmtDDLCommentOn::COMMENT_ON_TYPES commentOnEnum; // internal refresh OZ_REFRESH @@ -2391,6 +2392,8 @@ static void enableMakeQuotedStringISO88591Mechanism() %type <pElemDDL> with_check_option %type <levelEnum> optional_levels_clause %type <levelEnum> levels_clause +%type <pStmtDDL> comment_on_statement +%type <commentOnEnum> comment_on_object_types %type <stringval> optional_component_detail_clause %type <int64> optional_lob_unit @@ -14322,6 +14325,9 @@ sql_schema_definition_statement : | unregister_hbase_statement { } + | comment_on_statement + { + } /* type pStmtDDL */ sql_schema_manipulation_statement : @@ -33150,7 +33156,7 @@ reset_clause : /* empty */ { $$ = 0; } | TOK_RESET { $$ = 2; } /* same as RMS_INIT_STATS Positive value because we can't return negative */ - + qid_internal_stats_merge_clause : /* empty */ { $$ = 0; } /* use the session default view type */ @@ -33167,7 +33173,102 @@ stats_merge_clause : /*empty */ { $$ = SQLCLI_PROGRESS_STATS; } | TOK_DEFAULT { $$ = SQLCLI_SAME_STATS; } - + + +/* type pStmtDDL */ +comment_on_statement : TOK_COMMENT TOK_ON comment_on_object_types ddl_qualified_name TOK_IS QUOTED_STRING + { + StmtDDLCommentOn *pNode = + new(PARSERHEAP()) StmtDDLCommentOn( + $3, + *$4, + *$6, + PARSERHEAP() + ); + + $$ = pNode; + } + | TOK_COMMENT TOK_ON TOK_SCHEMA schema_name TOK_IS QUOTED_STRING + { + // EJF L4J - CQD dynamic are not allowed in Compound Statements + if (beginsWith(SQLTEXT(),"BEGIN")) { + *SqlParser_Diags << DgSqlCode(-3175); + YYERROR; + } + else { // business as usual + NAString tmpSchema($4->getSchemaNameAsAnsiString()); + + if (! validateVolatileSchemaName(tmpSchema)) + { + YYERROR; + } + + StmtDDLCommentOn *pNode = new(PARSERHEAP()) StmtDDLCommentOn( + StmtDDLCommentOn::COMMENT_ON_TYPE_SCHEMA, + QualifiedName(SEABASE_SCHEMA_OBJECTNAME, $4->getSchemaName(), $4->getCatalogName(), PARSERHEAP()), + *$6, + PARSERHEAP()); + + $$ = pNode; + } + } + | TOK_COMMENT TOK_ON TOK_COLUMN qualified_name TOK_IS QUOTED_STRING + { + ShortStringSequence *seq = (ShortStringSequence *) $4; + UInt32 numParts = seq->numParts(); + + if (numParts < 2) + YYABORT; + + NAString strEmpty("", PARSERHEAP()); + + NAString *columnName = seq->extract(numParts - 1); + NAString *tableName = seq->extract(numParts - 2); + NAString *schemaName = numParts > 2 ? seq->extract(numParts - 3) : &strEmpty; + NAString *catalogName = numParts > 3 ? seq->extract(numParts - 4) : &strEmpty; + + QualifiedName tblName(*tableName, *schemaName, *catalogName, PARSERHEAP()); + ColRefName *colRefName = new(PARSERHEAP()) ColRefName(*columnName, CorrName(tblName, PARSERHEAP())); + StmtDDLCommentOn *pNode = + new(PARSERHEAP()) StmtDDLCommentOn( + StmtDDLCommentOn::COMMENT_ON_TYPE_COLUMN, + tblName, + *$6, + new(PARSERHEAP()) ColReference(colRefName), + PARSERHEAP() + ); + + $$ = pNode; + } + + +comment_on_object_types : TOK_TABLE + { + $$ = StmtDDLCommentOn::COMMENT_ON_TYPE_TABLE; + } + | TOK_INDEX + { + $$ = StmtDDLCommentOn::COMMENT_ON_TYPE_INDEX; + } + | TOK_VIEW + { + $$ = StmtDDLCommentOn::COMMENT_ON_TYPE_VIEW; + } + | TOK_LIBRARY + { + $$ = StmtDDLCommentOn::COMMENT_ON_TYPE_LIBRARY; + } + | TOK_PROCEDURE + { + $$ = StmtDDLCommentOn::COMMENT_ON_TYPE_PROCEDURE; + } + | TOK_FUNCTION + { + $$ = StmtDDLCommentOn::COMMENT_ON_TYPE_FUNCTION; + } + + + /* type tokval */ // // As many tokens as possible should be ADDED to this list, and REMOVED http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/parser/ulexer.cpp ---------------------------------------------------------------------- diff --git a/core/sql/parser/ulexer.cpp b/core/sql/parser/ulexer.cpp index a2d2fab..65bb59c 100644 --- a/core/sql/parser/ulexer.cpp +++ b/core/sql/parser/ulexer.cpp @@ -118,6 +118,7 @@ class IntegerList; #include "SqlParserAux.h" #include "StmtDDLCreateMV.h" #include "ElemDDLHbaseOptions.h" +#include "StmtDDLCommentOn.h" // Need the definition of the Parsers Union. If this is not defined, // sqlparser.h will only define the Tokens. http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/regress/privs1/EXPECTED133 ---------------------------------------------------------------------- diff --git a/core/sql/regress/privs1/EXPECTED133 b/core/sql/regress/privs1/EXPECTED133 index 9be7977..fe6af83 100644 Binary files a/core/sql/regress/privs1/EXPECTED133 and b/core/sql/regress/privs1/EXPECTED133 differ http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/regress/privs1/EXPECTED137 ---------------------------------------------------------------------- diff --git a/core/sql/regress/privs1/EXPECTED137 b/core/sql/regress/privs1/EXPECTED137 index 40b421f..c2f3d92 100755 --- a/core/sql/regress/privs1/EXPECTED137 +++ b/core/sql/regress/privs1/EXPECTED137 @@ -1059,6 +1059,13 @@ CREATE COMPONENT PRIVILEGE CREATE_LIBRARY AS 'CL' ON SQL_OPERATIONS SYSTEM GRANT COMPONENT PRIVILEGE "CREATE_LIBRARY" ON "SQL_OPERATIONS" TO "DB__ROOTROLE" WITH GRANT OPTION; +CREATE COMPONENT PRIVILEGE COMMENT AS 'CO' ON SQL_OPERATIONS SYSTEM DETAIL + 'Allow grantee to comment on objects and columns'; + +-- GRANT COMPONENT PRIVILEGE "COMMENT" ON "SQL_OPERATIONS" TO "DB__ROOT" WITH GRANT OPTION; +GRANT COMPONENT PRIVILEGE "COMMENT" ON "SQL_OPERATIONS" TO "DB__ROOTROLE" WITH + GRANT OPTION; + CREATE COMPONENT PRIVILEGE CREATE_PROCEDURE AS 'CP' ON SQL_OPERATIONS SYSTEM DETAIL 'Allow grantee to create procedures'; @@ -1615,6 +1622,13 @@ CREATE COMPONENT PRIVILEGE CREATE_LIBRARY AS 'CL' ON SQL_OPERATIONS SYSTEM GRANT COMPONENT PRIVILEGE "CREATE_LIBRARY" ON "SQL_OPERATIONS" TO "DB__ROOTROLE" WITH GRANT OPTION; +CREATE COMPONENT PRIVILEGE COMMENT AS 'CO' ON SQL_OPERATIONS SYSTEM DETAIL + 'Allow grantee to comment on objects and columns'; + +-- GRANT COMPONENT PRIVILEGE "COMMENT" ON "SQL_OPERATIONS" TO "DB__ROOT" WITH GRANT OPTION; +GRANT COMPONENT PRIVILEGE "COMMENT" ON "SQL_OPERATIONS" TO "DB__ROOTROLE" WITH + GRANT OPTION; + CREATE COMPONENT PRIVILEGE CREATE_PROCEDURE AS 'CP' ON SQL_OPERATIONS SYSTEM DETAIL 'Allow grantee to create procedures'; http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/sqlcomp/CmpDescribe.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpDescribe.cpp b/core/sql/sqlcomp/CmpDescribe.cpp index bec4b58..af9503f 100644 --- a/core/sql/sqlcomp/CmpDescribe.cpp +++ b/core/sql/sqlcomp/CmpDescribe.cpp @@ -3049,6 +3049,8 @@ short CmpDescribeSeabaseTable ( return -1; } } + + Int64 objectUID = (Int64) naTable->objectUid().get_value(); if ((type == 2) && (isView)) { @@ -3059,6 +3061,36 @@ short CmpDescribeSeabaseTable ( outputLongLine(*space, viewtext, 0); + //display comment for VIEW + if (objectUID > 0/* && COMMENT_CQD*/) + { + if (cmpSBD.switchCompiler()) + { + *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_RETRIEVE_PRIVS); + return -1; + } + + ComTdbVirtObjCommentInfo * objCommentInfo = NULL; + cmpSBD.getSeabaseObjectComment(objectUID, COM_VIEW_OBJECT, objCommentInfo); + + if (objCommentInfo != NULL) + { + //new line + outputLine(*space, "", 0); + + //display VIEW COMMENT statements + if (objCommentInfo->objectComment != NULL) + { + sprintf(buf, "COMMENT ON VIEW %s IS '%s' ;", + tableName.data(), + objCommentInfo->objectComment); + outputLine(*space, buf, 0); + } + } + + cmpSBD.switchBackCompiler(); + } + // Display grant statements if (CmpCommon::context()->isAuthorizationEnabled() && displayPrivilegeGrants) { @@ -3746,7 +3778,6 @@ short CmpDescribeSeabaseTable ( } // showddl } - Int64 objectUID = (Int64)naTable->objectUid().get_value(); if ((type == 2) && (naTable->isHbaseCellTable() || naTable->isHbaseRowTable()) && (NOT isView)) @@ -3763,7 +3794,7 @@ short CmpDescribeSeabaseTable ( if (naTable->isRegistered()) { outputShortLine(*space, " "); - + sprintf(buf, "REGISTER%sHBASE %s %s;", (naTable->isInternalRegistered() ? " /*INTERNAL*/ " : " "), "TABLE", @@ -3777,6 +3808,65 @@ short CmpDescribeSeabaseTable ( } } + //display comments + if (type == 2 && objectUID > 0) + { + enum ComObjectType objType = COM_BASE_TABLE_OBJECT; + + if (isView) + { + objType = COM_VIEW_OBJECT; + } + + if (cmpSBD.switchCompiler()) + { + *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_RETRIEVE_PRIVS); + return -1; + } + + ComTdbVirtObjCommentInfo * objCommentInfo = NULL; + cmpSBD.getSeabaseObjectComment(objectUID, objType, objCommentInfo); + + if (objCommentInfo != NULL) + { + //new line + outputLine(*space, "", 0); + + //display Table COMMENT statements + if (objCommentInfo->objectComment != NULL) + { + sprintf(buf, "COMMENT ON %s %s IS '%s' ;", + objType == COM_BASE_TABLE_OBJECT? "TABLE" : "VIEW", + tableName.data(), + 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); + } + + //display Index COMMENT statements + outputLine(*space, "", 0); + for (int idx = 0; idx < objCommentInfo->numIndexComment; idx++) + { + sprintf(buf, "COMMENT ON INDEX %s IS '%s' ;", + objCommentInfo->indexCommentArray[idx].indexFullName, + objCommentInfo->indexCommentArray[idx].indexComment); + outputLine(*space, buf, 0); + } + } + + cmpSBD.switchBackCompiler(); + } + // If SHOWDDL and authorization is enabled, display GRANTS if (type == 2) { @@ -4129,6 +4219,33 @@ char buf[1000]; ((CmpCommon::getDefault(SHOWDDL_DISPLAY_PRIVILEGE_GRANTS) == DF_SYSTEM) && getenv("SQLMX_REGRESS"))) ? FALSE : TRUE; +//display library comment + if (libraryUID > 0) + { + if (cmpSBD.switchCompiler()) + { + *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_RETRIEVE_PRIVS); + return -1; + } + + ComTdbVirtObjCommentInfo * objCommentInfo = NULL; + cmpSBD.getSeabaseObjectComment(libraryUID, COM_LIBRARY_OBJECT, objCommentInfo); + + if (objCommentInfo != NULL && objCommentInfo->objectComment != NULL) + { + //new line + outputLine(*space, "", 0); + + sprintf(buf, "COMMENT ON LIBRARY %s IS '%s' ;", + cn.getQualifiedNameObj().getQualifiedNameAsAnsiString(TRUE).data(), + objCommentInfo->objectComment); + outputLine(*space, buf, 0); + + } + + cmpSBD.switchBackCompiler(); + } + // If authorization is enabled, display grant statements for library if (CmpCommon::context()->isAuthorizationEnabled() && displayPrivilegeGrants) { @@ -4181,7 +4298,7 @@ short CmpDescribeRoutine (const CorrName & cn, { BindWA bindWA(ActiveSchemaDB(), CmpCommon::context(), FALSE/*inDDL*/); - NARoutine *routine = bindWA.getNARoutine(cn.getQualifiedNameObj()); + NARoutine *routine = bindWA.getNARoutine(cn.getQualifiedNameObj()); const NAString& rName = cn.getQualifiedNameObj().getQualifiedNameAsAnsiString(TRUE); if (routine == NULL || bindWA.errStatus()) @@ -4634,12 +4751,44 @@ short CmpDescribeRoutine (const CorrName & cn, outputShortLine (*space, " ;"); + CmpSeabaseDDL cmpSBD((NAHeap*)heap); + char * sqlmxRegr = getenv("SQLMX_REGRESS"); NABoolean displayPrivilegeGrants = TRUE; if (((CmpCommon::getDefault(SHOWDDL_DISPLAY_PRIVILEGE_GRANTS) == DF_SYSTEM) && sqlmxRegr) || (CmpCommon::getDefault(SHOWDDL_DISPLAY_PRIVILEGE_GRANTS) == DF_OFF)) displayPrivilegeGrants = FALSE; + //display comment of routine + Int64 routineUID = routine->getRoutineID(); + if ( routineUID > 0) + { + if (cmpSBD.switchCompiler()) + { + *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_RETRIEVE_PRIVS); + return -1; + } + + ComTdbVirtObjCommentInfo * objCommentInfo = NULL; + cmpSBD.getSeabaseObjectComment(routineUID, COM_USER_DEFINED_ROUTINE_OBJECT, objCommentInfo); + + if (objCommentInfo != NULL && objCommentInfo->objectComment != NULL) + { + //new line + outputLine(*space, "", 0); + + sprintf(buf, "COMMENT ON %s %s IS '%s' ;", + routine->getRoutineType() == COM_PROCEDURE_TYPE ? "PROCEDURE" : "FUNCTION", + cn.getQualifiedNameObj().getQualifiedNameAsAnsiString(TRUE).data(), + objCommentInfo->objectComment); + outputLine(*space, buf, 0); + } + + cmpSBD.switchBackCompiler(); + + } + + // If authorization enabled, display grant statements if (CmpCommon::context()->isAuthorizationEnabled() && displayPrivilegeGrants) { @@ -4661,8 +4810,6 @@ short CmpDescribeRoutine (const CorrName & cn, (int32_t)routine->getSchemaOwner(), COM_USER_DEFINED_ROUTINE_OBJECT); - - CmpSeabaseDDL cmpSBD((NAHeap*)heap); if (cmpSBD.switchCompiler()) { *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_RETRIEVE_PRIVS); @@ -4678,8 +4825,6 @@ short CmpDescribeRoutine (const CorrName & cn, cmpSBD.switchBackCompiler(); } - - outbuflen = space->getAllocatedSpaceSize(); outbuf = new (heap) char[outbuflen]; space->makeContiguous(outbuf, outbuflen); http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/sqlcomp/CmpSeabaseDDL.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDL.h b/core/sql/sqlcomp/CmpSeabaseDDL.h index 9da0b01..a31ef52 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDL.h +++ b/core/sql/sqlcomp/CmpSeabaseDDL.h @@ -253,6 +253,10 @@ class CmpSeabaseDDL const ComObjectType objType, NABoolean includeInvalidDefs = FALSE); + short getSeabaseObjectComment(Int64 object_uid, + enum ComObjectType object_type, + ComTdbVirtObjCommentInfo * & comment_info); + short getObjectOwner(ExeCliInterface *cliInterface, const char * catName, const char * schName, @@ -1405,6 +1409,10 @@ protected: void dropSeabaseAuthorization(ExeCliInterface *cliInterface, NABoolean doCleanup = FALSE); + void doSeabaseCommentOn(StmtDDLCommentOn *commentOnNode, + NAString &currCatName, + NAString &currSchName); + NABoolean insertPrivMgrInfo(const Int64 objUID, const NAString &objName, const ComObjectType objectType, http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp new file mode 100644 index 0000000..83fc83f --- /dev/null +++ b/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp @@ -0,0 +1,202 @@ +/********************************************************************** +// @@@ START COPYRIGHT @@@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// +// @@@ END COPYRIGHT @@@ +**********************************************************************/ + +/* -*-C++-*- + ***************************************************************************** + * + * File: CmpSeabaseDDLcommentOn.cpp + * Description: Implements ddl operations for Seabase indexes. + * + * + * Created: 8/17/2017 + * Language: C++ + * + * + ***************************************************************************** + */ + +#define SQLPARSERGLOBALS_FLAGS // must precede all #include's +#define SQLPARSERGLOBALS_NADEFAULTS + +#include "ComObjectName.h" + +#include "CmpDDLCatErrorCodes.h" +#include "ElemDDLHbaseOptions.h" + +#include "SchemaDB.h" +#include "CmpSeabaseDDL.h" +#include "CmpDescribe.h" + +#include "ExpHbaseInterface.h" + +#include "ExExeUtilCli.h" +#include "Generator.h" + +#include "ComCextdecs.h" +#include "ComUser.h" + +#include "NumericType.h" + +#include "PrivMgrCommands.h" + +#include "StmtDDLCommentOn.h" + +#include "PrivMgrComponentPrivileges.h" +#include "PrivMgrCommands.h" +#include "ComUser.h" + + +void CmpSeabaseDDL::doSeabaseCommentOn(StmtDDLCommentOn *commentOnNode, + NAString &currCatName, + NAString &currSchName) +{ + Lng32 cliRC; + Lng32 retcode; + + enum ComObjectType enMDObjType = COM_UNKNOWN_OBJECT; + + ComObjectName objectName(commentOnNode->getObjectName()); + ComAnsiNamePart currCatAnsiName(currCatName); + ComAnsiNamePart currSchAnsiName(currSchName); + objectName.applyDefaults(currCatAnsiName, currSchAnsiName); + + enum StmtDDLCommentOn::COMMENT_ON_TYPES commentObjectType = commentOnNode->getObjectType(); + + switch (commentObjectType) + { + case StmtDDLCommentOn::COMMENT_ON_TYPE_TABLE: + enMDObjType = COM_BASE_TABLE_OBJECT; + break; + + case StmtDDLCommentOn::COMMENT_ON_TYPE_COLUMN: + enMDObjType = COM_BASE_TABLE_OBJECT; + break; + + case StmtDDLCommentOn::COMMENT_ON_TYPE_INDEX: + enMDObjType = COM_INDEX_OBJECT; + break; + + case StmtDDLCommentOn::COMMENT_ON_TYPE_SCHEMA: + enMDObjType = COM_PRIVATE_SCHEMA_OBJECT; + break; + + case StmtDDLCommentOn::COMMENT_ON_TYPE_VIEW: + enMDObjType = COM_VIEW_OBJECT; + break; + + case StmtDDLCommentOn::COMMENT_ON_TYPE_LIBRARY: + enMDObjType = COM_LIBRARY_OBJECT; + break; + + case StmtDDLCommentOn::COMMENT_ON_TYPE_PROCEDURE: + case StmtDDLCommentOn::COMMENT_ON_TYPE_FUNCTION: + enMDObjType = COM_USER_DEFINED_ROUTINE_OBJECT; + break; + + default: + break; + + } + + NAString catalogNamePart = objectName.getCatalogNamePartAsAnsiString(); + NAString schemaNamePart = objectName.getSchemaNamePartAsAnsiString(TRUE); + NAString objNamePart = objectName.getObjectNamePartAsAnsiString(TRUE); + + const NAString extObjName = objectName.getExternalName(TRUE); + + ExeCliInterface cliInterface(STMTHEAP, NULL, NULL, + CmpCommon::context()->sqlSession()->getParentQid()); + Int64 objUID = 0; + Int32 objectOwnerID = SUPER_USER; + Int32 schemaOwnerID = SUPER_USER; + 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(), + enMDObjType, + objectOwnerID, + schemaOwnerID, + objectFlags); + if (objUID < 0 || objectOwnerID == 0 || schemaOwnerID == 0) + { + CmpCommon::diags()->clear(); + *CmpCommon::diags() << DgSqlCode(-1389) + << DgString0(extObjName); + processReturn(); + return; + } + + // add, remove, change comment of object/column + const NAString & comment = commentOnNode->getComment(); + char * query = new(STMTHEAP) char[comment.length()+1024]; + + if (StmtDDLCommentOn::COMMENT_ON_TYPE_COLUMN == commentObjectType) + { + str_sprintf(query, "update %s.\"%s\".%s set comment = '%s' where object_uid = %ld and column_name = '%s' ", + getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS, + comment.data(), + objUID, + commentOnNode->getColName().data() + ); + cliRC = cliInterface.executeImmediate(query); + } + else + { + str_sprintf(query, "update %s.\"%s\".%s set comment = '%s' where catalog_name = '%s' and schema_name = '%s' and object_name = '%s' and object_type = '%s' ", + getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, + comment.data(), + catalogNamePart.data(), schemaNamePart.data(), objNamePart.data(), + comObjectTypeLit(enMDObjType)); + cliRC = cliInterface.executeImmediate(query); + } + + + NADELETEBASIC(query, STMTHEAP); + if (cliRC < 0) + { + cliInterface.retrieveSQLDiagnostics(CmpCommon::diags()); + processReturn(); + return; + } + + processReturn(); + return; +} + http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp index cc1e4a5..c23a180 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp @@ -4563,7 +4563,7 @@ short CmpSeabaseDDL::updateSeabaseMDObjectsTable( NAString quotedObjName; ToQuotedString(quotedObjName, NAString(objName), FALSE); - str_sprintf(buf, "insert into %s.\"%s\".%s values ('%s', '%s', '%s', '%s', %ld, %ld, %ld, '%s', '%s', %d, %d, %ld )", + str_sprintf(buf, "insert into %s.\"%s\".%s values ('%s', '%s', '%s', '%s', %ld, %ld, %ld, '%s', '%s', %d, %d, %ld, '')", getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, catName, quotedSchName.data(), quotedObjName.data(), objectTypeLit, @@ -4754,7 +4754,7 @@ short CmpSeabaseDDL::updateSeabaseMDTable( ExeCliInterface cqdCliInterface; cliRC = cqdCliInterface.holdAndSetCQD("ODBC_PROCESS", "ON"); - str_sprintf(buf, "upsert using rowset (max rowset size %d, input rowset size ?, input row max length ?, rowset buffer ?) into %s.\"%s\".%s values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + str_sprintf(buf, "upsert using rowset (max rowset size %d, input rowset size ?, input row max length ?, rowset buffer ?) into %s.\"%s\".%s values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", numCols, getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS); cliRC = rwrsCliInterface.rwrsPrepare(buf, numCols); @@ -4887,6 +4887,7 @@ short CmpSeabaseDDL::updateSeabaseMDTable( AssignColEntry(&rwrsCliInterface, entry++, inputRow, colInfo->paramDirection, firstColOffset); AssignColEntry(&rwrsCliInterface, entry++, inputRow, (colInfo->isOptional ? COM_YES_LIT : COM_NO_LIT), firstColOffset); AssignColEntry(&rwrsCliInterface, entry++, inputRow, (char*)&colInfo->colFlags, firstColOffset); + AssignColEntry(&rwrsCliInterface, entry++, inputRow, (char*)"", firstColOffset); cliRC = rwrsCliInterface.rwrsExec(inputRow, inputRowLen, &rowsAffected); if (cliRC < 0) @@ -4898,7 +4899,7 @@ short CmpSeabaseDDL::updateSeabaseMDTable( } else { - str_sprintf(buf, "insert into %s.\"%s\".%s values (%ld, '%s', %d, '%s', %d, '%s', %d, %d, %d, %d, %d, '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %ld)", + str_sprintf(buf, "insert into %s.\"%s\".%s values (%ld, '%s', %d, '%s', %d, '%s', %d, %d, %d, %d, %d, '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %ld, '')", getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS, objUID, colInfo->colName, @@ -5121,7 +5122,7 @@ short CmpSeabaseDDL::updateSeabaseMDSPJ( NAString quotedLibObjName; ToQuotedString(quotedLibObjName, NAString(libName), FALSE); - str_sprintf(buf, "insert into %s.\"%s\".%s values ('%s', '%s', '%s', '%s', %ld, %ld, %ld, '%s', '%s', %d, %d, 0 )", + str_sprintf(buf, "insert into %s.\"%s\".%s values ('%s', '%s', '%s', '%s', %ld, %ld, %ld, '%s', '%s', %d, %d, 0, '')", getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, catName, quotedSchName.data(), quotedLibObjName.data(), COM_LIBRARY_OBJECT_LIT, @@ -7783,7 +7784,7 @@ void CmpSeabaseDDL::createSeabaseSequence(StmtDDLCreateSequence * createSequen ToQuotedString(quotedSeqObjName, seqNamePart, FALSE); Int32 objOwner = ComUser::getCurrentUser(); - str_sprintf(buf, "insert into %s.\"%s\".%s values ('%s', '%s', '%s', '%s', %ld, %ld, %ld, '%s', '%s', %d, %d, 0)", + str_sprintf(buf, "insert into %s.\"%s\".%s values ('%s', '%s', '%s', '%s', %ld, %ld, %ld, '%s', '%s', %d, %d, 0, '')", getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, catalogNamePart.data(), quotedSchName.data(), quotedSeqObjName.data(), COM_SEQUENCE_GENERATOR_OBJECT_LIT, @@ -9506,6 +9507,13 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode, cmpSBDC.cleanupObjects(co, currCatName, currSchName, dws); } + else if (ddlNode->getOperatorType() == DDL_COMMENT_ON) + { + StmtDDLCommentOn * comment = + ddlNode->castToStmtDDLNode()->castToStmtDDLCommentOn(); + + doSeabaseCommentOn(comment, currCatName, currSchName); + } else { // some operator type that this routine doesn't support yet http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/sqlcomp/CmpSeabaseDDLincludes.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLincludes.h b/core/sql/sqlcomp/CmpSeabaseDDLincludes.h index 3b7b47a..9cbae54 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLincludes.h +++ b/core/sql/sqlcomp/CmpSeabaseDDLincludes.h @@ -69,6 +69,7 @@ #include "StmtDDLRegisterComponent.h" #include "StmtDDLCleanupObjects.h" #include "StmtDDLRegOrUnregHive.h" +#include "StmtDDLCommentOn.h" #include "ElemDDLHbaseOptions.h" #include "ElemDDLParamDefArray.h" http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/sqlcomp/CmpSeabaseDDLmd.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLmd.h b/core/sql/sqlcomp/CmpSeabaseDDLmd.h index 76383b6..fdaa99b 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLmd.h +++ b/core/sql/sqlcomp/CmpSeabaseDDLmd.h @@ -115,7 +115,8 @@ static const QString seabaseColumnsDDL[] = {" hbase_col_qualifier varchar(40) character set iso88591 not null not serialized, "}, {" direction char(2) character set iso88591 not null not serialized, "}, {" is_optional char(2) character set iso88591 not null not serialized, "}, - {" flags largeint not null not serialized "}, + {" flags largeint not null not serialized, "}, + {" comment VARCHAR(1000) CHARACTER SET UTF8 NOT NULL NOT SERIALIZED "}, {" ) "}, {" primary key (object_uid, column_name) "}, {" attribute hbase format "}, @@ -220,7 +221,8 @@ static const QString seabaseObjectsDDL[] = {" droppable char(2) character set iso88591 not null not serialized, "}, {" object_owner int not null not serialized, "}, {" schema_owner int not null not serialized, "}, - {" flags largeint not null not serialized "}, + {" flags largeint not null not serialized, "}, + {" comment VARCHAR(1000) CHARACTER SET UTF8 NOT NULL NOT SERIALIZED "}, {" ) "}, {" primary key (catalog_name, schema_name, object_name, object_type) "}, {" attribute hbase format "}, @@ -1544,6 +1546,9 @@ static const QString seabaseOldMDv11ViewsDDL[] = #define TRAF_SEQUENCES_VIEW "SEQUENCES_VIEW" #define TRAF_TABLES_VIEW "TABLES_VIEW" #define TRAF_VIEWS_VIEW "VIEWS_VIEW" +#define TRAF_OBJECT_COMMENT_VIEW "OBJECT_COMMENT_VIEW" +#define TRAF_COLUMN_COMMENT_VIEW "COLUMN_COMMENT_VIEW" + static const QString createTrafColumnsViewQuery[] = { @@ -1693,6 +1698,24 @@ static const QString createTrafViewsViewQuery[] = {" ; "} }; +static const QString createTrafObjectCommentViewQuery[] = +{ + {" create view %s.\"%s\"."TRAF_OBJECT_COMMENT_VIEW" as "}, + {" select catalog_name, schema_name, object_name, comment "}, + {" from %s.\"%s\".\"%s\" "}, + {" where COMMENT <> '' "}, + {" ; "} +}; + +static const QString createTrafColumnCommentViewQuery[] = +{ + {" create view %s.\"%s\"."TRAF_COLUMN_COMMENT_VIEW" as "}, + {" select O.CATALOG_NAME, O.SCHEMA_NAME, O.OBJECT_NAME, C.COLUMN_NAME, C.COMMENT "}, + {" from %s.\"%s\".\"%s\" as O, %s.\"%s\".\"%s\" as C "}, + {" where O.OBJECT_UID = C.OBJECT_UID and C.COMMENT <> '' "}, + {" ; "} +}; + struct MDViewInfo { const char * viewName; @@ -1747,7 +1770,18 @@ static const MDViewInfo allMDviewsInfo[] = { sizeof(createTrafViewsViewQuery), FALSE }, - + { + TRAF_OBJECT_COMMENT_VIEW, + createTrafObjectCommentViewQuery, + sizeof(createTrafObjectCommentViewQuery), + FALSE + }, + { + TRAF_COLUMN_COMMENT_VIEW, + createTrafColumnCommentViewQuery, + sizeof(createTrafColumnCommentViewQuery), + FALSE + }, }; #endif http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp index a39ad0b..dd35222 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp @@ -187,8 +187,8 @@ char schemaObjectLit[3] = {0}; break; } } - - str_sprintf(buf, "insert into %s.\"%s\".%s values ('%s', '%s', '%s', '%s', %ld, %ld, %ld, '%s', '%s', %d, %d, 0)", + + str_sprintf(buf, "insert into %s.\"%s\".%s values ('%s', '%s', '%s', '%s', %ld, %ld, %ld, '%s', '%s', %d, %d, 0, '')", getSystemCatalog(),SEABASE_MD_SCHEMA,SEABASE_OBJECTS, catalogName.data(), quotedSchName.data(), quotedObjName.data(), schemaObjectLit, @@ -445,7 +445,29 @@ Int16 status = ComUser::getAuthNameFromAuthID(objectOwner,username, output += catalogName.data(); output += "\".\""; output += schemaName.data(); - +// Disaply Comment of schema + { + ComTdbVirtObjCommentInfo * objCommentInfo = NULL; + cmpSBD.getSeabaseObjectComment(schemaUID, objectType, objCommentInfo); + + if (objCommentInfo != NULL && objCommentInfo->objectComment != NULL) + { + outlines.push_back(" "); + + output = "COMMENT ON SCHEMA "; + output += catalogName.data(); + output += "."; + output += schemaName.data(); + output += " IS '"; + output += objCommentInfo->objectComment; + output += "' ;"; + + outlines.push_back(output.data()); + + } + + } + // AUTHORIZATION clause is rarely used, but include it for replay. output += "\" AUTHORIZATION \""; output += username; http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp index bc33864..4924c14 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp @@ -909,7 +909,7 @@ short CmpSeabaseDDL::updatePKeyInfo( NAString quotedObjName; ToQuotedString(quotedObjName, NAString(objectNamePart), FALSE); - str_sprintf(buf, "insert into %s.\"%s\".%s values ('%s', '%s', '%s', '%s', %ld, %ld, %ld, '%s', '%s', %d, %d, 0 )", + str_sprintf(buf, "insert into %s.\"%s\".%s values ('%s', '%s', '%s', '%s', %ld, %ld, %ld, '%s', '%s', %d, %d, 0, '')", getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, catalogNamePart.data(), quotedSchName.data(), quotedObjName.data(), COM_PRIMARY_KEY_CONSTRAINT_OBJECT_LIT, @@ -1315,7 +1315,7 @@ short CmpSeabaseDDL::updateConstraintMD( NAString quotedObjName; ToQuotedString(quotedObjName, NAString(objectNamePart), FALSE); - str_sprintf(buf, "insert into %s.\"%s\".%s values ('%s', '%s', '%s', '%s', %ld, %ld, %ld, '%s', '%s', %d, %d, 0 )", + str_sprintf(buf, "insert into %s.\"%s\".%s values ('%s', '%s', '%s', '%s', %ld, %ld, %ld, '%s', '%s', %d, %d, 0, '')", getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, catalogNamePart.data(), quotedSchName.data(), quotedObjName.data(), ((ct == COM_UNIQUE_CONSTRAINT) ? COM_UNIQUE_CONSTRAINT_OBJECT_LIT : @@ -5646,7 +5646,7 @@ void CmpSeabaseDDL::alterSeabaseTableAddColumn( } } - str_sprintf(query, "insert into %s.\"%s\".%s values (%ld, '%s', %d, '%s', %d, '%s', %d, %d, %d, %d, %d, '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%u', '%s', '%s', %ld )", + str_sprintf(query, "insert into %s.\"%s\".%s values (%ld, '%s', %d, '%s', %d, '%s', %d, %d, %d, %d, %d, '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%u', '%s', '%s', %ld, '' )", getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS, objUID, col_name, @@ -7171,8 +7171,8 @@ short CmpSeabaseDDL::hbaseFormatTableAlterColumnAttr( cliInterface.retrieveSQLDiagnostics(CmpCommon::diags()); goto label_error1; } - - str_sprintf(buf, "insert into %s.\"%s\".%s select object_uid, '%s', %d, '%s', fs_data_type, sql_data_type, column_size, column_precision, column_scale, datetime_start_field, datetime_end_field, is_upshifted, column_flags, nullable, character_set, default_class, default_value, column_heading, '%s', '%s', direction, is_optional, flags from %s.\"%s\".%s where object_uid = %ld and column_number = (select column_number from %s.\"%s\".%s where object_uid = %ld and column_name = '%s')", + + str_sprintf(buf, "insert into %s.\"%s\".%s select object_uid, '%s', %d, '%s', fs_data_type, sql_data_type, column_size, column_precision, column_scale, datetime_start_field, datetime_end_field, is_upshifted, column_flags, nullable, character_set, default_class, default_value, column_heading, '%s', '%s', direction, is_optional, flags, comment from %s.\"%s\".%s where object_uid = %ld and column_number = (select column_number from %s.\"%s\".%s where object_uid = %ld and column_name = '%s')", getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS, naCol->getColName().data(), altColNum, @@ -12940,6 +12940,142 @@ TrafDesc *CmpSeabaseDDL::getSeabaseRoutineDescInternal(const NAString &catName, } +short CmpSeabaseDDL::getSeabaseObjectComment(Int64 object_uid, + enum ComObjectType object_type, + ComTdbVirtObjCommentInfo * & comment_info) +{ + Lng32 retcode = 0; + Lng32 cliRC = 0; + + char query[4000]; + + comment_info = NULL; + + + ExeCliInterface cliInterface(STMTHEAP, + NULL, NULL, + CmpCommon::context()->sqlSession()->getParentQid()); + + //get object comment + str_sprintf(query, "select comment from %s.\"%s\".%s where object_uid = %ld and object_type = '%s' and comment <> '' ;", + getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, + object_uid, comObjectTypeLit(object_type)); + + Queue * objQueue = NULL; + cliRC = cliInterface.fetchAllRows(objQueue, query, 0, FALSE, FALSE, TRUE); + if (cliRC < 0) + { + cliInterface.retrieveSQLDiagnostics(CmpCommon::diags()); + processReturn(); + return -1; + } + + if (objQueue->numEntries() == 1) + { + objQueue->position(); + + OutputInfo * vi = (OutputInfo*)objQueue->getNext(); + + comment_info = new(STMTHEAP) ComTdbVirtObjCommentInfo[1]; + comment_info->objectUid = object_uid; + comment_info->numColumnComment = 0; + comment_info->columnCommentArray = NULL; + comment_info->numIndexComment = 0; + comment_info->indexCommentArray = NULL; + comment_info->objectComment = (char*)vi->get(0); + } + else + { + return -1; + } + + if (COM_BASE_TABLE_OBJECT == object_type) + { + //get index comment of table + str_sprintf(query, "select CATALOG_NAME||'.'||SCHEMA_NAME||'.'||OBJECT_NAME, COMMENT " + "from %s.\"%s\".%s as O, %s.\"%s\".%s as I " + "where I.BASE_TABLE_UID = %ld and O.OBJECT_UID = I.INDEX_UID and O.comment <> '' ;", + getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, + getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_INDEXES, + object_uid); + + Queue * indexQueue = NULL; + cliRC = cliInterface.fetchAllRows(indexQueue, query, 0, FALSE, FALSE, TRUE); + if (cliRC < 0) + { + cliInterface.retrieveSQLDiagnostics(CmpCommon::diags()); + processReturn(); + return -1; + } + + if (indexQueue->numEntries() > 0) + { + if (NULL == comment_info) + { + comment_info = new(STMTHEAP) ComTdbVirtObjCommentInfo[1]; + comment_info->objectUid = object_uid; + comment_info->objectComment = NULL; + comment_info->numColumnComment = 0; + comment_info->columnCommentArray = NULL; + } + + comment_info->numIndexComment = indexQueue->numEntries(); + comment_info->indexCommentArray = new(STMTHEAP) ComTdbVirtIndexCommentInfo[comment_info->numIndexComment]; + + indexQueue->position(); + for (Lng32 idx = 0; idx < comment_info->numIndexComment; idx++) + { + OutputInfo * oi = (OutputInfo*)indexQueue->getNext(); + ComTdbVirtIndexCommentInfo &indexComment = comment_info->indexCommentArray[idx]; + + // get the index full name + indexComment.indexFullName = (char*) oi->get(0); + indexComment.indexComment = (char*) oi->get(1); + } + } + + //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); + + Queue * colQueue = NULL; + cliRC = cliInterface.fetchAllRows(colQueue, query, 0, FALSE, FALSE, TRUE); + if (cliRC < 0) + { + cliInterface.retrieveSQLDiagnostics(CmpCommon::diags()); + processReturn(); + return -1; + } + + if (colQueue->numEntries() > 0) + { + if (NULL == comment_info) + { + comment_info = new(STMTHEAP) ComTdbVirtObjCommentInfo[1]; + comment_info->objectUid = object_uid; + comment_info->objectComment = NULL; + comment_info->numIndexComment = 0; + comment_info->indexCommentArray = NULL; + } + + comment_info->numColumnComment = colQueue->numEntries(); + comment_info->columnCommentArray = new(STMTHEAP) ComTdbVirtColumnCommentInfo[comment_info->numColumnComment]; + + colQueue->position(); + for (Lng32 idx = 0; idx < comment_info->numColumnComment; idx++) + { + OutputInfo * oi = (OutputInfo*)colQueue->getNext(); + ComTdbVirtColumnCommentInfo &colComment = comment_info->columnCommentArray[idx]; + + // get the column name + colComment.columnName = (char*) oi->get(0); + colComment.columnComment = (char*) oi->get(1); + } + } + } + + return 0; +} // ***************************************************************************** http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h index 549b506..7e963e0 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h +++ b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h @@ -226,7 +226,14 @@ static const MDUpgradeInfo allMDupgradeInfo[] = { seabaseColumnsDDL, sizeof(seabaseColumnsDDL), NULL, 0, NULL, 0, - FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}, + TRUE, + "object_uid,column_name,column_number,column_class,fs_data_type,sql_data_type,column_size,column_precision," + "column_scale,datetime_start_field,datetime_end_field,is_upshifted,column_flags,nullable,character_set," + "default_class,default_value,column_heading,hbase_col_family,hbase_col_qualifier,direction,is_optional,flags,comment" , + "object_uid,column_name,column_number,column_class,fs_data_type,sql_data_type,column_size,column_precision," + "column_scale,datetime_start_field,datetime_end_field,is_upshifted,column_flags,nullable,character_set," + "default_class,default_value,column_heading,hbase_col_family,hbase_col_qualifier,direction,is_optional,flags,''" , + NULL, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE}, {SEABASE_DEFAULTS, SEABASE_DEFAULTS_OLD_MD, seabaseDefaultsDDL, sizeof(seabaseDefaultsDDL), @@ -279,13 +286,13 @@ static const MDUpgradeInfo allMDupgradeInfo[] = { "object_name," "object_type,object_uid," "create_time,redef_time,valid_def,droppable,object_owner,schema_owner," - "flags", + "flags,comment", "catalog_name,schema_name," "case when schema_name = '_MD_' then object_name || '_OLD_MD' else object_name end," "object_type,object_uid," "create_time,redef_time,valid_def,droppable,object_owner,schema_owner," - "flags", - NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}, + "flags,''", + NULL, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE}, {SEABASE_OBJECTS_UNIQ_IDX, SEABASE_OBJECTS_UNIQ_IDX_OLD_MD, seabaseObjectsUniqIdxDDL, sizeof(seabaseObjectsUniqIdxDDL), @@ -403,8 +410,8 @@ static const MDUpgradeInfo allMDv23tov30TablesInfo[] = { seabaseOldMDv23ColumnsDDL, sizeof(seabaseOldMDv23ColumnsDDL), NULL, 0, TRUE, - "object_uid, column_name, column_number, column_class, fs_data_type, sql_data_type, column_size, column_precision, column_scale, datetime_start_field, datetime_end_field, is_upshifted, column_flags, nullable, character_set, default_class, default_value, column_heading, hbase_col_family, hbase_col_qualifier, direction, is_optional, flags", - "object_uid, column_name, column_number, column_class, fs_data_type, '', column_size, column_precision, column_scale, datetime_start_field, datetime_end_field, is_upshifted, column_flags, nullable, character_set, default_class, default_value, column_heading, hbase_col_family, hbase_col_qualifier, direction, is_optional, 0", + "object_uid, column_name, column_number, column_class, fs_data_type, sql_data_type, column_size, column_precision, column_scale, datetime_start_field, datetime_end_field, is_upshifted, column_flags, nullable, character_set, default_class, default_value, column_heading, hbase_col_family, hbase_col_qualifier, direction, is_optional, flags, comment", + "object_uid, column_name, column_number, column_class, fs_data_type, '', column_size, column_precision, column_scale, datetime_start_field, datetime_end_field, is_upshifted, column_flags, nullable, character_set, default_class, default_value, column_heading, hbase_col_family, hbase_col_qualifier, direction, is_optional, 0, '' ", NULL, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE}, {SEABASE_DEFAULTS, SEABASE_DEFAULTS_OLD_MD, @@ -448,8 +455,8 @@ static const MDUpgradeInfo allMDv23tov30TablesInfo[] = { seabaseOldMDv23ObjectsDDL, sizeof(seabaseOldMDv23ObjectsDDL), NULL, 0, TRUE, - "catalog_name, schema_name, object_name, object_type, object_uid, create_time, redef_time, valid_def, droppable, object_owner, schema_owner, flags", - "catalog_name, schema_name, case when schema_name = '_MD_' then object_name || '_OLD_MD' else object_name end, object_type, object_uid, create_time, redef_time, valid_def, 'N', object_owner, " SUPER_USER_LIT", 0 ", + "catalog_name, schema_name, object_name, object_type, object_uid, create_time, redef_time, valid_def, droppable, object_owner, schema_owner, flags, comment", + "catalog_name, schema_name, case when schema_name = '_MD_' then object_name || '_OLD_MD' else object_name end, object_type, object_uid, create_time, redef_time, valid_def, 'N', object_owner, " SUPER_USER_LIT", 0, ''", NULL, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE}, {SEABASE_OBJECTS_UNIQ_IDX, SEABASE_OBJECTS_UNIQ_IDX_OLD_MD, http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/sqlcomp/CmpSeabaseDDLview.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLview.cpp b/core/sql/sqlcomp/CmpSeabaseDDLview.cpp index 0f2592e..587c666 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLview.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLview.cpp @@ -1492,6 +1492,25 @@ short CmpSeabaseDDL::createMetadataViews(ExeCliInterface * cliInterface) param_[9] = SEABASE_MD_SCHEMA; param_[10] = COM_VIEW_OBJECT_LIT; } + else if (strcmp(mdi.viewName, TRAF_OBJECT_COMMENT_VIEW) == 0) + { + param_[0] = getSystemCatalog(); + param_[1] = SEABASE_MD_SCHEMA; + param_[2] = getSystemCatalog(); + param_[3] = SEABASE_MD_SCHEMA; + param_[4] = SEABASE_OBJECTS; + } + else if (strcmp(mdi.viewName, TRAF_COLUMN_COMMENT_VIEW) == 0) + { + param_[0] = getSystemCatalog(); + param_[1] = SEABASE_MD_SCHEMA; + param_[2] = getSystemCatalog(); + param_[3] = SEABASE_MD_SCHEMA; + param_[4] = SEABASE_OBJECTS; + param_[5] = getSystemCatalog(); + param_[6] = SEABASE_MD_SCHEMA; + param_[7] = SEABASE_COLUMNS; + } else { NADELETEBASICARRAY(gluedQuery, STMTHEAP); http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/sqlcomp/PrivMgr.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/PrivMgr.cpp b/core/sql/sqlcomp/PrivMgr.cpp index 61e1dad..f9811c0 100644 --- a/core/sql/sqlcomp/PrivMgr.cpp +++ b/core/sql/sqlcomp/PrivMgr.cpp @@ -387,6 +387,7 @@ const char * PrivMgr::getSQLOperationName(SQLOperation operation) case SQLOperation::SHOW: return "SHOW"; case SQLOperation::UNREGISTER_HIVE_OBJECT: return "UNREGISTER_HIVE_OBJECT"; case SQLOperation::USE_ALTERNATE_SCHEMA: return "USE_ALTERNATE_SCHEMA"; + case SQLOperation::COMMENT: return "COMMENT"; default: return "UNKNOWN"; } @@ -482,6 +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"; default: return " "; } @@ -580,6 +582,7 @@ const char * PrivMgr::getSQLOperationDescription(SQLOperation operation) case SQLOperation::SHOW: return "Allow grantee to view metadata information about objects"; case SQLOperation::UNREGISTER_HIVE_OBJECT: return "Allow grantee to unregister hive object from traf metadata"; case SQLOperation::USE_ALTERNATE_SCHEMA: return "Allow grantee to use non-default schemas"; + case SQLOperation::COMMENT: return "Allow grantee to comment on objects and columns"; default: return ""; } http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/078ed10c/core/sql/sqlcomp/PrivMgrDefs.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/PrivMgrDefs.h b/core/sql/sqlcomp/PrivMgrDefs.h index 0c615c2..5820460 100644 --- a/core/sql/sqlcomp/PrivMgrDefs.h +++ b/core/sql/sqlcomp/PrivMgrDefs.h @@ -217,8 +217,9 @@ enum class SQLOperation { SHOW, UNREGISTER_HIVE_OBJECT, USE_ALTERNATE_SCHEMA, + COMMENT, FIRST_OPERATION = ALTER, - LAST_OPERATION = USE_ALTERNATE_SCHEMA, + LAST_OPERATION = COMMENT, NUMBER_OF_OPERATIONS = LAST_OPERATION - FIRST_OPERATION + 1, UNKNOWN, FIRST_DML_PRIV = DML_DELETE,