From 04123ad4168fbd7305caf37d5c8f02deb6eafa07 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Tue, 24 Apr 2018 21:28:26 +0000 Subject: [PATCH 1/5] AFODION-2953] initial implementation --- core/sql/regress/seabase/EXPECTED035 | 128 +++++++++++++++++++++++++++ core/sql/regress/seabase/TEST035 | 54 +++++++++++ 2 files changed, 182 insertions(+) create mode 100644 core/sql/regress/seabase/EXPECTED035 create mode 100644 core/sql/regress/seabase/TEST035 diff --git a/core/sql/regress/seabase/EXPECTED035 b/core/sql/regress/seabase/EXPECTED035 new file mode 100644 index 0000000000..a200939b5c --- /dev/null +++ b/core/sql/regress/seabase/EXPECTED035 @@ -0,0 +1,128 @@ +>> +>>drop table if exists t035t1 cascade; + +--- SQL operation complete. +>>drop table if exists t035t2 cascade; + +--- SQL operation complete. +>> +>>create table t035t1 (a int, b int, c int, d int not null) attribute super table system; + +--- SQL operation complete. +>>create table t035t2 (a int, b int, c int, d int not null) attribute super table system; + +--- SQL operation complete. +>>insert into t035t1 values (1,2,3,4),(2,3,4,5),(3,3,3,3),(3,3,4,5),(1,3,3,3), ++> (6,6,6,6); + +--- 6 row(s) inserted. +>>insert into t035t2 values (1,2,3,4),(2,3,4,5),(3,3,3,3),(3,3,4,5),(1,3,3,3), ++> (6,6,null,6); + +--- 6 row(s) inserted. +>> +>> +>>select * from t035t1 order by 1,2,3,4; + +A B C D +----------- ----------- ----------- ----------- + + 1 2 3 4 + 1 3 3 3 + 2 3 4 5 + 3 3 3 3 + 3 3 4 5 + 6 6 6 6 + +--- 6 row(s) selected. +>>select * from t035t1 where b = 2; + +A B C D +----------- ----------- ----------- ----------- + + 1 2 3 4 + +--- 1 row(s) selected. +>>update t035t1 set c = 3 ; + +--- 6 row(s) updated. +>>update t035t1 set c = 0 where b =3; + +--- 4 row(s) updated. +>>select * from t035t1; + +A B C D +----------- ----------- ----------- ----------- + + 1 2 3 4 + 2 3 0 5 + 3 3 0 3 + 3 3 0 5 + 1 3 0 3 + 6 6 3 6 + +--- 6 row(s) selected. +>>select * from t035t2; + +A B C D +----------- ----------- ----------- ----------- + + 1 2 3 4 + 2 3 4 5 + 3 3 3 3 + 3 3 4 5 + 1 3 3 3 + 6 6 ? 6 + +--- 6 row(s) selected. +>>delete from t035t1 where a > 2; + +--- 3 row(s) deleted. +>>select * from t035t1; + +A B C D +----------- ----------- ----------- ----------- + + 1 2 3 4 + 2 3 0 5 + 1 3 0 3 + +--- 3 row(s) selected. +>>select * from t035t2; + +A B C D +----------- ----------- ----------- ----------- + + 1 2 3 4 + 2 3 4 5 + 3 3 3 3 + 3 3 4 5 + 1 3 3 3 + 6 6 ? 6 + +--- 6 row(s) selected. +>>delete from t035t2; + +--- 6 row(s) deleted. +>>select * from t035t2; + +--- 0 row(s) selected. +>>select * from t035t1; + +A B C D +----------- ----------- ----------- ----------- + + 1 2 3 4 + 2 3 0 5 + 1 3 0 3 + +--- 3 row(s) selected. +>> +>>drop table t035t1; + +--- SQL operation complete. +>>drop table t035t2; + +--- SQL operation complete. +>> +>>log; diff --git a/core/sql/regress/seabase/TEST035 b/core/sql/regress/seabase/TEST035 new file mode 100644 index 0000000000..c71669b5af --- /dev/null +++ b/core/sql/regress/seabase/TEST035 @@ -0,0 +1,54 @@ +-- @@@ 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 @@@ +-- + +-- Tests for Small Table Feature + +log LOG035 clear; + +drop table if exists t035t1 cascade; +drop table if exists t035t2 cascade; + +create table t035t1 (a int, b int, c int, d int not null) attribute super table system; +create table t035t2 (a int, b int, c int, d int not null) attribute super table system; +insert into t035t1 values (1,2,3,4),(2,3,4,5),(3,3,3,3),(3,3,4,5),(1,3,3,3), + (6,6,6,6); +insert into t035t2 values (1,2,3,4),(2,3,4,5),(3,3,3,3),(3,3,4,5),(1,3,3,3), + (6,6,null,6); + + +select * from t035t1 order by 1,2,3,4; +select * from t035t1 where b = 2; +update t035t1 set c = 3 ; +update t035t1 set c = 0 where b =3; +select * from t035t1; +select * from t035t2; +delete from t035t1 where a > 2; +select * from t035t1; +select * from t035t2; +delete from t035t2; +select * from t035t2; +select * from t035t1; + +drop table t035t1; +drop table t035t2; + +log; From c195c6fe23a214cad3b8db3359c19b282ac7a5c1 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Tue, 24 Apr 2018 22:14:22 +0000 Subject: [PATCH 2/5] [TRAFODION-2953] first code drop for small table in one HBase Region --- core/sql/comexe/ComTdb.h | 1 + core/sql/common/ComSmallDefs.h | 3 +- core/sql/common/OperTypeEnum.h | 3 +- core/sql/generator/GenPreCode.cpp | 34 +++++- core/sql/generator/GenRelScan.cpp | 24 +++- core/sql/generator/GenRelUpdate.cpp | 32 +++-- core/sql/generator/Generator.cpp | 9 ++ core/sql/optimizer/BindRI.cpp | 2 + core/sql/optimizer/BindRelExpr.cpp | 47 +++++++ core/sql/optimizer/NATable.cpp | 12 ++ core/sql/optimizer/NATable.h | 25 +++- core/sql/optimizer/PartFunc.cpp | 91 ++++++++++++++ core/sql/optimizer/PartFunc.h | 7 ++ core/sql/parser/ElemDDLFileAttr.h | 42 +++++++ core/sql/parser/ElemDDLNode.cpp | 6 + core/sql/parser/ElemDDLNode.h | 2 + core/sql/parser/ParDDLFileAttrs.cpp | 11 +- core/sql/parser/ParDDLFileAttrsCreateTable.h | 19 +++ core/sql/parser/ParKeyWords.cpp | 1 + core/sql/parser/StmtDDLDrop.cpp | 2 + core/sql/parser/StmtDDLDropTable.h | 6 + core/sql/parser/sqlparser.y | 18 +++ core/sql/regress/tools/sbdefs | 2 +- core/sql/sqlcat/TrafDDLdesc.h | 18 ++- core/sql/sqlcomp/CmpSeabaseDDL.h | 7 ++ core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 122 ++++++++++++++++++- core/sql/sqlcomp/CmpSeabaseDDLmd.h | 6 +- core/sql/sqlcomp/CmpSeabaseDDLtable.cpp | 61 +++++++++- 28 files changed, 583 insertions(+), 30 deletions(-) diff --git a/core/sql/comexe/ComTdb.h b/core/sql/comexe/ComTdb.h index 1b90b907d8..4d899faa10 100644 --- a/core/sql/comexe/ComTdb.h +++ b/core/sql/comexe/ComTdb.h @@ -821,6 +821,7 @@ class ComTdbVirtTableTableInfo : public ComTdbVirtTableBase const char * allColFams; Int64 objectFlags; // flags from OBJECTS table Int64 tablesFlags; // flags from TABLES table + const char * superTable; }; class ComTdbVirtTableColumnInfo : public ComTdbVirtTableBase diff --git a/core/sql/common/ComSmallDefs.h b/core/sql/common/ComSmallDefs.h index db99f2824a..2b22ebf4a0 100644 --- a/core/sql/common/ComSmallDefs.h +++ b/core/sql/common/ComSmallDefs.h @@ -685,7 +685,8 @@ enum ComTextType {COM_VIEW_TEXT = 0, COM_STORED_DESC_TEXT = 7, COM_VIEW_REF_COLS_TEXT = 8, COM_OBJECT_COMMENT_TEXT = COM_TABLE_COMMENT_TEXT, - COM_COLUMN_COMMENT_TEXT = 12 + COM_COLUMN_COMMENT_TEXT = 12 , + COM_SUPER_TABLE_TEXT = 13 }; enum ComColumnDirection { COM_UNKNOWN_DIRECTION diff --git a/core/sql/common/OperTypeEnum.h b/core/sql/common/OperTypeEnum.h index 404c704157..065d6dfcd9 100644 --- a/core/sql/common/OperTypeEnum.h +++ b/core/sql/common/OperTypeEnum.h @@ -1244,7 +1244,8 @@ enum OperatorTypeEnum { // Unpublished attributes ELM_FILE_ATTR_EXTENT_ELEM, ELM_FILE_ATTR_MAXEXTENTS_ELEM, - ELM_FILE_ATTR_UID_ELEM + ELM_FILE_ATTR_UID_ELEM, + ELM_FILE_ATTR_SUPER_TABLE_ELEM }; #endif // OPERTYPEENUM_H diff --git a/core/sql/generator/GenPreCode.cpp b/core/sql/generator/GenPreCode.cpp index 9832c446c4..503eba763f 100644 --- a/core/sql/generator/GenPreCode.cpp +++ b/core/sql/generator/GenPreCode.cpp @@ -3777,6 +3777,8 @@ RelExpr * FileScan::preCodeGen(Generator * generator, myPartFunc->isPartitioned() && !myPartFunc->isAReplicationPartitioningFunction()); + NABoolean isSmallTable = getTableDesc()->getNATable()->isSmallTable(); + if (isRewrittenMV()) generator->setNonCacheableMVQRplan(TRUE); @@ -3816,6 +3818,31 @@ RelExpr * FileScan::preCodeGen(Generator * generator, VEGRewritePairs vegPairs(generator->wHeap()); ValueIdSet partKeyPredsHBase; + if (isSmallTable) + { + ValueId saltCol; + const ValueIdList &keyCols = getIndexDesc()->getIndexKey(); + + for (CollIndex i=0; icreateSmallTableKeyPredicates(getTableDesc()->getNATable()->getTableName().getQualifiedNameAsString().data(), saltCol.getItemExpr()); + } + partKeyPredsHBase = myPartFunc->getPartitioningKeyPredicates(); + } + + if (usePartKeyPreds) { // add the partitioning key predicates to this scan node, @@ -3844,7 +3871,7 @@ RelExpr * FileScan::preCodeGen(Generator * generator, createPartitioningKeyPredicatesForSaltedTable(saltCol); } - partKeyPredsHBase = myPartFunc->getPartitioningKeyPredicates(); + partKeyPredsHBase += myPartFunc->getPartitioningKeyPredicates(); } if (getMdamKeyPtr() != NULL) @@ -3918,7 +3945,10 @@ RelExpr * FileScan::preCodeGen(Generator * generator, if (getSearchKey()) existingKeyPreds += getSearchKey()->getKeyPredicates(); - + + if (isSmallTable) + existingKeyPreds += myPartFunc->getPartitioningKeyPredicates(); + // create a new search key that has the partitioning key preds SearchKey * partKeySearchKey = myPartFunc->createSearchKey(getIndexDesc(), diff --git a/core/sql/generator/GenRelScan.cpp b/core/sql/generator/GenRelScan.cpp index 827b94c5c2..7a6e5a0ecf 100644 --- a/core/sql/generator/GenRelScan.cpp +++ b/core/sql/generator/GenRelScan.cpp @@ -2438,6 +2438,7 @@ short HbaseAccess::codeGen(Generator * generator) NABoolean isAlignedFormat = getTableDesc()->getNATable()->isAlignedFormat(getIndexDesc()); NABoolean isHbaseMapFormat = getTableDesc()->getNATable()->isHbaseMapTable(); + NABoolean isSmallTable = getTableDesc()->getNATable()->isSmallTable(); // If CIF is not OFF use aligned format, except when table is // not aligned and it has added columns. Support for added columns @@ -2481,7 +2482,14 @@ short HbaseAccess::codeGen(Generator * generator) { if (getIndexDesc() && getIndexDesc()->getNAFileSet()) { - tablename = space->AllocateAndCopyToAlignedSpace(GenGetQualifiedName(getIndexDesc()->getNAFileSet()->getFileSetName()), 0); + if(getTableDesc()->getNATable()->isSmallTable()) + { + NAString st(""); + st = getTableDesc()->getNATable()->superTable() ; + tablename = space->AllocateAndCopyToAlignedSpace(st, 0); + } + else + tablename = space->AllocateAndCopyToAlignedSpace(GenGetQualifiedName(getIndexDesc()->getNAFileSet()->getFileSetName()), 0); if (getIndexDesc()->isClusteringIndex()) { //base table @@ -2495,9 +2503,15 @@ short HbaseAccess::codeGen(Generator * generator) } if (! tablename) - tablename = + { + if(getTableDesc()->getNATable()->isSmallTable()) + tablename = + space->AllocateAndCopyToAlignedSpace( NAString(getTableDesc()->getNATable()->superTable()), 0); + else + tablename = space->AllocateAndCopyToAlignedSpace( GenGetQualifiedName(getTableName()), 0); + } ValueIdList columnList; if ((getTableDesc()->getNATable()->isSeabaseTable()) && @@ -3410,7 +3424,11 @@ short HbaseAccessCoProcAggr::codeGen(Generator * generator) } else { - tablename = + if (getTableDesc()->getNATable()->isSmallTable()) + tablename = + space->AllocateAndCopyToAlignedSpace( NAString(getTableDesc()->getNATable()->superTable()), 0); + else + tablename = space->AllocateAndCopyToAlignedSpace( GenGetQualifiedName(getTableName()), 0); } diff --git a/core/sql/generator/GenRelUpdate.cpp b/core/sql/generator/GenRelUpdate.cpp index b7cc6bb017..4152beae4e 100644 --- a/core/sql/generator/GenRelUpdate.cpp +++ b/core/sql/generator/GenRelUpdate.cpp @@ -1175,7 +1175,9 @@ short HbaseDelete::codeGen(Generator * generator) (getTableName().getQualifiedNameObj().isHbaseMappedName())) { if (getIndexDesc() && getIndexDesc()->getNAFileSet()) - tablename = space->AllocateAndCopyToAlignedSpace(GenGetQualifiedName(getIndexDesc()->getNAFileSet()->getFileSetName().getObjectName()), 0); + { + tablename = space->AllocateAndCopyToAlignedSpace(GenGetQualifiedName(getIndexDesc()->getNAFileSet()->getFileSetName().getObjectName()), 0); + } } else { @@ -1184,9 +1186,14 @@ short HbaseDelete::codeGen(Generator * generator) } if (! tablename) - tablename = - space->AllocateAndCopyToAlignedSpace( + { + tablename = + space->AllocateAndCopyToAlignedSpace( GenGetQualifiedName(getTableName()), 0); + } + + if(getTableDesc()->getNATable()->isSmallTable()) + strcpy(tablename, NAString(getTableDesc()->getNATable()->superTable()) ); NAString serverNAS = ActiveSchemaDB()->getDefaults().getValue(HBASE_SERVER); NAString zkPortNAS = ActiveSchemaDB()->getDefaults().getValue(HBASE_ZOOKEEPER_PORT); @@ -2138,18 +2145,25 @@ short HbaseUpdate::codeGen(Generator * generator) (getTableDesc()->getNATable()->isHbaseCellTable())) { if (getIndexDesc() && getIndexDesc()->getNAFileSet()) - tablename = space->AllocateAndCopyToAlignedSpace(GenGetQualifiedName(getIndexDesc()->getNAFileSet()->getFileSetName().getObjectName()), 0); + { + tablename = space->AllocateAndCopyToAlignedSpace(GenGetQualifiedName(getIndexDesc()->getNAFileSet()->getFileSetName().getObjectName()), 0); + } } else { if (getIndexDesc() && getIndexDesc()->getNAFileSet()) - tablename = space->AllocateAndCopyToAlignedSpace(GenGetQualifiedName(getIndexDesc()->getNAFileSet()->getFileSetName()), 0); + tablename = space->AllocateAndCopyToAlignedSpace(GenGetQualifiedName(getIndexDesc()->getNAFileSet()->getFileSetName()), 0); } if (! tablename) + { tablename = space->AllocateAndCopyToAlignedSpace( GenGetQualifiedName(getTableName()), 0); + } + + if(getTableDesc()->getNATable()->isSmallTable()) + strcpy(tablename, NAString(getTableDesc()->getNATable()->superTable()) ); NAString serverNAS = ActiveSchemaDB()->getDefaults().getValue(HBASE_SERVER); NAString zkPortNAS = ActiveSchemaDB()->getDefaults().getValue(HBASE_ZOOKEEPER_PORT); @@ -2165,7 +2179,6 @@ short HbaseUpdate::codeGen(Generator * generator) // estrowsaccessed is 0 for now, so cache size will be set to minimum generator->setHBaseNumCacheRows(getEstRowsAccessed().getValue(), hbpa) ; - // create hdfsscan_tdb ComTdbHbaseAccess *hbasescan_tdb = new(space) ComTdbHbaseAccess( @@ -2768,14 +2781,17 @@ short HbaseInsert::codeGen(Generator *generator) (getTableDesc()->getNATable()->isHbaseCellTable()) || (getTableName().getQualifiedNameObj().isHbaseMappedName())) { - tablename = space->AllocateAndCopyToAlignedSpace(GenGetQualifiedName(getIndexDesc()->getIndexName().getObjectName()), 0); + tablename = space->AllocateAndCopyToAlignedSpace(GenGetQualifiedName(getIndexDesc()->getIndexName().getObjectName()), 0); } else { - tablename = space->AllocateAndCopyToAlignedSpace( + tablename = space->AllocateAndCopyToAlignedSpace( GenGetQualifiedName(getIndexDesc()->getIndexName()), 0); } + if(getTableDesc()->getNATable()->isSmallTable()) + strcpy(tablename, NAString(getTableDesc()->getNATable()->superTable()) ); + NAString serverNAS = ActiveSchemaDB()->getDefaults().getValue(HBASE_SERVER); NAString zkPortNAS = ActiveSchemaDB()->getDefaults().getValue(HBASE_ZOOKEEPER_PORT); char * server = space->allocateAlignedSpace(serverNAS.length() + 1); diff --git a/core/sql/generator/Generator.cpp b/core/sql/generator/Generator.cpp index 20f799ae3c..79ca867926 100644 --- a/core/sql/generator/Generator.cpp +++ b/core/sql/generator/Generator.cpp @@ -2001,6 +2001,15 @@ TrafDesc * Generator::createVirtualTableDesc new GENHEAP(space) char[strlen(tableInfo->allColFams)+1]; strcpy(table_desc->tableDesc()->all_col_fams, tableInfo->allColFams); } + if (tableInfo) + if (tableInfo->superTable != NULL) + { + table_desc->tableDesc()->superTable_= + new GENHEAP(space) char[strlen(tableInfo->superTable)+1]; + strcpy(table_desc->tableDesc()->superTable_, tableInfo->superTable); + + table_desc->tableDesc()->setSuperTable(tableInfo->superTable); + } table_desc->tableDesc()->objectFlags = (tableInfo ? tableInfo->objectFlags : 0); table_desc->tableDesc()->tablesFlags = (tableInfo ? tableInfo->tablesFlags : 0); diff --git a/core/sql/optimizer/BindRI.cpp b/core/sql/optimizer/BindRI.cpp index eeb1e201c5..cddab122b5 100644 --- a/core/sql/optimizer/BindRI.cpp +++ b/core/sql/optimizer/BindRI.cpp @@ -416,6 +416,8 @@ static NABoolean isHiddenColumn(const char *colname) int len = strlen(colname); if(strcmp(colname , "_SALT_") ==0) return TRUE; + if(strcmp(colname , "_TBLNM_") ==0) + return TRUE; //check for DIVISION column //pattern _DIVISION_%d_ //must longer than 12 diff --git a/core/sql/optimizer/BindRelExpr.cpp b/core/sql/optimizer/BindRelExpr.cpp index d5e874bec3..6b42faee80 100644 --- a/core/sql/optimizer/BindRelExpr.cpp +++ b/core/sql/optimizer/BindRelExpr.cpp @@ -8189,6 +8189,53 @@ RelExpr *Scan::bindNode(BindWA *bindWA) } } + if (naTable->isSmallTable()) + { + //go through all columns and find out the tblnm + NAColumn *nac = NULL; + for (CollIndex c = 0; c < naTable->getColumnCount(); c++) { + nac = naTable->getNAColumnArray()[c]; + if (nac->getColName()=="_TBLNM_") + break; + } + + ItemExpr *partPred = NULL; + ColReference *tnmColRef = new(bindWA->wHeap()) ColReference( + new(bindWA->wHeap()) ColRefName( + nac->getFullColRefName(), bindWA->wHeap())); + + NAString tb=naTable->getTableName().getQualifiedNameAsAnsiString(); + + ConstValue *tblnmpart= new (CmpCommon::statementHeap()) + ConstValue( + tb, CharInfo::UTF8, CharInfo::DefaultCollation, CharInfo::COERCIBLE , + CmpCommon::statementHeap() + ); + ItemExpr * dataConversionErrorFlag = new(bindWA->wHeap()) + HostVar("_sys_dataConversionErrorFlag", + new(CmpCommon::statementHeap()) SQLInt(bindWA->wHeap(), TRUE,FALSE), // int not null + TRUE); + NAType * paramType = new (bindWA->wHeap()) + SQLChar(bindWA->wHeap(), 128, FALSE, FALSE); + + ItemExpr *n = new(bindWA->wHeap()) Narrow( tblnmpart, dataConversionErrorFlag, paramType, ITM_NARROW , FALSE); + partPred = new(bindWA->wHeap()) BiRelat + (ITM_EQUAL, + tnmColRef, + n); + ItemExpr *newSelPred = removeSelPredTree(); + + if (newSelPred) + newSelPred = new(bindWA->wHeap()) BiLogic(ITM_AND, + newSelPred, + partPred); + else + newSelPred = partPred; + + addSelPredTree(newSelPred->bindNode(bindWA)); + + } + if (naTable->isHiveTable() && !(naTable->getClusteringIndex()->getHHDFSTableStats()->isOrcFile() || naTable->getClusteringIndex()->getHHDFSTableStats() diff --git a/core/sql/optimizer/NATable.cpp b/core/sql/optimizer/NATable.cpp index 6a959ec832..1c5e37aa33 100644 --- a/core/sql/optimizer/NATable.cpp +++ b/core/sql/optimizer/NATable.cpp @@ -5170,6 +5170,18 @@ NABoolean NATable::fetchObjectUIDForNativeTable(const CorrName& corrName, if (table_desc->tableDesc()->default_col_fam) defaultColFam_ = table_desc->tableDesc()->default_col_fam; + if (table_desc->tableDesc()->hasSuperTable() ) + { + if( table_desc->tableDesc()->superTable_ != NULL) + { + superTable_ = new(heap_) char[strlen(table_desc->tableDesc()->superTable_) + 1]; + strcpy(superTable_,table_desc->tableDesc()->superTable_); + setHasSuperTable(TRUE); + } + else + printf("LMDBG: Oops!\n"); + } + if (table_desc->tableDesc()->all_col_fams) { // Space delimited col families. diff --git a/core/sql/optimizer/NATable.h b/core/sql/optimizer/NATable.h index 4feece990a..7a525bf912 100644 --- a/core/sql/optimizer/NATable.h +++ b/core/sql/optimizer/NATable.h @@ -609,7 +609,12 @@ class NATable : public NABasicObject else return getSQLMXAlignedTable(); } - + + NABoolean isSmallTable() const + { + return hasSuperTable(); + } + NABoolean isAlignedFormat(const IndexDesc *indexDesc) const { NABoolean isAlignedFormat; @@ -781,6 +786,16 @@ class NATable : public NABasicObject NABoolean isInternalRegistered() const { return (flags_ & IS_INTERNAL_REGISTERED) != 0; } + void setHasSuperTable( NABoolean value ) + { + value ? flags_ |= HAS_SUPER_TABLE: flags_ &= ~HAS_SUPER_TABLE; + } + + NABoolean hasSuperTable() const + { + return (flags_ & HAS_SUPER_TABLE) != 0; + } + const CheckConstraintList &getCheckConstraints() const { return checkConstraints_; } const AbstractRIConstraintList &getUniqueConstraints() const @@ -919,6 +934,8 @@ class NATable : public NABasicObject static NAArray* getRegionsBeginKey(const char* extHBaseName); NAString &defaultColFam() { return defaultColFam_; } + char *superTable() const { + return superTable_; } NAList &allColFams() { return allColFams_; } private: @@ -1007,7 +1024,8 @@ class NATable : public NABasicObject HIVE_EXT_KEY_ATTRS = 0x04000000, IS_IMPLICIT_EXTERNAL_TABLE= 0x08000000, IS_REGISTERED = 0x10000000, - IS_INTERNAL_REGISTERED = 0x20000000 + IS_INTERNAL_REGISTERED = 0x20000000, + HAS_SUPER_TABLE = 0x40000000 }; UInt32 flags_; @@ -1232,6 +1250,9 @@ class NATable : public NABasicObject NAColumnArray newColumns_; NAString defaultColFam_; + + char *superTable_; + NAList allColFams_; }; // class NATable diff --git a/core/sql/optimizer/PartFunc.cpp b/core/sql/optimizer/PartFunc.cpp index afadbb93ae..e3faf9b2d2 100644 --- a/core/sql/optimizer/PartFunc.cpp +++ b/core/sql/optimizer/PartFunc.cpp @@ -743,6 +743,29 @@ SinglePartitionPartitioningFunction::copy() const SinglePartitionPartitioningFunction(*this, CmpCommon::statementHeap()); } +SearchKey *SinglePartitionPartitioningFunction::createSearchKey(const IndexDesc *indexDesc, + ValueIdSet availInputs, + ValueIdSet additionalPreds) const +{ + ValueIdSet preds(getPartitioningKeyPredicates()); + ValueIdSet nonKeyColumnSet; // empty set + SearchKey *partSearchKey = NULL; + + availInputs += getPartitionInputValues(); + preds += additionalPreds; + + partSearchKey = new (CmpCommon::statementHeap()) + SearchKey(indexDesc->getIndexKey(), + indexDesc->getOrderOfKeyValues(), + availInputs, + TRUE, + preds, + nonKeyColumnSet, + indexDesc); + + return partSearchKey; +} + void SinglePartitionPartitioningFunction::createPartitioningKeyPredicates() { // do nothing, there aren't any partitioning key preds for a single @@ -1063,6 +1086,74 @@ HashPartitioningFunction::copy() const HashPartitioningFunction(*this, CmpCommon::statementHeap()); } +void PartitioningFunction::createSmallTableKeyPredicates( + const char * tblName, + ItemExpr * partNumExpr + ) +{ + ItemExpr * rootPtr; + ItemExpr * loPart; + ItemExpr * hiPart; + ValueIdSet setOfPartKeyPredicates; + NAString tb; + char tmpbuf[128]; + memset(tmpbuf,0,128); + //strcpy(tmpbuf," "); + + int lenn=strlen(tblName); + { + strcat(tmpbuf,tblName); + tb=tmpbuf; + tmpbuf[lenn]++; + } + NAString tb1=tmpbuf; + + + ConstValue *tblnmpart= new (CmpCommon::statementHeap()) + ConstValue( + tb, CharInfo::UTF8, CharInfo::DefaultCollation, CharInfo::COERCIBLE , + CmpCommon::statementHeap() + ); + + NAType * paramType = new (CmpCommon::statementHeap()) + SQLChar(CmpCommon::statementHeap(), 128, FALSE, FALSE); + + ItemExpr * dataConversionErrorFlag = new(CmpCommon::statementHeap()) + HostVar("_sys_dataConversionErrorFlag", + new(CmpCommon::statementHeap()) SQLInt(CmpCommon::statementHeap(), TRUE,FALSE), // int not null + TRUE); + + ItemExpr * lop = new (CmpCommon::statementHeap()) + Narrow( tblnmpart, dataConversionErrorFlag, paramType, ITM_NARROW , FALSE); + + rootPtr = new (CmpCommon::statementHeap()) + BiRelat(ITM_EQUAL, + partNumExpr, + (ItemExpr*)lop, + TRUE); + + rootPtr->synthTypeAndValueId(); + setOfPartKeyPredicates += rootPtr->getValueId(); + ConstValue *tblnmpart1= new (CmpCommon::statementHeap()) + ConstValue( + tb, CharInfo::UTF8, CharInfo::DefaultCollation, CharInfo::COERCIBLE , + CmpCommon::statementHeap() + ); + + ItemExpr * hop = new (CmpCommon::statementHeap()) + Narrow( tblnmpart1, dataConversionErrorFlag, paramType, ITM_NARROW , FALSE); + + rootPtr = new (CmpCommon::statementHeap()) + BiRelat(ITM_EQUAL, + partNumExpr, + (ItemExpr*)hop, + TRUE); + rootPtr->synthTypeAndValueId(); + setOfPartKeyPredicates += rootPtr->getValueId(); + storePartitioningKeyPredicates(setOfPartKeyPredicates); + +} + // ----------------------------------------------------------------------- // PartitioningFunction::createBetweenPartitioningKeyPredicates() // ----------------------------------------------------------------------- diff --git a/core/sql/optimizer/PartFunc.h b/core/sql/optimizer/PartFunc.h index f5f320f652..7bd3f85864 100644 --- a/core/sql/optimizer/PartFunc.h +++ b/core/sql/optimizer/PartFunc.h @@ -820,6 +820,10 @@ class PartitioningFunction : public NABasicObject const char * pivHiName, ItemExpr * partNumExpr = NULL, NABoolean useHash2Split = FALSE); +public: + void createSmallTableKeyPredicates( + const char * tblName,ItemExpr * partNumExpr = NULL + ); private: @@ -959,6 +963,9 @@ class SinglePartitionPartitioningFunction : public PartitioningFunction virtual PartitioningFunction* copy() const; virtual void createPartitioningKeyPredicates(); + virtual SearchKey * createSearchKey(const IndexDesc *indexDesc, + ValueIdSet availInputs, + ValueIdSet additionalPreds) const; // Replace the pivs, partitioning key predicates and partitioning // expression with those passed in. diff --git a/core/sql/parser/ElemDDLFileAttr.h b/core/sql/parser/ElemDDLFileAttr.h index 0243172156..38fcf70d97 100644 --- a/core/sql/parser/ElemDDLFileAttr.h +++ b/core/sql/parser/ElemDDLFileAttr.h @@ -174,6 +174,48 @@ class ElemDDLFileAttrRowFormat : public ElemDDLFileAttr }; // class ElemDDLFileAttrRowFormat +class ElemDDLFileAttrSuperTable: public ElemDDLFileAttr +{ + +public: + + ElemDDLFileAttrSuperTable(NAString &tblNm) + : ElemDDLFileAttr(ELM_FILE_ATTR_SUPER_TABLE_ELEM), + superTable_(tblNm) + { + } + + // virtual destructor + virtual ~ElemDDLFileAttrSuperTable() + { + }; + + // cast + virtual ElemDDLFileAttrSuperTable* castToElemDDLFileAttrSuperTable() + { + return this; + } + + // accessors + NAString &getSuperTable() + { + return superTable_; + } + + // method for building text + virtual NAString getSyntax() const + { + return ""; + } + +private: + + NAString superTable_; + +}; // class ElemDDLFileAttrSuperTable + + + class ElemDDLFileAttrColFam : public ElemDDLFileAttr { diff --git a/core/sql/parser/ElemDDLNode.cpp b/core/sql/parser/ElemDDLNode.cpp index 4d67199d71..3e05a18a7e 100644 --- a/core/sql/parser/ElemDDLNode.cpp +++ b/core/sql/parser/ElemDDLNode.cpp @@ -429,6 +429,12 @@ ElemDDLNode::castToElemDDLFileAttrColFam() return NULL; } +ElemDDLFileAttrSuperTable* +ElemDDLNode::castToElemDDLFileAttrSuperTable() +{ + return NULL; +} + //++ MV ElemDDLFileAttrRangeLog * ElemDDLNode::castToElemDDLFileAttrRangeLog() diff --git a/core/sql/parser/ElemDDLNode.h b/core/sql/parser/ElemDDLNode.h index fb105918c7..405999e663 100644 --- a/core/sql/parser/ElemDDLNode.h +++ b/core/sql/parser/ElemDDLNode.h @@ -106,6 +106,7 @@ class ElemDDLFileAttrMaxExtents; class ElemDDLFileAttrUID; class ElemDDLFileAttrRowFormat; class ElemDDLFileAttrColFam; +class ElemDDLFileAttrSuperTable; class ElemDDLFileAttrNoLabelUpdate; class ElemDDLFileAttrOwner; //++ MV @@ -432,6 +433,7 @@ class ElemDDLNode : public ExprNode virtual ElemDDLFileAttrUID * castToElemDDLFileAttrUID(); virtual ElemDDLFileAttrRowFormat * castToElemDDLFileAttrRowFormat(); virtual ElemDDLFileAttrColFam * castToElemDDLFileAttrColFam(); + virtual ElemDDLFileAttrSuperTable* castToElemDDLFileAttrSuperTable(); virtual ElemDDLFileAttrNoLabelUpdate * castToElemDDLFileAttrNoLabelUpdate(); virtual ElemDDLFileAttrOwner * castToElemDDLFileAttrOwner(); diff --git a/core/sql/parser/ParDDLFileAttrs.cpp b/core/sql/parser/ParDDLFileAttrs.cpp index c8ba867b68..03848b3cc3 100644 --- a/core/sql/parser/ParDDLFileAttrs.cpp +++ b/core/sql/parser/ParDDLFileAttrs.cpp @@ -2039,6 +2039,8 @@ ParDDLFileAttrsCreateTable::resetAllIsSpecDataMembers() isColFamSpec_ = FALSE; + isSuperTableSpec_ = FALSE; + // [ NO ] AUDITCOMPRESS // inherits from class ParDDLFileAttrsCreateIndex @@ -2230,7 +2232,14 @@ ParDDLFileAttrsCreateTable::setFileAttr(ElemDDLFileAttr * pFileAttr) *SqlParser_Diags << DgSqlCode(-3097); break; - + case ELM_FILE_ATTR_SUPER_TABLE_ELEM: + if (isSuperTableSpec_) + *SqlParser_Diags << DgSqlCode(-3082); + ComASSERT(pFileAttr->castToElemDDLFileAttrSuperTable() NEQ NULL); + superTable_ = pFileAttr->castToElemDDLFileAttrSuperTable()->getSuperTable(); + isSuperTableSpec_ = TRUE; + + break; default : NAAbort("ParDDLFileAttrs.C", __LINE__, "internal logic error"); break; diff --git a/core/sql/parser/ParDDLFileAttrsCreateTable.h b/core/sql/parser/ParDDLFileAttrsCreateTable.h index 246da84d36..e46eb54aa6 100644 --- a/core/sql/parser/ParDDLFileAttrsCreateTable.h +++ b/core/sql/parser/ParDDLFileAttrsCreateTable.h @@ -158,6 +158,10 @@ class ParDDLFileAttrsCreateTable : public ParDDLFileAttrsCreateIndex inline NAString getColFam() const; + inline NABoolean isSuperTableSpecified() const; + + NAString getSuperTable() const; + // // mutators // @@ -246,6 +250,10 @@ class ParDDLFileAttrsCreateTable : public ParDDLFileAttrsCreateIndex NABoolean isColFamSpec_; NAString colFam_; + // SMALL TABLE + NABoolean isSuperTableSpec_; + NAString superTable_; + //-- MV // ALLOCATE @@ -424,6 +432,17 @@ ParDDLFileAttrsCreateTable::getCompressionType() const //-- MV //---------------------------------------------------------------------------- +inline NABoolean +ParDDLFileAttrsCreateTable::isSuperTableSpecified() const +{ + return isSuperTableSpec_; +} + +inline NAString ParDDLFileAttrsCreateTable::getSuperTable() const +{ + return superTable_; +} + // is the Col Family phrase specified? inline NABoolean ParDDLFileAttrsCreateTable::isColFamSpecified() const diff --git a/core/sql/parser/ParKeyWords.cpp b/core/sql/parser/ParKeyWords.cpp index a21345831c..309ec8edce 100644 --- a/core/sql/parser/ParKeyWords.cpp +++ b/core/sql/parser/ParKeyWords.cpp @@ -1067,6 +1067,7 @@ ParKeyWord ParKeyWords::keyWords_[] = { ParKeyWord("SUFFIX", TOK_SUFFIX, NONRESTOKEN_), ParKeyWord("SUM", TOK_SUM, ANS_|RESWORD_|MPWORD_), ParKeyWord("SUMMARY", TOK_SUMMARY, NONRESTOKEN_), + ParKeyWord("SUPER", TOK_SUPER, NONRESTOKEN_), ParKeyWord("SUSPEND", TOK_SUSPEND, NONRESTOKEN_), ParKeyWord("SYNONYM", TOK_SYNONYM, POTANS_|RESWORD_), ParKeyWord("SYNONYMS", TOK_SYNONYMS, NONRESTOKEN_), diff --git a/core/sql/parser/StmtDDLDrop.cpp b/core/sql/parser/StmtDDLDrop.cpp index 02e564e23d..be15397145 100644 --- a/core/sql/parser/StmtDDLDrop.cpp +++ b/core/sql/parser/StmtDDLDrop.cpp @@ -755,6 +755,7 @@ StmtDDLDropTable::StmtDDLDropTable(const QualifiedName & tableQualName, isCleanupSpec_(FALSE), isValidateSpec_(FALSE), pLogFile_(NULL), + smallTable_(FALSE), dropIfExists_(FALSE) { } @@ -776,6 +777,7 @@ StmtDDLDropTable::StmtDDLDropTable(const QualifiedName & tableQualName, isCleanupSpec_(cleanupSpec), isValidateSpec_(validateSpec), pLogFile_(pLogFile), + smallTable_(FALSE), dropIfExists_(FALSE) { } diff --git a/core/sql/parser/StmtDDLDropTable.h b/core/sql/parser/StmtDDLDropTable.h index 011c10ff17..d071adb363 100644 --- a/core/sql/parser/StmtDDLDropTable.h +++ b/core/sql/parser/StmtDDLDropTable.h @@ -96,6 +96,8 @@ class StmtDDLDropTable : public StmtDDLNode const NABoolean dropIfExists() const { return dropIfExists_; } + const NABoolean isSmallTable() const { return smallTable_; } + // for binding ExprNode * bindNode(BindWA *bindWAPtr); @@ -109,6 +111,8 @@ class StmtDDLDropTable : public StmtDDLNode void setDropIfExists(NABoolean v) { dropIfExists_ = v; } + void setSmallTable(NABoolean v) { smallTable_= v; } + private: // the tablename specified by user in the drop stmt. // This name is not fully qualified during bind phase. @@ -127,6 +131,8 @@ class StmtDDLDropTable : public StmtDDLNode // drop only if table exists. Otherwise just return. NABoolean dropIfExists_; + + NABoolean smallTable_; }; // class StmtDDLDropTable // ----------------------------------------------------------------------- diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y index b84546da17..c1de558b14 100755 --- a/core/sql/parser/sqlparser.y +++ b/core/sql/parser/sqlparser.y @@ -1038,6 +1038,7 @@ static void enableMakeQuotedStringISO88591Mechanism() %token TOK_SHAPE %token TOK_SHARE /* Tandem extension non-reserved word */ %token TOK_SHARED /* Tandem extension non-reserved word */ +%token TOK_SUPER %token TOK_SUSPEND %token TOK_SHOW %token TOK_SHOWCONTROL /* Tandem extension reserved word */ @@ -2641,6 +2642,7 @@ static void enableMakeQuotedStringISO88591Mechanism() %type file_attribute_icompress_clause %type file_attribute_list %type file_attribute_compression_clause +%type file_attribute_super_table_clause %type file_attribute_extent_clause %type file_attribute_maxextent_clause %type file_attribute_uid_clause @@ -26719,6 +26721,7 @@ file_attribute : file_attribute_allocate_clause | file_attribute_no_label_update_clause | file_attribute_owner_clause | file_attribute_default_col_fam + | file_attribute_super_table_clause /* type pElemDDL */ file_attribute_allocate_clause : TOK_ALLOCATE unsigned_smallint @@ -27108,6 +27111,20 @@ file_attribute_row_format_clause : TOK_ALIGNED TOK_FORMAT (ElemDDLFileAttrRowFormat::eHBASE); } +/* type pElemDDL */ +file_attribute_super_table_clause : TOK_SUPER TOK_TABLE TOK_SYSTEM + { + NAString defaultSuperTable("TRAFODION._SUPER_.SYSTEM"); + $$ = new (PARSERHEAP()) ElemDDLFileAttrSuperTable + (defaultSuperTable); + } + | TOK_SUPER TOK_TABLE QUOTED_STRING + { + YYERROR; + $$ = new (PARSERHEAP()) ElemDDLFileAttrSuperTable + (*$3); + } + /* type pElemDDL */ file_attribute_default_col_fam : TOK_DEFAULT TOK_COLUMN TOK_FAMILY QUOTED_STRING { @@ -34357,6 +34374,7 @@ nonreserved_func_word: TOK_ABS // | TOK_UPSERT | TOK_UNIQUE_ID | TOK_UUID + | TOK_SUPER | TOK_USERNAMEINTTOEXT | TOK_VARIANCE | TOK_WEEK diff --git a/core/sql/regress/tools/sbdefs b/core/sql/regress/tools/sbdefs index 3a932d980c..dc5905d10e 100644 --- a/core/sql/regress/tools/sbdefs +++ b/core/sql/regress/tools/sbdefs @@ -22,7 +22,7 @@ -- defs included during seabase regr run #ifdef SEABASE_REGRESS -cqd mode_seabase 'ON'; +--cqd mode_seabase 'ON'; cqd seabase_volatile_tables 'ON'; cqd hbase_async_drop_table 'OFF'; cqd hbase_serialization 'ON'; diff --git a/core/sql/sqlcat/TrafDDLdesc.h b/core/sql/sqlcat/TrafDDLdesc.h index 733ffa9d92..94aac8a1e0 100644 --- a/core/sql/sqlcat/TrafDDLdesc.h +++ b/core/sql/sqlcat/TrafDDLdesc.h @@ -964,7 +964,8 @@ class TrafTableDesc : public TrafDesc { VOLATILE = 0x0040, IN_MEM_OBJ = 0x0080, DROPPABLE = 0x0100, - INSERT_ONLY = 0x0200 + INSERT_ONLY = 0x0200, + HAS_SUPER_TABLE = 0x0400 }; void setSystemTableCode(NABoolean v) @@ -995,6 +996,19 @@ class TrafTableDesc : public TrafDesc { {(v ? tableDescFlags |= VOLATILE : tableDescFlags &= ~VOLATILE); }; NABoolean isVolatileTable() { return (tableDescFlags & VOLATILE) != 0; }; + void setSuperTable(const char *v) + { + if ( v = NULL ) + tableDescFlags &= ~HAS_SUPER_TABLE; + else + tableDescFlags |= HAS_SUPER_TABLE; + } + + NABoolean hasSuperTable() + { + return (tableDescFlags & HAS_SUPER_TABLE) != 0 ; + } + void setInMemoryObject(NABoolean v) {(v ? tableDescFlags |= IN_MEM_OBJ : tableDescFlags &= ~IN_MEM_OBJ); }; NABoolean isInMemoryObject() { return (tableDescFlags & IN_MEM_OBJ) != 0; }; @@ -1069,6 +1083,8 @@ class TrafTableDesc : public TrafDesc { DescStructPtr hbase_regionkey_desc; DescStructPtr sequence_generator_desc; + char * superTable_; + char filler[32]; }; diff --git a/core/sql/sqlcomp/CmpSeabaseDDL.h b/core/sql/sqlcomp/CmpSeabaseDDL.h index c6ff74b030..650c62f804 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDL.h +++ b/core/sql/sqlcomp/CmpSeabaseDDL.h @@ -294,6 +294,13 @@ class CmpSeabaseDDL ComObjectType & objectType, Int32 & objectOwner); + short getSuperTableText(ExeCliInterface *cliInterface, + const char * catName, + const char * schName, + const char * objName, + const char * inObjType, + NAString& superTable) ; + short getSaltText(ExeCliInterface *cliInterface, const char * catName, const char * schName, diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp index fa43caa980..10033b98f3 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp @@ -3174,6 +3174,8 @@ short CmpSeabaseDDL::getColInfo(ElemDDLColDef * colNode, colFlags |= SEABASE_COLUMN_IS_DIVISION; else if (colName == ElemDDLSaltOptionsClause::getSaltSysColName()) colFlags |= SEABASE_COLUMN_IS_SALT; + else if (colName == "_TBLNM_") + colFlags |= SEABASE_COLUMN_IS_TBLNM; else CMPASSERT(0); } @@ -4137,6 +4139,79 @@ short CmpSeabaseDDL::getAllUsingViews(ExeCliInterface *cliInterface, return 0; } +/* +Get the super table name +Returns 0 for object does not have super table +Returns 1 for object has super table returned in superTable +Returns -1 for error, which for now is ignored as we have an alternate code path. + */ + +short CmpSeabaseDDL::getSuperTableText( + ExeCliInterface *cliInterface, + const char * catName, + const char * schName, + const char * objName, + const char * inObjType, + NAString& superTable) +{ + Lng32 cliRC = 0; + + NAString quotedSchName; + ToQuotedString(quotedSchName, NAString(schName), FALSE); + NAString quotedObjName; + ToQuotedString(quotedObjName, NAString(objName), FALSE); + Int64 objUID; + Lng32 colNum; + NAString defaultValue; + + char buf[4000]; + char *data; + Lng32 len; + + // determine object UID + str_sprintf(buf, "select object_uid from %s.\"%s\".%s o where o.catalog_name = '%s' and o.schema_name = '%s' and o.object_name = '%s' and o.object_type = '%s' ", + getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS, + catName, quotedSchName.data(), quotedObjName.data(), + inObjType + ); + + Queue * sQueue = NULL; + cliRC = cliInterface->fetchAllRows(sQueue, buf, 0, FALSE, FALSE, TRUE); + if (cliRC < 0) + { + cliInterface->retrieveSQLDiagnostics(CmpCommon::diags()); + return -1; + } + + // did not find row + if (sQueue->numEntries() == 0) + return 0; + + sQueue->position(); + OutputInfo * vi = (OutputInfo*)sQueue->getNext(); + objUID = *(Int64 *)vi->get(0); + + // this should be the normal case, salt text is stored in the TEXT table, + // not the default value + cliRC = getTextFromMD(cliInterface, + objUID, + COM_SUPER_TABLE_TEXT, + 0, + superTable); + if (cliRC < 0) + { + cliInterface->retrieveSQLDiagnostics(CmpCommon::diags()); + return -1; + } + + if (superTable.isNull()) + superTable= defaultValue; + + CMPASSERT(!superTable.isNull()); + + return 1; +} + /* Get the salt column text for a given table or index. Returns 0 for object does not have salt column @@ -5052,6 +5127,15 @@ short CmpSeabaseDDL::updateSeabaseMDTable( } } + if (CmpSeabaseDDL::isMDflagsSet(tablesFlags, MD_TABLES_SUPER_TABLE_ATTRS)) + { + NAString nas(tableInfo->superTable); + if (updateTextTable(cliInterface, objUID, COM_SUPER_TABLE_TEXT , 0, nas)) + { + return -1; + } + } + } // BT if (objectType == COM_INDEX_OBJECT && numIndexes > 0) { @@ -6975,6 +7059,13 @@ short CmpSeabaseDDL::dropSeabaseObject(ExpHbaseInterface * ehi, ExeCliInterface cliInterface(STMTHEAP, 0, NULL, CmpCommon::context()->sqlSession()->getParentQid() ); + + NAString superTable; + short hasSuperTable = getSuperTableText(&cliInterface, + tableName.getCatalogNamePartAsAnsiString().data(), + tableName.getSchemaNamePartAsAnsiString().data(), + tableName.getObjectNamePartAsAnsiString().data(), + COM_BASE_TABLE_OBJECT_LIT,superTable); if (dropFromMD) { @@ -7044,13 +7135,24 @@ short CmpSeabaseDDL::dropSeabaseObject(ExpHbaseInterface * ehi, return -1; } } - + if (hasSuperTable == 1) // this table is embedded in super table, so do a delete first + { + char buf[4000]; + Lng32 cliRC = 0; + str_sprintf(buf, "DELETE FROM %s.%s.%s;", catalogNamePart.data(), schemaNamePart.data(),objectNamePart.data() ); + cliRC = cliInterface.executeImmediate(buf); + if (cliRC < 0) + { + cliInterface.retrieveSQLDiagnostics(CmpCommon::diags()); + return -1; + } + } if (deleteFromSeabaseMDTable(&cliInterface, catalogNamePart, schemaNamePart, objectNamePart, objType )) return -1; } - if (dropFromHbase) + if (dropFromHbase && hasSuperTable!=1) { if (objType != COM_VIEW_OBJECT) { @@ -7294,6 +7396,22 @@ void CmpSeabaseDDL::initSeabaseMD(NABoolean ddlXns, NABoolean minimal) { ehi->truncate(tddlTable, TRUE, TRUE); } + // create default system super table + HbaseStr sysSuperTable; + const NAString sysSTNAS("TRAFODION._SUPER_.SYSTEM"); + sysSuperTable.val = (char *)sysSTNAS.data(); + sysSuperTable.len = sysSTNAS.length(); + + if (ehi->exists(sysSuperTable) == 0 ) //not exists + { + if (createHbaseTable(ehi, &sysSuperTable, SEABASE_DEFAULT_COL_FAMILY, NULL, + 0, 0, NULL, + FALSE, ddlXns) == -1) + { + deallocEHI(ehi); + return; + } + } // create hbase physical objects for (Lng32 i = 0; i < numTables; i++) diff --git a/core/sql/sqlcomp/CmpSeabaseDDLmd.h b/core/sql/sqlcomp/CmpSeabaseDDLmd.h index 3ca7e789d3..958e18bd44 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLmd.h +++ b/core/sql/sqlcomp/CmpSeabaseDDLmd.h @@ -126,7 +126,8 @@ enum SeabaseColumnsFlags { SEABASE_COLUMN_IS_SALT = 0x0000000000000001, // don't rely on this quite yet, // since some older tables // don't have this flag set - SEABASE_COLUMN_IS_DIVISION = 0x0000000000000002 + SEABASE_COLUMN_IS_DIVISION = 0x0000000000000002, + SEABASE_COLUMN_IS_TBLNM = 0x0000000000000004 }; static const QString seabaseDefaultsDDL[] = @@ -375,7 +376,8 @@ enum SeabaseTablesFlags MD_TABLES_RESERVED1 = 0x0001, MD_TABLES_RESERVED2 = 0x0002, MD_TABLES_HIVE_EXT_COL_ATTRS = 0x0004, - MD_TABLES_HIVE_EXT_KEY_ATTRS = 0x0008 + MD_TABLES_HIVE_EXT_KEY_ATTRS = 0x0008, + MD_TABLES_SUPER_TABLE_ATTRS = 0x0040 }; static const QString seabaseTableConstraintsDDL[] = diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp index b9a2c88b5f..8fbdd5ba70 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp @@ -2075,6 +2075,32 @@ short CmpSeabaseDDL::createSeabaseTable2( Lng32 numSaltPartnsFromCQD = CmpCommon::getDefaultNumeric(TRAF_NUM_OF_SALT_PARTNS); + // create table in seabase + + if(createTableNode->getFileAttributes().isSuperTableSpecified()) //TODO + { + NAString smallColName("_TBLNM_"); + SQLVarChar * tblNmColType = new(STMTHEAP) SQLVarChar(STMTHEAP, 128, FALSE); + NAString tblNmExprText("CAST ( '"); + tblNmExprText += createTableNode->getTableName(); + tblNmExprText += "' AS CHAR(128) ) "; + ElemDDLColDefault *tblNmDef = + new(STMTHEAP) ElemDDLColDefault( + ElemDDLColDefault::COL_COMPUTED_DEFAULT); + tblNmDef->setComputedDefaultExpr(tblNmExprText); + ElemDDLColDef * tblNmColDef = + new(STMTHEAP) ElemDDLColDef(NULL, &smallColName, tblNmColType , tblNmDef, + STMTHEAP); + ElemDDLColRef * edcrs = + new(STMTHEAP) ElemDDLColRef(smallColName, COM_ASCENDING_ORDER); + + tblNmColDef->setColumnClass(COM_SYSTEM_COLUMN); + + colArray.insert(tblNmColDef); + keyArray.insertAt(0, edcrs); + numSysCols++; + } + if ((createTableNode->getSaltOptions()) || ((numSaltPartnsFromCQD > 0) && (NOT implicitPK))) @@ -2249,7 +2275,7 @@ short CmpSeabaseDDL::createSeabaseTable2( } } - // create table in seabase + ParDDLFileAttrsCreateTable &fileAttribs = createTableNode->getFileAttributes(); @@ -2606,7 +2632,13 @@ short CmpSeabaseDDL::createSeabaseTable2( tableInfo->hbaseCreateOptions = NULL; tableInfo->objectFlags = 0; tableInfo->tablesFlags = 0; - + + if (fileAttribs.isSuperTableSpecified()) + { + tableInfo->tablesFlags |= MD_TABLES_SUPER_TABLE_ATTRS; + tableInfo->superTable = fileAttribs.getSuperTable().data(); + } + if (fileAttribs.isOwnerSpecified()) { // Fixed bug: if BY CLAUSE specified an unregistered user, then the object @@ -2834,7 +2866,7 @@ short CmpSeabaseDDL::createSeabaseTable2( } NABoolean ddlXns = createTableNode->ddlXns(); - if (NOT extNameForHbase.isNull()) + if (NOT extNameForHbase.isNull() && (createTableNode->getFileAttributes().isSuperTableSpecified() == FALSE) ) { HbaseStr hbaseTable; hbaseTable.val = (char*)extNameForHbase.data(); @@ -3042,7 +3074,7 @@ void CmpSeabaseDDL::createSeabaseTable( if (retObjUID) *retObjUID = objUID; - if (NOT isCompound) + if (NOT isCompound && createTableNode->getFileAttributes().isSuperTableSpecified() == FALSE) { if (updateObjectRedefTime(&cliInterface, catalogNamePart, schemaNamePart, objectNamePart, @@ -3605,7 +3637,14 @@ short CmpSeabaseDDL::dropSeabaseTable2( volTabName = tableName; isVolatile = TRUE; } - + + NAString superTable; + short hasSuperTable = getSuperTableText(cliInterface, + tableName.getCatalogNamePartAsAnsiString().data(), + tableName.getSchemaNamePartAsAnsiString().data(), + tableName.getObjectNamePartAsAnsiString().data(), + COM_BASE_TABLE_OBJECT_LIT,superTable); + if ((NOT dropTableNode->isVolatile()) && (CmpCommon::context()->sqlSession()->volatileSchemaInUse())) { @@ -3720,7 +3759,7 @@ short CmpSeabaseDDL::dropSeabaseTable2( // This is an internal inconsistency which needs to be fixed by running cleanup. // If this is an external (native HIVE or HBASE) table, then skip - if (!isSeabaseExternalSchema(catalogNamePart, schemaNamePart)) + if (!isSeabaseExternalSchema(catalogNamePart, schemaNamePart) && hasSuperTable != 1 ) //dropTableNode->isSmallTable() == FALSE { HbaseStr hbaseTable; hbaseTable.val = (char*)extNameForHbase.data(); @@ -11907,6 +11946,7 @@ TrafDesc * CmpSeabaseDDL::getSeabaseUserTableDesc(const NAString &catName, NABoolean alignedFormat = FALSE; NABoolean hbaseStrDataFormat = FALSE; NAString * hbaseCreateOptions = new(STMTHEAP) NAString(); + NAString * superTable= new(STMTHEAP) NAString(); NAString colFamStr; if (cliRC == 0) // read some rows { @@ -11929,6 +11969,7 @@ TrafDesc * CmpSeabaseDDL::getSeabaseUserTableDesc(const NAString &catName, hbaseStrDataFormat = (memcmp(format, COM_HBASE_STR_FORMAT_LIT, 2) == 0); tablesFlags = *(Int64*)vi->get(3); + if (getTextFromMD(&cliInterface, objUID, COM_HBASE_OPTIONS_TEXT, 0, *hbaseCreateOptions)) { @@ -11936,6 +11977,12 @@ TrafDesc * CmpSeabaseDDL::getSeabaseUserTableDesc(const NAString &catName, return NULL; } + if (getTextFromMD(&cliInterface, objUID, COM_SUPER_TABLE_TEXT, 0, + *superTable)) + { + processReturn(); + return NULL; + } if (getTextFromMD(&cliInterface, objUID, COM_HBASE_COL_FAMILY_TEXT, 0, colFamStr)) { @@ -12561,6 +12608,8 @@ TrafDesc * CmpSeabaseDDL::getSeabaseUserTableDesc(const NAString &catName, tableInfo->numSaltPartns = numSaltPartns; tableInfo->hbaseCreateOptions = (hbaseCreateOptions->isNull() ? NULL : hbaseCreateOptions->data()); + tableInfo->superTable = + (superTable->isNull() ? NULL : superTable->data()); if (alignedFormat) tableInfo->rowFormat = COM_ALIGNED_FORMAT_TYPE; else if (hbaseStrDataFormat) From d4b37f676fc800f9103168262e12fd4e5b7710d9 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Wed, 25 Apr 2018 11:43:16 +0000 Subject: [PATCH 3/5] put a change to pass regression --- core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp index 10033b98f3..5710b7309e 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp @@ -4207,7 +4207,7 @@ short CmpSeabaseDDL::getSuperTableText( if (superTable.isNull()) superTable= defaultValue; - CMPASSERT(!superTable.isNull()); + //CMPASSERT(!superTable.isNull()); return 1; } From 395005f597d17f4dc8bdd2d5ad6e6e778c765a47 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Tue, 8 May 2018 01:20:27 +0000 Subject: [PATCH 4/5] try to fix regression issue --- core/sql/regress/tools/sbdefs | 2 +- core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/sql/regress/tools/sbdefs b/core/sql/regress/tools/sbdefs index dc5905d10e..3a932d980c 100644 --- a/core/sql/regress/tools/sbdefs +++ b/core/sql/regress/tools/sbdefs @@ -22,7 +22,7 @@ -- defs included during seabase regr run #ifdef SEABASE_REGRESS ---cqd mode_seabase 'ON'; +cqd mode_seabase 'ON'; cqd seabase_volatile_tables 'ON'; cqd hbase_async_drop_table 'OFF'; cqd hbase_serialization 'ON'; diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp index 39a9ea81a3..2558b1875b 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp @@ -7152,7 +7152,8 @@ short CmpSeabaseDDL::dropSeabaseObject(ExpHbaseInterface * ehi, return -1; } - if (dropFromHbase && hasSuperTable!=1) + //if (dropFromHbase && hasSuperTable !=1 ) + if (dropFromHbase ) { if (objType != COM_VIEW_OBJECT) { From c319dbacd9aa22ee6d9490ffa2f8b3707b7f659a Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Wed, 9 May 2018 11:45:17 +0000 Subject: [PATCH 5/5] fix issue in drop table --- core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp index 2558b1875b..2975a67d17 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp @@ -4204,10 +4204,8 @@ short CmpSeabaseDDL::getSuperTableText( return -1; } - if (superTable.isNull()) - superTable= defaultValue; - - //CMPASSERT(!superTable.isNull()); + if (superTable.isNull() || superTable == "") + return 0; return 1; } @@ -7152,8 +7150,7 @@ short CmpSeabaseDDL::dropSeabaseObject(ExpHbaseInterface * ehi, return -1; } - //if (dropFromHbase && hasSuperTable !=1 ) - if (dropFromHbase ) + if (dropFromHbase && hasSuperTable !=1 ) { if (objType != COM_VIEW_OBJECT) {