http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/681cad66/core/sql/regress/udr/EXPECTED102 ---------------------------------------------------------------------- diff --git a/core/sql/regress/udr/EXPECTED102 b/core/sql/regress/udr/EXPECTED102 new file mode 100644 index 0000000..04063b0 --- /dev/null +++ b/core/sql/regress/udr/EXPECTED102 @@ -0,0 +1,421 @@ +>>cqd SHOWDDL_DISPLAY_PRIVILEGE_GRANTS 'ON'; + +--- SQL operation complete. +>>set schema "_LIBMGR_"; + +--- SQL operation complete. +>> +>>prepare get_schemas from ++>select distinct substring (schema_name,1,16) as schema_name ++>from trafodion."_MD_".objects ++>where schema_name in ('SEABASE', '_LIBMGR_', '_MD_', '_PRIVMGR_MD_', '_REPOS_') ++>order by 1; + +--- SQL command prepared. +>> +>> +>>-- **************************************************************************** +>>-- Verify enabling library management followed by authorization is correct +>>-- **************************************************************************** +>> +>>-- authorization and library management should be disabled +>>execute get_schemas; + +SCHEMA_NAME +---------------------------------------------------------------- + +SEABASE +_MD_ +_REPOS_ + +--- 3 row(s) selected. +>> +>>-- create library management +>>initialize trafodion, create library management; + +--- SQL operation complete. +>>execute get_schemas; + +SCHEMA_NAME +---------------------------------------------------------------- + +SEABASE +_LIBMGR_ +_MD_ +_REPOS_ + +--- 4 row(s) selected. +>>get libraries; + +Libraries in Schema TRAFODION._LIBMGR_ +====================================== + +DB__LIBMGRNAME + +--- SQL operation complete. +>>get procedures; + +Procedures in Schema TRAFODION._LIBMGR_ +======================================= + +ADDLIB +ALTERLIB +DROPLIB +GETFILE +HELP +LS +LSALL +PUT +RM +RMREX + +--- SQL operation complete. +>>showddl procedure rm; + +CREATE PROCEDURE TRAFODION."_LIBMGR_".RM + ( + IN FILENAME VARCHAR(256 CHARS) CHARACTER SET UTF8 + ) + EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.rm (java.lang.String)' + LIBRARY TRAFODION."_LIBMGR_".DB__LIBMGRNAME + EXTERNAL SECURITY DEFINER + LANGUAGE JAVA + PARAMETER STYLE JAVA + READS SQL DATA + DYNAMIC RESULT SETS 0 + NO TRANSACTION REQUIRED + ISOLATE + ; + +--- SQL operation complete. +>>set param ?h 'PUT'; +>>call help (?h); + +COMMANDNAME +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +PUT - Upload a JAR. SHOWDDL PROCEDURE [SCHEMA NAME.]PUT for more info. + +--- SQL operation complete. +>> +>>-- enable authorization +>>initialize authorization; + +--- SQL operation complete. +>>execute get_schemas; + +SCHEMA_NAME +---------------------------------------------------------------- + +SEABASE +_LIBMGR_ +_MD_ +_PRIVMGR_MD_ +_REPOS_ + +--- 5 row(s) selected. +>>get roles; + +Roles +===== + +DB__HBASEROLE +DB__HIVEROLE +DB__LIBMGRROLE +DB__ROOTROLE +PUBLIC + +--- SQL operation complete. +>>showddl procedure rm; + +CREATE PROCEDURE TRAFODION."_LIBMGR_".RM + ( + IN FILENAME VARCHAR(256 CHARS) CHARACTER SET UTF8 + ) + EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.rm (java.lang.String)' + LIBRARY TRAFODION."_LIBMGR_".DB__LIBMGRNAME + EXTERNAL SECURITY DEFINER + LANGUAGE JAVA + PARAMETER STYLE JAVA + READS SQL DATA + DYNAMIC RESULT SETS 0 + NO TRANSACTION REQUIRED + ISOLATE + ; + +-- GRANT EXECUTE ON FUNCTION TRAFODION."_LIBMGR_".RM TO DB__ROOT WITH GRANT OPTION; + GRANT EXECUTE ON FUNCTION TRAFODION."_LIBMGR_".RM TO DB__LIBMGRROLE WITH + GRANT OPTION; + +--- SQL operation complete. +>> +>>-- reset +>>initialize authorization, drop; + +--- SQL operation complete. +>>initialize trafodion, drop library management; + +--- SQL operation complete. +>>execute get_schemas; + +SCHEMA_NAME +---------------------------------------------------------------- + +SEABASE +_MD_ +_REPOS_ + +--- 3 row(s) selected. +>>get procedures; + +--- SQL operation complete. +>>get roles; + +Roles +===== + +PUBLIC + +--- SQL operation complete. +>> +>>-- **************************************************************************** +>>-- Verify enabling authorization followed by library management is correct +>>-- **************************************************************************** +>> +>>-- enable authorization +>>initialize authorization; + +--- SQL operation complete. +>>execute get_schemas; + +SCHEMA_NAME +---------------------------------------------------------------- + +SEABASE +_MD_ +_PRIVMGR_MD_ +_REPOS_ + +--- 4 row(s) selected. +>>get roles; + +Roles +===== + +DB__HBASEROLE +DB__HIVEROLE +DB__LIBMGRROLE +DB__ROOTROLE +PUBLIC + +--- SQL operation complete. +>> +>>-- enable library management +>>initialize trafodion, create library management; + +--- SQL operation complete. +>>execute get_schemas; + +SCHEMA_NAME +---------------------------------------------------------------- + +SEABASE +_LIBMGR_ +_MD_ +_PRIVMGR_MD_ +_REPOS_ + +--- 5 row(s) selected. +>>get libraries; + +Libraries in Schema TRAFODION._LIBMGR_ +====================================== + +DB__LIBMGRNAME + +--- SQL operation complete. +>>get procedures; + +Procedures in Schema TRAFODION._LIBMGR_ +======================================= + +ADDLIB +ALTERLIB +DROPLIB +GETFILE +HELP +LS +LSALL +PUT +RM +RMREX + +--- SQL operation complete. +>>showddl procedure rm; + +CREATE PROCEDURE TRAFODION."_LIBMGR_".RM + ( + IN FILENAME VARCHAR(256 CHARS) CHARACTER SET UTF8 + ) + EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.rm (java.lang.String)' + LIBRARY TRAFODION."_LIBMGR_".DB__LIBMGRNAME + EXTERNAL SECURITY DEFINER + LANGUAGE JAVA + PARAMETER STYLE JAVA + READS SQL DATA + DYNAMIC RESULT SETS 0 + NO TRANSACTION REQUIRED + ISOLATE + ; + +-- GRANT EXECUTE ON FUNCTION TRAFODION."_LIBMGR_".RM TO DB__ROOT WITH GRANT OPTION; + GRANT EXECUTE ON FUNCTION TRAFODION."_LIBMGR_".RM TO DB__LIBMGRROLE WITH + GRANT OPTION; + +--- SQL operation complete. +>>set param ?h 'PUT'; +>>call help (?h); + +COMMANDNAME +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +PUT - Upload a JAR. SHOWDDL PROCEDURE [SCHEMA NAME.]PUT for more info. + +--- SQL operation complete. +>> +>>-- **************************************************************************** +>>-- Test upgrade +>>-- **************************************************************************** +>> +>>-- upgrade, remove a couple of procedures and run upgrade +>>set parserflags 131072; + +--- SQL operation complete. +>>drop procedure PUT; + +--- SQL operation complete. +>>drop procedure ls; + +--- SQL operation complete. +>>reset parserflags 131072; + +--- SQL operation complete. +>>get procedures; + +Procedures in Schema TRAFODION._LIBMGR_ +======================================= + +ADDLIB +ALTERLIB +DROPLIB +GETFILE +HELP +LSALL +RM +RMREX + +--- SQL operation complete. +>>call ls(?); + +*** ERROR[1389] Object LS does not exist in Trafodion. + +*** ERROR[8822] The statement was not prepared. + +>> +>>initialize trafodion, upgrade library management; + +--- SQL operation complete. +>>get procedures; + +Procedures in Schema TRAFODION._LIBMGR_ +======================================= + +ADDLIB +ALTERLIB +DROPLIB +GETFILE +HELP +LS +LSALL +PUT +RM +RMREX + +--- SQL operation complete. +>>showddl procedure put; + +CREATE PROCEDURE TRAFODION."_LIBMGR_".PUT + ( + IN FILEDATA VARCHAR(102400) CHARACTER SET ISO88591 + , IN FILENAME VARCHAR(256 CHARS) CHARACTER SET UTF8 + , IN CREATEFLAG INTEGER + , IN FILEOVERWRITE INTEGER + ) + EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.put (java.lang.String,java.lang.String,int,int)' + LIBRARY TRAFODION."_LIBMGR_".DB__LIBMGRNAME + EXTERNAL SECURITY DEFINER + LANGUAGE JAVA + PARAMETER STYLE JAVA + READS SQL DATA + DYNAMIC RESULT SETS 0 + NO TRANSACTION REQUIRED + ISOLATE + ; + +-- GRANT EXECUTE ON FUNCTION TRAFODION."_LIBMGR_".PUT TO DB__ROOT WITH GRANT OPTION; + GRANT EXECUTE ON FUNCTION TRAFODION."_LIBMGR_".PUT TO DB__LIBMGRROLE WITH + GRANT OPTION; + +--- SQL operation complete. +>>call ls ('lib_mgmt.jar',?); + +FILENAMES +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + +<ls></ls> + +--- SQL operation complete. +>> +>>-- should fail - library management already enabled +>>initialize trafodion, create library management; + +*** ERROR[1390] Object TRAFODION."_LIBMGR_".DB__LIBMGRNAME already exists in Trafodion. + +--- SQL operation failed with errors. +>> +>>-- make sure everything is enabled +>>execute get_schemas; + +SCHEMA_NAME +---------------------------------------------------------------- + +SEABASE +_LIBMGR_ +_MD_ +_PRIVMGR_MD_ +_REPOS_ + +--- 5 row(s) selected. +>>get procedures; + +Procedures in Schema TRAFODION._LIBMGR_ +======================================= + +ADDLIB +ALTERLIB +DROPLIB +GETFILE +HELP +LS +LSALL +PUT +RM +RMREX + +--- SQL operation complete. +>> +>>-- we are done +>>exit; + +End of MXCI Session +
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/681cad66/core/sql/regress/udr/TEST102 ---------------------------------------------------------------------- diff --git a/core/sql/regress/udr/TEST102 b/core/sql/regress/udr/TEST102 new file mode 100644 index 0000000..ad99838 --- /dev/null +++ b/core/sql/regress/udr/TEST102 @@ -0,0 +1,119 @@ +-- @@@ 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 @@@ +-- +-- This tests the following commands: +-- +-- INITIALIZE TRAFODION, CREATE LIBRARY MANAGEMENT +-- INITIALIZE TRAFODION, DROP LIBRARY MANAGEMENT +-- INITIALIZE TRAFODION, UPGRADE LIBRARY MANAGEMENT + +-- start with both authorization and library management disabled +initialize trafodion, drop library management; +initialize authorization, drop; + +log LOG102 clear; +cqd SHOWDDL_DISPLAY_PRIVILEGE_GRANTS 'ON'; +set schema "_LIBMGR_"; + +prepare get_schemas from +select distinct substring (schema_name,1,16) as schema_name +from trafodion."_MD_".objects +where schema_name in ('SEABASE', '_LIBMGR_', '_MD_', '_PRIVMGR_MD_', '_REPOS_') +order by 1; + + +-- **************************************************************************** +-- Verify enabling library management followed by authorization is correct +-- **************************************************************************** + +-- authorization and library management should be disabled +execute get_schemas; + +-- create library management +initialize trafodion, create library management; +execute get_schemas; +get libraries; +get procedures; +showddl procedure rm; +set param ?h 'PUT'; +call help (?h); + +-- enable authorization +initialize authorization; +execute get_schemas; +get roles; +showddl procedure rm; + +-- reset +initialize authorization, drop; +initialize trafodion, drop library management; +execute get_schemas; +get procedures; +get roles; + +-- **************************************************************************** +-- Verify enabling authorization followed by library management is correct +-- **************************************************************************** + +-- enable authorization +initialize authorization; +execute get_schemas; +get roles; + +-- enable library management +initialize trafodion, create library management; +execute get_schemas; +get libraries; +get procedures; +showddl procedure rm; +set param ?h 'PUT'; +call help (?h); + +-- **************************************************************************** +-- Test upgrade +-- **************************************************************************** + +-- upgrade, remove a couple of procedures and run upgrade +set parserflags 131072; +drop procedure PUT; +drop procedure ls; +reset parserflags 131072; +get procedures; +call ls(?); + +initialize trafodion, upgrade library management; +get procedures; +showddl procedure put; +call ls ('lib_mgmt.jar',?); + +-- should fail - library management already enabled +initialize trafodion, create library management; + +-- make sure everything is enabled +execute get_schemas; +get procedures; + +-- we are done +exit; + + + + http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/681cad66/core/sql/sqlcat/desc.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcat/desc.h b/core/sql/sqlcat/desc.h index c4f61dc..1391843 100644 --- a/core/sql/sqlcat/desc.h +++ b/core/sql/sqlcat/desc.h @@ -171,6 +171,7 @@ struct indexes_desc_struct { char *indexname; // physical name of index. Different from ext_indexname // for ARK tables. ULng32 redeftime[2]; + Int64 indexUID; Int32 issystemtablecode; // ...but too much bother in ReadTableDef.C // Indicates whether it is a vertical partition or an index ComPartitioningScheme partitioningScheme; // round robin, range, etc. http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/681cad66/core/sql/sqlcomp/CmpDescribe.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpDescribe.cpp b/core/sql/sqlcomp/CmpDescribe.cpp index 1b0b290..2ba9652 100644 --- a/core/sql/sqlcomp/CmpDescribe.cpp +++ b/core/sql/sqlcomp/CmpDescribe.cpp @@ -446,29 +446,6 @@ static size_t indexLastNewline(const NAString & text, return newlinePos; } -NAString &replaceAll(NAString &source, NAString &searchFor, - NAString &replaceWith) -{ - size_t indexOfReplace = NA_NPOS; - indexOfReplace = source.index(searchFor); - if (indexOfReplace != NA_NPOS) - { - // Replace all occurences of searchFor with replaceWith. When no - // more occurences are found or end of string is reached, index() - // will return NA_NPOS. - while (indexOfReplace != NA_NPOS) - { - source.replace(indexOfReplace, searchFor.length(), - replaceWith); - // Find index of next occurence to replace. - indexOfReplace = - source.index(searchFor, indexOfReplace + replaceWith.length()); - } - } - - return source; -} - static Int32 displayDefaultValue(const char * defVal, const char * colName, NAString &displayableDefVal) { @@ -2691,7 +2668,7 @@ short CmpDescribeSeabaseTable ( // display syscols for invoke if not running regrs // - NABoolean displaySystemCols = ((!sqlmxRegr) && (type == 1)); + NABoolean displaySystemCols = (type == 1); NABoolean isView = (naTable->getViewText() ? TRUE : FALSE); @@ -2893,8 +2870,7 @@ short CmpDescribeSeabaseTable ( { if ((naTable->getClusteringIndex()) && (nonSystemKeyCols > 0) && - (NOT isStoreBy) && - (((type == 1) && (! sqlmxRegr)) || (type != 1))) + (NOT isStoreBy)) { numBTpkeys = naf->getIndexKeyColumns().entries(); @@ -3029,7 +3005,7 @@ short CmpDescribeSeabaseTable ( } NABoolean attributesSet = FALSE; - if (((NOT sqlmxRegr) && ((NOT isAudited) || (isAligned))) || + if ((((NOT isAudited) || (isAligned))) || ((sqlmxRegr) && (type == 3) && ((NOT isAudited) || (isAligned))) || ((NOT naTable->defaultColFam().isNull()) && (naTable->defaultColFam() != SEABASE_DEFAULT_COL_FAMILY))) http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/681cad66/core/sql/sqlcomp/CmpDescribe.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpDescribe.h b/core/sql/sqlcomp/CmpDescribe.h index c5759b3..7a9004f 100644 --- a/core/sql/sqlcomp/CmpDescribe.h +++ b/core/sql/sqlcomp/CmpDescribe.h @@ -58,6 +58,4 @@ void sendParserFlag (ULng32 flag); short setParentQidAtSession(NAHeap *heap, const char *parentQid); -NAString &replaceAll(NAString &source, NAString &searchFor, NAString &replaceWith); - #endif http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/681cad66/core/sql/sqlcomp/CmpSeabaseDDL.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDL.h b/core/sql/sqlcomp/CmpSeabaseDDL.h index e1eee25..6edcb51 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDL.h +++ b/core/sql/sqlcomp/CmpSeabaseDDL.h @@ -162,7 +162,7 @@ class CmpSeabaseDDL static NABoolean isHbase(const NAString &catName); static bool isHistogramTable(const NAString &tabName); - + static NABoolean isLOBDependentNameMatch(const NAString &name); static NABoolean isSeabaseMD(const NAString &catName, const NAString &schName, const NAString &objName); @@ -622,6 +622,12 @@ class CmpSeabaseDDL Int64 objectUID, Queue * &usingViewsQueue); + short getAllUsingViews(ExeCliInterface *cliInterface, + NAString &catName, + NAString &schName, + NAString &objName, + Queue * &usingViewsQueue); + void handleDDLCreateAuthorizationError( int32_t SQLErrorCode, const NAString & catalogName, @@ -726,7 +732,8 @@ class CmpSeabaseDDL Int64 objUID, ComTextType textType, Lng32 subID, - NAString &text); + NAString &text, + NABoolean withDelete = FALSE); // del before ins short deleteFromTextTable(ExeCliInterface *cliInterface, Int64 objUID, @@ -1006,29 +1013,62 @@ class CmpSeabaseDDL const NATable * naTable, Lng32 dropColNum); - short alignedFormatTableDropColumn - ( + short alignedFormatTableDropColumn( const NAString &catalogNamePart, const NAString &schemaNamePart, const NAString &objectNamePart, const NATable * naTable, const NAString &altColName, ElemDDLColDef *pColDef, - NABoolean ddlXns); + NABoolean ddlXns, + NAList<NAString> &viewNameList, + NAList<NAString> &viewDefnList); + + short hbaseFormatTableDropColumn( + ExpHbaseInterface *ehi, + const NAString &catalogNamePart, + const NAString &schemaNamePart, + const NAString &objectNamePart, + const NATable * naTable, + const NAString &altColName, + const NAColumn * nacol, + NABoolean ddlXns, + NAList<NAString> &viewNameList, + NAList<NAString> &viewDefnList); void alterSeabaseTableDropColumn( StmtDDLAlterTableDropColumn * alterDropColNode, NAString &currCatName, NAString &currSchName); - short recreateViews(ExeCliInterface &cliInterface, - NAList<NAString> &viewNameList, - NAList<NAString> &viewDefnList); + short saveAndDropUsingViews(Int64 objUID, + ExeCliInterface *cliInterface, + NAList<NAString> &viewNameList, + NAList<NAString> &viewDefnList); + + short recreateUsingViews(ExeCliInterface *cliInterface, + NAList<NAString> &viewNameList, + NAList<NAString> &viewDefnList, + NABoolean ddlXns); void alterSeabaseTableAlterIdentityColumn( StmtDDLAlterTableAlterColumnSetSGOption * alterIdentityColNode, NAString &currCatName, NAString &currSchName); - short alignedFormatTableAlterColumn + short mdOnlyAlterColumnAttr( + const NAString &catalogNamePart, const NAString &schemaNamePart, + const NAString &objectNamePart, + const NATable * naTable, const NAColumn * naCol, NAType * newType, + StmtDDLAlterTableAlterColumnDatatype * alterColNode, + NAList<NAString> &viewNameList, + NAList<NAString> &viewDefnList); + + short hbaseFormatTableAlterColumnAttr( + const NAString &catalogNamePart, const NAString &schemaNamePart, + const NAString &objectNamePart, + const NATable * naTable, const NAColumn * naCol, NAType * newType, + StmtDDLAlterTableAlterColumnDatatype * alterColNode); + + short alignedFormatTableAlterColumnAttr ( const NAString &catalogNamePart, const NAString &schemaNamePart, @@ -1036,18 +1076,18 @@ class CmpSeabaseDDL const NATable * naTable, const NAString &altColName, ElemDDLColDef *pColDef, - NABoolean ddlXns); - - short alterColumnAttr( - const NAString &catalogNamePart, const NAString &schemaNamePart, - const NAString &objectNamePart, - const NATable * naTable, const NAColumn * naCol, NAType * newType, - StmtDDLAlterTableAlterColumnDatatype * alterColNode); + NABoolean ddlXns, + NAList<NAString> &viewNameList, + NAList<NAString> &viewDefnList); void alterSeabaseTableAlterColumnDatatype( StmtDDLAlterTableAlterColumnDatatype * alterColumnDatatype, NAString &currCatName, NAString &currSchName); + void alterSeabaseTableAlterColumnRename( + StmtDDLAlterTableAlterColumnRename * alterColumnDatatype, + NAString &currCatName, NAString &currSchName); + void alterSeabaseTableAddPKeyConstraint( StmtDDLAddConstraint * alterAddConstraint, NAString &currCatName, NAString &currSchName); @@ -1130,6 +1170,13 @@ class CmpSeabaseDDL void dropSeabaseRoutine(StmtDDLDropRoutine * dropRoutineNode, NAString &currCatName, NAString &currSchName); + short createSeabaseLibmgr(ExeCliInterface * cliInterface); + short upgradeSeabaseLibmgr(ExeCliInterface * inCliInterface); + short dropSeabaseLibmgr(ExeCliInterface *inCliInterface); + short createLibmgrProcs(ExeCliInterface * cliInterface); + short grantLibmgrPrivs(ExeCliInterface *cliInterface); + + void createSeabaseSequence(StmtDDLCreateSequence * createSequenceNode, NAString &currCatName, NAString &currSchName); http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/681cad66/core/sql/sqlcomp/CmpSeabaseDDLauth.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLauth.cpp b/core/sql/sqlcomp/CmpSeabaseDDLauth.cpp index 7d7ac01..a551266 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLauth.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLauth.cpp @@ -929,7 +929,7 @@ void CmpSeabaseDDLuser::unregisterUser(StmtDDLRegisterUser * pNode) std::string(privMgrMDLoc.data()), CmpCommon::diags()); - if (role.isAuthorizationEnabled() && + if (CmpCommon::context()->isAuthorizationEnabled() && role.isUserGrantedAnyRole(getAuthID())) { *CmpCommon::diags() << DgSqlCode(-CAT_NO_UNREG_USER_GRANTED_ROLES); @@ -1232,26 +1232,27 @@ void CmpSeabaseDDLuser::verifyAuthority(bool isRemapUser) { -int32_t currentUser = ComUser::getCurrentUser(); + // If authorization is not enabled, just return with no error + if (!CmpCommon::context()->isAuthorizationEnabled()) + return; -// Root user has authority to manage users. + int32_t currentUser = ComUser::getCurrentUser(); + + // Root user has authority to manage users. if (currentUser == ComUser::getRootUserID()) return; -// Verify authorization is enabled. If not, no restrictions. -NAString systemCatalog = CmpSeabaseDDL::getSystemCatalogStatic(); -std::string privMDLoc(systemCatalog.data()); + // Verify authorization is enabled. If not, no restrictions. + NAString systemCatalog = CmpSeabaseDDL::getSystemCatalogStatic(); + std::string privMDLoc(systemCatalog.data()); privMDLoc += std::string(".\"") + std::string(SEABASE_PRIVMGR_SCHEMA) + std::string("\""); -PrivMgrComponentPrivileges componentPrivileges(privMDLoc,CmpCommon::diags()); - - if (!componentPrivileges.isAuthorizationEnabled()) - return; + PrivMgrComponentPrivileges componentPrivileges(privMDLoc,CmpCommon::diags()); -// Authorization enabled. See if non-root user has authority to manage users. + // See if non-root user has authority to manage users. if (componentPrivileges.hasSQLPriv(currentUser,SQLOperation::MANAGE_USERS,true)) { if (!isRemapUser) @@ -1260,7 +1261,7 @@ PrivMgrComponentPrivileges componentPrivileges(privMDLoc,CmpCommon::diags()); return; } -// No authority. We're outta here. + // No authority. We're outta here. *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED); UserException excp (NULL, 0); throw excp; @@ -1307,6 +1308,13 @@ void CmpSeabaseDDLrole::createRole(StmtDDLCreateRole * pNode) { + // Don't allow roles to be created unless authorization is enabled + if (!CmpCommon::context()->isAuthorizationEnabled()) + { + *CmpCommon::diags() << DgSqlCode(-CAT_AUTHORIZATION_NOT_ENABLED); + return; + } + // Set up a global try/catch loop to catch unexpected errors try { @@ -1396,18 +1404,15 @@ void CmpSeabaseDDLrole::createRole(StmtDDLCreateRole * pNode) PrivMgrRoles roles(std::string(MDSchema_.data()),std::string(privMgrMDLoc), CmpCommon::diags()); - if (roles.isAuthorizationEnabled()) - { - PrivStatus privStatus = roles.grantRoleToCreator(roleID, - getAuthDbName().data(), - getAuthCreator(), - creatorUsername); - if (privStatus != PrivStatus::STATUS_GOOD) - { - SEABASEDDL_INTERNAL_ERROR("Unable to grant role to role administrator"); - return; - } - } + PrivStatus privStatus = roles.grantRoleToCreator(roleID, + getAuthDbName().data(), + getAuthCreator(), + creatorUsername); + if (privStatus != PrivStatus::STATUS_GOOD) + { + SEABASEDDL_INTERNAL_ERROR("Unable to grant role to role administrator"); + return; + } } catch (...) { @@ -1427,23 +1432,26 @@ void CmpSeabaseDDLrole::createRole(StmtDDLCreateRole * pNode) // Input: // role name // role ID +// +// returns: true - added role, +// false - did not add role // ---------------------------------------------------------------------------- -void CmpSeabaseDDLrole::createStandardRole( +bool CmpSeabaseDDLrole::createStandardRole( const std::string roleName, const int32_t roleID) { -// Verify name is a standard name + // Verify name is a standard name -size_t prefixLength = strlen(RESERVED_AUTH_NAME_PREFIX); + size_t prefixLength = strlen(RESERVED_AUTH_NAME_PREFIX); if (roleName.size() <= prefixLength || roleName.compare(0,prefixLength,RESERVED_AUTH_NAME_PREFIX) != 0) { *CmpCommon::diags() << DgSqlCode(-CAT_ROLE_NOT_EXIST) << DgString0(roleName.data()); - return; + return false; } setAuthDbName(roleName.c_str()); @@ -1457,13 +1465,16 @@ size_t prefixLength = strlen(RESERVED_AUTH_NAME_PREFIX); // Make sure role has not already been registered if (authExists(getAuthDbName(),false)) - return; - - setAuthID(roleID); + return false; + + Int32 newRoleID = (roleID == NA_UserIdDefault) ? getUniqueID() : roleID; + setAuthID(newRoleID); setAuthCreator(ComUser::getRootUserID()); // Add the role to AUTHS table insertRow(); + + return true; } @@ -1537,8 +1548,11 @@ bool CmpSeabaseDDLrole::describe( roleText += ";\n"; - // See if authorization is enable. If so, need to list any grants of this + // See if authorization is enabled. If so, need to list any grants of this // role. Otherwise, we are outta here. + if (!CmpCommon::context()->isAuthorizationEnabled()) + return true; + NAString privMgrMDLoc; CONCAT_CATSCH(privMgrMDLoc,systemCatalog_.data(),SEABASE_PRIVMGR_SCHEMA); @@ -1546,8 +1560,6 @@ bool CmpSeabaseDDLrole::describe( PrivMgrRoles roles(std::string(MDSchema_.data()),std::string(privMgrMDLoc), CmpCommon::diags()); - if (!roles.isAuthorizationEnabled()) - return true; std::vector<std::string> granteeNames; std::vector<int32_t> grantDepths; @@ -1678,7 +1690,9 @@ void CmpSeabaseDDLrole::dropRole(StmtDDLCreateRole * pNode) PrivMgrRoles role(std::string(MDSchema_.data()),std::string(privMgrMDLoc), CmpCommon::diags()); - if (role.isAuthorizationEnabled()) + // If authorization is not enabled and a role has been defined, skip + // looking for dependencies and just remove the role from auths. + if (CmpCommon::context()->isAuthorizationEnabled()) { //TODO: Could support a CASCADE option that would clean up // grants and dependent objects. @@ -1838,7 +1852,7 @@ Int32 CmpSeabaseDDLrole::getUniqueID() sprintf(roleIDString,"%d",MIN_ROLEID); whereClause += roleIDString; whereClause += " and auth_id < "; - sprintf(roleIDString, "%d", MAX_ROLEID); + sprintf(roleIDString, "%d", MAX_ROLEID_RANGE1); whereClause += roleIDString; newRoleID = selectMaxAuthID(whereClause); @@ -1850,7 +1864,7 @@ Int32 CmpSeabaseDDLrole::getUniqueID() // We have 490000 available ID's. Don't expect to run out of ID's for awhile // but if/when we do, the algorithm needs to change. Can reuse ID's for roles // that were dropped. - if (newRoleID >= MAX_ROLEID) + if (newRoleID >= MAX_ROLEID_RANGE1) SEABASEDDL_INTERNAL_ERROR("CmpSeabaseDDLrole::getUniqueID failed, ran out of available IDs"); return newRoleID; @@ -1869,30 +1883,30 @@ void CmpSeabaseDDLrole::verifyAuthority() { -int32_t currentUser = ComUser::getCurrentUser(); + // If authorization is not enabled then role has privilege, just return + if (!CmpCommon::context()->isAuthorizationEnabled()) + return; -// Root user has authority to manage roles. + int32_t currentUser = ComUser::getCurrentUser(); + + // Root user has authority to manage roles. if (currentUser == ComUser::getRootUserID()) return; -// Verify authorization is enabled. If not, no restrictions. -NAString systemCatalog = CmpSeabaseDDL::getSystemCatalogStatic(); -std::string privMDLoc(systemCatalog.data()); + NAString systemCatalog = CmpSeabaseDDL::getSystemCatalogStatic(); + std::string privMDLoc(systemCatalog.data()); privMDLoc += std::string(".\"") + std::string(SEABASE_PRIVMGR_SCHEMA) + std::string("\""); -PrivMgrComponentPrivileges componentPrivileges(privMDLoc,CmpCommon::diags()); - - if (!componentPrivileges.isAuthorizationEnabled()) - return; + PrivMgrComponentPrivileges componentPrivileges(privMDLoc,CmpCommon::diags()); -// Authorization enabled. See if non-root user has authority to manage roles. + // Authorization enabled. See if non-root user has authority to manage roles. if (componentPrivileges.hasSQLPriv(currentUser,SQLOperation::MANAGE_ROLES,true)) return; -// No authority. We're outta here. + // No authority. We're outta here. *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED); UserException excp (NULL, 0); throw excp; http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/681cad66/core/sql/sqlcomp/CmpSeabaseDDLauth.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLauth.h b/core/sql/sqlcomp/CmpSeabaseDDLauth.h index 382c64d..17d49ad 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLauth.h +++ b/core/sql/sqlcomp/CmpSeabaseDDLauth.h @@ -193,7 +193,7 @@ class CmpSeabaseDDLrole : public CmpSeabaseDDLauth void createRole(StmtDDLCreateRole * pNode); - void createStandardRole( + bool createStandardRole( const std::string roleName, const int32_t roleID); http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/681cad66/core/sql/sqlcomp/CmpSeabaseDDLcleanup.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcleanup.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcleanup.cpp index 3648cc3..6ca1586 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLcleanup.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLcleanup.cpp @@ -815,7 +815,8 @@ short CmpSeabaseMDcleanup::dropLOBs(ExeCliInterface *cliInterface) return 0; NAString newSchName = "\"" + catName_ + "\"" + "." + "\"" + schName_ + "\""; - + const char *lobHdfsServer = CmpCommon::getDefaultString(LOB_HDFS_SERVER); + Int32 lobHdfsPort = (Lng32)CmpCommon::getDefaultNumeric(LOB_HDFS_PORT); cliRC = SQL_EXEC_LOBddlInterface((char*)newSchName.data(), newSchName.length(), objUID_, @@ -823,7 +824,9 @@ short CmpSeabaseMDcleanup::dropLOBs(ExeCliInterface *cliInterface) LOB_CLI_CLEANUP, lobNumList_, lobTypList_, - lobLocList_,0); + lobLocList_, + (char *)lobHdfsServer, + lobHdfsPort,0); return 0; } http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/681cad66/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp index 938d8f2..e89f3e3 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp @@ -67,6 +67,7 @@ #include "ComUser.h" #include "ComMisc.h" #include "CmpSeabaseDDLmd.h" +#include "CmpSeabaseDDLroutine.h" #include "hdfs.h" void cleanupLOBDataDescFiles(const char*, int, const char *); @@ -926,6 +927,17 @@ bool CmpSeabaseDDL::isHistogramTable(const NAString &name) } +NABoolean CmpSeabaseDDL::isLOBDependentNameMatch(const NAString &name) +{ + if ((name(0,min((sizeof(LOB_MD_PREFIX)-1), name.length())) == LOB_MD_PREFIX) || + (name(0,min((sizeof(LOB_DESC_CHUNK_PREFIX)-1), name.length()))==LOB_DESC_CHUNK_PREFIX)|| + (name(0,min((sizeof(LOB_DESC_HANDLE_PREFIX)-1), name.length()))==LOB_DESC_HANDLE_PREFIX) + ) + return true; + else + return false; +} + NABoolean CmpSeabaseDDL::isSeabase(const NAString &catName) { if ((CmpCommon::getDefault(MODE_SEABASE) == DF_ON) && @@ -3918,6 +3930,39 @@ short CmpSeabaseDDL::getUsingViews(ExeCliInterface *cliInterface, return 0; } + +// finds all views that directly or indirectly(thru another view) contains +// the given object. +// Returns them in ascending order of their create time. +short CmpSeabaseDDL::getAllUsingViews(ExeCliInterface *cliInterface, + NAString &catName, + NAString &schName, + NAString &objName, + Queue * &usingViewsQueue) +{ + Lng32 retcode = 0; + Lng32 cliRC = 0; + + char buf[4000]; + + str_sprintf(buf, "select '\"' || trim(o.catalog_name) || '\"' || '.' || '\"' || trim(o.schema_name) || '\"' || '.' || '\"' || trim(o.object_name) || '\"' " + ", o.create_time from %s.\"%s\".%s O, " + " (get all views on table \"%s\".\"%s\".\"%s\") x(a) " + " where trim(O.schema_name) || '.' || trim(O.object_name) = x.a " + " order by 2", + getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, + catName.data(), schName.data(), objName.data()); + + cliRC = cliInterface->fetchAllRows(usingViewsQueue, buf, 0, FALSE, FALSE, TRUE); + if (cliRC < 0) + { + cliInterface->retrieveSQLDiagnostics(CmpCommon::diags()); + return cliRC; + } + + return 0; +} + /* Get the salt column text for a given table or index. Returns 0 for object does not have salt column @@ -5821,9 +5866,24 @@ short CmpSeabaseDDL::updateTextTable(ExeCliInterface *cliInterface, Int64 objUID, ComTextType textType, Lng32 subID, - NAString &text) + NAString &text, + NABoolean withDelete) { Lng32 cliRC = 0; + if (withDelete) + { + // Note: It might be tempting to try an upsert instead of a + // delete followed by an insert, but this won't work. It is + // possible that the metadata text could shrink and take fewer + // rows in its new form than the old. So we do the simple thing + // to avoid such complications. + cliRC = deleteFromTextTable(cliInterface, objUID, textType, subID); + if (cliRC < 0) + { + return -1; + } + } + Lng32 textLen = text.length(); Lng32 bufLen = (textLen>TEXTLEN ? TEXTLEN : textLen) + 1000; char * buf = new(STMTHEAP) char[bufLen]; @@ -6829,6 +6889,11 @@ void CmpSeabaseDDL::initSeabaseMD(NABoolean ddlXns) goto label_error; } + if (createSeabaseLibmgr (&cliInterface)) + { + goto label_error; + } + cliRC = cliInterface.restoreCQD("traf_bootstrap_md_mode"); return; @@ -7648,10 +7713,28 @@ short CmpSeabaseDDL::initSeabaseAuthorization( if (retcode != STATUS_ERROR) { - // change authorization status in compiler context and kill arkcmps - GetCliGlobals()->currContext()->setAuthStateInCmpContexts(TRUE, TRUE); - for (short i = 0; i < GetCliGlobals()->currContext()->getNumArkcmps(); i++) - GetCliGlobals()->currContext()->getArkcmp(i)->endConnection(); + // Commit the transaction so privmgr schema exists in other processes + endXnIfStartedHere(cliInterface, xnWasStartedHere, 0); + if (beginXnIfNotInProgress(cliInterface, xnWasStartedHere)) + { + SEABASEDDL_INTERNAL_ERROR("initialize authorization"); + return -1; + } + + // change authorization status in compiler context and kill arkcmps + GetCliGlobals()->currContext()->setAuthStateInCmpContexts(TRUE, TRUE); + for (short i = 0; i < GetCliGlobals()->currContext()->getNumArkcmps(); i++) + GetCliGlobals()->currContext()->getArkcmp(i)->endConnection(); + + // If someone initializes trafodion with library management but does not + // initialize authorization, then the role DB__LIBMGRROLE has not been + // granted to LIBMGR procedures. Do this now + cliRC = existsInSeabaseMDTable(cliInterface, + getSystemCatalog(), SEABASE_LIBMGR_SCHEMA, + SEABASE_LIBMGR_LIBRARY, + COM_LIBRARY_OBJECT, TRUE, FALSE); + if (cliRC == 1) // library exists + cliRC = grantLibmgrPrivs(cliInterface); } else { @@ -8292,6 +8375,7 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode, (ddlExpr->dropRepos()) || (ddlExpr->upgradeRepos()) || (ddlExpr->addSchemaObjects()) || + (ddlExpr->createLibmgr()) || (ddlExpr->updateVersion()))) ignoreUninitTrafErr = TRUE; @@ -8331,7 +8415,6 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode, } NABoolean startXn = TRUE; - // no DDL transactions. if ((NOT ddlExpr->ddlXns()) && ((ddlExpr->dropHbase()) || @@ -8364,6 +8447,7 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode, (ddlNode->getOperatorType() == DDL_CREATE_TABLE) || (ddlNode->getOperatorType() == DDL_ALTER_TABLE_DROP_COLUMN) || (ddlNode->getOperatorType() == DDL_ALTER_TABLE_ALTER_COLUMN_DATATYPE) || + // (ddlNode->getOperatorType() == DDL_ALTER_TABLE_ALTER_COLUMN_RENAME) || (ddlNode->getOperatorType() == DDL_DROP_TABLE))) { // transaction will be started and commited in called methods. @@ -8399,7 +8483,7 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode, ddlNode->castToStmtDDLNode()->ddlXns()) && ((ddlNode->getOperatorType() == DDL_CLEANUP_OBJECTS) || (ddlNode->getOperatorType() == DDL_ALTER_TABLE_DROP_COLUMN) || - (ddlNode->getOperatorType() == DDL_ALTER_TABLE_ALTER_COLUMN_DATATYPE))) + (ddlNode->getOperatorType() == DDL_ALTER_TABLE_ALTER_COLUMN_DATATYPE))) { // transaction will be started and commited in called methods. startXn = FALSE; @@ -8476,6 +8560,18 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode, { createSeabaseSchemaObjects(); } + else if (ddlExpr->createLibmgr()) + { + createSeabaseLibmgr(&cliInterface); + } + else if (ddlExpr->dropLibmgr()) + { + dropSeabaseLibmgr(&cliInterface); + } + else if (ddlExpr->upgradeLibmgr()) + { + upgradeSeabaseLibmgr(&cliInterface); + } else if (ddlExpr->updateVersion()) { updateVersion(); @@ -8898,6 +8994,14 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode, alterSeabaseTableAlterColumnDatatype(alterColNode, currCatName, currSchName); } + else if (ddlNode->getOperatorType() == DDL_ALTER_TABLE_ALTER_COLUMN_RENAME) + { + StmtDDLAlterTableAlterColumnRename * alterColNode = + ddlNode->castToStmtDDLNode()->castToStmtDDLAlterTableAlterColumnRename(); + + alterSeabaseTableAlterColumnRename(alterColNode, + currCatName, currSchName); + } else if (ddlNode->getOperatorType() == DDL_CLEANUP_OBJECTS) { StmtDDLCleanupObjects * co = @@ -8924,13 +9028,13 @@ label_return: cliRC = -1; // some ddl stmts are executed as multiple sub statements. - // with ddl xns, some of those sub stmts may abort the enclosing - // xn in case of an error amd add an error condition that the xn + // some of those sub stmts may abort the enclosing xn started here + // in case of an error, and add an error condition that the xn // was aborted. // remove that error condition from the diags area. But dont do it - // if it is main error. - if (ddlXns && xnWasStartedHere && - (CmpCommon::diags()->mainSQLCODE() != -CLI_VALIDATE_TRANSACTION_ERROR)) + // if it is the main error. + // if (xnWasStartedHere && + if (CmpCommon::diags()->mainSQLCODE() != -CLI_VALIDATE_TRANSACTION_ERROR) { CollIndex i = CmpCommon::diags()->returnIndex(-CLI_VALIDATE_TRANSACTION_ERROR); http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/681cad66/core/sql/sqlcomp/CmpSeabaseDDLindex.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLindex.cpp b/core/sql/sqlcomp/CmpSeabaseDDLindex.cpp index 89c00bc..a70f8ef 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLindex.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLindex.cpp @@ -152,7 +152,7 @@ CmpSeabaseDDL::createIndexColAndKeyInfoArrays( const NAType * naType = tableCol->getType(); if ((naType->getFSDatatype() == REC_BLOB) || (naType->getFSDatatype() == REC_CLOB)) { - *CmpCommon::diags() << DgSqlCode(CAT_LOB_COL_CANNOT_BE_INDEX_OR_KEY) + *CmpCommon::diags() << DgSqlCode(-CAT_LOB_COL_CANNOT_BE_INDEX_OR_KEY) << DgColumnName(col_name); processReturn(); return -1; @@ -1969,7 +1969,7 @@ void CmpSeabaseDDL::alterSeabaseTableDisableOrEnableAllIndexes( char * catName = NULL; char * schName = NULL; indexes->position(); - for (int idx = 0; idx < indexes->numEntries(); idx++) + for (int ii = 0; ii < indexes->numEntries(); ii++) { OutputInfo * idx = (OutputInfo*) indexes->getNext(); http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/681cad66/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp b/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp index 85a3f26..e2e3105 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp @@ -40,6 +40,7 @@ #include "ComObjectName.h" #include "ComUser.h" +#include "CmpSeabaseDDLroutine.h" #include "StmtDDLCreateRoutine.h" #include "StmtDDLDropRoutine.h" @@ -1425,3 +1426,173 @@ short CmpSeabaseDDL::validateRoutine(ExeCliInterface *cliInterface, return -1; } // CmpSeabaseDDL::validateRoutine + +short CmpSeabaseDDL::createSeabaseLibmgr(ExeCliInterface * cliInterface) +{ + Lng32 cliRC = 0; + + if ((CmpCommon::context()->isUninitializedSeabase()) && + (CmpCommon::context()->uninitializedSeabaseErrNum() == -1393)) + { + *CmpCommon::diags() << DgSqlCode(-1393); + return -1; + } + + NAString jarLocation(getenv("MY_SQROOT")); + jarLocation += "/export/lib/lib_mgmt.jar"; + char queryBuf[strlen(getSystemCatalog()) + strlen(SEABASE_LIBMGR_SCHEMA) + + strlen(SEABASE_LIBMGR_LIBRARY) + strlen(DB__LIBMGRROLE) + + jarLocation.length() + 100]; + + // Create the SEABASE_LIBMGR_SCHEMA schema + str_sprintf(queryBuf, "create schema if not exists %s.\"%s\" authorization %s ", + getSystemCatalog(),SEABASE_LIBMGR_SCHEMA, DB__ROOT); + + cliRC = cliInterface->executeImmediate(queryBuf); + if (cliRC < 0) + { + cliInterface->retrieveSQLDiagnostics(CmpCommon::diags()); + return -1; + } + + // Create the SEABASE_LIBMGR_LIBRARY library + str_sprintf(queryBuf, "create library %s.\"%s\".%s file '%s'", + getSystemCatalog(), SEABASE_LIBMGR_SCHEMA, SEABASE_LIBMGR_LIBRARY, + jarLocation.data()); + + cliRC = cliInterface->executeImmediate(queryBuf); + if (cliRC < 0) + { + cliInterface->retrieveSQLDiagnostics(CmpCommon::diags()); + return -1; + } + + return (createLibmgrProcs(cliInterface)); +} + +short CmpSeabaseDDL::createLibmgrProcs(ExeCliInterface * cliInterface) +{ + Lng32 cliRC = 0; + + // Create the procedures if they don't already exist + for (Int32 i = 0; i < sizeof(allLibmgrRoutineInfo)/sizeof(LibmgrRoutineInfo); i++) + { + // Get the next procedure routine details + const LibmgrRoutineInfo &prd = allLibmgrRoutineInfo[i]; + + const QString * qs = NULL; + Int32 sizeOfqs = 0; + + qs = prd.newDDL; + sizeOfqs = prd.sizeOfnewDDL; + + Int32 qryArraySize = sizeOfqs / sizeof(QString); + char * gluedQuery; + Lng32 gluedQuerySize; + glueQueryFragments(qryArraySize, qs, + gluedQuery, gluedQuerySize); + + param_[0] = getSystemCatalog(); + param_[1] = SEABASE_LIBMGR_SCHEMA; + param_[2] = getSystemCatalog(); + param_[3] = SEABASE_LIBMGR_SCHEMA; + param_[4] = SEABASE_LIBMGR_LIBRARY; + + // Review comment - make sure size of queryBuf is big enough to hold + // generated text. + char queryBuf[strlen(getSystemCatalog())*2 + strlen(SEABASE_LIBMGR_SCHEMA)*2 + + strlen(SEABASE_LIBMGR_LIBRARY) + gluedQuerySize + 200]; + + str_sprintf(queryBuf, gluedQuery, param_[0], param_[1], param_[2], param_[3], param_[4]); + NADELETEBASIC(gluedQuery, STMTHEAP); + + cliRC = cliInterface->executeImmediate(queryBuf); + if (cliRC < 0) + { + cliInterface->retrieveSQLDiagnostics(CmpCommon::diags()); + return -1; + } + } // for + + return (grantLibmgrPrivs(cliInterface)); +} + +// If authorization is enabled, grant privileges to DB__LIBMGRROLE +short CmpSeabaseDDL::grantLibmgrPrivs(ExeCliInterface *cliInterface) +{ + if (!isAuthorizationEnabled()) + return 0; + + Lng32 cliRC = 0; + char queryBuf[strlen(getSystemCatalog()) + strlen(SEABASE_LIBMGR_SCHEMA) + + strlen(SEABASE_LIBMGR_LIBRARY) + strlen(DB__LIBMGRROLE) + 200]; + for (Int32 i = 0; i < sizeof(allLibmgrRoutineInfo)/sizeof(LibmgrRoutineInfo); i++) + { + // Get the next procedure routine details + const LibmgrRoutineInfo &prd = allLibmgrRoutineInfo[i]; + + str_sprintf (queryBuf, "grant execute on procedure %s.\"%s\".%s to %s with grant option", + getSystemCatalog(),SEABASE_LIBMGR_SCHEMA,prd.newName, + DB__LIBMGRROLE); + cliRC = cliInterface->executeImmediate(queryBuf); + if (cliRC < 0) + { + cliInterface->retrieveSQLDiagnostics(CmpCommon::diags()); + return -1; + } + } + return 0; +} + +short CmpSeabaseDDL::upgradeSeabaseLibmgr(ExeCliInterface * cliInterface) +{ + Lng32 cliRC = 0; + + cliRC = existsInSeabaseMDTable(cliInterface, + getSystemCatalog(), SEABASE_LIBMGR_SCHEMA, + SEABASE_LIBMGR_LIBRARY, + COM_LIBRARY_OBJECT, TRUE, FALSE); + if (cliRC < 0) + return -1; + + if (cliRC == 0) // does not exist + { + NAString libraryName(getSystemCatalog()); + libraryName + ".\"" + SEABASE_LIBMGR_SCHEMA + "\"" + SEABASE_LIBMGR_LIBRARY; + *CmpCommon::diags() << DgSqlCode(-1389) + << DgString0(libraryName.data()); + return -1; + } + + return (createLibmgrProcs(cliInterface)); +} + +short CmpSeabaseDDL::dropSeabaseLibmgr(ExeCliInterface *cliInterface) +{ + Lng32 cliRC = 0; + + char queryBuf[strlen(getSystemCatalog()) + strlen(SEABASE_LIBMGR_SCHEMA) + 100]; + + // save the current parserflags setting + ULng32 savedParserFlags = Get_SqlParser_Flags(0xFFFFFFFF); + Set_SqlParser_Flags(INTERNAL_QUERY_FROM_EXEUTIL); + + str_sprintf(queryBuf, "drop schema if exists %s.\"%s\" cascade ", + getSystemCatalog(),SEABASE_LIBMGR_SCHEMA, DB__ROOT); + + // Drop the SEABASE_LIBMGR_SCHEMA schema + cliRC = cliInterface->executeImmediate(queryBuf); + + // Restore parser flags settings to what they originally were + Assign_SqlParser_Flags(savedParserFlags); + + if (cliRC < 0) + { + cliInterface->retrieveSQLDiagnostics(CmpCommon::diags()); + return -1; + } + return 0; +} + + +
