You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-12-06 08:40:57 +03:00
Reformat all code to coding standard
This commit is contained in:
@@ -25,217 +25,228 @@
|
||||
#include "ddlpkg.h"
|
||||
#undef DDLPKG_DLLEXPORT
|
||||
|
||||
namespace ddlpackage {
|
||||
using namespace std;
|
||||
namespace ddlpackage
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
AlterTableStatement::AlterTableStatement(QualifiedName *qName, AlterTableActionList *ataList):
|
||||
AlterTableStatement::AlterTableStatement(QualifiedName* qName, AlterTableActionList* ataList):
|
||||
fTableName(qName),
|
||||
fActions(*ataList)
|
||||
{
|
||||
{
|
||||
delete ataList;
|
||||
}
|
||||
}
|
||||
|
||||
AlterTableStatement::~AlterTableStatement()
|
||||
{
|
||||
AlterTableStatement::~AlterTableStatement()
|
||||
{
|
||||
delete fTableName;
|
||||
AlterTableActionList::iterator itr;
|
||||
for(itr=fActions.begin(); itr != fActions.end(); ++itr) {
|
||||
|
||||
for (itr = fActions.begin(); itr != fActions.end(); ++itr)
|
||||
{
|
||||
delete *itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& AlterTableStatement::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& AlterTableStatement::put(std::ostream& os) const
|
||||
{
|
||||
AlterTableActionList::const_iterator itr;
|
||||
os << "Alter Table " << *fTableName << endl;
|
||||
|
||||
for(itr = fActions.begin(); itr != fActions.end(); ++itr) {
|
||||
for (itr = fActions.begin(); itr != fActions.end(); ++itr)
|
||||
{
|
||||
os << **itr << endl;
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @brief Format to ostream. Diagnostic. */
|
||||
std::ostream& AlterTableAction::put(std::ostream& os) const
|
||||
{
|
||||
/** @brief Format to ostream. Diagnostic. */
|
||||
std::ostream& AlterTableAction::put(std::ostream& os) const
|
||||
{
|
||||
os << "AlterTableAction put stub";
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief Invokes the virtual function put, to dispatch to subclass
|
||||
/** @brief Invokes the virtual function put, to dispatch to subclass
|
||||
ostream writers. */
|
||||
std::ostream &operator<<(std::ostream& os, const AlterTableAction &ata)
|
||||
{
|
||||
std::ostream& operator<<(std::ostream& os, const AlterTableAction& ata)
|
||||
{
|
||||
return ata.put(os);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AtaAddColumn::~AtaAddColumn()
|
||||
{
|
||||
AtaAddColumn::~AtaAddColumn()
|
||||
{
|
||||
delete fColumnDef;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** @brief ostream output */
|
||||
std::ostream& AtaAddColumn::put(std::ostream& os) const
|
||||
{
|
||||
/** @brief ostream output */
|
||||
std::ostream& AtaAddColumn::put(std::ostream& os) const
|
||||
{
|
||||
os << "Add Column" << endl;
|
||||
os << *fColumnDef << endl;
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AtaDropColumn::AtaDropColumn(std::string columnName, DDL_REFERENTIAL_ACTION dropBehavior) :
|
||||
AtaDropColumn::AtaDropColumn(std::string columnName, DDL_REFERENTIAL_ACTION dropBehavior) :
|
||||
fColumnName(columnName),
|
||||
fDropBehavior(dropBehavior)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
std::ostream& AtaDropColumn::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& AtaDropColumn::put(std::ostream& os) const
|
||||
{
|
||||
os << "Drop Column: " << fColumnName << " "
|
||||
<< ReferentialActionStrings[fDropBehavior];
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AtaModifyColumnType::~AtaModifyColumnType()
|
||||
{
|
||||
AtaModifyColumnType::~AtaModifyColumnType()
|
||||
{
|
||||
delete fColumnType;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& AtaModifyColumnType::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& AtaModifyColumnType::put(std::ostream& os) const
|
||||
{
|
||||
os << "Modify column type: " << fName << " " << *fColumnType;
|
||||
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AtaRenameColumn::~AtaRenameColumn()
|
||||
{
|
||||
AtaRenameColumn::~AtaRenameColumn()
|
||||
{
|
||||
delete fNewType;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& AtaRenameColumn::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& AtaRenameColumn::put(std::ostream& os) const
|
||||
{
|
||||
os << "Rename Column: " << fName << " -> " << fNewName << " (" << *fNewType << ')';
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AtaSetColumnDefault::AtaSetColumnDefault(const char *colName, ColumnDefaultValue *defaultValue) :
|
||||
AtaSetColumnDefault::AtaSetColumnDefault(const char* colName, ColumnDefaultValue* defaultValue) :
|
||||
fColumnName(colName),
|
||||
fDefaultValue(defaultValue)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtaSetColumnDefault::~AtaSetColumnDefault()
|
||||
{
|
||||
AtaSetColumnDefault::~AtaSetColumnDefault()
|
||||
{
|
||||
delete fDefaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::ostream& AtaSetColumnDefault::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& AtaSetColumnDefault::put(std::ostream& os) const
|
||||
{
|
||||
os << "Set Column Default: " << fColumnName << " "
|
||||
<< *fDefaultValue << endl;
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
AtaDropColumnDefault::AtaDropColumnDefault(const char *colName) :
|
||||
AtaDropColumnDefault::AtaDropColumnDefault(const char* colName) :
|
||||
fColumnName(colName)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
std::ostream& AtaDropColumnDefault::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& AtaDropColumnDefault::put(std::ostream& os) const
|
||||
{
|
||||
os << "Drop Column Default: " << fColumnName << " ";
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
AtaRenameTable::AtaRenameTable(QualifiedName *qualifiedName) :
|
||||
AtaRenameTable::AtaRenameTable(QualifiedName* qualifiedName) :
|
||||
fQualifiedName(qualifiedName)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
AtaRenameTable::~AtaRenameTable()
|
||||
{
|
||||
AtaRenameTable::~AtaRenameTable()
|
||||
{
|
||||
delete fQualifiedName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::ostream& AtaRenameTable::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& AtaRenameTable::put(std::ostream& os) const
|
||||
{
|
||||
os << "Rename Table: " << *fQualifiedName << endl;
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AtaTableComment::AtaTableComment(const char *tableComment) :
|
||||
AtaTableComment::AtaTableComment(const char* tableComment) :
|
||||
fTableComment(tableComment)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
AtaTableComment::~AtaTableComment()
|
||||
{
|
||||
}
|
||||
AtaTableComment::~AtaTableComment()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::ostream& AtaTableComment::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& AtaTableComment::put(std::ostream& os) const
|
||||
{
|
||||
os << "TableComment: " << fTableComment << endl;
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AtaAddColumns::~AtaAddColumns()
|
||||
{
|
||||
AtaAddColumns::~AtaAddColumns()
|
||||
{
|
||||
ColumnDefList::iterator itr;
|
||||
for(itr=fColumns.begin(); itr != fColumns.end(); itr++)
|
||||
|
||||
for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
|
||||
delete *itr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AtaAddColumns::AtaAddColumns(TableElementList *tableElements)
|
||||
{
|
||||
AtaAddColumns::AtaAddColumns(TableElementList* tableElements)
|
||||
{
|
||||
/* It is convenient to reuse the grammar rules for
|
||||
table_element_list, and we do. So, it is possible for
|
||||
there to be errant table constraint defs in the input list.
|
||||
We ignore them. That is all we are doing here.
|
||||
*/
|
||||
ColumnDef *column;
|
||||
ColumnDef* column;
|
||||
TableElementList::const_iterator itr;
|
||||
for(itr = tableElements->begin();
|
||||
|
||||
for (itr = tableElements->begin();
|
||||
itr != tableElements->end();
|
||||
++itr)
|
||||
{
|
||||
column = dynamic_cast<ColumnDef *>(*itr);
|
||||
if(0 != column) {
|
||||
column = dynamic_cast<ColumnDef*>(*itr);
|
||||
|
||||
if (0 != column)
|
||||
{
|
||||
fColumns.push_back(column);
|
||||
}
|
||||
}
|
||||
delete tableElements;
|
||||
}
|
||||
|
||||
std::ostream& AtaAddColumns::put(std::ostream& os) const
|
||||
{
|
||||
delete tableElements;
|
||||
}
|
||||
|
||||
std::ostream& AtaAddColumns::put(std::ostream& os) const
|
||||
{
|
||||
os << "Add Columns: " << endl;
|
||||
ColumnDefList::const_iterator itr;
|
||||
for(itr = fColumns.begin();
|
||||
|
||||
for (itr = fColumns.begin();
|
||||
itr != fColumns.end();
|
||||
++itr)
|
||||
{
|
||||
@@ -243,25 +254,26 @@ namespace ddlpackage {
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
//////////////////////////
|
||||
}
|
||||
//////////////////////////
|
||||
|
||||
AtaDropColumns::~AtaDropColumns()
|
||||
{
|
||||
}
|
||||
AtaDropColumns::~AtaDropColumns()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtaDropColumns::AtaDropColumns(ColumnNameList *columnNames)
|
||||
{
|
||||
AtaDropColumns::AtaDropColumns(ColumnNameList* columnNames)
|
||||
{
|
||||
fColumns = *columnNames;
|
||||
delete columnNames;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& AtaDropColumns::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& AtaDropColumns::put(std::ostream& os) const
|
||||
{
|
||||
os << "Drop Columns: " << endl;
|
||||
ColumnNameList::const_iterator itr;
|
||||
for(itr = fColumns.begin();
|
||||
|
||||
for (itr = fColumns.begin();
|
||||
itr != fColumns.end();
|
||||
++itr)
|
||||
{
|
||||
@@ -269,43 +281,43 @@ namespace ddlpackage {
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
AtaAddTableConstraint::AtaAddTableConstraint(TableConstraintDef *tableConstraint) :
|
||||
AtaAddTableConstraint::AtaAddTableConstraint(TableConstraintDef* tableConstraint) :
|
||||
fTableConstraint(tableConstraint)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
AtaAddTableConstraint::~AtaAddTableConstraint()
|
||||
{
|
||||
AtaAddTableConstraint::~AtaAddTableConstraint()
|
||||
{
|
||||
delete fTableConstraint;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::ostream& AtaAddTableConstraint::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& AtaAddTableConstraint::put(std::ostream& os) const
|
||||
{
|
||||
os << "Add Table Constraint:" << endl;
|
||||
os << *fTableConstraint << endl;
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
AtaDropTableConstraint::AtaDropTableConstraint
|
||||
(const char *constraintName, DDL_REFERENTIAL_ACTION dropBehavior) :
|
||||
AtaDropTableConstraint::AtaDropTableConstraint
|
||||
(const char* constraintName, DDL_REFERENTIAL_ACTION dropBehavior) :
|
||||
fConstraintName(constraintName),
|
||||
fDropBehavior(dropBehavior)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
std::ostream& AtaDropTableConstraint::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& AtaDropTableConstraint::put(std::ostream& os) const
|
||||
{
|
||||
os << "Drop Table Constraint: " << fConstraintName;
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,37 +28,42 @@
|
||||
#include "ddlpkg.h"
|
||||
#undef DDLPKG_DLLEXPORT
|
||||
|
||||
namespace ddlpackage {
|
||||
namespace ddlpackage
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace std;
|
||||
|
||||
ColumnDef::~ColumnDef()
|
||||
{
|
||||
ColumnDef::~ColumnDef()
|
||||
{
|
||||
delete fType;
|
||||
delete fDefaultValue;
|
||||
ColumnConstraintList::iterator itr;
|
||||
for(itr=fConstraints.begin(); itr != fConstraints.end(); ++itr) {
|
||||
|
||||
for (itr = fConstraints.begin(); itr != fConstraints.end(); ++itr)
|
||||
{
|
||||
delete *itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColumnDef::ColumnDef(const char *name, ColumnType* columnType, ColumnConstraintList *constraints,
|
||||
ColumnDefaultValue *defaultValue, const char * comment ) :
|
||||
ColumnDef::ColumnDef(const char* name, ColumnType* columnType, ColumnConstraintList* constraints,
|
||||
ColumnDefaultValue* defaultValue, const char* comment ) :
|
||||
SchemaObject(name),
|
||||
fType(columnType),
|
||||
fDefaultValue(defaultValue)
|
||||
{
|
||||
if (constraints)
|
||||
{
|
||||
if(constraints) {
|
||||
fConstraints = *constraints;
|
||||
delete constraints;
|
||||
}
|
||||
|
||||
if ( comment )
|
||||
fComment = comment;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ostream &operator<<(ostream& os, const ColumnType& columnType)
|
||||
{
|
||||
ostream& operator<<(ostream& os, const ColumnType& columnType)
|
||||
{
|
||||
os << setw(12) << left << DDLDatatypeString[columnType.fType]
|
||||
<< "["
|
||||
<< "L=" << setw(2) << columnType.fLength << ","
|
||||
@@ -67,14 +72,15 @@ namespace ddlpackage {
|
||||
<< "T=" << setw(2) << columnType.fWithTimezone
|
||||
<< "]";
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ostream &operator<<(ostream& os, const ColumnDef &column)
|
||||
{
|
||||
ostream& operator<<(ostream& os, const ColumnDef& column)
|
||||
{
|
||||
os << "Column: " << column.fName << " " << *column.fType;
|
||||
|
||||
if(column.fDefaultValue) {
|
||||
if (column.fDefaultValue)
|
||||
{
|
||||
os << " def=";
|
||||
|
||||
if (column.fDefaultValue->fNull)
|
||||
@@ -87,61 +93,68 @@ namespace ddlpackage {
|
||||
<< " constraints ";
|
||||
|
||||
ColumnConstraintList::const_iterator itr;
|
||||
for(itr = column.fConstraints.begin();
|
||||
|
||||
for (itr = column.fConstraints.begin();
|
||||
itr != column.fConstraints.end();
|
||||
++itr) {
|
||||
ColumnConstraintDef *con = *itr;
|
||||
++itr)
|
||||
{
|
||||
ColumnConstraintDef* con = *itr;
|
||||
os << *con;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ostream &operator<<(ostream& os, const ColumnConstraintDef &con)
|
||||
{
|
||||
ostream& operator<<(ostream& os, const ColumnConstraintDef& con)
|
||||
{
|
||||
os << " Constraint: "
|
||||
<< con.fName << " "
|
||||
<< ConstraintString[con.fConstraintType] << " "
|
||||
<< "defer=" << con.fDeferrable << " "
|
||||
<< ConstraintAttrStrings[con.fCheckTime] << " ";
|
||||
if(!con.fCheck.empty())
|
||||
|
||||
if (!con.fCheck.empty())
|
||||
os << "check=" << "\"" << con.fCheck << "\"";
|
||||
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream& os, const ColumnDefList &clist)
|
||||
{
|
||||
std::ostream& operator<<(std::ostream& os, const ColumnDefList& clist)
|
||||
{
|
||||
ColumnDefList::const_iterator itr;
|
||||
for(itr = clist.begin(); itr != clist.end(); ++itr){
|
||||
|
||||
for (itr = clist.begin(); itr != clist.end(); ++itr)
|
||||
{
|
||||
os << **itr;
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ColumnDefaultValue::ColumnDefaultValue(const char *value) :
|
||||
ColumnDefaultValue::ColumnDefaultValue(const char* value) :
|
||||
fNull(false)
|
||||
{
|
||||
if(0 == value)
|
||||
{
|
||||
if (0 == value)
|
||||
fNull = true;
|
||||
else
|
||||
fValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::ostream &operator<<(std::ostream& os, const ColumnDefaultValue &defaultValue)
|
||||
{
|
||||
std::ostream& operator<<(std::ostream& os, const ColumnDefaultValue& defaultValue)
|
||||
{
|
||||
os << " def=";
|
||||
|
||||
if (defaultValue.fNull)
|
||||
os << "NULL";
|
||||
else
|
||||
os << defaultValue.fValue;
|
||||
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,38 +23,39 @@
|
||||
|
||||
#include "ddlpkg.h"
|
||||
|
||||
namespace ddlpackage {
|
||||
using namespace std;
|
||||
namespace ddlpackage
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
CreateIndexStatement::CreateIndexStatement():
|
||||
CreateIndexStatement::CreateIndexStatement():
|
||||
fIndexName(NULL),
|
||||
fTableName(NULL),
|
||||
fColumnNames(),
|
||||
fUnique(false)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
CreateIndexStatement::CreateIndexStatement(QualifiedName *indexName, QualifiedName *tableName,
|
||||
ColumnNameList *columnNames, bool unique) :
|
||||
CreateIndexStatement::CreateIndexStatement(QualifiedName* indexName, QualifiedName* tableName,
|
||||
ColumnNameList* columnNames, bool unique) :
|
||||
fIndexName(indexName),
|
||||
fTableName(tableName),
|
||||
fColumnNames(*columnNames),
|
||||
fUnique(unique)
|
||||
{
|
||||
{
|
||||
delete columnNames;
|
||||
}
|
||||
}
|
||||
|
||||
CreateIndexStatement::~CreateIndexStatement()
|
||||
{
|
||||
CreateIndexStatement::~CreateIndexStatement()
|
||||
{
|
||||
delete fIndexName;
|
||||
delete fTableName;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& CreateIndexStatement::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& CreateIndexStatement::put(std::ostream& os) const
|
||||
{
|
||||
os << "Create Index: " << *fIndexName << " on " << *fTableName
|
||||
<< fColumnNames << endl;
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,34 +27,35 @@
|
||||
#include "ddlpkg.h"
|
||||
#undef DDLPKG_DLLEXPORT
|
||||
|
||||
namespace ddlpackage {
|
||||
namespace ddlpackage
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace std;
|
||||
|
||||
CreateTableStatement::CreateTableStatement() :
|
||||
CreateTableStatement::CreateTableStatement() :
|
||||
fTableDef(0)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
CreateTableStatement::CreateTableStatement(TableDef* tableDef) :
|
||||
CreateTableStatement::CreateTableStatement(TableDef* tableDef) :
|
||||
fTableDef(tableDef)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CreateTableStatement::~CreateTableStatement()
|
||||
{
|
||||
CreateTableStatement::~CreateTableStatement()
|
||||
{
|
||||
if (fTableDef)
|
||||
{
|
||||
delete fTableDef;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** \brief Put to ostream. */
|
||||
ostream& CreateTableStatement::put(ostream& os) const
|
||||
{
|
||||
/** \brief Put to ostream. */
|
||||
ostream& CreateTableStatement::put(ostream& os) const
|
||||
{
|
||||
os << "CreateTable "
|
||||
<< *fTableDef;
|
||||
return os;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,9 +36,10 @@
|
||||
/* Tokens. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
/* Put the tokens into the symbol table, so that GDB and other debuggers
|
||||
/* Put the tokens into the symbol table, so that GDB and other debuggers
|
||||
know about them. */
|
||||
enum yytokentype {
|
||||
enum yytokentype
|
||||
{
|
||||
ACTION = 258,
|
||||
ADD = 259,
|
||||
ALTER = 260,
|
||||
@@ -122,7 +123,7 @@
|
||||
CP_SEARCH_CONDITION_TEXT = 338,
|
||||
ICONST = 339,
|
||||
DATE = 340
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -132,33 +133,33 @@ typedef union YYSTYPE
|
||||
{
|
||||
|
||||
|
||||
ddlpackage::AlterTableStatement *alterTableStmt;
|
||||
ddlpackage::AlterTableAction *ata;
|
||||
ddlpackage::AlterTableActionList *ataList;
|
||||
ddlpackage::AlterTableStatement* alterTableStmt;
|
||||
ddlpackage::AlterTableAction* ata;
|
||||
ddlpackage::AlterTableActionList* ataList;
|
||||
ddlpackage::DDL_CONSTRAINT_ATTRIBUTES cattr;
|
||||
std::pair<std::string, std::string> *tableOption;
|
||||
const char *columnOption;
|
||||
ddlpackage::ColumnConstraintDef *columnConstraintDef;
|
||||
ddlpackage::ColumnNameList *columnNameList;
|
||||
std::pair<std::string, std::string>* tableOption;
|
||||
const char* columnOption;
|
||||
ddlpackage::ColumnConstraintDef* columnConstraintDef;
|
||||
ddlpackage::ColumnNameList* columnNameList;
|
||||
ddlpackage::ColumnType* columnType;
|
||||
ddlpackage::ConstraintAttributes *constraintAttributes;
|
||||
ddlpackage::ColumnConstraintList *constraintList;
|
||||
ddlpackage::ConstraintAttributes* constraintAttributes;
|
||||
ddlpackage::ColumnConstraintList* constraintList;
|
||||
ddlpackage::DDL_CONSTRAINTS constraintType;
|
||||
double dval;
|
||||
bool flag;
|
||||
int ival;
|
||||
ddlpackage::QualifiedName *qualifiedName;
|
||||
ddlpackage::SchemaObject *schemaObject;
|
||||
ddlpackage::SqlStatement *sqlStmt;
|
||||
ddlpackage::SqlStatementList *sqlStmtList;
|
||||
const char *str;
|
||||
ddlpackage::TableConstraintDef *tableConstraint;
|
||||
ddlpackage::TableElementList *tableElementList;
|
||||
ddlpackage::TableOptionMap *tableOptionMap;
|
||||
ddlpackage::ColumnDefaultValue *colDefault;
|
||||
ddlpackage::QualifiedName* qualifiedName;
|
||||
ddlpackage::SchemaObject* schemaObject;
|
||||
ddlpackage::SqlStatement* sqlStmt;
|
||||
ddlpackage::SqlStatementList* sqlStmtList;
|
||||
const char* str;
|
||||
ddlpackage::TableConstraintDef* tableConstraint;
|
||||
ddlpackage::TableElementList* tableElementList;
|
||||
ddlpackage::TableOptionMap* tableOptionMap;
|
||||
ddlpackage::ColumnDefaultValue* colDefault;
|
||||
ddlpackage::DDL_MATCH_TYPE matchType;
|
||||
ddlpackage::DDL_REFERENTIAL_ACTION refActionCode;
|
||||
ddlpackage::ReferentialAction *refAction;
|
||||
ddlpackage::ReferentialAction* refAction;
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -29,103 +29,113 @@
|
||||
|
||||
namespace ddlpackage
|
||||
{
|
||||
using namespace std;
|
||||
using namespace std;
|
||||
|
||||
QualifiedName::QualifiedName(const char *name):
|
||||
QualifiedName::QualifiedName(const char* name):
|
||||
fName(name)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
QualifiedName::QualifiedName(const char *schema, const char *name):
|
||||
QualifiedName::QualifiedName(const char* schema, const char* name):
|
||||
fName(name),
|
||||
fSchema(schema)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
QualifiedName::QualifiedName(const char* catalog, const char *schema, const char *name):
|
||||
QualifiedName::QualifiedName(const char* catalog, const char* schema, const char* name):
|
||||
fCatalog(catalog),
|
||||
fName(name),
|
||||
fSchema(schema)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream &os, const QualifiedName& qname)
|
||||
{
|
||||
if(!qname.fCatalog.empty())
|
||||
ostream& operator<<(ostream& os, const QualifiedName& qname)
|
||||
{
|
||||
if (!qname.fCatalog.empty())
|
||||
os << qname.fCatalog << ".";
|
||||
if(!qname.fSchema.empty())
|
||||
|
||||
if (!qname.fSchema.empty())
|
||||
os << qname.fSchema << ".";
|
||||
|
||||
os << qname.fName;
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** @brief Map a DECIMAL precision to data width in bytes */
|
||||
unsigned int precision_width(unsigned p)
|
||||
{
|
||||
switch(p)
|
||||
/** @brief Map a DECIMAL precision to data width in bytes */
|
||||
unsigned int precision_width(unsigned p)
|
||||
{
|
||||
switch (p)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
return 1;
|
||||
|
||||
case 3:
|
||||
case 4:
|
||||
return 2;
|
||||
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
return 4;
|
||||
|
||||
default:
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColumnType::ColumnType(int prec, int scale) :
|
||||
ColumnType::ColumnType(int prec, int scale) :
|
||||
fType(DDL_INVALID_DATATYPE),
|
||||
fLength(0),
|
||||
fPrecision(prec),
|
||||
fScale(scale),
|
||||
fWithTimezone(false)
|
||||
{
|
||||
{
|
||||
fLength = precision_width(fPrecision);
|
||||
}
|
||||
}
|
||||
|
||||
ColumnType::ColumnType(int type) :
|
||||
ColumnType::ColumnType(int type) :
|
||||
fType(type),
|
||||
fLength(0),
|
||||
fScale(0),
|
||||
fWithTimezone(false)
|
||||
{
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
case DDL_TINYINT:
|
||||
case DDL_UNSIGNED_TINYINT:
|
||||
fPrecision = 3;
|
||||
break;
|
||||
|
||||
case DDL_SMALLINT:
|
||||
case DDL_UNSIGNED_SMALLINT:
|
||||
fPrecision = 5;
|
||||
break;
|
||||
|
||||
case DDL_INT:
|
||||
case DDL_UNSIGNED_INT:
|
||||
case DDL_MEDINT:
|
||||
fPrecision = 10;
|
||||
break;
|
||||
|
||||
case DDL_BIGINT:
|
||||
fPrecision = 19;
|
||||
|
||||
case DDL_UNSIGNED_BIGINT:
|
||||
fPrecision = 20;
|
||||
break;
|
||||
|
||||
default:
|
||||
fPrecision = 10;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
ColumnType::ColumnType(int type, int length, int precision, int scale, int compressiontype, const char* autoIncrement, int64_t nextValue, bool withTimezone) :
|
||||
fType(type) ,
|
||||
ColumnType::ColumnType(int type, int length, int precision, int scale, int compressiontype, const char* autoIncrement, int64_t nextValue, bool withTimezone) :
|
||||
fType(type),
|
||||
fLength(length),
|
||||
fPrecision(precision),
|
||||
fScale(scale),
|
||||
@@ -133,42 +143,42 @@ namespace ddlpackage
|
||||
fCompressiontype(compressiontype),
|
||||
fAutoincrement(autoIncrement),
|
||||
fNextvalue(nextValue)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
#endif
|
||||
ColumnConstraintDef::ColumnConstraintDef(DDL_CONSTRAINTS type) :
|
||||
ColumnConstraintDef::ColumnConstraintDef(DDL_CONSTRAINTS type) :
|
||||
SchemaObject(),
|
||||
fDeferrable(false),
|
||||
fCheckTime(DDL_INITIALLY_IMMEDIATE),
|
||||
fConstraintType(type),
|
||||
fCheck("")
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ColumnConstraintDef::ColumnConstraintDef(const char *check) :
|
||||
ColumnConstraintDef::ColumnConstraintDef(const char* check) :
|
||||
SchemaObject(),
|
||||
fDeferrable(false),
|
||||
fCheckTime(DDL_INITIALLY_IMMEDIATE),
|
||||
fConstraintType(DDL_CHECK),
|
||||
fCheck(check)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtaAddColumn::AtaAddColumn(ColumnDef *columnDef) :
|
||||
AtaAddColumn::AtaAddColumn(ColumnDef* columnDef) :
|
||||
fColumnDef(columnDef)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ostream &operator<<(ostream& os, const ReferentialAction& ref)
|
||||
{
|
||||
ostream& operator<<(ostream& os, const ReferentialAction& ref)
|
||||
{
|
||||
os << "ref action: u=" << ReferentialActionStrings[ref.fOnUpdate] << " "
|
||||
<< "d=" << ReferentialActionStrings[ref.fOnDelete];
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
void ColumnDef::convertDecimal()
|
||||
{
|
||||
void ColumnDef::convertDecimal()
|
||||
{
|
||||
//@Bug 2089 decimal precision default to 10 if 0 is used.
|
||||
if (fType->fPrecision <= 0)
|
||||
fType->fPrecision = 10;
|
||||
@@ -204,5 +214,5 @@ namespace ddlpackage
|
||||
fType->fType = DDL_BIGINT;
|
||||
fType->fLength = 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ typedef std::vector<SchemaObject*> TableElementList;
|
||||
typedef std::vector<TableConstraintDef*> TableConstraintDefList;
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const ColumnType& columnType);
|
||||
std::ostream& operator<<(std::ostream &os, const QualifiedName& constraint);
|
||||
std::ostream& operator<<(std::ostream &os, const TableConstraintDef& constraint);
|
||||
std::ostream& operator<<(std::ostream& os, const QualifiedName& constraint);
|
||||
std::ostream& operator<<(std::ostream& os, const TableConstraintDef& constraint);
|
||||
std::ostream& operator<<(std::ostream& os, const ColumnConstraintDef& con);
|
||||
std::ostream& operator<<(std::ostream& os, const ColumnDef& column);
|
||||
EXPORT std::ostream& operator<<(std::ostream& os, const SqlStatementList& ct);
|
||||
@@ -103,7 +103,8 @@ std::ostream& operator<<(std::ostream& os, const TableDef& tableDef);
|
||||
/** @brief Verb List
|
||||
* Make sure to keep the enum and string list in-sync
|
||||
*/
|
||||
enum DDL_VERBS {
|
||||
enum DDL_VERBS
|
||||
{
|
||||
DDL_CREATE,
|
||||
DDL_ALTER,
|
||||
DDL_DROP,
|
||||
@@ -112,7 +113,8 @@ enum DDL_VERBS {
|
||||
/** @brief Subject List
|
||||
* Make sure to keep the enum and string list in-sync
|
||||
*/
|
||||
enum DDL_SUBJECTS {
|
||||
enum DDL_SUBJECTS
|
||||
{
|
||||
DDL_TABLE,
|
||||
DDL_INDEX,
|
||||
DDL_INVALID_SUBJECT
|
||||
@@ -128,16 +130,17 @@ enum DDL_CONSTRAINT_ATTRIBUTES
|
||||
};
|
||||
|
||||
const std::string ConstraintAttrStrings[] =
|
||||
{
|
||||
{
|
||||
"deferrable",
|
||||
"non-deferrable",
|
||||
"initially-immediate",
|
||||
"initially-deferred",
|
||||
"invalid"
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
enum DDL_REFERENTIAL_ACTION {
|
||||
enum DDL_REFERENTIAL_ACTION
|
||||
{
|
||||
DDL_CASCADE,
|
||||
DDL_SET_NULL,
|
||||
DDL_SET_DEFAULT,
|
||||
@@ -147,32 +150,34 @@ enum DDL_REFERENTIAL_ACTION {
|
||||
};
|
||||
|
||||
const std::string ReferentialActionStrings[] =
|
||||
{
|
||||
{
|
||||
"cascade",
|
||||
"set_null",
|
||||
"set_default",
|
||||
"no_action",
|
||||
"invalid_action"
|
||||
};
|
||||
};
|
||||
|
||||
enum DDL_MATCH_TYPE {
|
||||
enum DDL_MATCH_TYPE
|
||||
{
|
||||
DDL_FULL,
|
||||
DDL_PARTIAL,
|
||||
DDL_INVALID_MATCH_TYPE
|
||||
};
|
||||
|
||||
const std::string MatchTypeStrings[] =
|
||||
{
|
||||
{
|
||||
"full",
|
||||
"partial",
|
||||
"invalid_match_type"
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/** @brief Constraint List
|
||||
* Make sure to keep the enum and string list in-sync
|
||||
*/
|
||||
enum DDL_CONSTRAINTS {
|
||||
enum DDL_CONSTRAINTS
|
||||
{
|
||||
DDL_PRIMARY_KEY,
|
||||
DDL_FOREIGN_KEY,
|
||||
DDL_CHECK,
|
||||
@@ -185,7 +190,7 @@ enum DDL_CONSTRAINTS {
|
||||
/** @brief
|
||||
*/
|
||||
const std::string ConstraintString[] =
|
||||
{
|
||||
{
|
||||
"primary",
|
||||
"foreign",
|
||||
"check",
|
||||
@@ -194,12 +199,13 @@ const std::string ConstraintString[] =
|
||||
"not_null",
|
||||
"auto_increment"
|
||||
""
|
||||
};
|
||||
};
|
||||
|
||||
/** @brief Datatype List
|
||||
* Make sure to keep the enum, string, and length list in-sync
|
||||
*/
|
||||
enum DDL_DATATYPES {
|
||||
enum DDL_DATATYPES
|
||||
{
|
||||
DDL_BIT,
|
||||
DDL_TINYINT,
|
||||
DDL_CHAR,
|
||||
@@ -236,7 +242,7 @@ enum DDL_DATATYPES {
|
||||
/** @brief Datatype string list
|
||||
*/
|
||||
const std::string DDLDatatypeString[] =
|
||||
{
|
||||
{
|
||||
"bit",
|
||||
"tinyint",
|
||||
"char",
|
||||
@@ -268,12 +274,12 @@ const std::string DDLDatatypeString[] =
|
||||
"unsigned-numeric",
|
||||
"text",
|
||||
""
|
||||
};
|
||||
};
|
||||
|
||||
/** @brief Alter table action string list
|
||||
*/
|
||||
const std::string AlterActionString[] =
|
||||
{
|
||||
{
|
||||
"AtaAddColumn",
|
||||
"AtaAddColumns",
|
||||
"AtaDropColumn",
|
||||
@@ -286,12 +292,12 @@ const std::string AlterActionString[] =
|
||||
"AtaModifyColumnType",
|
||||
"AtaRenameColumn",
|
||||
"AtaTableComment"
|
||||
};
|
||||
};
|
||||
/** @brief Datatype Length list
|
||||
*
|
||||
*/
|
||||
const int DDLDatatypeLength[] =
|
||||
{
|
||||
{
|
||||
1, // BIT
|
||||
1, // TINYINT
|
||||
1, // CHAR
|
||||
@@ -323,9 +329,10 @@ const int DDLDatatypeLength[] =
|
||||
2, // UNSIGNED_NUMERIC,
|
||||
8, // TEXT
|
||||
-1 // INVALID LENGTH
|
||||
};
|
||||
};
|
||||
|
||||
enum DDL_SERIAL_TYPE {
|
||||
enum DDL_SERIAL_TYPE
|
||||
{
|
||||
DDL_TABLE_DEF,
|
||||
DDL_COLUMN_DEF,
|
||||
DDL_COLUMN_CONSTRAINT_DEF,
|
||||
@@ -408,14 +415,14 @@ struct SchemaObject
|
||||
struct SqlStatement
|
||||
{
|
||||
/** @brief Deserialize from ByteStream */
|
||||
virtual int unserialize(messageqcpp::ByteStream& bs)=0;
|
||||
virtual int unserialize(messageqcpp::ByteStream& bs) = 0;
|
||||
|
||||
/** @brief Serialize to ByteStream */
|
||||
virtual int serialize(messageqcpp::ByteStream& bs)=0;
|
||||
virtual int serialize(messageqcpp::ByteStream& bs) = 0;
|
||||
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
virtual std::ostream& put(std::ostream &os) const = 0;
|
||||
virtual std::ostream& put(std::ostream& os) const = 0;
|
||||
|
||||
EXPORT SqlStatement();
|
||||
|
||||
@@ -530,7 +537,7 @@ struct TableDef : public SchemaObject
|
||||
/** @brief TableDef ctor.
|
||||
* ctor
|
||||
*/
|
||||
TableDef( QualifiedName *name,
|
||||
TableDef( QualifiedName* name,
|
||||
ColumnDefList columns,
|
||||
TableConstraintDefList constraints, int tableWithAutoinc) :
|
||||
fQualifiedName (name),
|
||||
@@ -579,6 +586,7 @@ struct CreateTableStatement : public SqlStatement
|
||||
std::string schemaName() const
|
||||
{
|
||||
if (!fTableDef || !fTableDef->fQualifiedName) return "UNKNOWN";
|
||||
|
||||
return fTableDef->fQualifiedName->fSchema;
|
||||
}
|
||||
|
||||
@@ -602,10 +610,10 @@ struct CreateTableStatement : public SqlStatement
|
||||
struct AlterTableAction
|
||||
{
|
||||
/** @brief Deserialize from ByteStream */
|
||||
EXPORT virtual int unserialize(messageqcpp::ByteStream& bs)=0;
|
||||
EXPORT virtual int unserialize(messageqcpp::ByteStream& bs) = 0;
|
||||
|
||||
/** @brief Serialize to ByteStream */
|
||||
EXPORT virtual int serialize(messageqcpp::ByteStream& bs)=0;
|
||||
EXPORT virtual int serialize(messageqcpp::ByteStream& bs) = 0;
|
||||
|
||||
/** @brief Ctor for deserialization */
|
||||
AlterTableAction()
|
||||
@@ -640,7 +648,7 @@ struct AtaAddColumn : public AlterTableAction
|
||||
|
||||
/** @brief You can't add a column without specifying a column
|
||||
definition. */
|
||||
AtaAddColumn(ColumnDef *columnDef);
|
||||
AtaAddColumn(ColumnDef* columnDef);
|
||||
|
||||
virtual ~AtaAddColumn();
|
||||
|
||||
@@ -648,7 +656,7 @@ struct AtaAddColumn : public AlterTableAction
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief The focal column definition. */
|
||||
ColumnDef *fColumnDef;
|
||||
ColumnDef* fColumnDef;
|
||||
};
|
||||
|
||||
|
||||
@@ -667,7 +675,7 @@ struct AtaAddColumns : public AlterTableAction
|
||||
AtaAddColumns()
|
||||
{}
|
||||
|
||||
AtaAddColumns(TableElementList *tableElements);
|
||||
AtaAddColumns(TableElementList* tableElements);
|
||||
|
||||
virtual ~AtaAddColumns();
|
||||
|
||||
@@ -693,7 +701,7 @@ struct AtaDropColumns : public AlterTableAction
|
||||
AtaDropColumns()
|
||||
{}
|
||||
|
||||
EXPORT AtaDropColumns(ColumnNameList *tableElements);
|
||||
EXPORT AtaDropColumns(ColumnNameList* tableElements);
|
||||
|
||||
EXPORT virtual ~AtaDropColumns();
|
||||
|
||||
@@ -719,14 +727,14 @@ struct AtaAddTableConstraint : public AlterTableAction
|
||||
AtaAddTableConstraint() : fTableConstraint(0)
|
||||
{}
|
||||
|
||||
AtaAddTableConstraint(TableConstraintDef *tableConstraint);
|
||||
AtaAddTableConstraint(TableConstraintDef* tableConstraint);
|
||||
|
||||
virtual ~AtaAddTableConstraint();
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
TableConstraintDef *fTableConstraint;
|
||||
TableConstraintDef* fTableConstraint;
|
||||
};
|
||||
|
||||
|
||||
@@ -776,10 +784,10 @@ struct AtaSetColumnDefault : AlterTableAction
|
||||
|
||||
virtual ~AtaSetColumnDefault();
|
||||
|
||||
AtaSetColumnDefault(const char *colName, ColumnDefaultValue *defaultValue);
|
||||
AtaSetColumnDefault(const char* colName, ColumnDefaultValue* defaultValue);
|
||||
|
||||
std::string fColumnName;
|
||||
ColumnDefaultValue *fDefaultValue;
|
||||
ColumnDefaultValue* fDefaultValue;
|
||||
|
||||
};
|
||||
|
||||
@@ -805,7 +813,7 @@ struct AtaDropColumnDefault : AlterTableAction
|
||||
{}
|
||||
|
||||
/** @brief Ctor for parser construction */
|
||||
AtaDropColumnDefault(const char *colName);
|
||||
AtaDropColumnDefault(const char* colName);
|
||||
|
||||
std::string fColumnName;
|
||||
};
|
||||
@@ -831,7 +839,7 @@ struct AtaDropTableConstraint : AlterTableAction
|
||||
virtual ~AtaDropTableConstraint()
|
||||
{}
|
||||
|
||||
AtaDropTableConstraint(const char *constraintName, DDL_REFERENTIAL_ACTION dropBehavior);
|
||||
AtaDropTableConstraint(const char* constraintName, DDL_REFERENTIAL_ACTION dropBehavior);
|
||||
|
||||
std::string fConstraintName;
|
||||
DDL_REFERENTIAL_ACTION fDropBehavior;
|
||||
@@ -850,14 +858,14 @@ struct AtaRenameTable : public AlterTableAction
|
||||
|
||||
/** @brief Ctor for deserialization */
|
||||
AtaRenameTable() : fQualifiedName(0) {}
|
||||
AtaRenameTable(QualifiedName *qualifiedName);
|
||||
AtaRenameTable(QualifiedName* qualifiedName);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
virtual ~AtaRenameTable();
|
||||
|
||||
QualifiedName *fQualifiedName;
|
||||
QualifiedName* fQualifiedName;
|
||||
};
|
||||
|
||||
/** alter table comment */
|
||||
@@ -872,7 +880,7 @@ struct AtaTableComment : public AlterTableAction
|
||||
/** @brief Ctor for deserialization */
|
||||
AtaTableComment() : fTableComment("")
|
||||
{}
|
||||
AtaTableComment(const char *tableComment);
|
||||
AtaTableComment(const char* tableComment);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
@@ -902,7 +910,7 @@ struct AtaModifyColumnType : public AlterTableAction
|
||||
fName(name)
|
||||
{}
|
||||
|
||||
AtaModifyColumnType(QualifiedName *qualifiedName);
|
||||
AtaModifyColumnType(QualifiedName* qualifiedName);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
@@ -928,18 +936,19 @@ struct AtaRenameColumn : public AlterTableAction
|
||||
/** @brief Ctor for deserialization */
|
||||
AtaRenameColumn() : fNewType(0), fDefaultValue(0) { }
|
||||
|
||||
AtaRenameColumn(const char* name, const char* newName, ColumnType* newType, const char * comment=NULL) :
|
||||
AtaRenameColumn(const char* name, const char* newName, ColumnType* newType, const char* comment = NULL) :
|
||||
fName(name),
|
||||
fNewName(newName),
|
||||
fNewType(newType)
|
||||
{
|
||||
if (comment)
|
||||
fComment = comment;
|
||||
|
||||
fDefaultValue = 0;
|
||||
}
|
||||
|
||||
AtaRenameColumn(const char* name, const char* newName, ColumnType* newType, ColumnConstraintList *constraint_list,
|
||||
ColumnDefaultValue *defaultValue, const char * comment=NULL) :
|
||||
AtaRenameColumn(const char* name, const char* newName, ColumnType* newType, ColumnConstraintList* constraint_list,
|
||||
ColumnDefaultValue* defaultValue, const char* comment = NULL) :
|
||||
fName(name),
|
||||
fNewName(newName),
|
||||
fNewType(newType),
|
||||
@@ -957,7 +966,7 @@ struct AtaRenameColumn : public AlterTableAction
|
||||
fComment = comment;
|
||||
}
|
||||
|
||||
AtaRenameColumn(QualifiedName *qualifiedName);
|
||||
AtaRenameColumn(QualifiedName* qualifiedName);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
@@ -971,7 +980,7 @@ struct AtaRenameColumn : public AlterTableAction
|
||||
ColumnConstraintList fConstraints;
|
||||
|
||||
/** @brief NULL if there was no DEFAULT clause */
|
||||
ColumnDefaultValue *fDefaultValue;
|
||||
ColumnDefaultValue* fDefaultValue;
|
||||
std::string fComment;
|
||||
};
|
||||
|
||||
@@ -992,7 +1001,7 @@ struct ColumnType
|
||||
ColumnType()
|
||||
{}
|
||||
|
||||
friend std::ostream &operator<<(std::ostream& os, const ColumnType &ac);
|
||||
friend std::ostream& operator<<(std::ostream& os, const ColumnType& ac);
|
||||
|
||||
/** @brief This constructor is used by the parser to construct the
|
||||
ColumnType when a precision/scale clause is encountered. */
|
||||
@@ -1053,7 +1062,7 @@ struct ColumnConstraintDef : public SchemaObject
|
||||
{}
|
||||
|
||||
/** @brief Constructs as check constraint. */
|
||||
EXPORT ColumnConstraintDef(const char *check);
|
||||
EXPORT ColumnConstraintDef(const char* check);
|
||||
|
||||
|
||||
/** @brief Constructs as other constraint. */
|
||||
@@ -1091,7 +1100,7 @@ struct ColumnDefaultValue
|
||||
ColumnDefaultValue()
|
||||
{}
|
||||
|
||||
ColumnDefaultValue(const char *value);
|
||||
ColumnDefaultValue(const char* value);
|
||||
|
||||
virtual ~ColumnDefaultValue()
|
||||
{}
|
||||
@@ -1123,17 +1132,17 @@ struct ColumnDef : public SchemaObject
|
||||
EXPORT virtual ~ColumnDef();
|
||||
|
||||
/** @brief Parser ctor. */
|
||||
EXPORT ColumnDef(const char *name,
|
||||
EXPORT ColumnDef(const char* name,
|
||||
ColumnType* type,
|
||||
ColumnConstraintList *constraint_list,
|
||||
ColumnDefaultValue *defaultValue, const char * comment=NULL);
|
||||
ColumnConstraintList* constraint_list,
|
||||
ColumnDefaultValue* defaultValue, const char* comment = NULL);
|
||||
|
||||
/** @brief ColumnDef ctor.
|
||||
* ctor */
|
||||
ColumnDef(const char *name,
|
||||
ColumnDef(const char* name,
|
||||
ColumnType* type,
|
||||
ColumnConstraintList constraints,
|
||||
ColumnDefaultValue *defaultValue = NULL, const char * comment=NULL) :
|
||||
ColumnDefaultValue* defaultValue = NULL, const char* comment = NULL) :
|
||||
SchemaObject(name),
|
||||
fType (type),
|
||||
fConstraints (constraints),
|
||||
@@ -1149,7 +1158,7 @@ struct ColumnDef : public SchemaObject
|
||||
ColumnConstraintList fConstraints;
|
||||
|
||||
/** @brief NULL if there was no DEFAULT clause */
|
||||
ColumnDefaultValue *fDefaultValue;
|
||||
ColumnDefaultValue* fDefaultValue;
|
||||
|
||||
std::string fComment;
|
||||
};
|
||||
@@ -1161,13 +1170,13 @@ struct ColumnDef : public SchemaObject
|
||||
struct TableConstraintDef : public SchemaObject
|
||||
{
|
||||
/** @brief Return DDL_SERIAL code */
|
||||
virtual DDL_SERIAL_TYPE getSerialType()=0;
|
||||
virtual DDL_SERIAL_TYPE getSerialType() = 0;
|
||||
|
||||
/** @brief Deserialize from ByteStream */
|
||||
virtual int unserialize(messageqcpp::ByteStream& bs)=0;
|
||||
virtual int unserialize(messageqcpp::ByteStream& bs) = 0;
|
||||
|
||||
/** @brief Serialize to ByteStream */
|
||||
virtual int serialize(messageqcpp::ByteStream& bs)=0;
|
||||
virtual int serialize(messageqcpp::ByteStream& bs) = 0;
|
||||
|
||||
|
||||
TableConstraintDef();
|
||||
@@ -1175,7 +1184,7 @@ struct TableConstraintDef : public SchemaObject
|
||||
TableConstraintDef(DDL_CONSTRAINTS cType);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
virtual ~TableConstraintDef()
|
||||
{}
|
||||
@@ -1207,12 +1216,12 @@ struct TableUniqueConstraintDef : public TableConstraintDef
|
||||
TableUniqueConstraintDef() : TableConstraintDef(DDL_UNIQUE)
|
||||
{}
|
||||
|
||||
TableUniqueConstraintDef(ColumnNameList *columns);
|
||||
TableUniqueConstraintDef(ColumnNameList* columns);
|
||||
virtual ~TableUniqueConstraintDef()
|
||||
{}
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
ColumnNameList fColumnNameList;
|
||||
};
|
||||
@@ -1239,13 +1248,13 @@ struct TablePrimaryKeyConstraintDef : public TableConstraintDef
|
||||
TablePrimaryKeyConstraintDef() : TableConstraintDef(DDL_PRIMARY_KEY)
|
||||
{}
|
||||
|
||||
EXPORT TablePrimaryKeyConstraintDef(ColumnNameList *columns);
|
||||
EXPORT TablePrimaryKeyConstraintDef(ColumnNameList* columns);
|
||||
|
||||
virtual ~TablePrimaryKeyConstraintDef()
|
||||
{}
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
EXPORT virtual std::ostream& put(std::ostream &os) const;
|
||||
EXPORT virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
ColumnNameList fColumnNameList;
|
||||
};
|
||||
@@ -1297,22 +1306,22 @@ struct TableReferencesConstraintDef : public TableConstraintDef
|
||||
{}
|
||||
|
||||
TableReferencesConstraintDef
|
||||
(ColumnNameList *columns,
|
||||
QualifiedName *fTableName,
|
||||
ColumnNameList *foreignColumns,
|
||||
(ColumnNameList* columns,
|
||||
QualifiedName* fTableName,
|
||||
ColumnNameList* foreignColumns,
|
||||
DDL_MATCH_TYPE matchType,
|
||||
ReferentialAction *refAction);
|
||||
ReferentialAction* refAction);
|
||||
|
||||
virtual ~TableReferencesConstraintDef();
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
ColumnNameList fColumns;
|
||||
QualifiedName *fTableName;
|
||||
QualifiedName* fTableName;
|
||||
ColumnNameList fForeignColumns;
|
||||
DDL_MATCH_TYPE fMatchType;
|
||||
ReferentialAction *fRefAction;
|
||||
ReferentialAction* fRefAction;
|
||||
};
|
||||
|
||||
|
||||
@@ -1337,10 +1346,10 @@ struct TableCheckConstraintDef : public TableConstraintDef
|
||||
TableCheckConstraintDef() : TableConstraintDef(DDL_CHECK)
|
||||
{}
|
||||
|
||||
TableCheckConstraintDef(const char *check);
|
||||
TableCheckConstraintDef(const char* check);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
virtual ~TableCheckConstraintDef()
|
||||
{}
|
||||
@@ -1367,10 +1376,10 @@ struct AlterTableStatement : public SqlStatement
|
||||
AlterTableStatement() : fTableName(0)
|
||||
{}
|
||||
|
||||
EXPORT AlterTableStatement(QualifiedName *qName, AlterTableActionList *ataList);
|
||||
EXPORT AlterTableStatement(QualifiedName* qName, AlterTableActionList* ataList);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
EXPORT virtual std::ostream& put(std::ostream &os) const;
|
||||
EXPORT virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief Delete members. */
|
||||
EXPORT virtual ~AlterTableStatement();
|
||||
@@ -1378,6 +1387,7 @@ struct AlterTableStatement : public SqlStatement
|
||||
std::string schemaName() const
|
||||
{
|
||||
if (!fTableName) return "UNKNOWN";
|
||||
|
||||
return fTableName->fSchema;
|
||||
}
|
||||
|
||||
@@ -1432,16 +1442,16 @@ struct CreateIndexStatement : public SqlStatement
|
||||
virtual int serialize(messageqcpp::ByteStream& bs);
|
||||
|
||||
CreateIndexStatement();
|
||||
CreateIndexStatement(QualifiedName *qualifiedName1, QualifiedName *qualifiedName2,
|
||||
ColumnNameList *columnNames, bool unique);
|
||||
CreateIndexStatement(QualifiedName* qualifiedName1, QualifiedName* qualifiedName2,
|
||||
ColumnNameList* columnNames, bool unique);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
virtual ~CreateIndexStatement();
|
||||
|
||||
QualifiedName *fIndexName;
|
||||
QualifiedName *fTableName;
|
||||
QualifiedName* fIndexName;
|
||||
QualifiedName* fTableName;
|
||||
ColumnNameList fColumnNames;
|
||||
bool fUnique;
|
||||
};
|
||||
@@ -1459,14 +1469,14 @@ struct DropIndexStatement : public SqlStatement
|
||||
|
||||
DropIndexStatement() : fIndexName(0)
|
||||
{}
|
||||
DropIndexStatement(QualifiedName *qualifiedName);
|
||||
DropIndexStatement(QualifiedName* qualifiedName);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
virtual ~DropIndexStatement();
|
||||
|
||||
QualifiedName *fIndexName;
|
||||
QualifiedName* fIndexName;
|
||||
};
|
||||
|
||||
/** @brief DropTableStatement represents the drop table operation
|
||||
@@ -1482,7 +1492,7 @@ struct DropTableStatement : public SqlStatement
|
||||
|
||||
DropTableStatement() : fTableName(0)
|
||||
{}
|
||||
EXPORT DropTableStatement(QualifiedName *qualifiedName, bool cascade);
|
||||
EXPORT DropTableStatement(QualifiedName* qualifiedName, bool cascade);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
EXPORT std::ostream& put(std::ostream& os) const;
|
||||
@@ -1495,10 +1505,11 @@ struct DropTableStatement : public SqlStatement
|
||||
std::string schemaName() const
|
||||
{
|
||||
if (!fTableName) return "UNKNOWN";
|
||||
|
||||
return fTableName->fSchema;
|
||||
}
|
||||
|
||||
QualifiedName *fTableName;
|
||||
QualifiedName* fTableName;
|
||||
bool fCascade;
|
||||
};
|
||||
|
||||
@@ -1515,7 +1526,7 @@ struct TruncTableStatement : public SqlStatement
|
||||
|
||||
TruncTableStatement() : fTableName(0)
|
||||
{}
|
||||
EXPORT TruncTableStatement(QualifiedName *qualifiedName);
|
||||
EXPORT TruncTableStatement(QualifiedName* qualifiedName);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
EXPORT std::ostream& put(std::ostream& os) const;
|
||||
@@ -1528,10 +1539,11 @@ struct TruncTableStatement : public SqlStatement
|
||||
std::string schemaName() const
|
||||
{
|
||||
if (!fTableName) return "UNKNOWN";
|
||||
|
||||
return fTableName->fSchema;
|
||||
}
|
||||
|
||||
QualifiedName *fTableName;
|
||||
QualifiedName* fTableName;
|
||||
};
|
||||
|
||||
/** @brief Represents the mark partition out of service statement
|
||||
@@ -1550,7 +1562,7 @@ struct MarkPartitionStatement : public SqlStatement
|
||||
{}
|
||||
|
||||
/** @brief You can't have a CreateTableStatement without a table defintion */
|
||||
EXPORT MarkPartitionStatement(QualifiedName *qualifiedName);
|
||||
EXPORT MarkPartitionStatement(QualifiedName* qualifiedName);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
EXPORT virtual std::ostream& put(std::ostream& os) const;
|
||||
@@ -1560,7 +1572,7 @@ struct MarkPartitionStatement : public SqlStatement
|
||||
delete fTableName;
|
||||
}
|
||||
|
||||
QualifiedName *fTableName; ///< The table defintion
|
||||
QualifiedName* fTableName; ///< The table defintion
|
||||
std::set<BRM::LogicalPartition> fPartitions; // partition numbers
|
||||
};
|
||||
|
||||
@@ -1579,7 +1591,7 @@ struct RestorePartitionStatement : public SqlStatement
|
||||
RestorePartitionStatement() : fTableName(0)
|
||||
{}
|
||||
|
||||
EXPORT RestorePartitionStatement(QualifiedName *qualifiedName);
|
||||
EXPORT RestorePartitionStatement(QualifiedName* qualifiedName);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
EXPORT virtual std::ostream& put(std::ostream& os) const;
|
||||
@@ -1589,7 +1601,7 @@ struct RestorePartitionStatement : public SqlStatement
|
||||
delete fTableName;
|
||||
}
|
||||
|
||||
QualifiedName *fTableName; ///< The table name.
|
||||
QualifiedName* fTableName; ///< The table name.
|
||||
std::set<BRM::LogicalPartition> fPartitions; // partition numbers
|
||||
};
|
||||
|
||||
@@ -1608,7 +1620,7 @@ struct DropPartitionStatement : public SqlStatement
|
||||
DropPartitionStatement() : fTableName(0)
|
||||
{}
|
||||
|
||||
EXPORT DropPartitionStatement(QualifiedName *qualifiedName);
|
||||
EXPORT DropPartitionStatement(QualifiedName* qualifiedName);
|
||||
|
||||
/** @brief Dump to stdout. */
|
||||
EXPORT virtual std::ostream& put(std::ostream& os) const;
|
||||
@@ -1618,7 +1630,7 @@ struct DropPartitionStatement : public SqlStatement
|
||||
delete fTableName;
|
||||
}
|
||||
|
||||
QualifiedName *fTableName; ///< The table name.
|
||||
QualifiedName* fTableName; ///< The table name.
|
||||
std::set<BRM::LogicalPartition> fPartitions; // partition numbers
|
||||
};
|
||||
|
||||
|
||||
@@ -23,23 +23,24 @@
|
||||
|
||||
#include "ddlpkg.h"
|
||||
|
||||
namespace ddlpackage {
|
||||
using namespace std;
|
||||
namespace ddlpackage
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
DropIndexStatement::~DropIndexStatement()
|
||||
{
|
||||
DropIndexStatement::~DropIndexStatement()
|
||||
{
|
||||
delete fIndexName;
|
||||
}
|
||||
}
|
||||
|
||||
DropIndexStatement::DropIndexStatement(QualifiedName *qualifiedName) :
|
||||
DropIndexStatement::DropIndexStatement(QualifiedName* qualifiedName) :
|
||||
fIndexName(qualifiedName)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
std::ostream& DropIndexStatement::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& DropIndexStatement::put(std::ostream& os) const
|
||||
{
|
||||
os << "Drop Index: " << *fIndexName << endl;
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,10 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ddlpackage {
|
||||
namespace ddlpackage
|
||||
{
|
||||
|
||||
DropPartitionStatement::DropPartitionStatement(QualifiedName *qualifiedName) :
|
||||
DropPartitionStatement::DropPartitionStatement(QualifiedName* qualifiedName) :
|
||||
fTableName(qualifiedName)
|
||||
{
|
||||
}
|
||||
@@ -39,8 +40,10 @@ ostream& DropPartitionStatement::put(ostream& os) const
|
||||
os << "Mark partitions out of service: " << *fTableName << endl;
|
||||
os << " partitions: ";
|
||||
set<BRM::LogicalPartition>::const_iterator it;
|
||||
for (it=fPartitions.begin(); it!=fPartitions.end(); ++it)
|
||||
|
||||
for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
|
||||
os << (*it) << " ";
|
||||
|
||||
os << endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -27,9 +27,10 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ddlpackage {
|
||||
namespace ddlpackage
|
||||
{
|
||||
|
||||
DropTableStatement::DropTableStatement(QualifiedName *qualifiedName, bool cascade) :
|
||||
DropTableStatement::DropTableStatement(QualifiedName* qualifiedName, bool cascade) :
|
||||
fTableName(qualifiedName),
|
||||
fCascade(cascade)
|
||||
{
|
||||
@@ -41,7 +42,7 @@ ostream& DropTableStatement::put(ostream& os) const
|
||||
return os;
|
||||
}
|
||||
|
||||
TruncTableStatement::TruncTableStatement(QualifiedName *qualifiedName) :
|
||||
TruncTableStatement::TruncTableStatement(QualifiedName* qualifiedName) :
|
||||
fTableName(qualifiedName)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ int main(int argc, char* argv[])
|
||||
po::variables_map vm;
|
||||
po::store (po::parse_command_line (argc, argv, desc), vm);
|
||||
po::notify (vm);
|
||||
|
||||
if (vm.count ("sql"))
|
||||
sqlfile = vm["sql"].as <string> ();
|
||||
|
||||
@@ -51,20 +52,23 @@ int main(int argc, char* argv[])
|
||||
count = vm["count"].as<int>();
|
||||
|
||||
SqlFileParser parser;
|
||||
|
||||
if (vm.count ("bisond"))
|
||||
parser.SetDebug(true);
|
||||
|
||||
parser.Parse(sqlfile);
|
||||
|
||||
if(parser.Good()) {
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
cout << "Parser succeeded." << endl;
|
||||
cout << ptree.fList.size() << " " << "SQL statements" << endl;
|
||||
cout << ptree;
|
||||
cout << endl;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
cout << "Parser failed." << endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,10 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ddlpackage {
|
||||
namespace ddlpackage
|
||||
{
|
||||
|
||||
MarkPartitionStatement::MarkPartitionStatement(QualifiedName *qualifiedName) :
|
||||
MarkPartitionStatement::MarkPartitionStatement(QualifiedName* qualifiedName) :
|
||||
fTableName(qualifiedName)
|
||||
{
|
||||
}
|
||||
@@ -39,8 +40,10 @@ ostream& MarkPartitionStatement::put(ostream& os) const
|
||||
os << "Mark partition out of service: " << *fTableName;
|
||||
os << " partitions: ";
|
||||
set<BRM::LogicalPartition>::const_iterator it;
|
||||
for (it=fPartitions.begin(); it!=fPartitions.end(); ++it)
|
||||
|
||||
for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
|
||||
os << (*it) << " ";
|
||||
|
||||
os << endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -50,18 +50,19 @@ std::string itoa(const int i);
|
||||
|
||||
// READ & WRITE STATEMENT TESTS
|
||||
|
||||
class DDLWriteReadTest : public CppUnit::TestFixture {
|
||||
class DDLWriteReadTest : public CppUnit::TestFixture
|
||||
{
|
||||
|
||||
CPPUNIT_TEST_SUITE( DDLWriteReadTest );
|
||||
CPPUNIT_TEST_SUITE( DDLWriteReadTest );
|
||||
|
||||
CPPUNIT_TEST( test_write_read_create_table_object );
|
||||
CPPUNIT_TEST( test_write_read_create_index_object );
|
||||
CPPUNIT_TEST( test_write_read_alter_table_object );
|
||||
CPPUNIT_TEST( test_write_read_drop_table_object );
|
||||
CPPUNIT_TEST( test_write_read_drop_index_object );
|
||||
CPPUNIT_TEST( test_write_read_create_table_object );
|
||||
CPPUNIT_TEST( test_write_read_create_index_object );
|
||||
CPPUNIT_TEST( test_write_read_alter_table_object );
|
||||
CPPUNIT_TEST( test_write_read_drop_table_object );
|
||||
CPPUNIT_TEST( test_write_read_drop_index_object );
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
|
||||
@@ -119,7 +120,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT( DDL_CREATE == package_type );
|
||||
|
||||
CreateObjectDDLPackage *pObject = new CreateObjectDDLPackage();
|
||||
CreateObjectDDLPackage* pObject = new CreateObjectDDLPackage();
|
||||
|
||||
pObject->Read( bs );
|
||||
|
||||
@@ -170,7 +171,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT( DDL_CREATE == package_type );
|
||||
|
||||
CreateObjectDDLPackage *pObject = new CreateObjectDDLPackage();
|
||||
CreateObjectDDLPackage* pObject = new CreateObjectDDLPackage();
|
||||
|
||||
pObject->Read( bs );
|
||||
|
||||
@@ -221,7 +222,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT( DDL_ALTER == package_type );
|
||||
|
||||
AlterObjectDDLPackage *pObject = new AlterObjectDDLPackage();
|
||||
AlterObjectDDLPackage* pObject = new AlterObjectDDLPackage();
|
||||
|
||||
pObject->Read( bs );
|
||||
|
||||
@@ -272,7 +273,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT( DDL_DROP == package_type );
|
||||
|
||||
DropObjectDDLPackage *pObject = new DropObjectDDLPackage();
|
||||
DropObjectDDLPackage* pObject = new DropObjectDDLPackage();
|
||||
|
||||
pObject->Read( bs );
|
||||
|
||||
@@ -323,7 +324,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT( DDL_DROP == package_type );
|
||||
|
||||
DropObjectDDLPackage *pObject = new DropObjectDDLPackage();
|
||||
DropObjectDDLPackage* pObject = new DropObjectDDLPackage();
|
||||
|
||||
pObject->Read( bs );
|
||||
|
||||
@@ -336,13 +337,14 @@ public:
|
||||
// PARSE STATEMENT TESTS
|
||||
|
||||
|
||||
class DDLCreateTableParserTest : public CppUnit::TestFixture {
|
||||
class DDLCreateTableParserTest : public CppUnit::TestFixture
|
||||
{
|
||||
|
||||
CPPUNIT_TEST_SUITE( DDLCreateTableParserTest );
|
||||
CPPUNIT_TEST_SUITE( DDLCreateTableParserTest );
|
||||
|
||||
CPPUNIT_TEST( create_t1 );
|
||||
CPPUNIT_TEST( create_t1 );
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
|
||||
@@ -372,8 +374,8 @@ public:
|
||||
|
||||
fileBuffer = Buffer;
|
||||
|
||||
string::size_type pos = fileBuffer.find ("create ",0);
|
||||
string::size_type pos1 = fileBuffer.find ("CREATE ",0);
|
||||
string::size_type pos = fileBuffer.find ("create ", 0);
|
||||
string::size_type pos1 = fileBuffer.find ("CREATE ", 0);
|
||||
|
||||
if (pos == string::npos && pos1 == string::npos )
|
||||
// end of file
|
||||
@@ -384,7 +386,7 @@ public:
|
||||
else
|
||||
pos_begin = pos1;
|
||||
|
||||
std::string DDLStatement = fileBuffer.substr (pos_begin,64000);
|
||||
std::string DDLStatement = fileBuffer.substr (pos_begin, 64000);
|
||||
|
||||
fileBuffer.append(";");
|
||||
|
||||
@@ -401,17 +403,19 @@ public:
|
||||
|
||||
delete pDDLPackage;
|
||||
}
|
||||
|
||||
fin.close();
|
||||
}
|
||||
};
|
||||
|
||||
class DDLCreateIndexParserTest : public CppUnit::TestFixture {
|
||||
class DDLCreateIndexParserTest : public CppUnit::TestFixture
|
||||
{
|
||||
|
||||
CPPUNIT_TEST_SUITE( DDLCreateIndexParserTest );
|
||||
CPPUNIT_TEST_SUITE( DDLCreateIndexParserTest );
|
||||
|
||||
CPPUNIT_TEST( createIndex_t1 );
|
||||
CPPUNIT_TEST( createIndex_t1 );
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
|
||||
@@ -441,8 +445,8 @@ public:
|
||||
|
||||
fileBuffer = Buffer;
|
||||
|
||||
string::size_type pos = fileBuffer.find ("create ",0);
|
||||
string::size_type pos1 = fileBuffer.find ("CREATE ",0);
|
||||
string::size_type pos = fileBuffer.find ("create ", 0);
|
||||
string::size_type pos1 = fileBuffer.find ("CREATE ", 0);
|
||||
|
||||
if (pos == string::npos && pos1 == string::npos )
|
||||
// end of file
|
||||
@@ -453,7 +457,7 @@ public:
|
||||
else
|
||||
pos_begin = pos1;
|
||||
|
||||
std::string DDLStatement = fileBuffer.substr (pos_begin,64000);
|
||||
std::string DDLStatement = fileBuffer.substr (pos_begin, 64000);
|
||||
|
||||
fileBuffer.append(";");
|
||||
|
||||
@@ -470,19 +474,21 @@ public:
|
||||
|
||||
delete pDDLPackage;
|
||||
}
|
||||
|
||||
fin.close();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class DDLAlterTableParserTest : public CppUnit::TestFixture {
|
||||
class DDLAlterTableParserTest : public CppUnit::TestFixture
|
||||
{
|
||||
|
||||
CPPUNIT_TEST_SUITE( DDLAlterTableParserTest );
|
||||
CPPUNIT_TEST_SUITE( DDLAlterTableParserTest );
|
||||
|
||||
CPPUNIT_TEST( alter_t1 );
|
||||
CPPUNIT_TEST( alter_t1 );
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
|
||||
@@ -512,8 +518,8 @@ public:
|
||||
|
||||
fileBuffer = Buffer;
|
||||
|
||||
string::size_type pos = fileBuffer.find ("alter ",0);
|
||||
string::size_type pos1 = fileBuffer.find ("ALTER ",0);
|
||||
string::size_type pos = fileBuffer.find ("alter ", 0);
|
||||
string::size_type pos1 = fileBuffer.find ("ALTER ", 0);
|
||||
|
||||
if (pos == string::npos && pos1 == string::npos )
|
||||
// end of file
|
||||
@@ -524,7 +530,7 @@ public:
|
||||
else
|
||||
pos_begin = pos1;
|
||||
|
||||
std::string DDLStatement = fileBuffer.substr (pos_begin,64000);
|
||||
std::string DDLStatement = fileBuffer.substr (pos_begin, 64000);
|
||||
|
||||
fileBuffer.append(";");
|
||||
|
||||
@@ -541,18 +547,20 @@ public:
|
||||
|
||||
delete pDDLPackage;
|
||||
}
|
||||
|
||||
fin.close();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class DDLDropTableParserTest : public CppUnit::TestFixture {
|
||||
class DDLDropTableParserTest : public CppUnit::TestFixture
|
||||
{
|
||||
|
||||
CPPUNIT_TEST_SUITE( DDLDropTableParserTest );
|
||||
CPPUNIT_TEST_SUITE( DDLDropTableParserTest );
|
||||
|
||||
CPPUNIT_TEST( drop_t1 );
|
||||
CPPUNIT_TEST( drop_t1 );
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
|
||||
@@ -583,8 +591,8 @@ public:
|
||||
|
||||
fileBuffer = Buffer;
|
||||
|
||||
string::size_type pos = fileBuffer.find ("drop ",0);
|
||||
string::size_type pos1 = fileBuffer.find ("DROP ",0);
|
||||
string::size_type pos = fileBuffer.find ("drop ", 0);
|
||||
string::size_type pos1 = fileBuffer.find ("DROP ", 0);
|
||||
|
||||
if (pos == string::npos && pos1 == string::npos )
|
||||
// end of file
|
||||
@@ -595,7 +603,7 @@ public:
|
||||
else
|
||||
pos_begin = pos1;
|
||||
|
||||
std::string DDLStatement = fileBuffer.substr (pos_begin,64000);
|
||||
std::string DDLStatement = fileBuffer.substr (pos_begin, 64000);
|
||||
|
||||
fileBuffer.append(";");
|
||||
|
||||
@@ -612,18 +620,20 @@ public:
|
||||
|
||||
delete pDDLPackage;
|
||||
}
|
||||
|
||||
fin.close();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class DDLDropIndexParserTest : public CppUnit::TestFixture {
|
||||
class DDLDropIndexParserTest : public CppUnit::TestFixture
|
||||
{
|
||||
|
||||
CPPUNIT_TEST_SUITE( DDLDropIndexParserTest );
|
||||
CPPUNIT_TEST_SUITE( DDLDropIndexParserTest );
|
||||
|
||||
CPPUNIT_TEST( dropIndex_t1 );
|
||||
CPPUNIT_TEST( dropIndex_t1 );
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
std::string fDDLStatement;
|
||||
@@ -654,8 +664,8 @@ public:
|
||||
|
||||
fileBuffer = Buffer;
|
||||
|
||||
string::size_type pos = fileBuffer.find ("drop ",0);
|
||||
string::size_type pos1 = fileBuffer.find ("DROP ",0);
|
||||
string::size_type pos = fileBuffer.find ("drop ", 0);
|
||||
string::size_type pos1 = fileBuffer.find ("DROP ", 0);
|
||||
|
||||
if (pos == string::npos && pos1 == string::npos )
|
||||
// end of file
|
||||
@@ -666,7 +676,7 @@ public:
|
||||
else
|
||||
pos_begin = pos1;
|
||||
|
||||
std::string DDLStatement = fileBuffer.substr (pos_begin,64000);
|
||||
std::string DDLStatement = fileBuffer.substr (pos_begin, 64000);
|
||||
|
||||
fileBuffer.append(";");
|
||||
|
||||
@@ -683,6 +693,7 @@ public:
|
||||
|
||||
delete pDDLPackage;
|
||||
}
|
||||
|
||||
fin.close();
|
||||
}
|
||||
|
||||
@@ -698,11 +709,11 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DDLWriteReadTest );
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
runner.addTest( registry.makeTest() );
|
||||
bool wasSuccessful = runner.run( "", false );
|
||||
|
||||
|
||||
@@ -27,9 +27,10 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ddlpackage {
|
||||
namespace ddlpackage
|
||||
{
|
||||
|
||||
RestorePartitionStatement::RestorePartitionStatement(QualifiedName *qualifiedName) :
|
||||
RestorePartitionStatement::RestorePartitionStatement(QualifiedName* qualifiedName) :
|
||||
fTableName(qualifiedName)
|
||||
{
|
||||
}
|
||||
@@ -39,8 +40,10 @@ ostream& RestorePartitionStatement::put(ostream& os) const
|
||||
os << "Mark partition out of service: " << *fTableName;
|
||||
os << " partitions: ";
|
||||
set<BRM::LogicalPartition>::const_iterator it;
|
||||
for (it=fPartitions.begin(); it!=fPartitions.end(); ++it)
|
||||
|
||||
for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
|
||||
os << (*it) << " ";
|
||||
|
||||
os << endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,94 +36,100 @@
|
||||
#endif
|
||||
|
||||
void scanner_finish(void* yyscanner);
|
||||
void scanner_init(const char *str, void* yyscanner);
|
||||
int ddllex_init_extra(void* user_defined,void** yyscanner);
|
||||
void scanner_init(const char* str, void* yyscanner);
|
||||
int ddllex_init_extra(void* user_defined, void** yyscanner);
|
||||
int ddllex_destroy(void* yyscanner);
|
||||
int ddlparse(ddlpackage::pass_to_bison* x);
|
||||
void set_schema(std::string schema);
|
||||
namespace ddlpackage {
|
||||
using namespace std;
|
||||
namespace ddlpackage
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
SqlParser::SqlParser() :
|
||||
SqlParser::SqlParser() :
|
||||
fStatus(-1),
|
||||
fDebug(false),
|
||||
x(&fParseTree)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SqlParser::SetDebug(bool debug)
|
||||
{
|
||||
void SqlParser::SetDebug(bool debug)
|
||||
{
|
||||
fDebug = debug;
|
||||
}
|
||||
}
|
||||
|
||||
void SqlParser::setDefaultSchema(std::string schema)
|
||||
{
|
||||
x.fDBSchema=schema;
|
||||
}
|
||||
void SqlParser::setDefaultSchema(std::string schema)
|
||||
{
|
||||
x.fDBSchema = schema;
|
||||
}
|
||||
|
||||
int SqlParser::Parse(const char* sqltext)
|
||||
{
|
||||
int SqlParser::Parse(const char* sqltext)
|
||||
{
|
||||
ddllex_init_extra(&scanData, &x.scanner);
|
||||
scanner_init(sqltext, x.scanner);
|
||||
fStatus = ddlparse(&x);
|
||||
return fStatus;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const ParseTree& SqlParser::GetParseTree(void)
|
||||
const ParseTree& SqlParser::GetParseTree(void)
|
||||
{
|
||||
if (!Good())
|
||||
{
|
||||
if(!Good()) {
|
||||
throw logic_error("The ParseTree is invalid");
|
||||
}
|
||||
|
||||
return fParseTree;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool SqlParser::Good()
|
||||
{
|
||||
bool SqlParser::Good()
|
||||
{
|
||||
return fStatus == 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SqlParser::~SqlParser()
|
||||
{
|
||||
SqlParser::~SqlParser()
|
||||
{
|
||||
scanner_finish(x.scanner); // free scanner allocated memory
|
||||
ddllex_destroy(x.scanner);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SqlFileParser::SqlFileParser() :
|
||||
SqlFileParser::SqlFileParser() :
|
||||
SqlParser()
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int SqlFileParser::Parse(const string& sqlfile)
|
||||
{
|
||||
int SqlFileParser::Parse(const string& sqlfile)
|
||||
{
|
||||
fStatus = -1;
|
||||
|
||||
ifstream ifsql;
|
||||
ifsql.open(sqlfile.c_str());
|
||||
if(!ifsql.is_open()) {
|
||||
|
||||
if (!ifsql.is_open())
|
||||
{
|
||||
perror(sqlfile.c_str());
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
char sqlbuf[1024*1024];
|
||||
char sqlbuf[1024 * 1024];
|
||||
unsigned length;
|
||||
ifsql.seekg (0, ios::end);
|
||||
length = ifsql.tellg();
|
||||
ifsql.seekg (0, ios::beg);
|
||||
|
||||
if(length > sizeof(sqlbuf) - 1) {
|
||||
if (length > sizeof(sqlbuf) - 1)
|
||||
{
|
||||
throw length_error("SqlFileParser has file size hard limit of 16K.");
|
||||
}
|
||||
|
||||
unsigned rcount;
|
||||
rcount = ifsql.readsome(sqlbuf, sizeof(sqlbuf) - 1);
|
||||
|
||||
if(rcount < 0)
|
||||
if (rcount < 0)
|
||||
return fStatus;
|
||||
|
||||
sqlbuf[rcount] = 0;
|
||||
@@ -133,5 +139,5 @@ namespace ddlpackage {
|
||||
//cout << sqlbuf << endl;
|
||||
|
||||
return SqlParser::Parse(sqlbuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,8 @@ struct scan_data
|
||||
valbuf_t valbuf;
|
||||
};
|
||||
|
||||
struct pass_to_bison {
|
||||
struct pass_to_bison
|
||||
{
|
||||
ParseTree* fParseTree;
|
||||
std::string fDBSchema;
|
||||
void* scanner;
|
||||
|
||||
@@ -25,22 +25,23 @@
|
||||
#include "ddlpkg.h"
|
||||
#undef DDLPKG_DLLEXPORT
|
||||
|
||||
namespace ddlpackage {
|
||||
using namespace std;
|
||||
namespace ddlpackage
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
static uint32_t sessionID = 1;
|
||||
static uint32_t sessionID = 1;
|
||||
|
||||
SqlStatement::SqlStatement()
|
||||
{
|
||||
SqlStatement::SqlStatement()
|
||||
{
|
||||
fSessionID = sessionID;
|
||||
}
|
||||
|
||||
SqlStatement::~SqlStatement()
|
||||
{
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream &os, const SqlStatement& stmt)
|
||||
{
|
||||
return stmt.put(os);
|
||||
}
|
||||
}
|
||||
|
||||
SqlStatement::~SqlStatement()
|
||||
{
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream& os, const SqlStatement& stmt)
|
||||
{
|
||||
return stmt.put(os);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,34 +25,39 @@
|
||||
#include "ddlpkg.h"
|
||||
#undef DDLPKG_DLLEXPORT
|
||||
|
||||
namespace ddlpackage {
|
||||
using namespace std;
|
||||
namespace ddlpackage
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
|
||||
ostream &operator<<(ostream& os, const SqlStatementList &ssl)
|
||||
{
|
||||
ostream& operator<<(ostream& os, const SqlStatementList& ssl)
|
||||
{
|
||||
vector<SqlStatement*>::const_iterator itr;
|
||||
|
||||
for(itr = ssl.fList.begin(); itr != ssl.fList.end(); ++itr) {
|
||||
SqlStatement &stmt = **itr;
|
||||
for (itr = ssl.fList.begin(); itr != ssl.fList.end(); ++itr)
|
||||
{
|
||||
SqlStatement& stmt = **itr;
|
||||
os << stmt;
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SqlStatementList::push_back(SqlStatement* v)
|
||||
{
|
||||
void SqlStatementList::push_back(SqlStatement* v)
|
||||
{
|
||||
fList.push_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SqlStatementList::~SqlStatementList()
|
||||
{
|
||||
SqlStatementList::~SqlStatementList()
|
||||
{
|
||||
vector<SqlStatement*>::iterator itr;
|
||||
for(itr = fList.begin(); itr != fList.end(); ++itr) {
|
||||
|
||||
for (itr = fList.begin(); itr != fList.end(); ++itr)
|
||||
{
|
||||
delete *itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,66 +28,79 @@
|
||||
|
||||
namespace ddlpackage
|
||||
{
|
||||
using namespace std;
|
||||
using namespace std;
|
||||
|
||||
|
||||
TableDef::~TableDef()
|
||||
{
|
||||
TableDef::~TableDef()
|
||||
{
|
||||
{
|
||||
ColumnDefList::iterator itr;
|
||||
for(itr=fColumns.begin(); itr != fColumns.end(); itr++) {
|
||||
|
||||
for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
|
||||
{
|
||||
delete *itr;
|
||||
}
|
||||
}
|
||||
{
|
||||
TableConstraintDefList::iterator itr;
|
||||
for(itr=fConstraints.begin(); itr != fConstraints.end(); itr++) {
|
||||
|
||||
for (itr = fConstraints.begin(); itr != fConstraints.end(); itr++)
|
||||
{
|
||||
delete *itr;
|
||||
}
|
||||
}
|
||||
|
||||
delete fQualifiedName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TableDef::TableDef(QualifiedName* name, TableElementList* elements, TableOptionMap* options) :
|
||||
TableDef::TableDef(QualifiedName* name, TableElementList* elements, TableOptionMap* options) :
|
||||
fQualifiedName(name)
|
||||
{
|
||||
if (options)
|
||||
{
|
||||
if(options) {
|
||||
fOptions = *options;
|
||||
delete options;
|
||||
}
|
||||
|
||||
ColumnDef *column;
|
||||
TableConstraintDef *constraint;
|
||||
ColumnDef* column;
|
||||
TableConstraintDef* constraint;
|
||||
|
||||
/* When parsing, it is necessary to collect ColumnDefs and
|
||||
TableConstraintDefs as TableElements. Here we separate
|
||||
them out into separately typed lists.
|
||||
*/
|
||||
TableElementList::iterator itr;
|
||||
for(itr = elements->begin(); itr != elements->end(); ++itr) {
|
||||
|
||||
for (itr = elements->begin(); itr != elements->end(); ++itr)
|
||||
{
|
||||
column = dynamic_cast<ColumnDef*>(*itr);
|
||||
if(column) {
|
||||
|
||||
if (column)
|
||||
{
|
||||
fColumns.push_back(column);
|
||||
}
|
||||
else {
|
||||
constraint = dynamic_cast<TableConstraintDef *>(*itr);
|
||||
if(constraint) {
|
||||
else
|
||||
{
|
||||
constraint = dynamic_cast<TableConstraintDef*>(*itr);
|
||||
|
||||
if (constraint)
|
||||
{
|
||||
fConstraints.push_back(constraint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete elements;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** \brief Put to ostream. */
|
||||
ostream& operator<<(ostream& os, const TableDef& tableDef)
|
||||
{
|
||||
/** \brief Put to ostream. */
|
||||
ostream& operator<<(ostream& os, const TableDef& tableDef)
|
||||
{
|
||||
os << "CreateTable ";
|
||||
if(tableDef.fQualifiedName->fSchema != "")
|
||||
|
||||
if (tableDef.fQualifiedName->fSchema != "")
|
||||
//cout << tableDef.fQualifiedName->fSchema << ".";
|
||||
os << tableDef.fQualifiedName->fName
|
||||
<< " " << tableDef.fConstraints.size()
|
||||
@@ -96,7 +109,8 @@ namespace ddlpackage
|
||||
|
||||
{
|
||||
ColumnDefList::const_iterator itr;
|
||||
for(itr = tableDef.fColumns.begin();
|
||||
|
||||
for (itr = tableDef.fColumns.begin();
|
||||
itr != tableDef.fColumns.end(); ++itr)
|
||||
{
|
||||
ColumnDef* col = *itr;
|
||||
@@ -107,7 +121,8 @@ namespace ddlpackage
|
||||
|
||||
{
|
||||
TableConstraintDefList::const_iterator itr;
|
||||
for(itr = tableDef.fConstraints.begin();
|
||||
|
||||
for (itr = tableDef.fConstraints.begin();
|
||||
itr != tableDef.fConstraints.end();
|
||||
++itr)
|
||||
{
|
||||
@@ -118,139 +133,149 @@ namespace ddlpackage
|
||||
pair<string, string> oval;
|
||||
TableOptionMap::const_iterator oitr;
|
||||
os << "Table Options" << endl;
|
||||
if(!tableDef.fOptions.empty()) {
|
||||
|
||||
if (!tableDef.fOptions.empty())
|
||||
{
|
||||
TableOptionMap::const_iterator oitr;
|
||||
for(oitr = tableDef.fOptions.begin();
|
||||
oitr != tableDef.fOptions.end(); ++oitr) {
|
||||
|
||||
for (oitr = tableDef.fOptions.begin();
|
||||
oitr != tableDef.fOptions.end(); ++oitr)
|
||||
{
|
||||
oval = *oitr;
|
||||
os << " " << oval.first << "=" << oval.second << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ostream& operator<<(ostream &os, const TableConstraintDef& constraint)
|
||||
{
|
||||
ostream& operator<<(ostream& os, const TableConstraintDef& constraint)
|
||||
{
|
||||
return constraint.put(os);
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& TableConstraintDef::put(std::ostream& os) const
|
||||
{
|
||||
std::ostream& TableConstraintDef::put(std::ostream& os) const
|
||||
{
|
||||
os << "No!!!" << endl;
|
||||
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TableConstraintDef::TableConstraintDef(DDL_CONSTRAINTS cType) :
|
||||
TableConstraintDef::TableConstraintDef(DDL_CONSTRAINTS cType) :
|
||||
fConstraintType(cType)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
TableConstraintDef::TableConstraintDef() :
|
||||
TableConstraintDef::TableConstraintDef() :
|
||||
fConstraintType(DDL_INVALID_CONSTRAINT)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
TableCheckConstraintDef::TableCheckConstraintDef(const char *check) :
|
||||
TableCheckConstraintDef::TableCheckConstraintDef(const char* check) :
|
||||
TableConstraintDef(DDL_CHECK),
|
||||
fCheck(check)
|
||||
{
|
||||
}
|
||||
std::ostream& TableCheckConstraintDef::put(std::ostream& os) const
|
||||
{
|
||||
{
|
||||
}
|
||||
std::ostream& TableCheckConstraintDef::put(std::ostream& os) const
|
||||
{
|
||||
os << "Constraint: "
|
||||
<< ConstraintString[fConstraintType] << " ";
|
||||
os << "\"" << fCheck << "\"";
|
||||
os << endl;
|
||||
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TableUniqueConstraintDef::TableUniqueConstraintDef(ColumnNameList *columns) :
|
||||
TableUniqueConstraintDef::TableUniqueConstraintDef(ColumnNameList* columns) :
|
||||
TableConstraintDef(DDL_UNIQUE),
|
||||
fColumnNameList(*columns)
|
||||
{
|
||||
{
|
||||
delete columns;
|
||||
}
|
||||
std::ostream& TableUniqueConstraintDef::put(std::ostream& os) const
|
||||
{
|
||||
}
|
||||
std::ostream& TableUniqueConstraintDef::put(std::ostream& os) const
|
||||
{
|
||||
os << "Constraint: "
|
||||
<< fName << " "
|
||||
<< ConstraintString[fConstraintType] << " ";
|
||||
|
||||
ColumnNameList::const_iterator itr;
|
||||
os << "(";
|
||||
for(itr = fColumnNameList.begin();
|
||||
|
||||
for (itr = fColumnNameList.begin();
|
||||
itr != fColumnNameList.end();
|
||||
++itr)
|
||||
{
|
||||
os << *itr << " ";
|
||||
}
|
||||
|
||||
os << ")";
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
TablePrimaryKeyConstraintDef::TablePrimaryKeyConstraintDef(ColumnNameList *columns) :
|
||||
TablePrimaryKeyConstraintDef::TablePrimaryKeyConstraintDef(ColumnNameList* columns) :
|
||||
TableConstraintDef(DDL_PRIMARY_KEY),
|
||||
fColumnNameList(*columns)
|
||||
{
|
||||
{
|
||||
delete columns;
|
||||
}
|
||||
std::ostream& TablePrimaryKeyConstraintDef::put(std::ostream& os) const
|
||||
{
|
||||
}
|
||||
std::ostream& TablePrimaryKeyConstraintDef::put(std::ostream& os) const
|
||||
{
|
||||
os << "Constraint: "
|
||||
<< fName << " "
|
||||
<< ConstraintString[fConstraintType] << " ";
|
||||
|
||||
ColumnNameList::const_iterator itr;
|
||||
os << "(";
|
||||
for(itr = fColumnNameList.begin();
|
||||
|
||||
for (itr = fColumnNameList.begin();
|
||||
itr != fColumnNameList.end();
|
||||
++itr)
|
||||
{
|
||||
os << *itr << " ";
|
||||
}
|
||||
|
||||
os << ")";
|
||||
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
TableReferencesConstraintDef::TableReferencesConstraintDef
|
||||
(ColumnNameList *columns,
|
||||
QualifiedName *tableName,
|
||||
ColumnNameList *foreignColumns,
|
||||
TableReferencesConstraintDef::TableReferencesConstraintDef
|
||||
(ColumnNameList* columns,
|
||||
QualifiedName* tableName,
|
||||
ColumnNameList* foreignColumns,
|
||||
DDL_MATCH_TYPE matchType,
|
||||
ReferentialAction *refAction) :
|
||||
ReferentialAction* refAction) :
|
||||
TableConstraintDef(DDL_REFERENCES),
|
||||
fColumns(*columns),
|
||||
fTableName(tableName),
|
||||
fForeignColumns(*foreignColumns),
|
||||
fMatchType(matchType),
|
||||
fRefAction(refAction)
|
||||
{
|
||||
{
|
||||
delete columns;
|
||||
delete foreignColumns;
|
||||
}
|
||||
std::ostream& TableReferencesConstraintDef::put(std::ostream& os) const
|
||||
{
|
||||
}
|
||||
std::ostream& TableReferencesConstraintDef::put(std::ostream& os) const
|
||||
{
|
||||
os << "Constraint: "
|
||||
<< fName << " "
|
||||
<< ConstraintString[fConstraintType] << " ";
|
||||
|
||||
ColumnNameList::const_iterator itr;
|
||||
os << "lcols (";
|
||||
for(itr = fColumns.begin();
|
||||
|
||||
for (itr = fColumns.begin();
|
||||
itr != fColumns.end();
|
||||
++itr)
|
||||
{
|
||||
os << *itr << " ";
|
||||
}
|
||||
|
||||
os << ")";
|
||||
|
||||
os << " ftable=" << *fTableName;
|
||||
@@ -258,36 +283,40 @@ namespace ddlpackage
|
||||
os << " ";
|
||||
|
||||
os << "fcols (";
|
||||
for(itr = fForeignColumns.begin();
|
||||
|
||||
for (itr = fForeignColumns.begin();
|
||||
itr != fForeignColumns.end();
|
||||
++itr)
|
||||
{
|
||||
os << *itr << " ";
|
||||
}
|
||||
|
||||
os << ")";
|
||||
|
||||
return os;
|
||||
}
|
||||
std::ostream &operator<<(std::ostream& os, const ColumnNameList &columnNames)
|
||||
{
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, const ColumnNameList& columnNames)
|
||||
{
|
||||
ColumnNameList::const_iterator itr;
|
||||
os << '(';
|
||||
for(itr = columnNames.begin();
|
||||
|
||||
for (itr = columnNames.begin();
|
||||
itr != columnNames.end();
|
||||
++itr)
|
||||
{
|
||||
os << *itr << " ";
|
||||
}
|
||||
|
||||
os << ')';
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TableReferencesConstraintDef::~TableReferencesConstraintDef()
|
||||
{
|
||||
TableReferencesConstraintDef::~TableReferencesConstraintDef()
|
||||
{
|
||||
delete fTableName;
|
||||
delete fRefAction;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,8 @@ bool parse_file(char* fileName)
|
||||
return parser.Good();
|
||||
}
|
||||
|
||||
class ParserTest : public CppUnit::TestFixture {
|
||||
class ParserTest : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(ParserTest);
|
||||
CPPUNIT_TEST(atac01);
|
||||
CPPUNIT_TEST(atac05);
|
||||
@@ -271,7 +272,7 @@ template<class T>
|
||||
void u_sertest(T* x)
|
||||
{
|
||||
ByteStream bs;
|
||||
stringstream s1,s2;
|
||||
stringstream s1, s2;
|
||||
auto_ptr<T> y(new T);
|
||||
|
||||
x->serialize(bs);
|
||||
@@ -296,7 +297,7 @@ template<class T>
|
||||
void t_sertest(T* x)
|
||||
{
|
||||
ByteStream bs;
|
||||
stringstream s1,s2;
|
||||
stringstream s1, s2;
|
||||
auto_ptr<T> y(new T);
|
||||
|
||||
x->serialize(bs);
|
||||
@@ -319,7 +320,8 @@ void t_sertest(T* x)
|
||||
}
|
||||
|
||||
|
||||
class SerializeTest : public CppUnit::TestFixture {
|
||||
class SerializeTest : public CppUnit::TestFixture
|
||||
{
|
||||
|
||||
CPPUNIT_TEST_SUITE(SerializeTest);
|
||||
CPPUNIT_TEST(qname);
|
||||
@@ -375,7 +377,8 @@ public:
|
||||
{
|
||||
SqlFileParser p;
|
||||
p.Parse("sql/atrc01.sql");
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
|
||||
@@ -389,7 +392,8 @@ public:
|
||||
{
|
||||
SqlFileParser p;
|
||||
p.Parse("sql/atmct01.sql");
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
|
||||
@@ -403,7 +407,8 @@ public:
|
||||
{
|
||||
SqlFileParser p;
|
||||
p.Parse("sql/atrt01.sql");
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
|
||||
@@ -416,7 +421,8 @@ public:
|
||||
{
|
||||
SqlFileParser p;
|
||||
p.Parse("sql/atdtc01.sql");
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
|
||||
@@ -429,7 +435,8 @@ public:
|
||||
{
|
||||
SqlFileParser p;
|
||||
p.Parse("sql/atmcdd01.sql");
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
|
||||
@@ -442,7 +449,8 @@ public:
|
||||
{
|
||||
SqlFileParser p;
|
||||
p.Parse("sql/atmcsd01.sql");
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
|
||||
@@ -456,7 +464,8 @@ public:
|
||||
{
|
||||
SqlFileParser p;
|
||||
p.Parse("sql/atdc01.sql");
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
|
||||
@@ -469,7 +478,8 @@ public:
|
||||
{
|
||||
SqlFileParser p;
|
||||
p.Parse("sql/atatc01.sql");
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
|
||||
@@ -498,11 +508,13 @@ public:
|
||||
files.push_back("sql/ct11.sql");
|
||||
|
||||
vector<string>::const_iterator itr;
|
||||
for(itr = files.begin(); itr != files.end(); ++itr)
|
||||
|
||||
for (itr = files.begin(); itr != files.end(); ++itr)
|
||||
{
|
||||
SqlFileParser p;
|
||||
p.Parse(*itr);
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]);
|
||||
@@ -511,7 +523,8 @@ public:
|
||||
ColumnDefList* columns = &(ct->fTableDef->fColumns);
|
||||
|
||||
ColumnDefList::const_iterator itr;
|
||||
for(itr = columns->begin();
|
||||
|
||||
for (itr = columns->begin();
|
||||
itr != columns->end();
|
||||
++itr)
|
||||
{
|
||||
@@ -544,11 +557,13 @@ public:
|
||||
files.push_back("sql/ct11.sql");
|
||||
|
||||
vector<string>::const_iterator itr;
|
||||
for(itr = files.begin(); itr != files.end(); ++itr)
|
||||
|
||||
for (itr = files.begin(); itr != files.end(); ++itr)
|
||||
{
|
||||
SqlFileParser p;
|
||||
p.Parse(*itr);
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]);
|
||||
@@ -577,7 +592,7 @@ public:
|
||||
void qname()
|
||||
{
|
||||
cout << "Serialize test: QualifiedName" << endl;
|
||||
auto_ptr<QualifiedName> name(new QualifiedName("one","two","three"));
|
||||
auto_ptr<QualifiedName> name(new QualifiedName("one", "two", "three"));
|
||||
u_sertest<QualifiedName>(name.get());
|
||||
}
|
||||
|
||||
@@ -647,12 +662,14 @@ public:
|
||||
files.push_back("sql/ct11.sql");
|
||||
|
||||
vector<string>::const_iterator itr;
|
||||
for(itr = files.begin(); itr != files.end(); ++itr)
|
||||
|
||||
for (itr = files.begin(); itr != files.end(); ++itr)
|
||||
{
|
||||
cout << "* * * Checking columndef serialization for " << *itr << endl;
|
||||
SqlFileParser p;
|
||||
p.Parse(*itr);
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]);
|
||||
@@ -664,7 +681,8 @@ public:
|
||||
ColumnDefList* columns = &(ct->fTableDef->fColumns);
|
||||
|
||||
ColumnDefList::const_iterator itr;
|
||||
for(itr = columns->begin();
|
||||
|
||||
for (itr = columns->begin();
|
||||
itr != columns->end();
|
||||
++itr)
|
||||
{
|
||||
@@ -764,12 +782,14 @@ public:
|
||||
files.push_back("sql/ct11.sql");
|
||||
|
||||
vector<string>::const_iterator itr;
|
||||
for(itr = files.begin(); itr != files.end(); ++itr)
|
||||
|
||||
for (itr = files.begin(); itr != files.end(); ++itr)
|
||||
{
|
||||
cout << "* * * Checking tabledef serialization for " << *itr << endl;
|
||||
SqlFileParser p;
|
||||
p.Parse(*itr);
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]);
|
||||
@@ -801,13 +821,15 @@ public:
|
||||
files.push_back("sql/ct11.sql");
|
||||
|
||||
vector<string>::const_iterator itr;
|
||||
for(itr = files.begin(); itr != files.end(); ++itr)
|
||||
|
||||
for (itr = files.begin(); itr != files.end(); ++itr)
|
||||
{
|
||||
cout << "* * * Checking CreateTableStatement serialization for " << *itr << endl;
|
||||
SqlFileParser p;
|
||||
p.setDefaultSchema("tpch");
|
||||
p.Parse(*itr);
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]);
|
||||
@@ -828,12 +850,14 @@ public:
|
||||
files.push_back("sql/dt02.sql");
|
||||
|
||||
vector<string>::const_iterator itr;
|
||||
for(itr = files.begin(); itr != files.end(); ++itr)
|
||||
|
||||
for (itr = files.begin(); itr != files.end(); ++itr)
|
||||
{
|
||||
cout << "* * * Checking DropTableStatement serialization for " << *itr << endl;
|
||||
SqlFileParser p;
|
||||
p.Parse(*itr);
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
DropTableStatement* stmt = dynamic_cast<DropTableStatement*>(stmts[0]);
|
||||
@@ -853,12 +877,14 @@ public:
|
||||
files.push_back("sql/ci02.sql");
|
||||
|
||||
vector<string>::const_iterator itr;
|
||||
for(itr = files.begin(); itr != files.end(); ++itr)
|
||||
|
||||
for (itr = files.begin(); itr != files.end(); ++itr)
|
||||
{
|
||||
cout << "* * * Checking Create Index serialization for " << *itr << endl;
|
||||
SqlFileParser p;
|
||||
p.Parse(*itr);
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
CreateIndexStatement* stmt = dynamic_cast<CreateIndexStatement*>(stmts[0]);
|
||||
@@ -877,12 +903,14 @@ public:
|
||||
files.push_back("sql/di01.sql");
|
||||
|
||||
vector<string>::const_iterator itr;
|
||||
for(itr = files.begin(); itr != files.end(); ++itr)
|
||||
|
||||
for (itr = files.begin(); itr != files.end(); ++itr)
|
||||
{
|
||||
cout << "* * * Checking Drop Index serialization for " << *itr << endl;
|
||||
SqlFileParser p;
|
||||
p.Parse(*itr);
|
||||
if(p.Good())
|
||||
|
||||
if (p.Good())
|
||||
{
|
||||
const ParseTree& stmts = p.GetParseTree();
|
||||
DropIndexStatement* stmt = dynamic_cast<DropIndexStatement*>(stmts[0]);
|
||||
@@ -903,11 +931,11 @@ CPPUNIT_TEST_SUITE_REGISTRATION(ParserTest);
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
runner.addTest( registry.makeTest() );
|
||||
|
||||
bool wasSuccessful = runner.run( "", false );
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -34,14 +34,14 @@
|
||||
|
||||
namespace ddlpackageprocessor
|
||||
{
|
||||
/** @brief specialization of a DDLPackageProcessor
|
||||
/** @brief specialization of a DDLPackageProcessor
|
||||
* for interacting with the Write Engine
|
||||
* to process alter table ddl statements.
|
||||
*/
|
||||
class AlterTableProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
AlterTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
|
||||
class AlterTableProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
AlterTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
|
||||
/** @brief process an alter table statement
|
||||
*
|
||||
* @param alterTableStmt the AlterTableStatement
|
||||
@@ -147,12 +147,12 @@ namespace ddlpackageprocessor
|
||||
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void rollBackAlter(const std::string& error, BRM::TxnID txnID, int sessionId, DDLResult& result, uint64_t uniqueId);
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
} //namespace ddlpackageprocessor
|
||||
|
||||
|
||||
@@ -56,8 +56,8 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
|
||||
DETAIL_INFO(createIndexStmt);
|
||||
|
||||
BRM::TxnID txnID;
|
||||
txnID.id= fTxnid.id;
|
||||
txnID.valid= fTxnid.valid;
|
||||
txnID.id = fTxnid.id;
|
||||
txnID.valid = fTxnid.valid;
|
||||
/*Check whether the table exists already. If not, it is assumed from primary key creating.
|
||||
This is based on the assumption that Front end is already error out if the user trys to
|
||||
create index on non-existing table. */
|
||||
@@ -66,7 +66,9 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
|
||||
tableName.table = (createIndexStmt.fTableName)->fName;
|
||||
CalpontSystemCatalog::ROPair roPair;
|
||||
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog( createIndexStmt.fSessionID );
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
roPair = systemCatalogPtr->tableRID( tableName );
|
||||
}
|
||||
catch (exception& ex)
|
||||
@@ -80,10 +82,12 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if ( roPair.objnum < 3000 )
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
fPKName = createIndexStmt.fIndexName->fName;
|
||||
int err = 0;
|
||||
|
||||
@@ -103,10 +107,12 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
|
||||
|
||||
VERBOSE_INFO("Writing meta data to SYSINDEX");
|
||||
bool multicol = false;
|
||||
|
||||
if ( createIndexStmt.fColumnNames.size() > 1 )
|
||||
{
|
||||
multicol = true;
|
||||
}
|
||||
|
||||
//validate index columns
|
||||
CalpontSystemCatalog::TableColName tableColName;
|
||||
tableColName.schema = (createIndexStmt.fTableName)->fSchema;
|
||||
@@ -118,6 +124,7 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
|
||||
DDLIndexPopulator pop(&fWriteEngine, &fSessionManager, createIndexStmt.fSessionID, txnID.id, result,
|
||||
fIdxOID, createIndexStmt.fColumnNames, *createIndexStmt.fTableName,
|
||||
type, getDebugLevel());
|
||||
|
||||
if ( multicol)
|
||||
{
|
||||
for ( colIter = createIndexStmt.fColumnNames.begin(); colIter != createIndexStmt.fColumnNames.end(); colIter++)
|
||||
@@ -129,6 +136,7 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
|
||||
colType = systemCatalogPtr->colType (oid );
|
||||
totalWidth += (pop.isDictionaryType(colType)) ? 8 : colType.colWidth;
|
||||
}
|
||||
|
||||
if ( totalWidth > 32 )
|
||||
{
|
||||
stringstream ss;
|
||||
@@ -147,8 +155,8 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
//writeSysIndexMetaData(createIndexStmt.fSessionID, txnID.id, result, *createIndexStmt.fTableName, type, createIndexStmt.fIndexName->fName, multicol);
|
||||
|
||||
//fIdxOID values are set in writeSysIndexMetaData.
|
||||
@@ -179,14 +187,16 @@ try
|
||||
// get the columns for the SYSCONSTRAINT table
|
||||
ColumnList sysConsColumns;
|
||||
ColumnList::const_iterator sysCons_iterator;
|
||||
getColumnsForTable(createIndexStmt.fSessionID, sysConsTableName.schema,sysConsTableName.table, sysConsColumns);
|
||||
getColumnsForTable(createIndexStmt.fSessionID, sysConsTableName.schema, sysConsTableName.table, sysConsColumns);
|
||||
sysCons_iterator = sysConsColumns.begin();
|
||||
std::string idxData;
|
||||
|
||||
while ( sysCons_iterator != sysConsColumns.end() )
|
||||
{
|
||||
column = *sysCons_iterator;
|
||||
boost::algorithm::to_lower(column.tableColName.column);
|
||||
isNull = false;
|
||||
|
||||
if (CONSTRAINTNAME_COL == column.tableColName.column)
|
||||
{
|
||||
idxData = createIndexStmt.fIndexName->fName;
|
||||
@@ -245,6 +255,7 @@ try
|
||||
{
|
||||
colTuple.data = tokenizeData(txnID.id, result, column.colType, colTuple.data);
|
||||
}
|
||||
|
||||
colStructs.push_back( colStruct );
|
||||
|
||||
colTuples.push_back( colTuple );
|
||||
@@ -296,10 +307,11 @@ try
|
||||
// get the columns for the SYSCONSTRAINTCOL table
|
||||
ColumnList sysConsColColumns;
|
||||
ColumnList::const_iterator sysConsCol_iterator;
|
||||
getColumnsForTable(createIndexStmt.fSessionID, sysConsColTableName.schema,sysConsColTableName.table, sysConsColColumns);
|
||||
getColumnsForTable(createIndexStmt.fSessionID, sysConsColTableName.schema, sysConsColTableName.table, sysConsColColumns);
|
||||
// write sysconstraintcol
|
||||
sysConsCol_iterator = sysConsColColumns.begin();
|
||||
std::string colData;
|
||||
|
||||
while ( sysConsCol_iterator != sysConsColColumns.end() )
|
||||
{
|
||||
column = *sysConsCol_iterator;
|
||||
@@ -368,7 +380,7 @@ try
|
||||
{
|
||||
return rollBackCreateIndex(errorString( "WE: Error inserting Column Record: ", error), txnID, createIndexStmt.fSessionID);
|
||||
|
||||
/* logging::Message::Args args;
|
||||
/* logging::Message::Args args;
|
||||
logging::Message message(9);
|
||||
args.add("Error updating: ");
|
||||
args.add("calpont.sysconstraintcol");
|
||||
@@ -388,12 +400,15 @@ try
|
||||
|
||||
VERBOSE_INFO("Creating index files");
|
||||
err = fWriteEngine.createIndex( txnID.id, fIdxOID.treeOID, fIdxOID.listOID );
|
||||
|
||||
if (err)
|
||||
{
|
||||
return rollBackCreateIndex(errorString("Write engine failed to create the new index. ", err), txnID, createIndexStmt.fSessionID);
|
||||
}
|
||||
|
||||
// new if BULK_LOAD close
|
||||
err = pop.populateIndex(result);
|
||||
|
||||
if ( err )
|
||||
{
|
||||
return rollBackCreateIndex(errorString("Failed to populate index with current data. ", err), txnID, createIndexStmt.fSessionID);
|
||||
@@ -405,6 +420,7 @@ try
|
||||
|
||||
DETAIL_INFO("Commiting transaction");
|
||||
err = fWriteEngine.commit( txnID.id );
|
||||
|
||||
if (err)
|
||||
{
|
||||
return rollBackCreateIndex(errorString("Failed to commit the create index transaction. ", err), txnID, createIndexStmt.fSessionID);
|
||||
@@ -412,7 +428,7 @@ try
|
||||
|
||||
fSessionManager.committed(txnID);
|
||||
// original if BULK_LOAD close }
|
||||
} // try
|
||||
} // try
|
||||
|
||||
catch (exception& ex)
|
||||
{
|
||||
@@ -455,8 +471,10 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::rollBackCreateIndex(const
|
||||
void CreateIndexProcessor::rollBackIndex(BRM::TxnID& txnID, int sessionId)
|
||||
{
|
||||
fWriteEngine.rollbackTran(txnID.id, sessionId);
|
||||
fWriteEngine.dropIndex(txnID.id,fIdxOID.listOID, fIdxOID.treeOID);
|
||||
try {
|
||||
fWriteEngine.dropIndex(txnID.id, fIdxOID.listOID, fIdxOID.treeOID);
|
||||
|
||||
try
|
||||
{
|
||||
//execplan::ObjectIDManager fObjectIDManager;
|
||||
//fObjectIDManager.returnOIDs(fIdxOID.treeOID, fIdxOID.listOID);
|
||||
}
|
||||
@@ -466,6 +484,7 @@ void CreateIndexProcessor::rollBackIndex(BRM::TxnID& txnID, int sessionId)
|
||||
}
|
||||
catch (... )
|
||||
{ }
|
||||
|
||||
fSessionManager.rolledback(txnID);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,26 +29,26 @@
|
||||
const int BULK_LOAD = 1;
|
||||
namespace ddlpackageprocessor
|
||||
{
|
||||
/** @brief specialization of a DDLPackageProcessor
|
||||
/** @brief specialization of a DDLPackageProcessor
|
||||
* for interacting with the Write Engine to process
|
||||
* create index ddl statements
|
||||
*/
|
||||
class CreateIndexProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
class CreateIndexProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
/** @brief process a create index statement
|
||||
*
|
||||
* @param createIndexStmt the create index statement
|
||||
*/
|
||||
DDLResult processPackage(ddlpackage::CreateIndexStatement& createIndexStmt);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
DDLResult rollBackCreateIndex(const std::string& error, BRM::TxnID& txnID, int sessionId);
|
||||
void rollBackIndex(BRM::TxnID& txnID);
|
||||
std::string errorString(const std::string& msg, int error);
|
||||
private:
|
||||
private:
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
} //namespace ddlpackageprocessor
|
||||
#endif //CREATEINDEXPROCESSOR_H
|
||||
|
||||
@@ -55,11 +55,12 @@ CreateTableProcessor::DDLResult CreateTableProcessor::processPackage(
|
||||
|
||||
DDLResult result;
|
||||
BRM::TxnID txnID;
|
||||
txnID.id= fTxnid.id;
|
||||
txnID.valid= fTxnid.valid;
|
||||
txnID.id = fTxnid.id;
|
||||
txnID.valid = fTxnid.valid;
|
||||
result.result = NO_ERROR;
|
||||
int rc1 = 0;
|
||||
rc1 = fDbrm->isReadWrite();
|
||||
|
||||
if (rc1 != 0 )
|
||||
{
|
||||
Message::Args args;
|
||||
@@ -71,16 +72,19 @@ CreateTableProcessor::DDLResult CreateTableProcessor::processPackage(
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
DETAIL_INFO(createTableStmt);
|
||||
ddlpackage::TableDef& tableDef = *createTableStmt.fTableDef;
|
||||
//If schema = CALPONTSYS, do not create table
|
||||
boost::algorithm::to_lower(tableDef.fQualifiedName->fSchema);
|
||||
|
||||
if (tableDef.fQualifiedName->fSchema == CALPONT_SCHEMA)
|
||||
{
|
||||
//release the transaction
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Commit current transaction.
|
||||
// all DDL statements cause an implicut commit
|
||||
VERBOSE_INFO("Getting current txnID");
|
||||
@@ -94,13 +98,14 @@ CreateTableProcessor::DDLResult CreateTableProcessor::processPackage(
|
||||
execplan::CalpontSystemCatalog::ROPair roPair;
|
||||
roPair.objnum = 0;
|
||||
ByteStream::byte rc = 0;
|
||||
|
||||
/** @Bug 217 */
|
||||
/** @Bug 225 */
|
||||
try
|
||||
{
|
||||
roPair = systemCatalogPtr->tableRID(tableName);
|
||||
}
|
||||
catch (IDBExcept &ie)
|
||||
catch (IDBExcept& ie)
|
||||
{
|
||||
// TODO: What is and is not an error here?
|
||||
if (ie.errorCode() == ERR_DATA_OFFLINE)
|
||||
@@ -167,10 +172,19 @@ CreateTableProcessor::DDLResult CreateTableProcessor::processPackage(
|
||||
#ifdef _MSC_VER
|
||||
//FIXME: Why do we need to do this???
|
||||
systemCatalogPtr->flushCache();
|
||||
try { roPair = systemCatalogPtr->tableRID(tableName); }
|
||||
catch (...) { roPair.objnum = 0; }
|
||||
|
||||
try
|
||||
{
|
||||
roPair = systemCatalogPtr->tableRID(tableName);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
roPair.objnum = 0;
|
||||
}
|
||||
|
||||
if (roPair.objnum < 3000)
|
||||
goto keepGoing;
|
||||
|
||||
#endif
|
||||
Message::Args args;
|
||||
Message message(9);
|
||||
@@ -186,24 +200,27 @@ CreateTableProcessor::DDLResult CreateTableProcessor::processPackage(
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
keepGoing:
|
||||
#endif
|
||||
// Start a new transaction
|
||||
VERBOSE_INFO("Starting a new transaction");
|
||||
|
||||
string stmt = createTableStmt.fSql + "|" + tableDef.fQualifiedName->fSchema +"|";
|
||||
string stmt = createTableStmt.fSql + "|" + tableDef.fQualifiedName->fSchema + "|";
|
||||
SQLLogger logger(stmt, fDDLLoggingId, createTableStmt.fSessionID, txnID.id);
|
||||
|
||||
|
||||
std::string err;
|
||||
execplan::ObjectIDManager fObjectIDManager;
|
||||
OamCache * oamcache = OamCache::makeOamCache();
|
||||
OamCache* oamcache = OamCache::makeOamCache();
|
||||
string errorMsg;
|
||||
//get a unique number
|
||||
uint64_t uniqueId = 0;
|
||||
|
||||
//Bug 5070. Added exception handling
|
||||
try {
|
||||
try
|
||||
{
|
||||
uniqueId = fDbrm->getUnique64();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
@@ -230,6 +247,7 @@ keepGoing:
|
||||
}
|
||||
|
||||
fWEClient->addQueue(uniqueId);
|
||||
|
||||
try
|
||||
{
|
||||
//Allocate tableoid table identification
|
||||
@@ -238,10 +256,12 @@ keepGoing:
|
||||
VERBOSE_INFO("Allocating object IDs for columns");
|
||||
uint32_t numColumns = tableDef.fColumns.size();
|
||||
uint32_t numDictCols = 0;
|
||||
for (unsigned i=0; i < numColumns; i++)
|
||||
|
||||
for (unsigned i = 0; i < numColumns; i++)
|
||||
{
|
||||
int dataType;
|
||||
dataType = convertDataType(tableDef.fColumns[i]->fType->fType);
|
||||
|
||||
if ( (dataType == CalpontSystemCatalog::CHAR && tableDef.fColumns[i]->fType->fLength > 8) ||
|
||||
(dataType == CalpontSystemCatalog::VARCHAR && tableDef.fColumns[i]->fType->fLength > 7) ||
|
||||
(dataType == CalpontSystemCatalog::VARBINARY && tableDef.fColumns[i]->fType->fLength > 7) ||
|
||||
@@ -249,10 +269,12 @@ keepGoing:
|
||||
(dataType == CalpontSystemCatalog::TEXT && tableDef.fColumns[i]->fType->fLength > 7) )
|
||||
numDictCols++;
|
||||
}
|
||||
fStartingColOID = fObjectIDManager.allocOIDs(numColumns+numDictCols+1); //include column, oids,dictionary oids and tableoid
|
||||
|
||||
fStartingColOID = fObjectIDManager.allocOIDs(numColumns + numDictCols + 1); //include column, oids,dictionary oids and tableoid
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " Create table allocOIDs got the starting oid " << fStartingColOID << endl;
|
||||
cout << fTxnid.id << " Create table allocOIDs got the starting oid " << fStartingColOID << endl;
|
||||
#endif
|
||||
|
||||
if (fStartingColOID < 0)
|
||||
{
|
||||
result.result = CREATE_ERROR;
|
||||
@@ -280,9 +302,10 @@ cout << fTxnid.id << " Create table allocOIDs got the starting oid " << fStartin
|
||||
BRM::OID_t sysOid = 1001;
|
||||
//Find out where systable is
|
||||
rc = fDbrm->getSysCatDBRoot(sysOid, dbRoot);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
result.result =(ResultCode) rc;
|
||||
result.result = (ResultCode) rc;
|
||||
Message::Args args;
|
||||
Message message(9);
|
||||
args.add("Error while calling getSysCatDBRoot ");
|
||||
@@ -302,31 +325,38 @@ cout << fTxnid.id << " Create table allocOIDs got the starting oid " << fStartin
|
||||
pmNum = (*dbRootPMMap)[dbRoot];
|
||||
// MCOL-66 The DBRM can't handle concurrent DDL
|
||||
boost::mutex::scoped_lock lk(dbrmMutex);
|
||||
|
||||
try
|
||||
{
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " create table sending We_SVR_WRITE_SYSTABLE to pm " << pmNum << endl;
|
||||
cout << fTxnid.id << " create table sending We_SVR_WRITE_SYSTABLE to pm " << pmNum << endl;
|
||||
#endif
|
||||
fWEClient->write(bytestream, (unsigned)pmNum);
|
||||
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> rc;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
errorMsg.clear();
|
||||
*bsIn >> errorMsg;
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl;
|
||||
cout << fTxnid.id << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -334,7 +364,7 @@ cout << fTxnid.id << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
|
||||
catch (runtime_error& ex) //write error
|
||||
{
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " create table got exception" << ex.what() << endl;
|
||||
cout << fTxnid.id << " create table got exception" << ex.what() << endl;
|
||||
#endif
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = ex.what();
|
||||
@@ -343,26 +373,28 @@ cout << fTxnid.id << " create table got exception" << ex.what() << endl;
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << "create table got unknown exception" << endl;
|
||||
cout << "create table got unknown exception" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl;
|
||||
cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl;
|
||||
#endif
|
||||
result.result =(ResultCode) rc;
|
||||
result.result = (ResultCode) rc;
|
||||
Message::Args args;
|
||||
Message message(9);
|
||||
args.add("(2)Create table failed due to ");
|
||||
args.add(errorMsg);
|
||||
message.format( args );
|
||||
result.message = message;
|
||||
|
||||
if (rc != NETWORK_ERROR)
|
||||
{
|
||||
rollBackTransaction( uniqueId, txnID, createTableStmt.fSessionID ); //What to do with the error code
|
||||
}
|
||||
|
||||
//release transaction
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
@@ -375,12 +407,17 @@ cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
|
||||
bytestream << (uint32_t) createTableStmt.fSessionID;
|
||||
bytestream << (uint32_t)txnID.id;
|
||||
bytestream << numColumns;
|
||||
for (unsigned i = 0; i <numColumns; ++i) {
|
||||
bytestream << (uint32_t)(fStartingColOID+i+1);
|
||||
|
||||
for (unsigned i = 0; i < numColumns; ++i)
|
||||
{
|
||||
bytestream << (uint32_t)(fStartingColOID + i + 1);
|
||||
}
|
||||
|
||||
bytestream << numDictCols;
|
||||
for (unsigned i = 0; i <numDictCols; ++i) {
|
||||
bytestream << (uint32_t)(fStartingColOID+numColumns+i+1);
|
||||
|
||||
for (unsigned i = 0; i < numDictCols; ++i)
|
||||
{
|
||||
bytestream << (uint32_t)(fStartingColOID + numColumns + i + 1);
|
||||
}
|
||||
|
||||
uint8_t alterFlag = 0;
|
||||
@@ -391,9 +428,10 @@ cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
|
||||
sysOid = 1021;
|
||||
//Find out where syscolumn is
|
||||
rc = fDbrm->getSysCatDBRoot(sysOid, dbRoot);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
result.result =(ResultCode) rc;
|
||||
result.result = (ResultCode) rc;
|
||||
Message::Args args;
|
||||
Message message(9);
|
||||
args.add("Error while calling getSysCatDBRoot ");
|
||||
@@ -408,31 +446,38 @@ cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
|
||||
bytestream << (uint32_t)dbRoot;
|
||||
tableDef.serialize(bytestream);
|
||||
pmNum = (*dbRootPMMap)[dbRoot];
|
||||
|
||||
try
|
||||
{
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " create table sending WE_SVR_WRITE_CREATE_SYSCOLUMN to pm " << pmNum << endl;
|
||||
cout << fTxnid.id << " create table sending WE_SVR_WRITE_CREATE_SYSCOLUMN to pm " << pmNum << endl;
|
||||
#endif
|
||||
fWEClient->write(bytestream, (uint32_t)pmNum);
|
||||
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> rc;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
errorMsg.clear();
|
||||
*bsIn >> errorMsg;
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl;
|
||||
cout << fTxnid.id << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -440,7 +485,7 @@ cout << fTxnid.id << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
|
||||
catch (runtime_error& ex) //write error
|
||||
{
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " create table got exception" << ex.what() << endl;
|
||||
cout << fTxnid.id << " create table got exception" << ex.what() << endl;
|
||||
#endif
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = ex.what();
|
||||
@@ -449,26 +494,28 @@ cout << fTxnid.id << " create table got exception" << ex.what() << endl;
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " create table got unknown exception" << endl;
|
||||
cout << fTxnid.id << " create table got unknown exception" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " Create table WE_SVR_WRITE_CREATE_SYSCOLUMN: " << errorMsg << endl;
|
||||
cout << fTxnid.id << " Create table WE_SVR_WRITE_CREATE_SYSCOLUMN: " << errorMsg << endl;
|
||||
#endif
|
||||
result.result =(ResultCode) rc;
|
||||
result.result = (ResultCode) rc;
|
||||
Message::Args args;
|
||||
Message message(9);
|
||||
args.add("(3)Create table failed due to ");
|
||||
args.add(errorMsg);
|
||||
message.format( args );
|
||||
result.message = message;
|
||||
|
||||
if (rc != NETWORK_ERROR)
|
||||
{
|
||||
rollBackTransaction( uniqueId, txnID, createTableStmt.fSessionID ); //What to do with the error code
|
||||
}
|
||||
|
||||
//release transaction
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
@@ -496,11 +543,13 @@ cout << fTxnid.id << " Create table WE_SVR_WRITE_CREATE_SYSCOLUMN: " << errorMsg
|
||||
bytestream << (numColumns + numDictCols);
|
||||
unsigned colNum = 0;
|
||||
unsigned dictNum = 0;
|
||||
|
||||
while (iter != tableDefCols.end())
|
||||
{
|
||||
colDefPtr = *iter;
|
||||
|
||||
CalpontSystemCatalog::ColDataType dataType = convertDataType(colDefPtr->fType->fType);
|
||||
|
||||
if (dataType == CalpontSystemCatalog::DECIMAL ||
|
||||
dataType == CalpontSystemCatalog::UDECIMAL)
|
||||
{
|
||||
@@ -526,6 +575,7 @@ cout << fTxnid.id << " Create table WE_SVR_WRITE_CREATE_SYSCOLUMN: " << errorMsg
|
||||
colDefPtr->fType->fLength = 8;
|
||||
}
|
||||
}
|
||||
|
||||
bytestream << (fStartingColOID + (colNum++) + 1);
|
||||
bytestream << (uint8_t) dataType;
|
||||
bytestream << (uint8_t) false;
|
||||
@@ -533,107 +583,130 @@ cout << fTxnid.id << " Create table WE_SVR_WRITE_CREATE_SYSCOLUMN: " << errorMsg
|
||||
bytestream << (uint32_t) colDefPtr->fType->fLength;
|
||||
bytestream << (uint16_t) useDBRoot;
|
||||
bytestream << (uint32_t) colDefPtr->fType->fCompressiontype;
|
||||
|
||||
if ( (dataType == CalpontSystemCatalog::CHAR && colDefPtr->fType->fLength > 8) ||
|
||||
(dataType == CalpontSystemCatalog::VARCHAR && colDefPtr->fType->fLength > 7) ||
|
||||
(dataType == CalpontSystemCatalog::VARBINARY && colDefPtr->fType->fLength > 7) ||
|
||||
(dataType == CalpontSystemCatalog::BLOB && colDefPtr->fType->fLength > 7) ||
|
||||
(dataType == CalpontSystemCatalog::TEXT && colDefPtr->fType->fLength > 7) )
|
||||
{
|
||||
bytestream << (uint32_t) (fStartingColOID+numColumns+(dictNum++)+1);
|
||||
bytestream << (uint32_t) (fStartingColOID + numColumns + (dictNum++) + 1);
|
||||
bytestream << (uint8_t) dataType;
|
||||
bytestream << (uint8_t) true;
|
||||
bytestream << (uint32_t) colDefPtr->fType->fLength;
|
||||
bytestream << (uint16_t) useDBRoot;
|
||||
bytestream << (uint32_t) colDefPtr->fType->fCompressiontype;
|
||||
}
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
//@Bug 4176. save oids to a log file for cleanup after fail over.
|
||||
std::vector <CalpontSystemCatalog::OID> oidList;
|
||||
for (unsigned i = 0; i <numColumns; ++i)
|
||||
|
||||
for (unsigned i = 0; i < numColumns; ++i)
|
||||
{
|
||||
oidList.push_back(fStartingColOID+i+1);
|
||||
}
|
||||
bytestream << numDictCols;
|
||||
for (unsigned i = 0; i <numDictCols; ++i)
|
||||
{
|
||||
oidList.push_back(fStartingColOID+numColumns+i+1);
|
||||
oidList.push_back(fStartingColOID + i + 1);
|
||||
}
|
||||
|
||||
try {
|
||||
bytestream << numDictCols;
|
||||
|
||||
for (unsigned i = 0; i < numDictCols; ++i)
|
||||
{
|
||||
oidList.push_back(fStartingColOID + numColumns + i + 1);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
createWriteDropLogFile( fStartingColOID, uniqueId, oidList );
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
result.result =(ResultCode) rc;
|
||||
result.result = (ResultCode) rc;
|
||||
Message::Args args;
|
||||
Message message(9);
|
||||
args.add("(4)Create table failed due to ");
|
||||
args.add(ex.what());
|
||||
message.format( args );
|
||||
result.message = message;
|
||||
|
||||
if (rc != NETWORK_ERROR)
|
||||
{
|
||||
rollBackTransaction( uniqueId, txnID, createTableStmt.fSessionID ); //What to do with the error code
|
||||
}
|
||||
|
||||
//release transaction
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
pmNum = (*dbRootPMMap)[useDBRoot];
|
||||
|
||||
try
|
||||
{
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " create table sending WE_SVR_WRITE_CREATETABLEFILES to pm " << pmNum << endl;
|
||||
cout << fTxnid.id << " create table sending WE_SVR_WRITE_CREATETABLEFILES to pm " << pmNum << endl;
|
||||
#endif
|
||||
fWEClient->write(bytestream, pmNum);
|
||||
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> rc;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
errorMsg.clear();
|
||||
*bsIn >> errorMsg;
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl;
|
||||
cout << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
if (rc != 0)
|
||||
{
|
||||
//drop the newly created files
|
||||
bytestream.restart();
|
||||
bytestream << (ByteStream::byte) WE_SVR_WRITE_DROPFILES;
|
||||
bytestream << uniqueId;
|
||||
bytestream << (uint32_t)(numColumns+numDictCols);
|
||||
for (unsigned i = 0; i < (numColumns+numDictCols); i++)
|
||||
bytestream << (uint32_t)(numColumns + numDictCols);
|
||||
|
||||
for (unsigned i = 0; i < (numColumns + numDictCols); i++)
|
||||
{
|
||||
bytestream << (uint32_t)(fStartingColOID + i + 1);
|
||||
}
|
||||
|
||||
fWEClient->write(bytestream, pmNum);
|
||||
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//@Bug 5464. Delete from extent map.
|
||||
fDbrm->deleteOIDs(oidList);
|
||||
|
||||
@@ -647,7 +720,7 @@ cout << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl;
|
||||
if (rc != 0)
|
||||
{
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl;
|
||||
cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl;
|
||||
#endif
|
||||
rollBackTransaction( uniqueId, txnID, createTableStmt.fSessionID); //What to do with the error code
|
||||
fSessionManager.rolledback(txnID);
|
||||
@@ -676,8 +749,9 @@ cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
return result;
|
||||
}
|
||||
|
||||
//fWEClient->removeQueue(uniqueId);
|
||||
if (rc !=0)
|
||||
if (rc != 0)
|
||||
{
|
||||
result.result = CREATE_ERROR;
|
||||
Message::Args args;
|
||||
@@ -687,6 +761,7 @@ cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
|
||||
message.format( args );
|
||||
result.message = message;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -709,6 +784,7 @@ void CreateTableProcessor::rollBackCreateTable(const string& error, BRM::TxnID t
|
||||
fWriteEngine.rollbackTran(txnID.id, sessionId);
|
||||
|
||||
size_t size = tableDef.fColumns.size();
|
||||
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
fWriteEngine.dropColumn(txnID.id, fStartingColOID + i);
|
||||
@@ -742,6 +818,7 @@ void CreateTableProcessor::rollBackCreateTable(const string& error, BRM::TxnID t
|
||||
}
|
||||
|
||||
DictionaryOIDList::const_iterator dictoid_iter = fDictionaryOIDList.begin();
|
||||
|
||||
while (dictoid_iter != fDictionaryOIDList.end())
|
||||
{
|
||||
DictOID dictOID = *dictoid_iter;
|
||||
@@ -750,6 +827,7 @@ void CreateTableProcessor::rollBackCreateTable(const string& error, BRM::TxnID t
|
||||
|
||||
++dictoid_iter;
|
||||
}
|
||||
|
||||
fSessionManager.rolledback(txnID);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class CreateTableProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
|
||||
CreateTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
|
||||
CreateTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
|
||||
/** @brief process a create table statement
|
||||
*
|
||||
* @param createTableStmt the CreateTableStatement
|
||||
|
||||
@@ -52,20 +52,22 @@ using namespace messageqcpp;
|
||||
namespace ddlpackageprocessor
|
||||
{
|
||||
|
||||
bool DDLIndexPopulator::populateIndex(DDLPackageProcessor::DDLResult& result)
|
||||
{
|
||||
bool DDLIndexPopulator::populateIndex(DDLPackageProcessor::DDLResult& result)
|
||||
{
|
||||
if (makeIndexStructs() )
|
||||
insertIndex();
|
||||
|
||||
result = fResult;
|
||||
return NO_ERROR != fResult.result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool DDLIndexPopulator::makeIndexStructs( )
|
||||
{
|
||||
bool DDLIndexPopulator::makeIndexStructs( )
|
||||
{
|
||||
CalpontSelectExecutionPlan csep;
|
||||
makeCsep(csep);
|
||||
ResourceManager *rm;
|
||||
ResourceManager* rm;
|
||||
|
||||
if (! fEC)
|
||||
{
|
||||
fEC = DistributedEngineComm::instance(rm);
|
||||
@@ -90,15 +92,18 @@ namespace ddlpackageprocessor
|
||||
|
||||
CalpontSystemCatalog::OID tableOid = (csc->tableRID ( tableName )).objnum;
|
||||
CalpontSystemCatalog::NJLSysDataList sysDataList;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
TableBand band;
|
||||
band = jbl->projectTable(tableOid);
|
||||
|
||||
if (band.getRowCount() == 0)
|
||||
{
|
||||
// No more bands, table is done
|
||||
break;
|
||||
}
|
||||
|
||||
band.convertToSysDataList(sysDataList, csc);
|
||||
break;
|
||||
}
|
||||
@@ -107,10 +112,12 @@ namespace ddlpackageprocessor
|
||||
size_t i = 0;
|
||||
vector<ColumnResult*>::const_iterator it;
|
||||
vector<int>::const_iterator oid_iter;
|
||||
|
||||
for (it = sysDataList.begin(); it != sysDataList.end(); it++)
|
||||
{
|
||||
if (isUnique())
|
||||
fUniqueColResultList.push_back(*it);
|
||||
|
||||
for ( oid_iter = fOidList.begin(); oid_iter != fOidList.end(); oid_iter++ )
|
||||
{
|
||||
if ( (*it)->ColumnOID() == *oid_iter )
|
||||
@@ -119,17 +126,18 @@ namespace ddlpackageprocessor
|
||||
addColumnData(*it, coltype, i);
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return (fIdxValueList.size() && NO_ERROR == fResult.result );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DDLIndexPopulator::makeCsep(CalpontSelectExecutionPlan& csep)
|
||||
{
|
||||
void DDLIndexPopulator::makeCsep(CalpontSelectExecutionPlan& csep)
|
||||
{
|
||||
|
||||
csep.sessionID(fSessionID);
|
||||
|
||||
@@ -146,6 +154,7 @@ namespace ddlpackageprocessor
|
||||
string tableName(fTable.fSchema + "." + fTable.fName + ".");
|
||||
|
||||
ColumnNameList::const_iterator cend = fColNames.end();
|
||||
|
||||
for (ColumnNameList::const_iterator cname = fColNames.begin(); cname != cend; ++cname)
|
||||
{
|
||||
string fullColName(tableName + *cname);
|
||||
@@ -156,13 +165,14 @@ namespace ddlpackageprocessor
|
||||
fOidList.push_back( oid );
|
||||
colMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(fullColName, srcp));
|
||||
}
|
||||
|
||||
csep.columnMap (colMap);
|
||||
csep.returnedCols (colList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CalpontSystemCatalog::ColType DDLIndexPopulator::makeIdxStruct(const ColumnResult* cr, size_t cols, boost::shared_ptr<CalpontSystemCatalog> csc )
|
||||
{
|
||||
CalpontSystemCatalog::ColType DDLIndexPopulator::makeIdxStruct(const ColumnResult* cr, size_t cols, boost::shared_ptr<CalpontSystemCatalog> csc )
|
||||
{
|
||||
IdxStruct idx;
|
||||
idx.treeOid = fIdxOID.treeOID;
|
||||
idx.listOid = fIdxOID.listOID;
|
||||
@@ -179,6 +189,7 @@ namespace ddlpackageprocessor
|
||||
{
|
||||
if (1 == coltype.colWidth) idx.idxWidth = 1;
|
||||
else idx.idxWidth = (coltype.colWidth > 4) ? 8 : 4;
|
||||
|
||||
idx.idxType = WR_CHAR;
|
||||
}
|
||||
else
|
||||
@@ -186,14 +197,14 @@ namespace ddlpackageprocessor
|
||||
|
||||
fIdxStructList.push_back(idx);
|
||||
return coltype;
|
||||
}
|
||||
}
|
||||
|
||||
void DDLIndexPopulator::addColumnData(const execplan::ColumnResult* cr, const CalpontSystemCatalog::ColType colType, int added)
|
||||
{
|
||||
void DDLIndexPopulator::addColumnData(const execplan::ColumnResult* cr, const CalpontSystemCatalog::ColType colType, int added)
|
||||
{
|
||||
WriteEngine::IdxTupleList tupleList;
|
||||
WriteEngine::IdxTuple tuple;
|
||||
|
||||
for(int i=0;i < cr->dataCount(); ++i)
|
||||
for (int i = 0; i < cr->dataCount(); ++i)
|
||||
{
|
||||
|
||||
WriteEngine::IdxTuple tuple ;
|
||||
@@ -202,34 +213,36 @@ namespace ddlpackageprocessor
|
||||
if (checkConstraints( tuple, colType, i, added))
|
||||
{
|
||||
tupleList.push_back(tuple);
|
||||
|
||||
if (! added )
|
||||
fRidList.push_back(cr->GetRid(i));
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (tupleList.size())
|
||||
fIdxValueList.push_back(tupleList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DDLIndexPopulator::convertColData(const execplan::ColumnResult* cr, int idx, const CalpontSystemCatalog::ColType& colType, WriteEngine::IdxTuple& tuple)
|
||||
{
|
||||
void DDLIndexPopulator::convertColData(const execplan::ColumnResult* cr, int idx, const CalpontSystemCatalog::ColType& colType, WriteEngine::IdxTuple& tuple)
|
||||
{
|
||||
if (isDictionaryType(colType))
|
||||
{
|
||||
/* tuple.data = tokenizeData ( colType, cr->GetStringData(idx) );*/
|
||||
/* tuple.data = tokenizeData ( cr->GetRid(idx) );*/
|
||||
/* tuple.data = tokenizeData ( colType, cr->GetStringData(idx) );*/
|
||||
/* tuple.data = tokenizeData ( cr->GetRid(idx) );*/
|
||||
tuple.data = convertTokenData(cr->GetStringData(idx));
|
||||
}
|
||||
else tuple.data = convertData( colType, cr, idx);
|
||||
}
|
||||
}
|
||||
|
||||
boost::any DDLIndexPopulator::convertTokenData( const std::string& data )
|
||||
{
|
||||
boost::any DDLIndexPopulator::convertTokenData( const std::string& data )
|
||||
{
|
||||
string strData((size_t)fTOKENSIZE < data.length() ? data.substr(0, fTOKENSIZE) : data);
|
||||
return strData;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Disabled this function as it is currently not used.
|
||||
@@ -237,10 +250,11 @@ namespace ddlpackageprocessor
|
||||
// With iteration 17, the more common version of this getFileName() takes a
|
||||
// partition and segment number in addition to an OID. openColumnFile
|
||||
// should perhaps be changed to use this updated version of getFileName().
|
||||
bool DDLIndexPopulator::openColumnFile(WriteEngine::OID oid)
|
||||
{
|
||||
bool DDLIndexPopulator::openColumnFile(WriteEngine::OID oid)
|
||||
{
|
||||
FileOp fileOp;
|
||||
char fileName[WriteEngine::FILE_NAME_SIZE];
|
||||
|
||||
if (WriteEngine::NO_ERROR == fileOp.getFileName(oid, fileName) )
|
||||
{
|
||||
fColumnFile.open(fileName);
|
||||
@@ -251,12 +265,12 @@ namespace ddlpackageprocessor
|
||||
logError("Could not get column file name for data");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Workaround to get original column token and not "retokenize" the string value
|
||||
boost::any DDLIndexPopulator::tokenizeData( WriteEngine::RID rid )
|
||||
{
|
||||
boost::any DDLIndexPopulator::tokenizeData( WriteEngine::RID rid )
|
||||
{
|
||||
int64_t byteOffset = rid * fTOKENSIZE;
|
||||
ByteStream::byte inbuf[fTOKENSIZE];
|
||||
fColumnFile.seekg(byteOffset, ios::beg);
|
||||
@@ -265,11 +279,11 @@ namespace ddlpackageprocessor
|
||||
WriteEngine::Token token;
|
||||
memcpy(&token, inbuf, fTOKENSIZE);
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::any DDLIndexPopulator::tokenizeData( const execplan::CalpontSystemCatalog::ColType& colType, const std::string& data )
|
||||
{
|
||||
boost::any DDLIndexPopulator::tokenizeData( const execplan::CalpontSystemCatalog::ColType& colType, const std::string& data )
|
||||
{
|
||||
WriteEngine::DctnryTuple dictTuple;
|
||||
|
||||
if ( data.length() > (unsigned int)colType.colWidth )
|
||||
@@ -285,29 +299,40 @@ namespace ddlpackageprocessor
|
||||
dictTuple.sigValue = data.c_str();
|
||||
dictTuple.sigSize = data.length();
|
||||
int error = NO_ERROR;
|
||||
|
||||
if ( NO_ERROR != (error = fWriteEngine->tokenize( fTxnID, dictStruct, dictTuple)) )
|
||||
{
|
||||
logError("Tokenization failed", error);
|
||||
}
|
||||
}
|
||||
|
||||
return dictTuple.token;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
boost::any DDLIndexPopulator::convertData(const CalpontSystemCatalog::ColType& colType, const execplan::ColumnResult* cr, int idx )
|
||||
{
|
||||
boost::any DDLIndexPopulator::convertData(const CalpontSystemCatalog::ColType& colType, const execplan::ColumnResult* cr, int idx )
|
||||
{
|
||||
uint64_t data = cr->GetData(idx);
|
||||
switch( colType.colDataType )
|
||||
|
||||
switch ( colType.colDataType )
|
||||
{
|
||||
case CalpontSystemCatalog::BIT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT: return *reinterpret_cast<char*>(&data);
|
||||
case execplan::CalpontSystemCatalog::SMALLINT: return *reinterpret_cast<short*>(&data);
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
return *reinterpret_cast<char*>(&data);
|
||||
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
return *reinterpret_cast<short*>(&data);
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATE: // @bug 375
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::INT: return *reinterpret_cast<int*>(&data);
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
return *reinterpret_cast<int*>(&data);
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATETIME: // @bug 375
|
||||
case execplan::CalpontSystemCatalog::BIGINT: return *reinterpret_cast<long long*>(&data);
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
return *reinterpret_cast<long long*>(&data);
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
if (colType.colWidth <= CalpontSystemCatalog::FOUR_BYTE) return *reinterpret_cast<short*>(&data);
|
||||
@@ -317,47 +342,55 @@ namespace ddlpackageprocessor
|
||||
else return *reinterpret_cast<long long*>(&data);
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::FLOAT: return *reinterpret_cast<float*>(&data);
|
||||
case execplan::CalpontSystemCatalog::DOUBLE: return *reinterpret_cast<double*>(&data);
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
return *reinterpret_cast<float*>(&data);
|
||||
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
return *reinterpret_cast<double*>(&data);
|
||||
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
{
|
||||
string strData(cr->GetStringData(idx) );
|
||||
return *reinterpret_cast<string*>(&strData);
|
||||
}
|
||||
default: break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
logError("Invalid column type");
|
||||
throw std::runtime_error("Invalid data");
|
||||
|
||||
return *reinterpret_cast<long long*>(&data);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DDLIndexPopulator::insertIndex( )
|
||||
{
|
||||
void DDLIndexPopulator::insertIndex( )
|
||||
{
|
||||
// @bug 359 use bulk load build
|
||||
int rc = (1 < fIdxStructList.size()) ?
|
||||
(void)0
|
||||
: (void)0;
|
||||
|
||||
if (rc)
|
||||
logError("Error inserting index values", rc );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool DDLIndexPopulator::isDictionaryType(const CalpontSystemCatalog::ColType& colType)
|
||||
{
|
||||
bool DDLIndexPopulator::isDictionaryType(const CalpontSystemCatalog::ColType& colType)
|
||||
{
|
||||
return ( (CalpontSystemCatalog::CHAR == colType.colDataType && 8 < colType.colWidth )
|
||||
|| (CalpontSystemCatalog::VARCHAR == colType.colDataType && 7 < colType.colWidth )
|
||||
|| (CalpontSystemCatalog::DECIMAL == colType.colDataType && 18 < colType.precision ));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool DDLIndexPopulator::checkConstraints( const IdxTuple& data, const CalpontSystemCatalog::ColType& ctype, int i, int column)
|
||||
{
|
||||
bool DDLIndexPopulator::checkConstraints( const IdxTuple& data, const CalpontSystemCatalog::ColType& ctype, int i, int column)
|
||||
{
|
||||
|
||||
switch( fConstraint )
|
||||
switch ( fConstraint )
|
||||
{
|
||||
case DDL_INVALID_CONSTRAINT:
|
||||
return true;
|
||||
@@ -366,6 +399,7 @@ namespace ddlpackageprocessor
|
||||
case DDL_PRIMARY_KEY:
|
||||
if ((size_t)column + 1 < fColNames.size() )
|
||||
return true;
|
||||
|
||||
return checkUnique( i, ctype );
|
||||
|
||||
case DDL_NOT_NULL:
|
||||
@@ -378,14 +412,15 @@ namespace ddlpackageprocessor
|
||||
return true; //?
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the row of data at idx is already in fUniqueColResultList
|
||||
|
||||
bool DDLIndexPopulator::checkUnique( int idx, const CalpontSystemCatalog::ColType& colType )
|
||||
{
|
||||
bool DDLIndexPopulator::checkUnique( int idx, const CalpontSystemCatalog::ColType& colType )
|
||||
{
|
||||
if (0 == idx)
|
||||
return true;
|
||||
|
||||
//Get row of data as each column result data at idx
|
||||
size_t indexSize = fColNames.size();
|
||||
vector <uint64_t> rowIntData(indexSize);
|
||||
@@ -399,12 +434,15 @@ namespace ddlpackageprocessor
|
||||
else
|
||||
rowIntData[i] = fUniqueColResultList[i]->GetData(idx);
|
||||
}
|
||||
|
||||
//check if each value in the idx row is equal to each value in a previous row
|
||||
// i is the row; j is the column.
|
||||
bool unique = true;
|
||||
|
||||
for (int i = 0; i < idx && unique; ++i)
|
||||
{
|
||||
bool equal = true;
|
||||
|
||||
for (size_t j = 0; j < indexSize && equal; ++j)
|
||||
{
|
||||
if ( isStringType(colType.colDataType) )
|
||||
@@ -416,25 +454,28 @@ namespace ddlpackageprocessor
|
||||
equal = (static_cast<uint64_t>(fUniqueColResultList[j]->GetData(i)) == rowIntData[j]);
|
||||
}
|
||||
}
|
||||
|
||||
unique = ! equal;
|
||||
}
|
||||
|
||||
if (! unique)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << idx;
|
||||
logError("Unique Constraint violated on row: " + ss.str() );
|
||||
}
|
||||
|
||||
return unique;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool DDLIndexPopulator::checkNotNull(const IdxTuple& data, const CalpontSystemCatalog::ColType& colType)
|
||||
{
|
||||
bool DDLIndexPopulator::checkNotNull(const IdxTuple& data, const CalpontSystemCatalog::ColType& colType)
|
||||
{
|
||||
|
||||
any nullvalue = DDLNullValueForType(colType);
|
||||
bool isNull = false;
|
||||
|
||||
switch( colType.colDataType )
|
||||
switch ( colType.colDataType )
|
||||
{
|
||||
case CalpontSystemCatalog::BIT:
|
||||
break;
|
||||
@@ -466,8 +507,10 @@ namespace ddlpackageprocessor
|
||||
isNull = any_cast<long long>(data.data) == any_cast<long long>(nullvalue);
|
||||
else
|
||||
isNull = compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
isNull = any_cast<float>(data.data) == any_cast<float>(nullvalue);
|
||||
break;
|
||||
@@ -494,9 +537,11 @@ namespace ddlpackageprocessor
|
||||
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
|
||||
else
|
||||
isNull = compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue));
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
{
|
||||
if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE)
|
||||
@@ -505,24 +550,29 @@ namespace ddlpackageprocessor
|
||||
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
|
||||
else
|
||||
isNull = compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw std::runtime_error("getNullValueForType: unkown column data type");
|
||||
}
|
||||
|
||||
if (isNull)
|
||||
logError("Null value not allowed in index");
|
||||
|
||||
return ! isNull;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DDLIndexPopulator::logError(const string& msg, int error)
|
||||
{
|
||||
void DDLIndexPopulator::logError(const string& msg, int error)
|
||||
{
|
||||
|
||||
Message::Args args;
|
||||
Message message(9);
|
||||
args.add((string)__FILE__ + ": ");
|
||||
args.add(msg);
|
||||
|
||||
if (error)
|
||||
{
|
||||
args.add("Error number: ");
|
||||
@@ -533,7 +583,7 @@ namespace ddlpackageprocessor
|
||||
|
||||
fResult.result = DDLPackageProcessor::CREATE_ERROR;
|
||||
fResult.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} //namespace
|
||||
|
||||
@@ -43,7 +43,8 @@
|
||||
|
||||
#include "joblistfactory.h"
|
||||
|
||||
namespace joblist {
|
||||
namespace joblist
|
||||
{
|
||||
class DistributedEngineComm;
|
||||
}
|
||||
|
||||
@@ -85,20 +86,35 @@ public:
|
||||
|
||||
/** @brief Is it required to debug
|
||||
*/
|
||||
const bool isDebug( const DDLPackageProcessor::DebugLevel level ) const { return level <= fDebugLevel; }
|
||||
const bool isDebug( const DDLPackageProcessor::DebugLevel level ) const
|
||||
{
|
||||
return level <= fDebugLevel;
|
||||
}
|
||||
|
||||
/** @brief Get debug level
|
||||
*/
|
||||
const DDLPackageProcessor::DebugLevel getDebugLevel() const { return fDebugLevel; }
|
||||
const DDLPackageProcessor::DebugLevel getDebugLevel() const
|
||||
{
|
||||
return fDebugLevel;
|
||||
}
|
||||
|
||||
|
||||
/** @brief set distributedEngineComm pointer ( for
|
||||
* loading index).
|
||||
*/
|
||||
void setEngineComm(joblist::DistributedEngineComm* ec) { fEC = ec; }
|
||||
void setIdxOID(const DDLPackageProcessor::IndexOID& idxOID) { fIdxOID = idxOID; }
|
||||
void setEngineComm(joblist::DistributedEngineComm* ec)
|
||||
{
|
||||
fEC = ec;
|
||||
}
|
||||
void setIdxOID(const DDLPackageProcessor::IndexOID& idxOID)
|
||||
{
|
||||
fIdxOID = idxOID;
|
||||
}
|
||||
|
||||
DDLPackageProcessor::DDLResult getResult() const { return fResult; }
|
||||
DDLPackageProcessor::DDLResult getResult() const
|
||||
{
|
||||
return fResult;
|
||||
}
|
||||
|
||||
|
||||
/** @brief add data to the index from the statement
|
||||
@@ -115,7 +131,7 @@ public:
|
||||
|
||||
void setConstraint(ddlpackage::DDL_CONSTRAINTS constraint);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** @brief make the structures to update the index
|
||||
*
|
||||
@@ -148,7 +164,7 @@ public:
|
||||
void insertIndex();
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
DDLIndexPopulator(const DDLIndexPopulator& );
|
||||
void operator=(const DDLIndexPopulator& );
|
||||
/** @brief makes Calpont Select Execution Plan
|
||||
@@ -229,9 +245,15 @@ public:
|
||||
*/
|
||||
bool checkUnique(int i, const execplan::CalpontSystemCatalog::ColType& colType );
|
||||
|
||||
bool checkCheck( const WriteEngine::IdxTuple& data, const execplan::CalpontSystemCatalog::ColType& ctype) const { return true; }
|
||||
bool checkCheck( const WriteEngine::IdxTuple& data, const execplan::CalpontSystemCatalog::ColType& ctype) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isUnique() { return ddlpackage::DDL_PRIMARY_KEY == fConstraint || ddlpackage::DDL_UNIQUE == fConstraint; }
|
||||
bool isUnique()
|
||||
{
|
||||
return ddlpackage::DDL_PRIMARY_KEY == fConstraint || ddlpackage::DDL_UNIQUE == fConstraint;
|
||||
}
|
||||
/** @brief logs error and message
|
||||
*
|
||||
* Updates result with message and sets it to CREATE_ERROR
|
||||
|
||||
@@ -86,7 +86,7 @@ DDLPackageProcessor::~DDLPackageProcessor()
|
||||
delete fWEClient;
|
||||
}
|
||||
|
||||
void DDLPackageProcessor::getColumnsForTable(uint32_t sessionID, std::string schema,std::string table,
|
||||
void DDLPackageProcessor::getColumnsForTable(uint32_t sessionID, std::string schema, std::string table,
|
||||
ColumnList& colList)
|
||||
{
|
||||
|
||||
@@ -94,6 +94,7 @@ void DDLPackageProcessor::getColumnsForTable(uint32_t sessionID, std::string sc
|
||||
tableName.schema = schema;
|
||||
tableName.table = table;
|
||||
std::string err;
|
||||
|
||||
try
|
||||
{
|
||||
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID);
|
||||
@@ -102,6 +103,7 @@ void DDLPackageProcessor::getColumnsForTable(uint32_t sessionID, std::string sc
|
||||
const CalpontSystemCatalog::RIDList ridList = systemCatalogPtr->columnRIDs(tableName);
|
||||
|
||||
CalpontSystemCatalog::RIDList::const_iterator rid_iterator = ridList.begin();
|
||||
|
||||
while (rid_iterator != ridList.end())
|
||||
{
|
||||
CalpontSystemCatalog::ROPair roPair = *rid_iterator;
|
||||
@@ -266,16 +268,20 @@ std::string DDLPackageProcessor::buildTableConstraintName(const int oid,
|
||||
// generated by Oracle. Use Oracle's PK name instead of making up our own
|
||||
indexName = fPKName;
|
||||
break;
|
||||
|
||||
case ddlpackage::DDL_FOREIGN_KEY:
|
||||
case ddlpackage::DDL_REFERENCES:
|
||||
prefix = "fk_";
|
||||
break;
|
||||
|
||||
case ddlpackage::DDL_UNIQUE:
|
||||
prefix = "uk_";
|
||||
break;
|
||||
|
||||
case ddlpackage::DDL_CHECK:
|
||||
prefix = "ck_";
|
||||
break;
|
||||
|
||||
case ddlpackage::DDL_NOT_NULL:
|
||||
prefix = "nk_";
|
||||
break;
|
||||
@@ -287,6 +293,7 @@ std::string DDLPackageProcessor::buildTableConstraintName(const int oid,
|
||||
|
||||
if (type != ddlpackage::DDL_PRIMARY_KEY)
|
||||
indexName = prefix + oid_number.str();
|
||||
|
||||
boost::to_lower(indexName);
|
||||
|
||||
return indexName;
|
||||
@@ -306,16 +313,20 @@ std::string DDLPackageProcessor::buildColumnConstraintName(const std::string& sc
|
||||
case ddlpackage::DDL_PRIMARY_KEY:
|
||||
prefix = "pk_";
|
||||
break;
|
||||
|
||||
case ddlpackage::DDL_FOREIGN_KEY:
|
||||
case ddlpackage::DDL_REFERENCES:
|
||||
prefix = "fk_";
|
||||
break;
|
||||
|
||||
case ddlpackage::DDL_UNIQUE:
|
||||
prefix = "uk_";
|
||||
break;
|
||||
|
||||
case ddlpackage::DDL_CHECK:
|
||||
prefix = "ck_";
|
||||
break;
|
||||
|
||||
case ddlpackage::DDL_NOT_NULL:
|
||||
prefix = "nk_";
|
||||
break;
|
||||
@@ -336,7 +347,7 @@ char DDLPackageProcessor::getConstraintCode(ddlpackage::DDL_CONSTRAINTS type)
|
||||
{
|
||||
char constraint_type;
|
||||
|
||||
switch(type)
|
||||
switch (type)
|
||||
{
|
||||
case ddlpackage::DDL_PRIMARY_KEY:
|
||||
constraint_type = 'p';
|
||||
@@ -371,7 +382,8 @@ boost::any
|
||||
DDLPackageProcessor::getNullValueForType(const execplan::CalpontSystemCatalog::ColType& colType)
|
||||
{
|
||||
boost::any value;
|
||||
switch(colType.colDataType)
|
||||
|
||||
switch (colType.colDataType)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::BIT:
|
||||
break;
|
||||
@@ -431,6 +443,7 @@ DDLPackageProcessor::getNullValueForType(const execplan::CalpontSystemCatalog::C
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
case execplan::CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
@@ -466,6 +479,7 @@ DDLPackageProcessor::getNullValueForType(const execplan::CalpontSystemCatalog::C
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
{
|
||||
std::string charnull;
|
||||
|
||||
if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE)
|
||||
{
|
||||
//charnull = joblist::CHAR1NULL;
|
||||
@@ -496,6 +510,7 @@ DDLPackageProcessor::getNullValueForType(const execplan::CalpontSystemCatalog::C
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
{
|
||||
std::string charnull;
|
||||
|
||||
if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE)
|
||||
{
|
||||
//charnull = joblist::CHAR2NULL;
|
||||
@@ -520,6 +535,7 @@ DDLPackageProcessor::getNullValueForType(const execplan::CalpontSystemCatalog::C
|
||||
case execplan::CalpontSystemCatalog::VARBINARY:
|
||||
{
|
||||
std::string charnull;
|
||||
|
||||
if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE)
|
||||
{
|
||||
//charnull = joblist::CHAR2NULL;
|
||||
@@ -584,9 +600,10 @@ bool DDLPackageProcessor::isIndexConstraint(ddlpackage::DDL_CONSTRAINTS type)
|
||||
{
|
||||
bool indexConstraint = false;
|
||||
|
||||
switch(type)
|
||||
switch (type)
|
||||
{
|
||||
case ddlpackage::DDL_PRIMARY_KEY:
|
||||
|
||||
// @bug fix for #418, #416. Do not insert into sysindex
|
||||
//case ddlpackage::DDL_REFERENCES:
|
||||
case ddlpackage::DDL_UNIQUE:
|
||||
@@ -605,7 +622,7 @@ void DDLPackageProcessor::getColumnReferences(ddlpackage::TableConstraintDef& ta
|
||||
ddlpackage::ColumnNameList& columns)
|
||||
{
|
||||
|
||||
switch(tableConstraint.fConstraintType)
|
||||
switch (tableConstraint.fConstraintType)
|
||||
{
|
||||
case ddlpackage::DDL_PRIMARY_KEY:
|
||||
{
|
||||
@@ -647,6 +664,7 @@ boost::any DDLPackageProcessor::tokenizeData(execplan::CalpontSystemCatalog::SCN
|
||||
std::string err("DDLPackageProcessor::tokenizeData ");
|
||||
SUMMARY_INFO(err);
|
||||
boost::any value;
|
||||
|
||||
if (result.result == NO_ERROR)
|
||||
{
|
||||
|
||||
@@ -680,11 +698,13 @@ boost::any DDLPackageProcessor::tokenizeData(execplan::CalpontSystemCatalog::SCN
|
||||
dictTuple.sigValue = (unsigned char*)str.c_str();
|
||||
dictTuple.sigSize = str.length();
|
||||
int error = NO_ERROR;
|
||||
|
||||
if (NO_ERROR != (error = fWriteEngine.tokenize(txnID, dictStruct, dictTuple, false))) // @bug 5572 HDFS tmp file
|
||||
{
|
||||
WErrorCodes ec;
|
||||
throw std::runtime_error("WE: Tokenization failed " + ec.errorString(error));
|
||||
}
|
||||
|
||||
WriteEngine::Token aToken = dictTuple.token;
|
||||
|
||||
value = aToken;
|
||||
@@ -695,13 +715,14 @@ boost::any DDLPackageProcessor::tokenizeData(execplan::CalpontSystemCatalog::SCN
|
||||
err += ex.what();
|
||||
throw std::runtime_error(err);
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
err += "Unknown exception caught, tokenizeData failed.";
|
||||
throw std::runtime_error(err);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -718,24 +739,30 @@ void DDLPackageProcessor::flushPrimprocCache(std::vector<execplan::CalpontSystem
|
||||
LBIDRange_v::iterator it;
|
||||
BRM::BlockList_t blockList;
|
||||
execplan::CalpontSystemCatalog::SCN verID = 0;
|
||||
|
||||
try
|
||||
{
|
||||
while (iter != oidList.end())
|
||||
{
|
||||
WriteEngine::OID oid = *iter;
|
||||
|
||||
if (oid < 3000)
|
||||
{
|
||||
++iter;
|
||||
continue;
|
||||
}
|
||||
|
||||
//@Bug 1708 Flush primproc cache for associated lbids.
|
||||
err = dbrm.lookup(oid, lbidRanges);
|
||||
|
||||
if (err)
|
||||
{
|
||||
error = "DBRM lookUp error.";
|
||||
throw std::runtime_error(error);
|
||||
}
|
||||
|
||||
blockList.clear();
|
||||
|
||||
for (it = lbidRanges.begin(); it != lbidRanges.end(); it++)
|
||||
{
|
||||
for (LBID_t lbid = it->start; lbid < (it->start + it->size); lbid++)
|
||||
@@ -743,6 +770,7 @@ void DDLPackageProcessor::flushPrimprocCache(std::vector<execplan::CalpontSystem
|
||||
blockList.push_back(BRM::LVP_t(lbid, verID));
|
||||
}
|
||||
}
|
||||
|
||||
//Need find a more efficient way to do this.
|
||||
err = cacheutils::flushPrimProcBlocks (blockList);
|
||||
//No need to handle this error as the error comes from timeout, not real error
|
||||
@@ -774,7 +802,8 @@ void DDLPackageProcessor::removeFiles(const uint64_t uniqueId, std::vector<execp
|
||||
bytestream << (ByteStream::byte)WE_SVR_WRITE_DROPFILES;
|
||||
bytestream << uniqueId;
|
||||
bytestream << (uint32_t) oidList.size();
|
||||
for (unsigned i=0; i < oidList.size(); i++)
|
||||
|
||||
for (unsigned i = 0; i < oidList.size(); i++)
|
||||
{
|
||||
bytestream << (uint32_t) oidList[i];
|
||||
}
|
||||
@@ -783,7 +812,9 @@ void DDLPackageProcessor::removeFiles(const uint64_t uniqueId, std::vector<execp
|
||||
ByteStream::byte rc = 0;
|
||||
ByteStream::byte tmp8;
|
||||
string errorMsg;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->write_to_all(bytestream);
|
||||
|
||||
bsIn.reset(new ByteStream());
|
||||
@@ -792,7 +823,9 @@ void DDLPackageProcessor::removeFiles(const uint64_t uniqueId, std::vector<execp
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
@@ -800,10 +833,13 @@ void DDLPackageProcessor::removeFiles(const uint64_t uniqueId, std::vector<execp
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = tmp8;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
@@ -823,7 +859,9 @@ void DDLPackageProcessor::removeFiles(const uint64_t uniqueId, std::vector<execp
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
throw std::runtime_error("Unknown error caught while deleting files.");
|
||||
}
|
||||
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
|
||||
if ( rc != 0)
|
||||
{
|
||||
throw std::runtime_error(errorMsg);
|
||||
@@ -844,6 +882,7 @@ void DDLPackageProcessor::createFiles(CalpontSystemCatalog::TableName aTableName
|
||||
bytestream << (uint32_t)1;
|
||||
bytestream << uniqueId;
|
||||
bytestream << numOids;
|
||||
|
||||
for (unsigned col = 0; col < ridList.size(); col++)
|
||||
{
|
||||
colType = systemCatalogPtr->colType(ridList[col].objnum);
|
||||
@@ -853,6 +892,7 @@ void DDLPackageProcessor::createFiles(CalpontSystemCatalog::TableName aTableName
|
||||
bytestream << (uint32_t) colType.colWidth;
|
||||
bytestream << (uint16_t) useDBRoot;
|
||||
bytestream << (uint32_t) colType.compressionType;
|
||||
|
||||
if (colType.ddn.dictOID > 3000)
|
||||
{
|
||||
bytestream << (uint32_t) colType.ddn.dictOID;
|
||||
@@ -863,11 +903,14 @@ void DDLPackageProcessor::createFiles(CalpontSystemCatalog::TableName aTableName
|
||||
bytestream << (uint32_t) colType.compressionType;
|
||||
}
|
||||
}
|
||||
|
||||
ByteStream::byte rc = 0;
|
||||
ByteStream::byte tmp8;
|
||||
string errorMsg;
|
||||
try {
|
||||
OamCache * oamcache = OamCache::makeOamCache();
|
||||
|
||||
try
|
||||
{
|
||||
OamCache* oamcache = OamCache::makeOamCache();
|
||||
boost::shared_ptr<std::map<int, int> > dbRootPMMap = oamcache->getDBRootToPMMap();
|
||||
int pmNum = (*dbRootPMMap)[useDBRoot];
|
||||
|
||||
@@ -877,6 +920,7 @@ void DDLPackageProcessor::createFiles(CalpontSystemCatalog::TableName aTableName
|
||||
while (1)
|
||||
{
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
@@ -884,12 +928,16 @@ void DDLPackageProcessor::createFiles(CalpontSystemCatalog::TableName aTableName
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = tmp8;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -904,7 +952,9 @@ void DDLPackageProcessor::createFiles(CalpontSystemCatalog::TableName aTableName
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
throw std::runtime_error("Unknown error caught while creating files.");
|
||||
}
|
||||
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
|
||||
if ( rc != 0)
|
||||
throw std::runtime_error(errorMsg);
|
||||
}
|
||||
@@ -932,6 +982,7 @@ void DDLPackageProcessor::removePartitionFiles(std::vector<execplan::CalpontSyst
|
||||
for (uint32_t i = 0; i < oidList.size(); i++)
|
||||
{
|
||||
bs << (uint32_t)oidList[i];
|
||||
|
||||
// add oid to LogicalPartition to form PartitionInfo
|
||||
for (partIt = partitions.begin(); partIt != partitions.end(); ++partIt)
|
||||
{
|
||||
@@ -943,6 +994,7 @@ void DDLPackageProcessor::removePartitionFiles(std::vector<execplan::CalpontSyst
|
||||
}
|
||||
|
||||
bs << (uint32_t)partInfos.size();
|
||||
|
||||
for (uint32_t i = 0; i < partInfos.size(); i++)
|
||||
partInfos[i].serialize(bs);
|
||||
|
||||
@@ -955,6 +1007,7 @@ void DDLPackageProcessor::removePartitionFiles(std::vector<execplan::CalpontSyst
|
||||
{
|
||||
bsIn->restart();
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
@@ -964,11 +1017,13 @@ void DDLPackageProcessor::removePartitionFiles(std::vector<execplan::CalpontSyst
|
||||
else
|
||||
{
|
||||
*bsIn >> rc;
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
break;
|
||||
}
|
||||
|
||||
pmCount--;
|
||||
}
|
||||
}
|
||||
@@ -981,6 +1036,7 @@ void DDLPackageProcessor::removePartitionFiles(std::vector<execplan::CalpontSyst
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
throw std::runtime_error(errorMsg);
|
||||
}
|
||||
|
||||
//@Bug 2171,3327. Drop PrimProc fd cache
|
||||
rc = cacheutils::dropPrimProcFdCache();
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
@@ -991,6 +1047,7 @@ void DDLPackageProcessor::removeExtents(std::vector<execplan::CalpontSystemCatal
|
||||
SUMMARY_INFO("DDLPackageProcessor::removeExtents");
|
||||
int err = 0;
|
||||
err = fDbrm->deleteOIDs(oidList);
|
||||
|
||||
if (err)
|
||||
{
|
||||
string errMsg;
|
||||
@@ -1005,7 +1062,7 @@ void DDLPackageProcessor::createWriteDropLogFile(execplan::CalpontSystemCatalog:
|
||||
{
|
||||
SUMMARY_INFO("DDLPackageProcessor::createWriteDropLogFile");
|
||||
//For shared nothing, the meta files are created under data1 with controllernode.
|
||||
OamCache * oamcache = OamCache::makeOamCache();
|
||||
OamCache* oamcache = OamCache::makeOamCache();
|
||||
std::string OAMParentModuleName = oamcache->getOAMParentModuleName();
|
||||
OAMParentModuleName = OAMParentModuleName.substr(2, OAMParentModuleName.length());
|
||||
int parentId = atoi(OAMParentModuleName.c_str());
|
||||
@@ -1017,27 +1074,36 @@ void DDLPackageProcessor::createWriteDropLogFile(execplan::CalpontSystemCatalog:
|
||||
bytestream << uniqueId;
|
||||
bytestream << (uint32_t)tableOid;
|
||||
bytestream << (uint32_t) oidList.size();
|
||||
for (uint32_t i=0; i < oidList.size(); i++)
|
||||
|
||||
for (uint32_t i = 0; i < oidList.size(); i++)
|
||||
{
|
||||
bytestream << (uint32_t)oidList[i];
|
||||
}
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->write(bytestream, (uint32_t)parentId);
|
||||
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Lost connection to Write Engine Server while writting drop table Log";
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> rc;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1060,7 +1126,7 @@ void DDLPackageProcessor::createWriteDropLogFile(execplan::CalpontSystemCatalog:
|
||||
void DDLPackageProcessor::deleteLogFile(LogFileType fileType, execplan::CalpontSystemCatalog::OID tableOid, uint64_t uniqueId)
|
||||
{
|
||||
SUMMARY_INFO("DDLPackageProcessor::deleteLogFile");
|
||||
OamCache * oamcache = OamCache::makeOamCache();
|
||||
OamCache* oamcache = OamCache::makeOamCache();
|
||||
std::string OAMParentModuleName = oamcache->getOAMParentModuleName();
|
||||
OAMParentModuleName = OAMParentModuleName.substr(2, OAMParentModuleName.length());
|
||||
int parentId = atoi(OAMParentModuleName.c_str());
|
||||
@@ -1073,23 +1139,31 @@ void DDLPackageProcessor::deleteLogFile(LogFileType fileType, execplan::CalpontS
|
||||
bytestream << uniqueId;
|
||||
bytestream << (uint32_t) fileType;
|
||||
bytestream << (uint32_t)tableOid;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->write(bytestream, (uint32_t)parentId);
|
||||
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Lost connection to Write Engine Server while deleting DDL log";
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> rc;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1104,21 +1178,25 @@ void DDLPackageProcessor::deleteLogFile(LogFileType fileType, execplan::CalpontS
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Got unknown exception while deleting DDL Log." ;
|
||||
}
|
||||
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
|
||||
if ( rc != 0)
|
||||
{
|
||||
throw std::runtime_error(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
void DDLPackageProcessor::fetchLogFile(TableLogInfo & tableLogInfos, uint64_t uniqueId)
|
||||
void DDLPackageProcessor::fetchLogFile(TableLogInfo& tableLogInfos, uint64_t uniqueId)
|
||||
{
|
||||
SUMMARY_INFO("DDLPackageProcessor::fetchLogFile");
|
||||
OamCache * oamcache = OamCache::makeOamCache();
|
||||
OamCache* oamcache = OamCache::makeOamCache();
|
||||
std::string OAMParentModuleName = oamcache->getOAMParentModuleName();
|
||||
|
||||
//Use a sensible default so that substr doesn't throw...
|
||||
if (OAMParentModuleName.empty())
|
||||
OAMParentModuleName = "pm1";
|
||||
|
||||
int parentId = atoi(OAMParentModuleName.substr(2, OAMParentModuleName.length()).c_str());
|
||||
ByteStream bytestream;
|
||||
uint8_t rc = 0;
|
||||
@@ -1129,21 +1207,27 @@ void DDLPackageProcessor::fetchLogFile(TableLogInfo & tableLogInfos, uint64_t un
|
||||
boost::shared_ptr<messageqcpp::ByteStream> bsIn;
|
||||
bytestream << (ByteStream::byte)WE_SVR_FETCH_DDL_LOGS;
|
||||
bytestream << uniqueId;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->write(bytestream, (uint32_t)parentId);
|
||||
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Lost connection to Write Engine Server while deleting DDL log";
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> rc;
|
||||
*bsIn >> errorMsg;
|
||||
|
||||
while ( bsIn->length() > 0 )
|
||||
{
|
||||
*bsIn >> tmp32;
|
||||
@@ -1154,19 +1238,23 @@ void DDLPackageProcessor::fetchLogFile(TableLogInfo & tableLogInfos, uint64_t un
|
||||
numOids = tmp32;
|
||||
OidList oidsList;
|
||||
PartitionNums partitionNums;
|
||||
for (unsigned i=0; i < numOids; i++)
|
||||
|
||||
for (unsigned i = 0; i < numOids; i++)
|
||||
{
|
||||
*bsIn >> tmp32;
|
||||
oidsList.push_back(tmp32);
|
||||
}
|
||||
|
||||
*bsIn >> tmp32;
|
||||
numPartitions = tmp32;
|
||||
BRM::LogicalPartition lp;
|
||||
for (unsigned i=0; i < numPartitions; i++)
|
||||
|
||||
for (unsigned i = 0; i < numPartitions; i++)
|
||||
{
|
||||
lp.unserialize(*bsIn);
|
||||
partitionNums.insert(lp);
|
||||
}
|
||||
|
||||
//build the tableloginfo
|
||||
LogInfo aLog;
|
||||
aLog.fileType = logFileType;
|
||||
@@ -1174,6 +1262,7 @@ void DDLPackageProcessor::fetchLogFile(TableLogInfo & tableLogInfos, uint64_t un
|
||||
aLog.partitionNums = partitionNums;
|
||||
tableLogInfos[tableOid] = aLog;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1188,7 +1277,9 @@ void DDLPackageProcessor::fetchLogFile(TableLogInfo & tableLogInfos, uint64_t un
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Got unknown exception while fetching DDL Log." ;
|
||||
}
|
||||
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
|
||||
if ( rc != 0)
|
||||
throw std::runtime_error(errorMsg);
|
||||
|
||||
@@ -1200,7 +1291,7 @@ void DDLPackageProcessor::createWritePartitionLogFile(execplan::CalpontSystemCat
|
||||
{
|
||||
SUMMARY_INFO("DDLPackageProcessor::createWritePartitionLogFile");
|
||||
fWEClient->addQueue(uniqueId);
|
||||
OamCache * oamcache = OamCache::makeOamCache();
|
||||
OamCache* oamcache = OamCache::makeOamCache();
|
||||
std::string OAMParentModuleName = oamcache->getOAMParentModuleName();
|
||||
OAMParentModuleName = OAMParentModuleName.substr(2, OAMParentModuleName.length());
|
||||
int parentId = atoi(OAMParentModuleName.c_str());
|
||||
@@ -1218,27 +1309,36 @@ void DDLPackageProcessor::createWritePartitionLogFile(execplan::CalpontSystemCat
|
||||
(*it).serialize(bytestream);
|
||||
|
||||
bytestream << (uint32_t) oidList.size();
|
||||
for (uint32_t i=0; i < oidList.size(); i++)
|
||||
|
||||
for (uint32_t i = 0; i < oidList.size(); i++)
|
||||
{
|
||||
bytestream << (uint32_t)oidList[i];
|
||||
}
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->write(bytestream, (uint32_t)parentId);
|
||||
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Lost connection to Write Engine Server while writing DDL drop partition log";
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> rc;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1253,7 +1353,9 @@ void DDLPackageProcessor::createWritePartitionLogFile(execplan::CalpontSystemCat
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Got unknown exception while writting truncate Log." ;
|
||||
}
|
||||
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
|
||||
if ( rc != 0)
|
||||
throw std::runtime_error(errorMsg);
|
||||
}
|
||||
@@ -1262,7 +1364,7 @@ void DDLPackageProcessor::createWriteTruncateTableLogFile(execplan::CalpontSyste
|
||||
{
|
||||
SUMMARY_INFO("DDLPackageProcessor::createWriteTruncateTableLogFile");
|
||||
//For shared nothing, the meta files are created under data1 with controllernode.
|
||||
OamCache * oamcache = OamCache::makeOamCache();
|
||||
OamCache* oamcache = OamCache::makeOamCache();
|
||||
std::string OAMParentModuleName = oamcache->getOAMParentModuleName();
|
||||
OAMParentModuleName = OAMParentModuleName.substr(2, OAMParentModuleName.length());
|
||||
int parentId = atoi(OAMParentModuleName.c_str());
|
||||
@@ -1274,27 +1376,36 @@ void DDLPackageProcessor::createWriteTruncateTableLogFile(execplan::CalpontSyste
|
||||
bytestream << uniqueId;
|
||||
bytestream << (uint32_t)tableOid;
|
||||
bytestream << (uint32_t) oidList.size();
|
||||
for (uint32_t i=0; i < oidList.size(); i++)
|
||||
|
||||
for (uint32_t i = 0; i < oidList.size(); i++)
|
||||
{
|
||||
bytestream << (uint32_t)oidList[i];
|
||||
}
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->write(bytestream, (uint32_t)parentId);
|
||||
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Lost connection to Write Engine Server while writing truncate table log";
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> rc;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1320,17 +1431,20 @@ void DDLPackageProcessor::createOpenTruncateTableLogFile(execplan::CalpontSystem
|
||||
SUMMARY_INFO("DDLPackageProcessor::createOpenTruncateTableLogFile");
|
||||
//Build file name with tableOid. Currently, table oid is not returned and therefore not reused
|
||||
string prefix, error;
|
||||
config::Config *config = config::Config::makeConfig();
|
||||
config::Config* config = config::Config::makeConfig();
|
||||
prefix = config->getConfig("SystemConfig", "DBRMRoot");
|
||||
if (prefix.length() == 0) {
|
||||
|
||||
if (prefix.length() == 0)
|
||||
{
|
||||
error = "Need a valid DBRMRoot entry in Calpont configuation file";
|
||||
throw std::runtime_error(error);
|
||||
}
|
||||
|
||||
uint64_t pos = prefix.find_last_of ("/") ;
|
||||
|
||||
if (pos != string::npos)
|
||||
{
|
||||
fDDLLogFileName = prefix.substr(0, pos+1); //Get the file path
|
||||
fDDLLogFileName = prefix.substr(0, pos + 1); //Get the file path
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1338,6 +1452,7 @@ void DDLPackageProcessor::createOpenTruncateTableLogFile(execplan::CalpontSystem
|
||||
throw std::runtime_error(error);
|
||||
|
||||
}
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << tableOid;
|
||||
fDDLLogFileName += "DDL_TRUNCATETABLE_Log_" + oss.str();
|
||||
@@ -1354,7 +1469,7 @@ void DDLPackageProcessor::removeIndexFiles(execplan::CalpontSystemCatalog::SCN t
|
||||
DDLResult& result,
|
||||
execplan::CalpontSystemCatalog::IndexOIDList& idxOIDList)
|
||||
{
|
||||
/* SUMMARY_INFO("DDLPackageProcessor::removeIndexFiles");
|
||||
/* SUMMARY_INFO("DDLPackageProcessor::removeIndexFiles");
|
||||
|
||||
if (result.result != NO_ERROR)
|
||||
return;
|
||||
@@ -1394,7 +1509,7 @@ void DDLPackageProcessor::removeIndexFiles(execplan::CalpontSystemCatalog::SCN t
|
||||
error = "Unknown exception caught";
|
||||
throw std::runtime_error(error);
|
||||
}
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -1422,7 +1537,7 @@ void DDLPackageProcessor::updateSyscolumns(execplan::CalpontSystemCatalog::SCN t
|
||||
colStructs.push_back(colStruct);
|
||||
int error;
|
||||
std::string err;
|
||||
std::vector<void *> colOldValuesList1;
|
||||
std::vector<void*> colOldValuesList1;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -1455,12 +1570,15 @@ void DDLPackageProcessor::returnOIDs(execplan::CalpontSystemCatalog::RIDList& ri
|
||||
CalpontSystemCatalog::ROPair roPair;
|
||||
CalpontSystemCatalog::RIDList::const_iterator col_iter = ridList.begin();
|
||||
std::string err;
|
||||
|
||||
try
|
||||
{
|
||||
execplan::ObjectIDManager fObjectIDManager;
|
||||
|
||||
while (col_iter != ridList.end())
|
||||
{
|
||||
roPair = *col_iter;
|
||||
|
||||
if (roPair.objnum < 3000)
|
||||
{
|
||||
++col_iter;
|
||||
@@ -1473,14 +1591,17 @@ void DDLPackageProcessor::returnOIDs(execplan::CalpontSystemCatalog::RIDList& ri
|
||||
|
||||
CalpontSystemCatalog::DictOID dictOID;
|
||||
CalpontSystemCatalog::DictOIDList::const_iterator dict_iter = dictOIDList.begin();
|
||||
|
||||
while (dict_iter != dictOIDList.end())
|
||||
{
|
||||
dictOID = *dict_iter;
|
||||
|
||||
if (dictOID.dictOID < 3000)
|
||||
{
|
||||
++dict_iter;
|
||||
continue;
|
||||
}
|
||||
|
||||
fObjectIDManager.returnOID(dictOID.dictOID);
|
||||
++dict_iter;
|
||||
}
|
||||
@@ -1504,10 +1625,12 @@ void DDLPackageProcessor::findColumnData(uint32_t sessionID, execplan::CalpontSy
|
||||
ColumnList columns;
|
||||
ColumnList::const_iterator column_iterator;
|
||||
std::string err;
|
||||
|
||||
try
|
||||
{
|
||||
getColumnsForTable(sessionID, systableName.schema,systableName.table, columns);
|
||||
getColumnsForTable(sessionID, systableName.schema, systableName.table, columns);
|
||||
column_iterator = columns.begin();
|
||||
|
||||
while (column_iterator != columns.end())
|
||||
{
|
||||
sysCol = *column_iterator;
|
||||
@@ -1517,6 +1640,7 @@ void DDLPackageProcessor::findColumnData(uint32_t sessionID, execplan::CalpontSy
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
++column_iterator;
|
||||
}
|
||||
}
|
||||
@@ -1535,21 +1659,25 @@ void DDLPackageProcessor::findColumnData(uint32_t sessionID, execplan::CalpontSy
|
||||
void DDLPackageProcessor::cleanString(string& s)
|
||||
{
|
||||
string::size_type pos = s.find_first_not_of(" ");
|
||||
|
||||
//stripe off space and ' or '' at beginning and end
|
||||
if (pos < s.length())
|
||||
{
|
||||
s = s.substr(pos, s.length()-pos);
|
||||
s = s.substr(pos, s.length() - pos);
|
||||
|
||||
if ((pos = s.find_last_of(" ")) < s.length())
|
||||
{
|
||||
s = s.substr(0, pos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (s[0] == '\'')
|
||||
{
|
||||
s = s.substr(1, s.length()-2);
|
||||
s = s.substr(1, s.length() - 2);
|
||||
|
||||
if (s[0] == '\'')
|
||||
s = s.substr(1, s.length()-2);
|
||||
s = s.substr(1, s.length() - 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1587,21 +1715,27 @@ int DDLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
|
||||
int rc = 0;
|
||||
ByteStream::byte tmp8;
|
||||
std::string errorMsg;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = tmp8;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
@@ -1621,20 +1755,26 @@ int DDLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
|
||||
fWEClient->write_to_all(bytestream);
|
||||
bsIn.reset(new ByteStream());
|
||||
msgRecived = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = tmp8;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
@@ -1645,6 +1785,7 @@ int DDLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,9 +88,11 @@ public:
|
||||
*/
|
||||
enum ResultCode { NO_ERROR, CREATE_ERROR, ALTER_ERROR, DROP_ERROR, TRUNC_ERROR,
|
||||
TOKENIZATION_ERROR, NOT_ACCEPTING_PACKAGES, PK_NOTNULL_ERROR, WARNING, USER_ERROR, NETWORK_ERROR, PARTITION_WARNING,
|
||||
WARN_NO_PARTITION};
|
||||
WARN_NO_PARTITION
|
||||
};
|
||||
|
||||
enum DebugLevel { /** @brief Debug level type enumeration */
|
||||
enum DebugLevel /** @brief Debug level type enumeration */
|
||||
{
|
||||
NONE = 0, /** @brief No debug info */
|
||||
SUMMARY = 1, /** @brief Summary level debug info */
|
||||
DETAIL = 2, /** @brief A little detail debug info */
|
||||
@@ -166,9 +168,15 @@ public:
|
||||
unsigned month : 4;
|
||||
unsigned year : 16;
|
||||
// NULL column value = 0xFFFFFFFE
|
||||
EXPORT Date( ) { year = 0xFFFF; month = 0xF; day = 0x3F; spare = 0x3E;}
|
||||
EXPORT Date( )
|
||||
{
|
||||
year = 0xFFFF;
|
||||
month = 0xF;
|
||||
day = 0x3F;
|
||||
spare = 0x3E;
|
||||
}
|
||||
};
|
||||
/*
|
||||
/*
|
||||
struct Date
|
||||
{
|
||||
int year : 16;
|
||||
@@ -189,10 +197,18 @@ public:
|
||||
unsigned month : 4;
|
||||
unsigned year : 16;
|
||||
// NULL column value = 0xFFFFFFFFFFFFFFFE
|
||||
EXPORT dateTime( ) { year = 0xFFFF; month = 0xF; day = 0x3F; hour = 0x3F; minute = 0x3F; second = 0x3F;
|
||||
msecond = 0xFFFFE; }
|
||||
EXPORT dateTime( )
|
||||
{
|
||||
year = 0xFFFF;
|
||||
month = 0xF;
|
||||
day = 0x3F;
|
||||
hour = 0x3F;
|
||||
minute = 0x3F;
|
||||
second = 0x3F;
|
||||
msecond = 0xFFFFE;
|
||||
}
|
||||
};
|
||||
/*
|
||||
/*
|
||||
struct dateTime
|
||||
{
|
||||
int year : 16;
|
||||
@@ -215,19 +231,34 @@ public:
|
||||
struct NJLSysDataList
|
||||
{
|
||||
NJLSysDataVector sysDataVec;
|
||||
EXPORT NJLSysDataList(){};
|
||||
EXPORT NJLSysDataList() {};
|
||||
EXPORT ~NJLSysDataList();
|
||||
NJLSysDataVector::const_iterator begin() {return sysDataVec.begin();}
|
||||
NJLSysDataVector::const_iterator end() {return sysDataVec.end();}
|
||||
void push_back(execplan::ColumnResult* cr) {sysDataVec.push_back(cr);}
|
||||
unsigned int size() {return static_cast<unsigned int>(sysDataVec.size());}
|
||||
NJLSysDataVector::const_iterator begin()
|
||||
{
|
||||
return sysDataVec.begin();
|
||||
}
|
||||
NJLSysDataVector::const_iterator end()
|
||||
{
|
||||
return sysDataVec.end();
|
||||
}
|
||||
void push_back(execplan::ColumnResult* cr)
|
||||
{
|
||||
sysDataVec.push_back(cr);
|
||||
}
|
||||
unsigned int size()
|
||||
{
|
||||
return static_cast<unsigned int>(sysDataVec.size());
|
||||
}
|
||||
int findColumn(const execplan::CalpontSystemCatalog::OID& columnOID)
|
||||
{
|
||||
for(uint32_t i = 0; i < sysDataVec.size(); i++) {
|
||||
if(sysDataVec[i]->ColumnOID() == columnOID) {
|
||||
for (uint32_t i = 0; i < sysDataVec.size(); i++)
|
||||
{
|
||||
if (sysDataVec[i]->ColumnOID() == columnOID)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
@@ -250,28 +281,49 @@ public:
|
||||
|
||||
/** @brief Is it required to debug
|
||||
*/
|
||||
const bool isDebug( const DebugLevel level ) const { return level <= fDebugLevel; }
|
||||
const bool isDebug( const DebugLevel level ) const
|
||||
{
|
||||
return level <= fDebugLevel;
|
||||
}
|
||||
|
||||
/** @brief Get debug level
|
||||
*/
|
||||
const DebugLevel getDebugLevel() const { return fDebugLevel; }
|
||||
const DebugLevel getDebugLevel() const
|
||||
{
|
||||
return fDebugLevel;
|
||||
}
|
||||
|
||||
/** @brief Set debug level
|
||||
*/
|
||||
void setDebugLevel( const DebugLevel level ) { fDebugLevel = level; }
|
||||
void setDebugLevel( const DebugLevel level )
|
||||
{
|
||||
fDebugLevel = level;
|
||||
}
|
||||
|
||||
/** @brief Get index oid that was allocated during index creation
|
||||
*/
|
||||
IndexOID getIndexOID() const { return fIdxOID; }
|
||||
IndexOID getIndexOID() const
|
||||
{
|
||||
return fIdxOID;
|
||||
}
|
||||
|
||||
/** @brief Get starting column oid that was allocated during table
|
||||
* creation.
|
||||
*/
|
||||
int getStartingColumnOID() const { return fStartingColOID; }
|
||||
int getStartingColumnOID() const
|
||||
{
|
||||
return fStartingColOID;
|
||||
}
|
||||
|
||||
/** @brief access and mutator of fPKName */
|
||||
const std::string PKName() const {return fPKName;}
|
||||
void PKName (const std::string PKName) {fPKName = PKName;}
|
||||
const std::string PKName() const
|
||||
{
|
||||
return fPKName;
|
||||
}
|
||||
void PKName (const std::string PKName)
|
||||
{
|
||||
fPKName = PKName;
|
||||
}
|
||||
/** @brief Flush primproc cache for associated lbids.
|
||||
*
|
||||
* @param oidList the list of OIDs for
|
||||
@@ -346,7 +398,7 @@ public:
|
||||
/** @brief fetch log file infomation
|
||||
*
|
||||
*/
|
||||
EXPORT void fetchLogFile(TableLogInfo & tableLogInfos, uint64_t uniqueId);
|
||||
EXPORT void fetchLogFile(TableLogInfo& tableLogInfos, uint64_t uniqueId);
|
||||
|
||||
BRM::TxnID fTxnid;
|
||||
|
||||
@@ -357,7 +409,7 @@ protected:
|
||||
* @param table the table name
|
||||
* @param colList will contain the list of columns on return
|
||||
*/
|
||||
EXPORT void getColumnsForTable( uint32_t sessionID, std::string schema,std::string table,
|
||||
EXPORT void getColumnsForTable( uint32_t sessionID, std::string schema, std::string table,
|
||||
ColumnList& colList );
|
||||
|
||||
/** @brief convert parsed ddl data type to a system catalog data type
|
||||
@@ -452,9 +504,9 @@ protected:
|
||||
* @param constraintList the table constrain list
|
||||
* @param qualifiedName the name of catalog, schema, object names
|
||||
*/
|
||||
// void writeTableSysConstraintMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
|
||||
// ddlpackage::TableConstraintDefList& constraintList, ddlpackage::QualifiedName&
|
||||
// qualifiedName, bool alterFlag=false );
|
||||
// void writeTableSysConstraintMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
|
||||
// ddlpackage::TableConstraintDefList& constraintList, ddlpackage::QualifiedName&
|
||||
// qualifiedName, bool alterFlag=false );
|
||||
/** @brief write the table constraint meta data to the SYSCONSTRAINTCOL table
|
||||
*
|
||||
* @param txnID the transaction id
|
||||
@@ -462,9 +514,9 @@ protected:
|
||||
* @param constraintList the table constrain list
|
||||
* @param qualifiedName the name of catalog, schema, object names
|
||||
*/
|
||||
// void writeTableSysConstraintColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
|
||||
// const DDLResult& result, ddlpackage::TableConstraintDefList& constraintList,
|
||||
// ddlpackage::QualifiedName& qualifiedName, bool alterFlag=false );
|
||||
// void writeTableSysConstraintColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
|
||||
// const DDLResult& result, ddlpackage::TableConstraintDefList& constraintList,
|
||||
// ddlpackage::QualifiedName& qualifiedName, bool alterFlag=false );
|
||||
|
||||
/** @brief write the column constraint meta data to the SYSCONTRAINT table
|
||||
*
|
||||
@@ -485,7 +537,7 @@ protected:
|
||||
*/
|
||||
// void writeColumnSysConstraintColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
|
||||
// const DDLResult& result, ddlpackage::ColumnDefList& tableDefCols,
|
||||
// ddlpackage::QualifiedName& qualifiedName);
|
||||
// ddlpackage::QualifiedName& qualifiedName);
|
||||
|
||||
|
||||
/** @brief write the index meta data to the SYSINDEX table
|
||||
@@ -586,7 +638,7 @@ protected:
|
||||
* @param tableName the qualified name of the table whose constraints
|
||||
* are to be removed
|
||||
*/
|
||||
// void removeSysContraintMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
|
||||
// void removeSysContraintMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
|
||||
// ddlpackage::QualifiedName& tableName);
|
||||
|
||||
/** @brief remove the constraint meta data from the SYSCONSTRAINT table
|
||||
@@ -595,9 +647,9 @@ protected:
|
||||
* @param result the result of the operation
|
||||
* @param indexName the index name to be removed
|
||||
*/
|
||||
// void removeSysIndexMetaDataForIndex(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
|
||||
// DDLResult& result,
|
||||
// execplan::CalpontSystemCatalog::IndexNameList& indexNameList);
|
||||
// void removeSysIndexMetaDataForIndex(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
|
||||
// DDLResult& result,
|
||||
// execplan::CalpontSystemCatalog::IndexNameList& indexNameList);
|
||||
|
||||
/** @brief remove the column constraint meta data from the SYSCONSTRAINTCOL table
|
||||
*
|
||||
@@ -643,7 +695,7 @@ protected:
|
||||
* @param tableDefCols the table column definition list
|
||||
*/
|
||||
void createColumnFiles(execplan::CalpontSystemCatalog::SCN txnID, const DDLResult& result,
|
||||
ddlpackage::ColumnDefList& tableDefCols, const int useDBRoot, const uint32_t partitionNum=0);
|
||||
ddlpackage::ColumnDefList& tableDefCols, const int useDBRoot, const uint32_t partitionNum = 0);
|
||||
|
||||
/** @brief update the SYSCOLUMN table
|
||||
*
|
||||
@@ -823,7 +875,7 @@ private:
|
||||
template <class T>
|
||||
bool from_string(T& t,
|
||||
const std::string& s,
|
||||
std::ios_base& (*f)(std::ios_base&))
|
||||
std::ios_base & (*f)(std::ios_base&))
|
||||
{
|
||||
std::istringstream iss(s);
|
||||
return !(iss >> f >> t).fail();
|
||||
|
||||
@@ -28,14 +28,15 @@
|
||||
|
||||
using namespace ddlpackage;
|
||||
|
||||
namespace ddlpackageprocessor {
|
||||
namespace ddlpackageprocessor
|
||||
{
|
||||
|
||||
DDLPackageProcessor* DDLPackageProcessorFactory::
|
||||
makePackageProcessor(int packageType, ddlpackage::CalpontDDLPackage& cpackage)
|
||||
{
|
||||
DDLPackageProcessor* ddlProcPtr = 0;
|
||||
|
||||
switch( packageType )
|
||||
switch ( packageType )
|
||||
{
|
||||
case DDL_CREATE:
|
||||
ddlProcPtr = new CreatePackageProcessor();
|
||||
|
||||
@@ -28,16 +28,18 @@
|
||||
#include "ddlpackageprocessor.h"
|
||||
|
||||
|
||||
namespace ddlpackageprocessor {
|
||||
namespace ddlpackageprocessor
|
||||
{
|
||||
|
||||
/** @brief create a ddlPackageProcessor object from a CalpontddlPackage object
|
||||
*
|
||||
*/
|
||||
class DDLPackageProcessorFactory {
|
||||
class DDLPackageProcessorFactory
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/** @brief static ddlPackageProcessor constructor method
|
||||
/** @brief static ddlPackageProcessor constructor method
|
||||
*
|
||||
* @param packageType the ddl Package type
|
||||
* @param cpackage the CalpontddlPackage from which the ddlPackageProcessor is constructed
|
||||
|
||||
@@ -39,8 +39,8 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
|
||||
CalpontSystemCatalog::IndexOID indexOID;
|
||||
|
||||
BRM::TxnID txnID;
|
||||
txnID.id= fTxnid.id;
|
||||
txnID.valid= fTxnid.valid;
|
||||
txnID.id = fTxnid.id;
|
||||
txnID.valid = fTxnid.valid;
|
||||
|
||||
DDLResult result;
|
||||
result.result = NO_ERROR;
|
||||
@@ -60,6 +60,7 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
|
||||
|
||||
VERBOSE_INFO("Removing the SYSINDEX meta data");
|
||||
removeSysIndexMetaData(dropIndexStmt.fSessionID, txnID.id, result, *dropIndexStmt.fIndexName);
|
||||
|
||||
if (result.result != NO_ERROR)
|
||||
{
|
||||
DETAIL_INFO("writeSysIndexMetaData failed");
|
||||
@@ -68,6 +69,7 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
|
||||
|
||||
VERBOSE_INFO("Removing the SYSINDEXCOL meta data");
|
||||
removeSysIndexColMetaData(dropIndexStmt.fSessionID, txnID.id, result, *dropIndexStmt.fIndexName);
|
||||
|
||||
if (result.result != NO_ERROR)
|
||||
{
|
||||
DETAIL_INFO("writeSysIndexMetaData failed");
|
||||
@@ -76,7 +78,8 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
|
||||
|
||||
|
||||
VERBOSE_INFO("Removing the index files");
|
||||
err = fWriteEngine.dropIndex(txnID.id, indexOID.objnum,indexOID.listOID);
|
||||
err = fWriteEngine.dropIndex(txnID.id, indexOID.objnum, indexOID.listOID);
|
||||
|
||||
if (err)
|
||||
{
|
||||
DETAIL_INFO("WriteEngine dropIndex failed");
|
||||
@@ -88,11 +91,13 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
|
||||
|
||||
// register the changes
|
||||
err = fWriteEngine.commit( txnID.id );
|
||||
|
||||
if (err)
|
||||
{
|
||||
DETAIL_INFO("Failed to commit the drop index transaction");
|
||||
goto rollback;
|
||||
}
|
||||
|
||||
fSessionManager.committed(txnID);
|
||||
//fObjectIDManager.returnOID(indexOID.objnum);
|
||||
//fObjectIDManager.returnOID(indexOID.listOID);
|
||||
|
||||
@@ -28,24 +28,24 @@
|
||||
|
||||
namespace ddlpackageprocessor
|
||||
{
|
||||
/** @brief specialization of a DDLPacakageProcessor
|
||||
/** @brief specialization of a DDLPacakageProcessor
|
||||
* for interaction with the Write Engine to process
|
||||
* drop index statements.
|
||||
*/
|
||||
class DropIndexProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
class DropIndexProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
/** @brief process a drop index statement
|
||||
*
|
||||
* @param dropIndexStmt the drop index statement
|
||||
*/
|
||||
DDLResult processPackage(ddlpackage::DropIndexStatement& dropIndexStmt);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
} //namespace ddlpackageprocessor
|
||||
#endif //DROPINDEXPROCESSOR_H
|
||||
|
||||
@@ -38,8 +38,8 @@ using namespace oam;
|
||||
namespace ddlpackageprocessor
|
||||
{
|
||||
|
||||
DropPartitionProcessor::DDLResult DropPartitionProcessor::processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt)
|
||||
{
|
||||
DropPartitionProcessor::DDLResult DropPartitionProcessor::processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt)
|
||||
{
|
||||
SUMMARY_INFO("DropPartitionProcessor::processPackage");
|
||||
|
||||
DDLResult result;
|
||||
@@ -54,8 +54,9 @@ namespace ddlpackageprocessor
|
||||
int rc = 0;
|
||||
rc = fDbrm->isReadWrite();
|
||||
BRM::TxnID txnID;
|
||||
txnID.id= fTxnid.id;
|
||||
txnID.valid= fTxnid.valid;
|
||||
txnID.id = fTxnid.id;
|
||||
txnID.valid = fTxnid.valid;
|
||||
|
||||
if (rc != 0 )
|
||||
{
|
||||
logging::Message::Args args;
|
||||
@@ -80,7 +81,8 @@ namespace ddlpackageprocessor
|
||||
uint64_t uniqueId = 0;
|
||||
|
||||
//Bug 5070. Added exception handling
|
||||
try {
|
||||
try
|
||||
{
|
||||
uniqueId = fDbrm->getUnique64();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
@@ -106,7 +108,7 @@ namespace ddlpackageprocessor
|
||||
return result;
|
||||
}
|
||||
|
||||
string stmt = dropPartitionStmt.fSql + "|" + dropPartitionStmt.fTableName->fSchema +"|";
|
||||
string stmt = dropPartitionStmt.fSql + "|" + dropPartitionStmt.fTableName->fSchema + "|";
|
||||
SQLLogger logger(stmt, fDDLLoggingId, sessionID, txnID.id);
|
||||
|
||||
try
|
||||
@@ -119,22 +121,26 @@ namespace ddlpackageprocessor
|
||||
tableName.schema = dropPartitionStmt.fTableName->fSchema;
|
||||
tableName.table = dropPartitionStmt.fTableName->fName;
|
||||
roPair = systemCatalogPtr->tableRID( tableName );
|
||||
|
||||
//@Bug 3054 check for system catalog
|
||||
if ( roPair.objnum < 3000 )
|
||||
{
|
||||
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
processID = ::getpid();
|
||||
oam::OamCache * oamcache = OamCache::makeOamCache();
|
||||
oam::OamCache* oamcache = OamCache::makeOamCache();
|
||||
std::vector<int> pmList = oamcache->getModuleIds();
|
||||
std::vector<uint32_t> pms;
|
||||
for (unsigned i=0; i < pmList.size(); i++)
|
||||
|
||||
for (unsigned i = 0; i < pmList.size(); i++)
|
||||
{
|
||||
pms.push_back((uint32_t)pmList[i]);
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -155,8 +161,8 @@ namespace ddlpackageprocessor
|
||||
numTries = waitPeriod * 10;
|
||||
struct timespec rm_ts;
|
||||
|
||||
rm_ts.tv_sec = sleepTime/1000;
|
||||
rm_ts.tv_nsec = sleepTime%1000 *1000000;
|
||||
rm_ts.tv_sec = sleepTime / 1000;
|
||||
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
|
||||
|
||||
for (; i < numTries; i++)
|
||||
{
|
||||
@@ -164,19 +170,22 @@ namespace ddlpackageprocessor
|
||||
Sleep(rm_ts.tv_sec * 1000);
|
||||
#else
|
||||
struct timespec abs_ts;
|
||||
|
||||
do
|
||||
{
|
||||
abs_ts.tv_sec = rm_ts.tv_sec;
|
||||
abs_ts.tv_nsec = rm_ts.tv_nsec;
|
||||
}
|
||||
while(nanosleep(&abs_ts,&rm_ts) < 0);
|
||||
while (nanosleep(&abs_ts, &rm_ts) < 0);
|
||||
|
||||
#endif
|
||||
// reset
|
||||
sessionID = dropPartitionStmt.fSessionID;
|
||||
txnID.id= fTxnid.id;
|
||||
txnID.valid= fTxnid.valid;
|
||||
txnID.id = fTxnid.id;
|
||||
txnID.valid = fTxnid.valid;
|
||||
processID = ::getpid();
|
||||
processName = "DDLProc";
|
||||
|
||||
try
|
||||
{
|
||||
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
|
||||
@@ -202,7 +211,7 @@ namespace ddlpackageprocessor
|
||||
args.add(processName);
|
||||
args.add((uint64_t)processID);
|
||||
args.add((uint64_t)sessionID);
|
||||
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED,args));
|
||||
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
@@ -225,12 +234,13 @@ namespace ddlpackageprocessor
|
||||
dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
|
||||
|
||||
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
|
||||
for ( unsigned i=0; i < tableColRidList.size(); i++ )
|
||||
for ( unsigned i = 0; i < tableColRidList.size(); i++ )
|
||||
{
|
||||
if ( tableColRidList[i].objnum > 3000 )
|
||||
oidList.push_back( tableColRidList[i].objnum );
|
||||
}
|
||||
for ( unsigned i=0; i < dictOIDList.size(); i++ )
|
||||
|
||||
for ( unsigned i = 0; i < dictOIDList.size(); i++ )
|
||||
{
|
||||
if ( dictOIDList[i].dictOID > 3000 )
|
||||
oidList.push_back( dictOIDList[i].dictOID );
|
||||
@@ -239,7 +249,8 @@ namespace ddlpackageprocessor
|
||||
//Mark the partition disabled from extent map
|
||||
string emsg;
|
||||
rc = fDbrm->markPartitionForDeletion( oidList, dropPartitionStmt.fPartitions, emsg);
|
||||
if (rc != 0 && rc !=BRM::ERR_PARTITION_DISABLED &&
|
||||
|
||||
if (rc != 0 && rc != BRM::ERR_PARTITION_DISABLED &&
|
||||
rc != BRM::ERR_INVALID_OP_LAST_PARTITION &&
|
||||
rc != BRM::ERR_NOT_EXIST_PARTITION)
|
||||
{
|
||||
@@ -262,6 +273,7 @@ namespace ddlpackageprocessor
|
||||
}
|
||||
|
||||
set<BRM::LogicalPartition>::iterator it;
|
||||
|
||||
for (it = dropPartitionStmt.fPartitions.begin(); it != dropPartitionStmt.fPartitions.end(); ++it)
|
||||
{
|
||||
if (outOfServicePartitions.find(*it) != outOfServicePartitions.end())
|
||||
@@ -279,6 +291,7 @@ namespace ddlpackageprocessor
|
||||
//Remove the partition from extent map
|
||||
emsg.clear();
|
||||
rc = fDbrm->deletePartition( oidList, dropPartitionStmt.fPartitions, emsg);
|
||||
|
||||
if ( rc != 0 )
|
||||
throw std::runtime_error(emsg);
|
||||
}
|
||||
@@ -297,14 +310,19 @@ namespace ddlpackageprocessor
|
||||
result.result = WARN_NO_PARTITION;
|
||||
else
|
||||
result.result = DROP_ERROR;
|
||||
|
||||
result.message = message;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fDbrm->releaseTableLock(uniqueID);
|
||||
} catch (std::exception&)
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
result.result = DROP_ERROR;
|
||||
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
|
||||
}
|
||||
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
@@ -322,32 +340,41 @@ namespace ddlpackageprocessor
|
||||
|
||||
result.result = DROP_ERROR;
|
||||
result.message = message;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fDbrm->releaseTableLock(uniqueID);
|
||||
} catch (std::exception&)
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
result.result = DROP_ERROR;
|
||||
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
|
||||
}
|
||||
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
// Log the DDL statement
|
||||
logging::logDDL(dropPartitionStmt.fSessionID, txnID.id, dropPartitionStmt.fSql, dropPartitionStmt.fOwner);
|
||||
//Remove the log file
|
||||
//release the transaction
|
||||
try {
|
||||
fDbrm->releaseTableLock(uniqueID);
|
||||
deleteLogFile(DROPPART_LOG, roPair.objnum, uniqueId);
|
||||
} catch (std::exception&)
|
||||
{
|
||||
result.result = DROP_ERROR;
|
||||
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
fSessionManager.committed(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Log the DDL statement
|
||||
logging::logDDL(dropPartitionStmt.fSessionID, txnID.id, dropPartitionStmt.fSql, dropPartitionStmt.fOwner);
|
||||
|
||||
//Remove the log file
|
||||
//release the transaction
|
||||
try
|
||||
{
|
||||
fDbrm->releaseTableLock(uniqueID);
|
||||
deleteLogFile(DROPPART_LOG, roPair.objnum, uniqueId);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
result.result = DROP_ERROR;
|
||||
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
fSessionManager.committed(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,25 +34,25 @@
|
||||
|
||||
namespace ddlpackageprocessor
|
||||
{
|
||||
/** @brief specialization of a DDLPacakageProcessor
|
||||
/** @brief specialization of a DDLPacakageProcessor
|
||||
* for interacting with the Write Engine to process
|
||||
* drop table ddl statements.
|
||||
*/
|
||||
class DropPartitionProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
DropPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
|
||||
class DropPartitionProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
DropPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
|
||||
/** @brief process a drop table statement
|
||||
*
|
||||
* @param dropTableStmt the drop table statement
|
||||
*/
|
||||
EXPORT DDLResult processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
};
|
||||
};
|
||||
} // namespace ddlpackageprocessor
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
@@ -65,10 +65,11 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
|
||||
VERBOSE_INFO("Getting current txnID");
|
||||
ByteStream::byte rc = 0;
|
||||
BRM::TxnID txnID;
|
||||
txnID.id= fTxnid.id;
|
||||
txnID.valid= fTxnid.valid;
|
||||
txnID.id = fTxnid.id;
|
||||
txnID.valid = fTxnid.valid;
|
||||
int rc1 = 0;
|
||||
rc1= fDbrm->isReadWrite();
|
||||
rc1 = fDbrm->isReadWrite();
|
||||
|
||||
if (rc1 != 0 )
|
||||
{
|
||||
Message::Args args;
|
||||
@@ -81,7 +82,7 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
|
||||
return result;
|
||||
}
|
||||
|
||||
string stmt = dropTableStmt.fSql + "|" + dropTableStmt.fTableName->fSchema +"|";
|
||||
string stmt = dropTableStmt.fSql + "|" + dropTableStmt.fTableName->fSchema + "|";
|
||||
SQLLogger logger(stmt, fDDLLoggingId, dropTableStmt.fSessionID, txnID.id);
|
||||
|
||||
std::vector <CalpontSystemCatalog::OID> oidList;
|
||||
@@ -91,8 +92,10 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
|
||||
std::string errorMsg;
|
||||
ByteStream bytestream;
|
||||
uint64_t uniqueId = 0;
|
||||
|
||||
//Bug 5070. Added exception handling
|
||||
try {
|
||||
try
|
||||
{
|
||||
uniqueId = fDbrm->getUnique64();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
@@ -142,7 +145,7 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
|
||||
{
|
||||
roPair = systemCatalogPtr->tableRID(tableName);
|
||||
}
|
||||
catch (IDBExcept &ie)
|
||||
catch (IDBExcept& ie)
|
||||
{
|
||||
if (ie.errorCode() == ERR_TABLE_NOT_IN_CATALOG)
|
||||
{
|
||||
@@ -179,12 +182,14 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
|
||||
int i = 0;
|
||||
|
||||
std::vector<uint32_t> pms;
|
||||
for (unsigned i=0; i < moduleIds.size(); i++)
|
||||
|
||||
for (unsigned i = 0; i < moduleIds.size(); i++)
|
||||
{
|
||||
pms.push_back((uint32_t)moduleIds[i]);
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnid, BRM::LOADING );
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -201,8 +206,8 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
|
||||
numTries = waitPeriod * 10;
|
||||
struct timespec rm_ts;
|
||||
|
||||
rm_ts.tv_sec = sleepTime/1000;
|
||||
rm_ts.tv_nsec = sleepTime%1000 *1000000;
|
||||
rm_ts.tv_sec = sleepTime / 1000;
|
||||
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
|
||||
|
||||
for (; i < numTries; i++)
|
||||
{
|
||||
@@ -210,14 +215,18 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
|
||||
Sleep(rm_ts.tv_sec * 1000);
|
||||
#else
|
||||
struct timespec abs_ts;
|
||||
|
||||
do
|
||||
{
|
||||
abs_ts.tv_sec = rm_ts.tv_sec;
|
||||
abs_ts.tv_nsec = rm_ts.tv_nsec;
|
||||
}
|
||||
while(nanosleep(&abs_ts,&rm_ts) < 0);
|
||||
while (nanosleep(&abs_ts, &rm_ts) < 0);
|
||||
|
||||
#endif
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
processID = ::getpid();
|
||||
txnid = txnID.id;
|
||||
sessionId = dropTableStmt.fSessionID;;
|
||||
@@ -232,6 +241,7 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
|
||||
if (tableLockId > 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i >= numTries) //error out
|
||||
{
|
||||
Message::Args args;
|
||||
@@ -240,7 +250,7 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
|
||||
args.add(processName);
|
||||
args.add((uint64_t)processID);
|
||||
args.add(sessionId);
|
||||
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED,args));
|
||||
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,12 +275,13 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
|
||||
Oam oam;
|
||||
|
||||
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
|
||||
for ( unsigned i=0; i < tableColRidList.size(); i++ )
|
||||
for ( unsigned i = 0; i < tableColRidList.size(); i++ )
|
||||
{
|
||||
if ( tableColRidList[i].objnum > 3000 )
|
||||
oidList.push_back( tableColRidList[i].objnum );
|
||||
}
|
||||
for ( unsigned i=0; i < dictOIDList.size(); i++ )
|
||||
|
||||
for ( unsigned i = 0; i < dictOIDList.size(); i++ )
|
||||
{
|
||||
if ( dictOIDList[i].dictOID > 3000 )
|
||||
oidList.push_back( dictOIDList[i].dictOID );
|
||||
@@ -279,7 +290,7 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
|
||||
//get a unique number
|
||||
VERBOSE_INFO("Removing the SYSTABLE meta data");
|
||||
//#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " Removing the SYSTABLEs meta data" << endl;
|
||||
cout << fTxnid.id << " Removing the SYSTABLEs meta data" << endl;
|
||||
//#endif
|
||||
bytestream << (ByteStream::byte)WE_SVR_DELETE_SYSTABLE;
|
||||
bytestream << uniqueId;
|
||||
@@ -294,9 +305,10 @@ cout << fTxnid.id << " Removing the SYSTABLEs meta data" << endl;
|
||||
|
||||
uint16_t dbRoot;
|
||||
rc = fDbrm->getSysCatDBRoot(sysOid, dbRoot);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
result.result =(ResultCode) rc;
|
||||
result.result = (ResultCode) rc;
|
||||
Message::Args args;
|
||||
Message message(9);
|
||||
args.add("Error while calling getSysCatDBRoot");
|
||||
@@ -309,28 +321,35 @@ cout << fTxnid.id << " Removing the SYSTABLEs meta data" << endl;
|
||||
|
||||
boost::shared_ptr<std::map<int, int> > dbRootPMMap = oamcache->getDBRootToPMMap();
|
||||
pmNum = (*dbRootPMMap)[dbRoot];
|
||||
|
||||
try
|
||||
{
|
||||
// #ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " Drop table sending WE_SVR_DELETE_SYSTABLES to pm " << pmNum << endl;
|
||||
cout << fTxnid.id << " Drop table sending WE_SVR_DELETE_SYSTABLES to pm " << pmNum << endl;
|
||||
//#endif
|
||||
//cout << "deleting systable entries with txnid " << txnID.id << endl;
|
||||
fWEClient->write(bytestream, (uint32_t)pmNum);
|
||||
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> rc;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -338,7 +357,7 @@ cout << fTxnid.id << " Drop table sending WE_SVR_DELETE_SYSTABLES to pm " << pmN
|
||||
catch (runtime_error& ex) //write error
|
||||
{
|
||||
// #ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " Drop table got exception" << endl;
|
||||
cout << fTxnid.id << " Drop table got exception" << endl;
|
||||
// #endif
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = ex.what();
|
||||
@@ -347,7 +366,7 @@ cout << fTxnid.id << " Drop table got exception" << endl;
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
//#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " Drop table got unknown exception" << endl;
|
||||
cout << fTxnid.id << " Drop table got unknown exception" << endl;
|
||||
//#endif
|
||||
}
|
||||
|
||||
@@ -380,9 +399,10 @@ cout << fTxnid.id << " Drop table got unknown exception" << endl;
|
||||
//Find out where syscolumn is
|
||||
sysOid = 1021;
|
||||
rc = fDbrm->getSysCatDBRoot(sysOid, dbRoot);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
result.result =(ResultCode) rc;
|
||||
result.result = (ResultCode) rc;
|
||||
Message::Args args;
|
||||
Message message(9);
|
||||
args.add("Error while calling getSysCatDBRoot");
|
||||
@@ -394,27 +414,34 @@ cout << fTxnid.id << " Drop table got unknown exception" << endl;
|
||||
}
|
||||
|
||||
pmNum = (*dbRootPMMap)[dbRoot];
|
||||
|
||||
try
|
||||
{
|
||||
//#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " Drop table sending WE_SVR_DELETE_SYSCOLUMN to pm " << pmNum << endl;
|
||||
cout << fTxnid.id << " Drop table sending WE_SVR_DELETE_SYSCOLUMN to pm " << pmNum << endl;
|
||||
//#endif
|
||||
fWEClient->write(bytestream, (unsigned)pmNum);
|
||||
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> rc;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -422,7 +449,7 @@ cout << fTxnid.id << " Drop table sending WE_SVR_DELETE_SYSCOLUMN to pm " << pmN
|
||||
catch (runtime_error& ex) //write error
|
||||
{
|
||||
//#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " Drop table got exception" << endl;
|
||||
cout << fTxnid.id << " Drop table got exception" << endl;
|
||||
//#endif
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = ex.what();
|
||||
@@ -431,7 +458,7 @@ cout << fTxnid.id << " Drop table got exception" << endl;
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
// #ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " Drop table got unknown exception" << endl;
|
||||
cout << fTxnid.id << " Drop table got unknown exception" << endl;
|
||||
//#endif
|
||||
}
|
||||
|
||||
@@ -453,6 +480,7 @@ cout << fTxnid.id << " Drop table got unknown exception" << endl;
|
||||
}
|
||||
|
||||
rc = commitTransaction(uniqueId, txnID);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
cout << txnID.id << " rolledback transaction " << " and valid is " << txnID.valid << endl;
|
||||
@@ -491,13 +519,16 @@ cout << fTxnid.id << " Drop table got unknown exception" << endl;
|
||||
args.add("Drop table failed due to ");
|
||||
args.add(ex.what());
|
||||
fSessionManager.rolledback(txnID);
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
(void)fDbrm->releaseTableLock(tableLockId);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
args.add(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE));
|
||||
}
|
||||
|
||||
message.format( args );
|
||||
result.message = message;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
@@ -512,20 +543,24 @@ cout << fTxnid.id << " Drop table got unknown exception" << endl;
|
||||
args.add("Drop table failed due to ");
|
||||
args.add(errorMsg);
|
||||
fSessionManager.rolledback(txnID);
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
(void)fDbrm->releaseTableLock(tableLockId);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
args.add(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE));
|
||||
}
|
||||
|
||||
message.format( args );
|
||||
result.message = message;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
return result;
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
(void)fDbrm->releaseTableLock(tableLockId);
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -543,7 +578,8 @@ cout << fTxnid.id << " Drop table got unknown exception" << endl;
|
||||
}
|
||||
|
||||
//Save the oids to a file
|
||||
try {
|
||||
try
|
||||
{
|
||||
createWriteDropLogFile( roPair.objnum, uniqueId, oidList );
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
@@ -559,6 +595,7 @@ cout << fTxnid.id << " Drop table got unknown exception" << endl;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Bug 4208 Drop the PrimProcFDCache before droping the column files
|
||||
// FOr Windows, this ensures (most likely) that the column files have
|
||||
// no open handles to hinder the deletion of the files.
|
||||
@@ -569,34 +606,44 @@ cout << fTxnid.id << " Drop table got unknown exception" << endl;
|
||||
bytestream << (ByteStream::byte)WE_SVR_WRITE_DROPFILES;
|
||||
bytestream << uniqueId;
|
||||
bytestream << (uint32_t) oidList.size();
|
||||
for (unsigned i=0; i < oidList.size(); i++)
|
||||
|
||||
for (unsigned i = 0; i < oidList.size(); i++)
|
||||
{
|
||||
bytestream << (uint32_t) oidList[i];
|
||||
}
|
||||
|
||||
//#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " Drop table removing column files" << endl;
|
||||
cout << fTxnid.id << " Drop table removing column files" << endl;
|
||||
//#endif
|
||||
uint32_t msgRecived = 0;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->write_to_all(bytestream);
|
||||
|
||||
bsIn.reset(new ByteStream());
|
||||
ByteStream::byte tmp8;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = tmp8;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
@@ -633,13 +680,14 @@ cout << fTxnid.id << " Drop table removing column files" << endl;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
return result;
|
||||
}
|
||||
|
||||
//Drop PrimProc FD cache
|
||||
rc = cacheutils::dropPrimProcFdCache();
|
||||
//Flush primProc cache
|
||||
rc = cacheutils::flushOIDsFromCache( oidList );
|
||||
//Delete extents from extent map
|
||||
//#ifdef IDB_DDL_DEBUG
|
||||
cout << fTxnid.id << " Drop table deleteOIDs" << endl;
|
||||
cout << fTxnid.id << " Drop table deleteOIDs" << endl;
|
||||
//#endif
|
||||
rc = fDbrm->deleteOIDs(oidList);
|
||||
|
||||
@@ -693,8 +741,9 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
int rc = 0;
|
||||
rc = fDbrm->isReadWrite();
|
||||
BRM::TxnID txnID;
|
||||
txnID.id= fTxnid.id;
|
||||
txnID.valid= fTxnid.valid;
|
||||
txnID.id = fTxnid.id;
|
||||
txnID.valid = fTxnid.valid;
|
||||
|
||||
if (rc != 0 )
|
||||
{
|
||||
Message::Args args;
|
||||
@@ -708,7 +757,7 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
}
|
||||
|
||||
//@Bug 5765 log the schema.
|
||||
string stmt = truncTableStmt.fSql + "|" + truncTableStmt.fTableName->fSchema +"|";
|
||||
string stmt = truncTableStmt.fSql + "|" + truncTableStmt.fTableName->fSchema + "|";
|
||||
SQLLogger logger(stmt, fDDLLoggingId, truncTableStmt.fSessionID, txnID.id);
|
||||
|
||||
std::vector <CalpontSystemCatalog::OID> columnOidList;
|
||||
@@ -724,8 +773,10 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
systemCatalogPtr->sessionID(truncTableStmt.fSessionID);
|
||||
CalpontSystemCatalog::TableInfo tableInfo;
|
||||
uint64_t uniqueId = 0;
|
||||
|
||||
//Bug 5070. Added exception handling
|
||||
try {
|
||||
try
|
||||
{
|
||||
uniqueId = fDbrm->getUnique64();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
@@ -750,14 +801,16 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
fWEClient->addQueue(uniqueId);
|
||||
int pmNum = 1;
|
||||
boost::shared_ptr<messageqcpp::ByteStream> bsIn;
|
||||
string errorMsg;
|
||||
uint32_t autoIncColOid = 0;
|
||||
uint64_t tableLockId = 0;
|
||||
OamCache * oamcache = OamCache::makeOamCache();
|
||||
OamCache* oamcache = OamCache::makeOamCache();
|
||||
std::vector<int> moduleIds = oamcache->getModuleIds();
|
||||
|
||||
try
|
||||
{
|
||||
//check table lock
|
||||
@@ -771,11 +824,14 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
int i = 0;
|
||||
|
||||
std::vector<uint32_t> pms;
|
||||
for (unsigned i=0; i < moduleIds.size(); i++)
|
||||
|
||||
for (unsigned i = 0; i < moduleIds.size(); i++)
|
||||
{
|
||||
pms.push_back((uint32_t)moduleIds[i]);
|
||||
}
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnid, BRM::LOADING );
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -792,8 +848,8 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
numTries = waitPeriod * 10;
|
||||
struct timespec rm_ts;
|
||||
|
||||
rm_ts.tv_sec = sleepTime/1000;
|
||||
rm_ts.tv_nsec = sleepTime%1000 *1000000;
|
||||
rm_ts.tv_sec = sleepTime / 1000;
|
||||
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
|
||||
|
||||
for (; i < numTries; i++)
|
||||
{
|
||||
@@ -801,14 +857,18 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
Sleep(rm_ts.tv_sec * 1000);
|
||||
#else
|
||||
struct timespec abs_ts;
|
||||
|
||||
do
|
||||
{
|
||||
abs_ts.tv_sec = rm_ts.tv_sec;
|
||||
abs_ts.tv_nsec = rm_ts.tv_nsec;
|
||||
}
|
||||
while(nanosleep(&abs_ts,&rm_ts) < 0);
|
||||
while (nanosleep(&abs_ts, &rm_ts) < 0);
|
||||
|
||||
#endif
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
processID = ::getpid();
|
||||
txnid = txnID.id;
|
||||
sessionId = truncTableStmt.fSessionID;
|
||||
@@ -823,15 +883,17 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
if (tableLockId > 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i >= numTries) //error out
|
||||
{
|
||||
Message::Args args;
|
||||
args.add(processName);
|
||||
args.add((uint64_t)processID);
|
||||
args.add(sessionId);
|
||||
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED,args));
|
||||
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
|
||||
}
|
||||
}
|
||||
|
||||
CalpontSystemCatalog::TableName userTableName;
|
||||
userTableName.schema = truncTableStmt.fTableName->fSchema;
|
||||
userTableName.table = truncTableStmt.fTableName->fName;
|
||||
@@ -839,7 +901,8 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
tableColRidList = systemCatalogPtr->columnRIDs( userTableName );
|
||||
|
||||
dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
|
||||
for ( unsigned i=0; i < tableColRidList.size(); i++ )
|
||||
|
||||
for ( unsigned i = 0; i < tableColRidList.size(); i++ )
|
||||
{
|
||||
if ( tableColRidList[i].objnum > 3000 )
|
||||
{
|
||||
@@ -847,11 +910,13 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
allOidList.push_back( tableColRidList[i].objnum );
|
||||
}
|
||||
}
|
||||
for ( unsigned i=0; i < dictOIDList.size(); i++ )
|
||||
|
||||
for ( unsigned i = 0; i < dictOIDList.size(); i++ )
|
||||
{
|
||||
if ( dictOIDList[i].dictOID > 3000 )
|
||||
allOidList.push_back( dictOIDList[i].dictOID );
|
||||
}
|
||||
|
||||
//Check whether the table has autoincrement column
|
||||
tableInfo = systemCatalogPtr->tableInfo(userTableName);
|
||||
}
|
||||
@@ -865,13 +930,16 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
args.add( ex.what() );
|
||||
args.add("");
|
||||
fSessionManager.rolledback(txnID);
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
(void)fDbrm->releaseTableLock(tableLockId);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
args.add(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE));
|
||||
}
|
||||
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
message.format( args );
|
||||
|
||||
@@ -888,13 +956,16 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
args.add("Truncate table failed: ");
|
||||
args.add( "encountered unkown exception" );
|
||||
args.add("");
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
(void)fDbrm->releaseTableLock(tableLockId);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
args.add(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE));
|
||||
}
|
||||
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
message.format( args );
|
||||
|
||||
@@ -904,7 +975,8 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
}
|
||||
|
||||
//Save the oids to a file
|
||||
try {
|
||||
try
|
||||
{
|
||||
createWriteTruncateTableLogFile( roPair.objnum, uniqueId, allOidList);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
@@ -916,11 +988,14 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
fSessionManager.rolledback(txnID);
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
message.format( args );
|
||||
|
||||
//@bug 4515 Release the tablelock as nothing has done to this table.
|
||||
try {
|
||||
try
|
||||
{
|
||||
(void)fDbrm->releaseTableLock(tableLockId);
|
||||
}
|
||||
catch (std::exception&) {}
|
||||
|
||||
result.result = TRUNC_ERROR;
|
||||
result.message = message;
|
||||
return result;
|
||||
@@ -932,9 +1007,11 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
// MCOL-66 The DBRM can't handle concurrent DDL
|
||||
boost::mutex::scoped_lock lk(dbrmMutex);
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
//Disable extents first
|
||||
int rc1 = fDbrm->markAllPartitionForDeletion( allOidList);
|
||||
|
||||
if (rc1 != 0)
|
||||
{
|
||||
string errMsg;
|
||||
@@ -951,13 +1028,16 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
bytestream << (ByteStream::byte)WE_SVR_WRITE_DROPFILES;
|
||||
bytestream << uniqueId;
|
||||
bytestream << (uint32_t) allOidList.size();
|
||||
for (unsigned i=0; i < allOidList.size(); i++)
|
||||
|
||||
for (unsigned i = 0; i < allOidList.size(); i++)
|
||||
{
|
||||
bytestream << (uint32_t) allOidList[i];
|
||||
}
|
||||
|
||||
uint32_t msgRecived = 0;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->write_to_all(bytestream);
|
||||
|
||||
bsIn.reset(new ByteStream());
|
||||
@@ -966,17 +1046,22 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = tmp8;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
@@ -1018,6 +1103,7 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
deleteLogFile(TRUNCATE_LOG, roPair.objnum, uniqueId);
|
||||
return result;
|
||||
}
|
||||
|
||||
//Drop PrimProc FD cache
|
||||
rc = cacheutils::dropPrimProcFdCache();
|
||||
//Flush primProc cache
|
||||
@@ -1063,8 +1149,10 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
for (unsigned col = 0; col < columnOidList.size(); col++)
|
||||
{
|
||||
colType = systemCatalogPtr->colType(columnOidList[col]);
|
||||
|
||||
if (colType.autoincrement)
|
||||
autoIncColOid = colType.columnOID;
|
||||
|
||||
bytestream << (uint32_t)columnOidList[col];
|
||||
bytestream << (uint8_t) colType.colDataType;
|
||||
bytestream << (uint8_t) false;
|
||||
@@ -1073,7 +1161,7 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
bytestream << (uint32_t) colType.compressionType;
|
||||
}
|
||||
|
||||
for (unsigned col = 0; col <dictOIDList.size(); col++)
|
||||
for (unsigned col = 0; col < dictOIDList.size(); col++)
|
||||
{
|
||||
colType = systemCatalogPtr->colTypeDct(dictOIDList[col].dictOID);
|
||||
bytestream << (uint32_t) dictOIDList[col].dictOID;
|
||||
@@ -1086,57 +1174,71 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
|
||||
|
||||
boost::shared_ptr<std::map<int, int> > dbRootPMMap = oamcache->getDBRootToPMMap();
|
||||
pmNum = (*dbRootPMMap)[useDBRoot];
|
||||
|
||||
try
|
||||
{
|
||||
#ifdef IDB_DDL_DEBUG
|
||||
cout << "Truncate table sending We_SVR_WRITE_CREATETABLEFILES to pm " << pmNum << endl;
|
||||
cout << "Truncate table sending We_SVR_WRITE_CREATETABLEFILES to pm " << pmNum << endl;
|
||||
#endif
|
||||
fWEClient->write(bytestream, pmNum);
|
||||
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = tmp8;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
if (rc != 0)
|
||||
{
|
||||
//drop the newly created files
|
||||
bytestream.restart();
|
||||
bytestream << (ByteStream::byte) WE_SVR_WRITE_DROPFILES;
|
||||
bytestream << uniqueId;
|
||||
bytestream << (uint32_t)(allOidList.size());
|
||||
|
||||
for (unsigned i = 0; i < (allOidList.size()); i++)
|
||||
{
|
||||
bytestream << (uint32_t)(allOidList[i]);
|
||||
}
|
||||
|
||||
fWEClient->write(bytestream, pmNum);
|
||||
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
//rc = tmp8;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Message::Args args;
|
||||
Message message(1);
|
||||
args.add( "Truncate table failed." );
|
||||
@@ -1157,11 +1259,13 @@ cout << "Truncate table sending We_SVR_WRITE_CREATETABLEFILES to pm " << pmNum <
|
||||
errorMsg = "Lost connection to Write Engine Server";
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
catch (std::exception&)
|
||||
{
|
||||
//FIXME: Windows can't delete a file that's still open by another process
|
||||
}
|
||||
|
||||
#else
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
@@ -1178,6 +1282,7 @@ cout << "Truncate table sending We_SVR_WRITE_CREATETABLEFILES to pm " << pmNum <
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
catch ( ... )
|
||||
{
|
||||
@@ -1195,6 +1300,7 @@ cout << "Truncate table sending We_SVR_WRITE_CREATETABLEFILES to pm " << pmNum <
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
rollBackTransaction( uniqueId, txnID, truncTableStmt.fSessionID); //What to do with the error code
|
||||
@@ -1206,11 +1312,14 @@ cout << "Truncate table sending We_SVR_WRITE_CREATETABLEFILES to pm " << pmNum <
|
||||
{
|
||||
//reset nextvalue to 1
|
||||
WE_DDLCommandClient commandClient;
|
||||
rc = commandClient.UpdateSyscolumnNextval(autoIncColOid,1);
|
||||
rc = commandClient.UpdateSyscolumnNextval(autoIncColOid, 1);
|
||||
}
|
||||
|
||||
// Log the DDL statement
|
||||
logDDL(truncTableStmt.fSessionID, txnID.id, truncTableStmt.fSql, truncTableStmt.fOwner);
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
(void)fDbrm->releaseTableLock(tableLockId);
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -1228,11 +1337,14 @@ cout << "Truncate table sending We_SVR_WRITE_CREATETABLEFILES to pm " << pmNum <
|
||||
fSessionManager.rolledback(txnID);
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
}
|
||||
|
||||
//release the transaction
|
||||
fSessionManager.committed(txnID);
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
|
||||
//Remove the log file
|
||||
try {
|
||||
try
|
||||
{
|
||||
deleteLogFile(TRUNCATE_LOG, roPair.objnum, uniqueId);
|
||||
}
|
||||
catch ( ... )
|
||||
|
||||
@@ -34,45 +34,45 @@
|
||||
|
||||
namespace ddlpackageprocessor
|
||||
{
|
||||
/** @brief specialization of a DDLPacakageProcessor
|
||||
/** @brief specialization of a DDLPacakageProcessor
|
||||
* for interacting with the Write Engine to process
|
||||
* drop table ddl statements.
|
||||
*/
|
||||
class DropTableProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
DropTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
|
||||
class DropTableProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
DropTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
|
||||
/** @brief process a drop table statement
|
||||
*
|
||||
* @param dropTableStmt the drop table statement
|
||||
*/
|
||||
EXPORT DDLResult processPackage(ddlpackage::DropTableStatement& dropTableStmt);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
/** @brief specialization of a DDLPacakageProcessor
|
||||
/** @brief specialization of a DDLPacakageProcessor
|
||||
* for interacting with the Write Engine to process
|
||||
* truncate table ddl statements.
|
||||
*/
|
||||
class TruncTableProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
TruncTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
|
||||
class TruncTableProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
TruncTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
|
||||
/** @brief process a truncate table statement
|
||||
*
|
||||
* @param truncTableStmt the truncate table statement
|
||||
*/
|
||||
EXPORT DDLResult processPackage(ddlpackage::TruncTableStatement& truncTableStmt);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace ddlpackageprocessor
|
||||
|
||||
|
||||
@@ -45,11 +45,12 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
|
||||
VERBOSE_INFO(markPartitionStmt);
|
||||
|
||||
BRM::TxnID txnID;
|
||||
txnID.id= fTxnid.id;
|
||||
txnID.valid= fTxnid.valid;
|
||||
txnID.id = fTxnid.id;
|
||||
txnID.valid = fTxnid.valid;
|
||||
|
||||
int rc = 0;
|
||||
rc = fDbrm->isReadWrite();
|
||||
|
||||
if (rc != 0 )
|
||||
{
|
||||
logging::Message::Args args;
|
||||
@@ -61,12 +62,13 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector <CalpontSystemCatalog::OID> oidList;
|
||||
CalpontSystemCatalog::RIDList tableColRidList;
|
||||
CalpontSystemCatalog::DictOIDList dictOIDList;
|
||||
std::string processName("DDLProc");
|
||||
|
||||
string stmt = markPartitionStmt.fSql + "|" + markPartitionStmt.fTableName->fSchema +"|";
|
||||
string stmt = markPartitionStmt.fSql + "|" + markPartitionStmt.fTableName->fSchema + "|";
|
||||
SQLLogger logger(stmt, fDDLLoggingId, markPartitionStmt.fSessionID, txnID.id);
|
||||
|
||||
uint32_t processID = 0;
|
||||
@@ -84,22 +86,26 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
|
||||
tableName.schema = markPartitionStmt.fTableName->fSchema;
|
||||
tableName.table = markPartitionStmt.fTableName->fName;
|
||||
roPair = systemCatalogPtr->tableRID( tableName );
|
||||
|
||||
//@Bug 3054 check for system catalog
|
||||
if ( roPair.objnum < 3000 )
|
||||
{
|
||||
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
processID = ::getpid();
|
||||
oam::OamCache * oamcache = OamCache::makeOamCache();
|
||||
oam::OamCache* oamcache = OamCache::makeOamCache();
|
||||
std::vector<int> pmList = oamcache->getModuleIds();
|
||||
std::vector<uint32_t> pms;
|
||||
for (unsigned i=0; i < pmList.size(); i++)
|
||||
|
||||
for (unsigned i = 0; i < pmList.size(); i++)
|
||||
{
|
||||
pms.push_back((uint32_t)pmList[i]);
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -119,8 +125,8 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
|
||||
numTries = waitPeriod * 10;
|
||||
struct timespec rm_ts;
|
||||
|
||||
rm_ts.tv_sec = sleepTime/1000;
|
||||
rm_ts.tv_nsec = sleepTime%1000 *1000000;
|
||||
rm_ts.tv_sec = sleepTime / 1000;
|
||||
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
|
||||
|
||||
for (; i < numTries; i++)
|
||||
{
|
||||
@@ -128,21 +134,24 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
|
||||
Sleep(rm_ts.tv_sec * 1000);
|
||||
#else
|
||||
struct timespec abs_ts;
|
||||
|
||||
do
|
||||
{
|
||||
abs_ts.tv_sec = rm_ts.tv_sec;
|
||||
abs_ts.tv_nsec = rm_ts.tv_nsec;
|
||||
}
|
||||
while(nanosleep(&abs_ts,&rm_ts) < 0);
|
||||
while (nanosleep(&abs_ts, &rm_ts) < 0);
|
||||
|
||||
#endif
|
||||
// reset
|
||||
sessionID = markPartitionStmt.fSessionID;
|
||||
txnID.id= fTxnid.id;
|
||||
txnID.valid= fTxnid.valid;
|
||||
txnID.id = fTxnid.id;
|
||||
txnID.valid = fTxnid.valid;
|
||||
processID = ::getpid();
|
||||
processName = "DDLProc";
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -164,7 +173,7 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
|
||||
args.add(processName);
|
||||
args.add((uint64_t)processID);
|
||||
args.add((uint64_t)sessionID);
|
||||
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED,args));
|
||||
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
@@ -186,12 +195,13 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
|
||||
dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
|
||||
|
||||
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
|
||||
for ( unsigned i=0; i < tableColRidList.size(); i++ )
|
||||
for ( unsigned i = 0; i < tableColRidList.size(); i++ )
|
||||
{
|
||||
if ( tableColRidList[i].objnum > 3000 )
|
||||
oidList.push_back( tableColRidList[i].objnum );
|
||||
}
|
||||
for ( unsigned i=0; i < dictOIDList.size(); i++ )
|
||||
|
||||
for ( unsigned i = 0; i < dictOIDList.size(); i++ )
|
||||
{
|
||||
if ( dictOIDList[i].dictOID > 3000 )
|
||||
oidList.push_back( dictOIDList[i].dictOID );
|
||||
@@ -200,6 +210,7 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
|
||||
//Remove the partition from extent map
|
||||
string emsg;
|
||||
rc = fDbrm->markPartitionForDeletion( oidList, markPartitionStmt.fPartitions, emsg);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw std::runtime_error(emsg);
|
||||
@@ -221,13 +232,17 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
|
||||
result.result = DROP_ERROR;
|
||||
|
||||
result.message = message;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fDbrm->releaseTableLock(uniqueID);
|
||||
} catch (std::exception&)
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
result.result = DROP_ERROR;
|
||||
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
|
||||
}
|
||||
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
@@ -245,27 +260,36 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
|
||||
|
||||
result.result = DROP_ERROR;
|
||||
result.message = message;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fDbrm->releaseTableLock(uniqueID);
|
||||
} catch (std::exception&)
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
result.result = DROP_ERROR;
|
||||
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
|
||||
}
|
||||
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Log the DDL statement
|
||||
logging::logDDL(markPartitionStmt.fSessionID, 0, markPartitionStmt.fSql, markPartitionStmt.fOwner);
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fDbrm->releaseTableLock(uniqueID);
|
||||
} catch (std::exception&)
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
result.result = DROP_ERROR;
|
||||
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
fSessionManager.committed(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace ddlpackageprocessor
|
||||
class MarkPartitionProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
MarkPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
|
||||
MarkPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
|
||||
/** @brief process a create table statement
|
||||
*
|
||||
* @param createTableStmt the CreateTableStatement
|
||||
|
||||
@@ -63,7 +63,7 @@ class PopulateIndexTest
|
||||
public:
|
||||
|
||||
PopulateIndexTest(DistributedEngineComm* ec) : fEC(ec) { }
|
||||
DistributedEngineComm *fEC;
|
||||
DistributedEngineComm* fEC;
|
||||
|
||||
void test_createindex()
|
||||
{
|
||||
@@ -73,9 +73,10 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
cout << "Parser succeeded." << endl;
|
||||
cout << ptree.fList.size() << " " << "SQL statements" << endl;
|
||||
@@ -85,7 +86,7 @@ public:
|
||||
{
|
||||
CreateIndexProcessor processor;
|
||||
processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
CreateIndexProcessor::DDLResult result;
|
||||
DISPLAY(stmt.fSessionID);
|
||||
|
||||
@@ -93,7 +94,7 @@ public:
|
||||
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@@ -108,9 +109,10 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
cout << ptree.fSqlText << endl;
|
||||
|
||||
try
|
||||
@@ -118,13 +120,13 @@ public:
|
||||
CreateIndexProcessor processor;
|
||||
processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
CreateIndexProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@@ -138,9 +140,10 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
cout << ptree.fSqlText << endl;
|
||||
|
||||
try
|
||||
@@ -148,11 +151,11 @@ public:
|
||||
CreateIndexProcessor processor;
|
||||
processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
CreateIndexProcessor::DDLResult result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@@ -165,22 +168,24 @@ public:
|
||||
cout << "Begining create table test: " << sqlbuf << endl;
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
cout << ptree.fSqlText << endl;
|
||||
|
||||
try
|
||||
{
|
||||
CreateTableProcessor processor;
|
||||
processor.setDebugLevel(CreateTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
CreateTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<CreateTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@@ -194,22 +199,24 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
cout << ptree.fSqlText << endl;
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@@ -225,22 +232,24 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
cout << ptree.fSqlText << endl;
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@@ -251,7 +260,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
int main( int argc, char **argv)
|
||||
int main( int argc, char** argv)
|
||||
{
|
||||
int DoAll = 0;
|
||||
int Do1 = 0;
|
||||
@@ -293,53 +302,54 @@ int main( int argc, char **argv)
|
||||
|
||||
cout << "Driver Test starting with " << argc << " parameters." << endl;
|
||||
|
||||
for (int i=0; i<argc; i++)
|
||||
for (int i = 0; i < argc; i++)
|
||||
{
|
||||
cout << "Arg " << i << ": " << argv[i] << endl;
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
if (strcmp(argv[1],"All") == 0) DoAll = 1;
|
||||
else if (strcmp(argv[1],"t1") == 0) Do1 = 1;
|
||||
else if (strcmp(argv[1],"t2") == 0) Do2 = 1;
|
||||
else if (strcmp(argv[1],"t3") == 0) Do3 = 1;
|
||||
else if (strcmp(argv[1],"t4") == 0) Do4 = 1;
|
||||
else if (strcmp(argv[1],"t5") == 0) Do5 = 1;
|
||||
else if (strcmp(argv[1],"t6") == 0) Do6 = 1;
|
||||
else if (strcmp(argv[1],"t7") == 0) Do7 = 1;
|
||||
else if (strcmp(argv[1],"t8") == 0) Do8 = 1;
|
||||
else if (strcmp(argv[1],"t9") == 0) Do9 = 1;
|
||||
else if (strcmp(argv[1],"t10") == 0) Do10 = 1;
|
||||
else if (strcmp(argv[1],"t11") == 0) Do11= 1;
|
||||
else if (strcmp(argv[1],"t12") == 0) Do12= 1;
|
||||
else if (strcmp(argv[1],"t13") == 0) Do13= 1;
|
||||
else if (strcmp(argv[1],"t14") == 0) Do14= 1;
|
||||
else if (strcmp(argv[1],"t15") == 0) Do15= 1;
|
||||
else if (strcmp(argv[1],"t16") == 0) Do16= 1;
|
||||
else if (strcmp(argv[1],"t17") == 0) Do17= 1;
|
||||
else if (strcmp(argv[1],"t18") == 0) Do18= 1;
|
||||
else if (strcmp(argv[1],"t19") == 0) Do19= 1;
|
||||
else if (strcmp(argv[1],"t20") == 0) Do20= 1;
|
||||
else if (strcmp(argv[1],"t21") == 0) Do21= 1;
|
||||
else if (strcmp(argv[1],"t22") == 0) Do22= 1;
|
||||
else if (strcmp(argv[1],"t23") == 0) Do23= 1;
|
||||
else if (strcmp(argv[1],"t24") == 0) Do24= 1;
|
||||
else if (strcmp(argv[1],"t25") == 0) Do25= 1;
|
||||
else if (strcmp(argv[1],"t26") == 0) Do26= 1;
|
||||
else if (strcmp(argv[1],"t27") == 0) Do27= 1;
|
||||
else if (strcmp(argv[1],"t28") == 0) Do28= 1;
|
||||
else if (strcmp(argv[1],"t29") == 0) Do29= 1;
|
||||
else if (strcmp(argv[1],"t30") == 0) Do30= 1;
|
||||
else if (strcmp(argv[1],"t31") == 0) Do31= 1;
|
||||
else if (strcmp(argv[1],"t32") == 0) Do32= 1;
|
||||
else if (strcmp(argv[1],"t33") == 0) Do33= 1;
|
||||
else if (strcmp(argv[1],"t34") == 0) Do34= 1;
|
||||
else if (strcmp(argv[1],"t35") == 0) Do35= 1;
|
||||
else if (strcmp(argv[1],"t36") == 0) Do35= 1;
|
||||
if (strcmp(argv[1], "All") == 0) DoAll = 1;
|
||||
else if (strcmp(argv[1], "t1") == 0) Do1 = 1;
|
||||
else if (strcmp(argv[1], "t2") == 0) Do2 = 1;
|
||||
else if (strcmp(argv[1], "t3") == 0) Do3 = 1;
|
||||
else if (strcmp(argv[1], "t4") == 0) Do4 = 1;
|
||||
else if (strcmp(argv[1], "t5") == 0) Do5 = 1;
|
||||
else if (strcmp(argv[1], "t6") == 0) Do6 = 1;
|
||||
else if (strcmp(argv[1], "t7") == 0) Do7 = 1;
|
||||
else if (strcmp(argv[1], "t8") == 0) Do8 = 1;
|
||||
else if (strcmp(argv[1], "t9") == 0) Do9 = 1;
|
||||
else if (strcmp(argv[1], "t10") == 0) Do10 = 1;
|
||||
else if (strcmp(argv[1], "t11") == 0) Do11 = 1;
|
||||
else if (strcmp(argv[1], "t12") == 0) Do12 = 1;
|
||||
else if (strcmp(argv[1], "t13") == 0) Do13 = 1;
|
||||
else if (strcmp(argv[1], "t14") == 0) Do14 = 1;
|
||||
else if (strcmp(argv[1], "t15") == 0) Do15 = 1;
|
||||
else if (strcmp(argv[1], "t16") == 0) Do16 = 1;
|
||||
else if (strcmp(argv[1], "t17") == 0) Do17 = 1;
|
||||
else if (strcmp(argv[1], "t18") == 0) Do18 = 1;
|
||||
else if (strcmp(argv[1], "t19") == 0) Do19 = 1;
|
||||
else if (strcmp(argv[1], "t20") == 0) Do20 = 1;
|
||||
else if (strcmp(argv[1], "t21") == 0) Do21 = 1;
|
||||
else if (strcmp(argv[1], "t22") == 0) Do22 = 1;
|
||||
else if (strcmp(argv[1], "t23") == 0) Do23 = 1;
|
||||
else if (strcmp(argv[1], "t24") == 0) Do24 = 1;
|
||||
else if (strcmp(argv[1], "t25") == 0) Do25 = 1;
|
||||
else if (strcmp(argv[1], "t26") == 0) Do26 = 1;
|
||||
else if (strcmp(argv[1], "t27") == 0) Do27 = 1;
|
||||
else if (strcmp(argv[1], "t28") == 0) Do28 = 1;
|
||||
else if (strcmp(argv[1], "t29") == 0) Do29 = 1;
|
||||
else if (strcmp(argv[1], "t30") == 0) Do30 = 1;
|
||||
else if (strcmp(argv[1], "t31") == 0) Do31 = 1;
|
||||
else if (strcmp(argv[1], "t32") == 0) Do32 = 1;
|
||||
else if (strcmp(argv[1], "t33") == 0) Do33 = 1;
|
||||
else if (strcmp(argv[1], "t34") == 0) Do34 = 1;
|
||||
else if (strcmp(argv[1], "t35") == 0) Do35 = 1;
|
||||
else if (strcmp(argv[1], "t36") == 0) Do35 = 1;
|
||||
|
||||
|
||||
}
|
||||
|
||||
PopulateIndexTest pit(DistributedEngineComm::instance());
|
||||
boost::timer theTimer;
|
||||
|
||||
@@ -588,6 +598,7 @@ int main( int argc, char **argv)
|
||||
cout << "t4" << endl;
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
cout << "Create index test took :" << theTimer.elapsed() << " seconds to complete." << endl;
|
||||
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ using namespace WriteEngine;
|
||||
namespace ddlpackageprocessor
|
||||
{
|
||||
|
||||
RestorePartitionProcessor::DDLResult RestorePartitionProcessor::processPackage(ddlpackage::RestorePartitionStatement& restorePartitionStmt)
|
||||
{
|
||||
RestorePartitionProcessor::DDLResult RestorePartitionProcessor::processPackage(ddlpackage::RestorePartitionStatement& restorePartitionStmt)
|
||||
{
|
||||
SUMMARY_INFO("RestorePartitionProcessor::processPackage");
|
||||
|
||||
DDLResult result;
|
||||
@@ -45,11 +45,12 @@ namespace ddlpackageprocessor
|
||||
VERBOSE_INFO(restorePartitionStmt);
|
||||
|
||||
BRM::TxnID txnID;
|
||||
txnID.id= fTxnid.id;
|
||||
txnID.valid= fTxnid.valid;
|
||||
txnID.id = fTxnid.id;
|
||||
txnID.valid = fTxnid.valid;
|
||||
|
||||
int rc = 0;
|
||||
rc = fDbrm->isReadWrite();
|
||||
|
||||
if (rc != 0 )
|
||||
{
|
||||
logging::Message::Args args;
|
||||
@@ -61,12 +62,13 @@ namespace ddlpackageprocessor
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector <CalpontSystemCatalog::OID> oidList;
|
||||
CalpontSystemCatalog::RIDList tableColRidList;
|
||||
CalpontSystemCatalog::DictOIDList dictOIDList;
|
||||
std::string processName("DDLProc");
|
||||
|
||||
string stmt = restorePartitionStmt.fSql + "|" + restorePartitionStmt.fTableName->fSchema +"|";
|
||||
string stmt = restorePartitionStmt.fSql + "|" + restorePartitionStmt.fTableName->fSchema + "|";
|
||||
SQLLogger logger(stmt, fDDLLoggingId, restorePartitionStmt.fSessionID, txnID.id);
|
||||
|
||||
uint32_t processID = 0;
|
||||
@@ -84,22 +86,26 @@ namespace ddlpackageprocessor
|
||||
tableName.schema = restorePartitionStmt.fTableName->fSchema;
|
||||
tableName.table = restorePartitionStmt.fTableName->fName;
|
||||
roPair = systemCatalogPtr->tableRID( tableName );
|
||||
|
||||
//@Bug 3054 check for system catalog
|
||||
if ( roPair.objnum < 3000 )
|
||||
{
|
||||
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
processID = ::getpid();
|
||||
oam::OamCache * oamcache = oam::OamCache::makeOamCache();
|
||||
oam::OamCache* oamcache = oam::OamCache::makeOamCache();
|
||||
std::vector<int> pmList = oamcache->getModuleIds();
|
||||
std::vector<uint32_t> pms;
|
||||
for (unsigned i=0; i < pmList.size(); i++)
|
||||
|
||||
for (unsigned i = 0; i < pmList.size(); i++)
|
||||
{
|
||||
pms.push_back((uint32_t)pmList[i]);
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -119,8 +125,8 @@ namespace ddlpackageprocessor
|
||||
numTries = waitPeriod * 10;
|
||||
struct timespec rm_ts;
|
||||
|
||||
rm_ts.tv_sec = sleepTime/1000;
|
||||
rm_ts.tv_nsec = sleepTime%1000 *1000000;
|
||||
rm_ts.tv_sec = sleepTime / 1000;
|
||||
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
|
||||
|
||||
for (; i < numTries; i++)
|
||||
{
|
||||
@@ -128,21 +134,24 @@ namespace ddlpackageprocessor
|
||||
Sleep(rm_ts.tv_sec * 1000);
|
||||
#else
|
||||
struct timespec abs_ts;
|
||||
|
||||
do
|
||||
{
|
||||
abs_ts.tv_sec = rm_ts.tv_sec;
|
||||
abs_ts.tv_nsec = rm_ts.tv_nsec;
|
||||
}
|
||||
while(nanosleep(&abs_ts,&rm_ts) < 0);
|
||||
while (nanosleep(&abs_ts, &rm_ts) < 0);
|
||||
|
||||
#endif
|
||||
// reset
|
||||
sessionID = restorePartitionStmt.fSessionID;
|
||||
txnID.id= fTxnid.id;
|
||||
txnID.valid= fTxnid.valid;
|
||||
txnID.id = fTxnid.id;
|
||||
txnID.valid = fTxnid.valid;
|
||||
processID = ::getpid();
|
||||
processName = "DDLProc";
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -166,7 +175,7 @@ namespace ddlpackageprocessor
|
||||
args.add(processName);
|
||||
args.add((uint64_t)processID);
|
||||
args.add((uint64_t)sessionID);
|
||||
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED,args));
|
||||
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
@@ -188,12 +197,13 @@ namespace ddlpackageprocessor
|
||||
dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
|
||||
|
||||
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
|
||||
for ( unsigned i=0; i < tableColRidList.size(); i++ )
|
||||
for ( unsigned i = 0; i < tableColRidList.size(); i++ )
|
||||
{
|
||||
if ( tableColRidList[i].objnum > 3000 )
|
||||
oidList.push_back( tableColRidList[i].objnum );
|
||||
}
|
||||
for ( unsigned i=0; i < dictOIDList.size(); i++ )
|
||||
|
||||
for ( unsigned i = 0; i < dictOIDList.size(); i++ )
|
||||
{
|
||||
if ( dictOIDList[i].dictOID > 3000 )
|
||||
oidList.push_back( dictOIDList[i].dictOID );
|
||||
@@ -202,6 +212,7 @@ namespace ddlpackageprocessor
|
||||
//Remove the partition from extent map
|
||||
string emsg;
|
||||
rc = fDbrm->restorePartition( oidList, restorePartitionStmt.fPartitions, emsg);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw std::runtime_error(emsg);
|
||||
@@ -221,13 +232,17 @@ namespace ddlpackageprocessor
|
||||
result.result = DROP_ERROR;
|
||||
|
||||
result.message = message;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fDbrm->releaseTableLock(uniqueID);
|
||||
} catch (std::exception&)
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
result.result = DROP_ERROR;
|
||||
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
|
||||
}
|
||||
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
@@ -245,28 +260,37 @@ namespace ddlpackageprocessor
|
||||
|
||||
result.result = DROP_ERROR;
|
||||
result.message = message;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fDbrm->releaseTableLock(uniqueID);
|
||||
} catch (std::exception&)
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
result.result = DROP_ERROR;
|
||||
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
|
||||
}
|
||||
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Log the DDL statement
|
||||
logging::logDDL(restorePartitionStmt.fSessionID, txnID.id, restorePartitionStmt.fSql, restorePartitionStmt.fOwner);
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fDbrm->releaseTableLock(uniqueID);
|
||||
} catch (std::exception&)
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
result.result = DROP_ERROR;
|
||||
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
|
||||
fSessionManager.rolledback(txnID);
|
||||
return result;
|
||||
}
|
||||
|
||||
fSessionManager.committed(txnID);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,25 +34,25 @@
|
||||
|
||||
namespace ddlpackageprocessor
|
||||
{
|
||||
/** @brief specialization of a DDLPacakageProcessor
|
||||
/** @brief specialization of a DDLPacakageProcessor
|
||||
* for interacting with the Write Engine to process
|
||||
* drop table ddl statements.
|
||||
*/
|
||||
class RestorePartitionProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
RestorePartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
|
||||
class RestorePartitionProcessor : public DDLPackageProcessor
|
||||
{
|
||||
public:
|
||||
RestorePartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
|
||||
/** @brief process a drop table statement
|
||||
*
|
||||
* @param dropTableStmt the drop table statement
|
||||
*/
|
||||
EXPORT DDLResult processPackage(ddlpackage::RestorePartitionStatement& RestorePartitionStmt);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
};
|
||||
};
|
||||
} // namespace ddlpackageprocessor
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
@@ -404,55 +404,59 @@ public:
|
||||
|
||||
};
|
||||
|
||||
void destroySemaphores()
|
||||
{
|
||||
void destroySemaphores()
|
||||
{
|
||||
key_t semkey;
|
||||
int sems, err;
|
||||
|
||||
semkey = 0x2149bdd2;
|
||||
sems = semget(semkey, 2, 0666);
|
||||
|
||||
if (sems != -1)
|
||||
{
|
||||
err = semctl(sems, 0, IPC_RMID);
|
||||
|
||||
if (err == -1)
|
||||
perror("tdriver: semctl");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void destroyShmseg()
|
||||
{
|
||||
void destroyShmseg()
|
||||
{
|
||||
key_t shmkey;
|
||||
int shms, err;
|
||||
|
||||
shmkey = 0x2149bdd2;
|
||||
shms = shmget(shmkey, 0, 0666);
|
||||
|
||||
if (shms != -1)
|
||||
{
|
||||
err = shmctl(shms, IPC_RMID, NULL);
|
||||
|
||||
if (err == -1 && errno != EINVAL)
|
||||
{
|
||||
perror("tdriver: shmctl");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setUp()
|
||||
{
|
||||
void setUp()
|
||||
{
|
||||
destroySemaphores();
|
||||
destroyShmseg();
|
||||
unlink("/tmp/oidbitmap");
|
||||
SystemCatalogBuilder::build();
|
||||
}
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
void tearDown()
|
||||
{
|
||||
destroySemaphores();
|
||||
destroyShmseg();
|
||||
unlink("/tmp/oidbitmap");
|
||||
}
|
||||
}
|
||||
|
||||
class DDLPackageProcessorTest : public CppUnit::TestFixture
|
||||
{
|
||||
@@ -496,26 +500,29 @@ public:
|
||||
std::string sqlbuf = "create table region( r_regionkey integer NOT NULL, r_name char(25) ,r_comment varchar(152));";
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
CreateTableProcessor processor;
|
||||
processor.setDebugLevel(CreateTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
CreateTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<CreateTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
@@ -528,15 +535,17 @@ public:
|
||||
std::string sqlbuf = "create table tpch.part( p_partkey integer NOT NULL ,p_name varchar(55) default 'helloworld', p_mfgr char(6), p_brand char(10) , p_type varchar(25) default 'foobar' , p_size integer , p_container char(10) ,p_retailprice integer , p_comment varchar(23), CONSTRAINT PK_PART PRIMARY KEY(p_partkey) )";
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
CreateTableProcessor processor;
|
||||
processor.setDebugLevel(CreateTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
|
||||
CreateTableStatement& ct = dynamic_cast<CreateTableStatement&>(stmt);
|
||||
|
||||
@@ -548,12 +557,13 @@ public:
|
||||
result = processor.processPackage(ct);
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
@@ -563,27 +573,29 @@ public:
|
||||
std::string sqlbuf = "CREATE INDEX test_idx ON tpch.part (p_size)";
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
CreateIndexProcessor processor;
|
||||
processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
CreateIndexProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
@@ -593,27 +605,29 @@ public:
|
||||
std::string sqlbuf = "CREATE UNIQUE INDEX test_idx ON tpch.part (p_mfgr)";
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
CreateIndexProcessor processor;
|
||||
processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
CreateIndexProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
void test_altertable_addacolumn()
|
||||
@@ -623,26 +637,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
@@ -653,26 +670,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
@@ -683,26 +703,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
void test_altertable_dropacolumn()
|
||||
@@ -712,26 +735,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
@@ -742,26 +768,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
@@ -772,26 +801,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
void test_dropindex()
|
||||
@@ -801,27 +833,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
DropIndexProcessor processor;
|
||||
processor.setDebugLevel(DropIndexProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
DropIndexProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<DropIndexStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
void test_altertable_renamecolumn()
|
||||
@@ -831,26 +865,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
@@ -862,26 +899,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
void test_altertable_addtableconstraint()
|
||||
@@ -891,26 +931,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
@@ -921,26 +964,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
@@ -951,26 +997,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
void test_altertable_dropcolumndefault()
|
||||
@@ -980,26 +1029,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
@@ -1010,26 +1062,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
AlterTableProcessor processor;
|
||||
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
AlterTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
@@ -1040,27 +1095,29 @@ public:
|
||||
|
||||
SqlParser parser;
|
||||
parser.Parse(sqlbuf.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ParseTree &ptree = parser.GetParseTree();
|
||||
const ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
DropTableProcessor processor;
|
||||
processor.setDebugLevel(DropTableProcessor::VERBOSE);
|
||||
|
||||
SqlStatement &stmt = *ptree.fList[0];
|
||||
SqlStatement& stmt = *ptree.fList[0];
|
||||
DropTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<DropTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
tearDown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
@@ -1071,12 +1128,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DDLPackageProcessorTest );
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
|
||||
int main( int argc, char **argv)
|
||||
int main( int argc, char** argv)
|
||||
{
|
||||
// Uncomment before running tests
|
||||
//setUp();
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
runner.addTest( registry.makeTest() );
|
||||
bool wasSuccessful = runner.run( "", false );
|
||||
return (wasSuccessful ? 0 : 1);
|
||||
|
||||
@@ -50,22 +50,25 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackage(dmlpacka
|
||||
std::string defaultSchema /*= ""*/)
|
||||
{
|
||||
CalpontDMLPackage* packagePtr = 0;
|
||||
|
||||
try
|
||||
{
|
||||
std::string dmlStatement = vpackage.get_DMLStatement();
|
||||
//@Bug 2680. DMLParser is not thread safe.
|
||||
boost::mutex::scoped_lock lk(fParserLock);
|
||||
DMLParser parser;
|
||||
|
||||
if (defaultSchema.size())
|
||||
{
|
||||
parser.setDefaultSchema(defaultSchema);
|
||||
}
|
||||
|
||||
parser.parse(dmlStatement.c_str());
|
||||
|
||||
if (parser.good())
|
||||
{
|
||||
|
||||
const ParseTree &ptree = parser.getParseTree();
|
||||
const ParseTree& ptree = parser.getParseTree();
|
||||
SqlStatement* statementPtr = ptree[0];
|
||||
|
||||
int dmlStatementType = statementPtr->getStatementType();
|
||||
@@ -122,32 +125,38 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackage(dmlpacka
|
||||
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromBuffer(dmlpackage::VendorDMLStatement& vpackage)
|
||||
{
|
||||
CalpontDMLPackage* packagePtr = 0;
|
||||
|
||||
try
|
||||
{
|
||||
int dmlStatementType = vpackage.get_DMLStatementType();
|
||||
|
||||
switch (dmlStatementType)
|
||||
{
|
||||
case DML_INSERT:
|
||||
packagePtr = new InsertDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID());
|
||||
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer
|
||||
(),vpackage.get_Columns(), vpackage.get_Rows());
|
||||
(), vpackage.get_Columns(), vpackage.get_Rows());
|
||||
break;
|
||||
|
||||
case DML_UPDATE:
|
||||
packagePtr = new UpdateDMLPackage(vpackage.get_SchemaName(),
|
||||
vpackage.get_TableName(),vpackage.get_DMLStatement(), vpackage.get_SessionID());
|
||||
vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID());
|
||||
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer
|
||||
(),vpackage.get_Columns(), vpackage.get_Rows());
|
||||
(), vpackage.get_Columns(), vpackage.get_Rows());
|
||||
break;
|
||||
|
||||
case DML_DELETE:
|
||||
packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(),
|
||||
vpackage.get_TableName(),vpackage.get_DMLStatement(), vpackage.get_SessionID());
|
||||
vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID());
|
||||
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer
|
||||
(),vpackage.get_Columns(), vpackage.get_Rows());
|
||||
(), vpackage.get_Columns(), vpackage.get_Rows());
|
||||
break;
|
||||
|
||||
case DML_COMMAND:
|
||||
packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID() );
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
cerr << "makeCalpontDMLPackage: invalid statement type" << endl;
|
||||
break;
|
||||
@@ -161,29 +170,35 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromBuffe
|
||||
{
|
||||
cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl;
|
||||
}
|
||||
|
||||
return packagePtr;
|
||||
}
|
||||
|
||||
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromMysqlBuffer(dmlpackage::VendorDMLStatement& vpackage)
|
||||
{
|
||||
CalpontDMLPackage* packagePtr = 0;
|
||||
|
||||
try
|
||||
{
|
||||
int dmlStatementType = vpackage.get_DMLStatementType();
|
||||
|
||||
switch (dmlStatementType)
|
||||
{
|
||||
case DML_INSERT:
|
||||
packagePtr = new InsertDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID());
|
||||
(void)packagePtr->buildFromMysqlBuffer(vpackage.get_ColNames(), vpackage.get_values(), vpackage.get_Columns(), vpackage.get_Rows(), vpackage.get_nullValues());
|
||||
break;
|
||||
|
||||
case DML_COMMAND:
|
||||
packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID() );
|
||||
break;
|
||||
|
||||
case DML_DELETE:
|
||||
packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(),
|
||||
vpackage.get_DMLStatement(), vpackage.get_SessionID() );
|
||||
(void)packagePtr->buildFromMysqlBuffer(vpackage.get_ColNames(), vpackage.get_values(), vpackage.get_Columns(), vpackage.get_Rows(), vpackage.get_nullValues());
|
||||
break;
|
||||
|
||||
default:
|
||||
cerr << "makeCalpontDMLPackage: invalid statement type" << endl;
|
||||
break;
|
||||
@@ -197,6 +212,7 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromMysql
|
||||
{
|
||||
cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl;
|
||||
}
|
||||
|
||||
return packagePtr;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,59 +26,62 @@ using namespace std;
|
||||
|
||||
namespace dmlpackage
|
||||
{
|
||||
/**
|
||||
/**
|
||||
* Constructors/Destructors
|
||||
*/
|
||||
|
||||
CalpontDMLPackage::CalpontDMLPackage()
|
||||
:fPlan(new messageqcpp::ByteStream()), fTable(0), fHasFilter(0), fLogging(true), fIsInsertSelect(false), fIsBatchInsert(false), fIsAutocommitOn(false), fTableOid(0)
|
||||
{
|
||||
CalpontDMLPackage::CalpontDMLPackage()
|
||||
: fPlan(new messageqcpp::ByteStream()), fTable(0), fHasFilter(0), fLogging(true), fIsInsertSelect(false), fIsBatchInsert(false), fIsAutocommitOn(false), fTableOid(0)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
CalpontDMLPackage::CalpontDMLPackage( std::string schemaName, std::string tableName,
|
||||
CalpontDMLPackage::CalpontDMLPackage( std::string schemaName, std::string tableName,
|
||||
std::string dmlStatement, int sessionID )
|
||||
:fSchemaName(schemaName), fTableName( tableName ), fDMLStatement( dmlStatement ),
|
||||
: fSchemaName(schemaName), fTableName( tableName ), fDMLStatement( dmlStatement ),
|
||||
fSessionID(sessionID), fPlan(new messageqcpp::ByteStream()), fTable(0), fHasFilter(false), fLogging(true), fIsInsertSelect(false),
|
||||
fIsBatchInsert(false), fIsAutocommitOn(false), fIsWarnToError(false), fTableOid(0)
|
||||
{
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
CalpontDMLPackage::~CalpontDMLPackage()
|
||||
{
|
||||
CalpontDMLPackage::~CalpontDMLPackage()
|
||||
{
|
||||
if ( 0 != fTable )
|
||||
delete fTable;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* strip off whitespaces from a string
|
||||
*/
|
||||
std::string CalpontDMLPackage::StripLeadingWhitespace( std::string value )
|
||||
std::string CalpontDMLPackage::StripLeadingWhitespace( std::string value )
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
string::size_type pos = value.find (' ',0);
|
||||
string::size_type pos = value.find (' ', 0);
|
||||
|
||||
if (pos == 0)
|
||||
{
|
||||
value = value.substr (pos+1,10000);
|
||||
value = value.substr (pos + 1, 10000);
|
||||
}
|
||||
else
|
||||
{ // no more whitespace
|
||||
{
|
||||
// no more whitespace
|
||||
break;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void CalpontDMLPackage::initializeTable()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
void CalpontDMLPackage::initializeTable()
|
||||
{
|
||||
if (0 == fTable)
|
||||
{
|
||||
fTable = new DMLTable();
|
||||
fTable->set_SchemaName(fSchemaName);
|
||||
fTable->set_TableName(fTableName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dmlpackage
|
||||
|
||||
@@ -36,13 +36,13 @@
|
||||
|
||||
namespace dmlpackage
|
||||
{
|
||||
/** @brief abstract class that defines the general interface and
|
||||
/** @brief abstract class that defines the general interface and
|
||||
* implemetation of a CalpontDMLPackage
|
||||
*/
|
||||
class CalpontDMLPackage
|
||||
{
|
||||
class CalpontDMLPackage
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
/** @brief ctor
|
||||
*/
|
||||
CalpontDMLPackage();
|
||||
@@ -98,57 +98,90 @@ namespace dmlpackage
|
||||
|
||||
/** @brief get the table object
|
||||
*/
|
||||
DMLTable* get_Table() { return fTable; }
|
||||
DMLTable* get_Table()
|
||||
{
|
||||
return fTable;
|
||||
}
|
||||
|
||||
/** @brief set the DML statement (the parsed statement)
|
||||
*
|
||||
* @param statement the dml statement to set
|
||||
*/
|
||||
void set_DMLStatement( const std::string& statement ) { fDMLStatement = statement; }
|
||||
void set_DMLStatement( const std::string& statement )
|
||||
{
|
||||
fDMLStatement = statement;
|
||||
}
|
||||
|
||||
/** @brief get the DML statement (the parsed statement)
|
||||
*/
|
||||
const std::string get_DMLStatement() const { return fDMLStatement; }
|
||||
const std::string get_DMLStatement() const
|
||||
{
|
||||
return fDMLStatement;
|
||||
}
|
||||
|
||||
/** @brief set the SQL statement (the original SQL statement)
|
||||
*
|
||||
* @param statement the SQL statement to set (the original SQL statement with quotes)
|
||||
*/
|
||||
void set_SQLStatement( const std::string& statement ) { fSQLStatement = statement; }
|
||||
void set_SQLStatement( const std::string& statement )
|
||||
{
|
||||
fSQLStatement = statement;
|
||||
}
|
||||
|
||||
/** @brief get the SQL statement (the original SQL statement)
|
||||
*/
|
||||
const std::string get_SQLStatement() const { return fSQLStatement; }
|
||||
const std::string get_SQLStatement() const
|
||||
{
|
||||
return fSQLStatement;
|
||||
}
|
||||
|
||||
/** @brief get the logging flag
|
||||
*/
|
||||
const bool get_Logging() const { return fLogging; }
|
||||
const bool get_Logging() const
|
||||
{
|
||||
return fLogging;
|
||||
}
|
||||
|
||||
/** @brief set the logging flag
|
||||
*
|
||||
* @param logging the logging flag to set
|
||||
*/
|
||||
void set_Logging( bool logging ) { fLogging = logging; }
|
||||
void set_Logging( bool logging )
|
||||
{
|
||||
fLogging = logging;
|
||||
}
|
||||
|
||||
/** @brief get the logending flag
|
||||
*/
|
||||
const bool get_Logending() const { return fLogending; }
|
||||
const bool get_Logending() const
|
||||
{
|
||||
return fLogending;
|
||||
}
|
||||
|
||||
/** @brief set the logending flag
|
||||
*
|
||||
* @param logending the logending flag to set
|
||||
*/
|
||||
void set_Logending( bool logending ) { fLogending = logending; }
|
||||
void set_Logending( bool logending )
|
||||
{
|
||||
fLogending = logending;
|
||||
}
|
||||
|
||||
/** @brief get the isFromCol flag
|
||||
*/
|
||||
const bool get_IsFromCol() const { return fIsFromCol; }
|
||||
const bool get_IsFromCol() const
|
||||
{
|
||||
return fIsFromCol;
|
||||
}
|
||||
|
||||
/** @brief set the update column from column flag
|
||||
*
|
||||
* @param logging the logging flag to set
|
||||
*/
|
||||
void set_IsFromCol ( bool isFromCol ) { fIsFromCol = isFromCol; }
|
||||
void set_IsFromCol ( bool isFromCol )
|
||||
{
|
||||
fIsFromCol = isFromCol;
|
||||
}
|
||||
/** @brief set the Table name
|
||||
*
|
||||
* @param tableName the name to set
|
||||
@@ -156,13 +189,17 @@ namespace dmlpackage
|
||||
void set_TableName( std::string& tableName )
|
||||
{
|
||||
fTableName = tableName;
|
||||
if(fTable != 0)
|
||||
|
||||
if (fTable != 0)
|
||||
fTable->set_TableName(tableName);
|
||||
}
|
||||
|
||||
/** @brief get the Table name
|
||||
*/
|
||||
const std::string get_TableName() const { return fTableName; }
|
||||
const std::string get_TableName() const
|
||||
{
|
||||
return fTableName;
|
||||
}
|
||||
|
||||
/** @brief set the Schema name
|
||||
*
|
||||
@@ -171,45 +208,76 @@ namespace dmlpackage
|
||||
void set_SchemaName( std::string& schemaName )
|
||||
{
|
||||
fSchemaName = schemaName;
|
||||
if(fTable != 0)
|
||||
|
||||
if (fTable != 0)
|
||||
fTable->set_SchemaName(schemaName);
|
||||
}
|
||||
|
||||
/** @brief get the Schema name
|
||||
*/
|
||||
const std::string get_SchemaName() const { return fSchemaName; }
|
||||
const std::string get_SchemaName() const
|
||||
{
|
||||
return fSchemaName;
|
||||
}
|
||||
|
||||
/** @brief does this dml statement have a filter
|
||||
*/
|
||||
bool HasFilter() const { return fHasFilter; }
|
||||
void HasFilter( bool hasFilter) { fHasFilter = hasFilter; }
|
||||
bool HasFilter() const
|
||||
{
|
||||
return fHasFilter;
|
||||
}
|
||||
void HasFilter( bool hasFilter)
|
||||
{
|
||||
fHasFilter = hasFilter;
|
||||
}
|
||||
|
||||
/** @brief get the filter statement
|
||||
*/
|
||||
const std::string get_QueryString() const { return fQueryString; }
|
||||
const std::string get_QueryString() const
|
||||
{
|
||||
return fQueryString;
|
||||
}
|
||||
|
||||
/** @brief set the sessionID associated with this package
|
||||
*/
|
||||
void set_SessionID( int sessionID ) { fSessionID = sessionID; }
|
||||
void set_SessionID( int sessionID )
|
||||
{
|
||||
fSessionID = sessionID;
|
||||
}
|
||||
|
||||
/** @brief get the sessionID associated with this package
|
||||
*/
|
||||
int get_SessionID() const { return fSessionID; }
|
||||
int get_SessionID() const
|
||||
{
|
||||
return fSessionID;
|
||||
}
|
||||
|
||||
/** @brief set the transaction ID associated with this package
|
||||
*/
|
||||
void set_TxnID( execplan::CalpontSystemCatalog::SCN txnID ) { fTxnId = txnID; }
|
||||
void set_TxnID( execplan::CalpontSystemCatalog::SCN txnID )
|
||||
{
|
||||
fTxnId = txnID;
|
||||
}
|
||||
|
||||
/** @brief get the transaction ID associated with this package
|
||||
*/
|
||||
execplan::CalpontSystemCatalog::SCN get_TxnID() const { return fTxnId; }
|
||||
execplan::CalpontSystemCatalog::SCN get_TxnID() const
|
||||
{
|
||||
return fTxnId;
|
||||
}
|
||||
/** @brief set the chunkmanager associated with this package
|
||||
*/
|
||||
void set_ChunkManager( WriteEngine::ChunkManager* cm ) { fCM = cm; }
|
||||
void set_ChunkManager( WriteEngine::ChunkManager* cm )
|
||||
{
|
||||
fCM = cm;
|
||||
}
|
||||
|
||||
/** @brief get the chunkmanager associated with this package
|
||||
*/
|
||||
WriteEngine::ChunkManager* get_ChunkManager() const { return fCM; }
|
||||
WriteEngine::ChunkManager* get_ChunkManager() const
|
||||
{
|
||||
return fCM;
|
||||
}
|
||||
|
||||
/** @brief get the ExecutionPlan associated with this package
|
||||
*/
|
||||
@@ -218,25 +286,61 @@ namespace dmlpackage
|
||||
return fPlan;
|
||||
}
|
||||
|
||||
bool get_isInsertSelect() { return fIsInsertSelect; }
|
||||
void set_isInsertSelect( const bool isInsertSelect ) { fIsInsertSelect = isInsertSelect; }
|
||||
bool get_isInsertSelect()
|
||||
{
|
||||
return fIsInsertSelect;
|
||||
}
|
||||
void set_isInsertSelect( const bool isInsertSelect )
|
||||
{
|
||||
fIsInsertSelect = isInsertSelect;
|
||||
}
|
||||
|
||||
bool get_isBatchInsert() { return fIsBatchInsert; }
|
||||
void set_isBatchInsert( const bool isBatchInsert ) { fIsBatchInsert = isBatchInsert; }
|
||||
bool get_isBatchInsert()
|
||||
{
|
||||
return fIsBatchInsert;
|
||||
}
|
||||
void set_isBatchInsert( const bool isBatchInsert )
|
||||
{
|
||||
fIsBatchInsert = isBatchInsert;
|
||||
}
|
||||
|
||||
bool get_isAutocommitOn() { return fIsAutocommitOn; }
|
||||
void set_isAutocommitOn( const bool isAutocommitOn ) { fIsAutocommitOn = isAutocommitOn; }
|
||||
bool get_isAutocommitOn()
|
||||
{
|
||||
return fIsAutocommitOn;
|
||||
}
|
||||
void set_isAutocommitOn( const bool isAutocommitOn )
|
||||
{
|
||||
fIsAutocommitOn = isAutocommitOn;
|
||||
}
|
||||
|
||||
bool get_isWarnToError() { return fIsWarnToError; }
|
||||
void set_isWarnToError( const bool isWarnToError ) { fIsWarnToError = isWarnToError; }
|
||||
bool get_isWarnToError()
|
||||
{
|
||||
return fIsWarnToError;
|
||||
}
|
||||
void set_isWarnToError( const bool isWarnToError )
|
||||
{
|
||||
fIsWarnToError = isWarnToError;
|
||||
}
|
||||
|
||||
uint32_t getTableOid() { return fTableOid; }
|
||||
void setTableOid( const uint32_t tableOid ) { fTableOid = tableOid; }
|
||||
uint32_t getTableOid()
|
||||
{
|
||||
return fTableOid;
|
||||
}
|
||||
void setTableOid( const uint32_t tableOid )
|
||||
{
|
||||
fTableOid = tableOid;
|
||||
}
|
||||
|
||||
void uuid(const boost::uuids::uuid& uuid) { fUuid = uuid; }
|
||||
const boost::uuids::uuid& uuid() const { return fUuid; }
|
||||
void uuid(const boost::uuids::uuid& uuid)
|
||||
{
|
||||
fUuid = uuid;
|
||||
}
|
||||
const boost::uuids::uuid& uuid() const
|
||||
{
|
||||
return fUuid;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
void initializeTable();
|
||||
|
||||
@@ -249,7 +353,7 @@ namespace dmlpackage
|
||||
boost::uuids::uuid fUuid;
|
||||
execplan::CalpontSystemCatalog::SCN fTxnId;
|
||||
boost::shared_ptr<messageqcpp::ByteStream> fPlan;
|
||||
DMLTable *fTable;
|
||||
DMLTable* fTable;
|
||||
bool fHasFilter;
|
||||
bool fLogging;
|
||||
bool fLogending;
|
||||
@@ -261,6 +365,6 @@ namespace dmlpackage
|
||||
bool fIsWarnToError;
|
||||
uint32_t fTableOid;
|
||||
WriteEngine::ChunkManager* fCM;
|
||||
};
|
||||
};
|
||||
}
|
||||
#endif //CALPONTDMLPACKAGE_H
|
||||
|
||||
@@ -32,18 +32,18 @@ using namespace std;
|
||||
namespace dmlpackage
|
||||
{
|
||||
|
||||
CommandDMLPackage::CommandDMLPackage()
|
||||
{}
|
||||
CommandDMLPackage::CommandDMLPackage()
|
||||
{}
|
||||
|
||||
CommandDMLPackage::CommandDMLPackage( std::string dmlStatement, int sessionID)
|
||||
:CalpontDMLPackage( "", "", dmlStatement, sessionID)
|
||||
{}
|
||||
CommandDMLPackage::CommandDMLPackage( std::string dmlStatement, int sessionID)
|
||||
: CalpontDMLPackage( "", "", dmlStatement, sessionID)
|
||||
{}
|
||||
|
||||
CommandDMLPackage::~CommandDMLPackage()
|
||||
{}
|
||||
CommandDMLPackage::~CommandDMLPackage()
|
||||
{}
|
||||
|
||||
int CommandDMLPackage::write(messageqcpp::ByteStream& bytestream)
|
||||
{
|
||||
int CommandDMLPackage::write(messageqcpp::ByteStream& bytestream)
|
||||
{
|
||||
int retval = 1;
|
||||
|
||||
messageqcpp::ByteStream::byte package_type = DML_COMMAND;
|
||||
@@ -63,10 +63,10 @@ namespace dmlpackage
|
||||
bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsAutocommitOn);
|
||||
bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsBatchInsert);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
int CommandDMLPackage::read(messageqcpp::ByteStream& bytestream)
|
||||
{
|
||||
int CommandDMLPackage::read(messageqcpp::ByteStream& bytestream)
|
||||
{
|
||||
int retval = 1;
|
||||
|
||||
messageqcpp::ByteStream::quadbyte session_id;
|
||||
@@ -85,14 +85,14 @@ namespace dmlpackage
|
||||
bytestream >> reinterpret_cast< messageqcpp::ByteStream::byte&>(fIsAutocommitOn);
|
||||
bytestream >> reinterpret_cast< messageqcpp::ByteStream::byte&>(fIsBatchInsert);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
int CommandDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
|
||||
{
|
||||
int CommandDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
|
||||
{
|
||||
CommandSqlStatement& cmdStmt = dynamic_cast<CommandSqlStatement&>(sqlStatement);
|
||||
fDMLStatement = cmdStmt.fCommandText;
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dmlpackage
|
||||
|
||||
@@ -36,13 +36,13 @@
|
||||
|
||||
namespace dmlpackage
|
||||
{
|
||||
/** @brief concrete implementation of a CalpontDMLPackage
|
||||
/** @brief concrete implementation of a CalpontDMLPackage
|
||||
* Specifically for representing COMMAND DML Statements
|
||||
*/
|
||||
class CommandDMLPackage : public CalpontDMLPackage
|
||||
{
|
||||
class CommandDMLPackage : public CalpontDMLPackage
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
/** @brief ctor
|
||||
*/
|
||||
EXPORT CommandDMLPackage();
|
||||
@@ -72,7 +72,7 @@ namespace dmlpackage
|
||||
* @param columns the number of columns in the buffer
|
||||
* @param rows the number of rows in the buffer
|
||||
*/
|
||||
inline int buildFromBuffer(std::string& buffer, int columns=0, int rows=0)
|
||||
inline int buildFromBuffer(std::string& buffer, int columns = 0, int rows = 0)
|
||||
{
|
||||
return 1;
|
||||
};
|
||||
@@ -91,11 +91,11 @@ namespace dmlpackage
|
||||
return 1;
|
||||
};
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ DeleteDMLPackage::DeleteDMLPackage()
|
||||
|
||||
DeleteDMLPackage::DeleteDMLPackage(std::string schemaName, std::string tableName,
|
||||
std::string dmlStatement, int sessionID)
|
||||
:CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID )
|
||||
: CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID )
|
||||
{}
|
||||
|
||||
DeleteDMLPackage::~DeleteDMLPackage()
|
||||
@@ -58,7 +58,7 @@ int DeleteDMLPackage::write(messageqcpp::ByteStream& bytestream)
|
||||
fHasFilter = true;
|
||||
else
|
||||
fHasFilter = false;
|
||||
*/
|
||||
*/
|
||||
messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter;
|
||||
bytestream << hasFilter;
|
||||
|
||||
@@ -67,11 +67,13 @@ int DeleteDMLPackage::write(messageqcpp::ByteStream& bytestream)
|
||||
bytestream << fDMLStatement;
|
||||
bytestream << fSQLStatement;
|
||||
bytestream << fSchemaName;
|
||||
|
||||
if (fTable != 0)
|
||||
{
|
||||
retval = fTable->write(bytestream);
|
||||
}
|
||||
if(fHasFilter)
|
||||
|
||||
if (fHasFilter)
|
||||
{
|
||||
bytestream += *(fPlan.get());
|
||||
}
|
||||
@@ -103,7 +105,8 @@ int DeleteDMLPackage::read(messageqcpp::ByteStream& bytestream)
|
||||
|
||||
fTable = new DMLTable();
|
||||
retval = fTable->read(bytestream);
|
||||
if(fHasFilter)
|
||||
|
||||
if (fHasFilter)
|
||||
{
|
||||
fPlan.reset(new messageqcpp::ByteStream(bytestream));
|
||||
}
|
||||
@@ -124,6 +127,7 @@ int DeleteDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
|
||||
fHasFilter = true;
|
||||
fQueryString = deleteStmt.getQueryString();
|
||||
}
|
||||
|
||||
// else all rows are deleted
|
||||
|
||||
return retval;
|
||||
@@ -146,6 +150,7 @@ int DeleteDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
boost::char_separator<char> sep(":");
|
||||
tokenizer tokens(buffer, sep);
|
||||
|
||||
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
|
||||
{
|
||||
dataList.push_back(StripLeadingWhitespace(*tok_iter));
|
||||
@@ -153,7 +158,8 @@ int DeleteDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
|
||||
}
|
||||
|
||||
int n = 0;
|
||||
for (int i=0; i < rows; i++)
|
||||
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
//get a new row
|
||||
Row aRow;
|
||||
@@ -195,7 +201,7 @@ int DeleteDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
|
||||
|
||||
initializeTable();
|
||||
//The row already built from MySql parser.
|
||||
/* Row *aRowPtr = new Row();
|
||||
/* Row *aRowPtr = new Row();
|
||||
std::string colName;
|
||||
std::vector<std::string> colValList;
|
||||
for (int j = 0; j < columns; j++)
|
||||
|
||||
@@ -36,13 +36,13 @@
|
||||
|
||||
namespace dmlpackage
|
||||
{
|
||||
/** @brief concrete implementation of a CalpontDMLPackage
|
||||
/** @brief concrete implementation of a CalpontDMLPackage
|
||||
* Specifically for representing DELETE DML Statements
|
||||
*/
|
||||
class DeleteDMLPackage : public CalpontDMLPackage
|
||||
{
|
||||
class DeleteDMLPackage : public CalpontDMLPackage
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/** @brief ctor
|
||||
*/
|
||||
@@ -94,11 +94,11 @@ namespace dmlpackage
|
||||
*/
|
||||
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,9 +36,10 @@
|
||||
/* Tokens. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
/* Put the tokens into the symbol table, so that GDB and other debuggers
|
||||
/* Put the tokens into the symbol table, so that GDB and other debuggers
|
||||
know about them. */
|
||||
enum yytokentype {
|
||||
enum yytokentype
|
||||
{
|
||||
NAME = 258,
|
||||
STRING = 259,
|
||||
INTNUM = 260,
|
||||
@@ -127,7 +128,7 @@
|
||||
WHERE = 343,
|
||||
WITH = 344,
|
||||
WORK = 345
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -139,10 +140,10 @@ typedef union YYSTYPE
|
||||
|
||||
int intval;
|
||||
double floatval;
|
||||
char *strval;
|
||||
char* strval;
|
||||
int subtok;
|
||||
dmlpackage::SqlStatementList *sqlStmtList;
|
||||
dmlpackage::SqlStatement *sqlStmt;
|
||||
dmlpackage::SqlStatementList* sqlStmtList;
|
||||
dmlpackage::SqlStatement* sqlStmt;
|
||||
dmlpackage::TableName* tblName;
|
||||
dmlpackage::ColumnNameList* colNameList;
|
||||
dmlpackage::ValuesOrQuery* valsOrQuery;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -40,10 +40,12 @@ DMLColumn::DMLColumn(std::string name, std::string value, bool isFromCol, uint32
|
||||
{
|
||||
fName = name;
|
||||
fData = value;
|
||||
|
||||
if (( strcasecmp(value.c_str(), "NULL") == 0) || (value.length() == 0) )
|
||||
{
|
||||
isNULL = true;
|
||||
}
|
||||
|
||||
fisNULL = isNULL;
|
||||
fIsFromCol = isFromCol;
|
||||
fFuncScale = funcScale;
|
||||
@@ -69,6 +71,7 @@ int DMLColumn::read(messageqcpp::ByteStream& bytestream)
|
||||
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fisNULL);
|
||||
uint32_t vectorSize;
|
||||
bytestream >> vectorSize;
|
||||
|
||||
if (vectorSize > 0 )
|
||||
{
|
||||
for ( uint32_t i = 0; i < vectorSize; i++ )
|
||||
@@ -85,8 +88,9 @@ int DMLColumn::read(messageqcpp::ByteStream& bytestream)
|
||||
else
|
||||
bytestream >> fData; //deprecated.
|
||||
|
||||
if ( (fColValuesList.size() <1) && (fColValuesList.size() > 0) ) //deprecated.
|
||||
fData =fColValuesList[0] ; //deprecated.
|
||||
if ( (fColValuesList.size() < 1) && (fColValuesList.size() > 0) ) //deprecated.
|
||||
fData = fColValuesList[0] ; //deprecated.
|
||||
|
||||
//bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fisNULL);
|
||||
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsFromCol);
|
||||
bytestream >> (uint32_t&) fFuncScale;
|
||||
@@ -100,6 +104,7 @@ int DMLColumn::write(messageqcpp::ByteStream& bytestream)
|
||||
bytestream << static_cast<uint8_t>(fisNULL);
|
||||
uint32_t vectorSize = fColValuesList.size();
|
||||
bytestream << vectorSize;
|
||||
|
||||
if (vectorSize > 0 )
|
||||
{
|
||||
for ( uint32_t i = 0; i < vectorSize; i++ )
|
||||
@@ -110,9 +115,10 @@ int DMLColumn::write(messageqcpp::ByteStream& bytestream)
|
||||
}
|
||||
else
|
||||
bytestream << fData; //deprecated.
|
||||
|
||||
//bytestream << static_cast<uint8_t>(fisNULL);
|
||||
bytestream << static_cast<uint8_t>(fIsFromCol);
|
||||
bytestream <<(uint32_t)fFuncScale;
|
||||
bytestream << (uint32_t)fFuncScale;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,12 +52,12 @@ public:
|
||||
/** @brief ctor
|
||||
*/
|
||||
|
||||
EXPORT DMLColumn(std::string name, std::string value, bool isFromCol = false, uint32_t funcScale=0, bool isNULL=false);
|
||||
EXPORT DMLColumn(std::string name, std::string value, bool isFromCol = false, uint32_t funcScale = 0, bool isNULL = false);
|
||||
/** @brief new ctor
|
||||
* isNUll is currently not in use. It supposed to indicate whether each value is null or not.
|
||||
*/
|
||||
|
||||
EXPORT DMLColumn(std::string name, std::vector<std::string>& valueList, bool isFromCol = false, uint32_t funcScale=0, bool isNULL=false );
|
||||
EXPORT DMLColumn(std::string name, std::vector<std::string>& valueList, bool isFromCol = false, uint32_t funcScale = 0, bool isNULL = false );
|
||||
|
||||
/** @brief dtor
|
||||
*/
|
||||
@@ -77,45 +77,75 @@ public:
|
||||
|
||||
/** @brief get the data for the column
|
||||
*/
|
||||
const std::string get_Data() const { return fData; }
|
||||
const std::string get_Data() const
|
||||
{
|
||||
return fData;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::string>& get_DataVector() const { return fColValuesList; }
|
||||
const std::vector<std::string>& get_DataVector() const
|
||||
{
|
||||
return fColValuesList;
|
||||
}
|
||||
|
||||
/** @brief get the data for the column
|
||||
*/
|
||||
const bool get_isnull() const { return fisNULL; }
|
||||
const bool get_isnull() const
|
||||
{
|
||||
return fisNULL;
|
||||
}
|
||||
/** @brief get the fIsFromCol data for the column
|
||||
*/
|
||||
const bool get_isFromCol() const { return fIsFromCol; }
|
||||
const bool get_isFromCol() const
|
||||
{
|
||||
return fIsFromCol;
|
||||
}
|
||||
/** @brief get the fFuncScale data for the column
|
||||
*/
|
||||
const uint32_t get_funcScale() const { return fFuncScale; }
|
||||
const uint32_t get_funcScale() const
|
||||
{
|
||||
return fFuncScale;
|
||||
}
|
||||
/** @brief get the column name
|
||||
*/
|
||||
const std::string get_Name() const { return fName; }
|
||||
const std::string get_Name() const
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
/** @brief set the column name
|
||||
*/
|
||||
EXPORT void set_Name( std::string name)
|
||||
{ boost::algorithm::to_lower(name);
|
||||
fName = name; }
|
||||
{
|
||||
boost::algorithm::to_lower(name);
|
||||
fName = name;
|
||||
}
|
||||
/** @brief set the NULL flag
|
||||
*/
|
||||
void set_isnull( bool isNULL)
|
||||
{ fisNULL = isNULL; }
|
||||
{
|
||||
fisNULL = isNULL;
|
||||
}
|
||||
/** @brief set the fIsFromCol flag
|
||||
*/
|
||||
void set_isFromCol( bool isFromCol)
|
||||
{ fIsFromCol = isFromCol; }
|
||||
{
|
||||
fIsFromCol = isFromCol;
|
||||
}
|
||||
/** @brief set the fFuncScale
|
||||
*/
|
||||
void set_funcScale( uint32_t funcScale)
|
||||
{ fFuncScale = funcScale; }
|
||||
{
|
||||
fFuncScale = funcScale;
|
||||
}
|
||||
void set_Data ( std::string data)
|
||||
{ fData = data; }
|
||||
{
|
||||
fData = data;
|
||||
}
|
||||
|
||||
void set_DataVector ( std::vector<std::string>& dataVec)
|
||||
{ fColValuesList = dataVec; }
|
||||
{
|
||||
fColValuesList = dataVec;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
|
||||
#include "dmlobject.h"
|
||||
|
||||
namespace dmlpackage {
|
||||
namespace dmlpackage
|
||||
{
|
||||
|
||||
DMLObject::DMLObject()
|
||||
{
|
||||
|
||||
@@ -29,10 +29,10 @@
|
||||
namespace dmlpackage
|
||||
{
|
||||
|
||||
#define DML_DEBUG 0 // debug flag 0 for off, 1 for on
|
||||
#define DML_DEBUG 0 // debug flag 0 for off, 1 for on
|
||||
|
||||
const std::string nullValue = "nvl";
|
||||
//const size_t maxThreads = 100;
|
||||
//const size_t queueSize = 200;
|
||||
const std::string nullValue = "nvl";
|
||||
//const size_t maxThreads = 100;
|
||||
//const size_t queueSize = 200;
|
||||
} // namespace dmlpackage
|
||||
#endif //DMLPACKAGE_H
|
||||
|
||||
@@ -44,97 +44,105 @@ int dmlparse(void* yyscanner);
|
||||
|
||||
namespace dmlpackage
|
||||
{
|
||||
using namespace std;
|
||||
using namespace std;
|
||||
|
||||
void scanner_finish(void* yyscanner);
|
||||
void scanner_init(const char *str, void* yyscanner);
|
||||
void grammar_init(dmlpackage::ParseTree* _ptree, bool);
|
||||
valbuf_t get_valbuffer(void);
|
||||
void scanner_finish(void* yyscanner);
|
||||
void scanner_init(const char* str, void* yyscanner);
|
||||
void grammar_init(dmlpackage::ParseTree* _ptree, bool);
|
||||
valbuf_t get_valbuffer(void);
|
||||
|
||||
void free_copybuffer();
|
||||
void set_defaultSchema(std::string schema);
|
||||
void free_copybuffer();
|
||||
void set_defaultSchema(std::string schema);
|
||||
|
||||
DMLParser::DMLParser() :
|
||||
DMLParser::DMLParser() :
|
||||
fStatus(-1), fDebug(false)
|
||||
{}
|
||||
{}
|
||||
|
||||
DMLParser::~DMLParser()
|
||||
{
|
||||
DMLParser::~DMLParser()
|
||||
{
|
||||
scanner_finish(scanner);
|
||||
dmllex_destroy(scanner);
|
||||
}
|
||||
}
|
||||
|
||||
void DMLParser::setDebug(bool debug)
|
||||
{
|
||||
void DMLParser::setDebug(bool debug)
|
||||
{
|
||||
fDebug = true;
|
||||
}
|
||||
}
|
||||
|
||||
int DMLParser::parse(const char* dmltext)
|
||||
{
|
||||
int DMLParser::parse(const char* dmltext)
|
||||
{
|
||||
dmllex_init_extra(&scanData, &scanner);
|
||||
scanner_init(dmltext, scanner);
|
||||
grammar_init(&fParseTree, fDebug);
|
||||
fStatus = dmlparse(scanner);
|
||||
|
||||
if (fStatus == 0)
|
||||
{
|
||||
char* str;
|
||||
valbuf_t valueBuffer = get_valbuffer();
|
||||
|
||||
for(unsigned int i=0; i < valueBuffer.size(); i++)
|
||||
for (unsigned int i = 0; i < valueBuffer.size(); i++)
|
||||
{
|
||||
str = valueBuffer[i];
|
||||
if(str)
|
||||
|
||||
if (str)
|
||||
{
|
||||
if (i > 0)
|
||||
fParseTree.fSqlText += " ";
|
||||
|
||||
fParseTree.fSqlText += str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free_copybuffer();
|
||||
return fStatus;
|
||||
}
|
||||
}
|
||||
|
||||
const ParseTree& DMLParser::getParseTree()
|
||||
{
|
||||
const ParseTree& DMLParser::getParseTree()
|
||||
{
|
||||
if (!good())
|
||||
{
|
||||
throw logic_error("The ParseTree is invalid");
|
||||
}
|
||||
|
||||
return fParseTree;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool DMLParser::good()
|
||||
{
|
||||
bool DMLParser::good()
|
||||
{
|
||||
return fStatus == 0;
|
||||
}
|
||||
}
|
||||
|
||||
void DMLParser::setDefaultSchema(std::string schema)
|
||||
{
|
||||
void DMLParser::setDefaultSchema(std::string schema)
|
||||
{
|
||||
set_defaultSchema(schema);
|
||||
}
|
||||
}
|
||||
|
||||
DMLFileParser::DMLFileParser()
|
||||
:DMLParser()
|
||||
{}
|
||||
DMLFileParser::DMLFileParser()
|
||||
: DMLParser()
|
||||
{}
|
||||
|
||||
int DMLFileParser::parse(const string& fileName)
|
||||
{
|
||||
int DMLFileParser::parse(const string& fileName)
|
||||
{
|
||||
fStatus = -1;
|
||||
|
||||
ifstream ifdml;
|
||||
ifdml.open(fileName.c_str());
|
||||
|
||||
if (!ifdml.is_open())
|
||||
{
|
||||
perror(fileName.c_str());
|
||||
return fStatus;
|
||||
}
|
||||
char dmlbuf[1024*1024];
|
||||
|
||||
char dmlbuf[1024 * 1024];
|
||||
unsigned length;
|
||||
ifdml.seekg(0, ios::end);
|
||||
length = ifdml.tellg();
|
||||
ifdml.seekg(0, ios::beg);
|
||||
|
||||
if (length > sizeof(dmlbuf) - 1)
|
||||
{
|
||||
throw length_error("DMLFileParser has file size hard limit of 16K.");
|
||||
@@ -142,6 +150,7 @@ namespace dmlpackage
|
||||
|
||||
unsigned rcount;
|
||||
rcount = ifdml.readsome(dmlbuf, sizeof(dmlbuf) - 1);
|
||||
|
||||
if (rcount < 0)
|
||||
return fStatus;
|
||||
|
||||
@@ -152,11 +161,11 @@ namespace dmlpackage
|
||||
//cout << dmlbuf << endl;
|
||||
|
||||
return DMLParser::parse(dmlbuf);
|
||||
}
|
||||
}
|
||||
|
||||
void end_sql(void)
|
||||
{
|
||||
void end_sql(void)
|
||||
{
|
||||
|
||||
} /* end_sql */
|
||||
} /* end_sql */
|
||||
|
||||
} // dmlpackage
|
||||
|
||||
@@ -31,27 +31,27 @@
|
||||
|
||||
namespace dmlpackage
|
||||
{
|
||||
typedef std::vector<char*> valbuf_t;
|
||||
typedef std::vector<char*> valbuf_t;
|
||||
|
||||
|
||||
typedef SqlStatementList ParseTree;
|
||||
typedef SqlStatementList ParseTree;
|
||||
|
||||
// instance data for the parser
|
||||
typedef std::vector<char*> valbuf_t;
|
||||
// instance data for the parser
|
||||
typedef std::vector<char*> valbuf_t;
|
||||
|
||||
struct scan_data
|
||||
{
|
||||
struct scan_data
|
||||
{
|
||||
/* Handles to the buffer that the lexer uses internally */
|
||||
char* scanbuf;
|
||||
void* scanbufhandle; // This is a YY_BUFFER_STATE defined in ddl-scan.cpp
|
||||
valbuf_t valbuf;
|
||||
};
|
||||
};
|
||||
|
||||
/** @brief BISON parser wrapper class
|
||||
/** @brief BISON parser wrapper class
|
||||
*/
|
||||
class DMLParser
|
||||
{
|
||||
public:
|
||||
class DMLParser
|
||||
{
|
||||
public:
|
||||
/** @brief ctor
|
||||
*/
|
||||
DMLParser();
|
||||
@@ -81,24 +81,24 @@ namespace dmlpackage
|
||||
*/
|
||||
void setDebug(bool debug);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
ParseTree fParseTree;
|
||||
int fStatus;
|
||||
bool fDebug;
|
||||
void* scanner; // yyscan_t * needed for re-entrant flex scanner
|
||||
scan_data scanData;
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
/** @brief specialization of the DMLParser class
|
||||
/** @brief specialization of the DMLParser class
|
||||
* specifically for reading the dml statement
|
||||
* from a file
|
||||
*/
|
||||
class DMLFileParser : public DMLParser
|
||||
{
|
||||
public:
|
||||
class DMLFileParser : public DMLParser
|
||||
{
|
||||
public:
|
||||
/** @brief ctor
|
||||
*/
|
||||
DMLFileParser();
|
||||
@@ -111,10 +111,10 @@ namespace dmlpackage
|
||||
*/
|
||||
int parse(const std::string& fileName);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
private:
|
||||
};
|
||||
private:
|
||||
};
|
||||
|
||||
}
|
||||
#endif // DMLPARSER_H
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -123,7 +123,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout.
|
||||
*/
|
||||
virtual std::ostream& put(std::ostream &os) const = 0;
|
||||
virtual std::ostream& put(std::ostream& os) const = 0;
|
||||
|
||||
/** @brief get the query string associated with the
|
||||
* SqlStatement
|
||||
@@ -225,7 +225,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get a string representation of the query spec
|
||||
*/
|
||||
@@ -233,7 +233,10 @@ public:
|
||||
|
||||
/** @brief get the statement type - DML_INSERT
|
||||
*/
|
||||
inline virtual int getStatementType() const { return DML_INSERT; }
|
||||
inline virtual int getStatementType() const
|
||||
{
|
||||
return DML_INSERT;
|
||||
}
|
||||
|
||||
ValuesOrQuery* fValuesOrQueryPtr;
|
||||
ColumnNameList fColumnList;
|
||||
@@ -267,7 +270,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the
|
||||
* SET assignment_commalist opt_where_clause
|
||||
@@ -277,7 +280,10 @@ public:
|
||||
|
||||
/** @brief get the statement type - DML_UPDATE
|
||||
*/
|
||||
inline virtual int getStatementType() const { return DML_UPDATE; }
|
||||
inline virtual int getStatementType() const
|
||||
{
|
||||
return DML_UPDATE;
|
||||
}
|
||||
|
||||
ColumnAssignmentList* fColAssignmentListPtr;
|
||||
WhereClause* fWhereClausePtr;
|
||||
@@ -309,7 +315,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the WHERE clause
|
||||
*/
|
||||
@@ -317,7 +323,10 @@ public:
|
||||
|
||||
/** @brief get the statement type - DML_DELETE
|
||||
*/
|
||||
inline virtual int getStatementType() const { return DML_DELETE; }
|
||||
inline virtual int getStatementType() const
|
||||
{
|
||||
return DML_DELETE;
|
||||
}
|
||||
|
||||
WhereClause* fWhereClausePtr;
|
||||
};
|
||||
@@ -344,11 +353,14 @@ public:
|
||||
|
||||
/** @brief get the statement type - DML_COMMAND
|
||||
*/
|
||||
inline virtual int getStatementType() const { return DML_COMMAND; }
|
||||
inline virtual int getStatementType() const
|
||||
{
|
||||
return DML_COMMAND;
|
||||
}
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the COMMIT or ROLLBACK string
|
||||
*/
|
||||
@@ -382,7 +394,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
std::ostream& put(std::ostream &os) const;
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
std::string fName;
|
||||
std::string fSchema;
|
||||
@@ -399,7 +411,7 @@ class ColumnAssignment
|
||||
public:
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
std::ostream& put(std::ostream &os) const;
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of
|
||||
* the column assignment
|
||||
@@ -444,7 +456,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
std::ostream& put(std::ostream &os) const;
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string reperesentation of
|
||||
* the ValuesList or the QuerySpec
|
||||
@@ -480,7 +492,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
std::ostream& put(std::ostream &os) const;
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string represntation of the SELECT statement
|
||||
*/
|
||||
@@ -513,7 +525,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
std::ostream& put(std::ostream &os) const;
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the FROM clause
|
||||
*/
|
||||
@@ -540,7 +552,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
std::ostream& put(std::ostream &os) const;
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the WHERE clause
|
||||
*/
|
||||
@@ -569,7 +581,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
std::ostream& put(std::ostream &os) const;
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the GROUP BY clause
|
||||
*/
|
||||
@@ -597,7 +609,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
std::ostream& put(std::ostream &os) const;
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the HAVING clause
|
||||
*/
|
||||
@@ -618,7 +630,7 @@ class Escape
|
||||
public:
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
std::ostream& put(std::ostream &os) const;
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
std::string fEscapeChar;
|
||||
};
|
||||
@@ -653,7 +665,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @param get the string representation of the predicate
|
||||
*/
|
||||
@@ -682,7 +694,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the COMPARISON
|
||||
* predicate
|
||||
@@ -717,7 +729,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the BETWEEN
|
||||
* predicate
|
||||
@@ -752,7 +764,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the LIKE
|
||||
* predicate
|
||||
@@ -786,7 +798,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the NULL test
|
||||
* predicate
|
||||
@@ -820,7 +832,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the IN
|
||||
* predicate
|
||||
@@ -853,7 +865,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the
|
||||
* ALL or ANY predicate
|
||||
@@ -886,7 +898,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
virtual std::ostream& put(std::ostream &os) const;
|
||||
virtual std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the EXISTS
|
||||
* predicate
|
||||
@@ -919,7 +931,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
std::ostream& put(std::ostream &os) const;
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the striong representation of the
|
||||
* search condition
|
||||
@@ -965,7 +977,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
std::ostream& put(std::ostream &os) const;
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the
|
||||
* table expression
|
||||
@@ -1013,7 +1025,7 @@ public:
|
||||
|
||||
/** @brief dump to stdout
|
||||
*/
|
||||
std::ostream& put(std::ostream &os) const;
|
||||
std::ostream& put(std::ostream& os) const;
|
||||
|
||||
/** @brief get the string representation of the
|
||||
* query specification
|
||||
|
||||
@@ -35,13 +35,14 @@ DMLTable::~DMLTable()
|
||||
try
|
||||
{
|
||||
RowList::iterator it = fRows.begin();
|
||||
while(it != fRows.end())
|
||||
|
||||
while (it != fRows.end())
|
||||
{
|
||||
delete *it;
|
||||
it++;
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
cout << "failed to delete the table rows" << endl;
|
||||
}
|
||||
@@ -67,6 +68,7 @@ int DMLTable::read(messageqcpp::ByteStream& bytestream)
|
||||
retval = aRow->read(bytestream);
|
||||
fRows.push_back(aRow);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -82,6 +84,7 @@ int DMLTable::write(messageqcpp::ByteStream& bytestream)
|
||||
//write the row list
|
||||
RowList::iterator rowListPtr;
|
||||
rowListPtr = fRows.begin();
|
||||
|
||||
for (; rowListPtr != fRows.end(); ++rowListPtr)
|
||||
{
|
||||
retval = (*rowListPtr)->write(bytestream);
|
||||
|
||||
@@ -51,23 +51,38 @@ public:
|
||||
|
||||
/** @brief get the schema name
|
||||
*/
|
||||
inline const std::string get_SchemaName() const { return fSchema; }
|
||||
inline const std::string get_SchemaName() const
|
||||
{
|
||||
return fSchema;
|
||||
}
|
||||
|
||||
/** @brief set the schema name
|
||||
*/
|
||||
inline void set_SchemaName( std::string& sName ) { fSchema = sName; }
|
||||
inline void set_SchemaName( std::string& sName )
|
||||
{
|
||||
fSchema = sName;
|
||||
}
|
||||
|
||||
/** @brief get the table name
|
||||
*/
|
||||
inline const std::string get_TableName() const { return fName; }
|
||||
inline const std::string get_TableName() const
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
|
||||
/** @brief set the table name
|
||||
*/
|
||||
inline void set_TableName( std::string& tName ) { fName = tName; }
|
||||
inline void set_TableName( std::string& tName )
|
||||
{
|
||||
fName = tName;
|
||||
}
|
||||
|
||||
/** @brief get the row list
|
||||
*/
|
||||
inline RowList& get_RowList() { return fRows; }
|
||||
inline RowList& get_RowList()
|
||||
{
|
||||
return fRows;
|
||||
}
|
||||
|
||||
/** @brief read a DMLTable from a ByteStream
|
||||
*
|
||||
|
||||
@@ -44,6 +44,7 @@ int main(int argc, char* argv[])
|
||||
po::variables_map vm;
|
||||
po::store (po::parse_command_line (argc, argv, desc), vm);
|
||||
po::notify (vm);
|
||||
|
||||
if (vm.count ("sql"))
|
||||
sqlfile = vm["sql"].as <string> ();
|
||||
|
||||
@@ -51,14 +52,15 @@ int main(int argc, char* argv[])
|
||||
count = vm["count"].as<int>();
|
||||
|
||||
DMLFileParser parser;
|
||||
|
||||
if (vm.count ("bisond"))
|
||||
parser.setDebug(true);
|
||||
|
||||
parser.parse(sqlfile);
|
||||
|
||||
if(parser.good())
|
||||
if (parser.good())
|
||||
{
|
||||
const ParseTree &ptree = parser.getParseTree();
|
||||
const ParseTree& ptree = parser.getParseTree();
|
||||
|
||||
cout << "Parser succeeded." << endl;
|
||||
cout << ptree.fList.size() << " " << "SQL statements" << endl;
|
||||
@@ -66,8 +68,10 @@ int main(int argc, char* argv[])
|
||||
cout << ptree;
|
||||
|
||||
SqlStatement* statementPtr = ptree[0];
|
||||
|
||||
if (statementPtr)
|
||||
cout << statementPtr->getQueryString();
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -41,7 +41,7 @@ InsertDMLPackage::InsertDMLPackage()
|
||||
|
||||
InsertDMLPackage::InsertDMLPackage( std::string schemaName, std::string tableName,
|
||||
std::string dmlStatement, int sessionID )
|
||||
:CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID )
|
||||
: CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID )
|
||||
{}
|
||||
|
||||
InsertDMLPackage::~InsertDMLPackage()
|
||||
@@ -64,10 +64,12 @@ int InsertDMLPackage::write(messageqcpp::ByteStream& bytestream)
|
||||
bytestream << fSchemaName;
|
||||
bytestream << (uint8_t)fLogging;
|
||||
bytestream << (uint8_t)fLogending;
|
||||
|
||||
if (fTable != 0)
|
||||
{
|
||||
retval = fTable->write(bytestream);
|
||||
}
|
||||
|
||||
bytestream << fTableOid;
|
||||
bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsInsertSelect);
|
||||
bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsBatchInsert);
|
||||
@@ -118,6 +120,7 @@ int InsertDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
boost::char_separator<char> sep(",");
|
||||
tokenizer tokens(buffer, sep);
|
||||
|
||||
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
|
||||
{
|
||||
dataList.push_back(StripLeadingWhitespace(*tok_iter));
|
||||
@@ -125,12 +128,14 @@ int InsertDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
|
||||
}
|
||||
|
||||
int n = 0;
|
||||
for (int i=0; i < rows; i++)
|
||||
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
//get a new row
|
||||
Row *aRowPtr = new Row();
|
||||
Row* aRowPtr = new Row();
|
||||
std::string colName;
|
||||
std::string colValue;
|
||||
|
||||
for (int j = 0; j < columns; j++)
|
||||
{
|
||||
//Build a column list
|
||||
@@ -144,6 +149,7 @@ int InsertDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
|
||||
DMLColumn* aColumn = new DMLColumn(colName, colValue, false);
|
||||
(aRowPtr->get_ColumnList()).push_back(aColumn);
|
||||
}
|
||||
|
||||
//build a row list for a table
|
||||
fTable->get_RowList().push_back(aRowPtr);
|
||||
}
|
||||
@@ -156,9 +162,10 @@ int InsertDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
|
||||
int retval = 1;
|
||||
|
||||
initializeTable();
|
||||
Row *aRowPtr = new Row();
|
||||
Row* aRowPtr = new Row();
|
||||
std::string colName;
|
||||
std::vector<std::string> colValList;
|
||||
|
||||
for (int j = 0; j < columns; j++)
|
||||
{
|
||||
//Build a column list
|
||||
@@ -169,6 +176,7 @@ int InsertDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
|
||||
DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]);
|
||||
(aRowPtr->get_ColumnList()).push_back(aColumn);
|
||||
}
|
||||
|
||||
//build a row list for a table
|
||||
fTable->get_RowList().push_back(aRowPtr);
|
||||
aRowPtr = NULL;
|
||||
@@ -188,6 +196,7 @@ int InsertDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
|
||||
|
||||
initializeTable();
|
||||
bool isNULL = false;
|
||||
|
||||
// only if we don't have a select statement
|
||||
if (0 == insertStmt.fValuesOrQueryPtr->fQuerySpecPtr)
|
||||
{
|
||||
@@ -198,16 +207,20 @@ int InsertDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
|
||||
{
|
||||
|
||||
ValuesList valuesList = insertStmt.fValuesOrQueryPtr->fValuesList;
|
||||
|
||||
if (columnNameList.size() != valuesList.size())
|
||||
{
|
||||
throw logic_error("Column names and values count mismatch!");
|
||||
}
|
||||
|
||||
Row* aRow = new Row();
|
||||
|
||||
for (unsigned int i = 0; i < columnNameList.size(); i++)
|
||||
{
|
||||
DMLColumn *aColumn = new DMLColumn(columnNameList[i],valuesList[i], isNULL);
|
||||
DMLColumn* aColumn = new DMLColumn(columnNameList[i], valuesList[i], isNULL);
|
||||
(aRow->get_ColumnList()).push_back(aColumn);
|
||||
}
|
||||
|
||||
fTable->get_RowList().push_back(aRow);
|
||||
|
||||
}
|
||||
@@ -218,9 +231,11 @@ int InsertDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
|
||||
Row* aRow = new Row();
|
||||
std::string colName = "";
|
||||
std::string colValue;
|
||||
|
||||
while (iter != valuesList.end())
|
||||
{
|
||||
colValue = *iter;
|
||||
|
||||
if ( strcasecmp(colValue.c_str(), "NULL") == 0)
|
||||
{
|
||||
isNULL = true;
|
||||
@@ -229,11 +244,13 @@ int InsertDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
|
||||
{
|
||||
isNULL = false;
|
||||
}
|
||||
DMLColumn *aColumn = new DMLColumn(colName,colValue, isNULL);
|
||||
|
||||
DMLColumn* aColumn = new DMLColumn(colName, colValue, isNULL);
|
||||
(aRow->get_ColumnList()).push_back(aColumn);
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
fTable->get_RowList().push_back(aRow);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace dmlpackage
|
||||
{
|
||||
|
||||
Row::Row()
|
||||
:fRowID(std::numeric_limits<WriteEngine::RID>::max())
|
||||
: fRowID(std::numeric_limits<WriteEngine::RID>::max())
|
||||
{}
|
||||
|
||||
Row::~Row()
|
||||
@@ -39,17 +39,19 @@ Row::~Row()
|
||||
{
|
||||
delete fColumnList[i];
|
||||
}
|
||||
|
||||
fColumnList.clear();
|
||||
}
|
||||
|
||||
Row::Row(const Row& row)
|
||||
{
|
||||
for(unsigned int i = 0; i < row.fColumnList.size(); i++)
|
||||
for (unsigned int i = 0; i < row.fColumnList.size(); i++)
|
||||
{
|
||||
const DMLColumn* aColumn = row.get_ColumnAt(i);
|
||||
DMLColumn* newColumn = new DMLColumn(aColumn->get_Name(), aColumn->get_Data());
|
||||
fColumnList.push_back(newColumn);
|
||||
}
|
||||
|
||||
fRowID = row.fRowID;
|
||||
}
|
||||
int Row::read(messageqcpp::ByteStream& bytestream)
|
||||
@@ -60,12 +62,14 @@ int Row::read(messageqcpp::ByteStream& bytestream)
|
||||
set_RowID(rowID);
|
||||
messageqcpp::ByteStream::quadbyte col_count;
|
||||
bytestream >> col_count;
|
||||
|
||||
for (unsigned int i = 0; i < col_count; i++)
|
||||
{
|
||||
DMLColumn* aColumn = new DMLColumn();
|
||||
retval = aColumn->read(bytestream);
|
||||
fColumnList.push_back(aColumn);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -79,6 +83,7 @@ int Row::write(messageqcpp::ByteStream& bytestream)
|
||||
colListPtr = fColumnList.begin();
|
||||
messageqcpp::ByteStream::quadbyte col_count = fColumnList.size();
|
||||
bytestream << col_count;
|
||||
|
||||
for (; colListPtr != fColumnList.end(); ++colListPtr)
|
||||
{
|
||||
retval = (*colListPtr)->write(bytestream);
|
||||
|
||||
@@ -71,19 +71,31 @@ public:
|
||||
|
||||
/** @brief get the list of columns in the row
|
||||
*/
|
||||
inline ColumnList& get_ColumnList() { return fColumnList; }
|
||||
inline ColumnList& get_ColumnList()
|
||||
{
|
||||
return fColumnList;
|
||||
}
|
||||
|
||||
/** @brief get the row id
|
||||
*/
|
||||
inline WriteEngine::RID get_RowID() const { return fRowID; }
|
||||
inline WriteEngine::RID get_RowID() const
|
||||
{
|
||||
return fRowID;
|
||||
}
|
||||
|
||||
/** @brief set the row id
|
||||
*/
|
||||
inline void set_RowID(WriteEngine::RID rowId) { fRowID = rowId; }
|
||||
inline void set_RowID(WriteEngine::RID rowId)
|
||||
{
|
||||
fRowID = rowId;
|
||||
}
|
||||
|
||||
/** @brief get the number of columns
|
||||
*/
|
||||
inline unsigned int get_NumberOfColumns() const { return static_cast<unsigned int>(fColumnList.size()); }
|
||||
inline unsigned int get_NumberOfColumns() const
|
||||
{
|
||||
return static_cast<unsigned int>(fColumnList.size());
|
||||
}
|
||||
|
||||
/** @brief get the column at the specified index
|
||||
*
|
||||
|
||||
@@ -46,9 +46,10 @@ bool parse_file(char* fileName)
|
||||
DMLFileParser parser;
|
||||
parser.parse(fileName);
|
||||
bool good = parser.good();
|
||||
|
||||
if (good)
|
||||
{
|
||||
const ParseTree &ptree = parser.getParseTree();
|
||||
const ParseTree& ptree = parser.getParseTree();
|
||||
|
||||
cout << "Parser succeeded." << endl;
|
||||
cout << ptree.fList.size() << " " << "SQL statements" << endl;
|
||||
@@ -56,8 +57,10 @@ bool parse_file(char* fileName)
|
||||
cout << ptree;
|
||||
|
||||
SqlStatement* statementPtr = ptree[0];
|
||||
|
||||
if (statementPtr)
|
||||
cout << statementPtr->getQueryString();
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
@@ -87,25 +90,55 @@ public:
|
||||
|
||||
void tearDown() {}
|
||||
|
||||
void test_i01() { CPPUNIT_ASSERT(parse_file("sql/i01.sql")); }
|
||||
void test_i01()
|
||||
{
|
||||
CPPUNIT_ASSERT(parse_file("sql/i01.sql"));
|
||||
}
|
||||
|
||||
void test_i02() { CPPUNIT_ASSERT(parse_file("sql/i02.sql")); }
|
||||
void test_i02()
|
||||
{
|
||||
CPPUNIT_ASSERT(parse_file("sql/i02.sql"));
|
||||
}
|
||||
|
||||
void test_i03() { CPPUNIT_ASSERT(parse_file("sql/i03.sql")); }
|
||||
void test_i03()
|
||||
{
|
||||
CPPUNIT_ASSERT(parse_file("sql/i03.sql"));
|
||||
}
|
||||
|
||||
void test_i04() { CPPUNIT_ASSERT(parse_file("sql/i04.sql")); }
|
||||
void test_i04()
|
||||
{
|
||||
CPPUNIT_ASSERT(parse_file("sql/i04.sql"));
|
||||
}
|
||||
|
||||
void test_u01() { CPPUNIT_ASSERT(parse_file("sql/u01.sql")); }
|
||||
void test_u01()
|
||||
{
|
||||
CPPUNIT_ASSERT(parse_file("sql/u01.sql"));
|
||||
}
|
||||
|
||||
void test_u02() { CPPUNIT_ASSERT(parse_file("sql/u02.sql")); }
|
||||
void test_u02()
|
||||
{
|
||||
CPPUNIT_ASSERT(parse_file("sql/u02.sql"));
|
||||
}
|
||||
|
||||
void test_d01() { CPPUNIT_ASSERT(parse_file("sql/d01.sql")); }
|
||||
void test_d01()
|
||||
{
|
||||
CPPUNIT_ASSERT(parse_file("sql/d01.sql"));
|
||||
}
|
||||
|
||||
void test_d02() { CPPUNIT_ASSERT(parse_file("sql/d02.sql")); }
|
||||
void test_d02()
|
||||
{
|
||||
CPPUNIT_ASSERT(parse_file("sql/d02.sql"));
|
||||
}
|
||||
|
||||
void test_d03() { CPPUNIT_ASSERT(parse_file("sql/d03.sql")); }
|
||||
void test_d03()
|
||||
{
|
||||
CPPUNIT_ASSERT(parse_file("sql/d03.sql"));
|
||||
}
|
||||
|
||||
void test_d04() { CPPUNIT_ASSERT(parse_file("sql/d04.sql")); }
|
||||
void test_d04()
|
||||
{
|
||||
CPPUNIT_ASSERT(parse_file("sql/d04.sql"));
|
||||
}
|
||||
};
|
||||
|
||||
class DMLTest : public CppUnit::TestFixture
|
||||
@@ -154,6 +187,7 @@ public:
|
||||
VendorDMLStatement dmlStmt(dmlStatement, 1);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
CPPUNIT_ASSERT( 0 != pDMLPackage );
|
||||
|
||||
if ( pDMLPackage->HasFilter() )
|
||||
{
|
||||
cout << "This INSERT statement has a filter:" << endl;
|
||||
@@ -180,7 +214,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT( DML_INSERT == package_type );
|
||||
|
||||
InsertDMLPackage *pObject = new InsertDMLPackage();
|
||||
InsertDMLPackage* pObject = new InsertDMLPackage();
|
||||
|
||||
pObject->read( bs );
|
||||
|
||||
@@ -196,7 +230,7 @@ public:
|
||||
|
||||
cout << dmlStatement << endl;
|
||||
|
||||
VendorDMLStatement dmlStmt(dmlStatement,1);
|
||||
VendorDMLStatement dmlStmt(dmlStatement, 1);
|
||||
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
CPPUNIT_ASSERT( 0 != pDMLPackage );
|
||||
@@ -212,15 +246,17 @@ public:
|
||||
|
||||
cout << dmlStatement << endl;
|
||||
|
||||
VendorDMLStatement dmlStmt(dmlStatement,1);
|
||||
VendorDMLStatement dmlStmt(dmlStatement, 1);
|
||||
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
CPPUNIT_ASSERT( 0 != pDMLPackage );
|
||||
|
||||
if (pDMLPackage->HasFilter())
|
||||
{
|
||||
cout << "This DELETE statement has a filter:" << endl;
|
||||
cout << pDMLPackage->get_QueryString() << endl;
|
||||
}
|
||||
|
||||
write_DML_object(bytestream, pDMLPackage);
|
||||
delete pDMLPackage;
|
||||
read_delete_object(bytestream);
|
||||
@@ -235,7 +271,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT( DML_DELETE == package_type );
|
||||
|
||||
DeleteDMLPackage *pObject = new DeleteDMLPackage();
|
||||
DeleteDMLPackage* pObject = new DeleteDMLPackage();
|
||||
|
||||
pObject->read( bs );
|
||||
|
||||
@@ -249,7 +285,7 @@ public:
|
||||
std::string dmlStatement = "UPDATE tpch.part SET p_partno = 1, p_name = 'joe' where p_partno=2;";
|
||||
cout << dmlStatement << endl;
|
||||
|
||||
VendorDMLStatement dmlStmt(dmlStatement,1);
|
||||
VendorDMLStatement dmlStmt(dmlStatement, 1);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
CPPUNIT_ASSERT( 0 != pDMLPackage );
|
||||
write_DML_object(bytestream, pDMLPackage);
|
||||
@@ -267,6 +303,7 @@ public:
|
||||
VendorDMLStatement dmlStmt(dmlStatement, 1);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
CPPUNIT_ASSERT( 0 != pDMLPackage );
|
||||
|
||||
if (pDMLPackage->HasFilter())
|
||||
{
|
||||
cout << "This UPDATE statement has a filter:" << endl;
|
||||
@@ -286,7 +323,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT( DML_UPDATE == package_type );
|
||||
|
||||
UpdateDMLPackage *pObject = new UpdateDMLPackage();
|
||||
UpdateDMLPackage* pObject = new UpdateDMLPackage();
|
||||
|
||||
pObject->read( bs );
|
||||
|
||||
@@ -300,7 +337,7 @@ public:
|
||||
std::string dmlStatement = "COMMIT;";
|
||||
cout << dmlStatement << endl;
|
||||
|
||||
VendorDMLStatement dmlStmt(dmlStatement,1);
|
||||
VendorDMLStatement dmlStmt(dmlStatement, 1);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
CPPUNIT_ASSERT( 0 != pDMLPackage );
|
||||
write_DML_object(bytestream, pDMLPackage);
|
||||
@@ -315,7 +352,7 @@ public:
|
||||
std::string dmlStatement = "ROLLBACK;";
|
||||
cout << dmlStatement << endl;
|
||||
|
||||
VendorDMLStatement dmlStmt(dmlStatement,1);
|
||||
VendorDMLStatement dmlStmt(dmlStatement, 1);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
CPPUNIT_ASSERT( 0 != pDMLPackage );
|
||||
write_DML_object(bytestream, pDMLPackage);
|
||||
@@ -331,7 +368,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT( DML_COMMAND == package_type );
|
||||
|
||||
CommandDMLPackage *pObject = new CommandDMLPackage();
|
||||
CommandDMLPackage* pObject = new CommandDMLPackage();
|
||||
|
||||
pObject->read( bs );
|
||||
|
||||
@@ -346,10 +383,10 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DMLTest );
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
|
||||
int main( int argc, char **argv)
|
||||
int main( int argc, char** argv)
|
||||
{
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
runner.addTest( registry.makeTest() );
|
||||
bool wasSuccessful = runner.run( "", false );
|
||||
return (wasSuccessful ? 0 : 1);
|
||||
|
||||
@@ -38,7 +38,7 @@ UpdateDMLPackage::UpdateDMLPackage()
|
||||
|
||||
UpdateDMLPackage::UpdateDMLPackage(std::string schemaName, std::string tableName,
|
||||
std::string dmlStatement, int sessionID)
|
||||
:CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID)
|
||||
: CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID)
|
||||
{}
|
||||
|
||||
UpdateDMLPackage::~UpdateDMLPackage()
|
||||
@@ -52,12 +52,12 @@ int UpdateDMLPackage::write(messageqcpp::ByteStream& bytestream)
|
||||
|
||||
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
|
||||
bytestream << session_id;
|
||||
/*
|
||||
/*
|
||||
if(fPlan != 0)
|
||||
fHasFilter = true;
|
||||
else
|
||||
fHasFilter = false;
|
||||
*/
|
||||
*/
|
||||
messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter;
|
||||
bytestream << hasFilter;
|
||||
|
||||
@@ -67,11 +67,13 @@ int UpdateDMLPackage::write(messageqcpp::ByteStream& bytestream)
|
||||
bytestream << fSQLStatement;
|
||||
bytestream << fSchemaName;
|
||||
bytestream << (uint8_t)fIsFromCol;
|
||||
|
||||
if (fTable != 0)
|
||||
{
|
||||
retval = fTable->write(bytestream);
|
||||
}
|
||||
if(fHasFilter)
|
||||
|
||||
if (fHasFilter)
|
||||
{
|
||||
bytestream += *(fPlan.get());
|
||||
}
|
||||
@@ -105,7 +107,8 @@ int UpdateDMLPackage::read(messageqcpp::ByteStream& bytestream)
|
||||
fIsFromCol = (isFromCol != 0);
|
||||
fTable = new DMLTable();
|
||||
retval = fTable->read(bytestream);
|
||||
if(fHasFilter)
|
||||
|
||||
if (fHasFilter)
|
||||
{
|
||||
fPlan.reset(new messageqcpp::ByteStream(bytestream));
|
||||
}
|
||||
@@ -130,6 +133,7 @@ int UpdateDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
|
||||
// Push one row always and let the filter happen on the proc side.
|
||||
Row* rowPtr = new Row();
|
||||
ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin();
|
||||
|
||||
while (iter != updateStmt.fColAssignmentListPtr->end())
|
||||
{
|
||||
ColumnAssignment* colaPtr = *iter;
|
||||
@@ -138,7 +142,9 @@ int UpdateDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
fTable->get_RowList().push_back(rowPtr);
|
||||
|
||||
if (0 != updateStmt.fWhereClausePtr)
|
||||
{
|
||||
// We need to filter the rows...get row ids
|
||||
@@ -166,6 +172,7 @@ int UpdateDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
boost::char_separator<char> sep(":,");
|
||||
tokenizer tokens(buffer, sep);
|
||||
|
||||
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
|
||||
{
|
||||
dataList.push_back(StripLeadingWhitespace(*tok_iter));
|
||||
@@ -173,10 +180,11 @@ int UpdateDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
|
||||
}
|
||||
|
||||
int n = 0;
|
||||
for (int i=0; i < rows; i++)
|
||||
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
//get a new row
|
||||
Row *aRowPtr = new Row();
|
||||
Row* aRowPtr = new Row();
|
||||
std::string colName;
|
||||
std::string colValue;
|
||||
//get row ID from the buffer
|
||||
@@ -200,6 +208,7 @@ int UpdateDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
|
||||
DMLColumn* aColumn = new DMLColumn(colName, colValue);
|
||||
(aRowPtr->get_ColumnList()).push_back(aColumn);
|
||||
}
|
||||
|
||||
//build a row list for a table
|
||||
fTable->get_RowList().push_back(aRowPtr);
|
||||
}
|
||||
@@ -211,9 +220,10 @@ int UpdateDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
|
||||
int retval = 1;
|
||||
|
||||
initializeTable();
|
||||
Row *aRowPtr = new Row();
|
||||
Row* aRowPtr = new Row();
|
||||
std::string colName;
|
||||
std::vector<std::string> colValList;
|
||||
|
||||
for (int j = 0; j < columns; j++)
|
||||
{
|
||||
//Build a column list
|
||||
@@ -224,6 +234,7 @@ int UpdateDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
|
||||
DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]);
|
||||
(aRowPtr->get_ColumnList()).push_back(aColumn);
|
||||
}
|
||||
|
||||
//build a row list for a table
|
||||
fTable->get_RowList().push_back(aRowPtr);
|
||||
return retval;
|
||||
@@ -242,6 +253,7 @@ void UpdateDMLPackage::buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStm
|
||||
// Push one row always and let the filter happen on the proc side.
|
||||
Row* rowPtr = new Row();
|
||||
ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin();
|
||||
|
||||
while (iter != updateStmt.fColAssignmentListPtr->end())
|
||||
{
|
||||
ColumnAssignment* colaPtr = *iter;
|
||||
@@ -250,6 +262,7 @@ void UpdateDMLPackage::buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStm
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
fTable->get_RowList().push_back(rowPtr);
|
||||
}
|
||||
} // namespace dmlpackage
|
||||
|
||||
@@ -36,13 +36,13 @@
|
||||
|
||||
namespace dmlpackage
|
||||
{
|
||||
/** @brief concrete implementation of a CalpontDMLPackage
|
||||
/** @brief concrete implementation of a CalpontDMLPackage
|
||||
* Specifically for representing UPDATE DML Statements
|
||||
*/
|
||||
class UpdateDMLPackage : public CalpontDMLPackage
|
||||
{
|
||||
class UpdateDMLPackage : public CalpontDMLPackage
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
/** @brief ctor
|
||||
*/
|
||||
EXPORT UpdateDMLPackage();
|
||||
@@ -96,11 +96,11 @@ namespace dmlpackage
|
||||
void buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStmt );
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
@@ -30,30 +30,30 @@ using namespace std;
|
||||
namespace dmlpackage
|
||||
{
|
||||
|
||||
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int sessionID)
|
||||
:fDMLStatement(dmlstatement),fSessionID(sessionID), fLogging(true),fLogending(true)
|
||||
{}
|
||||
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int sessionID)
|
||||
: fDMLStatement(dmlstatement), fSessionID(sessionID), fLogging(true), fLogending(true)
|
||||
{}
|
||||
|
||||
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, int sessionID)
|
||||
:fDMLStatement(dmlstatement), fDMLStatementType(stmttype), fSessionID(sessionID),fLogging(true),fLogending(true)
|
||||
{}
|
||||
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, int sessionID)
|
||||
: fDMLStatement(dmlstatement), fDMLStatementType(stmttype), fSessionID(sessionID), fLogging(true), fLogending(true)
|
||||
{}
|
||||
|
||||
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype,
|
||||
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype,
|
||||
std::string tName, std::string schema,
|
||||
int rows, int columns, std::string buf,
|
||||
int sessionID)
|
||||
:fDMLStatement(dmlstatement), fDMLStatementType(stmttype),
|
||||
: fDMLStatement(dmlstatement), fDMLStatementType(stmttype),
|
||||
fTableName(tName), fSchema(schema), fRows(rows), fColumns(columns),
|
||||
fDataBuffer(buf), fSessionID(sessionID), fLogging(true),fLogending(true)
|
||||
{}
|
||||
fDataBuffer(buf), fSessionID(sessionID), fLogging(true), fLogending(true)
|
||||
{}
|
||||
|
||||
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName, std::string schema, int rows, int columns,
|
||||
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName, std::string schema, int rows, int columns,
|
||||
ColNameList& colNameList, TableValuesMap& tableValuesMap, NullValuesBitset& nullValues, int sessionID)
|
||||
:fDMLStatement(dmlstatement), fDMLStatementType(stmttype),
|
||||
: fDMLStatement(dmlstatement), fDMLStatementType(stmttype),
|
||||
fTableName(tName), fSchema(schema), fRows(rows), fColumns(columns),
|
||||
fColNameList(colNameList), fTableValuesMap(tableValuesMap), fNullValues(nullValues), fSessionID(sessionID), fLogging(true),fLogending(true)
|
||||
{}
|
||||
fColNameList(colNameList), fTableValuesMap(tableValuesMap), fNullValues(nullValues), fSessionID(sessionID), fLogging(true), fLogending(true)
|
||||
{}
|
||||
|
||||
VendorDMLStatement::~VendorDMLStatement()
|
||||
{}
|
||||
VendorDMLStatement::~VendorDMLStatement()
|
||||
{}
|
||||
}
|
||||
|
||||
@@ -36,18 +36,18 @@
|
||||
#endif
|
||||
namespace dmlpackage
|
||||
{
|
||||
typedef std::vector<std::string> ColValuesList;
|
||||
typedef std::vector<std::string> ColNameList;
|
||||
typedef std::map<uint32_t, ColValuesList> TableValuesMap;
|
||||
typedef std::bitset<4096> NullValuesBitset;
|
||||
typedef std::vector<std::string> ColValuesList;
|
||||
typedef std::vector<std::string> ColNameList;
|
||||
typedef std::map<uint32_t, ColValuesList> TableValuesMap;
|
||||
typedef std::bitset<4096> NullValuesBitset;
|
||||
|
||||
/** @brief describes the general interface
|
||||
/** @brief describes the general interface
|
||||
* and implementation of a Vendor DML Statement
|
||||
*/
|
||||
class VendorDMLStatement
|
||||
{
|
||||
class VendorDMLStatement
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
/** @brief ctor
|
||||
*/
|
||||
EXPORT VendorDMLStatement(std::string dmlstatement, int sessionID);
|
||||
@@ -73,74 +73,134 @@ namespace dmlpackage
|
||||
|
||||
/** @brief Get the table name
|
||||
*/
|
||||
inline std::string get_TableName() const { return fTableName; }
|
||||
inline std::string get_TableName() const
|
||||
{
|
||||
return fTableName;
|
||||
}
|
||||
|
||||
/** @brief Set the table name
|
||||
*/
|
||||
inline void set_TableName( std::string value ) { fTableName = value; }
|
||||
inline void set_TableName( std::string value )
|
||||
{
|
||||
fTableName = value;
|
||||
}
|
||||
|
||||
/** @brief Get the schema name
|
||||
*/
|
||||
inline std::string get_SchemaName() const { return fSchema; }
|
||||
inline std::string get_SchemaName() const
|
||||
{
|
||||
return fSchema;
|
||||
}
|
||||
|
||||
/** @brief Set the schema name
|
||||
*/
|
||||
inline void set_SchemaName( std::string value ) { fSchema = value; }
|
||||
inline void set_SchemaName( std::string value )
|
||||
{
|
||||
fSchema = value;
|
||||
}
|
||||
|
||||
/** @brief Get the DML statVendorDMLStatement classement type
|
||||
*/
|
||||
inline int get_DMLStatementType() const { return fDMLStatementType; }
|
||||
inline int get_DMLStatementType() const
|
||||
{
|
||||
return fDMLStatementType;
|
||||
}
|
||||
|
||||
/** @brief Set the DML statement type
|
||||
*/
|
||||
inline void set_DMLStatementType( int value ) { fDMLStatementType = value; }
|
||||
inline void set_DMLStatementType( int value )
|
||||
{
|
||||
fDMLStatementType = value;
|
||||
}
|
||||
|
||||
/** @brief Get the DML statement
|
||||
*/
|
||||
inline const std::string get_DMLStatement() const { return fDMLStatement; }
|
||||
inline const std::string get_DMLStatement() const
|
||||
{
|
||||
return fDMLStatement;
|
||||
}
|
||||
|
||||
/** @brief Set the DML statVendorDMLStatement classement
|
||||
*/
|
||||
inline void set_DMLStatement( std::string dmlStatement ) { fDMLStatement = dmlStatement; }
|
||||
inline void set_DMLStatement( std::string dmlStatement )
|
||||
{
|
||||
fDMLStatement = dmlStatement;
|
||||
}
|
||||
|
||||
/** @brief Get the number of rows
|
||||
*/
|
||||
inline int get_Rows() const { return fRows; }
|
||||
inline int get_Rows() const
|
||||
{
|
||||
return fRows;
|
||||
}
|
||||
|
||||
/** @brief Set the number of rows
|
||||
*/
|
||||
inline void set_Rows( int value ) { fRows = value; }
|
||||
inline void set_Rows( int value )
|
||||
{
|
||||
fRows = value;
|
||||
}
|
||||
|
||||
/** @brief Get the number of columns
|
||||
*/
|
||||
inline int get_Columns() const { return fColumns; }
|
||||
inline int get_Columns() const
|
||||
{
|
||||
return fColumns;
|
||||
}
|
||||
|
||||
/** @brief Set the number of columns
|
||||
*/
|
||||
inline void set_Columns( int value ) { fColumns = value; }
|
||||
inline void set_Columns( int value )
|
||||
{
|
||||
fColumns = value;
|
||||
}
|
||||
|
||||
/** @brief Get the data buffer
|
||||
*/
|
||||
inline std::string& get_DataBuffer() { return fDataBuffer; }
|
||||
inline std::string& get_DataBuffer()
|
||||
{
|
||||
return fDataBuffer;
|
||||
}
|
||||
|
||||
/** @brief Set the data buffer
|
||||
*/
|
||||
inline void set_DataBuffer( std::string value ) { fDataBuffer= value; }
|
||||
inline void set_DataBuffer( std::string value )
|
||||
{
|
||||
fDataBuffer = value;
|
||||
}
|
||||
/** @brief Get the session ID
|
||||
*/
|
||||
inline int get_SessionID() { return fSessionID; }
|
||||
inline int get_SessionID()
|
||||
{
|
||||
return fSessionID;
|
||||
}
|
||||
|
||||
inline NullValuesBitset& get_nullValues() { return fNullValues; }
|
||||
inline NullValuesBitset& get_nullValues()
|
||||
{
|
||||
return fNullValues;
|
||||
}
|
||||
|
||||
/** @brief Set the session ID
|
||||
*/
|
||||
inline void set_SessionID( int value ) { fSessionID = value; }
|
||||
inline void set_SessionID( int value )
|
||||
{
|
||||
fSessionID = value;
|
||||
}
|
||||
|
||||
inline ColNameList& get_ColNames() { return fColNameList; }
|
||||
inline TableValuesMap& get_values() { return fTableValuesMap; }
|
||||
inline ColNameList& get_ColNames()
|
||||
{
|
||||
return fColNameList;
|
||||
}
|
||||
inline TableValuesMap& get_values()
|
||||
{
|
||||
return fTableValuesMap;
|
||||
}
|
||||
/** @brief get the logging flag
|
||||
*/
|
||||
inline const bool get_Logging() const { return fLogging; }
|
||||
inline const bool get_Logging() const
|
||||
{
|
||||
return fLogging;
|
||||
}
|
||||
|
||||
/** @brief set the logging flag
|
||||
*
|
||||
@@ -153,7 +213,10 @@ namespace dmlpackage
|
||||
|
||||
/** @brief get the logging flag
|
||||
*/
|
||||
inline const bool get_Logending() const { return fLogending; }
|
||||
inline const bool get_Logending() const
|
||||
{
|
||||
return fLogending;
|
||||
}
|
||||
|
||||
/** @brief set the logending flag
|
||||
*
|
||||
@@ -164,9 +227,9 @@ namespace dmlpackage
|
||||
fLogending = logending;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string fDMLStatement;
|
||||
int fDMLStatementType;
|
||||
std::string fTableName;
|
||||
@@ -181,7 +244,7 @@ namespace dmlpackage
|
||||
bool fLogging;
|
||||
bool fLogending;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ void AutoincrementData::removeAutoincrementData(uint32_t sessionID)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(map_mutex);
|
||||
AutoincDataMap::iterator it = fAutoincDataMap.find(sessionID);
|
||||
|
||||
if (it != fAutoincDataMap.end())
|
||||
{
|
||||
delete (*it).second;
|
||||
@@ -81,14 +82,16 @@ long long AutoincrementData::getNextValue(uint32_t columnOid)
|
||||
boost::mutex::scoped_lock lk(fOIDnextvalLock);
|
||||
long long nextValue = 0;
|
||||
OIDNextValue::iterator it = fOidNextValueMap.find(columnOid);
|
||||
|
||||
if (it != fOidNextValueMap.end())
|
||||
{
|
||||
nextValue = it->second;
|
||||
}
|
||||
|
||||
return nextValue;
|
||||
}
|
||||
|
||||
AutoincrementData::OIDNextValue & AutoincrementData::getOidNextValueMap()
|
||||
AutoincrementData::OIDNextValue& AutoincrementData::getOidNextValueMap()
|
||||
{
|
||||
boost::mutex::scoped_lock lk(fOIDnextvalLock);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
static void removeAutoincrementData(uint32_t sessionID = 0);
|
||||
void setNextValue(uint32_t columnOid, long long nextValue);
|
||||
long long getNextValue(uint32_t columnOid);
|
||||
OIDNextValue & getOidNextValueMap();
|
||||
OIDNextValue& getOidNextValueMap();
|
||||
|
||||
private:
|
||||
/** Constuctors */
|
||||
|
||||
@@ -49,11 +49,11 @@ using namespace BRM;
|
||||
|
||||
namespace dmlpackageprocessor
|
||||
{
|
||||
// Tracks active cleartablelock commands by storing set of table lock IDs
|
||||
/*static*/ std::set<uint64_t>
|
||||
CommandPackageProcessor::fActiveClearTableLockCmds;
|
||||
/*static*/ boost::mutex
|
||||
CommandPackageProcessor::fActiveClearTableLockCmdMutex;
|
||||
// Tracks active cleartablelock commands by storing set of table lock IDs
|
||||
/*static*/ std::set<uint64_t>
|
||||
CommandPackageProcessor::fActiveClearTableLockCmds;
|
||||
/*static*/ boost::mutex
|
||||
CommandPackageProcessor::fActiveClearTableLockCmdMutex;
|
||||
|
||||
DMLPackageProcessor::DMLResult
|
||||
CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
@@ -70,8 +70,10 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
fSessionID = cpackage.get_SessionID();
|
||||
BRM::TxnID txnid = fSessionManager.getTxnID(cpackage.get_SessionID());
|
||||
uint64_t uniqueId = 0;
|
||||
|
||||
//Bug 5070. Added exception handling
|
||||
try {
|
||||
try
|
||||
{
|
||||
uniqueId = fDbrm->getUnique64();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
@@ -105,6 +107,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
logging::Message::Args args1;
|
||||
logging::Message msg(1);
|
||||
Logger logger(logid.fSubsysID);
|
||||
|
||||
if (stmt != "CLEANUP")
|
||||
{
|
||||
args1.add("Start SQL statement: ");
|
||||
@@ -112,6 +115,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
msg.format( args1 );
|
||||
logger.logMessage(LOG_TYPE_DEBUG, msg, logid);
|
||||
}
|
||||
|
||||
//fWEClient->addQueue(uniqueId);
|
||||
try
|
||||
{
|
||||
@@ -125,6 +129,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
vector<LBID_t> lbidList;
|
||||
fDbrm->getUncommittedExtentLBIDs(static_cast<VER_t>(txnid.id), lbidList);
|
||||
bool cpInvalidated = false;
|
||||
|
||||
//cout << "get a valid txnid " << txnid.id << " and stmt is " << stmt << " and isBachinsert is " << cpackage.get_isBatchInsert() << endl;
|
||||
if ((stmt == "COMMIT") && (cpackage.get_isBatchInsert()))
|
||||
{
|
||||
@@ -132,9 +137,11 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(fSessionID);
|
||||
CalpontSystemCatalog::TableName tableName;
|
||||
tableName = systemCatalogPtr->tableName(cpackage.getTableOid());
|
||||
|
||||
try
|
||||
{
|
||||
uint64_t nextVal = systemCatalogPtr->nextAutoIncrValue(tableName);
|
||||
|
||||
if (nextVal != AUTOINCR_SATURATED) //need to update syscolumn
|
||||
{
|
||||
//get autoincrement column oid
|
||||
@@ -146,6 +153,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
aDbrm->getAILock(columnOid);
|
||||
nextVal = systemCatalogPtr->nextAutoIncrValue(tableName); //in case it has changed
|
||||
validNextVal = aDbrm->getAIValue(columnOid, &nextValInController);
|
||||
|
||||
if ((validNextVal) && (nextValInController > nextVal))
|
||||
{
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
@@ -154,6 +162,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
uint8_t rc = ddlClient.UpdateSyscolumnNextval(columnOid, nextValInController);
|
||||
//@bug 5894. Need release lock.
|
||||
aDbrm->releaseAILock(columnOid);
|
||||
|
||||
if (rc != 0)
|
||||
throw std::runtime_error("Error in UpdateSyscolumnNextval");
|
||||
}
|
||||
@@ -168,20 +177,26 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
fSessionManager.rolledback( txnid );
|
||||
throw std::runtime_error(ex.what());
|
||||
}
|
||||
|
||||
//systemCatalogPtr->updateColinfoCache(nextValMap);
|
||||
int weRc = 0;
|
||||
|
||||
if (cpackage.get_isAutocommitOn())
|
||||
{
|
||||
weRc = commitBatchAutoOnTransaction(uniqueId, txnid, cpackage.getTableOid(), errorMsg);
|
||||
|
||||
if (weRc != 0)
|
||||
BRM::errString(weRc, errorMsg);
|
||||
|
||||
cpInvalidated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
weRc = fDbrm->vbCommit(txnid.id);
|
||||
|
||||
if (weRc != 0)
|
||||
BRM::errString(weRc, errorMsg);
|
||||
|
||||
//weRc = commitBatchAutoOffTransaction(uniqueId, txnid, cpackage.getTableOid(), errorMsg);
|
||||
}
|
||||
|
||||
@@ -189,6 +204,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
{
|
||||
throw std::runtime_error(errorMsg);
|
||||
}
|
||||
|
||||
logging::logCommand(cpackage.get_SessionID(), txnid.id, "COMMIT;");
|
||||
fSessionManager.committed( txnid );
|
||||
//cout << "releasing transaction id for batchinsert" << txnid.id << endl;
|
||||
@@ -201,22 +217,27 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
CalpontSystemCatalog::TableName tableName;
|
||||
uint32_t tableOid = cpackage.getTableOid();
|
||||
std::vector<TableLockInfo> tableLocks = fDbrm->getAllTableLocks();
|
||||
|
||||
if (tableOid == 0) //special case: transaction commit for autocommit off and not following a dml statement immediately
|
||||
{
|
||||
TablelockData * tablelockData = TablelockData::makeTablelockData(fSessionID);
|
||||
TablelockData* tablelockData = TablelockData::makeTablelockData(fSessionID);
|
||||
TablelockData::OIDTablelock tablelockMap = tablelockData->getOidTablelockMap();
|
||||
TablelockData::OIDTablelock::iterator iter;
|
||||
|
||||
if (!tablelockMap.empty())
|
||||
{
|
||||
for ( unsigned k=0; k < tableLocks.size(); k++)
|
||||
for ( unsigned k = 0; k < tableLocks.size(); k++)
|
||||
{
|
||||
iter = tablelockMap.find(tableLocks[k].tableOID);
|
||||
|
||||
if ( iter != tablelockMap.end() )
|
||||
{
|
||||
tableName = systemCatalogPtr->tableName(tableLocks[k].tableOID);
|
||||
|
||||
try
|
||||
{
|
||||
uint64_t nextVal = systemCatalogPtr->nextAutoIncrValue(tableName);
|
||||
|
||||
if (nextVal != AUTOINCR_SATURATED) //neet to update syscolumn
|
||||
{
|
||||
//get autoincrement column oid
|
||||
@@ -235,8 +256,9 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
|
||||
queRemoved = true;
|
||||
WE_DDLCommandClient ddlClient;
|
||||
uint8_t rc = ddlClient.UpdateSyscolumnNextval(columnOid, nextValInController,fSessionID);
|
||||
uint8_t rc = ddlClient.UpdateSyscolumnNextval(columnOid, nextValInController, fSessionID);
|
||||
aDbrm->releaseAILock(columnOid);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
//for now
|
||||
@@ -266,9 +288,11 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
if (tableOid >= 3000)
|
||||
{
|
||||
tableName = systemCatalogPtr->tableName(tableOid);
|
||||
|
||||
try
|
||||
{
|
||||
uint64_t nextVal = systemCatalogPtr->nextAutoIncrValue(tableName);
|
||||
|
||||
if (nextVal != AUTOINCR_SATURATED) //need to update syscolumn
|
||||
{
|
||||
//get autoincrement column oid
|
||||
@@ -280,14 +304,16 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
aDbrm->getAILock(columnOid);
|
||||
nextVal = systemCatalogPtr->nextAutoIncrValue(tableName); //in case it has changed
|
||||
validNextVal = aDbrm->getAIValue(columnOid, &nextValInController);
|
||||
|
||||
if ((validNextVal) && (nextValInController > (uint64_t)nextVal))
|
||||
{
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
|
||||
queRemoved = true;
|
||||
WE_DDLCommandClient ddlClient;
|
||||
uint8_t rc = ddlClient.UpdateSyscolumnNextval(columnOid, nextValInController,fSessionID);
|
||||
uint8_t rc = ddlClient.UpdateSyscolumnNextval(columnOid, nextValInController, fSessionID);
|
||||
aDbrm->releaseAILock(columnOid);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
//for now
|
||||
@@ -303,22 +329,26 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
{
|
||||
//Rollback transaction, release tablelock
|
||||
rollBackTransaction(uniqueId, txnid, fSessionID, errorMsg);
|
||||
for ( unsigned k=0; k < tableLocks.size(); k++)
|
||||
|
||||
for ( unsigned k = 0; k < tableLocks.size(); k++)
|
||||
{
|
||||
if ( tableLocks[k].tableOID == tableOid )
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
fDbrm->releaseTableLock(tableLocks[k].id);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
||||
fSessionManager.rolledback( txnid );
|
||||
throw std::runtime_error(ex.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int weRc = commitTransaction(uniqueId, txnid );
|
||||
logging::logCommand(cpackage.get_SessionID(), txnid.id, "COMMIT;");
|
||||
|
||||
@@ -330,6 +360,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
oss << "COMMIT failed: " << ec.errorString(weRc);
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
|
||||
fSessionManager.committed( txnid );
|
||||
//cout << "commit releasing transaction id " << txnid.id << endl;
|
||||
}
|
||||
@@ -340,6 +371,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
|
||||
//version rollback, Bulkrollback
|
||||
weRc = rollBackTransaction(uniqueId, txnid, fSessionID, errorMsg);
|
||||
|
||||
if (weRc == 0)
|
||||
{
|
||||
//@Bug 4560 invalidate cp first as bulkrollback will truncate the newly added lbids.
|
||||
@@ -354,6 +386,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
}
|
||||
|
||||
logging::logCommand(cpackage.get_SessionID(), txnid.id, "ROLLBACK;");
|
||||
|
||||
if (weRc != 0)
|
||||
{
|
||||
//@Bug 4524. Don't set to readonly. Just error out.
|
||||
@@ -368,6 +401,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
ml.logErrorMessage( message1 );
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
|
||||
fSessionManager.rolledback( txnid );
|
||||
//cout << "batch rollback releasing transaction id " << txnid.id << endl;
|
||||
}
|
||||
@@ -376,6 +410,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
std::string errorMsg("");
|
||||
logging::logCommand(cpackage.get_SessionID(), txnid.id, "ROLLBACK;");
|
||||
int weRc = rollBackTransaction(uniqueId, txnid, fSessionID, errorMsg);
|
||||
|
||||
if (weRc != 0)
|
||||
{
|
||||
//cout << "Rollback failed" << endl;
|
||||
@@ -390,6 +425,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
ml.logErrorMessage( message2 );
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
|
||||
fSessionManager.rolledback( txnid );
|
||||
//cout << "Rollback releasing transaction id " << txnid.id << endl;
|
||||
}
|
||||
@@ -418,7 +454,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
else if ( !cpackage.get_Logging())
|
||||
{
|
||||
BRM::TxnID txnid = fSessionManager.getTxnID(cpackage.get_SessionID());
|
||||
logging::logDML(cpackage.get_SessionID(), txnid.id, cpackage.get_DMLStatement()+ ";", cpackage.get_SchemaName());
|
||||
logging::logDML(cpackage.get_SessionID(), txnid.id, cpackage.get_DMLStatement() + ";", cpackage.get_SchemaName());
|
||||
SQLLogger sqlLogger(cpackage.get_DMLStatement(), DMLLoggingId, fSessionID, txnid.id);
|
||||
//cout << "commandpackageprocessor Logging " << cpackage.get_DMLStatement()+ ";" << endl;
|
||||
}
|
||||
@@ -465,23 +501,26 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
result.result = COMMAND_ERROR;
|
||||
result.message = message;
|
||||
}
|
||||
|
||||
if (!queRemoved)
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
|
||||
//release table lock
|
||||
if ((result.result == NO_ERROR) && ((stmt == "COMMIT") || (stmt == "ROLLBACK")) )
|
||||
{
|
||||
TablelockData * tablelockData = TablelockData::makeTablelockData(fSessionID);
|
||||
TablelockData* tablelockData = TablelockData::makeTablelockData(fSessionID);
|
||||
TablelockData::OIDTablelock tablelockMap = tablelockData->getOidTablelockMap();
|
||||
bool lockReleased = true;
|
||||
|
||||
if (!tablelockMap.empty())
|
||||
{
|
||||
TablelockData::OIDTablelock::iterator it = tablelockMap.begin();
|
||||
|
||||
while (it != tablelockMap.end())
|
||||
{
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
lockReleased = fDbrm->releaseTableLock(it->second);
|
||||
//cout << "releasing tablelock " << it->second << endl;
|
||||
}
|
||||
@@ -497,6 +536,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
result.result = COMMAND_ERROR;
|
||||
result.message = message;
|
||||
}
|
||||
|
||||
if (!lockReleased) //log an error
|
||||
{
|
||||
ostringstream os;
|
||||
@@ -512,18 +552,22 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
|
||||
ml.logErrorMessage(message);
|
||||
}
|
||||
|
||||
//cout << "tablelock " << it->second << " is released" << endl;
|
||||
it++;
|
||||
}
|
||||
|
||||
//@Bug 3557. Clean tablelock cache after commit/rollback.
|
||||
TablelockData::removeTablelockData(cpackage.get_SessionID());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
VERBOSE_INFO("Finished processing Command DML Package");
|
||||
//LoggingID logid( DMLLoggingId, fSessionID, txnid.id);
|
||||
logging::Message::Args args2;
|
||||
logging::Message msg1(1);
|
||||
|
||||
if (stmt != "CLEANUP")
|
||||
{
|
||||
args2.add("End SQL statement");
|
||||
@@ -531,6 +575,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
//Logger logger(logid.fSubsysID);
|
||||
logger.logMessage(LOG_TYPE_DEBUG, msg1, logid);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -572,74 +617,94 @@ void CommandPackageProcessor::viewTableLock(
|
||||
unsigned int pidColumnWidth = 3; // "PID"
|
||||
unsigned int sessionIDColumnWidth = 7; // "Session"
|
||||
unsigned int txnIDColumnWidth = 3; // "Txn"
|
||||
unsigned int createTimeColumnWidth= 12;// "CreationTime"
|
||||
unsigned int createTimeColumnWidth = 12; // "CreationTime"
|
||||
unsigned int pmColumnWidth = 7; // "DBRoots"
|
||||
std::vector<std::string> createTimes;
|
||||
char cTimeBuffer[1024];
|
||||
|
||||
for (unsigned idx=0; idx<tableLocks.size(); idx++)
|
||||
for (unsigned idx = 0; idx < tableLocks.size(); idx++)
|
||||
{
|
||||
if (tableLocks[idx].id > maxLockID)
|
||||
maxLockID = tableLocks[idx].id;
|
||||
|
||||
if (tableLocks[idx].ownerName.length() > ownerColumnWidth)
|
||||
ownerColumnWidth = tableLocks[idx].ownerName.length();
|
||||
|
||||
if (tableLocks[idx].ownerPID > maxPID)
|
||||
maxPID = tableLocks[idx].ownerPID;
|
||||
|
||||
if (tableLocks[idx].ownerSessionID > maxSessionID)
|
||||
maxSessionID = tableLocks[idx].ownerSessionID;
|
||||
|
||||
if (tableLocks[idx].ownerSessionID < minSessionID)
|
||||
minSessionID = tableLocks[idx].ownerSessionID;
|
||||
|
||||
if (tableLocks[idx].ownerTxnID > maxTxnID)
|
||||
maxTxnID = tableLocks[idx].ownerTxnID;
|
||||
|
||||
ctime_r( &tableLocks[idx].creationTime, cTimeBuffer );
|
||||
cTimeBuffer[ strlen(cTimeBuffer)-1 ] = '\0'; // strip trailing '\n'
|
||||
cTimeBuffer[ strlen(cTimeBuffer) - 1 ] = '\0'; // strip trailing '\n'
|
||||
std::string cTimeStr( cTimeBuffer );
|
||||
|
||||
if (cTimeStr.length() > createTimeColumnWidth)
|
||||
createTimeColumnWidth = cTimeStr.length();
|
||||
|
||||
createTimes.push_back( cTimeStr );
|
||||
|
||||
std::ostringstream pms; //It is dbroots now
|
||||
for (unsigned k=0; k<tableLocks[idx].dbrootList.size(); k++)
|
||||
|
||||
for (unsigned k = 0; k < tableLocks[idx].dbrootList.size(); k++)
|
||||
{
|
||||
if (k > 0)
|
||||
pms << ',';
|
||||
|
||||
pms << tableLocks[idx].dbrootList[k];
|
||||
}
|
||||
|
||||
if (pms.str().length() > pmColumnWidth)
|
||||
pmColumnWidth = pms.str().length();
|
||||
}
|
||||
|
||||
ownerColumnWidth += 2;
|
||||
pmColumnWidth += 2;
|
||||
createTimeColumnWidth += 2;
|
||||
|
||||
std::ostringstream idString;
|
||||
idString << maxLockID;
|
||||
|
||||
if (idString.str().length() > lockIDColumnWidth)
|
||||
lockIDColumnWidth = idString.str().length();
|
||||
|
||||
lockIDColumnWidth += 2;
|
||||
|
||||
std::ostringstream pidString;
|
||||
pidString << maxPID;
|
||||
|
||||
if (pidString.str().length() > pidColumnWidth)
|
||||
pidColumnWidth = pidString.str().length();
|
||||
|
||||
pidColumnWidth += 2;
|
||||
|
||||
const std::string sessionNoneStr("BulkLoad");
|
||||
std::ostringstream sessionString;
|
||||
sessionString << maxSessionID;
|
||||
|
||||
if (sessionString.str().length() > sessionIDColumnWidth)
|
||||
sessionIDColumnWidth = sessionString.str().length();
|
||||
|
||||
if ((minSessionID < 0) &&
|
||||
(sessionNoneStr.length() > sessionIDColumnWidth))
|
||||
sessionIDColumnWidth = sessionNoneStr.length();
|
||||
|
||||
sessionIDColumnWidth += 2;
|
||||
|
||||
const std::string txnNoneStr("n/a");
|
||||
std::ostringstream txnString;
|
||||
txnString << maxTxnID;
|
||||
|
||||
if (txnString.str().length() > txnIDColumnWidth)
|
||||
txnIDColumnWidth = txnString.str().length();
|
||||
|
||||
txnIDColumnWidth += 2;
|
||||
|
||||
// Make second pass through the table locks to build our result.
|
||||
@@ -647,16 +712,19 @@ void CommandPackageProcessor::viewTableLock(
|
||||
// (on different PMs), so we don't exit loop after "first" match.
|
||||
bool found = false;
|
||||
ostringstream os;
|
||||
for (unsigned idx=0; idx<tableLocks.size(); idx++)
|
||||
|
||||
for (unsigned idx = 0; idx < tableLocks.size(); idx++)
|
||||
{
|
||||
if (roPair.objnum == (CalpontSystemCatalog::OID)
|
||||
tableLocks[idx].tableOID)
|
||||
{
|
||||
std::ostringstream pms;
|
||||
for (unsigned k=0; k<tableLocks[idx].dbrootList.size(); k++)
|
||||
|
||||
for (unsigned k = 0; k < tableLocks[idx].dbrootList.size(); k++)
|
||||
{
|
||||
if (k > 0)
|
||||
pms << ',';
|
||||
|
||||
pms << tableLocks[idx].dbrootList[k];
|
||||
}
|
||||
|
||||
@@ -672,14 +740,14 @@ void CommandPackageProcessor::viewTableLock(
|
||||
setw(pidColumnWidth) << "PID" <<
|
||||
setw(sessionIDColumnWidth) << "Session" <<
|
||||
setw(txnIDColumnWidth) << "Txn" <<
|
||||
setw(createTimeColumnWidth)<< "CreationTime" <<
|
||||
setw(createTimeColumnWidth) << "CreationTime" <<
|
||||
setw(9) << "State" <<
|
||||
setw(pmColumnWidth) << "DBRoots" << endl;
|
||||
}
|
||||
|
||||
os << " " <<
|
||||
setw(lockIDColumnWidth) << tableLocks[idx].id <<
|
||||
setw(ownerColumnWidth) << tableLocks[idx].ownerName<<
|
||||
setw(ownerColumnWidth) << tableLocks[idx].ownerName <<
|
||||
setw(pidColumnWidth) << tableLocks[idx].ownerPID;
|
||||
|
||||
// Log session ID, or "BulkLoad" if session is -1
|
||||
@@ -696,9 +764,9 @@ void CommandPackageProcessor::viewTableLock(
|
||||
os << setw(txnIDColumnWidth) <<
|
||||
tableLocks[idx].ownerTxnID;
|
||||
|
||||
os << setw(createTimeColumnWidth)<<
|
||||
os << setw(createTimeColumnWidth) <<
|
||||
createTimes[idx] <<
|
||||
setw(9) << ((tableLocks[idx].state==BRM::LOADING) ?
|
||||
setw(9) << ((tableLocks[idx].state == BRM::LOADING) ?
|
||||
"LOADING" : "CLEANUP") <<
|
||||
setw(pmColumnWidth) << pms.str();
|
||||
|
||||
@@ -759,9 +827,11 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
|
||||
bool bRemoveMetaErrFlag = false;
|
||||
std::ostringstream combinedErrMsg;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
// Make sure BRM is in READ-WRITE state before starting
|
||||
int brmRc = fDbrm->isReadWrite( );
|
||||
|
||||
if (brmRc != BRM::ERR_OK)
|
||||
{
|
||||
std::string brmErrMsg;
|
||||
@@ -777,14 +847,15 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
|
||||
|
||||
oam::OamCache* oamCache = oam::OamCache::makeOamCache();
|
||||
oam::OamCache::dbRootPMMap_t dbRootPmMap = oamCache->getDBRootToPMMap();
|
||||
std::map<int,int>::const_iterator mapIter;
|
||||
std::map<int, int>::const_iterator mapIter;
|
||||
std::set<int> pmSet;
|
||||
|
||||
// Construct relevant list of PMs based on the DBRoots associated
|
||||
// with the tableLock.
|
||||
for (unsigned int k=0; k<lockInfo.dbrootList.size(); k++)
|
||||
for (unsigned int k = 0; k < lockInfo.dbrootList.size(); k++)
|
||||
{
|
||||
mapIter = dbRootPmMap->find( lockInfo.dbrootList[k] );
|
||||
|
||||
if (mapIter != dbRootPmMap->end())
|
||||
{
|
||||
int pm = mapIter->second;
|
||||
@@ -800,6 +871,7 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
|
||||
}
|
||||
|
||||
std::vector<int> pmList;
|
||||
|
||||
for (std::set<int>::const_iterator setIter = pmSet.begin();
|
||||
setIter != pmSet.end();
|
||||
++setIter)
|
||||
@@ -809,12 +881,15 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
|
||||
|
||||
std::cout << "cleartablelock rollback for table lock " << tableLockID <<
|
||||
" being forwarded to PM(s): ";
|
||||
for (unsigned int k=0; k<pmList.size(); k++)
|
||||
|
||||
for (unsigned int k = 0; k < pmList.size(); k++)
|
||||
{
|
||||
if (k > 0)
|
||||
std::cout << ", ";
|
||||
|
||||
std::cout << pmList[k];
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
// Perform bulk rollback if state is in LOADING state
|
||||
@@ -839,23 +914,28 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
|
||||
bsOut << lockInfo.tableOID;
|
||||
bsOut << tableName.toString();
|
||||
bsOut << APPLNAME;
|
||||
for (unsigned j=0; j<pmList.size(); j++)
|
||||
|
||||
for (unsigned j = 0; j < pmList.size(); j++)
|
||||
{
|
||||
fWEClient->write(bsOut, pmList[j]);
|
||||
}
|
||||
|
||||
// Wait for "all" the responses, and accumulate any/all errors
|
||||
unsigned int pmMsgCnt = 0;
|
||||
|
||||
while (pmMsgCnt < pmList.size())
|
||||
{
|
||||
std::string rollbackErrMsg;
|
||||
bsIn.reset(new messageqcpp::ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if (bsIn->length() == 0)
|
||||
{
|
||||
bRemoveMetaErrFlag = true;
|
||||
|
||||
if (combinedErrMsg.str().length() > 0)
|
||||
combinedErrMsg << std::endl;
|
||||
|
||||
combinedErrMsg << "Network error, PM rollback; ";
|
||||
}
|
||||
else
|
||||
@@ -873,14 +953,17 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
|
||||
if (rc != 0)
|
||||
{
|
||||
bRemoveMetaErrFlag = true;
|
||||
|
||||
if (combinedErrMsg.str().empty())
|
||||
combinedErrMsg << "Rollback error; ";
|
||||
else
|
||||
combinedErrMsg << std::endl;
|
||||
|
||||
combinedErrMsg << "[PM" << pmNum << "] " <<
|
||||
rollbackErrMsg;
|
||||
}
|
||||
}
|
||||
|
||||
pmMsgCnt++;
|
||||
} // end of while loop to process all responses to bulk rollback
|
||||
|
||||
@@ -909,23 +992,28 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
|
||||
WE_SVR_DML_BULKROLLBACK_CLEANUP;
|
||||
bsOut << uniqueId;
|
||||
bsOut << lockInfo.tableOID;
|
||||
for (unsigned j=0; j<pmList.size(); j++)
|
||||
|
||||
for (unsigned j = 0; j < pmList.size(); j++)
|
||||
{
|
||||
fWEClient->write(bsOut, pmList[j]);
|
||||
}
|
||||
|
||||
// Wait for "all" the responses, and accumulate any/all errors
|
||||
unsigned int pmMsgCnt = 0;
|
||||
|
||||
while (pmMsgCnt < pmList.size())
|
||||
{
|
||||
std::string fileDeleteErrMsg;
|
||||
bsIn.reset(new messageqcpp::ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if (bsIn->length() == 0)
|
||||
{
|
||||
bRemoveMetaErrFlag = true;
|
||||
|
||||
if (combinedErrMsg.str().length() > 0)
|
||||
combinedErrMsg << std::endl;
|
||||
|
||||
combinedErrMsg << "Network error, PM rollback cleanup; ";
|
||||
}
|
||||
else
|
||||
@@ -943,14 +1031,17 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
|
||||
if (rc != 0)
|
||||
{
|
||||
bRemoveMetaErrFlag = true;
|
||||
|
||||
if (combinedErrMsg.str().empty())
|
||||
combinedErrMsg << "Cleanup error; ";
|
||||
else
|
||||
combinedErrMsg << std::endl;
|
||||
|
||||
combinedErrMsg << "[PM" << pmNum << "] " <<
|
||||
fileDeleteErrMsg;
|
||||
}
|
||||
}
|
||||
|
||||
pmMsgCnt++;
|
||||
} // end of while loop to process all responses to rollback cleanup
|
||||
|
||||
@@ -972,11 +1063,13 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
|
||||
std::ostringstream oss;
|
||||
oss << "Table lock " << tableLockID << " for table " <<
|
||||
tableName.toString() << " is cleared.";
|
||||
|
||||
//@Bug 4517. Release tablelock if remove meta files failed.
|
||||
if (bRemoveMetaErrFlag)
|
||||
{
|
||||
oss << " Warning: " << combinedErrMsg.str();
|
||||
}
|
||||
|
||||
result.tableLockInfo = oss.str();
|
||||
}
|
||||
else
|
||||
@@ -1006,6 +1099,7 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
|
||||
msgArgs.add( tableName.toString() );
|
||||
msgArgs.add( tableLockID );
|
||||
std::string finalStatus;
|
||||
|
||||
if (!bErrFlag)
|
||||
{
|
||||
finalStatus = "Completed successfully";
|
||||
@@ -1015,6 +1109,7 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
|
||||
finalStatus = "Encountered errors: ";
|
||||
finalStatus += combinedErrMsg.str();
|
||||
}
|
||||
|
||||
msgArgs.add( finalStatus );
|
||||
logMsg2.format( msgArgs );
|
||||
ml.logInfoMessage( logMsg2 );
|
||||
@@ -1048,6 +1143,7 @@ void CommandPackageProcessor::establishTableLockToClear( uint64_t tableLockID,
|
||||
{
|
||||
std::set<uint64_t>::const_iterator it =
|
||||
fActiveClearTableLockCmds.find( tableLockID );
|
||||
|
||||
if (it != fActiveClearTableLockCmds.end())
|
||||
{
|
||||
throw std::runtime_error( std::string( "Lock in use. "
|
||||
@@ -1063,6 +1159,7 @@ void CommandPackageProcessor::establishTableLockToClear( uint64_t tableLockID,
|
||||
int32_t txnid = -1;
|
||||
bool ownerChanged = fDbrm->changeOwner(
|
||||
tableLockID, processName, processID, sessionID, txnid);
|
||||
|
||||
if (!ownerChanged)
|
||||
{
|
||||
throw std::runtime_error( std::string(
|
||||
|
||||
@@ -50,7 +50,7 @@ class CommandPackageProcessor : public DMLPackageProcessor
|
||||
{
|
||||
|
||||
public:
|
||||
CommandPackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid){}
|
||||
CommandPackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid) {}
|
||||
/** @brief process an CommandDMLPackage
|
||||
*
|
||||
* @param cpackage the CommandDMLPackage to process
|
||||
|
||||
130
dbcon/dmlpackageproc/deletepackageprocessor.cpp
Executable file → Normal file
130
dbcon/dmlpackageproc/deletepackageprocessor.cpp
Executable file → Normal file
@@ -57,9 +57,9 @@ using namespace messageqcpp;
|
||||
using namespace oam;
|
||||
namespace dmlpackageprocessor
|
||||
{
|
||||
DMLPackageProcessor::DMLResult
|
||||
DeletePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
{
|
||||
DMLPackageProcessor::DMLResult
|
||||
DeletePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
{
|
||||
SUMMARY_INFO("DeletePackageProcessor::processPackage");
|
||||
|
||||
DMLResult result;
|
||||
@@ -71,10 +71,12 @@ namespace dmlpackageprocessor
|
||||
fSessionID = cpackage.get_SessionID();
|
||||
//StopWatch timer;
|
||||
VERBOSE_INFO("DeletePackageProcessor is processing CalpontDMLPackage ...");
|
||||
TablelockData * tablelockData = TablelockData::makeTablelockData(fSessionID);
|
||||
TablelockData* tablelockData = TablelockData::makeTablelockData(fSessionID);
|
||||
uint64_t uniqueId = 0;
|
||||
|
||||
//Bug 5070. Added exception handling
|
||||
try {
|
||||
try
|
||||
{
|
||||
uniqueId = fDbrm->getUnique64();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
@@ -111,6 +113,7 @@ namespace dmlpackageprocessor
|
||||
aTableName.schema = schemaName;
|
||||
fWEClient->addQueue(uniqueId);
|
||||
execplan::CalpontSystemCatalog::ROPair roPair;
|
||||
|
||||
try
|
||||
{
|
||||
string stmt = cpackage.get_SQLStatement() + "|" + schemaName + "|";
|
||||
@@ -122,6 +125,7 @@ namespace dmlpackageprocessor
|
||||
roPair = csc->tableRID(aTableName);
|
||||
|
||||
tableLockId = tablelockData->getTablelockId(roPair.objnum); //check whether this table is locked already for this session
|
||||
|
||||
if (tableLockId == 0)
|
||||
{
|
||||
//cout << "tablelock is not found in cache " << endl;
|
||||
@@ -130,15 +134,17 @@ namespace dmlpackageprocessor
|
||||
std::string processName("DMLProc");
|
||||
int32_t sessionId = fSessionID;
|
||||
int i = 0;
|
||||
OamCache * oamcache = OamCache::makeOamCache();
|
||||
OamCache* oamcache = OamCache::makeOamCache();
|
||||
std::vector<int> pmList = oamcache->getModuleIds();
|
||||
std::vector<uint32_t> pms;
|
||||
for (unsigned i=0; i < pmList.size(); i++)
|
||||
|
||||
for (unsigned i = 0; i < pmList.size(); i++)
|
||||
{
|
||||
pms.push_back((uint32_t)pmList[i]);
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnId, BRM::LOADING );
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -155,8 +161,8 @@ namespace dmlpackageprocessor
|
||||
numTries = waitPeriod * 10;
|
||||
struct timespec rm_ts;
|
||||
|
||||
rm_ts.tv_sec = sleepTime/1000;
|
||||
rm_ts.tv_nsec = sleepTime%1000 *1000000;
|
||||
rm_ts.tv_sec = sleepTime / 1000;
|
||||
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
|
||||
|
||||
for (; i < numTries; i++)
|
||||
{
|
||||
@@ -164,14 +170,18 @@ namespace dmlpackageprocessor
|
||||
Sleep(rm_ts.tv_sec * 1000);
|
||||
#else
|
||||
struct timespec abs_ts;
|
||||
|
||||
do
|
||||
{
|
||||
abs_ts.tv_sec = rm_ts.tv_sec;
|
||||
abs_ts.tv_nsec = rm_ts.tv_nsec;
|
||||
}
|
||||
while(nanosleep(&abs_ts,&rm_ts) < 0);
|
||||
while (nanosleep(&abs_ts, &rm_ts) < 0);
|
||||
|
||||
#endif
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
processID = ::getpid();
|
||||
txnId = txnid.id;
|
||||
sessionId = fSessionID;
|
||||
@@ -196,7 +206,7 @@ namespace dmlpackageprocessor
|
||||
args.add(processName);
|
||||
args.add((uint64_t)processID);
|
||||
args.add(sessionId);
|
||||
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED,args));
|
||||
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,6 +217,7 @@ namespace dmlpackageprocessor
|
||||
const CalpontSystemCatalog::RIDList ridList = csc->columnRIDs(aTableName);
|
||||
CalpontSystemCatalog::RIDList::const_iterator rid_iterator = ridList.begin();
|
||||
CalpontSystemCatalog::ColType colType;
|
||||
|
||||
while (rid_iterator != ridList.end())
|
||||
{
|
||||
// If user hit ctrl+c in the mysql console, fRollbackPending will be true.
|
||||
@@ -215,8 +226,10 @@ namespace dmlpackageprocessor
|
||||
result.result = JOB_CANCELED;
|
||||
break;
|
||||
}
|
||||
|
||||
CalpontSystemCatalog::ROPair roPair = *rid_iterator;
|
||||
colType = csc->colType(roPair.objnum);
|
||||
|
||||
if (colType.autoincrement)
|
||||
{
|
||||
try
|
||||
@@ -231,12 +244,14 @@ namespace dmlpackageprocessor
|
||||
throw std::runtime_error(ex.what());
|
||||
}
|
||||
}
|
||||
|
||||
++rid_iterator;
|
||||
}
|
||||
|
||||
uint64_t rowsProcessed = 0;
|
||||
|
||||
rowsProcessed = fixUpRows(cpackage, result, uniqueId, roPair.objnum);
|
||||
|
||||
//@Bug 4994 Cancelled job is not error
|
||||
if (result.result == JOB_CANCELED)
|
||||
throw std::runtime_error("Query execution was interrupted");
|
||||
@@ -259,6 +274,7 @@ namespace dmlpackageprocessor
|
||||
{
|
||||
result.result = DELETE_ERROR;
|
||||
}
|
||||
|
||||
result.message = Message(ex.what());
|
||||
}
|
||||
catch (...)
|
||||
@@ -275,16 +291,20 @@ namespace dmlpackageprocessor
|
||||
result.result = DELETE_ERROR;
|
||||
result.message = message;
|
||||
}
|
||||
|
||||
//timer.finish();
|
||||
//@Bug 1886,2870 Flush VM cache only once per statement.
|
||||
std::map<uint32_t,uint32_t> oids;
|
||||
std::map<uint32_t, uint32_t> oids;
|
||||
int rc = 0;
|
||||
|
||||
if (result.result == NO_ERROR)
|
||||
{
|
||||
rc = flushDataFiles( result.result, oids, uniqueId, txnid, roPair.objnum);
|
||||
|
||||
if (rc != NO_ERROR)
|
||||
{
|
||||
cerr << "UpdatePackageProcessor::processPackage: write data to disk failed" << endl;
|
||||
|
||||
if (!fRollbackPending)
|
||||
{
|
||||
logging::Message::Args args;
|
||||
@@ -298,8 +318,10 @@ namespace dmlpackageprocessor
|
||||
result.result = UPDATE_ERROR;
|
||||
result.message = message;
|
||||
}
|
||||
|
||||
result.rowCount = 0;
|
||||
rc = endTransaction(uniqueId, txnid, false);
|
||||
|
||||
if ( (rc != NO_ERROR) && (!fRollbackPending))
|
||||
{
|
||||
logging::Message::Args args;
|
||||
@@ -344,10 +366,10 @@ namespace dmlpackageprocessor
|
||||
|
||||
VERBOSE_INFO("Finished Processing Delete DML Package");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t DeletePackageProcessor::fixUpRows (dmlpackage::CalpontDMLPackage& cpackage, DMLResult& result, const uint64_t uniqueId, const uint32_t tableOid)
|
||||
{
|
||||
uint64_t DeletePackageProcessor::fixUpRows (dmlpackage::CalpontDMLPackage& cpackage, DMLResult& result, const uint64_t uniqueId, const uint32_t tableOid)
|
||||
{
|
||||
ByteStream msg, msgBk, emsgBs;
|
||||
rowgroup::RGData rgData;
|
||||
ByteStream::quadbyte qb = 4;
|
||||
@@ -356,28 +378,33 @@ namespace dmlpackageprocessor
|
||||
uint64_t rowsProcessed = 0;
|
||||
uint32_t dbroot = 1;
|
||||
bool metaData = false;
|
||||
oam::OamCache * oamCache = oam::OamCache::makeOamCache();
|
||||
oam::OamCache* oamCache = oam::OamCache::makeOamCache();
|
||||
std::vector<int> fPMs = oamCache->getModuleIds();
|
||||
std::map<unsigned, bool> pmStateDel;
|
||||
string emsg;
|
||||
string emsgStr;
|
||||
bool err = false;
|
||||
|
||||
//boost::scoped_ptr<messageqcpp::MessageQueueClient> fExeMgr;
|
||||
//fExeMgr.reset( new messageqcpp::MessageQueueClient("ExeMgr1"));
|
||||
try {
|
||||
for (unsigned i=0; i<fPMs.size(); i++)
|
||||
try
|
||||
{
|
||||
for (unsigned i = 0; i < fPMs.size(); i++)
|
||||
{
|
||||
pmStateDel[fPMs[i]] = true;
|
||||
}
|
||||
|
||||
fExeMgr->write(msg);
|
||||
fExeMgr->write(*(cpackage.get_ExecutionPlan()));
|
||||
//cout << "sending to ExeMgr plan with length " << (cpackage.get_ExecutionPlan())->length() << endl;
|
||||
msg.restart();
|
||||
emsgBs.restart();
|
||||
msg = fExeMgr->read(); //error handling
|
||||
|
||||
if (msg.length() == 4)
|
||||
{
|
||||
msg >> qb;
|
||||
|
||||
if (qb != 0)
|
||||
err = true;
|
||||
}
|
||||
@@ -386,6 +413,7 @@ namespace dmlpackageprocessor
|
||||
qb = 999;
|
||||
err = true;
|
||||
}
|
||||
|
||||
if (err)
|
||||
{
|
||||
logging::Message::Args args;
|
||||
@@ -422,10 +450,12 @@ namespace dmlpackageprocessor
|
||||
err = true;
|
||||
break;
|
||||
}
|
||||
|
||||
msg.restart();
|
||||
msgBk.restart();
|
||||
msg = fExeMgr->read();
|
||||
msgBk = msg;
|
||||
|
||||
if ( msg.length() == 0 )
|
||||
{
|
||||
logging::Message::Args args;
|
||||
@@ -462,6 +492,7 @@ namespace dmlpackageprocessor
|
||||
rowGroup->setData(&rgData);
|
||||
//rowGroup->setData(const_cast<uint8_t*>(msg.buf()));
|
||||
err = (rowGroup->getStatus() != 0);
|
||||
|
||||
if (err)
|
||||
{
|
||||
//msgBk.advance(rowGroup->getDataSize());
|
||||
@@ -483,22 +514,27 @@ namespace dmlpackageprocessor
|
||||
//return rowsProcessed;
|
||||
break;
|
||||
}
|
||||
|
||||
if (rowGroup->getRGData() == NULL)
|
||||
{
|
||||
msg.restart();
|
||||
}
|
||||
|
||||
if (rowGroup->getRowCount() == 0) //done fetching
|
||||
{
|
||||
err = receiveAll( result, uniqueId, fPMs, pmStateDel, tableOid);
|
||||
//return rowsProcessed;
|
||||
break;
|
||||
}
|
||||
|
||||
if (rowGroup->getBaseRid() == (uint64_t) (-1))
|
||||
{
|
||||
continue; // @bug4247, not valid row ids, may from small side outer
|
||||
}
|
||||
|
||||
dbroot = rowGroup->getDBRoot();
|
||||
err = processRowgroup(msgBk, result, uniqueId, cpackage, pmStateDel, metaData, dbroot);
|
||||
|
||||
if (err)
|
||||
{
|
||||
DMLResult tmpResult;
|
||||
@@ -510,9 +546,11 @@ namespace dmlpackageprocessor
|
||||
//return rowsProcessed;
|
||||
break;
|
||||
}
|
||||
|
||||
rowsProcessed += rowGroup->getRowCount();
|
||||
}
|
||||
}
|
||||
|
||||
if (fRollbackPending)
|
||||
{
|
||||
err = true;
|
||||
@@ -556,6 +594,7 @@ namespace dmlpackageprocessor
|
||||
msg << qb;
|
||||
fExeMgr->write(msg);
|
||||
}
|
||||
|
||||
return rowsProcessed;
|
||||
}
|
||||
catch (runtime_error& ex)
|
||||
@@ -592,9 +631,9 @@ namespace dmlpackageprocessor
|
||||
}
|
||||
|
||||
return rowsProcessed;
|
||||
}
|
||||
}
|
||||
|
||||
bool DeletePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult& result, const uint64_t uniqueId,
|
||||
bool DeletePackageProcessor::processRowgroup(ByteStream& aRowGroup, DMLResult& result, const uint64_t uniqueId,
|
||||
dmlpackage::CalpontDMLPackage& cpackage, std::map<unsigned, bool>& pmStateDel, bool isMeta, uint32_t dbroot)
|
||||
{
|
||||
bool rc = false;
|
||||
@@ -622,20 +661,26 @@ bool DeletePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
|
||||
if (isMeta) //send to all PMs
|
||||
{
|
||||
fWEClient->write_to_all(bytestream);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = true;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = (tmp8 != 0);
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
break;
|
||||
}
|
||||
@@ -643,12 +688,14 @@ bool DeletePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
|
||||
msgRecived++;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (pmStateDel[pmNum])
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
fWEClient->write(bytestream, (uint32_t)pmNum);
|
||||
//cout << "sent tp pm " << pmNum<<endl;
|
||||
pmStateDel[pmNum] = false;
|
||||
@@ -681,15 +728,19 @@ bool DeletePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = true;
|
||||
errorMsg = "Lost connection to Write Engine Server while deleting";
|
||||
throw std::runtime_error(errorMsg);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = (tmp8 != 0);
|
||||
*bsIn >> errorMsg;
|
||||
@@ -700,9 +751,12 @@ bool DeletePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
|
||||
|
||||
//cout << "received from pm " << (uint32_t)tmp32 << " and rc = " << rc << endl;
|
||||
pmStateDel[tmp32] = true;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
throw std::runtime_error(errorMsg);
|
||||
}
|
||||
|
||||
if ( tmp32 == (uint32_t)pmNum )
|
||||
{
|
||||
fWEClient->write(bytestream, (uint32_t)pmNum);
|
||||
@@ -737,6 +791,7 @@ bool DeletePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -746,7 +801,8 @@ bool DeletePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
|
||||
//check how many message we need to receive
|
||||
uint32_t messagesNotReceived = 0;
|
||||
bool err = false;
|
||||
for (unsigned i=0; i<fPMs.size(); i++)
|
||||
|
||||
for (unsigned i = 0; i < fPMs.size(); i++)
|
||||
{
|
||||
if (!pmStateDel[fPMs[i]])
|
||||
messagesNotReceived++;
|
||||
@@ -756,16 +812,18 @@ bool DeletePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
|
||||
uint32_t msgReceived = 0;
|
||||
ByteStream::byte tmp8;
|
||||
string errorMsg;
|
||||
|
||||
if (messagesNotReceived > 0)
|
||||
{
|
||||
LoggingID logid( DMLLoggingId, fSessionID, fSessionID);
|
||||
|
||||
if ( messagesNotReceived > fWEClient->getPmCount())
|
||||
{
|
||||
logging::Message::Args args1;
|
||||
logging::Message msg(1);
|
||||
args1.add("Delete outstanding messages exceed PM count , need to receive messages:PMcount = ");
|
||||
ostringstream oss;
|
||||
oss << messagesNotReceived <<":"<<fPMCount;
|
||||
oss << messagesNotReceived << ":" << fPMCount;
|
||||
args1.add(oss.str());
|
||||
msg.format( args1 );
|
||||
logging::Logger logger(logid.fSubsysID);
|
||||
@@ -791,15 +849,19 @@ bool DeletePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
|
||||
break;
|
||||
|
||||
bsIn.reset(new ByteStream());
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
err = true;
|
||||
errorMsg = "Lost connection to Write Engine Server while deleting";
|
||||
throw std::runtime_error(errorMsg);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
err = (tmp8 != 0);
|
||||
*bsIn >> errorMsg;
|
||||
@@ -808,9 +870,11 @@ bool DeletePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
|
||||
//cout << "Received response from pm " << tmp32 << endl;
|
||||
pmStateDel[tmp32] = true;
|
||||
|
||||
if (err) {
|
||||
if (err)
|
||||
{
|
||||
throw std::runtime_error(errorMsg);
|
||||
}
|
||||
|
||||
msgReceived++;
|
||||
result.stats.fBlocksChanged += blocksChanged;
|
||||
result.stats.fErrorNo = tmp8;
|
||||
|
||||
@@ -49,7 +49,7 @@ class DeletePackageProcessor : public DMLPackageProcessor
|
||||
|
||||
public:
|
||||
|
||||
DeletePackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid){}
|
||||
DeletePackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid) {}
|
||||
/** @brief process a DeleteDMLPackage
|
||||
*
|
||||
* @param cpackage the delete dml package to process
|
||||
@@ -71,8 +71,8 @@ private:
|
||||
WriteEngine::RIDList& rowIDList, WriteEngine::ColValueList& colOldValuesList,
|
||||
DMLResult& result);
|
||||
*/
|
||||
bool processRowgroup(messageqcpp::ByteStream & aRowGroup, DMLResult& result, const uint64_t uniqueId, dmlpackage::CalpontDMLPackage& cpackage, std::map<unsigned, bool>& pmStateDel,
|
||||
bool isMeta = false, uint32_t dbroot=1);
|
||||
bool processRowgroup(messageqcpp::ByteStream& aRowGroup, DMLResult& result, const uint64_t uniqueId, dmlpackage::CalpontDMLPackage& cpackage, std::map<unsigned, bool>& pmStateDel,
|
||||
bool isMeta = false, uint32_t dbroot = 1);
|
||||
|
||||
|
||||
/** @brief add all rows if we have no filter for the delete
|
||||
|
||||
@@ -66,33 +66,38 @@ const SOP opand(new Operator("and"));
|
||||
namespace dmlpackageprocessor
|
||||
{
|
||||
|
||||
DMLPackageProcessor::~DMLPackageProcessor()
|
||||
{
|
||||
DMLPackageProcessor::~DMLPackageProcessor()
|
||||
{
|
||||
//cout << "In DMLPackageProcessor destructor " << this << endl;
|
||||
if (fWEClient)
|
||||
delete fWEClient;
|
||||
|
||||
if (fExeMgr)
|
||||
delete fExeMgr;
|
||||
}
|
||||
}
|
||||
|
||||
//@bug 397
|
||||
void DMLPackageProcessor::cleanString(string& s)
|
||||
{
|
||||
string::size_type pos = s.find_first_not_of(" ");
|
||||
|
||||
//stripe off space and ' or '' at beginning and end
|
||||
if ( pos < s.length() )
|
||||
{
|
||||
s = s.substr( pos, s.length()-pos );
|
||||
s = s.substr( pos, s.length() - pos );
|
||||
|
||||
if ( (pos = s.find_last_of(" ")) < s.length())
|
||||
{
|
||||
s = s.substr(0, pos );
|
||||
}
|
||||
}
|
||||
|
||||
if ( s[0] == '\'')
|
||||
{
|
||||
s = s.substr(1, s.length()-2);
|
||||
s = s.substr(1, s.length() - 2);
|
||||
|
||||
if ( s[0] == '\'')
|
||||
s = s.substr(1, s.length()-2);
|
||||
s = s.substr(1, s.length() - 2);
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
@@ -134,6 +139,7 @@ boost::any DMLPackageProcessor::tokenizeData( execplan::CalpontSystemCatalog::SC
|
||||
dictTuple.sigValue = data.c_str();
|
||||
dictTuple.sigSize = data.length();
|
||||
int error = NO_ERROR;
|
||||
|
||||
if ( NO_ERROR != (error = fWriteEngine.tokenize( txnID, dictStruct, dictTuple)) )
|
||||
{
|
||||
retval = false;
|
||||
@@ -150,10 +156,12 @@ boost::any DMLPackageProcessor::tokenizeData( execplan::CalpontSystemCatalog::SC
|
||||
result.result = TOKEN_ERROR;
|
||||
result.message = message;
|
||||
}
|
||||
|
||||
WriteEngine::Token aToken = dictTuple.token;
|
||||
value = aToken;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
#endif
|
||||
@@ -169,6 +177,7 @@ void DMLPackageProcessor::getColumnsForTable(uint32_t sessionID, std::string sch
|
||||
CalpontSystemCatalog::RIDList ridList = systemCatalogPtr->columnRIDs(tableName, true);
|
||||
|
||||
CalpontSystemCatalog::RIDList::const_iterator rid_iterator = ridList.begin();
|
||||
|
||||
while (rid_iterator != ridList.end())
|
||||
{
|
||||
CalpontSystemCatalog::ROPair roPair = *rid_iterator;
|
||||
@@ -186,6 +195,7 @@ void DMLPackageProcessor::getColumnsForTable(uint32_t sessionID, std::string sch
|
||||
char* DMLPackageProcessor::strlower(char* in)
|
||||
{
|
||||
char* p = in;
|
||||
|
||||
if (p)
|
||||
{
|
||||
while (*p)
|
||||
@@ -194,6 +204,7 @@ char* DMLPackageProcessor::strlower(char* in)
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
@@ -234,10 +245,11 @@ string DMLPackageProcessor::projectTableErrCodeToMsg(uint32_t ec)
|
||||
return IDBErrorInfo::instance()->errorMsg(ec);
|
||||
}
|
||||
|
||||
bool DMLPackageProcessor::validateVarbinaryVal( std::string & inStr)
|
||||
bool DMLPackageProcessor::validateVarbinaryVal( std::string& inStr)
|
||||
{
|
||||
bool invalid = false;
|
||||
for (unsigned i=0; i < inStr.length(); i++)
|
||||
|
||||
for (unsigned i = 0; i < inStr.length(); i++)
|
||||
{
|
||||
if (!isxdigit(inStr[i]))
|
||||
{
|
||||
@@ -246,6 +258,7 @@ bool DMLPackageProcessor::validateVarbinaryVal( std::string & inStr)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return invalid;
|
||||
}
|
||||
|
||||
@@ -264,6 +277,7 @@ int DMLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
|
||||
int rc = 0;
|
||||
//Check BRM status before processing.
|
||||
rc = fDbrm->isReadWrite();
|
||||
|
||||
if (rc != 0 )
|
||||
{
|
||||
std::string brmMsg;
|
||||
@@ -282,16 +296,21 @@ int DMLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
|
||||
bytestream << sessionID;
|
||||
bytestream << (uint32_t)txnID.id;
|
||||
uint32_t msgRecived = 0;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->write_to_all(bytestream);
|
||||
boost::shared_ptr<messageqcpp::ByteStream> bsIn;
|
||||
bsIn.reset(new ByteStream());
|
||||
ByteStream::byte tmp8;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
@@ -300,10 +319,13 @@ int DMLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
|
||||
//cout << "erroring out remove queue id " << uniqueId << endl;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = tmp8;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
char szrc[20];
|
||||
*bsIn >> errorMsg;
|
||||
errorMsg += " (WriteEngine returns error ";
|
||||
@@ -319,7 +341,7 @@ int DMLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(std::exception& e)
|
||||
catch (std::exception& e)
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Network error occured when rolling back blocks";
|
||||
@@ -349,6 +371,7 @@ int DMLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
|
||||
//delete fWEClient;
|
||||
// cout << "success. remove queue id " << uniqueId << endl;
|
||||
rc = fDbrm->getUncommittedLBIDs(txnID.id, lbidList);
|
||||
|
||||
if (rc != 0 )
|
||||
{
|
||||
std::string brmMsg;
|
||||
@@ -359,11 +382,13 @@ int DMLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
|
||||
return rc;
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < lbidList.size(); i++) {
|
||||
for (size_t i = 0; i < lbidList.size(); i++)
|
||||
{
|
||||
range.start = lbidList[i];
|
||||
range.size = 1;
|
||||
lbidRangeList.push_back(range);
|
||||
}
|
||||
|
||||
rc = fDbrm->vbRollback(txnID.id, lbidRangeList);
|
||||
|
||||
if (rc != 0 )
|
||||
@@ -379,7 +404,7 @@ int DMLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
|
||||
return rc;
|
||||
}
|
||||
|
||||
int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::TxnID txnID, const uint32_t tableOid, std::string & errorMsg)
|
||||
int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::TxnID txnID, const uint32_t tableOid, std::string& errorMsg)
|
||||
{
|
||||
//collect hwm info from all pms and set them here. remove table metadata if all successful
|
||||
ByteStream bytestream;
|
||||
@@ -398,21 +423,27 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
|
||||
ByteStream::byte tmp8;
|
||||
typedef std::vector<BRM::BulkSetHWMArg> BulkSetHWMArgs;
|
||||
std::vector<BulkSetHWMArgs> hwmArgsAllPms;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = tmp8;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
@@ -430,16 +461,19 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
|
||||
//set hwm
|
||||
std::vector<BRM::BulkSetHWMArg> allHwm;
|
||||
BulkSetHWMArgs::const_iterator itor;
|
||||
|
||||
//cout << "total hwmArgsAllPms size " << hwmArgsAllPms.size() << endl;
|
||||
for (unsigned i=0; i < fWEClient->getPmCount(); i++)
|
||||
for (unsigned i = 0; i < fWEClient->getPmCount(); i++)
|
||||
{
|
||||
itor = hwmArgsAllPms[i].begin();
|
||||
|
||||
while (itor != hwmArgsAllPms[i].end())
|
||||
{
|
||||
allHwm.push_back(*itor);
|
||||
@@ -447,14 +481,17 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
|
||||
itor++;
|
||||
}
|
||||
}
|
||||
|
||||
//set CP data before hwm.
|
||||
|
||||
//cout << "setting hwm allHwm size " << allHwm.size() << endl;
|
||||
vector<BRM::LBID_t> lbidList;
|
||||
|
||||
if (idbdatafile::IDBPolicy::useHdfs())
|
||||
{
|
||||
BRM::LBID_t startLbid;
|
||||
for ( unsigned i=0; i < allHwm.size(); i++)
|
||||
|
||||
for ( unsigned i = 0; i < allHwm.size(); i++)
|
||||
{
|
||||
rc = fDbrm->lookupLocalStartLbid(allHwm[i].oid, allHwm[i].partNum, allHwm[i].segNum, allHwm[i].hwm, startLbid);
|
||||
lbidList.push_back(startLbid);
|
||||
@@ -462,10 +499,12 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
|
||||
}
|
||||
else
|
||||
fDbrm->getUncommittedExtentLBIDs(static_cast<BRM::VER_t>(txnID.id), lbidList);
|
||||
|
||||
vector<BRM::LBID_t>::const_iterator iter = lbidList.begin();
|
||||
vector<BRM::LBID_t>::const_iterator end = lbidList.end();
|
||||
BRM::CPInfoList_t cpInfos;
|
||||
BRM::CPInfo aInfo;
|
||||
|
||||
while (iter != end)
|
||||
{
|
||||
aInfo.firstLbid = *iter;
|
||||
@@ -475,6 +514,7 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
|
||||
cpInfos.push_back(aInfo);
|
||||
++iter;
|
||||
}
|
||||
|
||||
std::vector<BRM::CPInfoMerge> mergeCPDataArgs;
|
||||
rc = fDbrm->bulkSetHWMAndCP(allHwm, cpInfos, mergeCPDataArgs, txnID.id);
|
||||
fDbrm->takeSnapshot();
|
||||
@@ -484,10 +524,11 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
|
||||
return rc;
|
||||
|
||||
bool stateChanged = true;
|
||||
TablelockData * tablelockData = TablelockData::makeTablelockData(fSessionID);
|
||||
TablelockData* tablelockData = TablelockData::makeTablelockData(fSessionID);
|
||||
uint64_t tablelockId = tablelockData->getTablelockId(tableOid);
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
stateChanged = fDbrm->changeState(tablelockId, BRM::CLEANUP);
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -506,17 +547,21 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
|
||||
bytestream << tableOid;
|
||||
msgRecived = 0;
|
||||
fWEClient->write_to_all(bytestream);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
msgRecived++;
|
||||
}
|
||||
@@ -528,18 +573,19 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
|
||||
}
|
||||
|
||||
int DMLPackageProcessor::rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID,
|
||||
const uint32_t tableOid, std::string & errorMsg)
|
||||
const uint32_t tableOid, std::string& errorMsg)
|
||||
{
|
||||
//Bulkrollback, rollback blocks, vbrollback, change state, remove meta file
|
||||
//cout << "In rollBackBatchAutoOnTransaction" << endl;
|
||||
std::vector<BRM::TableLockInfo> tableLocks;
|
||||
tableLocks = fDbrm->getAllTableLocks();
|
||||
//cout << " Got all tablelocks" << endl;
|
||||
unsigned idx=0;
|
||||
unsigned idx = 0;
|
||||
string ownerName ("DMLProc batchinsert");
|
||||
uint64_t tableLockId = 0;
|
||||
int rc = 0;
|
||||
for (; idx<tableLocks.size(); idx++)
|
||||
|
||||
for (; idx < tableLocks.size(); idx++)
|
||||
{
|
||||
if ((tableLocks[idx].ownerName == ownerName) && (tableLocks[idx].tableOID == tableOid))
|
||||
{
|
||||
@@ -548,13 +594,14 @@ int DMLPackageProcessor::rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::
|
||||
}
|
||||
}
|
||||
|
||||
if ((tableLockId == 0) || (tableOid ==0))
|
||||
if ((tableLockId == 0) || (tableOid == 0))
|
||||
{
|
||||
// table is not locked by DMLProc. Could happen if we failed to get lock
|
||||
// while inserting. Not an error during rollback, but we don't
|
||||
// want to do anything.
|
||||
return rc;
|
||||
}
|
||||
|
||||
//cout << "sending to WES" << endl;
|
||||
ByteStream bytestream;
|
||||
fWEClient->addQueue(uniqueId);
|
||||
@@ -569,12 +616,15 @@ int DMLPackageProcessor::rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::
|
||||
boost::shared_ptr<messageqcpp::ByteStream> bsIn;
|
||||
bsIn.reset(new ByteStream());
|
||||
ByteStream::byte tmp8;
|
||||
|
||||
//cout << "waiting for reply from WES" << endl;
|
||||
while (1)
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
@@ -582,10 +632,13 @@ int DMLPackageProcessor::rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::
|
||||
//cout << "erroring out remove queue id " << uniqueId << endl;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = tmp8;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
//cout << "erroring out remove queue id " << uniqueId << endl;
|
||||
@@ -595,11 +648,14 @@ int DMLPackageProcessor::rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::
|
||||
msgRecived++;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc == 0) //change table lock state
|
||||
{
|
||||
bool stateChanged = true;
|
||||
|
||||
//cout << "changing tablelock state" << endl;
|
||||
try {
|
||||
try
|
||||
{
|
||||
stateChanged = fDbrm->changeState(tableLockId, BRM::CLEANUP);
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -607,53 +663,61 @@ int DMLPackageProcessor::rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::
|
||||
errorMsg = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
|
||||
stateChanged = false;
|
||||
}
|
||||
|
||||
if (!stateChanged)
|
||||
{
|
||||
rc = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( rc !=0 )
|
||||
if ( rc != 0 )
|
||||
return rc;
|
||||
|
||||
bytestream.restart();
|
||||
bytestream << (ByteStream::byte)WE_SVR_BATCH_AUTOON_REMOVE_META;
|
||||
bytestream << uniqueId;
|
||||
bytestream << tableOid;
|
||||
msgRecived = 0;
|
||||
fWEClient->write_to_all(bytestream);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
//cout << "erroring out remove queue id " << uniqueId << endl;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
msgRecived++;
|
||||
}
|
||||
}
|
||||
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int DMLPackageProcessor::commitBatchAutoOffTransaction(uint64_t uniqueId, BRM::TxnID txnID, const uint32_t tableOid, std::string & errorMsg)
|
||||
int DMLPackageProcessor::commitBatchAutoOffTransaction(uint64_t uniqueId, BRM::TxnID txnID, const uint32_t tableOid, std::string& errorMsg)
|
||||
{
|
||||
std::vector<BRM::TableLockInfo> tableLocks;
|
||||
tableLocks = fDbrm->getAllTableLocks();
|
||||
//cout << " Got all tablelocks" << endl;
|
||||
unsigned idx=0;
|
||||
unsigned idx = 0;
|
||||
string ownerName ("DMLProc batchinsert");
|
||||
uint64_t tableLockId = 0;
|
||||
int rc = 0;
|
||||
boost::shared_ptr<messageqcpp::ByteStream> bsIn;
|
||||
bsIn.reset(new ByteStream());
|
||||
ByteStream::byte tmp8;
|
||||
for (; idx<tableLocks.size(); idx++)
|
||||
|
||||
for (; idx < tableLocks.size(); idx++)
|
||||
{
|
||||
if ((tableLocks[idx].ownerName == ownerName) && (tableLocks[idx].tableOID == tableOid))
|
||||
{
|
||||
@@ -662,7 +726,7 @@ int DMLPackageProcessor::commitBatchAutoOffTransaction(uint64_t uniqueId, BRM::T
|
||||
}
|
||||
}
|
||||
|
||||
if ((tableLockId == 0) || (tableOid ==0))
|
||||
if ((tableLockId == 0) || (tableOid == 0))
|
||||
{
|
||||
// table is not locked by DMLProc. Could happen if we failed to get lock
|
||||
// while inserting. Not an error during rollback, but we don't
|
||||
@@ -671,8 +735,10 @@ int DMLPackageProcessor::commitBatchAutoOffTransaction(uint64_t uniqueId, BRM::T
|
||||
}
|
||||
|
||||
bool stateChanged = true;
|
||||
|
||||
//cout << "changing tablelock state" << endl;
|
||||
try {
|
||||
try
|
||||
{
|
||||
stateChanged = fDbrm->changeState(tableLockId, BRM::CLEANUP);
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -680,11 +746,13 @@ int DMLPackageProcessor::commitBatchAutoOffTransaction(uint64_t uniqueId, BRM::T
|
||||
errorMsg = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
|
||||
stateChanged = false;
|
||||
}
|
||||
|
||||
if (!stateChanged)
|
||||
{
|
||||
rc = 1;
|
||||
}
|
||||
if ( rc !=0 )
|
||||
|
||||
if ( rc != 0 )
|
||||
return rc;
|
||||
|
||||
ByteStream bytestream;
|
||||
@@ -694,27 +762,32 @@ int DMLPackageProcessor::commitBatchAutoOffTransaction(uint64_t uniqueId, BRM::T
|
||||
bytestream << tableOid;
|
||||
uint32_t msgRecived = 0;
|
||||
fWEClient->write_to_all(bytestream);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
msgRecived++;
|
||||
}
|
||||
}
|
||||
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int DMLPackageProcessor::rollBackBatchAutoOffTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID,
|
||||
const uint32_t tableOid, std::string & errorMsg)
|
||||
const uint32_t tableOid, std::string& errorMsg)
|
||||
{
|
||||
ByteStream bytestream;
|
||||
fWEClient->addQueue(uniqueId);
|
||||
@@ -734,17 +807,22 @@ int DMLPackageProcessor::rollBackBatchAutoOffTransaction(uint64_t uniqueId, BRM:
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = tmp8;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
break;
|
||||
@@ -757,7 +835,7 @@ int DMLPackageProcessor::rollBackBatchAutoOffTransaction(uint64_t uniqueId, BRM:
|
||||
return rc;
|
||||
}
|
||||
|
||||
int DMLPackageProcessor::flushDataFiles (int rcIn, std::map<FID,FID> & columnOids, uint64_t uniqueId, BRM::TxnID txnID, uint32_t tableOid)
|
||||
int DMLPackageProcessor::flushDataFiles (int rcIn, std::map<FID, FID>& columnOids, uint64_t uniqueId, BRM::TxnID txnID, uint32_t tableOid)
|
||||
{
|
||||
//cout <<"in flushDataFiles" << endl;
|
||||
ByteStream bytestream;
|
||||
@@ -773,21 +851,28 @@ int DMLPackageProcessor::flushDataFiles (int rcIn, std::map<FID,FID> & columnOid
|
||||
int rc = 0;
|
||||
ByteStream::byte tmp8;
|
||||
std::string errorMsg;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = tmp8;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
break;
|
||||
}
|
||||
@@ -796,7 +881,8 @@ int DMLPackageProcessor::flushDataFiles (int rcIn, std::map<FID,FID> & columnOid
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception&) {
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
|
||||
return rc;
|
||||
@@ -817,21 +903,28 @@ int DMLPackageProcessor::endTransaction (uint64_t uniqueId, BRM::TxnID txnID, bo
|
||||
int rc = 0;
|
||||
ByteStream::byte tmp8;
|
||||
std::string errorMsg;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
rc = tmp8;
|
||||
if (rc != 0) {
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
break;
|
||||
}
|
||||
@@ -840,7 +933,8 @@ int DMLPackageProcessor::endTransaction (uint64_t uniqueId, BRM::TxnID txnID, bo
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception&) {
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
||||
@@ -119,7 +119,7 @@ public:
|
||||
std::string miniStats;
|
||||
querystats::QueryStats stats;
|
||||
|
||||
DMLResult():result(NO_ERROR),rowCount(0){};
|
||||
DMLResult(): result(NO_ERROR), rowCount(0) {};
|
||||
};
|
||||
/** @brief a structure to hold a date
|
||||
*/
|
||||
@@ -130,7 +130,13 @@ public:
|
||||
unsigned month : 4;
|
||||
unsigned year : 16;
|
||||
// NULL column value = 0xFFFFFFFE
|
||||
Date( ) { year = 0xFFFF; month = 0xF; day = 0x3F; spare = 0x3E;}
|
||||
Date( )
|
||||
{
|
||||
year = 0xFFFF;
|
||||
month = 0xF;
|
||||
day = 0x3F;
|
||||
spare = 0x3E;
|
||||
}
|
||||
};
|
||||
/** @brief a structure to hold a datetime
|
||||
*/
|
||||
@@ -144,15 +150,24 @@ public:
|
||||
unsigned month : 4;
|
||||
unsigned year : 16;
|
||||
// NULL column value = 0xFFFFFFFFFFFFFFFE
|
||||
dateTime( ) { year = 0xFFFF; month = 0xF; day = 0x3F; hour = 0x3F; minute = 0x3F; second = 0x3F;
|
||||
msecond = 0xFFFFE; }
|
||||
dateTime( )
|
||||
{
|
||||
year = 0xFFFF;
|
||||
month = 0xF;
|
||||
day = 0x3F;
|
||||
hour = 0x3F;
|
||||
minute = 0x3F;
|
||||
second = 0x3F;
|
||||
msecond = 0xFFFFE;
|
||||
}
|
||||
};
|
||||
|
||||
/** @brief ctor
|
||||
*/
|
||||
DMLPackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : fEC(0), DMLLoggingId(21), fRollbackPending(false), fDebugLevel(NONE)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
fWEClient = new WriteEngine::WEClients(WriteEngine::WEClients::DMLPROC);
|
||||
//std::cout << "In DMLPackageProcessor constructor " << this << std::endl;
|
||||
fPMCount = fWEClient->getPmCount();
|
||||
@@ -162,7 +177,7 @@ public:
|
||||
std::cout << "Cannot make connection to WES" << std::endl;
|
||||
}
|
||||
|
||||
oam::OamCache * oamCache = oam::OamCache::makeOamCache();
|
||||
oam::OamCache* oamCache = oam::OamCache::makeOamCache();
|
||||
fDbRootPMMap = oamCache->getDBRootToPMMap();
|
||||
fDbrm = aDbrm;
|
||||
fSessionID = sid;
|
||||
@@ -179,22 +194,34 @@ public:
|
||||
|
||||
/** @brief Is it required to debug
|
||||
*/
|
||||
inline const bool isDebug( const DebugLevel level ) const { return level <= fDebugLevel; }
|
||||
inline const bool isDebug( const DebugLevel level ) const
|
||||
{
|
||||
return level <= fDebugLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get debug level
|
||||
*/
|
||||
inline const DebugLevel getDebugLevel() const { return fDebugLevel; }
|
||||
inline const DebugLevel getDebugLevel() const
|
||||
{
|
||||
return fDebugLevel;
|
||||
}
|
||||
//int rollBackTransaction(uint64_t uniqueId, uint32_t txnID, uint32_t sessionID, std::string & errorMsg);
|
||||
/**
|
||||
* @brief Set debug level
|
||||
*/
|
||||
inline void setDebugLevel( const DebugLevel level ) { fDebugLevel = level; }
|
||||
inline void setDebugLevel( const DebugLevel level )
|
||||
{
|
||||
fDebugLevel = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Distributed Engine Comm object
|
||||
*/
|
||||
inline void setEngineComm(joblist::DistributedEngineComm* ec) { fEC = ec; }
|
||||
inline void setEngineComm(joblist::DistributedEngineComm* ec)
|
||||
{
|
||||
fEC = ec;
|
||||
}
|
||||
|
||||
/** @brief process the dml package
|
||||
*
|
||||
@@ -202,11 +229,14 @@ public:
|
||||
*/
|
||||
virtual DMLResult processPackage(dmlpackage::CalpontDMLPackage& cpackage) = 0;
|
||||
|
||||
inline void setRM ( joblist::ResourceManager* frm) { fRM = frm; };
|
||||
inline void setRM ( joblist::ResourceManager* frm)
|
||||
{
|
||||
fRM = frm;
|
||||
};
|
||||
|
||||
EXPORT int rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID, std::string & errorMsg);
|
||||
EXPORT int rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID, std::string& errorMsg);
|
||||
|
||||
EXPORT int rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID, const uint32_t tableOid, std::string & errorMsg);
|
||||
EXPORT int rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID, const uint32_t tableOid, std::string& errorMsg);
|
||||
/**
|
||||
* @brief convert a columns data, represnted as a string, to it's native
|
||||
* data type
|
||||
@@ -262,11 +292,17 @@ public:
|
||||
|
||||
/** @brief Access the rollback pending flag
|
||||
*/
|
||||
bool getRollbackPending() {return fRollbackPending;}
|
||||
bool getRollbackPending()
|
||||
{
|
||||
return fRollbackPending;
|
||||
}
|
||||
|
||||
/** @brief Set the rollback pending flag
|
||||
*/
|
||||
void setRollbackPending(bool rollback) {fRollbackPending = rollback;}
|
||||
void setRollbackPending(bool rollback)
|
||||
{
|
||||
fRollbackPending = rollback;
|
||||
}
|
||||
|
||||
protected:
|
||||
/** @brief update the indexes on the target table
|
||||
@@ -279,7 +315,7 @@ protected:
|
||||
* @param colNameList the updated column names, only valid for update SQL statement
|
||||
*/
|
||||
bool updateIndexes( uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, const std::string& schema,
|
||||
const std::string& table,const dmlpackage::RowList& rows, DMLResult& result,
|
||||
const std::string& table, const dmlpackage::RowList& rows, DMLResult& result,
|
||||
std::vector<WriteEngine::RID> ridList,
|
||||
WriteEngine::ColValueList& colValuesList, std::vector<std::string>& colNameList, const char updateFlag,
|
||||
std::vector<dicStrValues>& dicStrValCols );
|
||||
@@ -365,7 +401,7 @@ protected:
|
||||
const std::string& schema,
|
||||
const std::string& table,
|
||||
std::vector<WriteEngine::RID>& rowIDList,
|
||||
std::vector<void *>& oldValueList,
|
||||
std::vector<void*>& oldValueList,
|
||||
DMLResult& result );
|
||||
|
||||
/** @brief validate that the rows deleted does not violate a reference (foreign key) constraint
|
||||
@@ -381,7 +417,7 @@ protected:
|
||||
const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo,
|
||||
DMLResult& result );
|
||||
|
||||
bool violatesReferenceConstraint_PK( std::vector<void *>& oldValueList,
|
||||
bool violatesReferenceConstraint_PK( std::vector<void*>& oldValueList,
|
||||
const int totalRows,
|
||||
const execplan::CalpontSystemCatalog::ColType& colType,
|
||||
unsigned int colOffset,
|
||||
@@ -463,18 +499,18 @@ protected:
|
||||
|
||||
// bool validateNextValue(execplan::CalpontSystemCatalog::ColType colType, int64_t value, bool & offByOne);
|
||||
|
||||
bool validateVarbinaryVal( std::string & inStr);
|
||||
bool validateVarbinaryVal( std::string& inStr);
|
||||
int commitTransaction(uint64_t uniqueId, BRM::TxnID txnID);
|
||||
int commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::TxnID txnID, const uint32_t tableOid, std::string & errorMsg);
|
||||
int commitBatchAutoOffTransaction(uint64_t uniqueId, BRM::TxnID txnID, const uint32_t tableOid, std::string & errorMsg);
|
||||
int rollBackBatchAutoOffTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID, const uint32_t tableOid, std::string & errorMsg);
|
||||
int flushDataFiles (int rc, std::map<uint32_t,uint32_t> & columnOids, uint64_t uniqueId, BRM::TxnID txnID, uint32_t tableOid);
|
||||
int commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::TxnID txnID, const uint32_t tableOid, std::string& errorMsg);
|
||||
int commitBatchAutoOffTransaction(uint64_t uniqueId, BRM::TxnID txnID, const uint32_t tableOid, std::string& errorMsg);
|
||||
int rollBackBatchAutoOffTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID, const uint32_t tableOid, std::string& errorMsg);
|
||||
int flushDataFiles (int rc, std::map<uint32_t, uint32_t>& columnOids, uint64_t uniqueId, BRM::TxnID txnID, uint32_t tableOid);
|
||||
int endTransaction (uint64_t uniqueId, BRM::TxnID txnID, bool success);
|
||||
|
||||
/** @brief the Session Manager interface
|
||||
*/
|
||||
execplan::SessionManager fSessionManager;
|
||||
joblist::DistributedEngineComm *fEC;
|
||||
joblist::DistributedEngineComm* fEC;
|
||||
joblist::ResourceManager* fRM;
|
||||
char* strlower(char* in);
|
||||
uint32_t fSessionID;
|
||||
@@ -505,7 +541,7 @@ private:
|
||||
template <class T>
|
||||
bool from_string(T& t,
|
||||
const std::string& s,
|
||||
std::ios_base& (*f)(std::ios_base&))
|
||||
std::ios_base & (*f)(std::ios_base&))
|
||||
{
|
||||
std::istringstream iss(s);
|
||||
return !(iss >> f >> t).fail();
|
||||
|
||||
@@ -31,14 +31,15 @@
|
||||
|
||||
using namespace dmlpackage;
|
||||
|
||||
namespace dmlpackageprocessor {
|
||||
namespace dmlpackageprocessor
|
||||
{
|
||||
|
||||
DMLPackageProcessor* DMLPackageProcessorFactory::
|
||||
makePackageProcessor(int packageType, dmlpackage::CalpontDMLPackage& cpackage)
|
||||
{
|
||||
DMLPackageProcessor* dmlProcPtr = 0;
|
||||
|
||||
switch( packageType )
|
||||
switch ( packageType )
|
||||
{
|
||||
case DML_INSERT:
|
||||
dmlProcPtr = new InsertPackageProcessor();
|
||||
|
||||
@@ -33,16 +33,18 @@
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
namespace dmlpackageprocessor {
|
||||
namespace dmlpackageprocessor
|
||||
{
|
||||
|
||||
/** @brief create a DMLPackageProcessor object from a CalpontDMLPackage object
|
||||
*
|
||||
*/
|
||||
class DMLPackageProcessorFactory {
|
||||
class DMLPackageProcessorFactory
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/** @brief static DMLPackageProcessor constructor method
|
||||
/** @brief static DMLPackageProcessor constructor method
|
||||
*
|
||||
* @param packageType the DML Package type
|
||||
* @param cpackage the CalpontDMLPackage from which the DMLPackageProcessor is constructed
|
||||
|
||||
@@ -51,8 +51,8 @@ using namespace messageqcpp;
|
||||
namespace dmlpackageprocessor
|
||||
{
|
||||
|
||||
DMLPackageProcessor::DMLResult InsertPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage & cpackage)
|
||||
{
|
||||
DMLPackageProcessor::DMLResult InsertPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
{
|
||||
SUMMARY_INFO("InsertPackageProcessor::processPackage");
|
||||
|
||||
DMLResult result;
|
||||
@@ -62,14 +62,14 @@ namespace dmlpackageprocessor
|
||||
txnid.id = cpackage.get_TxnID();
|
||||
txnid.valid = true;
|
||||
fSessionID = cpackage.get_SessionID();
|
||||
DMLTable *tablePtr = cpackage.get_Table();
|
||||
DMLTable* tablePtr = cpackage.get_Table();
|
||||
|
||||
LoggingID logid( DMLLoggingId, fSessionID, txnid.id);
|
||||
logging::Message::Args args1;
|
||||
logging::Message msg(1);
|
||||
args1.add("Start SQL statement: ");
|
||||
ostringstream oss;
|
||||
oss << cpackage.get_SQLStatement() << "; |" << tablePtr->get_SchemaName()<<"|";
|
||||
oss << cpackage.get_SQLStatement() << "; |" << tablePtr->get_SchemaName() << "|";
|
||||
args1.add(oss.str());
|
||||
|
||||
msg.format( args1 );
|
||||
@@ -80,8 +80,10 @@ namespace dmlpackageprocessor
|
||||
//std::map<uint32_t,uint32_t> oids;
|
||||
VERBOSE_INFO("Processing Insert DML Package...");
|
||||
uint64_t uniqueId = 0;
|
||||
|
||||
//Bug 5070. Added exception handling
|
||||
try {
|
||||
try
|
||||
{
|
||||
uniqueId = fDbrm->getUnique64();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
@@ -106,16 +108,17 @@ namespace dmlpackageprocessor
|
||||
fSessionManager.rolledback(txnid);
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t tableLockId = 0;
|
||||
int rc = 0;
|
||||
std::string errorMsg;
|
||||
OamCache * oamcache = OamCache::makeOamCache();
|
||||
OamCache* oamcache = OamCache::makeOamCache();
|
||||
std::vector<int> moduleIds = oamcache->getModuleIds();
|
||||
std::vector<uint32_t> pms;
|
||||
|
||||
try
|
||||
{
|
||||
for (unsigned int i=0; i <moduleIds.size(); i++)
|
||||
for (unsigned int i = 0; i < moduleIds.size(); i++)
|
||||
{
|
||||
pms.push_back((uint32_t)moduleIds[i]);
|
||||
}
|
||||
@@ -126,7 +129,8 @@ namespace dmlpackageprocessor
|
||||
//cout << "DMLProc using syscatptr:sessionid = " << systemCatalogPtr <<":" << fSessionID<< endl;
|
||||
CalpontSystemCatalog::TableName tableName;
|
||||
execplan::CalpontSystemCatalog::ROPair roPair;
|
||||
TablelockData * tablelockData = TablelockData::makeTablelockData(fSessionID);
|
||||
TablelockData* tablelockData = TablelockData::makeTablelockData(fSessionID);
|
||||
|
||||
if (0 != tablePtr)
|
||||
{
|
||||
//check table lock
|
||||
@@ -137,6 +141,7 @@ namespace dmlpackageprocessor
|
||||
roPair = systemCatalogPtr->tableRID( tableName );
|
||||
|
||||
tableLockId = tablelockData->getTablelockId(roPair.objnum); //check whether this table is locked already for this session
|
||||
|
||||
if (tableLockId == 0)
|
||||
{
|
||||
//cout << "tablelock is not found in cache, getting from dbrm" << endl;
|
||||
@@ -146,7 +151,8 @@ namespace dmlpackageprocessor
|
||||
std::string processName("DMLProc");
|
||||
int i = 0;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnId, BRM::LOADING );
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -163,8 +169,8 @@ namespace dmlpackageprocessor
|
||||
numTries = waitPeriod * 10;
|
||||
struct timespec rm_ts;
|
||||
|
||||
rm_ts.tv_sec = sleepTime/1000;
|
||||
rm_ts.tv_nsec = sleepTime%1000 *1000000;
|
||||
rm_ts.tv_sec = sleepTime / 1000;
|
||||
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
|
||||
|
||||
for (; i < numTries; i++)
|
||||
{
|
||||
@@ -172,14 +178,18 @@ namespace dmlpackageprocessor
|
||||
Sleep(rm_ts.tv_sec * 1000);
|
||||
#else
|
||||
struct timespec abs_ts;
|
||||
|
||||
do
|
||||
{
|
||||
abs_ts.tv_sec = rm_ts.tv_sec;
|
||||
abs_ts.tv_nsec = rm_ts.tv_nsec;
|
||||
}
|
||||
while(nanosleep(&abs_ts,&rm_ts) < 0);
|
||||
while (nanosleep(&abs_ts, &rm_ts) < 0);
|
||||
|
||||
#endif
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
processID = ::getpid();
|
||||
txnId = txnid.id;
|
||||
sessionId = fSessionID;
|
||||
@@ -194,6 +204,7 @@ namespace dmlpackageprocessor
|
||||
if (tableLockId > 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i >= numTries) //error out
|
||||
{
|
||||
result.result = INSERT_ERROR;
|
||||
@@ -203,7 +214,7 @@ namespace dmlpackageprocessor
|
||||
args.add(processName);
|
||||
args.add((uint64_t)processID);
|
||||
args.add(sessionId);
|
||||
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED,args));
|
||||
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,10 +231,12 @@ namespace dmlpackageprocessor
|
||||
// 3. Map the selected DBRoot to the corresponding PM
|
||||
CalpontSystemCatalog::RIDList ridList = systemCatalogPtr->columnRIDs(tableName, true);
|
||||
std::vector<BRM::EmDbRootHWMInfo_v> allInfo (pms.size());
|
||||
|
||||
for (unsigned i = 0; i < pms.size(); i++)
|
||||
{
|
||||
rc = fDbrm->getDbRootHWMInfo((ridList[0].objnum), pms[i], allInfo[i]);
|
||||
if ( rc !=0 ) //@Bug 4760.
|
||||
|
||||
if ( rc != 0 ) //@Bug 4760.
|
||||
{
|
||||
result.result = INSERT_ERROR;
|
||||
ostringstream oss;
|
||||
@@ -236,11 +249,12 @@ namespace dmlpackageprocessor
|
||||
// have 0 blocks, then we select the first DBRoot
|
||||
BRM::EmDbRootHWMInfo tmp;
|
||||
bool tmpSet = false;
|
||||
for (unsigned i=0; i < allInfo.size(); i++)
|
||||
|
||||
for (unsigned i = 0; i < allInfo.size(); i++)
|
||||
{
|
||||
BRM::EmDbRootHWMInfo_v emDbRootHWMInfos = allInfo[i];
|
||||
|
||||
for (unsigned j=0; j < emDbRootHWMInfos.size(); j++)
|
||||
for (unsigned j = 0; j < emDbRootHWMInfos.size(); j++)
|
||||
{
|
||||
if (!tmpSet)
|
||||
{
|
||||
@@ -260,6 +274,7 @@ namespace dmlpackageprocessor
|
||||
|
||||
// Select the PM to receive the row
|
||||
uint32_t dbroot;
|
||||
|
||||
if (tmpSet)
|
||||
{
|
||||
dbroot = tmp.dbRoot;
|
||||
@@ -295,23 +310,28 @@ namespace dmlpackageprocessor
|
||||
boost::shared_ptr<messageqcpp::ByteStream> bsIn;
|
||||
|
||||
ByteStream::byte rc1;
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->write(bytestream, (uint32_t)pmNum);
|
||||
#ifdef IDB_DML_DEBUG
|
||||
cout << "Single insert sending WE_SVR_SINGLE_INSERT to pm " << pmNum << endl;
|
||||
cout << "Single insert sending WE_SVR_SINGLE_INSERT to pm " << pmNum << endl;
|
||||
#endif
|
||||
|
||||
bsIn.reset(new ByteStream());
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> rc1;
|
||||
if (rc1 != 0) {
|
||||
|
||||
if (rc1 != 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
rc = rc1;
|
||||
}
|
||||
@@ -321,7 +341,7 @@ cout << "Single insert sending WE_SVR_SINGLE_INSERT to pm " << pmNum << endl;
|
||||
catch (runtime_error& ex) //write error
|
||||
{
|
||||
#ifdef IDB_DML_DEBUG
|
||||
cout << "Single insert got exception" << ex.what() << endl;
|
||||
cout << "Single insert got exception" << ex.what() << endl;
|
||||
#endif
|
||||
rc = NETWORK_ERROR;
|
||||
errorMsg = ex.what();
|
||||
@@ -331,9 +351,10 @@ cout << "Single insert got exception" << ex.what() << endl;
|
||||
errorMsg = "Caught ... exception during single row insert";
|
||||
rc = NETWORK_ERROR;
|
||||
#ifdef IDB_DML_DEBUG
|
||||
cout << "Single insert got unknown exception" << endl;
|
||||
cout << "Single insert got unknown exception" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Log the insert statement.
|
||||
LoggingID logid( DMLLoggingId, fSessionID, txnid.id);
|
||||
logging::Message::Args args1;
|
||||
@@ -342,10 +363,10 @@ cout << "Single insert got unknown exception" << endl;
|
||||
msg.format( args1 );
|
||||
Logger logger(logid.fSubsysID);
|
||||
logger.logMessage(LOG_TYPE_DEBUG, msg, logid);
|
||||
logging::logDML(cpackage.get_SessionID(), txnid.id, cpackage.get_SQLStatement()+ ";", cpackage.get_SchemaName());
|
||||
logging::logDML(cpackage.get_SessionID(), txnid.id, cpackage.get_SQLStatement() + ";", cpackage.get_SchemaName());
|
||||
}
|
||||
}
|
||||
catch(exception & ex)
|
||||
catch (exception& ex)
|
||||
{
|
||||
cerr << "InsertPackageProcessor::processPackage: " << ex.what() << endl;
|
||||
|
||||
@@ -364,7 +385,7 @@ cout << "Single insert got unknown exception" << endl;
|
||||
errorMsg = ex.what();
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
cerr << "InsertPackageProcessor::processPackage: caught unknown exception!" << endl;
|
||||
logging::Message::Args args;
|
||||
@@ -379,7 +400,7 @@ cout << "Single insert got unknown exception" << endl;
|
||||
result.message = message;
|
||||
}
|
||||
|
||||
if (( rc !=0) && (rc != IDBRANGE_WARNING))
|
||||
if (( rc != 0) && (rc != IDBRANGE_WARNING))
|
||||
{
|
||||
logging::Message::Args args;
|
||||
logging::Message message(1);
|
||||
@@ -406,7 +427,7 @@ cout << "Single insert got unknown exception" << endl;
|
||||
fWEClient->removeQueue(uniqueId);
|
||||
VERBOSE_INFO("Finished Processing Insert DML Package");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dmlpackageprocessor
|
||||
|
||||
|
||||
@@ -48,7 +48,8 @@ class InsertPackageProcessor : public DMLPackageProcessor
|
||||
{
|
||||
|
||||
public:
|
||||
InsertPackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid) {
|
||||
InsertPackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid)
|
||||
{
|
||||
}
|
||||
/** @brief process an InsertDMLPackage
|
||||
*
|
||||
|
||||
@@ -59,6 +59,7 @@ void TablelockData::removeTablelockData(uint32_t sessionID)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(map_mutex);
|
||||
TablelockDataMap::iterator it = fTablelockDataMap.find(sessionID);
|
||||
|
||||
if (it != fTablelockDataMap.end())
|
||||
{
|
||||
delete (*it).second;
|
||||
@@ -84,14 +85,16 @@ uint64_t TablelockData::getTablelockId(uint32_t tableOid)
|
||||
boost::mutex::scoped_lock lk(fOIDTablelock);
|
||||
uint64_t tablelockId = 0;
|
||||
OIDTablelock::iterator it = fOIDTablelockMap.find(tableOid);
|
||||
|
||||
if (it != fOIDTablelockMap.end())
|
||||
{
|
||||
tablelockId = it->second;
|
||||
}
|
||||
|
||||
return tablelockId;
|
||||
}
|
||||
|
||||
TablelockData::OIDTablelock & TablelockData::getOidTablelockMap()
|
||||
TablelockData::OIDTablelock& TablelockData::getOidTablelockMap()
|
||||
{
|
||||
boost::mutex::scoped_lock lk(fOIDTablelock);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
EXPORT static void removeTablelockData(uint32_t sessionID = 0);
|
||||
EXPORT void setTablelock(uint32_t tableOid, uint64_t tablelockId);
|
||||
EXPORT uint64_t getTablelockId(uint32_t tableOid);
|
||||
OIDTablelock & getOidTablelockMap();
|
||||
OIDTablelock& getOidTablelockMap();
|
||||
|
||||
private:
|
||||
/** Constuctors */
|
||||
|
||||
@@ -458,21 +458,23 @@ public:
|
||||
|
||||
ddlpackage::SqlParser parser;
|
||||
parser.Parse(createText.c_str());
|
||||
|
||||
if (parser.Good())
|
||||
{
|
||||
const ddlpackage::ParseTree &ptree = parser.GetParseTree();
|
||||
const ddlpackage::ParseTree& ptree = parser.GetParseTree();
|
||||
|
||||
try
|
||||
{
|
||||
ddlpackageprocessor::CreateTableProcessor processor;
|
||||
processor.setDebugLevel(ddlpackageprocessor::CreateTableProcessor::VERBOSE);
|
||||
|
||||
ddlpackage::SqlStatement &stmt = *ptree.fList[0];
|
||||
ddlpackage::SqlStatement& stmt = *ptree.fList[0];
|
||||
ddlpackageprocessor::CreateTableProcessor::DDLResult result;
|
||||
|
||||
result = processor.processPackage(dynamic_cast<ddlpackage::CreateTableStatement&>(stmt));
|
||||
std::cout << "return: " << result.result << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
|
||||
throw;
|
||||
@@ -493,9 +495,11 @@ void destroySemaphores()
|
||||
|
||||
semkey = 0x2149bdd2;
|
||||
sems = semget(semkey, 2, 0666);
|
||||
|
||||
if (sems != -1)
|
||||
{
|
||||
err = semctl(sems, 0, IPC_RMID);
|
||||
|
||||
if (err == -1)
|
||||
perror("tdriver: semctl");
|
||||
}
|
||||
@@ -508,9 +512,11 @@ void destroyShmseg()
|
||||
|
||||
shmkey = 0x2149bdd2;
|
||||
shms = shmget(shmkey, 0, 0666);
|
||||
|
||||
if (shms != -1)
|
||||
{
|
||||
err = shmctl(shms, IPC_RMID, NULL);
|
||||
|
||||
if (err == -1 && errno != EINVAL)
|
||||
{
|
||||
perror("tdriver: shmctl");
|
||||
@@ -650,7 +656,7 @@ public:
|
||||
|
||||
cout << "\nDML statement:" << dmlStatement.c_str() << endl;
|
||||
|
||||
VendorDMLStatement dmlStmt(dmlStatement,1);
|
||||
VendorDMLStatement dmlStmt(dmlStatement, 1);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
CPPUNIT_ASSERT( 0 != pDMLPackage );
|
||||
|
||||
@@ -676,7 +682,7 @@ public:
|
||||
|
||||
cout << "\nDML statement:" << dmlStatement.c_str() << endl;
|
||||
|
||||
VendorDMLStatement dmlStmt(dmlStatement,1);
|
||||
VendorDMLStatement dmlStmt(dmlStatement, 1);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
CPPUNIT_ASSERT( 0 != pDMLPackage );
|
||||
|
||||
@@ -708,7 +714,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT( DML_INSERT == package_type );
|
||||
|
||||
InsertDMLPackage *pObject = new InsertDMLPackage();
|
||||
InsertDMLPackage* pObject = new InsertDMLPackage();
|
||||
|
||||
pObject->read( bs );
|
||||
|
||||
@@ -720,6 +726,7 @@ public:
|
||||
|
||||
pkgProcPtr->setDebugLevel(DMLPackageProcessor::VERBOSE);
|
||||
DMLPackageProcessor::DMLResult result = pkgProcPtr->processPackage( *pObject );
|
||||
|
||||
if ( DMLPackageProcessor::NO_ERROR != result.result )
|
||||
{
|
||||
cout << "Insert failed!" << endl;
|
||||
@@ -770,7 +777,7 @@ public:
|
||||
|
||||
cout << "\nDML statement:" << dmlStatement.c_str() << endl;
|
||||
|
||||
VendorDMLStatement dmlStmt(dmlStatement,1);
|
||||
VendorDMLStatement dmlStmt(dmlStatement, 1);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
CPPUNIT_ASSERT( 0 != pDMLPackage );
|
||||
|
||||
@@ -801,7 +808,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT( DML_DELETE == package_type );
|
||||
|
||||
DeleteDMLPackage *pObject = new DeleteDMLPackage();
|
||||
DeleteDMLPackage* pObject = new DeleteDMLPackage();
|
||||
|
||||
pObject->read( bs );
|
||||
|
||||
@@ -822,6 +829,7 @@ public:
|
||||
|
||||
ml.logDebugMessage( result.message );
|
||||
}
|
||||
|
||||
delete pkgProcPtr;
|
||||
delete pObject;
|
||||
|
||||
@@ -837,7 +845,7 @@ public:
|
||||
|
||||
cout << "\nDML statement:" << dmlStatement.c_str() << endl;
|
||||
|
||||
VendorDMLStatement dmlStmt(dmlStatement,1);
|
||||
VendorDMLStatement dmlStmt(dmlStatement, 1);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
CPPUNIT_ASSERT( 0 != pDMLPackage );
|
||||
|
||||
@@ -866,6 +874,7 @@ public:
|
||||
ByteStream bytestream;
|
||||
|
||||
std::vector<std::string>::const_iterator iter = commands.begin();
|
||||
|
||||
while (iter != commands.end())
|
||||
{
|
||||
std::string command = *iter;
|
||||
@@ -873,6 +882,7 @@ public:
|
||||
|
||||
VendorDMLStatement dml_command(command, 1);
|
||||
CalpontDMLPackage* dmlCommandPkgPtr = CalpontDMLFactory::makeCalpontDMLPackage(dml_command);
|
||||
|
||||
if (dmlCommandPkgPtr)
|
||||
{
|
||||
cout << "CalpontDMLFactory::makeCalpontDMLPackage: success" << endl;
|
||||
@@ -900,7 +910,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT( DML_COMMAND == package_type );
|
||||
|
||||
CommandDMLPackage *pObject = new CommandDMLPackage();
|
||||
CommandDMLPackage* pObject = new CommandDMLPackage();
|
||||
|
||||
pObject->read( bs );
|
||||
|
||||
@@ -921,6 +931,7 @@ public:
|
||||
|
||||
ml.logDebugMessage( result.message );
|
||||
}
|
||||
|
||||
delete pkgProcPtr;
|
||||
delete pObject;
|
||||
}
|
||||
@@ -967,7 +978,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT( DML_UPDATE == package_type );
|
||||
|
||||
UpdateDMLPackage *pObject = new UpdateDMLPackage();
|
||||
UpdateDMLPackage* pObject = new UpdateDMLPackage();
|
||||
|
||||
pObject->read( bs );
|
||||
|
||||
@@ -1002,13 +1013,13 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DMLPackageProcessorTest );
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
|
||||
int main( int argc, char **argv)
|
||||
int main( int argc, char** argv)
|
||||
{
|
||||
// Uncomment before running tests
|
||||
//setUp();
|
||||
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
runner.addTest( registry.makeTest() );
|
||||
bool wasSuccessful = runner.run( "", false );
|
||||
|
||||
|
||||
139
dbcon/dmlpackageproc/updatepackageprocessor.cpp
Executable file → Normal file
139
dbcon/dmlpackageproc/updatepackageprocessor.cpp
Executable file → Normal file
@@ -78,10 +78,12 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
txnid.valid = true;
|
||||
fSessionID = cpackage.get_SessionID();
|
||||
VERBOSE_INFO("Processing Update DML Package...");
|
||||
TablelockData * tablelockData = TablelockData::makeTablelockData(fSessionID);
|
||||
TablelockData* tablelockData = TablelockData::makeTablelockData(fSessionID);
|
||||
uint64_t uniqueId = 0;
|
||||
|
||||
//Bug 5070. Added exception handling
|
||||
try {
|
||||
try
|
||||
{
|
||||
uniqueId = fDbrm->getUnique64();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
@@ -116,6 +118,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
tableName.table = tablePtr->get_TableName();
|
||||
fWEClient->addQueue(uniqueId);
|
||||
execplan::CalpontSystemCatalog::ROPair roPair;
|
||||
|
||||
//#ifdef PROFILE
|
||||
// StopWatch timer;
|
||||
//#endif
|
||||
@@ -126,7 +129,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
logging::Message msg(1);
|
||||
args1.add("Start SQL statement: ");
|
||||
ostringstream oss;
|
||||
oss << cpackage.get_SQLStatement() << "|" << tablePtr->get_SchemaName()<<"|";
|
||||
oss << cpackage.get_SQLStatement() << "|" << tablePtr->get_SchemaName() << "|";
|
||||
args1.add(oss.str());
|
||||
msg.format( args1 );
|
||||
logging::Logger logger(logid.fSubsysID);
|
||||
@@ -134,10 +137,12 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
|
||||
VERBOSE_INFO("The table name is:");
|
||||
VERBOSE_INFO(tablePtr->get_TableName());
|
||||
|
||||
if (0 != tablePtr)
|
||||
{
|
||||
// get the row(s) from the table
|
||||
RowList rows = tablePtr->get_RowList();
|
||||
|
||||
if (rows.size() == 0)
|
||||
{
|
||||
SUMMARY_INFO("No row to update!");
|
||||
@@ -147,6 +152,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
|
||||
roPair = systemCatalogPtr->tableRID(tableName);
|
||||
tableLockId = tablelockData->getTablelockId(roPair.objnum); //check whether this table is locked already for this session
|
||||
|
||||
if (tableLockId == 0)
|
||||
{
|
||||
//cout << "tablelock is not found in cache, getting from dbrm" << endl;
|
||||
@@ -155,15 +161,17 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
int32_t sessionId = fSessionID;
|
||||
std::string processName("DMLProc");
|
||||
int i = 0;
|
||||
OamCache * oamcache = OamCache::makeOamCache();
|
||||
OamCache* oamcache = OamCache::makeOamCache();
|
||||
std::vector<int> pmList = oamcache->getModuleIds();
|
||||
std::vector<uint32_t> pms;
|
||||
for (unsigned i=0; i < pmList.size(); i++)
|
||||
|
||||
for (unsigned i = 0; i < pmList.size(); i++)
|
||||
{
|
||||
pms.push_back((uint32_t)pmList[i]);
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnId, BRM::LOADING );
|
||||
}
|
||||
catch (std::exception&)
|
||||
@@ -180,8 +188,8 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
numTries = waitPeriod * 10;
|
||||
struct timespec rm_ts;
|
||||
|
||||
rm_ts.tv_sec = sleepTime/1000;
|
||||
rm_ts.tv_nsec = sleepTime%1000 *1000000;
|
||||
rm_ts.tv_sec = sleepTime / 1000;
|
||||
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
|
||||
|
||||
for (; i < numTries; i++)
|
||||
{
|
||||
@@ -189,14 +197,18 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
Sleep(rm_ts.tv_sec * 1000);
|
||||
#else
|
||||
struct timespec abs_ts;
|
||||
|
||||
do
|
||||
{
|
||||
abs_ts.tv_sec = rm_ts.tv_sec;
|
||||
abs_ts.tv_nsec = rm_ts.tv_nsec;
|
||||
}
|
||||
while(nanosleep(&abs_ts,&rm_ts) < 0);
|
||||
while (nanosleep(&abs_ts, &rm_ts) < 0);
|
||||
|
||||
#endif
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
processID = ::getpid();
|
||||
txnId = txnid.id;
|
||||
sessionId = fSessionID;
|
||||
@@ -211,6 +223,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
if (tableLockId > 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i >= numTries) //error out
|
||||
{
|
||||
result.result = UPDATE_ERROR;
|
||||
@@ -220,16 +233,18 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
args.add(processName);
|
||||
args.add((uint64_t)processID);
|
||||
args.add(sessionId);
|
||||
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED,args));
|
||||
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//cout << " tablelock is obtained with id " << tableLockId << endl;
|
||||
tablelockData->setTablelock(roPair.objnum, tableLockId);
|
||||
//@Bug 4491 start AI sequence for autoincrement column
|
||||
const CalpontSystemCatalog::RIDList ridList = systemCatalogPtr->columnRIDs(tableName);
|
||||
CalpontSystemCatalog::RIDList::const_iterator rid_iterator = ridList.begin();
|
||||
CalpontSystemCatalog::ColType colType;
|
||||
|
||||
while (rid_iterator != ridList.end())
|
||||
{
|
||||
// If user hit ctrl+c in the mysql console, this will be true.
|
||||
@@ -238,8 +253,10 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
result.result = JOB_CANCELED;
|
||||
break;
|
||||
}
|
||||
|
||||
CalpontSystemCatalog::ROPair roPair = *rid_iterator;
|
||||
colType = systemCatalogPtr->colType(roPair.objnum);
|
||||
|
||||
if (colType.autoincrement)
|
||||
{
|
||||
try
|
||||
@@ -254,10 +271,12 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
throw std::runtime_error(ex.what());
|
||||
}
|
||||
}
|
||||
|
||||
++rid_iterator;
|
||||
}
|
||||
|
||||
uint64_t rowsProcessed = 0;
|
||||
|
||||
if (!fRollbackPending)
|
||||
{
|
||||
rowsProcessed = fixUpRows(cpackage, result, uniqueId, roPair.objnum);
|
||||
@@ -291,6 +310,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
{
|
||||
result.result = UPDATE_ERROR;
|
||||
}
|
||||
|
||||
result.message = Message(ex.what());
|
||||
result.rowCount = 0;
|
||||
LoggingID logid( DMLLoggingId, fSessionID, txnid.id);
|
||||
@@ -323,16 +343,19 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
logging::Logger logger(logid.fSubsysID);
|
||||
logger.logMessage(LOG_TYPE_DEBUG, msg, logid);
|
||||
}
|
||||
|
||||
// timer.finish();
|
||||
//@Bug 1886,2870 Flush VM cache only once per statement. send to all PMs.
|
||||
//WriteEngineWrapper writeEngine;
|
||||
std::map<uint32_t,uint32_t> oids;
|
||||
std::map<uint32_t, uint32_t> oids;
|
||||
int rc = 0;
|
||||
|
||||
if (result.result == NO_ERROR || result.result == IDBRANGE_WARNING)
|
||||
{
|
||||
if ((rc = flushDataFiles(NO_ERROR, oids, uniqueId, txnid, roPair.objnum)) != NO_ERROR)
|
||||
{
|
||||
cerr << "UpdatePackageProcessor::processPackage: write data to disk failed" << endl;
|
||||
|
||||
if (!fRollbackPending)
|
||||
{
|
||||
logging::Message::Args args;
|
||||
@@ -347,6 +370,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
result.message = message;
|
||||
result.rowCount = 0;
|
||||
}
|
||||
|
||||
rc = endTransaction(uniqueId, txnid, false);
|
||||
}
|
||||
else
|
||||
@@ -355,6 +379,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
rc = endTransaction(uniqueId, txnid, false);
|
||||
else
|
||||
rc = endTransaction(uniqueId, txnid, true);
|
||||
|
||||
if (( rc != NO_ERROR) && (!fRollbackPending))
|
||||
{
|
||||
logging::Message::Args args;
|
||||
@@ -378,13 +403,14 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
|
||||
rc = flushDataFiles(result.result, oids, uniqueId, txnid, roPair.objnum);
|
||||
rc = endTransaction(uniqueId, txnid, false);
|
||||
}
|
||||
|
||||
//timer.finish();
|
||||
|
||||
/* if (result.result != IDBRANGE_WARNING)
|
||||
/* if (result.result != IDBRANGE_WARNING)
|
||||
flushDataFiles(result.result, oids, uniqueId, txnid);
|
||||
else
|
||||
flushDataFiles(0, oids, uniqueId, txnid);
|
||||
*/
|
||||
*/
|
||||
if (fRollbackPending)
|
||||
{
|
||||
result.result = JOB_CANCELED;
|
||||
@@ -409,20 +435,23 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
|
||||
uint64_t rowsProcessed = 0;
|
||||
uint32_t dbroot = 1;
|
||||
bool metaData = false;
|
||||
oam::OamCache * oamCache = oam::OamCache::makeOamCache();
|
||||
oam::OamCache* oamCache = oam::OamCache::makeOamCache();
|
||||
std::vector<int> fPMs = oamCache->getModuleIds();
|
||||
std::map<unsigned, bool> pmState;
|
||||
string emsg;
|
||||
string emsgStr;
|
||||
bool err = false;
|
||||
|
||||
//boost::scoped_ptr<messageqcpp::MessageQueueClient> fExeMgr;
|
||||
//fExeMgr.reset( new messageqcpp::MessageQueueClient("ExeMgr1"));
|
||||
try {
|
||||
try
|
||||
{
|
||||
|
||||
for (unsigned i=0; i<fPMs.size(); i++)
|
||||
for (unsigned i = 0; i < fPMs.size(); i++)
|
||||
{
|
||||
pmState[fPMs[i]] = true;
|
||||
}
|
||||
|
||||
//timer.start("ExeMgr");
|
||||
fExeMgr->write(msg);
|
||||
fExeMgr->write(*(cpackage.get_ExecutionPlan()));
|
||||
@@ -430,9 +459,11 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
|
||||
msg.restart();
|
||||
emsgBs.restart();
|
||||
msg = fExeMgr->read(); //error handling
|
||||
|
||||
if (msg.length() == 4)
|
||||
{
|
||||
msg >> qb;
|
||||
|
||||
if (qb != 0)
|
||||
err = true;
|
||||
}
|
||||
@@ -441,6 +472,7 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
|
||||
qb = 999;
|
||||
err = true;
|
||||
}
|
||||
|
||||
if (err)
|
||||
{
|
||||
logging::Message::Args args;
|
||||
@@ -455,6 +487,7 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
|
||||
}
|
||||
|
||||
emsgBs = fExeMgr->read();
|
||||
|
||||
if (emsgBs.length() == 0)
|
||||
{
|
||||
logging::Message::Args args;
|
||||
@@ -469,16 +502,19 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
|
||||
}
|
||||
|
||||
emsgBs >> emsgStr;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (fRollbackPending)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
msg.restart();
|
||||
msgBk.restart();
|
||||
msg = fExeMgr->read();
|
||||
msgBk = msg;
|
||||
|
||||
if ( msg.length() == 0 )
|
||||
{
|
||||
cerr << "UpdatePackageProcessor::processPackage::fixupRows" << endl;
|
||||
@@ -512,10 +548,12 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
|
||||
//timer.stop("Meta");
|
||||
continue;
|
||||
}
|
||||
|
||||
rgData.deserialize(msg, true);
|
||||
rowGroup->setData(&rgData);
|
||||
//rowGroup->setData(const_cast<uint8_t*>(msg.buf()));
|
||||
err = (rowGroup->getStatus() != 0);
|
||||
|
||||
if (err)
|
||||
{
|
||||
//msgBk.advance(rowGroup->getDataSize());
|
||||
@@ -530,20 +568,22 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
|
||||
result.message = message;
|
||||
DMLResult tmpResult;
|
||||
receiveAll( tmpResult, uniqueId, fPMs, pmState, tableOid);
|
||||
/* qb = 100;
|
||||
/* qb = 100;
|
||||
//@Bug 4358 get rid of broken pipe error.
|
||||
msg.restart();
|
||||
msg << qb;
|
||||
fExeMgr->write(msg);
|
||||
*/ //timer.finish();
|
||||
*/ //timer.finish();
|
||||
//return rowsProcessed;
|
||||
//err = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (rowGroup->getRGData() == NULL)
|
||||
{
|
||||
msg.restart();
|
||||
}
|
||||
|
||||
if (rowGroup->getRowCount() == 0) //done fetching
|
||||
{
|
||||
//timer.finish();
|
||||
@@ -552,16 +592,20 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
|
||||
//return rowsProcessed;
|
||||
break;
|
||||
}
|
||||
|
||||
if (rowGroup->getBaseRid() == (uint64_t) (-1))
|
||||
{
|
||||
continue; // @bug4247, not valid row ids, may from small side outer
|
||||
}
|
||||
|
||||
dbroot = rowGroup->getDBRoot();
|
||||
//cout << "dbroot in the rowgroup is " << dbroot << endl;
|
||||
//timer.start("processRowgroup");
|
||||
err = processRowgroup(msgBk, result, uniqueId, cpackage, pmState, metaData, dbroot);
|
||||
|
||||
//timer.stop("processRowgroup");
|
||||
if (err) {
|
||||
if (err)
|
||||
{
|
||||
//timer.finish();
|
||||
LoggingID logid( DMLLoggingId, fSessionID, cpackage.get_TxnID());
|
||||
logging::Message::Args args1;
|
||||
@@ -578,17 +622,19 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
|
||||
msg2.format( args2 );
|
||||
logger.logMessage(LOG_TYPE_DEBUG, msg2, logid);
|
||||
//@Bug 4358 get rid of broken pipe error.
|
||||
/* msg.restart();
|
||||
/* msg.restart();
|
||||
msg << qb;
|
||||
fExeMgr->write(msg);
|
||||
return rowsProcessed;
|
||||
*/
|
||||
*/
|
||||
//err = true;
|
||||
break;
|
||||
}
|
||||
|
||||
rowsProcessed += rowGroup->getRowCount();
|
||||
}
|
||||
}
|
||||
|
||||
if (fRollbackPending)
|
||||
{
|
||||
err = true;
|
||||
@@ -610,6 +656,7 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
|
||||
DMLResult tmpResult;
|
||||
receiveAll( tmpResult, uniqueId, fPMs, pmState, tableOid);
|
||||
}
|
||||
|
||||
// get stats from ExeMgr
|
||||
if (!err)
|
||||
{
|
||||
@@ -631,6 +678,7 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
|
||||
msg << qb;
|
||||
fExeMgr->write(msg);
|
||||
}
|
||||
|
||||
return rowsProcessed;
|
||||
//stats.insert();
|
||||
}
|
||||
@@ -666,11 +714,12 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
|
||||
fExeMgr->write(msg);
|
||||
return rowsProcessed;
|
||||
}
|
||||
|
||||
//timer.finish();
|
||||
return rowsProcessed;
|
||||
}
|
||||
|
||||
bool UpdatePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult& result, const uint64_t uniqueId,
|
||||
bool UpdatePackageProcessor::processRowgroup(ByteStream& aRowGroup, DMLResult& result, const uint64_t uniqueId,
|
||||
dmlpackage::CalpontDMLPackage& cpackage, std::map<unsigned, bool>& pmState, bool isMeta, uint32_t dbroot)
|
||||
{
|
||||
bool rc = false;
|
||||
@@ -696,18 +745,23 @@ bool UpdatePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
|
||||
{
|
||||
cpackage.write(bytestream);
|
||||
fWEClient->write_to_all(bytestream);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (msgRecived == fWEClient->getPmCount())
|
||||
break;
|
||||
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = true;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
|
||||
if (tmp8 > 0)
|
||||
{
|
||||
*bsIn >> errorMsg;
|
||||
@@ -725,12 +779,14 @@ bool UpdatePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
|
||||
msgRecived++;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (pmState[pmNum])
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
//cout << "sending rows to pm " << pmNum << " with msg length " << bytestream.length() << endl;
|
||||
fWEClient->write(bytestream, (uint32_t)pmNum);
|
||||
pmState[pmNum] = false;
|
||||
@@ -763,8 +819,11 @@ bool UpdatePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
|
||||
while (1)
|
||||
{
|
||||
bsIn.reset(new ByteStream());
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
rc = true;
|
||||
@@ -775,6 +834,7 @@ bool UpdatePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
*bsIn >> errorMsg;
|
||||
|
||||
if (tmp8 == IDBRANGE_WARNING)
|
||||
{
|
||||
result.result = IDBRANGE_WARNING;
|
||||
@@ -789,15 +849,18 @@ bool UpdatePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
|
||||
result.stats.fErrorNo = tmp8;
|
||||
rc = (tmp8 != 0);
|
||||
}
|
||||
|
||||
*bsIn >> tmp32;
|
||||
//cout << "Received response from pm " << tmp32 << endl;
|
||||
pmState[tmp32] = true;
|
||||
*bsIn >> blocksChanged;
|
||||
result.stats.fBlocksChanged += blocksChanged;
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
throw std::runtime_error(errorMsg);
|
||||
}
|
||||
|
||||
if (tmp32 == (uint32_t)pmNum)
|
||||
{
|
||||
//cout << "sending rows to pm " << pmNum << " with msg length " << bytestream.length() << endl;
|
||||
@@ -833,6 +896,7 @@ bool UpdatePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -842,7 +906,8 @@ bool UpdatePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
|
||||
//check how many message we need to receive
|
||||
uint32_t messagesNotReceived = 0;
|
||||
bool err = false;
|
||||
for (unsigned i=0; i<fPMs.size(); i++)
|
||||
|
||||
for (unsigned i = 0; i < fPMs.size(); i++)
|
||||
{
|
||||
if (!pmState[fPMs[i]])
|
||||
messagesNotReceived++;
|
||||
@@ -852,16 +917,18 @@ bool UpdatePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
|
||||
ByteStream::byte tmp8;
|
||||
string errorMsg;
|
||||
uint32_t msgReceived = 0;
|
||||
|
||||
if (messagesNotReceived > 0)
|
||||
{
|
||||
LoggingID logid( DMLLoggingId, fSessionID, fSessionID);
|
||||
|
||||
if ( messagesNotReceived > fWEClient->getPmCount())
|
||||
{
|
||||
logging::Message::Args args1;
|
||||
logging::Message msg(1);
|
||||
args1.add("Update outstanding messages exceed PM count , need to receive messages:PMcount = ");
|
||||
ostringstream oss;
|
||||
oss << messagesNotReceived <<":"<<fWEClient->getPmCount();
|
||||
oss << messagesNotReceived << ":" << fWEClient->getPmCount();
|
||||
args1.add(oss.str());
|
||||
msg.format( args1 );
|
||||
logging::Logger logger(logid.fSubsysID);
|
||||
@@ -887,17 +954,22 @@ bool UpdatePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
|
||||
break;
|
||||
|
||||
bsIn.reset(new ByteStream());
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
fWEClient->read(uniqueId, bsIn);
|
||||
|
||||
if ( bsIn->length() == 0 ) //read error
|
||||
{
|
||||
err = true;
|
||||
errorMsg = "Lost connection to Write Engine Server while updating";
|
||||
throw std::runtime_error(errorMsg);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*bsIn >> tmp8;
|
||||
*bsIn >> errorMsg;
|
||||
|
||||
if (tmp8 == IDBRANGE_WARNING)
|
||||
{
|
||||
result.result = IDBRANGE_WARNING;
|
||||
@@ -912,13 +984,17 @@ bool UpdatePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
|
||||
result.stats.fErrorNo = tmp8;
|
||||
err = (tmp8 != 0);
|
||||
}
|
||||
|
||||
*bsIn >> tmp32;
|
||||
*bsIn >> blocksChanged;
|
||||
//cout << "Received response from pm " << tmp32 << endl;
|
||||
pmState[tmp32] = true;
|
||||
if (err) {
|
||||
|
||||
if (err)
|
||||
{
|
||||
throw std::runtime_error(errorMsg);
|
||||
}
|
||||
|
||||
msgReceived++;
|
||||
result.stats.fBlocksChanged += blocksChanged;
|
||||
}
|
||||
@@ -949,6 +1025,7 @@ bool UpdatePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
} // namespace dmlpackageprocessor
|
||||
|
||||
@@ -45,7 +45,8 @@ class UpdatePackageProcessor : public DMLPackageProcessor
|
||||
{
|
||||
|
||||
public:
|
||||
UpdatePackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid) {
|
||||
UpdatePackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid)
|
||||
{
|
||||
}
|
||||
/** @brief process an UpdateDMLPackage
|
||||
*
|
||||
@@ -71,9 +72,9 @@ private:
|
||||
* @param result the result of the operation
|
||||
* @return the error code
|
||||
*/
|
||||
bool processRowgroup(messageqcpp::ByteStream & aRowGroup, DMLResult& result, const uint64_t uniqueId, dmlpackage::CalpontDMLPackage& cpackage, std::map<unsigned, bool>& pmState, bool isMeta = false, uint32_t dbroot=1);
|
||||
bool processRowgroup(messageqcpp::ByteStream& aRowGroup, DMLResult& result, const uint64_t uniqueId, dmlpackage::CalpontDMLPackage& cpackage, std::map<unsigned, bool>& pmState, bool isMeta = false, uint32_t dbroot = 1);
|
||||
bool receiveAll(DMLResult& result, const uint64_t uniqueId, std::vector<int>& fPMs, std::map<unsigned, bool>& pmState, const uint32_t tableOid);
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
#ifndef DBCON_CALPONTSYSTEMCATALOG_H
|
||||
#define DBCON_CALPONTSYSTEMCATALOG_H
|
||||
|
||||
namespace dbcon {
|
||||
namespace dbcon
|
||||
{
|
||||
|
||||
class CalpontSystemCatalog
|
||||
{
|
||||
|
||||
@@ -43,17 +43,19 @@ using namespace joblist;
|
||||
#include "functioncolumn.h"
|
||||
#include "objectreader.h"
|
||||
|
||||
namespace execplan {
|
||||
namespace execplan
|
||||
{
|
||||
|
||||
void getAggCols(execplan::ParseTree* n, void* obj)
|
||||
{
|
||||
vector<AggregateColumn*>* list = reinterpret_cast< vector<AggregateColumn*>*>(obj);
|
||||
TreeNode* tn = n->data();
|
||||
AggregateColumn *sc = dynamic_cast<AggregateColumn*>(tn);
|
||||
FunctionColumn *fc = dynamic_cast<FunctionColumn*>(tn);
|
||||
ArithmeticColumn *ac = dynamic_cast<ArithmeticColumn*>(tn);
|
||||
SimpleFilter *sf = dynamic_cast<SimpleFilter*>(tn);
|
||||
ConstantFilter *cf = dynamic_cast<ConstantFilter*>(tn);
|
||||
AggregateColumn* sc = dynamic_cast<AggregateColumn*>(tn);
|
||||
FunctionColumn* fc = dynamic_cast<FunctionColumn*>(tn);
|
||||
ArithmeticColumn* ac = dynamic_cast<ArithmeticColumn*>(tn);
|
||||
SimpleFilter* sf = dynamic_cast<SimpleFilter*>(tn);
|
||||
ConstantFilter* cf = dynamic_cast<ConstantFilter*>(tn);
|
||||
|
||||
if (sc)
|
||||
{
|
||||
list->push_back(sc);
|
||||
@@ -161,13 +163,17 @@ const string AggregateColumn::toString() const
|
||||
output << "AggregateColumn " << data() << endl;
|
||||
output << "func/distinct: " << (int)fAggOp << "/" << fDistinct << endl;
|
||||
output << "expressionId=" << fExpressionId << endl;
|
||||
|
||||
if (fAlias.length() > 0) output << "/Alias: " << fAlias << endl;
|
||||
|
||||
if (fFunctionParms == 0)
|
||||
output << "No arguments" << endl;
|
||||
else
|
||||
output << *fFunctionParms << endl;
|
||||
|
||||
if (fConstCol)
|
||||
output << *fConstCol;
|
||||
|
||||
return output.str();
|
||||
}
|
||||
|
||||
@@ -184,20 +190,27 @@ void AggregateColumn::serialize(messageqcpp::ByteStream& b) const
|
||||
ReturnedColumn::serialize(b);
|
||||
b << fFunctionName;
|
||||
b << static_cast<uint8_t>(fAggOp);
|
||||
|
||||
if (fFunctionParms == 0)
|
||||
b << (uint8_t) ObjectReader::NULL_CLASS;
|
||||
else
|
||||
fFunctionParms->serialize(b);
|
||||
|
||||
b << static_cast<uint32_t>(fGroupByColList.size());
|
||||
|
||||
for (rcit = fGroupByColList.begin(); rcit != fGroupByColList.end(); ++rcit)
|
||||
(*rcit)->serialize(b);
|
||||
|
||||
b << static_cast<uint32_t>(fProjectColList.size());
|
||||
|
||||
for (rcit = fProjectColList.begin(); rcit != fProjectColList.end(); ++rcit)
|
||||
(*rcit)->serialize(b);
|
||||
|
||||
b << fData;
|
||||
//b << fAlias;
|
||||
b << fTableAlias;
|
||||
b << static_cast<const ByteStream::doublebyte>(fAsc);
|
||||
|
||||
if (fConstCol.get() == 0)
|
||||
b << (uint8_t) ObjectReader::NULL_CLASS;
|
||||
else
|
||||
@@ -218,20 +231,26 @@ void AggregateColumn::unserialize(messageqcpp::ByteStream& b)
|
||||
|
||||
messageqcpp::ByteStream::quadbyte size;
|
||||
messageqcpp::ByteStream::quadbyte i;
|
||||
ReturnedColumn *rc;
|
||||
ReturnedColumn* rc;
|
||||
|
||||
b >> size;
|
||||
for (i = 0; i < size; i++) {
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
rc = dynamic_cast<ReturnedColumn*>(ObjectReader::createTreeNode(b));
|
||||
SRCP srcp(rc);
|
||||
fGroupByColList.push_back(srcp);
|
||||
}
|
||||
|
||||
b >> size;
|
||||
for (i = 0; i < size; i++) {
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
rc = dynamic_cast<ReturnedColumn*>(ObjectReader::createTreeNode(b));
|
||||
SRCP srcp(rc);
|
||||
fProjectColList.push_back(srcp);
|
||||
}
|
||||
|
||||
b >> fData;
|
||||
//b >> fAlias;
|
||||
b >> fTableAlias;
|
||||
@@ -241,18 +260,23 @@ void AggregateColumn::unserialize(messageqcpp::ByteStream& b)
|
||||
|
||||
bool AggregateColumn::operator==(const AggregateColumn& t) const
|
||||
{
|
||||
const ReturnedColumn *rc1, *rc2;
|
||||
const ReturnedColumn* rc1, *rc2;
|
||||
|
||||
rc1 = static_cast<const ReturnedColumn*>(this);
|
||||
rc2 = static_cast<const ReturnedColumn*>(&t);
|
||||
|
||||
if (*rc1 != *rc2)
|
||||
return false;
|
||||
|
||||
if (fFunctionName != t.fFunctionName)
|
||||
return false;
|
||||
|
||||
if (fAggOp == COUNT_ASTERISK && t.fAggOp == COUNT_ASTERISK)
|
||||
return true;
|
||||
|
||||
if (fAggOp != t.fAggOp)
|
||||
return false;
|
||||
|
||||
if (fFunctionParms.get() != NULL && t.fFunctionParms.get() != NULL)
|
||||
{
|
||||
if (*fFunctionParms.get() != t.fFunctionParms.get())
|
||||
@@ -260,29 +284,36 @@ bool AggregateColumn::operator==(const AggregateColumn& t) const
|
||||
}
|
||||
else if (fFunctionParms.get() != NULL || t.fFunctionParms.get() != NULL)
|
||||
return false;
|
||||
|
||||
//if (fAlias != t.fAlias)
|
||||
// return false;
|
||||
if (fTableAlias != t.fTableAlias)
|
||||
return false;
|
||||
|
||||
if (fData != t.fData)
|
||||
return false;
|
||||
|
||||
if (fAsc != t.fAsc)
|
||||
return false;
|
||||
|
||||
if ((fConstCol.get() != NULL && t.fConstCol.get() == NULL) ||
|
||||
(fConstCol.get() == NULL && t.fConstCol.get() != NULL) ||
|
||||
(fConstCol.get() != NULL && t.fConstCol.get() != NULL &&
|
||||
*(fConstCol.get()) != t.fConstCol.get()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AggregateColumn::operator==(const TreeNode* t) const
|
||||
{
|
||||
const AggregateColumn *ac;
|
||||
const AggregateColumn* ac;
|
||||
|
||||
ac = dynamic_cast<const AggregateColumn*>(t);
|
||||
|
||||
if (ac == NULL)
|
||||
return false;
|
||||
|
||||
return *this == *ac;
|
||||
}
|
||||
|
||||
@@ -311,13 +342,17 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
|
||||
isNull = true;
|
||||
else
|
||||
fResult.intVal = row.getUintField<4>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
if (row.equals<8>(DATETIMENULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.intVal = row.getUintField<8>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::CHAR:
|
||||
case CalpontSystemCatalog::VARCHAR:
|
||||
case CalpontSystemCatalog::STRINT:
|
||||
@@ -329,20 +364,26 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
|
||||
isNull = true;
|
||||
else
|
||||
fResult.origIntVal = row.getUintField<1>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (row.equals<2>(CHAR2NULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.origIntVal = row.getUintField<2>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
case 4:
|
||||
if (row.equals<4>(CHAR4NULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.origIntVal = row.getUintField<4>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
@@ -351,72 +392,95 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
|
||||
isNull = true;
|
||||
else
|
||||
fResult.origIntVal = row.getUintField<8>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
if (row.equals(CPNULLSTRMARK, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.strVal = row.getStringField(fInputIndex);
|
||||
|
||||
// stringColVal is padded with '\0' to colWidth so can't use str.length()
|
||||
if (strlen(fResult.strVal.c_str()) == 0)
|
||||
isNull = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (fResultType.colDataType == CalpontSystemCatalog::STRINT)
|
||||
fResult.intVal = uint64ToStr(fResult.origIntVal);
|
||||
else
|
||||
fResult.intVal = atoll((char*)&fResult.origIntVal);
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
if (row.equals<8>(BIGINTNULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.intVal = row.getIntField<8>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
if (row.equals<8>(UBIGINTNULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.uintVal = row.getUintField<8>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
if (row.equals<4>(INTNULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.intVal = row.getIntField<4>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
if (row.equals<4>(UINTNULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.uintVal = row.getUintField<4>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
if (row.equals<2>(SMALLINTNULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.intVal = row.getIntField<2>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
if (row.equals<2>(USMALLINTNULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.uintVal = row.getUintField<2>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
if (row.equals<1>(TINYINTNULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.intVal = row.getIntField<1>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
if (row.equals<1>(UTINYINTNULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.uintVal = row.getUintField<1>(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
//In this case, we're trying to load a double output column with float data. This is the
|
||||
// case when you do sum(floatcol), e.g.
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
@@ -425,14 +489,18 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
|
||||
isNull = true;
|
||||
else
|
||||
fResult.floatVal = row.getFloatField(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
if (row.equals<8>(DOUBLENULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.doubleVal = row.getDoubleField(fInputIndex);
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
switch (fResultType.colWidth)
|
||||
@@ -445,7 +513,9 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
|
||||
fResult.decimalVal.value = row.getIntField<1>(fInputIndex);
|
||||
fResult.decimalVal.scale = (unsigned)fResultType.scale;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (row.equals<2>(SMALLINTNULL, fInputIndex))
|
||||
isNull = true;
|
||||
@@ -454,7 +524,9 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
|
||||
fResult.decimalVal.value = row.getIntField<2>(fInputIndex);
|
||||
fResult.decimalVal.scale = (unsigned)fResultType.scale;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 4:
|
||||
if (row.equals<4>(INTNULL, fInputIndex))
|
||||
isNull = true;
|
||||
@@ -463,7 +535,9 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
|
||||
fResult.decimalVal.value = row.getIntField<4>(fInputIndex);
|
||||
fResult.decimalVal.scale = (unsigned)fResultType.scale;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
if (row.equals<8>(BIGINTNULL, fInputIndex))
|
||||
isNull = true;
|
||||
@@ -472,18 +546,23 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
|
||||
fResult.decimalVal.value = (int64_t)row.getUintField<8>(fInputIndex);
|
||||
fResult.decimalVal.scale = (unsigned)fResultType.scale;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case CalpontSystemCatalog::VARBINARY:
|
||||
case CalpontSystemCatalog::BLOB:
|
||||
isNull = true;
|
||||
break;
|
||||
|
||||
default: // treat as int64
|
||||
if (row.equals<8>(BIGINTNULL, fInputIndex))
|
||||
isNull = true;
|
||||
else
|
||||
fResult.intVal = row.getUintField<8>(fInputIndex);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -491,7 +570,7 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
|
||||
/*static*/
|
||||
AggregateColumn::AggOp AggregateColumn::agname2num(const string& agname)
|
||||
{
|
||||
/*
|
||||
/*
|
||||
NOOP = 0,
|
||||
COUNT_ASTERISK,
|
||||
COUNT,
|
||||
@@ -511,35 +590,49 @@ AggregateColumn::AggOp AggregateColumn::agname2num(const string& agname)
|
||||
BIT_OR,
|
||||
BIT_XOR,
|
||||
GROUP_CONCAT
|
||||
*/
|
||||
*/
|
||||
string lfn(agname);
|
||||
algorithm::to_lower(lfn);
|
||||
|
||||
if (lfn == "count(*)")
|
||||
return COUNT_ASTERISK;
|
||||
|
||||
if (lfn == "count")
|
||||
return COUNT;
|
||||
|
||||
if (lfn == "sum")
|
||||
return SUM;
|
||||
|
||||
if (lfn == "avg")
|
||||
return AVG;
|
||||
|
||||
if (lfn == "min")
|
||||
return MIN;
|
||||
|
||||
if (lfn == "max")
|
||||
return MAX;
|
||||
|
||||
if (lfn == "std")
|
||||
return STDDEV_POP;
|
||||
|
||||
if (lfn == "stddev_pop")
|
||||
return STDDEV_POP;
|
||||
|
||||
if (lfn == "stddev_samp")
|
||||
return STDDEV_SAMP;
|
||||
|
||||
if (lfn == "stddev")
|
||||
return STDDEV_POP;
|
||||
|
||||
if (lfn == "var_pop")
|
||||
return VAR_POP;
|
||||
|
||||
if (lfn == "var_samp")
|
||||
return VAR_SAMP;
|
||||
|
||||
if (lfn == "variance")
|
||||
return VAR_POP;
|
||||
|
||||
return NOOP;
|
||||
}
|
||||
|
||||
|
||||
94
dbcon/execplan/aggregatecolumn.h
Executable file → Normal file
94
dbcon/execplan/aggregatecolumn.h
Executable file → Normal file
@@ -29,14 +29,16 @@
|
||||
#include "calpontselectexecutionplan.h"
|
||||
#include "returnedcolumn.h"
|
||||
|
||||
namespace messageqcpp {
|
||||
namespace messageqcpp
|
||||
{
|
||||
class ByteStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Namespace
|
||||
*/
|
||||
namespace execplan {
|
||||
namespace execplan
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief A class to represent a aggregate return column
|
||||
@@ -44,7 +46,8 @@ namespace execplan {
|
||||
* This class is a specialization of class ReturnedColumn that
|
||||
* handles an aggregate function call (e.g., SUM, COUNT, MIN, MAX).
|
||||
*/
|
||||
class AggregateColumn : public ReturnedColumn {
|
||||
class AggregateColumn : public ReturnedColumn
|
||||
{
|
||||
|
||||
public:
|
||||
/**
|
||||
@@ -94,27 +97,27 @@ public:
|
||||
/**
|
||||
* ctor
|
||||
*/
|
||||
AggregateColumn(const AggOp aggop, ReturnedColumn* parm, const uint32_t sessionID=0);
|
||||
AggregateColumn(const AggOp aggop, ReturnedColumn* parm, const uint32_t sessionID = 0);
|
||||
|
||||
/**
|
||||
* ctor
|
||||
*/
|
||||
AggregateColumn(const AggOp aggop, const std::string& content, const uint32_t sessionID=0);
|
||||
AggregateColumn(const AggOp aggop, const std::string& content, const uint32_t sessionID = 0);
|
||||
|
||||
/**
|
||||
* ctor
|
||||
*/
|
||||
AggregateColumn(const std::string& functionName, ReturnedColumn* parm, const uint32_t sessionID=0);
|
||||
AggregateColumn(const std::string& functionName, ReturnedColumn* parm, const uint32_t sessionID = 0);
|
||||
|
||||
/**
|
||||
* ctor
|
||||
*/
|
||||
AggregateColumn(const std::string& functionName, const std::string& content, const uint32_t sessionID=0);
|
||||
AggregateColumn(const std::string& functionName, const std::string& content, const uint32_t sessionID = 0);
|
||||
|
||||
/**
|
||||
* ctor
|
||||
*/
|
||||
AggregateColumn( const AggregateColumn& rhs, const uint32_t sessionID=0 );
|
||||
AggregateColumn( const AggregateColumn& rhs, const uint32_t sessionID = 0 );
|
||||
|
||||
/**
|
||||
* Destructors
|
||||
@@ -140,11 +143,17 @@ public:
|
||||
/**
|
||||
* accessor
|
||||
*/
|
||||
virtual const uint8_t aggOp() const {return fAggOp;}
|
||||
virtual const uint8_t aggOp() const
|
||||
{
|
||||
return fAggOp;
|
||||
}
|
||||
/**
|
||||
* accessor
|
||||
*/
|
||||
virtual void aggOp(const uint8_t aggOp) {fAggOp = aggOp;}
|
||||
virtual void aggOp(const uint8_t aggOp)
|
||||
{
|
||||
fAggOp = aggOp;
|
||||
}
|
||||
|
||||
/** get function parms
|
||||
*
|
||||
@@ -176,29 +185,47 @@ public:
|
||||
/**
|
||||
* table alias name
|
||||
*/
|
||||
virtual const std::string tableAlias() const { return fTableAlias; }
|
||||
virtual const std::string tableAlias() const
|
||||
{
|
||||
return fTableAlias;
|
||||
}
|
||||
/**
|
||||
* table alias name
|
||||
*/
|
||||
virtual void tableAlias (const std::string& tableAlias) { fTableAlias = tableAlias; }
|
||||
virtual void tableAlias (const std::string& tableAlias)
|
||||
{
|
||||
fTableAlias = tableAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* ASC flag
|
||||
*/
|
||||
inline virtual const bool asc() const { return fAsc; }
|
||||
inline virtual const bool asc() const
|
||||
{
|
||||
return fAsc;
|
||||
}
|
||||
/**
|
||||
* ASC flag
|
||||
*/
|
||||
inline virtual void asc(const bool asc) { fAsc = asc; }
|
||||
inline virtual void asc(const bool asc)
|
||||
{
|
||||
fAsc = asc;
|
||||
}
|
||||
|
||||
/**
|
||||
* fData: SQL representation of this object
|
||||
*/
|
||||
virtual const std::string data() const { return fData; }
|
||||
virtual const std::string data() const
|
||||
{
|
||||
return fData;
|
||||
}
|
||||
/**
|
||||
* fData: SQL representation of this object
|
||||
*/
|
||||
virtual void data(const std::string& data) { fData = data; }
|
||||
virtual void data(const std::string& data)
|
||||
{
|
||||
fData = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded stream operator
|
||||
@@ -243,26 +270,44 @@ public:
|
||||
virtual bool operator!=(const AggregateColumn& t) const;
|
||||
|
||||
/** @brief push back arg to group by column list*/
|
||||
virtual void addGroupByCol(SRCP ac) {fGroupByColList.push_back(ac);}
|
||||
virtual void addGroupByCol(SRCP ac)
|
||||
{
|
||||
fGroupByColList.push_back(ac);
|
||||
}
|
||||
|
||||
/** @brief push back arg to project by column list*/
|
||||
virtual void addProjectCol(SRCP ac) {fProjectColList.push_back(ac);}
|
||||
virtual void addProjectCol(SRCP ac)
|
||||
{
|
||||
fProjectColList.push_back(ac);
|
||||
}
|
||||
|
||||
/**
|
||||
* accessor
|
||||
*/
|
||||
virtual const ColumnList& groupByColList() const { return fGroupByColList;}
|
||||
virtual const ColumnList& groupByColList() const
|
||||
{
|
||||
return fGroupByColList;
|
||||
}
|
||||
/**
|
||||
* accessor
|
||||
*/
|
||||
virtual const ColumnList& projectColList() const { return fProjectColList;}
|
||||
virtual const ColumnList& projectColList() const
|
||||
{
|
||||
return fProjectColList;
|
||||
}
|
||||
|
||||
/** @brief constant argument for aggregate with constant */
|
||||
inline const SRCP constCol() const { return fConstCol; }
|
||||
inline const SRCP constCol() const
|
||||
{
|
||||
return fConstCol;
|
||||
}
|
||||
/**
|
||||
* accessor
|
||||
*/
|
||||
inline void constCol(const SRCP& constCol) { fConstCol = constCol; }
|
||||
inline void constCol(const SRCP& constCol)
|
||||
{
|
||||
fConstCol = constCol;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert an aggregate name to an AggOp enum
|
||||
@@ -270,7 +315,10 @@ public:
|
||||
static AggOp agname2num(const std::string&);
|
||||
|
||||
virtual bool hasAggregate();
|
||||
virtual bool hasWindowFunc() {return false;}
|
||||
virtual bool hasWindowFunc()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string fFunctionName; // deprecated field
|
||||
|
||||
@@ -41,7 +41,8 @@ using namespace messageqcpp;
|
||||
#include "aggregatecolumn.h"
|
||||
#include "windowfunctioncolumn.h"
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
/** print the tree
|
||||
*
|
||||
* this function is mostly for debug purpose
|
||||
@@ -53,7 +54,8 @@ void walkfn(const execplan::ParseTree* n, ostream& output)
|
||||
|
||||
}
|
||||
|
||||
namespace execplan {
|
||||
namespace execplan
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructors/Destructors
|
||||
@@ -91,6 +93,7 @@ ArithmeticColumn::~ArithmeticColumn()
|
||||
{
|
||||
if (fExpression != NULL)
|
||||
delete fExpression;
|
||||
|
||||
fExpression = NULL;
|
||||
}
|
||||
|
||||
@@ -102,6 +105,7 @@ void ArithmeticColumn::expression(ParseTree*& expression)
|
||||
{
|
||||
if (fExpression != NULL)
|
||||
delete fExpression;
|
||||
|
||||
fExpression = expression;
|
||||
expression = 0;
|
||||
}
|
||||
@@ -116,18 +120,20 @@ void ArithmeticColumn::buildTree()
|
||||
|
||||
//string fData = ReturnedColumn::data();
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
while (fData[i])
|
||||
{
|
||||
if (isdigit(fData[i]) || fData[i] == '.')
|
||||
{
|
||||
string num;
|
||||
|
||||
while (isdigit(fData[i]) || fData[i] == '.')
|
||||
{
|
||||
num.push_back(fData[i++]);
|
||||
}
|
||||
|
||||
ConstantColumn *cc = new ConstantColumn(num, ConstantColumn::NUM);
|
||||
ConstantColumn* cc = new ConstantColumn(num, ConstantColumn::NUM);
|
||||
t.value = cc;
|
||||
|
||||
tokens.push_back(t);
|
||||
@@ -144,23 +150,23 @@ void ArithmeticColumn::buildTree()
|
||||
// t.is_operator now indicate the previous token type
|
||||
// if prev token is operand, then this '(' is func_open
|
||||
// otherwise, this '(' is open
|
||||
if (fData[i] == '(' && fData[i+1] != '-' && !t.is_operator())
|
||||
if (fData[i] == '(' && fData[i + 1] != '-' && !t.is_operator())
|
||||
{
|
||||
// open '('
|
||||
Operator *op1 = new Operator("(");
|
||||
Operator* op1 = new Operator("(");
|
||||
t.value = op1;
|
||||
tokens.push_back(t);
|
||||
|
||||
//This is not complete... we shouldn't be creating TreeNodes
|
||||
string param = nextToken(++i, ')');
|
||||
|
||||
TreeNode *tn = new TreeNodeImpl(param);
|
||||
TreeNode* tn = new TreeNodeImpl(param);
|
||||
t.value = tn;
|
||||
|
||||
tokens.push_back(t);
|
||||
|
||||
// close ')'
|
||||
Operator *op2 = new Operator(")");
|
||||
Operator* op2 = new Operator(")");
|
||||
t.value = op2;
|
||||
tokens.push_back(t);
|
||||
continue;
|
||||
@@ -173,7 +179,8 @@ void ArithmeticColumn::buildTree()
|
||||
op = "||";
|
||||
else
|
||||
op.push_back(fData[i]);
|
||||
Operator *oper = new Operator(op);
|
||||
|
||||
Operator* oper = new Operator(op);
|
||||
t.value = oper;
|
||||
|
||||
tokens.push_back(t);
|
||||
@@ -187,22 +194,24 @@ void ArithmeticColumn::buildTree()
|
||||
{
|
||||
//This is not complete... we shouldn't be creating TreeNodes
|
||||
string param = nextToken(++i, ')');
|
||||
TreeNode *sc = new TreeNodeImpl(param);
|
||||
TreeNode* sc = new TreeNodeImpl(param);
|
||||
t.value = sc;
|
||||
|
||||
tokens.push_back(t);
|
||||
|
||||
// close ')'
|
||||
Operator *oper = new Operator(")");
|
||||
Operator* oper = new Operator(")");
|
||||
t.value = oper;
|
||||
tokens.push_back(t);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
else if (isalpha(fData[i]) || fData[i] == '_' )
|
||||
{
|
||||
string identifier;
|
||||
|
||||
while (isalnum(fData[i]) ||
|
||||
fData[i] == '_' ||
|
||||
fData[i] == '.' )
|
||||
@@ -210,7 +219,7 @@ void ArithmeticColumn::buildTree()
|
||||
identifier.push_back(fData[i++]);
|
||||
}
|
||||
|
||||
SimpleColumn *sc = new SimpleColumn(identifier, fSessionID );
|
||||
SimpleColumn* sc = new SimpleColumn(identifier, fSessionID );
|
||||
t.value = sc;
|
||||
|
||||
tokens.push_back(t);
|
||||
@@ -220,12 +229,13 @@ void ArithmeticColumn::buildTree()
|
||||
else if (fData[i] == '\'')
|
||||
{
|
||||
string literal = nextToken(++i, '\'');
|
||||
ConstantColumn *cc = new ConstantColumn (literal, ConstantColumn::LITERAL);
|
||||
ConstantColumn* cc = new ConstantColumn (literal, ConstantColumn::LITERAL);
|
||||
t.value = cc;
|
||||
|
||||
tokens.push_back(t);
|
||||
continue;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
@@ -234,16 +244,17 @@ void ArithmeticColumn::buildTree()
|
||||
catch (const invalid_argument& e)
|
||||
{
|
||||
// clean up tokens
|
||||
for (unsigned int i=0; i<tokens.size(); i++)
|
||||
for (unsigned int i = 0; i < tokens.size(); i++)
|
||||
{
|
||||
delete tokens[i].value;
|
||||
tokens[i].value = 0;
|
||||
}
|
||||
|
||||
throw runtime_error(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
const string ArithmeticColumn::nextToken(string::size_type &pos, char end) const
|
||||
const string ArithmeticColumn::nextToken(string::size_type& pos, char end) const
|
||||
{
|
||||
string token;
|
||||
// string fData = ReturnedColumn::data();
|
||||
@@ -251,6 +262,7 @@ const string ArithmeticColumn::nextToken(string::size_type &pos, char end) const
|
||||
// increment num when get '(' and decrement when get ')'
|
||||
// to find the mathing ')' when num = 0
|
||||
int num = 1;
|
||||
|
||||
for (; pos < fData.length(); )
|
||||
{
|
||||
if (end == ')')
|
||||
@@ -259,6 +271,7 @@ const string ArithmeticColumn::nextToken(string::size_type &pos, char end) const
|
||||
num++;
|
||||
else if (fData[pos] == ')')
|
||||
num--;
|
||||
|
||||
if (num == 0)
|
||||
{
|
||||
pos++;
|
||||
@@ -273,6 +286,7 @@ const string ArithmeticColumn::nextToken(string::size_type &pos, char end) const
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
token.push_back(fData[pos++]);
|
||||
}
|
||||
|
||||
@@ -293,12 +307,15 @@ const string ArithmeticColumn::toString() const
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "ArithmeticColumn: ";
|
||||
|
||||
if (fAlias.length() > 0) oss << "Alias: " << fAlias << endl;
|
||||
|
||||
if (fExpression != 0) fExpression->walk(walkfn, oss);
|
||||
|
||||
oss << "expressionId=" << fExpressionId << endl;
|
||||
oss << "joinInfo=" << fJoinInfo << " returnAll=" << fReturnAll << " sequence#=" << fSequence << endl;
|
||||
oss << "resultType=" << colDataTypeToString(fResultType.colDataType) << "|" << fResultType.colWidth <<
|
||||
endl;
|
||||
endl;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -316,8 +333,10 @@ void ArithmeticColumn::unserialize(messageqcpp::ByteStream& b)
|
||||
{
|
||||
ObjectReader::checkType(b, ObjectReader::ARITHMETICCOLUMN);
|
||||
ReturnedColumn::unserialize(b);
|
||||
|
||||
if (fExpression != NULL)
|
||||
delete fExpression;
|
||||
|
||||
fExpression = ObjectReader::createParseTree(b);
|
||||
b >> fTableAlias;
|
||||
b >> fData;
|
||||
@@ -333,34 +352,43 @@ void ArithmeticColumn::unserialize(messageqcpp::ByteStream& b)
|
||||
|
||||
bool ArithmeticColumn::operator==(const ArithmeticColumn& t) const
|
||||
{
|
||||
const ReturnedColumn *rc1, *rc2;
|
||||
const ReturnedColumn* rc1, *rc2;
|
||||
|
||||
rc1 = static_cast<const ReturnedColumn*>(this);
|
||||
rc2 = static_cast<const ReturnedColumn*>(&t);
|
||||
|
||||
if (*rc1 != *rc2)
|
||||
return false;
|
||||
if (fExpression != NULL && t.fExpression != NULL) {
|
||||
|
||||
if (fExpression != NULL && t.fExpression != NULL)
|
||||
{
|
||||
if (*fExpression != *t.fExpression)
|
||||
return false;
|
||||
}
|
||||
else if (fExpression != NULL || t.fExpression != NULL)
|
||||
return false;
|
||||
|
||||
if (fAlias != t.fAlias)
|
||||
return false;
|
||||
|
||||
if (fTableAlias != t.fTableAlias)
|
||||
return false;
|
||||
|
||||
if (fData != t.fData)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArithmeticColumn::operator==(const TreeNode* t) const
|
||||
{
|
||||
const ArithmeticColumn *o;
|
||||
const ArithmeticColumn* o;
|
||||
|
||||
o = dynamic_cast<const ArithmeticColumn*>(t);
|
||||
|
||||
if (o == NULL)
|
||||
return false;
|
||||
|
||||
return *this == *o;
|
||||
}
|
||||
|
||||
@@ -377,10 +405,13 @@ bool ArithmeticColumn::operator!=(const TreeNode* t) const
|
||||
bool ArithmeticColumn::hasAggregate()
|
||||
{
|
||||
if (fHasAggregate) return true;
|
||||
|
||||
fAggColumnList.clear();
|
||||
fExpression->walk(getAggCols, &fAggColumnList);
|
||||
|
||||
if (!fAggColumnList.empty())
|
||||
fHasAggregate = true;
|
||||
|
||||
return fHasAggregate;
|
||||
}
|
||||
|
||||
@@ -388,8 +419,10 @@ bool ArithmeticColumn::hasWindowFunc()
|
||||
{
|
||||
fWindowFunctionColumnList.clear();
|
||||
fExpression->walk(getWindowFunctionCols, &fWindowFunctionColumnList);
|
||||
|
||||
if (fWindowFunctionColumnList.empty())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -400,6 +433,7 @@ void ArithmeticColumn::setDerivedTable()
|
||||
fDerivedTable = "";
|
||||
return;
|
||||
}
|
||||
|
||||
if (fExpression)
|
||||
{
|
||||
fExpression->setDerivedTable();
|
||||
@@ -423,17 +457,20 @@ bool ArithmeticColumn::singleTable(CalpontSystemCatalog::TableAliasName& tan)
|
||||
{
|
||||
tan.clear();
|
||||
setSimpleColumnList();
|
||||
|
||||
for (uint32_t i = 0; i < fSimpleColumnList.size(); i++)
|
||||
{
|
||||
CalpontSystemCatalog::TableAliasName stan(fSimpleColumnList[i]->schemaName(),
|
||||
fSimpleColumnList[i]->tableName(),
|
||||
fSimpleColumnList[i]->tableAlias(),
|
||||
fSimpleColumnList[i]->viewName());
|
||||
|
||||
if (tan.table.empty())
|
||||
tan = stan;
|
||||
else if (stan != tan)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,10 @@
|
||||
/**
|
||||
* Namespace
|
||||
*/
|
||||
namespace execplan {
|
||||
class SimpleColumn;
|
||||
class AggregateColumn;
|
||||
namespace execplan
|
||||
{
|
||||
class SimpleColumn;
|
||||
class AggregateColumn;
|
||||
|
||||
/**
|
||||
* @brief A class to represent a arithmetic expression return column
|
||||
@@ -44,11 +45,12 @@ namespace execplan {
|
||||
* This class is a specialization of class ReturnedColumn that
|
||||
* handles an arithmetic expression.
|
||||
*/
|
||||
class ArithmeticColumn : public ReturnedColumn {
|
||||
class ArithmeticColumn : public ReturnedColumn
|
||||
{
|
||||
public:
|
||||
ArithmeticColumn();
|
||||
ArithmeticColumn( const std::string& sql, const uint32_t sessionID=0 );
|
||||
ArithmeticColumn( const ArithmeticColumn& rhs, const uint32_t sessionID=0 );
|
||||
ArithmeticColumn( const std::string& sql, const uint32_t sessionID = 0 );
|
||||
ArithmeticColumn( const ArithmeticColumn& rhs, const uint32_t sessionID = 0 );
|
||||
virtual ~ArithmeticColumn();
|
||||
|
||||
inline ParseTree* expression() const
|
||||
@@ -84,22 +86,34 @@ public:
|
||||
/**
|
||||
* get asc flag
|
||||
*/
|
||||
inline const bool asc() const { return fAsc; }
|
||||
inline const bool asc() const
|
||||
{
|
||||
return fAsc;
|
||||
}
|
||||
|
||||
/**
|
||||
* set asc flag
|
||||
*/
|
||||
inline void asc(const bool asc) { fAsc = asc; }
|
||||
inline void asc(const bool asc)
|
||||
{
|
||||
fAsc = asc;
|
||||
}
|
||||
|
||||
/**
|
||||
* get SQL representation of this object
|
||||
*/
|
||||
virtual const std::string data() const { return fData; }
|
||||
virtual const std::string data() const
|
||||
{
|
||||
return fData;
|
||||
}
|
||||
|
||||
/**
|
||||
* set SQL representation of this object
|
||||
*/
|
||||
virtual void data(const std::string data) { fData = data; }
|
||||
virtual void data(const std::string data)
|
||||
{
|
||||
fData = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* virtual stream method
|
||||
@@ -155,7 +169,9 @@ public:
|
||||
virtual void setDerivedTable();
|
||||
virtual void replaceRealCol(std::vector<SRCP>&);
|
||||
virtual const std::vector<SimpleColumn*>& simpleColumnList() const
|
||||
{ return fSimpleColumnList; }
|
||||
{
|
||||
return fSimpleColumnList;
|
||||
}
|
||||
virtual void setSimpleColumnList();
|
||||
|
||||
/**
|
||||
@@ -186,7 +202,7 @@ private:
|
||||
* return the retrived token. curPos reference is updated to the
|
||||
* new position after end char
|
||||
*/
|
||||
const std::string nextToken(std::string::size_type &curPos, char end) const;
|
||||
const std::string nextToken(std::string::size_type& curPos, char end) const;
|
||||
|
||||
/***********************************************************
|
||||
* F&E framework *
|
||||
|
||||
@@ -28,12 +28,16 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
|
||||
/**@brief util struct for converting string to lower case */
|
||||
struct to_lower
|
||||
{
|
||||
char operator() (char c) const { return tolower(c); }
|
||||
char operator() (char c) const
|
||||
{
|
||||
return tolower(c);
|
||||
}
|
||||
};
|
||||
|
||||
//Trim any leading/trailing ws
|
||||
@@ -41,16 +45,21 @@ const string lrtrim(const string& in)
|
||||
{
|
||||
string::size_type p1;
|
||||
p1 = in.find_first_not_of(" \t\n");
|
||||
|
||||
if (p1 == string::npos) p1 = 0;
|
||||
|
||||
string::size_type p2;
|
||||
p2 = in.find_last_not_of(" \t\n");
|
||||
|
||||
if (p2 == string::npos) p2 = in.size() - 1;
|
||||
|
||||
return string(in, p1, (p2 - p1 + 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace execplan {
|
||||
namespace execplan
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructors/Destructors
|
||||
@@ -59,11 +68,11 @@ ArithmeticOperator::ArithmeticOperator() : Operator()
|
||||
{
|
||||
}
|
||||
|
||||
ArithmeticOperator::ArithmeticOperator(const string& operatorName):Operator(operatorName)
|
||||
ArithmeticOperator::ArithmeticOperator(const string& operatorName): Operator(operatorName)
|
||||
{
|
||||
}
|
||||
|
||||
ArithmeticOperator::ArithmeticOperator(const ArithmeticOperator& rhs):Operator(rhs)
|
||||
ArithmeticOperator::ArithmeticOperator(const ArithmeticOperator& rhs): Operator(rhs)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -78,7 +87,7 @@ ArithmeticOperator:: ~ArithmeticOperator()
|
||||
/**
|
||||
* friend function
|
||||
*/
|
||||
ostream& operator<<(ostream &output, const ArithmeticOperator& rhs)
|
||||
ostream& operator<<(ostream& output, const ArithmeticOperator& rhs)
|
||||
{
|
||||
output << rhs.toString();
|
||||
output << "opType=" << rhs.operationType().colDataType << endl;
|
||||
@@ -104,16 +113,19 @@ bool ArithmeticOperator::operator==(const ArithmeticOperator& t) const
|
||||
{
|
||||
if (fData == t.fData)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ArithmeticOperator::operator==(const TreeNode* t) const
|
||||
{
|
||||
const ArithmeticOperator *o;
|
||||
const ArithmeticOperator* o;
|
||||
|
||||
o = dynamic_cast<const ArithmeticOperator*>(t);
|
||||
|
||||
if (o == NULL)
|
||||
return false;
|
||||
|
||||
return *this == *o;
|
||||
}
|
||||
|
||||
@@ -140,6 +152,7 @@ void ArithmeticOperator::operationType(const Type& l, const Type& r)
|
||||
fOperationType = fResultType;
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
@@ -147,6 +160,7 @@ void ArithmeticOperator::operationType(const Type& l, const Type& r)
|
||||
fOperationType.colDataType = execplan::CalpontSystemCatalog::DECIMAL;
|
||||
fOperationType.scale = l.scale;
|
||||
break;
|
||||
|
||||
default:
|
||||
fOperationType.colDataType = execplan::CalpontSystemCatalog::DOUBLE;
|
||||
}
|
||||
@@ -162,6 +176,7 @@ void ArithmeticOperator::operationType(const Type& l, const Type& r)
|
||||
fOperationType = fResultType;
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
@@ -169,6 +184,7 @@ void ArithmeticOperator::operationType(const Type& l, const Type& r)
|
||||
fOperationType.colDataType = execplan::CalpontSystemCatalog::DECIMAL;
|
||||
fOperationType.scale = r.scale;
|
||||
break;
|
||||
|
||||
default:
|
||||
fOperationType.colDataType = execplan::CalpontSystemCatalog::DOUBLE;
|
||||
}
|
||||
|
||||
@@ -32,13 +32,16 @@
|
||||
#include "operator.h"
|
||||
#include "parsetree.h"
|
||||
|
||||
namespace messageqcpp {
|
||||
namespace messageqcpp
|
||||
{
|
||||
class ByteStream;
|
||||
}
|
||||
|
||||
namespace execplan {
|
||||
namespace execplan
|
||||
{
|
||||
|
||||
class ArithmeticOperator : public Operator {
|
||||
class ArithmeticOperator : public Operator
|
||||
{
|
||||
|
||||
public:
|
||||
ArithmeticOperator();
|
||||
@@ -100,22 +103,22 @@ public:
|
||||
evaluate(row, isNull, lop, rop);
|
||||
return TreeNode::getStrVal();
|
||||
}
|
||||
virtual int64_t getIntVal(rowgroup::Row& row, bool& isNull,ParseTree* lop, ParseTree* rop)
|
||||
virtual int64_t getIntVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop)
|
||||
{
|
||||
evaluate(row, isNull, lop, rop);
|
||||
return TreeNode::getIntVal();
|
||||
}
|
||||
virtual uint64_t getUintVal(rowgroup::Row& row, bool& isNull,ParseTree* lop, ParseTree* rop)
|
||||
virtual uint64_t getUintVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop)
|
||||
{
|
||||
evaluate(row, isNull, lop, rop);
|
||||
return TreeNode::getUintVal();
|
||||
}
|
||||
virtual float getFloatVal(rowgroup::Row& row, bool& isNull,ParseTree* lop, ParseTree* rop)
|
||||
virtual float getFloatVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop)
|
||||
{
|
||||
evaluate(row, isNull, lop, rop);
|
||||
return TreeNode::getFloatVal();
|
||||
}
|
||||
virtual double getDoubleVal(rowgroup::Row& row, bool& isNull,ParseTree* lop, ParseTree* rop)
|
||||
virtual double getDoubleVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop)
|
||||
{
|
||||
evaluate(row, isNull, lop, rop);
|
||||
return TreeNode::getDoubleVal();
|
||||
@@ -138,17 +141,17 @@ public:
|
||||
|
||||
return TreeNode::getDecimalVal();
|
||||
}
|
||||
virtual int32_t getDateIntVal(rowgroup::Row& row, bool& isNull,ParseTree* lop, ParseTree* rop)
|
||||
virtual int32_t getDateIntVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop)
|
||||
{
|
||||
evaluate(row, isNull, lop, rop);
|
||||
return TreeNode::getDateIntVal();
|
||||
}
|
||||
virtual int64_t getDatetimeIntVal(rowgroup::Row& row, bool& isNull,ParseTree* lop, ParseTree* rop)
|
||||
virtual int64_t getDatetimeIntVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop)
|
||||
{
|
||||
evaluate(row, isNull, lop, rop);
|
||||
return TreeNode::getDatetimeIntVal();
|
||||
}
|
||||
virtual bool getBoolVal(rowgroup::Row& row, bool& isNull,ParseTree* lop, ParseTree* rop)
|
||||
virtual bool getBoolVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop)
|
||||
{
|
||||
evaluate(row, isNull, lop, rop);
|
||||
return TreeNode::getBoolVal();
|
||||
@@ -175,6 +178,7 @@ inline void ArithmeticOperator::evaluate(rowgroup::Row& row, bool& isNull, Parse
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
fResult.intVal = execute(lop->getIntVal(row, isNull), rop->getIntVal(row, isNull), isNull);
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::UBIGINT:
|
||||
case execplan::CalpontSystemCatalog::UINT:
|
||||
case execplan::CalpontSystemCatalog::UMEDINT:
|
||||
@@ -182,14 +186,17 @@ inline void ArithmeticOperator::evaluate(rowgroup::Row& row, bool& isNull, Parse
|
||||
case execplan::CalpontSystemCatalog::UTINYINT:
|
||||
fResult.uintVal = execute(lop->getUintVal(row, isNull), rop->getUintVal(row, isNull), isNull);
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
fResult.doubleVal = execute(lop->getDoubleVal(row, isNull), rop->getDoubleVal(row, isNull), isNull);
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
execute (fResult.decimalVal, lop->getDecimalVal(row, isNull), rop->getDecimalVal(row, isNull), isNull);
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
std::ostringstream oss;
|
||||
@@ -206,16 +213,21 @@ inline result_t ArithmeticOperator::execute(result_t op1, result_t op2, bool& is
|
||||
{
|
||||
case OP_ADD:
|
||||
return op1 + op2;
|
||||
|
||||
case OP_SUB:
|
||||
return op1 - op2;
|
||||
|
||||
case OP_MUL:
|
||||
return op1 * op2;
|
||||
|
||||
case OP_DIV:
|
||||
if (op2)
|
||||
return op1 / op2;
|
||||
else
|
||||
isNull = true;
|
||||
|
||||
return 0;
|
||||
|
||||
default:
|
||||
{
|
||||
std::ostringstream oss;
|
||||
@@ -235,63 +247,76 @@ inline void ArithmeticOperator::execute(IDB_Decimal& result, IDB_Decimal op1, ID
|
||||
result.value = op1.value + op2.value;
|
||||
break;
|
||||
}
|
||||
|
||||
if (result.scale >= op1.scale)
|
||||
op1.value *= IDB_pow[result.scale-op1.scale];
|
||||
op1.value *= IDB_pow[result.scale - op1.scale];
|
||||
else
|
||||
op1.value = (int64_t)(op1.value > 0 ?
|
||||
(double)op1.value/IDB_pow[op1.scale-result.scale] + 0.5 :
|
||||
(double)op1.value/IDB_pow[op1.scale-result.scale] - 0.5);
|
||||
(double)op1.value / IDB_pow[op1.scale - result.scale] + 0.5 :
|
||||
(double)op1.value / IDB_pow[op1.scale - result.scale] - 0.5);
|
||||
|
||||
if (result.scale >= op2.scale)
|
||||
op2.value *= IDB_pow[result.scale-op2.scale];
|
||||
op2.value *= IDB_pow[result.scale - op2.scale];
|
||||
else
|
||||
op2.value = (int64_t)(op2.value > 0 ?
|
||||
(double)op2.value/IDB_pow[op2.scale-result.scale] + 0.5 :
|
||||
(double)op2.value/IDB_pow[op2.scale-result.scale] - 0.5);
|
||||
(double)op2.value / IDB_pow[op2.scale - result.scale] + 0.5 :
|
||||
(double)op2.value / IDB_pow[op2.scale - result.scale] - 0.5);
|
||||
|
||||
result.value = op1.value + op2.value;
|
||||
break;
|
||||
|
||||
case OP_SUB:
|
||||
if (result.scale == op1.scale && result.scale == op2.scale)
|
||||
{
|
||||
result.value = op1.value - op2.value;
|
||||
break;
|
||||
}
|
||||
|
||||
if (result.scale >= op1.scale)
|
||||
op1.value *= IDB_pow[result.scale-op1.scale];
|
||||
op1.value *= IDB_pow[result.scale - op1.scale];
|
||||
else
|
||||
op1.value = (int64_t)(op1.value > 0 ?
|
||||
(double)op1.value/IDB_pow[op1.scale-result.scale] + 0.5 :
|
||||
(double)op1.value/IDB_pow[op1.scale-result.scale] - 0.5);
|
||||
(double)op1.value / IDB_pow[op1.scale - result.scale] + 0.5 :
|
||||
(double)op1.value / IDB_pow[op1.scale - result.scale] - 0.5);
|
||||
|
||||
if (result.scale >= op2.scale)
|
||||
op2.value *= IDB_pow[result.scale-op2.scale];
|
||||
op2.value *= IDB_pow[result.scale - op2.scale];
|
||||
else
|
||||
op2.value = (int64_t)(op2.value > 0 ?
|
||||
(double)op2.value/IDB_pow[op2.scale-result.scale] + 0.5 :
|
||||
(double)op2.value/IDB_pow[op2.scale-result.scale] - 0.5);
|
||||
(double)op2.value / IDB_pow[op2.scale - result.scale] + 0.5 :
|
||||
(double)op2.value / IDB_pow[op2.scale - result.scale] - 0.5);
|
||||
|
||||
result.value = op1.value - op2.value;
|
||||
break;
|
||||
|
||||
case OP_MUL:
|
||||
if (result.scale >= op1.scale + op2.scale)
|
||||
result.value = op1.value * op2.value * IDB_pow[result.scale-(op1.scale+op2.scale)];
|
||||
result.value = op1.value * op2.value * IDB_pow[result.scale - (op1.scale + op2.scale)];
|
||||
else
|
||||
result.value = (int64_t)(( (op1.value > 0 && op2.value >0) || (op1.value < 0 && op2.value < 0) ?
|
||||
(double)op1.value * op2.value / IDB_pow[op1.scale+op2.scale-result.scale] + 0.5 :
|
||||
(double)op1.value * op2.value / IDB_pow[op1.scale+op2.scale-result.scale] - 0.5));
|
||||
result.value = (int64_t)(( (op1.value > 0 && op2.value > 0) || (op1.value < 0 && op2.value < 0) ?
|
||||
(double)op1.value * op2.value / IDB_pow[op1.scale + op2.scale - result.scale] + 0.5 :
|
||||
(double)op1.value * op2.value / IDB_pow[op1.scale + op2.scale - result.scale] - 0.5));
|
||||
|
||||
break;
|
||||
|
||||
case OP_DIV:
|
||||
if (op2.value == 0)
|
||||
{
|
||||
isNull = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (result.scale >= op1.scale - op2.scale)
|
||||
result.value = (int64_t)(( (op1.value > 0 && op2.value >0) || (op1.value < 0 && op2.value < 0) ?
|
||||
(long double)op1.value / op2.value * IDB_pow[result.scale-(op1.scale-op2.scale)] + 0.5 :
|
||||
(long double)op1.value / op2.value * IDB_pow[result.scale-(op1.scale-op2.scale)] - 0.5));
|
||||
result.value = (int64_t)(( (op1.value > 0 && op2.value > 0) || (op1.value < 0 && op2.value < 0) ?
|
||||
(long double)op1.value / op2.value * IDB_pow[result.scale - (op1.scale - op2.scale)] + 0.5 :
|
||||
(long double)op1.value / op2.value * IDB_pow[result.scale - (op1.scale - op2.scale)] - 0.5));
|
||||
else
|
||||
result.value = (int64_t)(( (op1.value > 0 && op2.value >0) || (op1.value < 0 && op2.value < 0) ?
|
||||
(long double)op1.value / op2.value / IDB_pow[op1.scale-op2.scale-result.scale] + 0.5 :
|
||||
(long double)op1.value / op2.value / IDB_pow[op1.scale-op2.scale-result.scale] - 0.5));
|
||||
result.value = (int64_t)(( (op1.value > 0 && op2.value > 0) || (op1.value < 0 && op2.value < 0) ?
|
||||
(long double)op1.value / op2.value / IDB_pow[op1.scale - op2.scale - result.scale] + 0.5 :
|
||||
(long double)op1.value / op2.value / IDB_pow[op1.scale - op2.scale - result.scale] - 0.5));
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user