Merge remote branch 'origin/master' into deliver2_dt_br
-- resolved merge conflicts
Conflicts:
core/sql/executor/HBaseClient_JNI.h
core/sql/regress/executor/EXPECTED013.SB
core/sql/regress/seabase/EXPECTED011
core/sql/sqlcomp/CmpSeabaseDDL.h
core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit:
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/faf5dca6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/faf5dca6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/faf5dca6
Branch: refs/heads/master
Commit: faf5dca658cb005e0d37b6dabff0f82f1a7f1468
Parents: cd9f7a1 b2fe5fd
Author: Cloud User <[email protected]>
Authored: Wed Mar 2 23:00:30 2016 +0000
Committer: Cloud User <[email protected]>
Committed: Wed Mar 2 23:00:30 2016 +0000
----------------------------------------------------------------------
core/sql/cli/Statement.cpp | 36 +-
core/sql/common/ComSmallDefs.h | 2 +
core/sql/executor/HBaseClient_JNI.cpp | 25 +-
core/sql/executor/HBaseClient_JNI.h | 3 +-
core/sql/executor/ex_transaction.cpp | 8 +
core/sql/exp/ExpHbaseInterface.cpp | 8 +-
core/sql/exp/ExpHbaseInterface.h | 12 +-
core/sql/generator/Generator.cpp | 5 +
core/sql/optimizer/NAColumn.h | 43 +-
core/sql/optimizer/NARoutineDB.h | 3 -
core/sql/optimizer/NATable.cpp | 26 +-
.../sql/parser/StmtDDLAlterTableAlterColumn.cpp | 20 +-
core/sql/parser/StmtDDLAlterTableAlterColumn.h | 17 +-
core/sql/parser/sqlparser.y | 6 +-
core/sql/regress/compGeneral/EXPECTED071 | 8 +-
core/sql/regress/core/EXPECTED056.SB | 20 +-
core/sql/regress/core/EXPECTED116 | 8 +-
core/sql/regress/executor/EXPECTED013.SB | 38 +-
core/sql/regress/privs2/EXPECTED138 | 2 +-
core/sql/regress/seabase/EXPECTED011 | 101 +-
core/sql/regress/seabase/EXPECTED027 | 433 ++++-
core/sql/regress/seabase/TEST011 | 16 -
core/sql/regress/seabase/TEST027 | 58 +
core/sql/sqlcomp/CmpDescribe.cpp | 180 ++-
core/sql/sqlcomp/CmpSeabaseDDL.h | 69 +-
core/sql/sqlcomp/CmpSeabaseDDLcleanup.cpp | 2 +-
core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 252 ++-
core/sql/sqlcomp/CmpSeabaseDDLtable.cpp | 1525 ++++++++++++------
core/sql/sqlcomp/DefaultConstants.h | 4 +
core/sql/sqlcomp/nadefaults.cpp | 8 +-
.../java/org/trafodion/sql/HBaseClient.java | 33 +-
31 files changed, 2057 insertions(+), 914 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/cli/Statement.cpp
----------------------------------------------------------------------
diff --cc core/sql/cli/Statement.cpp
index 462e226,462e226..66d175c
--- a/core/sql/cli/Statement.cpp
+++ b/core/sql/cli/Statement.cpp
@@@ -6275,7 -6275,7 +6275,10 @@@ short Statement::beginTransaction(ComDi
// will be updated for BEGIN WORK statements.
updateTModeValues();
-- if (root_tdb->transactionReqd())
++ // implicit xns for ddl stmts will be started and committed/aborted
++ // in arkcmp
++ if ((root_tdb->transactionReqd()) &&
++ (NOT root_tdb->ddlQuery()))
{
// the trans mode at compile time of this query must be the
// same as the transaction mode at execution time.
@@@ -6412,30 -6412,30 +6415,29 @@@ short Statement::commitTransaction(ComD
// waited = TRUE;
short taRetcode = context_->commitTransaction(waited);
-- StmtDebug1(" Return code is %d", (Lng32) taRetcode);
++ StmtDebug1(" Return code is %d", (Lng32) taRetcode);
setAutocommitXn(FALSE);
if (taRetcode != 0)
{
-- // If there are diagnostics in the statement globals then add
-- // them to the caller's diags area first. They may contain
-- // information about something that went wrong before the
-- // COMMIT was attempted. Then add information about the COMMIT
-- // failure that just occurred.
-- statementGlobals_->takeGlobalDiagsArea(diagsArea);
-- diagsArea.mergeAfter(*context_->getTransaction()->getDiagsArea());
-- return ERROR;
-- }
--
-- StmtDebug0(" COMMIT was successful");
++ // If there are diagnostics in the statement globals then add
++ // them to the caller's diags area first. They may contain
++ // information about something that went wrong before the
++ // COMMIT was attempted. Then add information about the COMMIT
++ // failure that just occurred.
++ statementGlobals_->takeGlobalDiagsArea(diagsArea);
++
diagsArea.mergeAfter(*context_->getTransaction()->getDiagsArea());
++ return ERROR;
++ }
++ StmtDebug0(" COMMIT was successful");
++ }
}
-- }
else
-- {
-- StmtDebug0(" No AUTOCOMMIT transaction for this stmt");
++ {
++ StmtDebug0(" No AUTOCOMMIT transaction for this stmt");
}
--
++
return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/common/ComSmallDefs.h
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/executor/HBaseClient_JNI.cpp
----------------------------------------------------------------------
diff --cc core/sql/executor/HBaseClient_JNI.cpp
index 5dc8547,34ab08f..7f0fd22
--- a/core/sql/executor/HBaseClient_JNI.cpp
+++ b/core/sql/executor/HBaseClient_JNI.cpp
@@@ -452,9 -452,9 +452,9 @@@ HBC_RetCode HBaseClient_JNI::init(
JavaMethods_[JM_GET_REGION_STATS ].jm_name = "getRegionStats";
JavaMethods_[JM_GET_REGION_STATS ].jm_signature =
"(Ljava/lang/String;)Lorg/trafodion/sql/ByteArrayList;";
JavaMethods_[JM_COPY ].jm_name = "copy";
- JavaMethods_[JM_COPY ].jm_signature =
"(Ljava/lang/String;Ljava/lang/String;)Z";
+ JavaMethods_[JM_COPY ].jm_signature =
"(Ljava/lang/String;Ljava/lang/String;Z)Z";
JavaMethods_[JM_EXISTS ].jm_name = "exists";
- JavaMethods_[JM_EXISTS ].jm_signature = "(Ljava/lang/String;)Z";
+ JavaMethods_[JM_EXISTS ].jm_signature = "(Ljava/lang/String;J)Z";
JavaMethods_[JM_GRANT ].jm_name = "grant";
JavaMethods_[JM_GRANT ].jm_signature = "([B[B[Ljava/lang/Object;)Z";
JavaMethods_[JM_REVOKE ].jm_name = "revoke";
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/executor/HBaseClient_JNI.h
----------------------------------------------------------------------
diff --cc core/sql/executor/HBaseClient_JNI.h
index 3f13f8a,1ecd0e2..89217df
--- a/core/sql/executor/HBaseClient_JNI.h
+++ b/core/sql/executor/HBaseClient_JNI.h
@@@ -510,8 -510,9 +510,9 @@@ public
HBC_RetCode registerTruncateOnAbort(const char* fileName, Int64 transID);
HBC_RetCode drop(const char* fileName, bool async, Int64 transID);
HBC_RetCode drop(const char* fileName, JNIEnv* jenv, Int64 transID); //
thread specific
- HBC_RetCode dropAll(const char* pattern, bool async);
+ HBC_RetCode dropAll(const char* pattern, bool async, Int64 transID);
- HBC_RetCode copy(const char* currTblName, const char* oldTblName);
+ HBC_RetCode copy(const char* srcTblName, const char* tgtTblName,
+ NABoolean force);
ByteArrayList* listAll(const char* pattern);
ByteArrayList* getRegionStats(const char* tblName);
static HBC_RetCode flushAllTablesStatic();
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/executor/ex_transaction.cpp
----------------------------------------------------------------------
diff --cc core/sql/executor/ex_transaction.cpp
index 107f1f7,1e8deda..e508284
--- a/core/sql/executor/ex_transaction.cpp
+++ b/core/sql/executor/ex_transaction.cpp
@@@ -1219,25 -1264,6 +1219,27 @@@ short ExTransTcb::work(
rc = ta->commitTransaction(FALSE);
if (rc != 0)
handleErrors(pentry_down, ta->getDiagsArea());
+
+ if (cliGlobals->currContext()->ddlStmtsExecuted())
+ {
+ ComDiagsArea * diagsArea = NULL;
+ ExSqlComp::ReturnStatus cmpStatus =
+ cliGlobals->currContext()->sendXnMsgToArkcmp
+ (NULL, 0,
+ EXSQLCOMP::DDL_NATABLE_INVALIDATE,
+ diagsArea);
+ if (cmpStatus == ExSqlComp::ERROR)
+ {
++ cliGlobals->currContext()->ddlStmtsExecuted() = FALSE;
++
+ handleErrors(pentry_down, NULL,
+ (ExeErrorCode)(-EXE_CANT_COMMIT_OR_ROLLBACK));
+
+ return -1;
+ }
+ }
+
+ cliGlobals->currContext()->ddlStmtsExecuted() = FALSE;
// if user had specified AUTO COMMIT, turn it back on.
ta->enableAutoCommit();
@@@ -1262,26 -1288,7 +1264,28 @@@
rc = ta->commitTransaction(TRUE);
if (rc != 0)
handleErrors(pentry_down, ta->getDiagsArea());
-
+
+ if (cliGlobals->currContext()->ddlStmtsExecuted())
+ {
+ ComDiagsArea * diagsArea = NULL;
+ ExSqlComp::ReturnStatus cmpStatus =
+ cliGlobals->currContext()->sendXnMsgToArkcmp
+ (NULL, 0,
+ EXSQLCOMP::DDL_NATABLE_INVALIDATE,
+ diagsArea);
+ if (cmpStatus == ExSqlComp::ERROR)
+ {
++ cliGlobals->currContext()->ddlStmtsExecuted() = FALSE;
++
+ handleErrors(pentry_down, NULL,
+ (ExeErrorCode)(-EXE_CANT_COMMIT_OR_ROLLBACK));
+
+ return -1;
+ }
+ }
+
+ cliGlobals->currContext()->ddlStmtsExecuted() = FALSE;
+
// if user had specified AUTO COMMIT, turn it back on.
ta->enableAutoCommit();
}
@@@ -1309,25 -1316,6 +1313,27 @@@
// create a diagsArea and return it to the parent.
handleErrors(pentry_down, ta->getDiagsArea());
+ if (cliGlobals->currContext()->ddlStmtsExecuted())
+ {
+ ComDiagsArea * diagsArea = NULL;
+ ExSqlComp::ReturnStatus cmpStatus =
+ cliGlobals->currContext()->sendXnMsgToArkcmp
+ (NULL, 0,
+ EXSQLCOMP::DDL_NATABLE_INVALIDATE,
+ diagsArea);
+ if (cmpStatus == ExSqlComp::ERROR)
+ {
++ cliGlobals->currContext()->ddlStmtsExecuted() = FALSE;
++
+ handleErrors(pentry_down, NULL,
+ (ExeErrorCode)(-EXE_CANT_COMMIT_OR_ROLLBACK));
+
+ return -1;
+ }
+ }
+
+ cliGlobals->currContext()->ddlStmtsExecuted() = FALSE;
+
// if user had specified AUTO COMMIT, turn it back on.
ta->enableAutoCommit();
}
@@@ -1351,25 -1340,6 +1357,27 @@@
if (rc != 0)
handleErrors(pentry_down, ta->getDiagsArea());
+ if (cliGlobals->currContext()->ddlStmtsExecuted())
+ {
+ ComDiagsArea * diagsArea = NULL;
+ ExSqlComp::ReturnStatus cmpStatus =
+ cliGlobals->currContext()->sendXnMsgToArkcmp
+ (NULL, 0,
+ EXSQLCOMP::DDL_NATABLE_INVALIDATE,
+ diagsArea);
+ if (cmpStatus == ExSqlComp::ERROR)
+ {
++ cliGlobals->currContext()->ddlStmtsExecuted() = FALSE;
++
+ handleErrors(pentry_down, NULL,
+ (ExeErrorCode)(-EXE_CANT_COMMIT_OR_ROLLBACK));
+
+ return -1;
+ }
+ }
+
+ cliGlobals->currContext()->ddlStmtsExecuted() = FALSE;
+
// if user had specified AUTO COMMIT, turn it back on.
ta->enableAutoCommit();
}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/exp/ExpHbaseInterface.cpp
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/exp/ExpHbaseInterface.h
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/optimizer/NARoutineDB.h
----------------------------------------------------------------------
diff --cc core/sql/optimizer/NARoutineDB.h
index 3bc6ebe,c08ed18..9e91e8e
--- a/core/sql/optimizer/NARoutineDB.h
+++ b/core/sql/optimizer/NARoutineDB.h
@@@ -49,9 -49,9 +49,6 @@@ class NARoutineDB : public NAKeyLookup<
public:
-- // This same enum exists in NATableDB, should probably only have one copy
- // enum QiScope { REMOVE_FROM_ALL_USERS = 100, REMOVE_MINE_ONLY };
- enum QiScope { REMOVE_FROM_ALL_USERS = 100, REMOVE_MINE_ONLY };
--
NARoutineDB(NAMemory *h = 0);
void resetAfterStatement();
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/optimizer/NATable.cpp
----------------------------------------------------------------------
diff --cc core/sql/optimizer/NATable.cpp
index f77467c,0e59dcf..ef095ce
--- a/core/sql/optimizer/NATable.cpp
+++ b/core/sql/optimizer/NATable.cpp
@@@ -8361,40 -8364,6 +8364,53 @@@ void NATableDB::removeNATable2(CorrNam
}
}
+void NATableDB::removeNATable(CorrName &corrName, ComQiScope qiScope,
+ ComObjectType ot,
+ NABoolean ddlXns, NABoolean atCommit)
+{
+ // if ddl xns are being used, add this name to ddlObjsList and
+ // invalidate NATable in my environment. This will allow subsequent
+ // operations running in my environemnt under my current transaction
+ // to access the latest definition.
+ //
+ // NATable removal for other users will happen at xn commit/rollback time.
+ //
+ // If atCommit is set, then this is being called at commit time.
+ // In that case, do NATable removal processing for all users
+ // instead of adding to ddlObjsList.
+ //
+ // If ddl xns are not being used, then invalidate NATable cache for
+ // all users.
+ if ((ddlXns) &&
+ (NOT atCommit))
+ {
- removeNATable2(corrName, ComQiScope::REMOVE_MINE_ONLY, ot);
-
+ CmpContext::DDLObjInfo ddlObj;
+ ddlObj.ddlObjName = corrName.getQualifiedNameAsString();
+ ddlObj.qiScope = qiScope;
+ ddlObj.ot = ot;
- CmpCommon::context()->ddlObjsList().insert(ddlObj);
++
++ NABoolean found = FALSE;
++ for (Lng32 i = 0;
++ ((NOT found) && (i <
CmpCommon::context()->ddlObjsList().entries()));
++ i++)
++ {
++ CmpContext::DDLObjInfo &ddlObjInList =
++ CmpCommon::context()->ddlObjsList()[i];
++ if (ddlObj.ddlObjName == ddlObjInList.ddlObjName)
++ found = TRUE;
++ }
++
++ removeNATable2(corrName, qiScope, ot); //ComQiScope::REMOVE_MINE_ONLY,
ot);
++
++ if (NOT found)
++ CmpCommon::context()->ddlObjsList().insert(ddlObj);
+
+ return;
+ }
+
+ removeNATable2(corrName, qiScope, ot);
+}
+
//This method is called at the end of each statement to reset statement
//specific stuff in the NATable objects in the cache.
void NATableDB::resetAfterStatement(){
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/regress/core/EXPECTED056.SB
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/regress/core/EXPECTED116
----------------------------------------------------------------------
diff --cc core/sql/regress/core/EXPECTED116
index 5a36506,ec5d614..42092e2
--- a/core/sql/regress/core/EXPECTED116
+++ b/core/sql/regress/core/EXPECTED116
@@@ -327,242 -470,5 +327,242 @@@ A1 C1 B
--- 1 row(s) inserted.
>>
+>>-- tests to validate ddl definitions are correctly loaded
+>>drop table if exists t116t1;
+
+--- SQL operation complete.
+>>create table t116t1(a int not null, b varchar(2),
++> c varchar(4) character set utf8 not null);
+
+--- SQL operation complete.
+>>invoke t116t1;
+
+-- Definition of Trafodion table TRAFODION.SCH.T116T1
+-- Definition current Mon Feb 15 16:04:39 2016
+
+ (
+ A INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , B VARCHAR(2) CHARACTER SET ISO88591 COLLATE
+ DEFAULT DEFAULT NULL
+ , C VARCHAR(4 CHARS) CHARACTER SET UTF8
+ COLLATE DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
+ )
+
+--- SQL operation complete.
+>>begin work;
+
+--- SQL operation complete.
+>>alter table t116t1 alter column b varchar(3);
+
+--- SQL operation complete.
+>>invoke t116t1;
+
+-- Definition of Trafodion table TRAFODION.SCH.T116T1
+-- Definition current Mon Feb 15 16:04:40 2016
+
+ (
+ A INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , B VARCHAR(3) CHARACTER SET ISO88591 COLLATE
- DEFAULT DEFAULT NULL
++ DEFAULT DEFAULT NULL /*altered_col*/
+ , C VARCHAR(4 CHARS) CHARACTER SET UTF8
+ COLLATE DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
+ )
+
+--- SQL operation complete.
+>>commit work;
+
+--- SQL operation complete.
+>>invoke t116t1;
+
+-- Definition of Trafodion table TRAFODION.SCH.T116T1
+-- Definition current Mon Feb 15 16:04:51 2016
+
+ (
+ A INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , B VARCHAR(3) CHARACTER SET ISO88591 COLLATE
- DEFAULT DEFAULT NULL
++ DEFAULT DEFAULT NULL /*altered_col*/
+ , C VARCHAR(4 CHARS) CHARACTER SET UTF8
+ COLLATE DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
+ )
+
+--- SQL operation complete.
+>>
+>>begin work;
+
+--- SQL operation complete.
+>>alter table t116t1 alter column b varchar(4);
+
+--- SQL operation complete.
+>>invoke t116t1;
+
+-- Definition of Trafodion table TRAFODION.SCH.T116T1
+-- Definition current Mon Feb 15 16:04:52 2016
+
+ (
+ A INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , B VARCHAR(4) CHARACTER SET ISO88591 COLLATE
- DEFAULT DEFAULT NULL
++ DEFAULT DEFAULT NULL /*altered_col*/
+ , C VARCHAR(4 CHARS) CHARACTER SET UTF8
+ COLLATE DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
+ )
+
+--- SQL operation complete.
+>>rollback work;
+
+--- SQL operation complete.
+>>
+>>invoke t116t1;
+
+-- Definition of Trafodion table TRAFODION.SCH.T116T1
+-- Definition current Mon Feb 15 16:05:01 2016
+
+ (
+ A INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , B VARCHAR(3) CHARACTER SET ISO88591 COLLATE
- DEFAULT DEFAULT NULL
++ DEFAULT DEFAULT NULL /*altered_col*/
+ , C VARCHAR(4 CHARS) CHARACTER SET UTF8
+ COLLATE DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
+ )
+
+--- SQL operation complete.
+>>
+>>-- concurrent ddl operations
+>>drop table if exists t116t1;
+
+--- SQL operation complete.
+>>begin work;
+
+--- SQL operation complete.
+>>create table t116t1 (a int);
+
+--- SQL operation complete.
+>>
+>>sh sqlci -iTEST116\(concurrent_ddl\) >> LOG116;
+Apache Trafodion Conversational Interface 2.0.0
+Copyright (c) 2015 Apache Software Foundation
+>>?section concurrent_ddl
+>>cqd ddl_transactions 'ON';
+
+--- SQL operation complete.
+>>begin work;
+
+--- SQL operation complete.
+>>
+>>-- should fail
+>>create table t116t1 (a int);
+
+*** ERROR[1431] Object TRAFODION.SCH.T116T1 exists in HBase. This could be
due to a concurrent transactional ddl operation in progress on this table.
+
+*** ERROR[8839] Transaction was aborted.
+
+--- SQL operation failed with errors.
+>>commit work;
+
+*** ERROR[8605] Committing a transaction which has not started.
+
+--- SQL operation failed with errors.
+>>exit;
+
+End of MXCI Session
+
+>>
+>>commit work;
+
+--- SQL operation complete.
+>>invoke t116t1;
+
+-- Definition of Trafodion table TRAFODION.SCH.T116T1
+-- Definition current Mon Feb 15 16:05:22 2016
+
+ (
+ A INT DEFAULT NULL
+ )
+
+--- SQL operation complete.
+>>cleanup table t116t1;
+
+--- SQL operation complete.
+>>
+>>-- test table/schema drops and get stmts with read uncommitted access
+>>create schema if not exists t116sch1;
+
+--- SQL operation complete.
+>>set schema t116sch1;
+
+--- SQL operation complete.
+>>drop table if exists t116t1;
+
+--- SQL operation complete.
+>>drop table if exists t116t2;
+
+--- SQL operation complete.
+>>
+>>create table t116t1 (a int);
+
+--- SQL operation complete.
+>>begin work;
+
+--- SQL operation complete.
+>>get tables in schema t116sch1, match 'T116T1';
+
+Tables in Schema TRAFODION.T116SCH1
+===================================
+
+T116T1
+
+--- SQL operation complete.
+>>drop table t116t1;
+
+--- SQL operation complete.
+>>get tables in schema t116sch1;
+
+Tables in Schema TRAFODION.T116SCH1
+===================================
+
+SB_HISTOGRAMS
+SB_HISTOGRAM_INTERVALS
+
+--- SQL operation complete.
+>>create table t116t2 (a int);
+
+--- SQL operation complete.
+>>get tables in schema t116sch1;
+
+Tables in Schema TRAFODION.T116SCH1
+===================================
+
+SB_HISTOGRAMS
+SB_HISTOGRAM_INTERVALS
+T116T2
+
+--- SQL operation complete.
+>>drop schema t116sch1 cascade;
+
+--- SQL operation complete.
+>>get tables in schema t116sch1;
+
+--- SQL operation complete.
+>>select count(*) from "_MD_".objects where schema_name = 'T116SCH1'
++> for read uncommitted access;
+
+(EXPR)
+--------------------
+
+ 0
+
+--- 1 row(s) selected.
+>>rollback work;
+
+--- SQL operation complete.
+>>get tables in schema t116sch1;
+
+Tables in Schema TRAFODION.T116SCH1
+===================================
+
+SB_HISTOGRAMS
+SB_HISTOGRAM_INTERVALS
+T116T1
+
+--- SQL operation complete.
>>
>>log;
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/regress/executor/EXPECTED013.SB
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/regress/seabase/EXPECTED011
----------------------------------------------------------------------
diff --cc core/sql/regress/seabase/EXPECTED011
index 0b2cafa,61031c9..400317e
--- a/core/sql/regress/seabase/EXPECTED011
+++ b/core/sql/regress/seabase/EXPECTED011
@@@ -7,7 -7,7 +7,7 @@@
>>invoke T011T1;
-- Definition of Trafodion table TRAFODION.SCH.T011T1
- -- Definition current Wed Feb 10 17:28:56 2016
--- Definition current Wed Feb 24 09:06:39 2016
++-- Definition current Wed Mar 2 05:16:53 2016
(
A INT NO DEFAULT NOT NULL NOT DROPPABLE
@@@ -142,7 -142,7 +142,7 @@@ A
------------------------------------------------------------------ PLAN
SUMMARY
MODULE_NAME .............. DYNAMICALLY COMPILED
STATEMENT_NAME ........... NOT NAMED
- PLAN_ID .................. 212321885336541730
-PLAN_ID .................. 212323064800054288
++PLAN_ID .................. 212323655814425974
ROWS_OUT ................. 7
EST_TOTAL_COST ........... 0.01
STATEMENT ................ select * from t011t1 where a >= 3 and a < 5;
@@@ -182,7 -181,7 +182,7 @@@ DESCRIPTIO
SCHEMA ................. TRAFODION.SCH
QUERY_CACHE ............ 0
GENERATE_EXPLAIN ....... ON
- ObjectUIDs ............. 7276217900832183965
- ObjectUIDs ............. 2452863879398277316
++ ObjectUIDs ............. 4553793696580766799
select_list ............ TRAFODION.SCH.T011T1.A, TRAFODION.SCH.T011T1.B
@@@ -1269,7 -1268,7 +1269,7 @@@ METRIC_TEXT_TABL
>>invoke trafodion."_REPOS_".metric_query_table;
-- Definition of Trafodion table TRAFODION."_REPOS_".METRIC_QUERY_TABLE
- -- Definition current Wed Feb 10 17:31:00 2016
--- Definition current Wed Feb 24 09:08:40 2016
++-- Definition current Wed Mar 2 05:18:55 2016
(
INSTANCE_ID INT UNSIGNED NO DEFAULT NOT NULL NOT
@@@ -1451,7 -1450,7 +1451,7 @@@
>>-- get qid for the prepared stmt
>>get qid for statement explstmt;
- MXID11000029309212321885301727001000000000206U3333300_1921_EXPLSTMT
-MXID11000020741212323064781124001000000000206U3333300_1924_EXPLSTMT
++MXID11000008089212323655795185001000000000206U3333300_1994_EXPLSTMT
--- SQL operation complete.
>>
@@@ -1503,7 -1502,7 +1503,7 @@@ SEQ_NUM OPERATO
--- SQL command prepared.
>>get qid for statement explstmt2;
- MXID11000029309212321885301727001000000000206U3333300_1932_EXPLSTMT2
-MXID11000020741212323064781124001000000000206U3333300_1935_EXPLSTMT2
++MXID11000008089212323655795185001000000000206U3333300_2005_EXPLSTMT2
--- SQL operation complete.
>>set qid MXID123456 for explstmt2;
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/sqlcomp/CmpDescribe.cpp
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/sqlcomp/CmpSeabaseDDL.h
----------------------------------------------------------------------
diff --cc core/sql/sqlcomp/CmpSeabaseDDL.h
index 6d441b1,e616f85..e1eee25
--- a/core/sql/sqlcomp/CmpSeabaseDDL.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDL.h
@@@ -988,9 -1002,14 +1011,15 @@@ class CmpSeabaseDD
const NAString &catalogNamePart,
const NAString &schemaNamePart,
const NAString &objectNamePart,
- char * colName, const NAColumn * nacol,
+ const NATable * naTable,
+ const NAString &altColName,
- ElemDDLColDef *pColDef);
-
++ ElemDDLColDef *pColDef,
+ NABoolean ddlXns);
+
+ void alterSeabaseTableDropColumn(
+ StmtDDLAlterTableDropColumn * alterDropColNode,
+ NAString &currCatName, NAString &currSchName);
+
short recreateViews(ExeCliInterface &cliInterface,
NAList<NAString> &viewNameList,
NAList<NAString> &viewDefnList);
@@@ -999,6 -1018,21 +1028,22 @@@
StmtDDLAlterTableAlterColumnSetSGOption * alterIdentityColNode,
NAString &currCatName, NAString &currSchName);
+ short alignedFormatTableAlterColumn
+ (
+ const NAString &catalogNamePart,
+ const NAString &schemaNamePart,
+ const NAString &objectNamePart,
+ const NATable * naTable,
+ const NAString &altColName,
- ElemDDLColDef *pColDef);
++ ElemDDLColDef *pColDef,
++ NABoolean ddlXns);
+
+ short alterColumnAttr(
+ const NAString &catalogNamePart, const NAString &schemaNamePart,
+ const NAString &objectNamePart,
+ const NATable * naTable, const NAColumn * naCol, NAType * newType,
+ StmtDDLAlterTableAlterColumnDatatype * alterColNode);
+
void alterSeabaseTableAlterColumnDatatype(
StmtDDLAlterTableAlterColumnDatatype * alterColumnDatatype,
NAString &currCatName, NAString &currSchName);
@@@ -1150,9 -1183,15 +1195,15 @@@
const ComObjectType objType);
- short dropSeabaseObjectsFromHbase(const char * pattern);
+ short dropSeabaseObjectsFromHbase(const char * pattern, NABoolean ddlXns);
short updateSeabaseAuths(ExeCliInterface * cliInterface, const char *
sysCat);
+ short truncateHbaseTable(const NAString &catalogNamePart,
+ const NAString &schemaNamePart,
+ const NAString &objectNamePart,
+ NATable * naTable,
+ ExpHbaseInterface * ehi);
+
void purgedataHbaseTable(DDLExpr * ddlExpr,
NAString &currCatName, NAString &currSchName);
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/sqlcomp/CmpSeabaseDDLcleanup.cpp
----------------------------------------------------------------------
diff --cc core/sql/sqlcomp/CmpSeabaseDDLcleanup.cpp
index f51c6ce,3fa0b16..3648cc3
--- a/core/sql/sqlcomp/CmpSeabaseDDLcleanup.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcleanup.cpp
@@@ -1092,7 -1089,7 +1092,7 @@@ short CmpSeabaseMDcleanup::cleanupOrpha
NABoolean errorSeen = FALSE;
// find out all entries which do not have corresponsing hbase objects
- str_sprintf(query, "select object_uid, trim(catalog_name) || '.' ||
trim(schema_name) || '.' || trim(object_name) from %s.\"%s\".%s where
catalog_name = '%s' and schema_name not in ( '_MD_', '_REPOS_', '_PRIVMGR_MD_')
and schema_name not like '|_HV|_%%' escape '|' and schema_name not like
'|_HB|_%%' escape '|' and (object_type = 'BT' or object_type = 'IX') ",
- str_sprintf(query, "select object_uid, trim(catalog_name) || '.' ||
trim(schema_name) || '.' || trim(object_name) from %s.\"%s\".%s where
catalog_name = '%s' and schema_name not in ( '_MD_', '_REPOS_', 'PRIVMGR_MD')
and (object_type = 'BT' or object_type = 'IX') ",
++ str_sprintf(query, "select object_uid, trim(catalog_name) || '.' ||
trim(schema_name) || '.' || trim(object_name) from %s.\"%s\".%s where
catalog_name = '%s' and schema_name not in ( '_MD_', '_REPOS_', '_PRIVMGR_MD_')
and schema_name not like '|_HV|_%%|_' escape '|' and schema_name not like
'|_HB|_%%|_' escape '|' and (object_type = 'BT' or object_type = 'IX') ",
getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS,
getSystemCatalog());
cliRC = cliInterface->fetchRowsPrologue(query);
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
----------------------------------------------------------------------
diff --cc core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
index 69ed4c8,2d97501..938d8f2
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
@@@ -7871,6 -7862,95 +7932,98 @@@ void CmpSeabaseDDL::updateVersion(
}
+ // this method truncates an hbase table by dropping it and then recreating
+ // it. Options that were used for the original hbase table are stored in
+ // traf metadata and are passed in to hbase during table create.
+ // When hbase truncate api is available (HBAse 1.0 and later), then this
+ // method will call it instead of drop/recreate.
++// truncate is a non-transactional operation. Caller need to restore back
++// the truncated table if an error occurs.
+ short CmpSeabaseDDL::truncateHbaseTable(const NAString &catalogNamePart,
+ const NAString &schemaNamePart,
+ const NAString &objectNamePart,
+ NATable * naTable,
+ ExpHbaseInterface * ehi)
+ {
+ Lng32 retcode = 0;
+
+ const NAString extNameForHbase =
+ catalogNamePart + "." + schemaNamePart + "." + objectNamePart;
+
+ HbaseStr hbaseTable;
+ hbaseTable.val = (char*)extNameForHbase.data();
+ hbaseTable.len = extNameForHbase.length();
+
+ // drop this table from hbase
- retcode = dropHbaseTable(ehi, &hbaseTable, FALSE);
++ retcode = dropHbaseTable(ehi, &hbaseTable, FALSE, FALSE);
+ if (retcode)
+ {
+ deallocEHI(ehi);
+
+ processReturn();
+
+ return -1;
+ }
+
+ // and recreate it.
+ NAFileSet * naf = naTable->getClusteringIndex();
+
+ NAList<HbaseCreateOption*> * hbaseCreateOptions =
+ naTable->hbaseCreateOptions();
+ Lng32 numSaltPartns = naf->numSaltPartns();
+ Lng32 numSaltSplits = numSaltPartns - 1;
+ Lng32 numSplits = 0;
+ const Lng32 numKeys = naf->getIndexKeyColumns().entries();
+ 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();
+
+ if (createEncodedKeysBuffer(encodedKeysBuffer/*out*/,
+ numSplits/*out*/,
+ colDescs, keyDescs,
+ numSaltPartns,
+ numSaltSplits,
+ NULL,
+ numKeys,
+ keyLength,
+ FALSE))
+ {
+ deallocEHI(ehi);
+
+ processReturn();
+
+ return -1;
+ }
+
+ std::vector<NAString> userColFamVec;
+ std::vector<NAString> trafColFamVec;
+ NAString outColFam;
+ for (int i = 0; i < naTable->allColFams().entries(); i++)
+ {
+ processColFamily(naTable->allColFams()[i], outColFam,
+ &userColFamVec, &trafColFamVec);
+ } // for
+
+ retcode = createHbaseTable(ehi, &hbaseTable, trafColFamVec,
+ hbaseCreateOptions,
+ numSplits, keyLength,
- encodedKeysBuffer);
++ encodedKeysBuffer,
++ FALSE);
+ if (retcode == -1)
+ {
+ deallocEHI(ehi);
+
+ processReturn();
+
+ return -1;
+ }
+
+ return 0;
+ }
+
void CmpSeabaseDDL::purgedataHbaseTable(DDLExpr * ddlExpr,
NAString &currCatName, NAString
&currSchName)
{
@@@ -8036,15 -8116,9 +8189,9 @@@
}
NABoolean asyncDrop = (CmpCommon::getDefault(HBASE_ASYNC_DROP_TABLE) ==
DF_ON);
-
- HbaseStr hbaseTable;
- hbaseTable.val = (char*)extNameForHbase.data();
- hbaseTable.len = extNameForHbase.length();
-
- // drop this table from hbase
-
+ NABoolean ddlXns = ddlExpr->ddlXns();
- retcode = dropHbaseTable(ehi, &hbaseTable, FALSE, ddlXns);
- if (retcode)
+ if (truncateHbaseTable(catalogNamePart, schemaNamePart, objectNamePart,
+ naTable, ehi))
{
deallocEHI(ehi);
@@@ -8239,71 -8258,37 +8331,80 @@@ short CmpSeabaseDDL::executeSeabaseDDL(
}
NABoolean startXn = TRUE;
- if ((ddlExpr->dropHbase()) ||
- (ddlExpr->purgedataHbase()) ||
- (ddlExpr->initHbase()) ||
- (ddlExpr->createMDViews()) ||
- (ddlExpr->dropMDViews()) ||
- (ddlExpr->initAuthorization()) ||
- (ddlExpr->dropAuthorization()) ||
- (ddlExpr->addSeqTable()) ||
- (ddlExpr->createRepos()) ||
- (ddlExpr->dropRepos()) ||
- (ddlExpr->upgradeRepos()) ||
- (ddlExpr->addSchemaObjects()) ||
- (ddlExpr->updateVersion()) ||
- ((ddlNode) &&
- // TODO: When making ALTER TABLE/INDEX transactional, add cases here
for them
- ((ddlNode->getOperatorType() == DDL_DROP_SCHEMA) ||
- (ddlNode->getOperatorType() == DDL_CLEANUP_OBJECTS) ||
- (ddlNode->getOperatorType() ==
DDL_ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY) ||
- (ddlNode->getOperatorType() ==
DDL_ALTER_TABLE_ALTER_COLUMN_SET_SG_OPTION) ||
- (ddlNode->getOperatorType() == DDL_CREATE_INDEX) ||
- (ddlNode->getOperatorType() == DDL_POPULATE_INDEX) ||
- (ddlNode->getOperatorType() == DDL_CREATE_TABLE) ||
- (ddlNode->getOperatorType() == DDL_ALTER_TABLE_DROP_COLUMN) ||
- (ddlNode->getOperatorType() == DDL_ALTER_TABLE_ALTER_COLUMN_DATATYPE)
||
-
- (ddlNode->getOperatorType() == DDL_DROP_TABLE))))
+
+ // no DDL transactions.
+ if ((NOT ddlExpr->ddlXns()) &&
+ ((ddlExpr->dropHbase()) ||
+ (ddlExpr->purgedataHbase()) ||
+ (ddlExpr->initHbase()) ||
+ (ddlExpr->createMDViews()) ||
+ (ddlExpr->dropMDViews()) ||
+ (ddlExpr->initAuthorization()) ||
+ (ddlExpr->dropAuthorization()) ||
+ (ddlExpr->addSeqTable()) ||
+ (ddlExpr->createRepos()) ||
+ (ddlExpr->dropRepos()) ||
+ (ddlExpr->upgradeRepos()) ||
+ (ddlExpr->addSchemaObjects()) ||
+ (ddlExpr->updateVersion())))
+ {
+ // transaction will be started and commited in called methods.
+ startXn = FALSE;
+ }
+
+ // no DDL transactions
+ if (((ddlNode) && (ddlNode->castToStmtDDLNode()) &&
+ (NOT ddlNode->castToStmtDDLNode()->ddlXns())) &&
+ ((ddlNode->getOperatorType() == DDL_DROP_SCHEMA) ||
+ (ddlNode->getOperatorType() == DDL_CLEANUP_OBJECTS) ||
+ (ddlNode->getOperatorType() ==
DDL_ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY) ||
+ (ddlNode->getOperatorType() ==
DDL_ALTER_TABLE_ALTER_COLUMN_SET_SG_OPTION) ||
+ (ddlNode->getOperatorType() == DDL_CREATE_INDEX) ||
+ (ddlNode->getOperatorType() == DDL_POPULATE_INDEX) ||
+ (ddlNode->getOperatorType() == DDL_CREATE_TABLE) ||
+ (ddlNode->getOperatorType() == DDL_ALTER_TABLE_DROP_COLUMN) ||
++ (ddlNode->getOperatorType() == DDL_ALTER_TABLE_ALTER_COLUMN_DATATYPE)
||
+ (ddlNode->getOperatorType() == DDL_DROP_TABLE)))
+ {
+ // transaction will be started and commited in called methods.
+ startXn = FALSE;
+ }
-
++
++ NABoolean ddlXns = FALSE;
++ if ((ddlExpr->ddlXns()) ||
++ ((ddlNode && ddlNode->castToStmtDDLNode() &&
++ ddlNode->castToStmtDDLNode()->ddlXns())))
++ ddlXns = TRUE;
++
+ // ddl transactions are on.
+ // Following commands currently require transactions be started and
+ // committed in the called methods.
+ if ((ddlExpr->ddlXns()) &&
+ (
+ (ddlExpr->purgedataHbase()) ||
+ (ddlExpr->initAuthorization()) ||
+ (ddlExpr->dropAuthorization()) ||
+ (ddlExpr->upgradeRepos())
+ )
+ )
{
// transaction will be started and commited in called methods.
startXn = FALSE;
}
+ // ddl transactions are on.
- // Cleanup command requires transactions to be started and commited
++ // Cleanup and alter commands requires transactions to be started and
commited
+ // in the called method.
+ if ((ddlNode && ddlNode->castToStmtDDLNode() &&
+ ddlNode->castToStmtDDLNode()->ddlXns()) &&
- (ddlNode->getOperatorType() == DDL_CLEANUP_OBJECTS))
++ ((ddlNode->getOperatorType() == DDL_CLEANUP_OBJECTS) ||
++ (ddlNode->getOperatorType() == DDL_ALTER_TABLE_DROP_COLUMN) ||
++ (ddlNode->getOperatorType() ==
DDL_ALTER_TABLE_ALTER_COLUMN_DATATYPE)))
+ {
+ // transaction will be started and commited in called methods.
+ startXn = FALSE;
+ }
+
if (startXn)
{
if (beginXnIfNotInProgress(&cliInterface, xnWasStartedHere))
@@@ -8819,7 -8802,7 +8920,24 @@@ label_return
restoreAllControlsAndFlags();
if (CmpCommon::diags()->getNumber(DgSqlCode::ERROR_))
-- cliRC = -1;
++ {
++ cliRC = -1;
++
++ // some ddl stmts are executed as multiple sub statements.
++ // with ddl xns, some of those sub stmts may abort the enclosing
++ // xn in case of an error amd add an error condition that the xn
++ // was aborted.
++ // remove that error condition from the diags area. But dont do it
++ // if it is main error.
++ if (ddlXns && xnWasStartedHere &&
++ (CmpCommon::diags()->mainSQLCODE() !=
-CLI_VALIDATE_TRANSACTION_ERROR))
++ {
++ CollIndex i =
++ CmpCommon::diags()->returnIndex(-CLI_VALIDATE_TRANSACTION_ERROR);
++ if (i != NULL_COLL_INDEX)
++ CmpCommon::diags()->deleteError(i);
++ }
++ }
if (endXnIfStartedHere(&cliInterface, xnWasStartedHere, cliRC) < 0)
return -1;
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------
diff --cc core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
index 0fdc2a9,9ebf15e..42d932f
--- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
@@@ -4262,157 -4114,108 +4157,108 @@@ short CmpSeabaseDDL::createSeabaseTable
done = TRUE;
}
- cliRC = cliInterface.executeImmediate((char*)query.data());
- if (cliRC < 0)
- {
- cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
- goto label_error;
- }
-
- // naTable = bindWA.getNATable((isAdd ? currTabCN : newTempTabCN));
- naTable = bindWA.getNATable(newTempTabCN);
- if (! naTable)
- {
- goto label_error;
- }
+ query += ";";
- // update metadata to change column type to 'A'(added)
- if (isAdd)
- {
- str_sprintf(queryBuf, "update %s.\"%s\".%s set column_class = 'A' where
object_uid = %Ld and column_name = '%s' ",
- getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS,
- naTable->objectUid().castToInt64(), colName);
-
- cliRC = cliInterface.executeImmediate(queryBuf);
- if (cliRC < 0)
- {
- cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
- goto label_error;
- }
-
- }
+ // send any user CQDs down
+ Lng32 retCode = sendAllControls(FALSE, FALSE, TRUE);
- // insert data from current table into new temp table.
- // query = "upsert using load into ";
- query = "insert into ";
- query += newTempTabStr;
- query += " ";
+ ExeCliInterface cliInterface(STMTHEAP, NULL, NULL,
+ CmpCommon::context()->sqlSession()->getParentQid());
- for (Lng32 i = 0; i < naTable->getNAColumnArray().entries(); i++)
+ Lng32 cliRC = 0;
+ cliRC = cliInterface.executeImmediate((char*)query.data());
+ if (cliRC < 0)
{
- const NAColumn *nac = naTable->getNAColumnArray()[i];
-
- if (nac->isSystemColumn())
- continue;
-
- if ((isAdd) && (colName == nac->getColName()))
- continue;
-
- colNames += nac->getColName();
-
- colNames += ",";
+ cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+ return -1;
}
- // remove last comma
- colNames = colNames.strip(NAString::trailing, ',');
-
- query += "(" + colNames + ")";
+ return 0;
+ }
- query += " select ";
- query += colNames;
+ short CmpSeabaseDDL::cloneHbaseTable(
+ const NAString &srcTable, const NAString &clonedTable,
+ ExpHbaseInterface * inEHI)
+ {
+ HbaseStr hbaseTable;
+ hbaseTable.val = (char*)srcTable.data();
+ hbaseTable.len = srcTable.length();
- query += " from ";
- query += currTabStr;
+ HbaseStr clonedHbaseTable;
+ clonedHbaseTable.val = (char*)clonedTable.data();
+ clonedHbaseTable.len = clonedTable.length();
- query += ";";
+ ExpHbaseInterface * ehi = (inEHI ? inEHI : allocEHI());
- cliRC = cliInterface.executeImmediate(query.data());
- if (cliRC < 0)
+ // copy hbaseTable as clonedHbaseTable
+ if (ehi->copy(hbaseTable, clonedHbaseTable, TRUE))
{
- cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+ if (! inEHI)
+ deallocEHI(ehi);
processReturn();
-
- goto label_error;
- }
-
- // rename current table to temp
- str_sprintf(queryBuf, "alter table \"%s\".\"%s\".\"%s\" rename to \"%s\" ",
- catalogNamePart.data(), schemaNamePart.data(),
objectNamePart.data(),
- currTempTab.data());
-
- cliRC = cliInterface.executeImmediate(queryBuf);
- if (cliRC < 0)
- {
- cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
- processReturn();
-
- goto label_error;
+ return -1;
}
- // rename new temp table to current table
- str_sprintf(queryBuf, "alter table \"%s\".\"%s\".\"%s\" rename to \"%s\" ",
- catalogNamePart.data(), schemaNamePart.data(),
newTempTab.data(),
- objectNamePart.data());
-
- cliRC = cliInterface.executeImmediate(queryBuf);
- if (cliRC < 0)
- {
- cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
-
- processReturn();
+ if (! inEHI)
+ deallocEHI(ehi);
+
+ return 0;
+ }
- goto label_error1;
- }
+ short CmpSeabaseDDL::cloneSeabaseTable(
+ CorrName &cn,
+ const NATable * naTable,
+ const NAString &clonedTableName,
+ ExpHbaseInterface * inEHI,
+ ExeCliInterface * cliInterface)
+ {
+ Lng32 cliRC = 0;
+ Lng32 retcode = 0;
- // drop curr temp table
- str_sprintf(queryBuf, "drop table \"%s\".\"%s\".\"%s\" ",
- catalogNamePart.data(), schemaNamePart.data(),
currTempTab.data(),
- objectNamePart.data());
-
- cliRC = cliInterface.executeImmediate(queryBuf);
+ retcode = createSeabaseTableLike2(cn, clonedTableName);
+ if (retcode)
+ return -1;
+
+ ComObjectName tableName(clonedTableName, COM_TABLE_NAME);
+ const NAString catalogNamePart = tableName.getCatalogNamePartAsAnsiString();
+ const NAString schemaNamePart =
tableName.getSchemaNamePartAsAnsiString(TRUE);
+ const NAString objectNamePart =
tableName.getObjectNamePartAsAnsiString(TRUE);
+ Int64 clonedTableUID =
+ getObjectUID
+ (cliInterface,
+ catalogNamePart.data(), schemaNamePart.data(), objectNamePart.data(),
+ COM_BASE_TABLE_OBJECT_LIT);
+
+ char buf[2000];
+ str_sprintf(buf, "merge into %s.\"%s\".%s using (select column_name,
column_class from %s.\"%s\".%s where object_uid = %Ld) x on (object_uid = %Ld
and column_name = x.column_name) when matched then update set column_class =
x.column_class;",
+ getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS,
+ getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS,
+ naTable->objectUid().castToInt64(),
+ clonedTableUID);
+ cliRC = cliInterface->executeImmediate(buf);
if (cliRC < 0)
{
- cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
-
+ cliInterface->retrieveSQLDiagnostics(CmpCommon::diags());
processReturn();
- goto label_error0;
+ return -1;
}
+
+ const NAString extNameForHbase =
+ cn.getQualifiedNameObj().getCatalogName() + "." +
+ cn.getQualifiedNameObj().getSchemaName() + "." +
+ cn.getQualifiedNameObj().getObjectName();
- if (recreateViews(cliInterface, viewNameList, viewDefnList))
+ if (cloneHbaseTable(extNameForHbase, clonedTableName, inEHI))
{
+ processReturn();
+
return -1;
}
-
+
return 0;
-
- label_error1:
- // rename current temp table to current
- str_sprintf(queryBuf, "alter table \"%s\".\"%s\".\"%s\" rename to \"%s\" ",
- catalogNamePart.data(), schemaNamePart.data(),
currTempTab.data(),
- objectNamePart.data());
-
- cliRC = cliInterface.executeImmediate(queryBuf);
-
- label_error:
- cleanupObjectAfterError(cliInterface,
- catalogNamePart, schemaNamePart, newTempTab,
- COM_BASE_TABLE_OBJECT, ddlXns);
-
- recreateViews(cliInterface, viewNameList, viewDefnList);
-
- return -1;
-
- label_error0:
- cleanupObjectAfterError(cliInterface,
- catalogNamePart, schemaNamePart, currTempTab,
- COM_BASE_TABLE_OBJECT, ddlXns);
-
- recreateViews(cliInterface, viewNameList, viewDefnList);
-
- return -1;
}
short CmpSeabaseDDL::recreateViews(ExeCliInterface &cliInterface,
@@@ -4973,6 -4966,6 +5013,15 @@@ void CmpSeabaseDDL::alterSeabaseTableDr
<< DgColumnName(colName);
}
++ // this operation cannot be done if a xn is already in progress.
++ if (xnInProgress(&cliInterface))
++ {
++ *CmpCommon::diags() << DgSqlCode(-20123);
++
++ processReturn();
++ return;
++ }
++
Int64 objUID = naTable->objectUid().castToInt64();
NABoolean xnWasStartedHere = FALSE;
@@@ -4981,11 -4974,12 +5030,12 @@@
char *col = NULL;
if (naTable->isSQLMXAlignedTable())
{
- if (alignedFormatTableAddDropColumn(naTable->objectUid().castToInt64(),
- FALSE, // drop col
- catalogNamePart, schemaNamePart,
objectNamePart,
- (char*)colName.data(), NULL,
- alterDropColNode->ddlXns()))
+ if (alignedFormatTableDropColumn
+ (
+ catalogNamePart, schemaNamePart, objectNamePart,
+ naTable,
+ alterDropColNode->getColName(),
- NULL))
++ NULL, alterDropColNode->ddlXns()))
{
processReturn();
return;
@@@ -5312,154 -5236,479 +5294,500 @@@ void CmpSeabaseDDL::alterSeabaseTableAl
}
}
- // CorrName cn(objectNamePart, STMTHEAP, schemaNamePart, catalogNamePart);
- ActiveSchemaDB()->getNATableDB()->removeNATable(cn,
- NATableDB::REMOVE_FROM_ALL_USERS, COM_BASE_TABLE_OBJECT);
+ ActiveSchemaDB()->getNATableDB()->removeNATable
+ (cn,
+ ComQiScope::REMOVE_FROM_ALL_USERS, COM_BASE_TABLE_OBJECT,
+ alterIdentityColNode->ddlXns(), FALSE);
return;
}
- void CmpSeabaseDDL::alterSeabaseTableAlterColumnDatatype(
- StmtDDLAlterTableAlterColumnDatatype * alterColNode,
- NAString &currCatName, NAString &currSchName)
+ ///////////////////////////////////////////////////////////////////////
+ //
+ // An aligned table constains all columns in one hbase cell.
+ // To drop a column, we need to read each row, create a
+ // new row with the removed column and insert into the original table.
+ //
+ // Steps to drop a column from an aligned table:
+ //
+ // -- make a copy of the source aligned table using hbase copy
+ // -- truncate the source table
+ // -- Update metadata and remove the dropped column.
+ // -- bulk load data from copied table into the source table
+ // -- drop the copied temp table
+ //
+ // If an error happens after the source table has been truncated, then
+ // it will be restored from the copied table.
+ //
+ ///////////////////////////////////////////////////////////////////////
+ short CmpSeabaseDDL::alignedFormatTableDropColumn
+ (
+ const NAString &catalogNamePart,
+ const NAString &schemaNamePart,
+ const NAString &objectNamePart,
+ const NATable * naTable,
+ const NAString &altColName,
- ElemDDLColDef *pColDef)
++ ElemDDLColDef *pColDef,
++ NABoolean ddlXns)
{
Lng32 cliRC = 0;
- Lng32 retcode = 0;
- const NAString &tabName = alterColNode->getTableName();
+ const NAFileSet * naf = naTable->getClusteringIndex();
+
+ CorrName cn(objectNamePart, STMTHEAP, schemaNamePart, catalogNamePart);
- ComObjectName tableName(tabName, COM_TABLE_NAME);
- ComAnsiNamePart currCatAnsiName(currCatName);
- ComAnsiNamePart currSchAnsiName(currSchName);
- tableName.applyDefaults(currCatAnsiName, currSchAnsiName);
+ ComUID comUID;
+ comUID.make_UID();
+ Int64 objUID = comUID.get_value();
+
+ char objUIDbuf[100];
- const NAString catalogNamePart = tableName.getCatalogNamePartAsAnsiString();
- const NAString schemaNamePart =
tableName.getSchemaNamePartAsAnsiString(TRUE);
- const NAString objectNamePart =
tableName.getObjectNamePartAsAnsiString(TRUE);
- const NAString extTableName = tableName.getExternalName(TRUE);
- const NAString extNameForHbase = catalogNamePart + "." + schemaNamePart +
"." + objectNamePart;
+ NAString tempTable(naTable->getTableName().getQualifiedNameAsAnsiString());
+ tempTable += "_";
+ tempTable += str_ltoa(objUID, objUIDbuf);
- ExeCliInterface cliInterface(STMTHEAP, NULL, NULL,
- CmpCommon::context()->sqlSession()->getParentQid());
+ ExpHbaseInterface * ehi = allocEHI();
+ ExeCliInterface cliInterface
+ (STMTHEAP, NULL, NULL,
+ CmpCommon::context()->sqlSession()->getParentQid());
- if ((isSeabaseReservedSchema(tableName)) &&
- (!Get_SqlParser_Flags(INTERNAL_QUERY_FROM_EXEUTIL)))
+ Int64 tableUID = naTable->objectUid().castToInt64();
+ const NAColumnArray &naColArr = naTable->getNAColumnArray();
+ const NAColumn * altNaCol = naColArr.getColumn(altColName);
+ Lng32 altColNum = altNaCol->getPosition();
+
+ NAString tgtCols;
+ NAString srcCols;
+
+ NABoolean xnWasStartedHere = FALSE;
+
+ char buf[4000];
+
+ if (cloneSeabaseTable(cn, naTable, tempTable, ehi, &cliInterface))
{
- *CmpCommon::diags() <<
DgSqlCode(-CAT_CANNOT_ALTER_DEFINITION_METADATA_SCHEMA);
- processReturn();
- return;
+ cliRC = -1;
+ goto label_drop;
}
-
- ExpHbaseInterface * ehi = allocEHI();
- if (ehi == NULL)
+
+ if (truncateHbaseTable(catalogNamePart, schemaNamePart, objectNamePart,
+ (NATable*)naTable, ehi))
{
- processReturn();
-
- return;
+ cliRC = -1;
+ goto label_restore;
}
- retcode = existsInSeabaseMDTable(&cliInterface,
- catalogNamePart, schemaNamePart,
objectNamePart,
- COM_BASE_TABLE_OBJECT,
-
(Get_SqlParser_Flags(INTERNAL_QUERY_FROM_EXEUTIL)
- ? FALSE : TRUE),
- TRUE, TRUE);
- if (retcode < 0)
+ if (beginXnIfNotInProgress(&cliInterface, xnWasStartedHere))
{
- processReturn();
-
- return;
+ cliRC = -1;
+ goto label_restore;
}
- ActiveSchemaDB()->getNATableDB()->useCache();
-
- BindWA bindWA(ActiveSchemaDB(), CmpCommon::context(), FALSE/*inDDL*/);
- CorrName cn(tableName.getObjectNamePart().getInternalName(),
- STMTHEAP,
- tableName.getSchemaNamePart().getInternalName(),
- tableName.getCatalogNamePart().getInternalName());
+ if (updateMDforDropCol(cliInterface, naTable, altColNum))
+ {
+ cliRC = -1;
+ goto label_restore;
+ }
+
+ ActiveSchemaDB()->getNATableDB()->removeNATable
+ (cn,
- NATableDB::REMOVE_FROM_ALL_USERS,
- COM_BASE_TABLE_OBJECT);
++ ComQiScope::REMOVE_FROM_ALL_USERS,
++ COM_BASE_TABLE_OBJECT, ddlXns, FALSE);
- NATable *naTable = bindWA.getNATable(cn);
- if (naTable == NULL || bindWA.errStatus())
+ for (Int32 c = 0; c < naColArr.entries(); c++)
{
- *CmpCommon::diags()
- << DgSqlCode(-4082)
- << DgTableName(cn.getExposedNameAsAnsiString());
-
- processReturn();
+ const NAColumn * nac = naColArr[c];
+ if (nac->getColName() == altColName)
+ continue;
- return;
- }
+ if (nac->isComputedColumn())
+ continue;
- // Make sure user has the privilege to perform the alter column
- if (!isDDLOperationAuthorized(SQLOperation::ALTER_TABLE,
-
naTable->getOwner(),naTable->getSchemaOwner()))
- {
- *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED);
+ if (nac->isSystemColumn())
+ continue;
- processReturn ();
+ tgtCols += nac->getColName();
+ tgtCols += ",";
+ } // for
- return;
- }
+ tgtCols = tgtCols.strip(NAString::trailing, ',');
- // return an error if trying to alter a column from a volatile table
- if (naTable->isVolatileTable())
+ str_sprintf(buf, "upsert using load into %s(%s) select %s from %s",
+ naTable->getTableName().getQualifiedNameAsAnsiString().data(),
+ tgtCols.data(),
+ tgtCols.data(),
+ tempTable.data());
+ cliRC = cliInterface.executeImmediate(buf);
+ if (cliRC < 0)
{
- *CmpCommon::diags() <<
DgSqlCode(-CAT_REGULAR_OPERATION_ON_VOLATILE_OBJECT);
-
- processReturn ();
-
- return;
+ cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+ goto label_restore;
}
- const NAColumnArray &nacolArr = naTable->getNAColumnArray();
- const NAString &colName = alterColNode->getColumnName();
+ endXnIfStartedHere(&cliInterface, xnWasStartedHere, 0);
- const NAColumn * nacol = nacolArr.getColumn(colName);
- if (! nacol)
+ str_sprintf(buf, "drop table %s", tempTable.data());
+ cliRC = cliInterface.executeImmediate(buf);
+ if (cliRC < 0)
{
- // column doesnt exist. Error.
- *CmpCommon::diags() << DgSqlCode(-CAT_COLUMN_DOES_NOT_EXIST_ERROR)
- << DgColumnName(colName);
+ cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+ goto label_restore;
+ }
+
+ deallocEHI(ehi);
+
+ return 0;
+
+ label_restore:
+ endXnIfStartedHere(&cliInterface, xnWasStartedHere, -1);
+
+ cloneHbaseTable(tempTable,
+ naTable->getTableName().getQualifiedNameAsAnsiString(),
+ ehi);
+
+ label_drop:
+ str_sprintf(buf, "drop table %s", tempTable.data());
+ Lng32 cliRC2 = cliInterface.executeImmediate(buf);
+
+ deallocEHI(ehi);
+
+ return (cliRC < 0 ? -1 : 0);
+ }
+
+ ///////////////////////////////////////////////////////////////////////
+ //
+ // An aligned table constains all columns in one hbase cell.
+ // To alter a column, we need to read each row, create a
+ // new row with the altered column and insert into the original table.
+ //
+ // Steps to alter a column from an aligned table:
+ //
+ // -- make a copy of the source aligned table using hbase copy
+ // -- truncate the source table
+ // -- Update metadata column definition with the new definition
+ // -- bulk load data from copied table into the source table
+ // -- drop the copied temp table
+ //
+ // If an error happens after the source table has been truncated, then
+ // it will be restored from the copied table.
+ //
+ ///////////////////////////////////////////////////////////////////////
+ short CmpSeabaseDDL::alignedFormatTableAlterColumn
+ (
+ const NAString &catalogNamePart,
+ const NAString &schemaNamePart,
+ const NAString &objectNamePart,
+ const NATable * naTable,
+ const NAString &altColName,
- ElemDDLColDef *pColDef)
++ ElemDDLColDef *pColDef,
++ NABoolean ddlXns)
+ {
+ Lng32 cliRC = 0;
+
+ const NAFileSet * naf = naTable->getClusteringIndex();
+
+ CorrName cn(objectNamePart, STMTHEAP, schemaNamePart, catalogNamePart);
+
+ ComUID comUID;
+ comUID.make_UID();
+ Int64 objUID = comUID.get_value();
+
+ char objUIDbuf[100];
+
+ NAString tempTable(naTable->getTableName().getQualifiedNameAsAnsiString());
+ tempTable += "_";
+ tempTable += str_ltoa(objUID, objUIDbuf);
+
+ ExpHbaseInterface * ehi = allocEHI();
+ ExeCliInterface cliInterface
+ (STMTHEAP, NULL, NULL,
+ CmpCommon::context()->sqlSession()->getParentQid());
+
+ Int64 tableUID = naTable->objectUid().castToInt64();
+ const NAColumnArray &naColArr = naTable->getNAColumnArray();
+ const NAColumn * altNaCol = naColArr.getColumn(altColName);
+ Lng32 altColNum = altNaCol->getPosition();
+
+ char buf[4000];
+ NAString colFamily;
+ NAString colName;
+ Lng32 datatype, length, precision, scale, dt_start, dt_end,
+ nullable, upshifted;
+ ComColumnClass colClass;
+ ComColumnDefaultClass defaultClass;
+ NAString charset, defVal;
+ NAString heading;
+ ULng32 hbaseColFlags;
+ Int64 colFlags;
+ LobsStorage lobStorage;
+ NAString quotedDefVal;
+ NABoolean xnWasStartedHere = FALSE;
+
+ if (cloneSeabaseTable(cn, naTable, tempTable, ehi, &cliInterface))
+ {
+ cliRC = -1;
+ goto label_drop;
+ }
+
+ if (truncateHbaseTable(catalogNamePart, schemaNamePart, objectNamePart,
+ (NATable*)naTable, ehi))
+ {
+ cliRC = -1;
+ goto label_restore;
+ }
+
-
+ if (beginXnIfNotInProgress(&cliInterface, xnWasStartedHere))
+ goto label_restore;
+
+ if (getColInfo(pColDef,
+ colFamily,
+ colName,
+ naTable->isSQLMXAlignedTable(),
+ datatype, length, precision, scale, dt_start, dt_end,
+ upshifted, nullable,
+ charset, colClass, defaultClass, defVal, heading, lobStorage,
+ hbaseColFlags, colFlags))
+ {
+ cliRC = -1;
processReturn();
+
+ goto label_restore;
+ }
+
+ if (NOT defVal.isNull())
+ {
+ ToQuotedString(quotedDefVal, defVal, FALSE);
+ }
+
+ str_sprintf(buf, "update %s.\"%s\".%s set (column_class, fs_data_type,
sql_data_type, column_size, column_precision, column_scale,
datetime_start_field, datetime_end_field, is_upshifted, nullable,
character_set, default_class, default_value) = ('%s', %d, '%s', %d, %d, %d, %d,
%d, '%s', %d, '%s', %d, '%s') where object_uid = %Ld and column_number = %d",
+ getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS,
+ COM_ALTERED_USER_COLUMN_LIT,
+ datatype,
+ getAnsiTypeStrFromFSType(datatype),
+ length,
+ precision,
+ scale,
+ dt_start,
+ dt_end,
+ (upshifted ? "Y" : "N"),
+ nullable,
+ (char*)charset.data(),
+ (Lng32)defaultClass,
+ (quotedDefVal.isNull() ? "" : quotedDefVal.data()),
+ tableUID,
+ altColNum);
+
+ cliRC = cliInterface.executeImmediate(buf);
+ if (cliRC < 0)
+ {
+ cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+ goto label_restore;
+ }
+
+ ActiveSchemaDB()->getNATableDB()->removeNATable
+ (cn,
- NATableDB::REMOVE_FROM_ALL_USERS,
- COM_BASE_TABLE_OBJECT);
++ ComQiScope::REMOVE_FROM_ALL_USERS,
++ COM_BASE_TABLE_OBJECT, ddlXns, FALSE);
+
+ str_sprintf(buf, "upsert using load into %s select * from %s",
+ naTable->getTableName().getQualifiedNameAsAnsiString().data(),
+ tempTable.data());
+ cliRC = cliInterface.executeImmediate(buf);
+ if (cliRC < 0)
+ {
+ cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
- return;
+ NAString reason;
+ reason = "Old data could not be updated using the altered column
definition.";
+
+ // column cannot be altered
+ *CmpCommon::diags() << DgSqlCode(-1404)
+ << DgColumnName(altColName)
+ << DgString0(reason);
+
+ goto label_restore;
}
- const NAType * currType = nacol->getType();
- NAType * newType = alterColNode->getType();
+ deallocEHI(ehi);
+
+ endXnIfStartedHere(&cliInterface, xnWasStartedHere, 0);
+
+ return 0;
- // Column that can be altered must meet these conditions:
- // -- old and new column datatype must be VARCHAR
- // -- new col length must be greater than or equal to old length
- // -- old and new character sets must be the same
- NABoolean canAlter = FALSE;
- if ((DFS2REC::isSQLVarChar(currType->getFSDatatype())) &&
- (DFS2REC::isSQLVarChar(newType->getFSDatatype())) &&
- (currType->getFSDatatype() == newType->getFSDatatype()) &&
- (currType->getNominalSize() <= newType->getNominalSize()) &&
- (((CharType*)currType)->getCharSet() ==
((CharType*)newType)->getCharSet()))
- canAlter = TRUE;
+ label_restore:
+ cloneHbaseTable(tempTable,
+ naTable->getTableName().getQualifiedNameAsAnsiString(),
+ ehi);
+
+ label_drop:
+ str_sprintf(buf, "drop table %s", tempTable.data());
+ Lng32 cliRC2 = cliInterface.executeImmediate(buf);
+
+ deallocEHI(ehi);
+
+ endXnIfStartedHere(&cliInterface, xnWasStartedHere, -1);
- if (NOT canAlter)
+ return (cliRC < 0 ? -1 : 0);
+ }
+
+ short CmpSeabaseDDL::alterColumnAttr(
+ const NAString &catalogNamePart, const NAString &schemaNamePart,
+ const NAString &objectNamePart,
+ const NATable * naTable, const NAColumn * naCol, NAType * newType,
+ StmtDDLAlterTableAlterColumnDatatype * alterColNode)
+ {
++ ExeCliInterface cliInterface
++ (STMTHEAP, NULL, NULL,
++ CmpCommon::context()->sqlSession()->getParentQid());
++
++ // this operation cannot be done if a xn is already in progress.
++ if (xnInProgress(&cliInterface))
+ {
- NAString reason;
- if (NOT ((DFS2REC::isSQLVarChar(currType->getFSDatatype())) &&
- (DFS2REC::isSQLVarChar(newType->getFSDatatype()))))
- reason = "Old and New datatypes must be VARCHAR.";
- else if (currType->getFSDatatype() != newType->getFSDatatype())
- reason = "Old and New datatypes must be the same.";
- else if (((CharType*)currType)->getCharSet() !=
((CharType*)newType)->getCharSet())
- reason = "Old and New character sets must be the same.";
- else if (currType->getNominalSize() > newType->getNominalSize())
- reason = "New length must be greater than or equal to old length.";
++ *CmpCommon::diags() << DgSqlCode(-20123);
+
- // key column cannot be altered
++ processReturn();
++ return -1;
++ }
++
+ if (naTable->isSQLMXAlignedTable())
+ {
+ ElemDDLColDef *pColDef =
+ alterColNode->getColToAlter()->castToElemDDLColDef();
+
+ if (alignedFormatTableAlterColumn
+ (
+ catalogNamePart, schemaNamePart, objectNamePart,
+ naTable,
+ naCol->getColName(),
- pColDef))
++ pColDef,
++ alterColNode->ddlXns()))
+ {
+ processReturn();
+ return -1;
+ }
+
+ return 0;
+ }
+
+ CorrName cn(objectNamePart, STMTHEAP, schemaNamePart,catalogNamePart);
+
+ Lng32 cliRC = 0;
+ Lng32 retcode = 0;
+
+ ComUID comUID;
+ comUID.make_UID();
+ Int64 objUID = comUID.get_value();
+
+ char objUIDbuf[100];
+
+ NAString tempCol(naCol->getColName());
+ tempCol += "_";
+ tempCol += str_ltoa(objUID, objUIDbuf);
+
+ char dispBuf[1000];
+ Lng32 ii = 0;
+ NABoolean identityCol;
+ ElemDDLColDef *pColDef =
alterColNode->getColToAlter()->castToElemDDLColDef();
+ NAColumn *nac = NULL;
+ if (getNAColumnFromColDef(pColDef, nac))
+ return -1;
+
+ dispBuf[0] = 0;
+ if (cmpDisplayColumn(nac, (char*)tempCol.data(), newType, 3, NULL, dispBuf,
+ ii, FALSE, identityCol,
+ FALSE, FALSE))
+ return -1;
+
- ExeCliInterface cliInterface
- (STMTHEAP, NULL, NULL,
- CmpCommon::context()->sqlSession()->getParentQid());
-
+ Int64 tableUID = naTable->objectUid().castToInt64();
+ const NAColumnArray &nacolArr = naTable->getNAColumnArray();
+ const NAString &altColName = naCol->getColName();
+ const NAColumn * altNaCol = nacolArr.getColumn(altColName);
+ Lng32 altColNum = altNaCol->getPosition();
+
+ char buf[4000];
+ str_sprintf(buf, "alter table %s add column %s",
+ naTable->getTableName().getQualifiedNameAsAnsiString().data(),
+ dispBuf);
+ cliRC = cliInterface.executeImmediate(buf);
+ if (cliRC < 0)
+ {
+ cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+
+ processReturn();
+ return -1;
+ }
+
++ ActiveSchemaDB()->getNATableDB()->removeNATable
++ (cn,
++ ComQiScope::REMOVE_FROM_ALL_USERS,
++ COM_BASE_TABLE_OBJECT,
++ alterColNode->ddlXns(), FALSE);
++
+ str_sprintf(buf, "update %s set %s = %s",
+ naTable->getTableName().getQualifiedNameAsAnsiString().data(),
+ tempCol.data(),
+ naCol->getColName().data());
+ cliRC = cliInterface.executeImmediate(buf);
+ if (cliRC < 0)
+ {
+ cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+
+ goto label_error1;
+ }
+
+ str_sprintf(buf, "delete from %s.\"%s\".%s where object_uid = %Ld and
column_number = %d",
+ getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS,
+ tableUID,
+ altColNum);
+
+ cliRC = cliInterface.executeImmediate(buf);
+ if (cliRC < 0)
+ {
+ cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+ goto label_error1;
+ }
+
+ str_sprintf(buf, "insert into %s.\"%s\".%s select object_uid, '%s', %d,
'%s', fs_data_type, sql_data_type, column_size, column_precision, column_scale,
datetime_start_field, datetime_end_field, is_upshifted, column_flags, nullable,
character_set, default_class, default_value, column_heading, '%s', '%s',
direction, is_optional, flags from %s.\"%s\".%s where object_uid = %Ld and
column_number = (select column_number from %s.\"%s\".%s where object_uid = %Ld
and column_name = '%s')",
+ getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS,
+ naCol->getColName().data(),
+ altColNum,
+ COM_ALTERED_USER_COLUMN_LIT,
+ altNaCol->getHbaseColFam().data(),
+ altNaCol->getHbaseColQual().data(),
+ getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS,
+ tableUID,
+ getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS,
+ tableUID,
+ tempCol.data());
+
+ cliRC = cliInterface.executeImmediate(buf);
+ if (cliRC < 0)
+ {
+ cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+ goto label_error1;
+ }
+
+ ActiveSchemaDB()->getNATableDB()->removeNATable
+ (cn,
- NATableDB::REMOVE_FROM_ALL_USERS,
- COM_BASE_TABLE_OBJECT);
++ ComQiScope::REMOVE_FROM_ALL_USERS,
++ COM_BASE_TABLE_OBJECT,
++ alterColNode->ddlXns(), FALSE);
++
+ str_sprintf(buf, "update %s set %s = %s",
+ naTable->getTableName().getQualifiedNameAsAnsiString().data(),
+ naCol->getColName().data(),
+ tempCol.data());
+ cliRC = cliInterface.executeImmediate(buf);
+ if (cliRC < 0)
+ {
+ cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+
+ NAString reason;
+ reason = "Old data could not be updated into the new column
definition.";
+
+ // column cannot be altered
*CmpCommon::diags() << DgSqlCode(-1404)
- << DgColumnName(colName)
+ << DgColumnName(naCol->getColName())
<< DgString0(reason);
processReturn();
@@@ -5514,35 -5897,105 +5976,106 @@@ void CmpSeabaseDDL::alterSeabaseTableAl
} // for
} // secondary indexes present
- Int64 objUID = naTable->objectUid().castToInt64();
+ if ((NOT currType->isCompatible(*newType)) &&
+ (NOT ((currType->getTypeQualifier() == NA_CHARACTER_TYPE) &&
+ (newType->getTypeQualifier() == NA_CHARACTER_TYPE))))
+ {
+ NAString reason = "Old and New datatypes must be compatible.";
- Lng32 colNumber = nacol->getPosition();
- char *col = NULL;
+ // column cannot be altered
+ *CmpCommon::diags() << DgSqlCode(-1404)
+ << DgColumnName(colName)
+ << DgString0(reason);
+
+ processReturn();
+
+ return;
+ }
- char buf[4000];
- str_sprintf(buf, "update %s.\"%s\".%s set column_size = %d where object_uid
= %Ld and column_number = %d",
- getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS,
- newType->getNominalSize(),
- objUID,
- colNumber);
-
- cliRC = cliInterface.executeImmediate(buf);
- if (cliRC < 0)
+ // Column that can be altered by updating metadata only
+ // must meet these conditions:
+ // -- old and new column datatype must be VARCHAR
+ // -- old and new datatype must have the same nullable attr
+ // -- new col length must be greater than or equal to old length
+ // -- old and new character sets must be the same
+ NABoolean mdAlterOnly = FALSE;
+ if ((DFS2REC::isSQLVarChar(currType->getFSDatatype())) &&
+ (DFS2REC::isSQLVarChar(newType->getFSDatatype())) &&
+ (currType->getFSDatatype() == newType->getFSDatatype()) &&
+ (currType->supportsSQLnull() == newType->supportsSQLnull()) &&
+ (currType->getNominalSize() <= newType->getNominalSize()) &&
+ (((CharType*)currType)->getCharSet() ==
((CharType*)newType)->getCharSet()))
+ mdAlterOnly = TRUE;
+
+ if ((NOT mdAlterOnly) &&
+ (CmpCommon::getDefault(TRAF_ALTER_COL_ATTRS) == DF_OFF))
{
- cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+ NAString reason;
+ if (NOT ((DFS2REC::isSQLVarChar(currType->getFSDatatype())) &&
+ (DFS2REC::isSQLVarChar(newType->getFSDatatype()))))
+ reason = "Old and New datatypes must be VARCHAR.";
+ else if (currType->getFSDatatype() != newType->getFSDatatype())
+ reason = "Old and New datatypes must be the same.";
+ else if (((CharType*)currType)->getCharSet() !=
((CharType*)newType)->getCharSet())
+ reason = "Old and New character sets must be the same.";
+ else if (currType->getNominalSize() > newType->getNominalSize())
+ reason = "New length must be greater than or equal to old length.";
+ else if (currType->supportsSQLnull() != newType->supportsSQLnull())
+ reason = "Old and New nullability must be the same.";
+
+ // column cannot be altered
+ *CmpCommon::diags() << DgSqlCode(-1404)
+ << DgColumnName(colName)
+ << DgString0(reason);
processReturn();
+
return;
}
+
+ if (mdAlterOnly)
+ {
+ Int64 objUID = naTable->objectUid().castToInt64();
+
+ Lng32 colNumber = nacol->getPosition();
+
+ char buf[4000];
+ str_sprintf(buf, "update %s.\"%s\".%s set column_size = %d,
column_class = '%s' where object_uid = %Ld and column_number = %d",
+ getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS,
+ newType->getNominalSize(),
+ COM_ALTERED_USER_COLUMN_LIT,
+ objUID,
+ colNumber);
+
+ cliRC = cliInterface.executeImmediate(buf);
+ if (cliRC < 0)
+ {
+ cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
+
+ processReturn();
+ return;
+ }
+ }
+ else
+ {
+ if (alterColumnAttr(catalogNamePart, schemaNamePart, objectNamePart,
+ naTable, nacol, newType, alterColNode))
+ return;
+ }
- deallocEHI(ehi);
- heap_->deallocateMemory(col);
+ cliRC = updateObjectRedefTime(&cliInterface,
+ catalogNamePart, schemaNamePart,
objectNamePart,
+ COM_BASE_TABLE_OBJECT_LIT);
+ if (cliRC < 0)
+ {
+ return;
+ }
-
+
ActiveSchemaDB()->getNATableDB()->removeNATable
(cn,
- NATableDB::REMOVE_FROM_ALL_USERS, COM_BASE_TABLE_OBJECT);
-
+ ComQiScope::REMOVE_FROM_ALL_USERS, COM_BASE_TABLE_OBJECT,
+ alterColNode->ddlXns(), FALSE);
-
++
processReturn();
return;
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/faf5dca6/core/sql/src/main/java/org/trafodion/sql/HBaseClient.java
----------------------------------------------------------------------