http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/19c96b1e/core/sql/sqlcat/readRealArk.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcat/readRealArk.cpp b/core/sql/sqlcat/readRealArk.cpp index 5e04877..e49553c 100644 --- a/core/sql/sqlcat/readRealArk.cpp +++ b/core/sql/sqlcat/readRealArk.cpp @@ -22,7 +22,7 @@ ***************************************************************************** * * File: readRealArk.C - * Description: This module converts SOL based meta-data to desc_struct + * Description: This module converts SOL based meta-data to TrafDesc * based meta-data. * * Created: 11/20/96 @@ -43,6 +43,7 @@ #include "CmpStatement.h" #include "BaseTypes.h" #include "readRealArk.h" +#include "TrafDDLdesc.h" // Copy a string. A null terminated buffer is returned. // Uses HEAP (StatementHeap) of CmpCommon! @@ -57,148 +58,59 @@ static char *copyString(const ComString &sourceString, // ----------------------------------------------------------------------- -// Allocate one of the primitive structs and initialize to all zeroes. -// Uses HEAP (StatementHeap) of CmpCommon! -// ----------------------------------------------------------------------- -desc_struct *readtabledef_allocate_desc(desc_nodetype nodetype) -{ - size_t size = 0; - - switch (nodetype) - { - case DESC_CHECK_CONSTRNTS_TYPE: - size = sizeof(check_constrnts_desc_struct); - break; - case DESC_COLUMNS_TYPE: - size = sizeof(columns_desc_struct); - break; - case DESC_CONSTRNTS_TYPE: - size = sizeof(constrnts_desc_struct); - break; - case DESC_CONSTRNT_KEY_COLS_TYPE: - size = sizeof(constrnt_key_cols_desc_struct); - break; - case DESC_FILES_TYPE: - size = sizeof(files_desc_struct); - break; - case DESC_HISTOGRAM_TYPE: - size = sizeof(histogram_desc_struct); - break; - case DESC_HIST_INTERVAL_TYPE: - size = sizeof(hist_interval_desc_struct); - break; - case DESC_INDEXES_TYPE: - size = sizeof(indexes_desc_struct); - break; - case DESC_KEYS_TYPE: - size = sizeof(keys_desc_struct); - break; - case DESC_PARTNS_TYPE: - size = sizeof(partns_desc_struct); - break; - case DESC_REF_CONSTRNTS_TYPE: - size = sizeof(ref_constrnts_desc_struct); - break; - case DESC_TABLE_TYPE: - size = sizeof(table_desc_struct); - break; - case DESC_VIEW_TYPE: - size = sizeof(view_desc_struct); - break; - case DESC_USING_MV_TYPE: // MV - size = sizeof(using_mv_desc_struct); - break; - case DESC_SEQUENCE_GENERATOR_TYPE: - size = sizeof(sequence_generator_desc_struct); - break; - case DESC_ROUTINE_TYPE: - size = sizeof(routine_desc_struct); - break; - case DESC_LIBRARY_TYPE: - size = sizeof(library_desc_struct); - break; - default: - assert(FALSE); - break; - } - // DBG( cerr << "... rtd_allocate_desc " << nodetype << " " << size << " "; ) - - size += sizeof(header_desc_struct); - char *desc_buf = new HEAP char[size]; - - // Note that this puts literal zero bytes into floats and pointer fields, - // which are not portably equivalent to (float)0 and (void *)NULL. - // This is a better default than not initializing at all, however. - memset(desc_buf, 0, size); - - desc_struct *desc_ptr = (desc_struct *)desc_buf; - desc_ptr->header.nodetype = nodetype; - desc_ptr->header.next = NULL; // example of portable initlzn. - - // DBG( cerr << size << " " << desc_ptr << endl; ) - return desc_ptr; - -} - -// ----------------------------------------------------------------------- // Allocate a column_desc and do simple initialization of several fields, // based on what's passed in. Many of the fields we just default, // to either hardcoded values or to zero. The callers, // in arkcmplib + generator + optimizer, can set additional fields afterwards. // ----------------------------------------------------------------------- -desc_struct *readtabledef_make_column_desc(const char *tablename, - const char *colname, - Lng32 &colnumber, // INOUT - DataType datatype, - Lng32 length, - Lng32 &offset, // INOUT - short null_flag, - NABoolean tablenameMustBeAllocated, - desc_struct *passedDesc, - SQLCHARSET_CODE datacharset - ) +TrafDesc *TrafMakeColumnDesc(const char *tablename, + const char *colname, + Lng32 &colnumber, // INOUT + Int32 datatype, + Lng32 length, + Lng32 &offset, // INOUT + NABoolean null_flag, + SQLCHARSET_CODE datacharset, + Space * space + ) { #undef COLUMN - #define COLUMN returnDesc->body.columns_desc + #define COLUMN returnDesc->columnsDesc() // Pass in the optional "passedDesc" if you just want to overwrite an // already existing desc. - desc_struct *returnDesc = passedDesc; - if (!returnDesc) returnDesc = readtabledef_allocate_desc(DESC_COLUMNS_TYPE); + TrafDesc *returnDesc = + TrafAllocateDDLdesc(DESC_COLUMNS_TYPE, space); - if (tablenameMustBeAllocated) - COLUMN.tablename = copyString(NAString(tablename)); - else - COLUMN.tablename = (char *)tablename; // just copy the pointer! + COLUMN->colname = (char *)colname; - COLUMN.colname = copyString(colname); - COLUMN.colnumber = colnumber; - COLUMN.datatype = datatype; - COLUMN.length = length; - COLUMN.offset = offset; - COLUMN.null_flag = null_flag; + COLUMN->colnumber = colnumber; + COLUMN->datatype = datatype; + COLUMN->length = length; + COLUMN->offset = offset; + COLUMN->setNullable(null_flag); // Hardcode some fields here. // All other fields (scale, precision, etc) default to zero! - COLUMN.colclass = 'U'; - COLUMN.defaultClass = COM_NO_DEFAULT; + COLUMN->colclass = 'U'; + COLUMN->setDefaultClass(COM_NO_DEFAULT); if (DFS2REC::isAnyCharacter(datatype)) { if (datacharset == SQLCHARSETCODE_UNKNOWN) { - COLUMN.character_set = CharInfo::DefaultCharSet; - COLUMN.encoding_charset = CharInfo::DefaultCharSet; + COLUMN->character_set = CharInfo::DefaultCharSet; + COLUMN->encoding_charset = CharInfo::DefaultCharSet; } else { - COLUMN.character_set = (CharInfo::CharSet)datacharset; - COLUMN.encoding_charset = (CharInfo::CharSet)datacharset; + COLUMN->character_set = (CharInfo::CharSet)datacharset; + COLUMN->encoding_charset = (CharInfo::CharSet)datacharset; } - COLUMN.collation_sequence = CharInfo::DefaultCollation; + COLUMN->collation_sequence = CharInfo::DefaultCollation; if (DFS2REC::isSQLVarChar(datatype)) offset += SQL_VARCHAR_HDR_SIZE; } else { // datetime, interval, numeric, etc. - COLUMN.datetimestart = COLUMN.datetimeend = REC_DATE_UNKNOWN; + COLUMN->datetimestart = COLUMN->datetimeend = REC_DATE_UNKNOWN; } colnumber++;
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/19c96b1e/core/sql/sqlcat/readRealArk.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcat/readRealArk.h b/core/sql/sqlcat/readRealArk.h index bc70266..cb2867b 100644 --- a/core/sql/sqlcat/readRealArk.h +++ b/core/sql/sqlcat/readRealArk.h @@ -24,7 +24,6 @@ #ifndef READREALARK_H #define READREALARK_H -#include "desc.h" #include "ComSmallDefs.h" #include "ObjectNames.h" http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/19c96b1e/core/sql/sqlcomp/CmpDDLCatErrorCodes.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpDDLCatErrorCodes.h b/core/sql/sqlcomp/CmpDDLCatErrorCodes.h index d79bf2a..25f439c 100644 --- a/core/sql/sqlcomp/CmpDDLCatErrorCodes.h +++ b/core/sql/sqlcomp/CmpDDLCatErrorCodes.h @@ -285,6 +285,7 @@ enum CatErrorCode { CAT_FIRST_ERROR = 1000 , CAT_COLUMN_WRONG_DEFAULT_TYPE = 1295 , CAT_COLUMN_MISMATCHED_DEFAULT_TYPES = 1296 , CAT_VOLATILE_SCHEMA_PRESENT = 1297 + , CAT_UNABLE_TO_ALTER_SCHEMA = 1298 // Restrict and No Action referential action Messages. , CAT_REF_CONSTRAINT_NO_ACTION_NOT_SUPPORTED = 1301 http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/19c96b1e/core/sql/sqlcomp/CmpDescribe.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpDescribe.cpp b/core/sql/sqlcomp/CmpDescribe.cpp index c663fb4..97cd5b5 100644 --- a/core/sql/sqlcomp/CmpDescribe.cpp +++ b/core/sql/sqlcomp/CmpDescribe.cpp @@ -96,6 +96,7 @@ #include "Analyzer.h" #include "ComSqlId.h" #include "ExExeUtilCli.h" +#include "TrafDDLdesc.h" #define CM_SIM_NAME_LEN 32 @@ -230,8 +231,8 @@ bool CmpDescribeIsAuthorized( // ## This only applies to CatSim; remove it! #define CONSTRAINT_IS_NAMED(constrdesc) \ - (constrdesc->body.constrnts_desc.constrntname && \ - *constrdesc->body.constrnts_desc.constrntname) + (constrdesc->constrnts_desc.constrntname && \ + *constrdesc->constrnts_desc.constrntname) // Define a shorter synonym. #define SpacePrefix CmpDescribeSpaceCountPrefix @@ -872,7 +873,7 @@ short CmpDescribe(const char *query, const RelExpr *queryExpr, goto finally; // we are done } - desc_struct *tabledesc = NULL; + TrafDesc *tabledesc = NULL; if ( ExtendedQualName::isDescribableTableType(tType) ) { *CmpCommon::diags() << DgSqlCode(-4222) @@ -909,7 +910,7 @@ short CmpDescribe(const char *query, const RelExpr *queryExpr, goto finally; } - NAString tableName(tabledesc->body.table_desc.tablename) ; + NAString tableName(tabledesc->tableDesc()->tablename) ; NABoolean external = d->getIsExternal(); //strip catalog off of table name @@ -942,7 +943,7 @@ short CmpDescribe(const char *query, const RelExpr *queryExpr, buf = new (CmpCommon::statementHeap()) char[LOCAL_BIGBUF_SIZE]; CMPASSERT(buf); - desc_struct *viewdesc = tabledesc->body.table_desc.views_desc; + TrafDesc *viewdesc = tabledesc->tableDesc()->views_desc; if (d->getFormat() == Describe::INVOKE_) { @@ -1010,7 +1011,6 @@ short CmpDescribe(const char *query, const RelExpr *queryExpr, space.makeContiguous(outbuf, outbuflen); NADELETEBASIC(buf, CmpCommon::statementHeap()); - CmpCommon::context()->readTableDef_->deleteTree(tabledesc); goto finally; // we are done and rc is already 0 } @@ -1060,7 +1060,6 @@ short CmpDescribe(const char *query, const RelExpr *queryExpr, Reset_SqlParser_Flags(ALLOW_VOLATILE_SCHEMA_IN_TABLE_NAME); NADELETEBASIC(buf, CmpCommon::statementHeap()); - CmpCommon::context()->readTableDef_->deleteTree(tabledesc); } // end of try block @@ -3737,7 +3736,7 @@ bool CmpDescribeLibrary( ExeCliInterface cliInterface(heap); - desc_struct *tDesc = cmpSBD.getSeabaseLibraryDesc(libCatNamePart, + TrafDesc *tDesc = cmpSBD.getSeabaseLibraryDesc(libCatNamePart, libSchNamePart, libObjNamePart); if (tDesc == NULL) @@ -3748,7 +3747,7 @@ bool CmpDescribeLibrary( } - Int64 libraryUID = tDesc->body.library_desc.libraryUID; + Int64 libraryUID = tDesc->libraryDesc()->libraryUID; if (libraryUID <= 0) // does not exist { @@ -3793,7 +3792,7 @@ Space * space = &localSpace; char buf[1000]; sprintf(buf,"CREATE LIBRARY %s FILE '%s'", - extLibraryName.data(), tDesc->body.library_desc.libraryFilename); + extLibraryName.data(), tDesc->libraryDesc()->libraryFilename); outputShortLine(*space,buf); outputShortLine(*space,";"); @@ -3819,8 +3818,8 @@ char buf[1000]; std::string privilegeText; PrivMgrObjectInfo objectInfo ( libraryUID, extLibraryName.data(), - tDesc->body.library_desc.libraryOwnerID, - tDesc->body.library_desc.librarySchemaOwnerID, + tDesc->libraryDesc()->libraryOwnerID, + tDesc->libraryDesc()->librarySchemaOwnerID, COM_LIBRARY_OBJECT ); if (cmpSBD.switchCompiler()) { http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/19c96b1e/core/sql/sqlcomp/CmpSeabaseDDL.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDL.h b/core/sql/sqlcomp/CmpSeabaseDDL.h index a00a7ec..3b583e7 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDL.h +++ b/core/sql/sqlcomp/CmpSeabaseDDL.h @@ -40,7 +40,6 @@ #include "ExpLOBenums.h" #include "NADefaults.h" #include "NAColumn.h" -#include "desc.h" #include "CmpMessage.h" #include "PrivMgrDefs.h" #include "PrivMgrMD.h" @@ -81,6 +80,7 @@ class StmtDDLCreateSequence; class StmtDDLDropSequence; class StmtDDLDropSchema; +class StmtDDLAlterSchema; // Classes for user management class StmtDDLRegisterUser; @@ -111,7 +111,7 @@ class NADefaults; class NAType; -struct desc_struct; +struct TrafDesc; class OutputInfo; class HbaseCreateOption; @@ -120,7 +120,7 @@ class Parser; class NAColumnArray; -struct routine_desc_struct; +class TrafRoutineDesc; struct MDDescsInfo; class CmpDDLwithStatusInfo; @@ -232,7 +232,7 @@ class CmpSeabaseDDL NAString &currCatName, NAString &currSchName, CmpDDLwithStatusInfo *dws = NULL); - desc_struct * getSeabaseTableDesc(const NAString &catName, + TrafDesc * getSeabaseTableDesc(const NAString &catName, const NAString &schName, const NAString &objName, const ComObjectType objType, @@ -279,12 +279,12 @@ class CmpSeabaseDDL Int64 objectUID, ElemDDLHbaseOptions * edhbo); - desc_struct * getSeabaseLibraryDesc( + TrafDesc * getSeabaseLibraryDesc( const NAString &catName, const NAString &schName, const NAString &libraryName); - desc_struct *getSeabaseRoutineDesc(const NAString &catName, + TrafDesc *getSeabaseRoutineDesc(const NAString &catName, const NAString &schName, const NAString &objName); @@ -334,19 +334,19 @@ class CmpSeabaseDDL // The next three methods do use anything from the CmpSeabaseDDL class. // They are placed here as a packaging convinience, to avoid code // duplication that would occur if non-member static functions were used. - // These methods convert VirtTable*Info classes to corresponding desc_struct + // These methods convert VirtTable*Info classes to corresponding TrafDesc // objects void convertVirtTableColumnInfoToDescStruct( const ComTdbVirtTableColumnInfo * colInfo, const ComObjectName * objectName, - desc_struct * column_desc); + TrafDesc * column_desc); - desc_struct * convertVirtTableColumnInfoArrayToDescStructs( + TrafDesc * convertVirtTableColumnInfoArrayToDescStructs( const ComObjectName * objectName, const ComTdbVirtTableColumnInfo * colInfoArray, Lng32 numCols); - desc_struct * convertVirtTableKeyInfoArrayToDescStructs( + TrafDesc * convertVirtTableKeyInfoArrayToDescStructs( const ComTdbVirtTableKeyInfo *keyInfoArray, const ComTdbVirtTableColumnInfo *colInfoArray, Lng32 numKeys); @@ -430,7 +430,13 @@ class CmpSeabaseDDL enum { // set if we need to get the hbase snapshot info of the table - GET_SNAPSHOTS = 0x0002 + GET_SNAPSHOTS = 0x0002, + + // set if descr is to be generated in packed format to be stored in metadata + GEN_PACKED_DESC = 0x0004, + + // set if stored object descriptor is to be read from metadata. + READ_OBJECT_DESC = 0x0008 }; protected: @@ -482,7 +488,7 @@ protected: void getColName(const char * colFam, const char * colQual, NAString &colName); - desc_struct *getSeabaseRoutineDescInternal(const NAString &catName, + TrafDesc *getSeabaseRoutineDescInternal(const NAString &catName, const NAString &schName, const NAString &objName); @@ -720,13 +726,22 @@ protected: const char * schName, const char * objName); + // retrieved stored desc from metadata, check if it is good, + // and set retDesc, if passed in. + short checkAndGetStoredObjectDesc( + ExeCliInterface *cliInterface, + Int64 objUID, + TrafDesc* *retDesc); + short updateObjectRedefTime( ExeCliInterface *cliInterface, const NAString &catName, const NAString &schName, const NAString &objName, const char * objType, - Int64 rt = -1); + Int64 rt = -1, + Int64 objUID = -1, + NABoolean force = FALSE); short updateObjectValidDef( ExeCliInterface *cliInterface, @@ -744,6 +759,12 @@ protected: NABoolean audited, const NAString& objType); + short updateObjectFlags( + ExeCliInterface *cliInterface, + const Int64 objUID, + const Int64 inFlags, + NABoolean reset); + // subID: 0, for text that belongs to table. colNumber, for column based text. short updateTextTable(ExeCliInterface *cliInterface, Int64 objUID, @@ -752,6 +773,15 @@ protected: NAString &text, NABoolean withDelete = FALSE); // del before ins + // input data in non-char format. + short updateTextTableWithBinaryData(ExeCliInterface *cliInterface, + Int64 objUID, + ComTextType textType, + Lng32 subID, + char * data, + Int32 dataLen, + NABoolean withDelete); + short deleteFromTextTable(ExeCliInterface *cliInterface, Int64 objUID, ComTextType textType, @@ -764,7 +794,7 @@ protected: short createEncodedKeysBuffer(char** &encodedKeysBuffer, int &numSplits, - desc_struct * colDescs, desc_struct * keyDescs, + TrafDesc * colDescs, TrafDesc * keyDescs, int numSaltPartitions, Lng32 numSaltSplits, NAString *splitByClause, @@ -946,12 +976,14 @@ protected: ExeCliInterface &cliInterface, StmtDDLCreateTable * createTableNode, NAString &currCatName, NAString &currSchName, - NABoolean isCompound = FALSE); + NABoolean isCompound, + Int64 &objUID); void createSeabaseTable( StmtDDLCreateTable * createTableNode, NAString &currCatName, NAString &currSchName, - NABoolean isCompound = FALSE); + NABoolean isCompound = FALSE, + Int64 * retObjUID = NULL); void createSeabaseTableCompound( StmtDDLCreateTable * createTableNode, @@ -1012,6 +1044,10 @@ protected: StmtDDLAlterTableRename * renameTableNode, NAString &currCatName, NAString &currSchName); + void alterSeabaseTableStoredDesc( + StmtDDLAlterTableStoredDesc * alterStoredDesc, + NAString &currCatName, NAString &currSchName); + void alterSeabaseTableHBaseOptions( StmtDDLAlterTableHBaseOptions * hbaseOptionsNode, NAString &currCatName, NAString &currSchName); @@ -1227,6 +1263,9 @@ protected: NAString &currCatName, NAString &currSchName); void dropSeabaseSchema(StmtDDLDropSchema * dropSchemaNode); + + void alterSeabaseSchema(StmtDDLAlterSchema * alterSchemaNode); + bool dropOneTableorView( ExeCliInterface & cliInterface, @@ -1315,12 +1354,12 @@ protected: ComTdbVirtTableTableInfo* &tableInfo ); - desc_struct * getSeabaseMDTableDesc(const NAString &catName, + TrafDesc * getSeabaseMDTableDesc(const NAString &catName, const NAString &schName, const NAString &objName, const ComObjectType objType); - desc_struct * getSeabaseHistTableDesc(const NAString &catName, + TrafDesc * getSeabaseHistTableDesc(const NAString &catName, const NAString &schName, const NAString &objName); @@ -1333,7 +1372,7 @@ protected: Int32 & schemaOwner, Int64 & seqUID); - desc_struct * getSeabaseSequenceDesc(const NAString &catName, + TrafDesc * getSeabaseSequenceDesc(const NAString &catName, const NAString &schName, const NAString &seqName); @@ -1348,12 +1387,13 @@ protected: Lng32 *numCols, ComTdbVirtTableColumnInfo **colInfoArray); - desc_struct * getSeabaseUserTableDesc(const NAString &catName, + TrafDesc * getSeabaseUserTableDesc(const NAString &catName, const NAString &schName, const NAString &objName, const ComObjectType objType, NABoolean includeInvalidDefs, - Int32 ctlFlags); + Int32 ctlFlags, + Int32 &packedDescLen); static NABoolean getMDtableInfo(const ComObjectName &ansiName, ComTdbVirtTableTableInfo* &tableInfo, @@ -1452,7 +1492,4 @@ private: NABoolean cmpSwitched_; }; -desc_struct* assembleDescs(NAArray<HbaseStr>*keyArray, populateFuncT func, NAMemory* heap); - - #endif // _CMP_SEABASE_DDL_H_ http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/19c96b1e/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp index 6b51feb..1a8f16f 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp @@ -71,6 +71,8 @@ #include "hdfs.h" #include "StmtDDLAlterLibrary.h" #include "logmxevent_traf.h" +#include "exp_clause_derived.h" +#include "TrafDDLdesc.h" void cleanupLOBDataDescFiles(const char*, int, const char *); @@ -406,29 +408,34 @@ short CmpSeabaseDDL::convertColAndKeyInfoArrays( { ComTdbVirtTableColumnInfo &ci = btColInfoArray[i]; - columns_desc_struct column_desc; - column_desc.datatype = ci.datatype; - column_desc.length = ci.length; - column_desc.precision = ci.precision; - column_desc.scale = ci.scale; - column_desc.null_flag = ci.nullable; - column_desc.character_set/*CharInfo::CharSet*/ + Lng32 colnum, offset; + TrafDesc * desc = + TrafMakeColumnDesc(NULL, NULL, colnum, ci.datatype, ci.length, + offset, ci.nullable, ci.charset, NULL); + TrafColumnsDesc *column_desc = desc->columnsDesc(); + + column_desc->datatype = ci.datatype; + column_desc->length = ci.length; + column_desc->precision = ci.precision; + column_desc->scale = ci.scale; + column_desc->setNullable(ci.nullable); + column_desc->character_set/*CharInfo::CharSet*/ = (CharInfo::CharSet)ci.charset; - column_desc.upshift = ci.upshifted; - column_desc.caseinsensitive = 0; - column_desc.collation_sequence = CharInfo::DefaultCollation; - column_desc.encoding_charset = (CharInfo::CharSet)ci.charset; + column_desc->setUpshifted(ci.upshifted); + column_desc->setCaseInsensitive(FALSE); + column_desc->collation_sequence = CharInfo::DefaultCollation; + column_desc->encoding_charset = (CharInfo::CharSet)ci.charset; - column_desc.datetimestart = (rec_datetime_field)ci.dtStart; - column_desc.datetimeend = (rec_datetime_field)ci.dtEnd; - column_desc.datetimefractprec = ci.scale; + column_desc->datetimestart = (rec_datetime_field)ci.dtStart; + column_desc->datetimeend = (rec_datetime_field)ci.dtEnd; + column_desc->datetimefractprec = ci.scale; - column_desc.intervalleadingprec = ci.precision; - column_desc.defaultClass = ci.defaultClass; - column_desc.colFlags = ci.colFlags; + column_desc->intervalleadingprec = ci.precision; + column_desc->setDefaultClass(ci.defaultClass); + column_desc->colFlags = ci.colFlags; NAType *type; - NAColumn::createNAType(&column_desc, NULL, type, STMTHEAP); + NAColumn::createNAType(column_desc, NULL, type, STMTHEAP); NAColumn * nac = new(STMTHEAP) NAColumn(ci.colName, i, type, STMTHEAP); naColArray->insert(nac); @@ -5302,13 +5309,79 @@ short CmpSeabaseDDL::deleteConstraintInfoFromSeabaseMDTables( return 0; } +short CmpSeabaseDDL::checkAndGetStoredObjectDesc( + ExeCliInterface *cliInterface, + Int64 objUID, + TrafDesc* *retDesc) +{ + Lng32 cliRC = 0; + + NAString packedDesc; + cliRC = getTextFromMD( + cliInterface, objUID, COM_STORED_DESC_TEXT, 0, packedDesc); + if (cliRC < 0) + { + *CmpCommon::diags() << DgSqlCode(-4493) + << DgString0("Error reading from metadata."); + + processReturn(); + return -1; + } + + if (packedDesc.length() == 0) + { + // stored desc doesn't exist + *CmpCommon::diags() << DgSqlCode(-4493) + << DgString0("Does not exist. It needs to be regenerated."); + + processReturn(); + return -2; + } + + char * descBuf = new(STMTHEAP) char[packedDesc.length()]; + str_cpy_all(descBuf, packedDesc.data(), packedDesc.length()); + + TrafDesc * desc = (TrafDesc*)descBuf; + TrafDesc dummyDesc; + desc = (TrafDesc*)desc->driveUnpack((void*)desc, &dummyDesc, NULL); + + if (! desc) + { + NADELETEBASIC(descBuf, STMTHEAP); + + // error during unpack. Desc need to be regenerated. + *CmpCommon::diags() << DgSqlCode(-4493) + << DgString0("Error during unpacking due to change in stored structures. It needs to be regenerated."); + + processReturn(); + return -3; + } + + // all good + *CmpCommon::diags() << DgSqlCode(4493) + << DgString0("Uptodate and current."); + + if (retDesc) + *retDesc = desc; + else + NADELETEBASIC(descBuf, STMTHEAP); + + return 0; +} + +// rt = -1, generate redef time. rt = -2, dont update redef time. +// otherwise use provided redef time. +// +// Also generate and update object descriptor in metadata. short CmpSeabaseDDL::updateObjectRedefTime( ExeCliInterface *cliInterface, const NAString &catName, const NAString &schName, const NAString &objName, const char * objType, - Int64 rt) + Int64 rt, + Int64 objUID, + NABoolean force) { Lng32 retcode = 0; Lng32 cliRC = 0; @@ -5322,11 +5395,66 @@ short CmpSeabaseDDL::updateObjectRedefTime( NAString quotedObjName; ToQuotedString(quotedObjName, NAString(objName), FALSE); - str_sprintf(buf, "update %s.\"%s\".%s set redef_time = %Ld where catalog_name = '%s' and schema_name = '%s' and object_name = '%s' and object_type = '%s' ", - getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, - redefTime, - catName.data(), quotedSchName.data(), quotedObjName.data(), - objType); + Int64 flags = 0; + if (((CmpCommon::getDefault(TRAF_STORE_OBJECT_DESC) == DF_ON) || + (force)) && + (objUID > 0) && + (NOT isSeabaseReservedSchema(catName, schName)) && + ((strcmp(objType, COM_BASE_TABLE_OBJECT_LIT) == 0) || + (strcmp(objType, COM_VIEW_OBJECT_LIT) == 0))) + { + Int32 ctlFlags = GEN_PACKED_DESC | GET_SNAPSHOTS; + Int32 packedDescLen = 0; + TrafDesc * ds = + getSeabaseUserTableDesc(catName, schName, objName, + (strcmp(objType, COM_BASE_TABLE_OBJECT_LIT) == 0 + ? COM_BASE_TABLE_OBJECT : COM_VIEW_OBJECT), + FALSE, ctlFlags, packedDescLen); + if (! ds) + { + processReturn(); + return -1; + } + + cliRC = updateTextTableWithBinaryData + (cliInterface, objUID, + COM_STORED_DESC_TEXT, 0, + (char*)ds, packedDescLen, + TRUE /*delete existing data*/); + if (cliRC < 0) + { + processReturn(); + return -1; + } + + CmpSeabaseDDL::setMDflags(flags, MD_OBJECTS_STORED_DESC); + } + + if ((flags & MD_OBJECTS_STORED_DESC) != 0) + { + if (rt == -2) + str_sprintf(buf, "update %s.\"%s\".%s set flags = bitor(flags, %Ld) where catalog_name = '%s' and schema_name = '%s' and object_name = '%s' and object_type = '%s' ", + getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, + flags, + catName.data(), quotedSchName.data(), quotedObjName.data(), + objType); + else + str_sprintf(buf, "update %s.\"%s\".%s set redef_time = %Ld, flags = bitor(flags, %Ld) where catalog_name = '%s' and schema_name = '%s' and object_name = '%s' and object_type = '%s' ", + getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, + redefTime, + flags, + catName.data(), quotedSchName.data(), quotedObjName.data(), + objType); + } + else + { + str_sprintf(buf, "update %s.\"%s\".%s set redef_time = %Ld where catalog_name = '%s' and schema_name = '%s' and object_name = '%s' and object_type = '%s' ", + getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, + redefTime, + catName.data(), quotedSchName.data(), quotedObjName.data(), + objType); + } + cliRC = cliInterface->executeImmediate(buf); if (cliRC < 0) @@ -5334,7 +5462,7 @@ short CmpSeabaseDDL::updateObjectRedefTime( cliInterface->retrieveSQLDiagnostics(CmpCommon::diags()); return -1; } - + return 0; } @@ -5436,6 +5564,40 @@ short CmpSeabaseDDL::updateObjectAuditAttr( return 0; } +short CmpSeabaseDDL::updateObjectFlags( + ExeCliInterface *cliInterface, + const Int64 objUID, + const Int64 inFlags, + NABoolean reset) +{ + Lng32 retcode = 0; + Lng32 cliRC = 0; + + char buf[4000]; + + Int64 flags = inFlags; + if (reset) + flags = ~inFlags; + + if (reset) + str_sprintf(buf, "update %s.\"%s\".%s set flags = bitand(flags, %Ld) where object_uid = %Ld", + getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, + flags, objUID); + else + str_sprintf(buf, "update %s.\"%s\".%s set flags = bitor(flags, %Ld) where object_uid = %Ld", + getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, + flags, objUID); + cliRC = cliInterface->executeImmediate(buf); + if (cliRC < 0) + { + cliInterface->retrieveSQLDiagnostics(CmpCommon::diags()); + + return -1; + } + + return 0; +} + void CmpSeabaseDDL::cleanupObjectAfterError( ExeCliInterface &cliInterface, const NAString &catName, @@ -6019,6 +6181,93 @@ short CmpSeabaseDDL::updateTextTable(ExeCliInterface *cliInterface, return 0; } +short CmpSeabaseDDL::updateTextTableWithBinaryData +(ExeCliInterface *cliInterface, + Int64 objUID, + ComTextType textType, + Lng32 subID, + char * inputData, + Int32 inputDataLen, + 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; + } + } + + // convert input data to utf8 first. + ComDiagsArea * diagsArea = CmpCommon::diags(); + char * inputDataUTF8 = new(STMTHEAP) char[inputDataLen*4]; + Lng32 inputDataLenUTF8 = 0; + ex_expr::exp_return_type rc = + convDoIt(inputData, + inputDataLen, + REC_BYTE_F_ASCII, + 0, + (Int32)CharInfo::ISO88591, + inputDataUTF8, + inputDataLen*4, + REC_BYTE_V_ASCII, + inputDataLen, + (Int32)CharInfo::UTF8, + (char*)&inputDataLenUTF8, + sizeof(Lng32), + STMTHEAP, + &diagsArea, + CONV_ASCII_F_V); + if ((rc != ex_expr::EXPR_OK) || + (inputDataLenUTF8 <= 0)) + { + return -1; + } + + Int32 maxLen = TEXTLEN; + char queryBuf[1000]; + Lng32 numRows = (inputDataLenUTF8 / maxLen) + 1; + Lng32 currPos = 0; + Int32 currDataLen = 0; + + for (Lng32 i = 0; i < numRows; i++) + { + NAString temp; + + if (i < numRows-1) + currDataLen = maxLen; + else + currDataLen = inputDataLenUTF8 - currPos; + + str_sprintf(queryBuf, "insert into %s.\"%s\".%s values (%Ld, %d, %d, %d, 0, cast(? as char(%d bytes) character set utf8 not null))", + getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_TEXT, + objUID, + textType, + subID, + i, + currDataLen); + cliRC = cliInterface->executeImmediateCEFC + (queryBuf, &inputData[currPos], currDataLen, NULL, NULL, NULL); + + if (cliRC < 0) + { + cliInterface->retrieveSQLDiagnostics(CmpCommon::diags()); + return -1; + } + + currPos += maxLen; + } + + return 0; +} + short CmpSeabaseDDL::deleteFromTextTable(ExeCliInterface *cliInterface, Int64 objUID, ComTextType textType, @@ -6457,8 +6706,8 @@ short CmpSeabaseDDL::validateDivisionByExprForDDL(ItemExpr *divExpr) short CmpSeabaseDDL::createEncodedKeysBuffer(char** &encodedKeysBuffer, int &numSplits, - desc_struct * colDescs, - desc_struct * keyDescs, + TrafDesc * colDescs, + TrafDesc * keyDescs, int numSaltPartitions, Lng32 numSaltSplits, NAString *splitByClause, @@ -8209,9 +8458,9 @@ short CmpSeabaseDDL::truncateHbaseTable(const NAString &catalogNamePart, Lng32 keyLength = naf->getKeyLength(); char ** encodedKeysBuffer = NULL; - const desc_struct * tableDesc = naTable->getTableDesc(); - desc_struct * colDescs = tableDesc->body.table_desc.columns_desc; - desc_struct * keyDescs = (desc_struct*)naf->getKeysDesc(); + TrafDesc * tableDesc = (TrafDesc*)naTable->getTableDesc(); + TrafDesc * colDescs = tableDesc->tableDesc()->columns_desc; + TrafDesc * keyDescs = (TrafDesc*)naf->getKeysDesc(); if (createEncodedKeysBuffer(encodedKeysBuffer/*out*/, numSplits/*out*/, @@ -8857,6 +9106,13 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode, renameSeabaseTable(alterRenameTable, currCatName, currSchName); } + else if (ddlNode->getOperatorType() == DDL_ALTER_TABLE_STORED_DESC) + { + StmtDDLAlterTableStoredDesc * alterStoredDesc = + ddlNode->castToStmtDDLNode()->castToStmtDDLAlterTableStoredDesc(); + + alterSeabaseTableStoredDesc(alterStoredDesc, currCatName, currSchName); + } else if (ddlNode->getOperatorType() == DDL_ALTER_TABLE_ALTER_HBASE_OPTIONS) { StmtDDLAlterTableHBaseOptions * athbo = @@ -9001,6 +9257,13 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, ExprNode * ddlNode, dropSeabaseSchema(dropSchemaParseNode); } + else if (ddlNode->getOperatorType() == DDL_ALTER_SCHEMA) + { + StmtDDLAlterSchema * alterSchemaParseNode = + ddlNode->castToStmtDDLNode()->castToStmtDDLAlterSchema(); + + alterSeabaseSchema(alterSchemaParseNode); + } else if (ddlNode->getOperatorType() == DDL_CREATE_LIBRARY) { // create seabase library http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/19c96b1e/core/sql/sqlcomp/CmpSeabaseDDLincludes.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLincludes.h b/core/sql/sqlcomp/CmpSeabaseDDLincludes.h index 80fed40..2743bdd 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLincludes.h +++ b/core/sql/sqlcomp/CmpSeabaseDDLincludes.h @@ -40,6 +40,7 @@ #include "StmtDDLCreateTable.h" #include "StmtDDLDropTable.h" #include "StmtDDLAlterTableRename.h" +#include "StmtDDLAlterTableStoredDesc.h" #include "StmtDDLCreateIndex.h" #include "StmtDDLPopulateIndex.h" #include "StmtDDLDropIndex.h" @@ -86,7 +87,6 @@ #include "ExExeUtilCli.h" #include "Generator.h" -#include "desc.h" #include "ComCextdecs.h" http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/19c96b1e/core/sql/sqlcomp/CmpSeabaseDDLindex.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLindex.cpp b/core/sql/sqlcomp/CmpSeabaseDDLindex.cpp index 718934a..9234c66 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLindex.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLindex.cpp @@ -58,7 +58,6 @@ #include "ExExeUtilCli.h" #include "Generator.h" -#include "desc.h" #include "ComCextdecs.h" #include "ComUser.h" @@ -556,6 +555,8 @@ void CmpSeabaseDDL::createSeabaseIndex( StmtDDLCreateIndex * createIndexNode, return; } + Int64 btObjUID = naTable->objectUid().castToInt64(); + NAString &indexColFam = naTable->defaultColFam(); NAString trafColFam; if (indexColFam != SEABASE_DEFAULT_COL_FAMILY) @@ -859,11 +860,11 @@ void CmpSeabaseDDL::createSeabaseIndex( StmtDDLCreateIndex * createIndexNode, char ** encodedKeysBuffer = NULL; if (numSplits > 0) { - desc_struct * colDescs = + TrafDesc * colDescs = convertVirtTableColumnInfoArrayToDescStructs(&tableName, colInfoArray, totalColCount) ; - desc_struct * keyDescs = + TrafDesc * keyDescs = convertVirtTableKeyInfoArrayToDescStructs(keyInfoArray, colInfoArray, keyColCount) ; @@ -1027,7 +1028,7 @@ void CmpSeabaseDDL::createSeabaseIndex( StmtDDLCreateIndex * createIndexNode, if (updateObjectRedefTime(&cliInterface, btCatalogNamePart, btSchemaNamePart, btObjectNamePart, - COM_BASE_TABLE_OBJECT_LIT)) + COM_BASE_TABLE_OBJECT_LIT, -1, btObjUID)) { goto label_error_drop_index; } @@ -1244,7 +1245,7 @@ void CmpSeabaseDDL::populateSeabaseIndex( // Create a table descriptor that contains information on both valid and // invalid indexes. Pass that to getNATable method which will use this // table desc to create the NATable struct. - desc_struct * tableDesc = + TrafDesc * tableDesc = getSeabaseTableDesc( tableName.getCatalogNamePart().getInternalName(), tableName.getSchemaNamePart().getInternalName(), @@ -1698,7 +1699,7 @@ void CmpSeabaseDDL::dropSeabaseIndex( if (updateObjectRedefTime(&cliInterface, btCatName, btSchName, btObjName, - COM_BASE_TABLE_OBJECT_LIT)) + COM_BASE_TABLE_OBJECT_LIT, -1, btUID)) { processReturn(); @@ -1819,10 +1820,10 @@ void CmpSeabaseDDL::alterSeabaseTableDisableOrEnableIndex( Int32 btObjOwner = 0; Int32 btSchemaOwner = 0; Int64 btObjectFlags = 0; - if ((getObjectInfo(&cliInterface, - btCatName, btSchName, btObjName, - COM_BASE_TABLE_OBJECT, - btObjOwner, btSchemaOwner, btObjectFlags)) < 0) + if ((btUID = getObjectInfo(&cliInterface, + btCatName, btSchName, btObjName, + COM_BASE_TABLE_OBJECT, + btObjOwner, btSchemaOwner, btObjectFlags, btUID)) < 0) { processReturn(); @@ -1850,6 +1851,15 @@ void CmpSeabaseDDL::alterSeabaseTableDisableOrEnableIndex( return; } + if (updateObjectRedefTime(&cliInterface, + btCatName, btSchName, btObjName, + COM_BASE_TABLE_OBJECT_LIT, -1, btUID)) + { + processReturn(); + + return; + } + // remove NATable for the base table of this index CorrName cn(btObjName, STMTHEAP, btSchName, btCatName); ActiveSchemaDB()->getNATableDB()->removeNATable @@ -2148,6 +2158,16 @@ void CmpSeabaseDDL::alterSeabaseIndexHBaseOptions( return; } + if (updateObjectRedefTime(&cliInterface, + btCatName, btSchName, btObjName, + COM_BASE_TABLE_OBJECT_LIT, -1, btUID)) + { + deallocEHI(ehi); + processReturn(); + + return; + } + // invalidate cached NATable info on this table for all users ActiveSchemaDB()->getNATableDB()->removeNATable http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/19c96b1e/core/sql/sqlcomp/CmpSeabaseDDLmd.h ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLmd.h b/core/sql/sqlcomp/CmpSeabaseDDLmd.h index 83d72c5..e9d6a6f 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLmd.h +++ b/core/sql/sqlcomp/CmpSeabaseDDLmd.h @@ -245,10 +245,15 @@ enum SeabaseObjectsFlags { SEABASE_OBJECT_IS_EXTERNAL_HIVE = 0x0000000000000001, // set if this object // references external // HIVE table - SEABASE_OBJECT_IS_EXTERNAL_HBASE = 0x0000000000000002 // set if this object + SEABASE_OBJECT_IS_EXTERNAL_HBASE = 0x0000000000000002, // set if this object // references external // HBASE table + + // descriptor was generated for this table and is stored in TEXT table + MD_OBJECTS_STORED_DESC = 0x0000000000000004, + // stored descriptor is disabled, should not be used + MD_OBJECTS_DISABLE_STORED_DESC = 0x0000000000000008 }; static const QString seabaseRefConstraintsDDL[] = http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/19c96b1e/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp b/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp index e2f891f..d6996a6 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp @@ -60,7 +60,6 @@ #include "ExExeUtilCli.h" #include "Generator.h" -#include "desc.h" #include "ComSmallDefs.h" #include "CmpDDLCatErrorCodes.h" http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/19c96b1e/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp index 03a700e..b914961 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp @@ -39,6 +39,7 @@ #include "CmpSeabaseDDLincludes.h" #include "StmtDDLCreateSchema.h" #include "StmtDDLDropSchema.h" +#include "StmtDDLAlterSchema.h" #include "StmtDDLGive.h" #include "ElemDDLColDefault.h" #include "NumericType.h" @@ -971,6 +972,251 @@ label_error: // ***************************************************************************** // * * +// * Function: CmpSeabaseDDL::alterSeabaseSchema * +// * * +// * Implements the ALTER SCHEMA command. * +// * * +// ***************************************************************************** +// * * +// * Parameters: * +// * * +// * <alterSchemaNode> StmtDDLAlterSchema * In * +// * is a pointer to a create schema parser node. * +// * * +// ***************************************************************************** +void CmpSeabaseDDL::alterSeabaseSchema(StmtDDLAlterSchema * alterSchemaNode) + +{ + Lng32 cliRC = 0; + + ComSchemaName schemaName(alterSchemaNode->getSchemaName()); + NAString catName = schemaName.getCatalogNamePartAsAnsiString(); + ComAnsiNamePart schNameAsComAnsi = schemaName.getSchemaNamePart(); + NAString schName = schNameAsComAnsi.getInternalName(); + ComObjectName objName(catName,schName,NAString("dummy"),COM_TABLE_NAME,TRUE); + + ExeCliInterface cliInterface(STMTHEAP, NULL, NULL, + CmpCommon::context()->sqlSession()->getParentQid()); + Int32 objectOwnerID = 0; + Int32 schemaOwnerID = 0; + ComObjectType objectType; + + bool isVolatile = (memcmp(schName.data(),"VOLATILE_SCHEMA",strlen("VOLATILE_SCHEMA")) == 0); + int32_t length = 0; + int32_t rowCount = 0; + bool someObjectsCouldNotBeAltered = false; + char errorObjs[1010]; + Queue * objectsQueue = NULL; + Queue * otherObjectsQueue = NULL; + + NABoolean dirtiedMetadata = FALSE; + Int32 checkErr = 0; + + StmtDDLAlterTableStoredDesc::AlterStoredDescType sdo = + alterSchemaNode->getStoredDescOperation(); + + errorObjs[0] = 0; + + Int64 schemaUID = getObjectTypeandOwner(&cliInterface,catName.data(),schName.data(), + SEABASE_SCHEMA_OBJECTNAME,objectType,schemaOwnerID); + + // if schemaUID == -1, then either the schema does not exist or an unexpected error occurred + if (schemaUID == -1) + { + // If an error occurred, return + if (CmpCommon::diags()->getNumber(DgSqlCode::ERROR_) > 0) + goto label_error; + + // A Trafodion schema does not exist if the schema object row is not + // present: CATALOG-NAME.SCHEMA-NAME.__SCHEMA__. + *CmpCommon::diags() << DgSqlCode(-CAT_SCHEMA_DOES_NOT_EXIST_ERROR) + << DgSchemaName(schemaName.getExternalName().data()); + goto label_error; + } + + if (!isDDLOperationAuthorized(SQLOperation::DROP_SCHEMA, + schemaOwnerID,schemaOwnerID)) + { + *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED); + goto label_error; + } + + if ((isSeabaseReservedSchema(objName) || + (schName == SEABASE_SYSTEM_SCHEMA)) && + !Get_SqlParser_Flags(INTERNAL_QUERY_FROM_EXEUTIL)) + { + *CmpCommon::diags() << DgSqlCode(-CAT_USER_CANNOT_DROP_SMD_SCHEMA) + << DgSchemaName(schemaName.getExternalName().data()); + goto label_error; + } + + // Can't alter a schema whose name begins with VOLATILE_SCHEMA unless the + // keyword VOLATILE was specified in the ALTER SCHEMA command. + if (isVolatile && !alterSchemaNode->isVolatile()) + { + *CmpCommon::diags() << DgSqlCode(-CAT_RESERVED_METADATA_SCHEMA_NAME) + << DgTableName(schName); + goto label_error; + } + + if (alterSchemaNode->isDropAllTables()) + { + // should not reach here, is transformed to DropSchema during parsing + *CmpCommon::diags() << DgSqlCode(-3242) + << DgString0("Should not reach here. Should have been transformed to DropSchema during parsing."); + goto label_error; + } + + if (alterSchemaNode->isRenameSchema()) + { + // Not yet supported + *CmpCommon::diags() << DgSqlCode(-3242) + << DgString0("Cannot rename a schema."); + goto label_error; + } + + if (NOT alterSchemaNode->isAlterStoredDesc()) + { + // unsupported option + *CmpCommon::diags() << DgSqlCode(-3242) + << DgString0("Unsupported option specified."); + goto label_error; + } + + // Get a list of all objects in the schema, excluding the schema object itself. + char query[4000]; + + // select objects in the schema to alter + str_sprintf(query,"SELECT distinct TRIM(object_name), TRIM(object_type), object_uid " + "FROM %s.\"%s\".%s " + "WHERE catalog_name = '%s' AND schema_name = '%s' AND " + "object_name <> '"SEABASE_SCHEMA_OBJECTNAME"' AND " + "(object_type = 'BT' OR " + " object_type = 'VI') " + "FOR READ COMMITTED ACCESS", + getSystemCatalog(),SEABASE_MD_SCHEMA,SEABASE_OBJECTS, + (char*)catName.data(),(char*)schName.data()); + + cliRC = cliInterface.fetchAllRows(objectsQueue, query, 0, FALSE, FALSE, TRUE); + if (cliRC < 0) + { + cliInterface.retrieveSQLDiagnostics(CmpCommon::diags()); + goto label_error; + } + + objectsQueue->position(); + for (int idx = 0; idx < objectsQueue->numEntries(); idx++) + { + OutputInfo * vi = (OutputInfo*)objectsQueue->getNext(); + + NAString objName = vi->get(0); + NAString objType = vi->get(1); + Int64 objUID = *(Int64*)vi->get(2); + + if (sdo == StmtDDLAlterTableStoredDesc::GENERATE) + { + cliRC = + updateObjectRedefTime(&cliInterface, + getSystemCatalog(), schName, objName, + COM_BASE_TABLE_OBJECT_LIT, + -1, objUID, TRUE); + if (cliRC < 0) + { + // append error and move on to next one + appendErrorObjName(errorObjs, objName); + someObjectsCouldNotBeAltered = true; + + CmpCommon::diags()->clear(); + } + } + else if (sdo == StmtDDLAlterTableStoredDesc::DELETE) + { + cliRC = deleteFromTextTable + (&cliInterface, objUID, COM_STORED_DESC_TEXT, 0); + if (cliRC < 0) + { + // append error and move on to next one + appendErrorObjName(errorObjs, objName); + someObjectsCouldNotBeAltered = true; + + CmpCommon::diags()->clear(); + } + + } // delete stored desc + else if (sdo == StmtDDLAlterTableStoredDesc::ENABLE) + { + Int64 flags = MD_OBJECTS_DISABLE_STORED_DESC; + cliRC = updateObjectFlags(&cliInterface, objUID, flags, TRUE); + if (cliRC < 0) + { + appendErrorObjName(errorObjs, objName); + someObjectsCouldNotBeAltered = true; + + CmpCommon::diags()->clear(); + } + } + else if (sdo == StmtDDLAlterTableStoredDesc::DISABLE) + { + Int64 flags = MD_OBJECTS_DISABLE_STORED_DESC; + cliRC = updateObjectFlags(&cliInterface, objUID, flags, FALSE); + if (cliRC < 0) + { + appendErrorObjName(errorObjs, objName); + someObjectsCouldNotBeAltered = true; + + CmpCommon::diags()->clear(); + } + } + else if (sdo == StmtDDLAlterTableStoredDesc::CHECK) + { + cliRC = checkAndGetStoredObjectDesc(&cliInterface, objUID, NULL); + CmpCommon::diags()->clear(); + if (cliRC < 0) + { + checkErr = cliRC; + appendErrorObjName(errorObjs, objName); + someObjectsCouldNotBeAltered = true; + } + } + + } // for + + if (someObjectsCouldNotBeAltered) + { + NAString reason; + if (sdo == StmtDDLAlterTableStoredDesc::CHECK) + { + reason = "Reason: Following objects failed stored descriptor check"; + if (checkErr == -1) + reason += " (object could not be accessed) "; + else if (checkErr == -2) + reason += " (object does not exist) "; + else if (checkErr == -3) + reason += " (change in stored structures) "; + reason += ": "; + reason += errorObjs; + } + else + reason = "Reason: Some objects could not be accessed in schema " + + schName + ". ObjectsInSchema: " + + errorObjs; + *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_ALTER_SCHEMA) + << DgSchemaName(catName + "." + schName) + << DgString0(reason); + goto label_error; + } + + // Everything succeeded, return + return; + +label_error: + return; +} +//****************** End of CmpSeabaseDDL::alterSeabaseSchema ***************** + + +// ***************************************************************************** +// * * // * Function: CmpSeabaseDDL::giveSeabaseSchema * // * * // * Implements the GIVE SCHEMA command. *