/dbcon/execplan/calpontsystemcatalog.cpp
C++ | 5693 lines | 4721 code | 668 blank | 304 comment | 932 complexity | 757b97d2e403fb6473c5e38e4f074531 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- /* Copyright (C) 2014 InfiniDB, Inc.
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; version 2 of
- the License.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- MA 02110-1301, USA. */
- /***********************************************************************
- * $Id: calpontsystemcatalog.cpp 9594 2013-06-04 18:19:21Z pleblanc $
- *
- *
- ***********************************************************************/
- #include <unistd.h>
- #include <stdexcept>
- #include <string>
- #include <iostream>
- using namespace std;
- #include "messagequeue.h"
- #include "calpontsystemcatalog.h"
- #include "ddlpkg.h"
- #include "expressionparser.h"
- #include "calpontselectexecutionplan.h"
- #include "calpontselectexecutionplan.h"
- #include "clientrotator.h"
- #include "simplefilter.h"
- #include "simplecolumn.h"
- #include "expressionparser.h"
- #include "constantcolumn.h"
- #include "treenode.h"
- #include "operator.h"
- #include "sessionmanager.h"
- #include "columnresult.h"
- #include "joblistfactory.h"
- #include "joblist.h"
- #include "distributedenginecomm.h"
- #include "resourcemanager.h"
- using namespace joblist;
- #include "bytestream.h"
- #include "messagequeue.h"
- using namespace messageqcpp;
- #include "configcpp.h"
- #include "liboamcpp.h"
- using namespace config;
- #include "exceptclasses.h"
- #include "idberrorinfo.h"
- #include "errorids.h"
- using namespace logging;
- #include "rowgroup.h"
- using namespace rowgroup;
- #include <boost/thread/thread.hpp>
- #include <boost/thread/mutex.hpp>
- #include <boost/version.hpp>
- #ifdef _MSC_VER
- #include "idbregistry.h"
- #endif
- #undef BAIL_IF_0
- #if 1
- //We are unlikely to ever get anything more out of this connection, so bail out
- #define BAIL_IF_0(m) \
- if ((m).length() == 0) \
- { \
- fExeMgr->shutdown(); \
- throw runtime_error("CALPONT_INTERNAL_ERROR"); \
- }
- #else
- #define BAIL_IF_0(m)
- #endif
- #undef CSC_DEBUG
- #define CSC_DEBUG 0
- #if CSC_DEBUG
- namespace {
- std::ofstream csclog("/tmp/csc.log", std::ios::app);
- }
- #define DEBUG csclog
- #else
- #define DEBUG if (false) cerr
- #endif
- namespace execplan
- {
- const SOP opeq(new Operator("="));
- const string colDataTypeToString(CalpontSystemCatalog::ColDataType cdt)
- {
- switch (cdt)
- {
- case CalpontSystemCatalog::BIT:
- return "bit";
- break;
- case CalpontSystemCatalog::TINYINT:
- return "tinyint";
- break;
- case CalpontSystemCatalog::CHAR:
- return "char";
- break;
- case CalpontSystemCatalog::SMALLINT:
- return "smallint";
- break;
- case CalpontSystemCatalog::DECIMAL:
- return "decimal";
- break;
- case CalpontSystemCatalog::MEDINT:
- return "medint";
- break;
- case CalpontSystemCatalog::INT:
- return "int";
- break;
- case CalpontSystemCatalog::FLOAT:
- return "float";
- break;
- case CalpontSystemCatalog::DATE:
- return "date";
- break;
- case CalpontSystemCatalog::BIGINT:
- return "bigint";
- break;
- case CalpontSystemCatalog::DOUBLE:
- return "double";
- break;
- case CalpontSystemCatalog::DATETIME:
- return "datetime";
- break;
- case CalpontSystemCatalog::VARCHAR:
- return "varchar";
- break;
- case CalpontSystemCatalog::VARBINARY:
- return "varbinary";
- break;
- case CalpontSystemCatalog::CLOB:
- return "clob";
- break;
- case CalpontSystemCatalog::BLOB:
- return "blob";
- break;
- case CalpontSystemCatalog::UTINYINT:
- return "utinyint";
- break;
- case CalpontSystemCatalog::USMALLINT:
- return "usmallint";
- break;
- case CalpontSystemCatalog::UDECIMAL:
- return "udecimal";
- break;
- case CalpontSystemCatalog::UMEDINT:
- return "umedint";
- break;
- case CalpontSystemCatalog::UINT:
- return "uint32_t";
- break;
- case CalpontSystemCatalog::UFLOAT:
- return "ufloat";
- break;
- case CalpontSystemCatalog::UBIGINT:
- return "ubigint";
- break;
- case CalpontSystemCatalog::UDOUBLE:
- return "udouble";
- break;
- default:
- break;
- }
- return "invalid!";
- }
- }
- namespace execplan
- {
- typedef CalpontSelectExecutionPlan::ColumnMap::value_type CMVT_;
- boost::shared_ptr<SessionManager> fSessionManager;
- CalpontSystemCatalog::NJLSysDataList::~NJLSysDataList()
- {
- NJLSysDataVector::iterator it;
- for (it = sysDataVec.begin(); it != sysDataVec.end(); it++)
- delete *it;
- }
-
- const CalpontSystemCatalog::TableColName make_tcn(const string& s, const string& t, const string& c)
- {
- CalpontSystemCatalog::TableColName tcns;
- tcns.schema = s;
- tcns.table = t;
- tcns.column = c;
- transform (tcns.schema.begin(), tcns.schema.end(), tcns.schema.begin(), to_lower());
- transform (tcns.table.begin(), tcns.table.end(), tcns.table.begin(), to_lower());
- transform (tcns.column.begin(), tcns.column.end(), tcns.column.begin(), to_lower());
- return tcns;
- }
- const CalpontSystemCatalog::TableName make_table(const string& s, const string& t)
- {
- CalpontSystemCatalog::TableName tn;
- tn.schema = s;
- tn.table = t;
- transform (tn.schema.begin(), tn.schema.end(), tn.schema.begin(), to_lower());
- transform (tn.table.begin(), tn.table.end(), tn.table.begin(), to_lower());
- return tn;
- }
- const CalpontSystemCatalog::TableAliasName make_aliastable(const string& s, const string& t, const string& a, const bool isInfiniDB)
- {
- CalpontSystemCatalog::TableAliasName tn;
- tn.schema = s;
- tn.table = t;
- tn.alias = a;
- tn.view = "";
- tn.fIsInfiniDB = isInfiniDB;
- transform (tn.schema.begin(), tn.schema.end(), tn.schema.begin(), to_lower());
- transform (tn.table.begin(), tn.table.end(), tn.table.begin(), to_lower());
- transform (tn.alias.begin(), tn.alias.end(), tn.alias.begin(), to_lower());
- return tn;
- }
- const CalpontSystemCatalog::TableAliasName make_aliasview(const string& s, const string& t, const string& a, const string& v, const bool isInfiniDB)
- {
- CalpontSystemCatalog::TableAliasName tn;
- tn.schema = s;
- tn.table = t;
- tn.alias = a;
- tn.view = v;
- tn.fIsInfiniDB = isInfiniDB;
- transform (tn.schema.begin(), tn.schema.end(), tn.schema.begin(), to_lower());
- transform (tn.table.begin(), tn.table.end(), tn.table.begin(), to_lower());
- transform (tn.alias.begin(), tn.alias.end(), tn.alias.begin(), to_lower());
- transform (tn.view.begin(), tn.view.end(), tn.view.begin(), to_lower());
- return tn;
- }
- bool CalpontSystemCatalog::TableColName::operator<(const TableColName& rhs) const
- {
- if (schema < rhs.schema)
- {
- return true;
- }
- else if (schema == rhs.schema)
- {
- if (table < rhs.table)
- {
- return true;
- }
- else if (table == rhs.table)
- {
- if (column < rhs.column)
- {
- return true;
- }
- }
- }
- return false;
- }
- const string CalpontSystemCatalog::TableColName::toString() const
- {
- string os;
- os = schema + '.' + table + '.' + column;
- return os;
- }
- bool CalpontSystemCatalog::TableName::operator<(const TableName& rhs) const
- {
- if (schema < rhs.schema)
- {
- return true;
- }
- else if (schema == rhs.schema)
- {
- if (table < rhs.table)
- {
- return true;
- }
- }
- return false;
- }
- void CalpontSystemCatalog::TableAliasName::clear()
- {
- schema.clear();
- table.clear();
- alias.clear();
- view.clear();
- }
- bool CalpontSystemCatalog::TableAliasName::operator<(const TableAliasName& rhs) const
- {
- if (schema < rhs.schema)
- {
- return true;
- }
- else if (schema == rhs.schema)
- {
- if (table < rhs.table)
- {
- return true;
- }
- else if (table == rhs.table)
- {
- if (alias < rhs.alias)
- {
- return true;
- }
- else if (alias == rhs.alias)
- {
- if (view < rhs.view)
- {
- return true;
- }
- else if (view == rhs.view)
- {
- if (fIsInfiniDB < rhs.fIsInfiniDB)
- return true;
- }
- }
- }
- }
- return false;
- }
- void CalpontSystemCatalog::TableAliasName::serialize(messageqcpp::ByteStream& b) const
- {
- b << schema;
- b << table;
- b << alias;
- b << view;
- b << static_cast<const ByteStream::doublebyte>(fIsInfiniDB);
- }
- void CalpontSystemCatalog::TableAliasName::unserialize(messageqcpp::ByteStream& b)
- {
- b >> schema;
- b >> table;
- b >> alias;
- b >> view;
- b >> reinterpret_cast< ByteStream::doublebyte&>(fIsInfiniDB);
- }
- /*static*/
- boost::mutex CalpontSystemCatalog::map_mutex;
- /*static*/
- CalpontSystemCatalog::CatalogMap CalpontSystemCatalog::fCatalogMap;
- /*static*/
- uint32_t CalpontSystemCatalog::fModuleID = numeric_limits<uint32_t>::max();
- const CalpontSystemCatalog::OID CalpontSystemCatalog::lookupOID(const TableColName& tableColName)
- {
- if (tableColName.schema.length() == 0 || tableColName.table.length() == 0 || tableColName.column.length() == 0)
- return -1;
- TableColName aTableColName;
- aTableColName.schema = tableColName.schema;
- aTableColName.table = tableColName.table;
- aTableColName.column = tableColName.column;
- transform( aTableColName.schema.begin(), aTableColName.schema.end(), aTableColName.schema.begin(), to_lower() );
- transform( aTableColName.table.begin(), aTableColName.table.end(), aTableColName.table.begin(), to_lower() );
- transform( aTableColName.column.begin(), aTableColName.column.end(), aTableColName.column.begin(), to_lower() );
- if (aTableColName.schema.compare(CALPONT_SCHEMA) != 0)
- DEBUG << "Enter lookupOID: " << tableColName.schema << "|" << tableColName.table
- << "|" << tableColName.column << endl;
- //Check whether cache needs to be flushed
- if ( aTableColName.schema.compare(CALPONT_SCHEMA) != 0) {
- checkSysCatVer();
- }
- boost::mutex::scoped_lock lk2(fOIDmapLock);
- if ( fOIDmap.size() > 0 )
- {
- OIDmap::const_iterator iter = fOIDmap.find(aTableColName);
-
- // @bug 1358. double check fColRIDMap in case it's not filled with valid rid.
- if (iter != fOIDmap.end())
- {
- if (fIdentity == EC && aTableColName.schema.compare(CALPONT_SCHEMA) != 0)
- {
- ColRIDmap::const_iterator iter1 = fColRIDmap.find(aTableColName);
- if ( iter1 != fColRIDmap.end() ) {
- return iter->second;
- }
- }
- else {
- return iter->second;
- }
- }
- }
- lk2.unlock();
- // select objectid,columnlength,datatype,dictobjectid,listobjectid,treeobjectid,columnposition,scale,prec,
- // defaultvalue from syscolumn where schema=schema and tablename=table and columnname=column;
- CalpontSelectExecutionPlan csep;
- CalpontSelectExecutionPlan::ReturnedColumnList returnedColumnList;
- CalpontSelectExecutionPlan::FilterTokenList filterTokenList;
- CalpontSelectExecutionPlan::ColumnMap colMap;
- string columnlength = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+COLUMNLEN_COL;
- string objectid = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+OBJECTID_COL;
- string datatype = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+DATATYPE_COL;
- string dictobjectid = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+DICTOID_COL;
- string listobjectid = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+LISTOBJID_COL;
- string treeobjectid = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+TREEOBJID_COL;
- string columnposition = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+COLUMNPOS_COL;
- string scale = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+SCALE_COL;
- string precision = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+PRECISION_COL;
- string defaultvalue = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+DEFAULTVAL_COL;
- // the following columns will be save in cache although it's not needed for now
- string columnname = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+COLNAME_COL;
- string tablename = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+TABLENAME_COL;
- string schemaname = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+SCHEMA_COL;
- string compressiontype = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+COMPRESSIONTYPE_COL;
- string autoincrement = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+AUTOINC_COL;
- string nextVal = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+NEXTVALUE_COL;
- string nullable = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+NULLABLE_COL;
- SimpleColumn* col[17];
- col[0] = new SimpleColumn(columnlength, fSessionID);
- col[1] = new SimpleColumn(objectid, fSessionID);
- col[2] = new SimpleColumn(datatype, fSessionID);
- col[3] = new SimpleColumn(dictobjectid, fSessionID);
- col[4] = new SimpleColumn(listobjectid, fSessionID);
- col[5] = new SimpleColumn(treeobjectid, fSessionID);
- col[6] = new SimpleColumn(columnposition, fSessionID);
- col[7] = new SimpleColumn(scale, fSessionID);
- col[8] = new SimpleColumn(precision, fSessionID);
- col[9] = new SimpleColumn(defaultvalue, fSessionID);
- col[10] = new SimpleColumn(schemaname, fSessionID);
- col[11] = new SimpleColumn(tablename, fSessionID);
- col[12] = new SimpleColumn(columnname, fSessionID);
- col[13] = new SimpleColumn(compressiontype, fSessionID);
- col[14] = new SimpleColumn(autoincrement, fSessionID);
- col[15] = new SimpleColumn(nextVal, fSessionID);
- col[16] = new SimpleColumn(nullable, fSessionID);
-
- SRCP srcp;
- srcp.reset(col[0]);
- colMap.insert(CMVT_(columnlength, srcp));
- srcp.reset(col[1]);
- colMap.insert(CMVT_(objectid, srcp));
- srcp.reset(col[2]);
- colMap.insert(CMVT_(datatype, srcp));
- srcp.reset(col[3]);
- colMap.insert(CMVT_(dictobjectid, srcp));
- srcp.reset(col[4]);
- colMap.insert(CMVT_(listobjectid, srcp));
- srcp.reset(col[5]);
- colMap.insert(CMVT_(treeobjectid, srcp));
- srcp.reset(col[6]);
- colMap.insert(CMVT_(columnposition, srcp));
- srcp.reset(col[7]);
- colMap.insert(CMVT_(scale, srcp));
- srcp.reset(col[8]);
- colMap.insert(CMVT_(precision, srcp));
- // TODO: NULL value handling
- srcp.reset(col[9]);
- colMap.insert(CMVT_(defaultvalue, srcp));
- srcp.reset(col[10]);
- colMap.insert(CMVT_(schemaname, srcp));
- srcp.reset(col[11]);
- colMap.insert(CMVT_(tablename, srcp));
- srcp.reset(col[12]);
- colMap.insert(CMVT_(columnname, srcp));
- srcp.reset(col[13]);
- colMap.insert(CMVT_(compressiontype, srcp));
- srcp.reset(col[14]);
- colMap.insert(CMVT_(autoincrement, srcp));
- srcp.reset(col[15]);
- colMap.insert(CMVT_(nextVal, srcp));
- srcp.reset(col[16]);
- colMap.insert(CMVT_(nullable, srcp));
- csep.columnMapNonStatic(colMap);
- // ignore returnedcolumn, because it's not read by Joblist for now
- csep.returnedCols(returnedColumnList);
- OID oid[17];
- for (int i = 0; i < 17; i++)
- oid[i] = col[i]->oid();
- // Filters
- SimpleFilter *f1 = new SimpleFilter (opeq,
- col[10]->clone(),
- new ConstantColumn(aTableColName.schema, ConstantColumn::LITERAL));
- filterTokenList.push_back(f1);
- filterTokenList.push_back(new Operator("and"));
- SimpleFilter *f2 = new SimpleFilter (opeq,
- col[11]->clone(),
- new ConstantColumn(aTableColName.table, ConstantColumn::LITERAL));
- filterTokenList.push_back(f2);
- filterTokenList.push_back(new Operator("and"));
- SimpleFilter *f3 = new SimpleFilter (opeq,
- col[12]->clone(),
- new ConstantColumn(aTableColName.column, ConstantColumn::LITERAL));
- filterTokenList.push_back(f3);
- csep.filterTokenList(filterTokenList);
- ostringstream oss;
- oss << "select objectid,columnlength,datatype,dictobjectid,listobjectid,treeobjectid,columnposition,scale,"
- "prec,defaultvalue from syscolumn where schema='" << aTableColName.schema << "' and tablename='" <<
- aTableColName.table << "' and columnname='" << aTableColName.column << "' --lookupOID/";
- if (fIdentity == EC) oss << "EC";
- else oss << "FE";
- csep.data(oss.str());
- NJLSysDataList sysDataList;
- TableColName tcn;
- ColType ct;
- OID coloid = -1;
- getSysData (csep, sysDataList, SYSCOLUMN_TABLE);
- vector<ColumnResult*>::const_iterator it;
- for (it = sysDataList.begin(); it != sysDataList.end(); it++)
- {
- if ((*it)->ColumnOID() == oid[1])
- {
- // populate cache
- coloid = (OID)((*it)->GetData(0));
- lk2.lock();
- fOIDmap[aTableColName] = coloid;
- if (fIdentity == EC)
- fColRIDmap[aTableColName] = (*it)->GetRid(0);
- // @bug 1358. do not insert this entry to map
- //else
- // fColRIDmap[aTableColName] = 0;
- lk2.unlock();
- }
- if ((*it)->ColumnOID() == oid[0])
- ct.colWidth = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[2])
- ct.colDataType = (ColDataType)((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[3])
- ct.ddn.dictOID = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[4])
- ct.ddn.listOID = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[5])
- ct.ddn.treeOID = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[6])
- ct.colPosition = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[7])
- ct.scale = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[8])
- ct.precision = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[13])
- ct.compressionType = ct.ddn.compressionType = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[14])
- {
- ostringstream os;
- os << (char) (*it)->GetData(0);
- if (os.str().compare("y") == 0)
- ct.autoincrement = true;
- else
- ct.autoincrement = false;
- }
- else if ((*it)->ColumnOID() == oid[15])
- ct.nextvalue = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[16])
- {
- if (static_cast<ConstraintType> ((*it)->GetData(0)) == 0)
- {
- ct.constraintType = NOTNULL_CONSTRAINT;
- }
- }
- else if ((*it)->ColumnOID() == DICTOID_SYSCOLUMN_DEFAULTVAL)
- {
- ct.defaultValue = ((*it)->GetStringData(0));
- if ((!ct.defaultValue.empty()) || (ct.defaultValue.length() > 0))
- {
- if (ct.constraintType != NOTNULL_CONSTRAINT)
- ct.constraintType = DEFAULT_CONSTRAINT;
- }
- }
- else if ((*it)->ColumnOID() == DICTOID_SYSCOLUMN_SCHEMA)
- tcn.schema = ((*it)->GetStringData(0));
- else if ((*it)->ColumnOID() == DICTOID_SYSCOLUMN_TABLENAME)
- tcn.table = ((*it)->GetStringData(0));
- else if ((*it)->ColumnOID() == DICTOID_SYSCOLUMN_COLNAME)
- tcn.column = ((*it)->GetStringData(0));
- }
- // temporialy memory leak fix until defaultvalue is added.
- // delete col[9];
- ct.columnOID = coloid;
- // populate colinfomap cache and oidbitmap
- boost::mutex::scoped_lock lk3(fColinfomapLock);
- fColinfomap[coloid] = ct;
- return coloid;
- }
- void CalpontSystemCatalog::getSysData (CalpontSelectExecutionPlan& csep,
- NJLSysDataList& sysDataList,
- const string& sysTableName)
- {
- // start up new transaction
-
- BRM::TxnID txnID;
- int oldTxnID;
- txnID = fSessionManager->getTxnID(fSessionID);
-
- if (!txnID.valid)
- {
- txnID.id = 0;
- txnID.valid = true;
- }
-
- BRM::QueryContext verID, oldVerID;
- verID = fSessionManager->verID();
- oldTxnID = csep.txnID();
- csep.txnID(txnID.id);
- oldVerID = csep.verID();
- csep.verID(verID);
- //We need to use a session ID that's separate from the actual query SID, because the dbcon runs queries
- // in the middle of receiving data bands for the real query.
- //TODO: we really need a flag or something to identify this as a syscat query: there are assumptions made
- // in joblist that a high-bit-set session id is always a syscat query. This will be okay for a long time,
- // but not forever...
- csep.sessionID(fSessionID | 0x80000000);
- int tryCnt = 0;
-
- // add the tableList to csep for tuple joblist to use
- CalpontSelectExecutionPlan::TableList tablelist;
- tablelist.push_back(make_aliastable("calpontsys", sysTableName, ""));
- csep.tableList(tablelist);
-
- // populate the returned column list as column map
- csep.returnedCols().clear();
- CalpontSelectExecutionPlan::ColumnMap::const_iterator it;
- for (it = csep.columnMap().begin(); it != csep.columnMap().end(); ++it)
- {
- csep.returnedCols().push_back(it->second);
- }
-
- if (fIdentity == EC)
- {
- try {
- getSysData_EC(csep, sysDataList, sysTableName);
- }
- catch ( IDBExcept& ){
- throw;
- }
- catch ( runtime_error& e ) {
- throw runtime_error ( e.what() );
- }
- }
- else
- {
- while (tryCnt < 5)
- {
- tryCnt++;
- try {
- getSysData_FE(csep, sysDataList, sysTableName);
- break;
- }
- catch(IDBExcept&) // error already occured. this is not a broken pipe
- {
- throw;
- }
- catch(...)
- {
- // may be a broken pipe. re-establish exeMgr and send the message
- delete fExeMgr;
- fExeMgr = new ClientRotator(0, "ExeMgr");
- try {
- fExeMgr->connect(5);
- } catch (...) {
- throw IDBExcept(ERR_LOST_CONN_EXEMGR);
- }
- }
- }
- if (tryCnt >= 5)
- //throw runtime_error("Error occured when calling system catalog. ExeMgr is not functioning.");
- throw IDBExcept(ERR_SYSTEM_CATALOG);
- }
- csep.sessionID(fSessionID);
- csep.txnID(oldTxnID);
- csep.verID(oldVerID);
- }
-
- void CalpontSystemCatalog::getSysData_EC(CalpontSelectExecutionPlan& csep,
- NJLSysDataList& sysDataList,
- const string& sysTableName)
- {
- DEBUG << "Enter getSysData_EC " << fSessionID << endl;
- uint32_t tableOID = IDB_VTABLE_ID;
- ByteStream bs;
- uint32_t status;
- ResourceManager rm(true);
- DistributedEngineComm* fEc = DistributedEngineComm::instance(rm);
- SJLP jl = JobListFactory::makeJobList(&csep, rm, true);
- //@bug 2221. Work around to prevent DMLProc crash.
- int retryNum = 0;
- while ( jl->status() != 0 )
- {
- if ( retryNum >= 6 )
- throw runtime_error("Error occured when calling makeJobList");
- #ifdef _MSC_VER
- Sleep(1 * 1000);
- #else
- sleep(1);
- #endif
- jl = JobListFactory::makeJobList(&csep, rm, true);
- retryNum++;
- }
- if (jl->status() != 0 || jl->putEngineComm(fEc) != 0)
- {
- string emsg = jl->errMsg();
- throw runtime_error("Error occured when calling system catalog (1). " + emsg);
- }
- if ( jl->doQuery() != 0)
- {
- throw runtime_error("Error occured when calling system catalog (2). Make sure all processes are running.");
- }
-
- TupleJobList* tjlp = dynamic_cast<TupleJobList*>(jl.get());
- idbassert(tjlp);
- RowGroup rowGroup = tjlp->getOutputRowGroup();
- RGData rgData;
- while (true)
- {
- bs.restart();
- uint32_t rowCount = jl->projectTable(tableOID, bs);
-
- // XXXST: take out the 'true' when all jobsteps have been made st-compatible.
- rgData.deserialize(bs, true);
- rowGroup.setData(&rgData);
- //rowGroup.setData(const_cast<uint8_t*>(bs.buf()));
- if ((status = rowGroup.getStatus()) != 0)
- {
- if (status >= 1000) // new error system
- throw IDBExcept(status);
- else
- throw IDBExcept(ERR_SYSTEM_CATALOG);
- }
-
- if (rowCount > 0)
- rowGroup.addToSysDataList(sysDataList);
- else
- break;
- }
- }
- void CalpontSystemCatalog::getSysData_FE(const CalpontSelectExecutionPlan& csep,
- NJLSysDataList& sysDataList,
- const string& sysTableName)
- {
- DEBUG << "Enter getSysData_FE " << fSessionID << endl;
-
- ByteStream msg;
-
- // send code to indicat tuple
- ByteStream::quadbyte qb = 4;
- msg << qb;
- fExeMgr->write(msg);
- msg.restart();
- // Send the CalpontSelectExecutionPlan to ExeMgr.
- csep.serialize(msg);
- fExeMgr->write(msg);
-
- // Get the table oid for the system table being queried.
- TableName tableName;
- tableName.schema = CALPONT_SCHEMA;
- tableName.table = sysTableName;
- uint32_t tableOID = IDB_VTABLE_ID;
- uint16_t status = 0;
-
- // Send the request for the table.
- qb = static_cast<ByteStream::quadbyte>(tableOID);
- ByteStream bs;
- bs << qb;
- fExeMgr->write(bs);
- boost::scoped_ptr<rowgroup::RowGroup> rowGroup;
- RGData rgData;
- msg.restart();
- bs.restart();
- msg = fExeMgr->read();
- bs = fExeMgr->read();
-
- if (bs.length() == 0)
- {
- throw IDBExcept(ERR_LOST_CONN_EXEMGR);
- }
- string emsgStr;
- bs >> emsgStr;
- bool err = false;
-
- if (msg.length() == 4)
- {
- msg >> qb;
- if (qb != 0)
- err = true;
- }
- else
- {
- err = true;
- }
- if (err)
- {
- throw runtime_error(emsgStr);
- }
-
- while(true)
- {
- bs.restart();
- bs = fExeMgr->read();
- // @bug 1782. check ExeMgr connection lost
- if (bs.length() == 0)
- throw IDBExcept(ERR_LOST_CONN_EXEMGR);
- if (!rowGroup)
- {
- rowGroup.reset(new RowGroup());
- rowGroup->deserialize(bs);
- continue;
- }
- else
- {
- // XXXST
- rgData.deserialize(bs, true);
- rowGroup->setData(&rgData);
- //rowGroup->setData(const_cast<uint8_t*>(bs.buf()));
- }
- if ((status = rowGroup->getStatus()) != 0)
- {
- if (status >= 1000) // new error system
- {
- //bs.advance(rowGroup->getDataSize());
- bs >> emsgStr;
- throw IDBExcept(emsgStr, rowGroup->getStatus()); }
- else
- {
- throw IDBExcept(ERR_SYSTEM_CATALOG);
- }
- }
-
- if (rowGroup->getRowCount() > 0)
- rowGroup->addToSysDataList(sysDataList);
- else
- break;
- }
- bs.reset();
- qb = 0;
- bs << qb;
- fExeMgr->write(bs);
- }
- const CalpontSystemCatalog::ColType CalpontSystemCatalog::colType(const OID& Oid)
- {
- if ( Oid >= 3000)
- DEBUG << "Enter colType: " << Oid << endl;
- ColType ct;
- // invalid oid
- if (Oid < 1000)
- return ct;
-
- //Check whether cache needs to be flushed
- if ( Oid >= 3000) {
- checkSysCatVer();
- }
- // check colinfomap first for system table column or cached column type
- boost::mutex::scoped_lock lk3(fColinfomapLock);
- if ( fColinfomap.size() > 0 )
- {
- Colinfomap::const_iterator iter = fColinfomap.find(Oid);
- if (iter != fColinfomap.end())
- {
- return iter->second;
- }
- }
- lk3.unlock();
-
- /* SQL statement: select columnlength, datatype, dictobjectid,listobjectid,treeobjectid,
- * columnposition, scale, prec, defaultvalue, schema, tablename, columnname
- * from syscolumn where objectid = Oid;
- */
- CalpontSelectExecutionPlan csep;
- CalpontSelectExecutionPlan::ReturnedColumnList returnedColumnList;
- CalpontSelectExecutionPlan::FilterTokenList filterTokenList;
- CalpontSelectExecutionPlan::ColumnMap colMap;
-
- string columnlength = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+COLUMNLEN_COL;
- string objectid = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+OBJECTID_COL;
- string datatype = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+DATATYPE_COL;
- string dictobjectid = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+DICTOID_COL;
- string listobjectid = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+LISTOBJID_COL;
- string treeobjectid = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+TREEOBJID_COL;
- string columnposition = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+COLUMNPOS_COL;
- string scale = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+SCALE_COL;
- string precision = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+PRECISION_COL;
- string defaultvalue = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+DEFAULTVAL_COL;
- // the following columns will be save in cache although it's not needed for now
- string columnname = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+COLNAME_COL;
- string tablename = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+TABLENAME_COL;
- string schemaname = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+SCHEMA_COL;
- string nullable = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+NULLABLE_COL;
- string compressionType = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+COMPRESSIONTYPE_COL;
- string autoincrement = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+AUTOINC_COL;
- string nextvalue = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+NEXTVALUE_COL;
-
- SimpleColumn* col[17];
- col[0] = new SimpleColumn(columnlength, fSessionID);
- col[1] = new SimpleColumn(objectid, fSessionID);
- col[2] = new SimpleColumn(datatype, fSessionID);
- col[3] = new SimpleColumn(dictobjectid, fSessionID);
- col[4] = new SimpleColumn(listobjectid, fSessionID);
- col[5] = new SimpleColumn(treeobjectid, fSessionID);
- col[6] = new SimpleColumn(columnposition, fSessionID);
- col[7] = new SimpleColumn(scale, fSessionID);
- col[8] = new SimpleColumn(precision, fSessionID);
- col[9] = new SimpleColumn(defaultvalue, fSessionID);
- col[10] = new SimpleColumn(schemaname, fSessionID);
- col[11] = new SimpleColumn(tablename, fSessionID);
- col[12] = new SimpleColumn(columnname, fSessionID);
- col[13] = new SimpleColumn(nullable, fSessionID);
- col[14] = new SimpleColumn(compressionType, fSessionID);
- col[15] = new SimpleColumn(autoincrement, fSessionID);
- col[16] = new SimpleColumn(nextvalue, fSessionID);
-
- SRCP srcp;
- srcp.reset(col[0]);
- colMap.insert(CMVT_(columnlength, srcp));
- srcp.reset(col[1]);
- colMap.insert(CMVT_(objectid, srcp));
- srcp.reset(col[2]);
- colMap.insert(CMVT_(datatype, srcp));
- srcp.reset(col[3]);
- colMap.insert(CMVT_(dictobjectid, srcp));
- srcp.reset(col[4]);
- colMap.insert(CMVT_(listobjectid, srcp));
- srcp.reset(col[5]);
- colMap.insert(CMVT_(treeobjectid, srcp));
- srcp.reset(col[6]);
- colMap.insert(CMVT_(columnposition, srcp));
- srcp.reset(col[7]);
- colMap.insert(CMVT_(scale, srcp));
- srcp.reset(col[8]);
- colMap.insert(CMVT_(precision, srcp));
- // TODO: NULL value handling & convert to boost::any
- // delete this manually at fcn exit
- srcp.reset(col[9]);
- colMap.insert(CMVT_(defaultvalue, srcp));
- srcp.reset(col[10]);
- colMap.insert(CMVT_(schemaname, srcp));
- srcp.reset(col[11]);
- colMap.insert(CMVT_(tablename, srcp));
- srcp.reset(col[12]);
- colMap.insert(CMVT_(columnname, srcp));
- srcp.reset(col[13]);
- colMap.insert(CMVT_(nullable, srcp));
- srcp.reset(col[14]);
- colMap.insert(CMVT_(compressionType, srcp));
- srcp.reset(col[15]);
- colMap.insert(CMVT_(autoincrement, srcp));
- srcp.reset(col[16]);
- colMap.insert(CMVT_(nextvalue, srcp));
-
- csep.columnMapNonStatic(colMap);
-
- // ignore returnedcolumn, because it's not read by Joblist for now
- csep.returnedCols(returnedColumnList);
- OID oid[17];
- for (int i = 0; i < 17; i++)
- oid[i] = col[i]->oid();
- // Filters
- SimpleFilter *f1 = new SimpleFilter (opeq,
- col[1]->clone(),
- new ConstantColumn((int64_t)Oid, ConstantColumn::NUM));
- filterTokenList.push_back(f1);
-
- csep.filterTokenList(filterTokenList);
- ostringstream oss;
- oss << "select columnlength,datatype,dictobjectid,listobjectid,treeobjectid,columnposition,scale,compressiontype"
- "prec,defaultvalue,schema,tablename,columnname from syscolumn where objectid=" << Oid <<
- " --colType/";
- if (fIdentity == EC) oss << "EC";
- else oss << "FE";
- csep.data(oss.str());
- NJLSysDataList sysDataList;
- getSysData(csep, sysDataList, SYSCOLUMN_TABLE);
-
- TableColName tcn;
- vector<ColumnResult*>::const_iterator it;
- RID rid = std::numeric_limits<RID>::max();
- for (it = sysDataList.begin(); it != sysDataList.end(); it++)
- {
-
- if ((*it)->ColumnOID() == oid[0])
- {
- ct.colWidth = ((*it)->GetData(0));
- if (fIdentity == EC)
- rid = (*it)->GetRid(0);
- }
- else if ((*it)->ColumnOID() == oid[2])
- ct.colDataType = (ColDataType)((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[3])
- ct.ddn.dictOID = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[4])
- ct.ddn.listOID = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[5])
- ct.ddn.treeOID = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[6])
- ct.colPosition = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[7])
- ct.scale = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[8])
- ct.precision = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == DICTOID_SYSCOLUMN_DEFAULTVAL)
- {
- ct.defaultValue = ((*it)->GetStringData(0));
- if ((!ct.defaultValue.empty()) || (ct.defaultValue.length() > 0))
- {
- if (ct.constraintType != NOTNULL_CONSTRAINT)
- ct.constraintType = DEFAULT_CONSTRAINT;
- }
- }
- // NJL fix. The schema, table, and column now return the oids for the dictionary columns
- // on schema, table, and column.
- else if ((*it)->ColumnOID() == DICTOID_SYSCOLUMN_SCHEMA)
- tcn.schema = ((*it)->GetStringData(0));
- else if ((*it)->ColumnOID() == DICTOID_SYSCOLUMN_TABLENAME)
- tcn.table = ((*it)->GetStringData(0));
- else if ((*it)->ColumnOID() == DICTOID_SYSCOLUMN_COLNAME)
- tcn.column = ((*it)->GetStringData(0));
- else if ((*it)->ColumnOID() == oid[13])
- {
- if (static_cast<ConstraintType> ((*it)->GetData(0)) == 0)
- {
- ct.constraintType = NOTNULL_CONSTRAINT;
- }
- }
- else if ((*it)->ColumnOID() == oid[14])
- ct.compressionType = ct.ddn.compressionType = ((*it)->GetData(0));
- else if ((*it)->ColumnOID() == oid[15])
- {
- ostringstream os;
- os << (char) (*it)->GetData(0);
- if (os.str().compare("y") == 0)
- ct.autoincrement = true;
- else
- ct.autoincrement = false;
- }
- else if ((*it)->ColumnOID() == oid[16])
- ct.nextvalue = ((*it)->GetData(0));
-
- ct.columnOID = Oid;
- }
- // populate colinfomap cache and oidbitmap
- lk3.lock();
- boost::mutex::scoped_lock lk2(fOIDmapLock);
- fColinfomap[Oid] = ct;
- fOIDmap[tcn] = Oid;
- if (fIdentity == EC)
- fColRIDmap[tcn] = rid;
- //Prevent mem leak
- //delete col[9];
- return ct;
- }
- const CalpontSystemCatalog::ColType CalpontSystemCatalog::colTypeDct(const OID& dictOid)
- {
- if ( dictOid >= 3000)
- DEBUG << "Enter colType: " << dictOid << endl;
- ColType ct;
- // invalid oid
- if (dictOid < 1000)
- return ct;
-
- //Check whether cache needs to be flushed
- if ( dictOid >= 3000) {
- checkSysCatVer();
- }
- // check map first cached column type
- boost::mutex::scoped_lock lk3(fDctTokenMapLock);
- DctTokenMap::const_iterator iter = fDctTokenMap.find(dictOid);
- if (iter != fDctTokenMap.end())
- return colType(iter->second);
- lk3.unlock();
- /* SQL statement: select objectid from syscolumn where dictobjectid = dictOid;
- */
- CalpontSelectExecutionPlan csep;
- CalpontSelectExecutionPlan::ReturnedColumnList returnedColumnList;
- CalpontSelectExecutionPlan::FilterTokenList filterTokenList;
- CalpontSelectExecutionPlan::ColumnMap colMap;
-
- string objectid = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+OBJECTID_COL;
- string dictobjectid = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+DICTOID_COL;
- SimpleColumn* col[2];
- col[0] = new SimpleColumn(objectid, fSessionID);
- col[1] = new SimpleColumn(dictobjectid, fSessionID);
-
- SRCP srcp;
- srcp.reset(col[0]);
- colMap.insert(CMVT_(objectid, srcp));
- srcp.reset(col[1]);
- colMap.insert(CMVT_(dictobjectid, srcp));
- csep.columnMapNonStatic(colMap);
-
- // ignore returnedcolumn, because it's not read by Joblist for now
- csep.returnedCols(returnedColumnList);
- OID oid[2];
- for (int i = 0; i < 2; i++)
- oid[i] = col[i]->oid();
- // Filters
- SimpleFilter *f1 = new SimpleFilter (opeq,
- col[1]->clone(),
- new ConstantColumn((int64_t)dictOid, ConstantColumn::NUM));
- filterTokenList.push_back(f1);
-
- csep.filterTokenList(filterTokenList);
- ostringstream oss;
- oss << "select objectid from syscolumn where dictobjectid=" << dictOid << " --colTypeDct/";
- if (fIdentity == EC) oss << "EC";
- else oss << "FE";
- csep.data(oss.str());
- NJLSysDataList sysDataList;
- getSysData(csep, sysDataList, SYSCOLUMN_TABLE);
- vector<ColumnResult*>::const_iterator it;
- OID tokenOID = 0;
-
- for (it = sysDataList.begin(); it != sysDataList.end(); it++)
- {
- if ((*it)->ColumnOID() == oid[0])
- tokenOID = ((*it)->GetData(0));
- }
- // populate cache
- lk3.lock();
- fDctTokenMap[dictOid] = tokenOID;
- return colType(tokenOID);
- }
- const CalpontSystemCatalog::TableColName CalpontSystemCatalog::colName(const OID& oid)
- {
- if (oid >= 3000)
- DEBUG << "Enter colName: " << oid;
-
- TableColName tableColName;
-
- // invalid oid
- if (oid < 1000)
- return tableColName;
-
- //Check whether cache needs to be flushed
- if ( oid >= 3000) {
- checkSysCatVer();
- }
- // check oidmap for system table columns and cached columns
- boost::mutex::scoped_lock lk2(fOIDmapLock);
- OIDmap::const_iterator iter = fOIDmap.begin();
- while ( iter != fOIDmap.end() )
- {
- if (oid == (*iter).second )
- {
- tableColName = (*iter).first;
- DEBUG << "|in cache|" << tableColName.schema << "|" << tableColName.table << "|" << tableColName.column << endl;
- return tableColName;
- }
- ++iter;
- }
- lk2.unlock();
-
- // SQL statement: select schema, tablename, columnname from syscolumn where objectid = oid;
- CalpontSelectExecutionPlan csep;
- CalpontSelectExecutionPlan::ReturnedColumnList returnedColumnList;
- CalpontSelectExecutionPlan::FilterTokenList filterTokenList;
- CalpontSelectExecutionPlan::ColumnMap colMap;
-
- SimpleColumn *c1 = new SimpleColumn(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+OBJECTID_COL, fSessionID);
- SimpleColumn *c2 = new SimpleColumn(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+SCHEMA_COL, fSessionID);
- SimpleColumn *c3 = new SimpleColumn(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+TABLENAME_COL, fSessionID);
- SimpleColumn *c4 = new SimpleColumn(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+COLNAME_COL, fSessionID);
-
- SRCP srcp;
- srcp.reset(c1);
- colMap.insert(CMVT_(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+OBJECTID_COL, srcp));
- srcp.reset(c2);
- colMap.insert(CMVT_(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+SCHEMA_COL, srcp));
- srcp.reset(c3);
- colMap.insert(CMVT_(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+TABLENAME_COL, srcp));
- srcp.reset(c4);
- colMap.insert(CMVT_(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+COLNAME_COL, srcp));
- csep.columnMapNonStatic(colMap);
- srcp.reset(c2->clone());
- returnedColumnList.push_back(srcp);
- srcp.reset(c3->clone());
- returnedColumnList.push_back(srcp);
- srcp.reset(c4->clone());
- returnedColumnList.push_back(srcp);
- csep.returnedCols(returnedColumnList);
- // NJL fix. The dictionary column OID is now returned from getSysData.
- // OID oid2 = c2->oid();
- // OID oid3 = c3->oid();
- // OID oid4 = c4->oid();
- OID oid2 = DICTOID_SYSCOLUMN_SCHEMA;
- OID oid3 = DICTOID_SYSCOLUMN_TABLENAME;
- OID oid4 = DICTOID_SYSCOLUMN_COLNAME;
-
- // Filters
- SimpleFilter *f1 = new SimpleFilter (opeq,
- c1->clone(),
- new ConstantColumn((int64_t)oid, ConstantColumn::NUM));
- filterTokenList.push_back(f1);
-
- csep.filterTokenList(filterTokenList);
- ostringstream oss;
- oss << "select schema,tablename,columnname from syscolumn where objectid=" << oid <<
- " --colName/";
- if (fIdentity == EC) oss << "EC";
- else oss << "FE";
- csep.data(oss.str());
- NJLSysDataList sysDataList;
- getSysData (csep, sysDataList, SYSCOLUMN_TABLE);
-
- vector<ColumnResult*>::const_iterator it;
- for (it = sysDataList.begin(); it != sysDataList.end(); it++)
- {
- if ((*it)->ColumnOID() == oid2)
- tableColName.schema = (*it)->GetStringData(0);
- else if ((*it)->ColumnOID() == oid3)
- tableColName.table = (*it)->GetStringData(0);
- else if ((*it)->ColumnOID() == oid4)
- tableColName.column = (*it)->GetStringData(0);
- }
- if (oid > 3000)
- DEBUG << "|" << tableColName.schema << "|" << tableColName.table << "|" << tableColName.column << endl;
- #if BOOST_VERSION < 103800
- if (!lk2.locked()) lk2.lock();
- #else
- if (!lk2.owns_lock()) lk2.lock();
- #endif
- fOIDmap[tableColName] = oid;
-
- return tableColName;
- }
- const CalpontSystemCatalog::TableColName CalpontSystemCatalog::dictColName(const OID& oid)
- {
- if (oid >= 3000)
- DEBUG << "Enter dictColName: " << oid;
-
- TableColName tableColName;
-
- // invalid oid
- if (oid < 1000)
- return tableColName;
-
- //Check whether cache needs to be flushed
- if ( oid >= 3000) {
- checkSysCatVer();
- }
-
- // SQL statement: select schema, tablename, columnname from syscolumn where dictobjectid = oid;
- CalpontSelectExecutionPlan csep;
- CalpontSelectExecutionPlan::ReturnedColumnList returnedColumnList;
- CalpontSelectExecutionPlan::FilterTokenList filterTokenList;
- CalpontSelectExecutionPlan::ColumnMap colMap;
-
- SimpleColumn *c1 = new SimpleColumn(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+DICTOID_COL, fSessionID);
- SimpleColumn *c2 = new SimpleColumn(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+SCHEMA_COL, fSessionID);
- SimpleColumn *c3 = new SimpleColumn(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+TABLENAME_COL, fSessionID);
- SimpleColumn *c4 = new SimpleColumn(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+COLNAME_COL, fSessionID);
-
- SRCP srcp;
- srcp.reset(c1);
- colMap.insert(CMVT_(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+DICTOID_COL, srcp));
- srcp.reset(c2);
- colMap.insert(CMVT_(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+SCHEMA_COL, srcp));
- srcp.reset(c3);
- colMap.insert(CMVT_(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+TABLENAME_COL, srcp));
- srcp.reset(c4);
- colMap.insert(CMVT_(CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+COLNAME_COL, srcp));
- csep.columnMapNonStatic(colMap);
- srcp.reset(c2->clone());
- returnedColumnList.push_back(srcp);
- srcp.reset(c3->clone());
- returnedColumnList.push_back(srcp);
- srcp.reset(c4->clone());
- returnedColumnList.push_back(srcp);
- csep.returnedCols(returnedColumnList);
- OID oid2 = DICTOID_SYSCOLUMN_SCHEMA;
- OID oid3 = DICTOID_SYSCOLUMN_TABLENAME;
- OID oid4 = DICTOID_SYSCOLUMN_COLNAME;
-
- // Filters
- SimpleFilter *f1 = new SimpleFilter (opeq,
- c1->clone(),
- new ConstantColumn((int64_t)oid, ConstantColumn::NUM));
- filterTokenList.push_back(f1);
-
- csep.filterTokenList(filterTokenList);
- ostringstream oss;
- oss << "select schema,tablename,columnname from syscolumn where dictobjectid=" << oid <<
- " --colName/";
- if (fIdentity == EC) oss << "EC";
- else oss << "FE";
- csep.data(oss.str());
- NJLSysDataList sysDataList;
- getSysData (csep, sysDataList, SYSCOLUMN_TABLE);
-
- vector<ColumnResult*>::const_iterator it;
- for (it = sysDataList.begin(); it != sysDataList.end(); it++)
- {
- if ((*it)->ColumnOID() == oid2)
- tableColName.schema = (*it)->GetStringData(0);
- else if ((*it)->ColumnOID() == oid3)
- tableColName.table = (*it)->GetStringData(0);
- else if ((*it)->ColumnOID() == oid4)
- tableColName.column = (*it)->GetStringData(0);
- }
- if (oid > 3000)
- DEBUG << "|" << tableColName.schema << "|" << tableColName.table << "|" << tableColName.column << endl;
-
- return tableColName;
- }
- const uint64_t CalpontSystemCatalog::nextAutoIncrValue ( TableName aTableName)
- {
- transform( aTableName.schema.begin(), aTableName.schema.end(), aTableName.schema.begin(), to_lower() );
- transform( aTableName.table.begin(), aTableName.table.end(), aTableName.table.begin(), to_lower() );
-
- TableInfo tbInfo;
- try {
- tbInfo = tableInfo (aTableName);
- }
- catch (runtime_error& /*ex*/)
- {
- throw;
- }
-
- if (tbInfo.tablewithautoincr == NO_AUTOINCRCOL)
- return AUTOINCR_SATURATED;
- //Build a plan to get current nextvalue: select nextvalue from syscolumn where schema = tableName.schema and tablename = tableName.table and autoincrement='y';
- CalpontSelectExecutionPlan csep;
- CalpontSelectExecutionPlan::ReturnedColumnList returnedColumnList;
- CalpontSelectExecutionPlan::FilterTokenList filterTokenList;
- CalpontSelectExecutionPlan::ColumnMap colMap;
-
- string tablename = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+TABLENAME_COL;
- string schemaname = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+SCHEMA_COL;
- string autoincrement = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+AUTOINC_COL;
- string nextvalue = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+NEXTVALUE_COL;
-
- SimpleColumn* col[5];
- col[0] = new SimpleColumn(tablename, fSessionID);
- col[1] = new SimpleColumn(schemaname, fSessionID);
- col[2] = new SimpleColumn(autoincrement, fSessionID);
- col[3] = new SimpleColumn(nextvalue, fSessionID);
-
- SRCP srcp;
- srcp.reset(col[0]);
- colMap.insert(CMVT_(tablename, srcp));
- srcp.reset(col[1]);
- colMap.insert(CMVT_(schemaname, srcp));
- srcp.reset(col[2]);
- colMap.insert(CMVT_(autoincrement, srcp));
- srcp.reset(col[3]);
- colMap.insert(CMVT_(nextvalue, srcp));
-
- csep.columnMapNonStatic(colMap);
-
- csep.returnedCols(returnedColumnList);
-
- OID oid[4];
- for (int i = 0; i < 4; i++)
- oid[i] = col[i]->oid();
- // Filters
- SimpleFilter *f1 = new SimpleFilter (opeq,
- col[1]->clone(),
- new ConstantColumn(aTableName.schema, ConstantColumn::LITERAL));
- filterTokenList.push_back(f1);
- filterTokenList.push_back(new Operator("and"));
- SimpleFilter *f2 = new SimpleFilter (opeq,
- col[0]->clone(),
- new ConstantColumn(aTableName.table, ConstantColumn::LITERAL));
- filterTokenList.push_back(f2);
- filterTokenList.push_back(new Operator("and"));
- SimpleFilter *f3 = new SimpleFilter (opeq,
- col[2]->clone(),
- new ConstantColumn("y", ConstantColumn::LITERAL));
- filterTokenList.push_back(f3);
- csep.filterTokenList(filterTokenList);
- ostringstream oss;
- oss << "select nextvalue from syscolumn where schema = aTableName.schema and tablename = aTableName.table and autoincrement='y'";
- if (fIdentity == EC) oss << "EC";
- else oss << "FE";
- csep.data(oss.str());
-
- NJLSysDataList sysDataList;
- try {
- getSysData(csep, sysDataList, SYSCOLUMN_TABLE);
- }
- catch (runtime_error& e)
- {
- throw runtime_error ( e.what() );
- }
- uint64_t nextVal = AUTOINCR_SATURATED;
- vector<ColumnResult*>::const_iterator it;
- for (it = sysDataList.begin(); it != sysDataList.end(); it++)
- {
-
- if ((*it)->ColumnOID() == oid[3])
- {
- nextVal = static_cast<uint64_t>(((*it)->GetData(0)));
- }
- }
-
- return (nextVal);
-
- }
- int32_t CalpontSystemCatalog::autoColumOid ( TableName aTableName)
- {
- transform( aTableName.schema.begin(), aTableName.schema.end(), aTableName.schema.begin(), to_lower() );
- transform( aTableName.table.begin(), aTableName.table.end(), aTableName.table.begin(), to_lower() );
-
- TableInfo tbInfo;
- try {
- tbInfo = tableInfo (aTableName);
- }
- catch (runtime_error& /*ex*/)
- {
- return -2;
- }
-
- if (tbInfo.tablewithautoincr == NO_AUTOINCRCOL)
- return 0;
- //Build a plan to get column oid: select objectid from syscolumn where schema = tableName.schema and tablename = tableName.table and autoincrement='y';
- CalpontSelectExecutionPlan csep;
- CalpontSelectExecutionPlan::ReturnedColumnList returnedColumnList;
- CalpontSelectExecutionPlan::FilterTokenList filterTokenList;
- CalpontSelectExecutionPlan::ColumnMap colMap;
-
- string tablename = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+TABLENAME_COL;
- string schemaname = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+SCHEMA_COL;
- string autoincrement = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+AUTOINC_COL;
- string objectid = CALPONT_SCHEMA+"."+SYSCOLUMN_TABLE+"."+OBJECTID_COL;
-
- SimpleColumn* col[5];
- col[0] = new SimpleColumn(tablename, fSessionID);
- col[1] = new SimpleColumn(schemaname, fSessionID);
- col[2] = new SimpleColumn(autoincrement, fSessionID);
- col[3] = new SimpleColumn(objectid, fSessionID);
-
- SRCP srcp;
- srcp.reset(col[0]);
- colMap.insert(CMVT_(tablename, srcp));
- srcp.reset(col[1]);
- colMap.insert(CMVT_(schemaname, srcp));
- srcp.reset(col[2]);
- colMap.insert(CMVT_(autoincrement, srcp));
- srcp.reset(col[3]);
- colMap.insert(CMVT_(objectid, srcp));
-
- csep.columnMapNonStatic(colMap);
-
- csep.returnedCols(returnedColumnList);
-
- OID oid[4];
- for (int i = 0; i < 4; i++)
- oid[i] = col[i]->oid();
- // Filters
- SimpleFilter *f1 = new SimpleFilter (opeq,
- col[1]->clone(),
- new ConstantColumn(aTableName.schema, C…
Large files files are truncated, but you can click here to view the full file