1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-10-17 01:27:36 +03:00

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

View File

@@ -25,217 +25,228 @@
#include "ddlpkg.h" #include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT #undef DDLPKG_DLLEXPORT
namespace ddlpackage { namespace ddlpackage
using namespace std; {
using namespace std;
AlterTableStatement::AlterTableStatement(QualifiedName *qName, AlterTableActionList *ataList): AlterTableStatement::AlterTableStatement(QualifiedName* qName, AlterTableActionList* ataList):
fTableName(qName), fTableName(qName),
fActions(*ataList) fActions(*ataList)
{ {
delete ataList; delete ataList;
} }
AlterTableStatement::~AlterTableStatement() AlterTableStatement::~AlterTableStatement()
{ {
delete fTableName; delete fTableName;
AlterTableActionList::iterator itr; AlterTableActionList::iterator itr;
for(itr=fActions.begin(); itr != fActions.end(); ++itr) {
for (itr = fActions.begin(); itr != fActions.end(); ++itr)
{
delete *itr; delete *itr;
} }
} }
std::ostream& AlterTableStatement::put(std::ostream& os) const std::ostream& AlterTableStatement::put(std::ostream& os) const
{ {
AlterTableActionList::const_iterator itr; AlterTableActionList::const_iterator itr;
os << "Alter Table " << *fTableName << endl; os << "Alter Table " << *fTableName << endl;
for(itr = fActions.begin(); itr != fActions.end(); ++itr) { for (itr = fActions.begin(); itr != fActions.end(); ++itr)
{
os << **itr << endl; os << **itr << endl;
} }
return os; return os;
} }
/** @brief Format to ostream. Diagnostic. */ /** @brief Format to ostream. Diagnostic. */
std::ostream& AlterTableAction::put(std::ostream& os) const std::ostream& AlterTableAction::put(std::ostream& os) const
{ {
os << "AlterTableAction put stub"; os << "AlterTableAction put stub";
return os; return os;
} }
/** @brief Invokes the virtual function put, to dispatch to subclass /** @brief Invokes the virtual function put, to dispatch to subclass
ostream writers. */ ostream writers. */
std::ostream &operator<<(std::ostream& os, const AlterTableAction &ata) std::ostream& operator<<(std::ostream& os, const AlterTableAction& ata)
{ {
return ata.put(os); return ata.put(os);
} }
AtaAddColumn::~AtaAddColumn() AtaAddColumn::~AtaAddColumn()
{ {
delete fColumnDef; delete fColumnDef;
} }
/** @brief ostream output */ /** @brief ostream output */
std::ostream& AtaAddColumn::put(std::ostream& os) const std::ostream& AtaAddColumn::put(std::ostream& os) const
{ {
os << "Add Column" << endl; os << "Add Column" << endl;
os << *fColumnDef << endl; os << *fColumnDef << endl;
return os; return os;
} }
AtaDropColumn::AtaDropColumn(std::string columnName, DDL_REFERENTIAL_ACTION dropBehavior) : AtaDropColumn::AtaDropColumn(std::string columnName, DDL_REFERENTIAL_ACTION dropBehavior) :
fColumnName(columnName), fColumnName(columnName),
fDropBehavior(dropBehavior) fDropBehavior(dropBehavior)
{ {
} }
std::ostream& AtaDropColumn::put(std::ostream& os) const std::ostream& AtaDropColumn::put(std::ostream& os) const
{ {
os << "Drop Column: " << fColumnName << " " os << "Drop Column: " << fColumnName << " "
<< ReferentialActionStrings[fDropBehavior]; << ReferentialActionStrings[fDropBehavior];
return os; return os;
} }
AtaModifyColumnType::~AtaModifyColumnType() AtaModifyColumnType::~AtaModifyColumnType()
{ {
delete fColumnType; delete fColumnType;
} }
std::ostream& AtaModifyColumnType::put(std::ostream& os) const std::ostream& AtaModifyColumnType::put(std::ostream& os) const
{ {
os << "Modify column type: " << fName << " " << *fColumnType; os << "Modify column type: " << fName << " " << *fColumnType;
return os; return os;
} }
AtaRenameColumn::~AtaRenameColumn() AtaRenameColumn::~AtaRenameColumn()
{ {
delete fNewType; delete fNewType;
} }
std::ostream& AtaRenameColumn::put(std::ostream& os) const std::ostream& AtaRenameColumn::put(std::ostream& os) const
{ {
os << "Rename Column: " << fName << " -> " << fNewName << " (" << *fNewType << ')'; os << "Rename Column: " << fName << " -> " << fNewName << " (" << *fNewType << ')';
return os; return os;
} }
AtaSetColumnDefault::AtaSetColumnDefault(const char *colName, ColumnDefaultValue *defaultValue) : AtaSetColumnDefault::AtaSetColumnDefault(const char* colName, ColumnDefaultValue* defaultValue) :
fColumnName(colName), fColumnName(colName),
fDefaultValue(defaultValue) fDefaultValue(defaultValue)
{ {
} }
AtaSetColumnDefault::~AtaSetColumnDefault() AtaSetColumnDefault::~AtaSetColumnDefault()
{ {
delete fDefaultValue; delete fDefaultValue;
} }
std::ostream& AtaSetColumnDefault::put(std::ostream& os) const std::ostream& AtaSetColumnDefault::put(std::ostream& os) const
{ {
os << "Set Column Default: " << fColumnName << " " os << "Set Column Default: " << fColumnName << " "
<< *fDefaultValue << endl; << *fDefaultValue << endl;
return os; return os;
} }
AtaDropColumnDefault::AtaDropColumnDefault(const char *colName) : AtaDropColumnDefault::AtaDropColumnDefault(const char* colName) :
fColumnName(colName) fColumnName(colName)
{ {
} }
std::ostream& AtaDropColumnDefault::put(std::ostream& os) const std::ostream& AtaDropColumnDefault::put(std::ostream& os) const
{ {
os << "Drop Column Default: " << fColumnName << " "; os << "Drop Column Default: " << fColumnName << " ";
return os; return os;
} }
AtaRenameTable::AtaRenameTable(QualifiedName *qualifiedName) : AtaRenameTable::AtaRenameTable(QualifiedName* qualifiedName) :
fQualifiedName(qualifiedName) fQualifiedName(qualifiedName)
{ {
} }
AtaRenameTable::~AtaRenameTable() AtaRenameTable::~AtaRenameTable()
{ {
delete fQualifiedName; delete fQualifiedName;
} }
std::ostream& AtaRenameTable::put(std::ostream& os) const std::ostream& AtaRenameTable::put(std::ostream& os) const
{ {
os << "Rename Table: " << *fQualifiedName << endl; os << "Rename Table: " << *fQualifiedName << endl;
return os; return os;
} }
AtaTableComment::AtaTableComment(const char *tableComment) : AtaTableComment::AtaTableComment(const char* tableComment) :
fTableComment(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; os << "TableComment: " << fTableComment << endl;
return os; return os;
} }
AtaAddColumns::~AtaAddColumns() AtaAddColumns::~AtaAddColumns()
{ {
ColumnDefList::iterator itr; ColumnDefList::iterator itr;
for(itr=fColumns.begin(); itr != fColumns.end(); itr++)
for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
delete *itr; delete *itr;
} }
AtaAddColumns::AtaAddColumns(TableElementList *tableElements) AtaAddColumns::AtaAddColumns(TableElementList* tableElements)
{ {
/* It is convenient to reuse the grammar rules for /* It is convenient to reuse the grammar rules for
table_element_list, and we do. So, it is possible for table_element_list, and we do. So, it is possible for
there to be errant table constraint defs in the input list. there to be errant table constraint defs in the input list.
We ignore them. That is all we are doing here. We ignore them. That is all we are doing here.
*/ */
ColumnDef *column; ColumnDef* column;
TableElementList::const_iterator itr; TableElementList::const_iterator itr;
for(itr = tableElements->begin();
for (itr = tableElements->begin();
itr != tableElements->end(); itr != tableElements->end();
++itr) ++itr)
{ {
column = dynamic_cast<ColumnDef *>(*itr); column = dynamic_cast<ColumnDef*>(*itr);
if(0 != column) {
if (0 != column)
{
fColumns.push_back(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; os << "Add Columns: " << endl;
ColumnDefList::const_iterator itr; ColumnDefList::const_iterator itr;
for(itr = fColumns.begin();
for (itr = fColumns.begin();
itr != fColumns.end(); itr != fColumns.end();
++itr) ++itr)
{ {
@@ -243,25 +254,26 @@ namespace ddlpackage {
} }
return os; return os;
} }
////////////////////////// //////////////////////////
AtaDropColumns::~AtaDropColumns() AtaDropColumns::~AtaDropColumns()
{ {
} }
AtaDropColumns::AtaDropColumns(ColumnNameList *columnNames) AtaDropColumns::AtaDropColumns(ColumnNameList* columnNames)
{ {
fColumns = *columnNames; fColumns = *columnNames;
delete columnNames; delete columnNames;
} }
std::ostream& AtaDropColumns::put(std::ostream& os) const std::ostream& AtaDropColumns::put(std::ostream& os) const
{ {
os << "Drop Columns: " << endl; os << "Drop Columns: " << endl;
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
for(itr = fColumns.begin();
for (itr = fColumns.begin();
itr != fColumns.end(); itr != fColumns.end();
++itr) ++itr)
{ {
@@ -269,43 +281,43 @@ namespace ddlpackage {
} }
return os; return os;
} }
AtaAddTableConstraint::AtaAddTableConstraint(TableConstraintDef *tableConstraint) : AtaAddTableConstraint::AtaAddTableConstraint(TableConstraintDef* tableConstraint) :
fTableConstraint(tableConstraint) fTableConstraint(tableConstraint)
{ {
} }
AtaAddTableConstraint::~AtaAddTableConstraint() AtaAddTableConstraint::~AtaAddTableConstraint()
{ {
delete fTableConstraint; delete fTableConstraint;
} }
std::ostream& AtaAddTableConstraint::put(std::ostream& os) const std::ostream& AtaAddTableConstraint::put(std::ostream& os) const
{ {
os << "Add Table Constraint:" << endl; os << "Add Table Constraint:" << endl;
os << *fTableConstraint << endl; os << *fTableConstraint << endl;
return os; return os;
} }
AtaDropTableConstraint::AtaDropTableConstraint AtaDropTableConstraint::AtaDropTableConstraint
(const char *constraintName, DDL_REFERENTIAL_ACTION dropBehavior) : (const char* constraintName, DDL_REFERENTIAL_ACTION dropBehavior) :
fConstraintName(constraintName), fConstraintName(constraintName),
fDropBehavior(dropBehavior) fDropBehavior(dropBehavior)
{ {
} }
std::ostream& AtaDropTableConstraint::put(std::ostream& os) const std::ostream& AtaDropTableConstraint::put(std::ostream& os) const
{ {
os << "Drop Table Constraint: " << fConstraintName; os << "Drop Table Constraint: " << fConstraintName;
return os; return os;
} }
} }

View File

@@ -28,37 +28,42 @@
#include "ddlpkg.h" #include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT #undef DDLPKG_DLLEXPORT
namespace ddlpackage { namespace ddlpackage
{
using namespace std; using namespace std;
ColumnDef::~ColumnDef() ColumnDef::~ColumnDef()
{ {
delete fType; delete fType;
delete fDefaultValue; delete fDefaultValue;
ColumnConstraintList::iterator itr; ColumnConstraintList::iterator itr;
for(itr=fConstraints.begin(); itr != fConstraints.end(); ++itr) {
for (itr = fConstraints.begin(); itr != fConstraints.end(); ++itr)
{
delete *itr; delete *itr;
} }
} }
ColumnDef::ColumnDef(const char *name, ColumnType* columnType, ColumnConstraintList *constraints, ColumnDef::ColumnDef(const char* name, ColumnType* columnType, ColumnConstraintList* constraints,
ColumnDefaultValue *defaultValue, const char * comment ) : ColumnDefaultValue* defaultValue, const char* comment ) :
SchemaObject(name), SchemaObject(name),
fType(columnType), fType(columnType),
fDefaultValue(defaultValue) fDefaultValue(defaultValue)
{
if (constraints)
{ {
if(constraints) {
fConstraints = *constraints; fConstraints = *constraints;
delete constraints; delete constraints;
} }
if ( comment ) if ( comment )
fComment = comment; fComment = comment;
} }
ostream &operator<<(ostream& os, const ColumnType& columnType) ostream& operator<<(ostream& os, const ColumnType& columnType)
{ {
os << setw(12) << left << DDLDatatypeString[columnType.fType] os << setw(12) << left << DDLDatatypeString[columnType.fType]
<< "[" << "["
<< "L=" << setw(2) << columnType.fLength << "," << "L=" << setw(2) << columnType.fLength << ","
@@ -67,14 +72,15 @@ namespace ddlpackage {
<< "T=" << setw(2) << columnType.fWithTimezone << "T=" << setw(2) << columnType.fWithTimezone
<< "]"; << "]";
return os; return os;
} }
ostream &operator<<(ostream& os, const ColumnDef &column) ostream& operator<<(ostream& os, const ColumnDef& column)
{ {
os << "Column: " << column.fName << " " << *column.fType; os << "Column: " << column.fName << " " << *column.fType;
if(column.fDefaultValue) { if (column.fDefaultValue)
{
os << " def="; os << " def=";
if (column.fDefaultValue->fNull) if (column.fDefaultValue->fNull)
@@ -87,61 +93,68 @@ namespace ddlpackage {
<< " constraints "; << " constraints ";
ColumnConstraintList::const_iterator itr; ColumnConstraintList::const_iterator itr;
for(itr = column.fConstraints.begin();
for (itr = column.fConstraints.begin();
itr != column.fConstraints.end(); itr != column.fConstraints.end();
++itr) { ++itr)
ColumnConstraintDef *con = *itr; {
ColumnConstraintDef* con = *itr;
os << *con; os << *con;
} }
return os; return os;
} }
ostream &operator<<(ostream& os, const ColumnConstraintDef &con) ostream& operator<<(ostream& os, const ColumnConstraintDef& con)
{ {
os << " Constraint: " os << " Constraint: "
<< con.fName << " " << con.fName << " "
<< ConstraintString[con.fConstraintType] << " " << ConstraintString[con.fConstraintType] << " "
<< "defer=" << con.fDeferrable << " " << "defer=" << con.fDeferrable << " "
<< ConstraintAttrStrings[con.fCheckTime] << " "; << ConstraintAttrStrings[con.fCheckTime] << " ";
if(!con.fCheck.empty())
if (!con.fCheck.empty())
os << "check=" << "\"" << con.fCheck << "\""; os << "check=" << "\"" << con.fCheck << "\"";
return os; return os;
} }
std::ostream &operator<<(std::ostream& os, const ColumnDefList &clist) std::ostream& operator<<(std::ostream& os, const ColumnDefList& clist)
{ {
ColumnDefList::const_iterator itr; ColumnDefList::const_iterator itr;
for(itr = clist.begin(); itr != clist.end(); ++itr){
for (itr = clist.begin(); itr != clist.end(); ++itr)
{
os << **itr; os << **itr;
} }
return os; return os;
} }
ColumnDefaultValue::ColumnDefaultValue(const char *value) : ColumnDefaultValue::ColumnDefaultValue(const char* value) :
fNull(false) fNull(false)
{ {
if(0 == value) if (0 == value)
fNull = true; fNull = true;
else else
fValue = value; fValue = value;
} }
std::ostream &operator<<(std::ostream& os, const ColumnDefaultValue &defaultValue) std::ostream& operator<<(std::ostream& os, const ColumnDefaultValue& defaultValue)
{ {
os << " def="; os << " def=";
if (defaultValue.fNull) if (defaultValue.fNull)
os << "NULL"; os << "NULL";
else else
os << defaultValue.fValue; os << defaultValue.fValue;
return os; return os;
} }
} }

View File

@@ -23,38 +23,39 @@
#include "ddlpkg.h" #include "ddlpkg.h"
namespace ddlpackage { namespace ddlpackage
using namespace std; {
using namespace std;
CreateIndexStatement::CreateIndexStatement(): CreateIndexStatement::CreateIndexStatement():
fIndexName(NULL), fIndexName(NULL),
fTableName(NULL), fTableName(NULL),
fColumnNames(), fColumnNames(),
fUnique(false) fUnique(false)
{ {
} }
CreateIndexStatement::CreateIndexStatement(QualifiedName *indexName, QualifiedName *tableName, CreateIndexStatement::CreateIndexStatement(QualifiedName* indexName, QualifiedName* tableName,
ColumnNameList *columnNames, bool unique) : ColumnNameList* columnNames, bool unique) :
fIndexName(indexName), fIndexName(indexName),
fTableName(tableName), fTableName(tableName),
fColumnNames(*columnNames), fColumnNames(*columnNames),
fUnique(unique) fUnique(unique)
{ {
delete columnNames; delete columnNames;
} }
CreateIndexStatement::~CreateIndexStatement() CreateIndexStatement::~CreateIndexStatement()
{ {
delete fIndexName; delete fIndexName;
delete fTableName; delete fTableName;
} }
std::ostream& CreateIndexStatement::put(std::ostream& os) const std::ostream& CreateIndexStatement::put(std::ostream& os) const
{ {
os << "Create Index: " << *fIndexName << " on " << *fTableName os << "Create Index: " << *fIndexName << " on " << *fTableName
<< fColumnNames << endl; << fColumnNames << endl;
return os; return os;
} }
} }

View File

@@ -27,34 +27,35 @@
#include "ddlpkg.h" #include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT #undef DDLPKG_DLLEXPORT
namespace ddlpackage { namespace ddlpackage
{
using namespace std; using namespace std;
CreateTableStatement::CreateTableStatement() : CreateTableStatement::CreateTableStatement() :
fTableDef(0) fTableDef(0)
{ {
} }
CreateTableStatement::CreateTableStatement(TableDef* tableDef) : CreateTableStatement::CreateTableStatement(TableDef* tableDef) :
fTableDef(tableDef) fTableDef(tableDef)
{ {
} }
CreateTableStatement::~CreateTableStatement() CreateTableStatement::~CreateTableStatement()
{ {
if (fTableDef) if (fTableDef)
{ {
delete fTableDef; delete fTableDef;
} }
} }
/** \brief Put to ostream. */ /** \brief Put to ostream. */
ostream& CreateTableStatement::put(ostream& os) const ostream& CreateTableStatement::put(ostream& os) const
{ {
os << "CreateTable " os << "CreateTable "
<< *fTableDef; << *fTableDef;
return os; return os;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -36,9 +36,10 @@
/* Tokens. */ /* Tokens. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
# define 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. */ know about them. */
enum yytokentype { enum yytokentype
{
ACTION = 258, ACTION = 258,
ADD = 259, ADD = 259,
ALTER = 260, ALTER = 260,
@@ -122,7 +123,7 @@
CP_SEARCH_CONDITION_TEXT = 338, CP_SEARCH_CONDITION_TEXT = 338,
ICONST = 339, ICONST = 339,
DATE = 340 DATE = 340
}; };
#endif #endif
@@ -132,33 +133,33 @@ typedef union YYSTYPE
{ {
ddlpackage::AlterTableStatement *alterTableStmt; ddlpackage::AlterTableStatement* alterTableStmt;
ddlpackage::AlterTableAction *ata; ddlpackage::AlterTableAction* ata;
ddlpackage::AlterTableActionList *ataList; ddlpackage::AlterTableActionList* ataList;
ddlpackage::DDL_CONSTRAINT_ATTRIBUTES cattr; ddlpackage::DDL_CONSTRAINT_ATTRIBUTES cattr;
std::pair<std::string, std::string> *tableOption; std::pair<std::string, std::string>* tableOption;
const char *columnOption; const char* columnOption;
ddlpackage::ColumnConstraintDef *columnConstraintDef; ddlpackage::ColumnConstraintDef* columnConstraintDef;
ddlpackage::ColumnNameList *columnNameList; ddlpackage::ColumnNameList* columnNameList;
ddlpackage::ColumnType* columnType; ddlpackage::ColumnType* columnType;
ddlpackage::ConstraintAttributes *constraintAttributes; ddlpackage::ConstraintAttributes* constraintAttributes;
ddlpackage::ColumnConstraintList *constraintList; ddlpackage::ColumnConstraintList* constraintList;
ddlpackage::DDL_CONSTRAINTS constraintType; ddlpackage::DDL_CONSTRAINTS constraintType;
double dval; double dval;
bool flag; bool flag;
int ival; int ival;
ddlpackage::QualifiedName *qualifiedName; ddlpackage::QualifiedName* qualifiedName;
ddlpackage::SchemaObject *schemaObject; ddlpackage::SchemaObject* schemaObject;
ddlpackage::SqlStatement *sqlStmt; ddlpackage::SqlStatement* sqlStmt;
ddlpackage::SqlStatementList *sqlStmtList; ddlpackage::SqlStatementList* sqlStmtList;
const char *str; const char* str;
ddlpackage::TableConstraintDef *tableConstraint; ddlpackage::TableConstraintDef* tableConstraint;
ddlpackage::TableElementList *tableElementList; ddlpackage::TableElementList* tableElementList;
ddlpackage::TableOptionMap *tableOptionMap; ddlpackage::TableOptionMap* tableOptionMap;
ddlpackage::ColumnDefaultValue *colDefault; ddlpackage::ColumnDefaultValue* colDefault;
ddlpackage::DDL_MATCH_TYPE matchType; ddlpackage::DDL_MATCH_TYPE matchType;
ddlpackage::DDL_REFERENTIAL_ACTION refActionCode; ddlpackage::DDL_REFERENTIAL_ACTION refActionCode;
ddlpackage::ReferentialAction *refAction; ddlpackage::ReferentialAction* refAction;

File diff suppressed because it is too large Load Diff

View File

@@ -29,103 +29,113 @@
namespace ddlpackage namespace ddlpackage
{ {
using namespace std; using namespace std;
QualifiedName::QualifiedName(const char *name): QualifiedName::QualifiedName(const char* name):
fName(name) fName(name)
{ {
} }
QualifiedName::QualifiedName(const char *schema, const char *name): QualifiedName::QualifiedName(const char* schema, const char* name):
fName(name), fName(name),
fSchema(schema) 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), fCatalog(catalog),
fName(name), fName(name),
fSchema(schema) fSchema(schema)
{ {
} }
ostream& operator<<(ostream &os, const QualifiedName& qname) ostream& operator<<(ostream& os, const QualifiedName& qname)
{ {
if(!qname.fCatalog.empty()) if (!qname.fCatalog.empty())
os << qname.fCatalog << "."; os << qname.fCatalog << ".";
if(!qname.fSchema.empty())
if (!qname.fSchema.empty())
os << qname.fSchema << "."; os << qname.fSchema << ".";
os << qname.fName; os << qname.fName;
return os; return os;
} }
/** @brief Map a DECIMAL precision to data width in bytes */ /** @brief Map a DECIMAL precision to data width in bytes */
unsigned int precision_width(unsigned p) unsigned int precision_width(unsigned p)
{ {
switch(p) switch (p)
{ {
case 1: case 1:
case 2: case 2:
return 1; return 1;
case 3: case 3:
case 4: case 4:
return 2; return 2;
case 5: case 5:
case 6: case 6:
case 7: case 7:
case 8: case 8:
case 9: case 9:
return 4; return 4;
default: default:
return 8; return 8;
} }
} }
ColumnType::ColumnType(int prec, int scale) : ColumnType::ColumnType(int prec, int scale) :
fType(DDL_INVALID_DATATYPE), fType(DDL_INVALID_DATATYPE),
fLength(0), fLength(0),
fPrecision(prec), fPrecision(prec),
fScale(scale), fScale(scale),
fWithTimezone(false) fWithTimezone(false)
{ {
fLength = precision_width(fPrecision); fLength = precision_width(fPrecision);
} }
ColumnType::ColumnType(int type) : ColumnType::ColumnType(int type) :
fType(type), fType(type),
fLength(0), fLength(0),
fScale(0), fScale(0),
fWithTimezone(false) fWithTimezone(false)
{ {
switch ( type ) switch ( type )
{ {
case DDL_TINYINT: case DDL_TINYINT:
case DDL_UNSIGNED_TINYINT: case DDL_UNSIGNED_TINYINT:
fPrecision = 3; fPrecision = 3;
break; break;
case DDL_SMALLINT: case DDL_SMALLINT:
case DDL_UNSIGNED_SMALLINT: case DDL_UNSIGNED_SMALLINT:
fPrecision = 5; fPrecision = 5;
break; break;
case DDL_INT: case DDL_INT:
case DDL_UNSIGNED_INT: case DDL_UNSIGNED_INT:
case DDL_MEDINT: case DDL_MEDINT:
fPrecision = 10; fPrecision = 10;
break; break;
case DDL_BIGINT: case DDL_BIGINT:
fPrecision = 19; fPrecision = 19;
case DDL_UNSIGNED_BIGINT: case DDL_UNSIGNED_BIGINT:
fPrecision = 20; fPrecision = 20;
break; break;
default: default:
fPrecision = 10; fPrecision = 10;
break; break;
} }
} }
#if 0 #if 0
ColumnType::ColumnType(int type, int length, int precision, int scale, int compressiontype, const char* autoIncrement, int64_t nextValue, bool withTimezone) : ColumnType::ColumnType(int type, int length, int precision, int scale, int compressiontype, const char* autoIncrement, int64_t nextValue, bool withTimezone) :
fType(type) , fType(type),
fLength(length), fLength(length),
fPrecision(precision), fPrecision(precision),
fScale(scale), fScale(scale),
@@ -133,42 +143,42 @@ namespace ddlpackage
fCompressiontype(compressiontype), fCompressiontype(compressiontype),
fAutoincrement(autoIncrement), fAutoincrement(autoIncrement),
fNextvalue(nextValue) fNextvalue(nextValue)
{ {
} }
#endif #endif
ColumnConstraintDef::ColumnConstraintDef(DDL_CONSTRAINTS type) : ColumnConstraintDef::ColumnConstraintDef(DDL_CONSTRAINTS type) :
SchemaObject(), SchemaObject(),
fDeferrable(false), fDeferrable(false),
fCheckTime(DDL_INITIALLY_IMMEDIATE), fCheckTime(DDL_INITIALLY_IMMEDIATE),
fConstraintType(type), fConstraintType(type),
fCheck("") fCheck("")
{ {
} }
ColumnConstraintDef::ColumnConstraintDef(const char *check) : ColumnConstraintDef::ColumnConstraintDef(const char* check) :
SchemaObject(), SchemaObject(),
fDeferrable(false), fDeferrable(false),
fCheckTime(DDL_INITIALLY_IMMEDIATE), fCheckTime(DDL_INITIALLY_IMMEDIATE),
fConstraintType(DDL_CHECK), fConstraintType(DDL_CHECK),
fCheck(check) fCheck(check)
{ {
} }
AtaAddColumn::AtaAddColumn(ColumnDef *columnDef) : AtaAddColumn::AtaAddColumn(ColumnDef* columnDef) :
fColumnDef(columnDef) fColumnDef(columnDef)
{ {
} }
ostream &operator<<(ostream& os, const ReferentialAction& ref) ostream& operator<<(ostream& os, const ReferentialAction& ref)
{ {
os << "ref action: u=" << ReferentialActionStrings[ref.fOnUpdate] << " " os << "ref action: u=" << ReferentialActionStrings[ref.fOnUpdate] << " "
<< "d=" << ReferentialActionStrings[ref.fOnDelete]; << "d=" << ReferentialActionStrings[ref.fOnDelete];
return os; return os;
} }
void ColumnDef::convertDecimal() void ColumnDef::convertDecimal()
{ {
//@Bug 2089 decimal precision default to 10 if 0 is used. //@Bug 2089 decimal precision default to 10 if 0 is used.
if (fType->fPrecision <= 0) if (fType->fPrecision <= 0)
fType->fPrecision = 10; fType->fPrecision = 10;
@@ -204,5 +214,5 @@ namespace ddlpackage
fType->fType = DDL_BIGINT; fType->fType = DDL_BIGINT;
fType->fLength = 8; fType->fLength = 8;
} }
} }
} }

View File

@@ -86,8 +86,8 @@ typedef std::vector<SchemaObject*> TableElementList;
typedef std::vector<TableConstraintDef*> TableConstraintDefList; typedef std::vector<TableConstraintDef*> TableConstraintDefList;
std::ostream& operator<<(std::ostream& os, const ColumnType& columnType); 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 QualifiedName& constraint);
std::ostream& operator<<(std::ostream &os, const TableConstraintDef& 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 ColumnConstraintDef& con);
std::ostream& operator<<(std::ostream& os, const ColumnDef& column); std::ostream& operator<<(std::ostream& os, const ColumnDef& column);
EXPORT std::ostream& operator<<(std::ostream& os, const SqlStatementList& ct); 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 /** @brief Verb List
* Make sure to keep the enum and string list in-sync * Make sure to keep the enum and string list in-sync
*/ */
enum DDL_VERBS { enum DDL_VERBS
{
DDL_CREATE, DDL_CREATE,
DDL_ALTER, DDL_ALTER,
DDL_DROP, DDL_DROP,
@@ -112,7 +113,8 @@ enum DDL_VERBS {
/** @brief Subject List /** @brief Subject List
* Make sure to keep the enum and string list in-sync * Make sure to keep the enum and string list in-sync
*/ */
enum DDL_SUBJECTS { enum DDL_SUBJECTS
{
DDL_TABLE, DDL_TABLE,
DDL_INDEX, DDL_INDEX,
DDL_INVALID_SUBJECT DDL_INVALID_SUBJECT
@@ -128,16 +130,17 @@ enum DDL_CONSTRAINT_ATTRIBUTES
}; };
const std::string ConstraintAttrStrings[] = const std::string ConstraintAttrStrings[] =
{ {
"deferrable", "deferrable",
"non-deferrable", "non-deferrable",
"initially-immediate", "initially-immediate",
"initially-deferred", "initially-deferred",
"invalid" "invalid"
}; };
enum DDL_REFERENTIAL_ACTION { enum DDL_REFERENTIAL_ACTION
{
DDL_CASCADE, DDL_CASCADE,
DDL_SET_NULL, DDL_SET_NULL,
DDL_SET_DEFAULT, DDL_SET_DEFAULT,
@@ -147,32 +150,34 @@ enum DDL_REFERENTIAL_ACTION {
}; };
const std::string ReferentialActionStrings[] = const std::string ReferentialActionStrings[] =
{ {
"cascade", "cascade",
"set_null", "set_null",
"set_default", "set_default",
"no_action", "no_action",
"invalid_action" "invalid_action"
}; };
enum DDL_MATCH_TYPE { enum DDL_MATCH_TYPE
{
DDL_FULL, DDL_FULL,
DDL_PARTIAL, DDL_PARTIAL,
DDL_INVALID_MATCH_TYPE DDL_INVALID_MATCH_TYPE
}; };
const std::string MatchTypeStrings[] = const std::string MatchTypeStrings[] =
{ {
"full", "full",
"partial", "partial",
"invalid_match_type" "invalid_match_type"
}; };
/** @brief Constraint List /** @brief Constraint List
* Make sure to keep the enum and string list in-sync * Make sure to keep the enum and string list in-sync
*/ */
enum DDL_CONSTRAINTS { enum DDL_CONSTRAINTS
{
DDL_PRIMARY_KEY, DDL_PRIMARY_KEY,
DDL_FOREIGN_KEY, DDL_FOREIGN_KEY,
DDL_CHECK, DDL_CHECK,
@@ -185,7 +190,7 @@ enum DDL_CONSTRAINTS {
/** @brief /** @brief
*/ */
const std::string ConstraintString[] = const std::string ConstraintString[] =
{ {
"primary", "primary",
"foreign", "foreign",
"check", "check",
@@ -194,12 +199,13 @@ const std::string ConstraintString[] =
"not_null", "not_null",
"auto_increment" "auto_increment"
"" ""
}; };
/** @brief Datatype List /** @brief Datatype List
* Make sure to keep the enum, string, and length list in-sync * Make sure to keep the enum, string, and length list in-sync
*/ */
enum DDL_DATATYPES { enum DDL_DATATYPES
{
DDL_BIT, DDL_BIT,
DDL_TINYINT, DDL_TINYINT,
DDL_CHAR, DDL_CHAR,
@@ -236,7 +242,7 @@ enum DDL_DATATYPES {
/** @brief Datatype string list /** @brief Datatype string list
*/ */
const std::string DDLDatatypeString[] = const std::string DDLDatatypeString[] =
{ {
"bit", "bit",
"tinyint", "tinyint",
"char", "char",
@@ -268,12 +274,12 @@ const std::string DDLDatatypeString[] =
"unsigned-numeric", "unsigned-numeric",
"text", "text",
"" ""
}; };
/** @brief Alter table action string list /** @brief Alter table action string list
*/ */
const std::string AlterActionString[] = const std::string AlterActionString[] =
{ {
"AtaAddColumn", "AtaAddColumn",
"AtaAddColumns", "AtaAddColumns",
"AtaDropColumn", "AtaDropColumn",
@@ -286,12 +292,12 @@ const std::string AlterActionString[] =
"AtaModifyColumnType", "AtaModifyColumnType",
"AtaRenameColumn", "AtaRenameColumn",
"AtaTableComment" "AtaTableComment"
}; };
/** @brief Datatype Length list /** @brief Datatype Length list
* *
*/ */
const int DDLDatatypeLength[] = const int DDLDatatypeLength[] =
{ {
1, // BIT 1, // BIT
1, // TINYINT 1, // TINYINT
1, // CHAR 1, // CHAR
@@ -323,9 +329,10 @@ const int DDLDatatypeLength[] =
2, // UNSIGNED_NUMERIC, 2, // UNSIGNED_NUMERIC,
8, // TEXT 8, // TEXT
-1 // INVALID LENGTH -1 // INVALID LENGTH
}; };
enum DDL_SERIAL_TYPE { enum DDL_SERIAL_TYPE
{
DDL_TABLE_DEF, DDL_TABLE_DEF,
DDL_COLUMN_DEF, DDL_COLUMN_DEF,
DDL_COLUMN_CONSTRAINT_DEF, DDL_COLUMN_CONSTRAINT_DEF,
@@ -408,14 +415,14 @@ struct SchemaObject
struct SqlStatement struct SqlStatement
{ {
/** @brief Deserialize from ByteStream */ /** @brief Deserialize from ByteStream */
virtual int unserialize(messageqcpp::ByteStream& bs)=0; virtual int unserialize(messageqcpp::ByteStream& bs) = 0;
/** @brief Serialize to ByteStream */ /** @brief Serialize to ByteStream */
virtual int serialize(messageqcpp::ByteStream& bs)=0; virtual int serialize(messageqcpp::ByteStream& bs) = 0;
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
virtual std::ostream& put(std::ostream &os) const = 0; virtual std::ostream& put(std::ostream& os) const = 0;
EXPORT SqlStatement(); EXPORT SqlStatement();
@@ -530,7 +537,7 @@ struct TableDef : public SchemaObject
/** @brief TableDef ctor. /** @brief TableDef ctor.
* ctor * ctor
*/ */
TableDef( QualifiedName *name, TableDef( QualifiedName* name,
ColumnDefList columns, ColumnDefList columns,
TableConstraintDefList constraints, int tableWithAutoinc) : TableConstraintDefList constraints, int tableWithAutoinc) :
fQualifiedName (name), fQualifiedName (name),
@@ -579,6 +586,7 @@ struct CreateTableStatement : public SqlStatement
std::string schemaName() const std::string schemaName() const
{ {
if (!fTableDef || !fTableDef->fQualifiedName) return "UNKNOWN"; if (!fTableDef || !fTableDef->fQualifiedName) return "UNKNOWN";
return fTableDef->fQualifiedName->fSchema; return fTableDef->fQualifiedName->fSchema;
} }
@@ -602,10 +610,10 @@ struct CreateTableStatement : public SqlStatement
struct AlterTableAction struct AlterTableAction
{ {
/** @brief Deserialize from ByteStream */ /** @brief Deserialize from ByteStream */
EXPORT virtual int unserialize(messageqcpp::ByteStream& bs)=0; EXPORT virtual int unserialize(messageqcpp::ByteStream& bs) = 0;
/** @brief Serialize to ByteStream */ /** @brief Serialize to ByteStream */
EXPORT virtual int serialize(messageqcpp::ByteStream& bs)=0; EXPORT virtual int serialize(messageqcpp::ByteStream& bs) = 0;
/** @brief Ctor for deserialization */ /** @brief Ctor for deserialization */
AlterTableAction() AlterTableAction()
@@ -640,7 +648,7 @@ struct AtaAddColumn : public AlterTableAction
/** @brief You can't add a column without specifying a column /** @brief You can't add a column without specifying a column
definition. */ definition. */
AtaAddColumn(ColumnDef *columnDef); AtaAddColumn(ColumnDef* columnDef);
virtual ~AtaAddColumn(); virtual ~AtaAddColumn();
@@ -648,7 +656,7 @@ struct AtaAddColumn : public AlterTableAction
virtual std::ostream& put(std::ostream& os) const; virtual std::ostream& put(std::ostream& os) const;
/** @brief The focal column definition. */ /** @brief The focal column definition. */
ColumnDef *fColumnDef; ColumnDef* fColumnDef;
}; };
@@ -667,7 +675,7 @@ struct AtaAddColumns : public AlterTableAction
AtaAddColumns() AtaAddColumns()
{} {}
AtaAddColumns(TableElementList *tableElements); AtaAddColumns(TableElementList* tableElements);
virtual ~AtaAddColumns(); virtual ~AtaAddColumns();
@@ -693,7 +701,7 @@ struct AtaDropColumns : public AlterTableAction
AtaDropColumns() AtaDropColumns()
{} {}
EXPORT AtaDropColumns(ColumnNameList *tableElements); EXPORT AtaDropColumns(ColumnNameList* tableElements);
EXPORT virtual ~AtaDropColumns(); EXPORT virtual ~AtaDropColumns();
@@ -719,14 +727,14 @@ struct AtaAddTableConstraint : public AlterTableAction
AtaAddTableConstraint() : fTableConstraint(0) AtaAddTableConstraint() : fTableConstraint(0)
{} {}
AtaAddTableConstraint(TableConstraintDef *tableConstraint); AtaAddTableConstraint(TableConstraintDef* tableConstraint);
virtual ~AtaAddTableConstraint(); virtual ~AtaAddTableConstraint();
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
virtual std::ostream& put(std::ostream& os) const; virtual std::ostream& put(std::ostream& os) const;
TableConstraintDef *fTableConstraint; TableConstraintDef* fTableConstraint;
}; };
@@ -776,10 +784,10 @@ struct AtaSetColumnDefault : AlterTableAction
virtual ~AtaSetColumnDefault(); virtual ~AtaSetColumnDefault();
AtaSetColumnDefault(const char *colName, ColumnDefaultValue *defaultValue); AtaSetColumnDefault(const char* colName, ColumnDefaultValue* defaultValue);
std::string fColumnName; std::string fColumnName;
ColumnDefaultValue *fDefaultValue; ColumnDefaultValue* fDefaultValue;
}; };
@@ -805,7 +813,7 @@ struct AtaDropColumnDefault : AlterTableAction
{} {}
/** @brief Ctor for parser construction */ /** @brief Ctor for parser construction */
AtaDropColumnDefault(const char *colName); AtaDropColumnDefault(const char* colName);
std::string fColumnName; std::string fColumnName;
}; };
@@ -831,7 +839,7 @@ struct AtaDropTableConstraint : AlterTableAction
virtual ~AtaDropTableConstraint() virtual ~AtaDropTableConstraint()
{} {}
AtaDropTableConstraint(const char *constraintName, DDL_REFERENTIAL_ACTION dropBehavior); AtaDropTableConstraint(const char* constraintName, DDL_REFERENTIAL_ACTION dropBehavior);
std::string fConstraintName; std::string fConstraintName;
DDL_REFERENTIAL_ACTION fDropBehavior; DDL_REFERENTIAL_ACTION fDropBehavior;
@@ -850,14 +858,14 @@ struct AtaRenameTable : public AlterTableAction
/** @brief Ctor for deserialization */ /** @brief Ctor for deserialization */
AtaRenameTable() : fQualifiedName(0) {} AtaRenameTable() : fQualifiedName(0) {}
AtaRenameTable(QualifiedName *qualifiedName); AtaRenameTable(QualifiedName* qualifiedName);
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
std::ostream& put(std::ostream& os) const; std::ostream& put(std::ostream& os) const;
virtual ~AtaRenameTable(); virtual ~AtaRenameTable();
QualifiedName *fQualifiedName; QualifiedName* fQualifiedName;
}; };
/** alter table comment */ /** alter table comment */
@@ -872,7 +880,7 @@ struct AtaTableComment : public AlterTableAction
/** @brief Ctor for deserialization */ /** @brief Ctor for deserialization */
AtaTableComment() : fTableComment("") AtaTableComment() : fTableComment("")
{} {}
AtaTableComment(const char *tableComment); AtaTableComment(const char* tableComment);
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
std::ostream& put(std::ostream& os) const; std::ostream& put(std::ostream& os) const;
@@ -902,7 +910,7 @@ struct AtaModifyColumnType : public AlterTableAction
fName(name) fName(name)
{} {}
AtaModifyColumnType(QualifiedName *qualifiedName); AtaModifyColumnType(QualifiedName* qualifiedName);
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
std::ostream& put(std::ostream& os) const; std::ostream& put(std::ostream& os) const;
@@ -928,18 +936,19 @@ struct AtaRenameColumn : public AlterTableAction
/** @brief Ctor for deserialization */ /** @brief Ctor for deserialization */
AtaRenameColumn() : fNewType(0), fDefaultValue(0) { } 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), fName(name),
fNewName(newName), fNewName(newName),
fNewType(newType) fNewType(newType)
{ {
if (comment) if (comment)
fComment = comment; fComment = comment;
fDefaultValue = 0; fDefaultValue = 0;
} }
AtaRenameColumn(const char* name, const char* newName, ColumnType* newType, ColumnConstraintList *constraint_list, AtaRenameColumn(const char* name, const char* newName, ColumnType* newType, ColumnConstraintList* constraint_list,
ColumnDefaultValue *defaultValue, const char * comment=NULL) : ColumnDefaultValue* defaultValue, const char* comment = NULL) :
fName(name), fName(name),
fNewName(newName), fNewName(newName),
fNewType(newType), fNewType(newType),
@@ -957,7 +966,7 @@ struct AtaRenameColumn : public AlterTableAction
fComment = comment; fComment = comment;
} }
AtaRenameColumn(QualifiedName *qualifiedName); AtaRenameColumn(QualifiedName* qualifiedName);
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
std::ostream& put(std::ostream& os) const; std::ostream& put(std::ostream& os) const;
@@ -971,7 +980,7 @@ struct AtaRenameColumn : public AlterTableAction
ColumnConstraintList fConstraints; ColumnConstraintList fConstraints;
/** @brief NULL if there was no DEFAULT clause */ /** @brief NULL if there was no DEFAULT clause */
ColumnDefaultValue *fDefaultValue; ColumnDefaultValue* fDefaultValue;
std::string fComment; std::string fComment;
}; };
@@ -992,7 +1001,7 @@ struct ColumnType
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 /** @brief This constructor is used by the parser to construct the
ColumnType when a precision/scale clause is encountered. */ ColumnType when a precision/scale clause is encountered. */
@@ -1053,7 +1062,7 @@ struct ColumnConstraintDef : public SchemaObject
{} {}
/** @brief Constructs as check constraint. */ /** @brief Constructs as check constraint. */
EXPORT ColumnConstraintDef(const char *check); EXPORT ColumnConstraintDef(const char* check);
/** @brief Constructs as other constraint. */ /** @brief Constructs as other constraint. */
@@ -1091,7 +1100,7 @@ struct ColumnDefaultValue
ColumnDefaultValue() ColumnDefaultValue()
{} {}
ColumnDefaultValue(const char *value); ColumnDefaultValue(const char* value);
virtual ~ColumnDefaultValue() virtual ~ColumnDefaultValue()
{} {}
@@ -1123,17 +1132,17 @@ struct ColumnDef : public SchemaObject
EXPORT virtual ~ColumnDef(); EXPORT virtual ~ColumnDef();
/** @brief Parser ctor. */ /** @brief Parser ctor. */
EXPORT ColumnDef(const char *name, EXPORT ColumnDef(const char* name,
ColumnType* type, ColumnType* type,
ColumnConstraintList *constraint_list, ColumnConstraintList* constraint_list,
ColumnDefaultValue *defaultValue, const char * comment=NULL); ColumnDefaultValue* defaultValue, const char* comment = NULL);
/** @brief ColumnDef ctor. /** @brief ColumnDef ctor.
* ctor */ * ctor */
ColumnDef(const char *name, ColumnDef(const char* name,
ColumnType* type, ColumnType* type,
ColumnConstraintList constraints, ColumnConstraintList constraints,
ColumnDefaultValue *defaultValue = NULL, const char * comment=NULL) : ColumnDefaultValue* defaultValue = NULL, const char* comment = NULL) :
SchemaObject(name), SchemaObject(name),
fType (type), fType (type),
fConstraints (constraints), fConstraints (constraints),
@@ -1149,7 +1158,7 @@ struct ColumnDef : public SchemaObject
ColumnConstraintList fConstraints; ColumnConstraintList fConstraints;
/** @brief NULL if there was no DEFAULT clause */ /** @brief NULL if there was no DEFAULT clause */
ColumnDefaultValue *fDefaultValue; ColumnDefaultValue* fDefaultValue;
std::string fComment; std::string fComment;
}; };
@@ -1161,13 +1170,13 @@ struct ColumnDef : public SchemaObject
struct TableConstraintDef : public SchemaObject struct TableConstraintDef : public SchemaObject
{ {
/** @brief Return DDL_SERIAL code */ /** @brief Return DDL_SERIAL code */
virtual DDL_SERIAL_TYPE getSerialType()=0; virtual DDL_SERIAL_TYPE getSerialType() = 0;
/** @brief Deserialize from ByteStream */ /** @brief Deserialize from ByteStream */
virtual int unserialize(messageqcpp::ByteStream& bs)=0; virtual int unserialize(messageqcpp::ByteStream& bs) = 0;
/** @brief Serialize to ByteStream */ /** @brief Serialize to ByteStream */
virtual int serialize(messageqcpp::ByteStream& bs)=0; virtual int serialize(messageqcpp::ByteStream& bs) = 0;
TableConstraintDef(); TableConstraintDef();
@@ -1175,7 +1184,7 @@ struct TableConstraintDef : public SchemaObject
TableConstraintDef(DDL_CONSTRAINTS cType); TableConstraintDef(DDL_CONSTRAINTS cType);
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
virtual std::ostream& put(std::ostream &os) const; virtual std::ostream& put(std::ostream& os) const;
virtual ~TableConstraintDef() virtual ~TableConstraintDef()
{} {}
@@ -1207,12 +1216,12 @@ struct TableUniqueConstraintDef : public TableConstraintDef
TableUniqueConstraintDef() : TableConstraintDef(DDL_UNIQUE) TableUniqueConstraintDef() : TableConstraintDef(DDL_UNIQUE)
{} {}
TableUniqueConstraintDef(ColumnNameList *columns); TableUniqueConstraintDef(ColumnNameList* columns);
virtual ~TableUniqueConstraintDef() virtual ~TableUniqueConstraintDef()
{} {}
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
virtual std::ostream& put(std::ostream &os) const; virtual std::ostream& put(std::ostream& os) const;
ColumnNameList fColumnNameList; ColumnNameList fColumnNameList;
}; };
@@ -1239,13 +1248,13 @@ struct TablePrimaryKeyConstraintDef : public TableConstraintDef
TablePrimaryKeyConstraintDef() : TableConstraintDef(DDL_PRIMARY_KEY) TablePrimaryKeyConstraintDef() : TableConstraintDef(DDL_PRIMARY_KEY)
{} {}
EXPORT TablePrimaryKeyConstraintDef(ColumnNameList *columns); EXPORT TablePrimaryKeyConstraintDef(ColumnNameList* columns);
virtual ~TablePrimaryKeyConstraintDef() virtual ~TablePrimaryKeyConstraintDef()
{} {}
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
EXPORT virtual std::ostream& put(std::ostream &os) const; EXPORT virtual std::ostream& put(std::ostream& os) const;
ColumnNameList fColumnNameList; ColumnNameList fColumnNameList;
}; };
@@ -1297,22 +1306,22 @@ struct TableReferencesConstraintDef : public TableConstraintDef
{} {}
TableReferencesConstraintDef TableReferencesConstraintDef
(ColumnNameList *columns, (ColumnNameList* columns,
QualifiedName *fTableName, QualifiedName* fTableName,
ColumnNameList *foreignColumns, ColumnNameList* foreignColumns,
DDL_MATCH_TYPE matchType, DDL_MATCH_TYPE matchType,
ReferentialAction *refAction); ReferentialAction* refAction);
virtual ~TableReferencesConstraintDef(); virtual ~TableReferencesConstraintDef();
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
virtual std::ostream& put(std::ostream &os) const; virtual std::ostream& put(std::ostream& os) const;
ColumnNameList fColumns; ColumnNameList fColumns;
QualifiedName *fTableName; QualifiedName* fTableName;
ColumnNameList fForeignColumns; ColumnNameList fForeignColumns;
DDL_MATCH_TYPE fMatchType; DDL_MATCH_TYPE fMatchType;
ReferentialAction *fRefAction; ReferentialAction* fRefAction;
}; };
@@ -1337,10 +1346,10 @@ struct TableCheckConstraintDef : public TableConstraintDef
TableCheckConstraintDef() : TableConstraintDef(DDL_CHECK) TableCheckConstraintDef() : TableConstraintDef(DDL_CHECK)
{} {}
TableCheckConstraintDef(const char *check); TableCheckConstraintDef(const char* check);
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
virtual std::ostream& put(std::ostream &os) const; virtual std::ostream& put(std::ostream& os) const;
virtual ~TableCheckConstraintDef() virtual ~TableCheckConstraintDef()
{} {}
@@ -1367,10 +1376,10 @@ struct AlterTableStatement : public SqlStatement
AlterTableStatement() : fTableName(0) AlterTableStatement() : fTableName(0)
{} {}
EXPORT AlterTableStatement(QualifiedName *qName, AlterTableActionList *ataList); EXPORT AlterTableStatement(QualifiedName* qName, AlterTableActionList* ataList);
/** @brief Dump to stdout. */ /** @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. */ /** @brief Delete members. */
EXPORT virtual ~AlterTableStatement(); EXPORT virtual ~AlterTableStatement();
@@ -1378,6 +1387,7 @@ struct AlterTableStatement : public SqlStatement
std::string schemaName() const std::string schemaName() const
{ {
if (!fTableName) return "UNKNOWN"; if (!fTableName) return "UNKNOWN";
return fTableName->fSchema; return fTableName->fSchema;
} }
@@ -1432,16 +1442,16 @@ struct CreateIndexStatement : public SqlStatement
virtual int serialize(messageqcpp::ByteStream& bs); virtual int serialize(messageqcpp::ByteStream& bs);
CreateIndexStatement(); CreateIndexStatement();
CreateIndexStatement(QualifiedName *qualifiedName1, QualifiedName *qualifiedName2, CreateIndexStatement(QualifiedName* qualifiedName1, QualifiedName* qualifiedName2,
ColumnNameList *columnNames, bool unique); ColumnNameList* columnNames, bool unique);
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
std::ostream& put(std::ostream& os) const; std::ostream& put(std::ostream& os) const;
virtual ~CreateIndexStatement(); virtual ~CreateIndexStatement();
QualifiedName *fIndexName; QualifiedName* fIndexName;
QualifiedName *fTableName; QualifiedName* fTableName;
ColumnNameList fColumnNames; ColumnNameList fColumnNames;
bool fUnique; bool fUnique;
}; };
@@ -1459,14 +1469,14 @@ struct DropIndexStatement : public SqlStatement
DropIndexStatement() : fIndexName(0) DropIndexStatement() : fIndexName(0)
{} {}
DropIndexStatement(QualifiedName *qualifiedName); DropIndexStatement(QualifiedName* qualifiedName);
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
std::ostream& put(std::ostream& os) const; std::ostream& put(std::ostream& os) const;
virtual ~DropIndexStatement(); virtual ~DropIndexStatement();
QualifiedName *fIndexName; QualifiedName* fIndexName;
}; };
/** @brief DropTableStatement represents the drop table operation /** @brief DropTableStatement represents the drop table operation
@@ -1482,7 +1492,7 @@ struct DropTableStatement : public SqlStatement
DropTableStatement() : fTableName(0) DropTableStatement() : fTableName(0)
{} {}
EXPORT DropTableStatement(QualifiedName *qualifiedName, bool cascade); EXPORT DropTableStatement(QualifiedName* qualifiedName, bool cascade);
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
EXPORT std::ostream& put(std::ostream& os) const; EXPORT std::ostream& put(std::ostream& os) const;
@@ -1495,10 +1505,11 @@ struct DropTableStatement : public SqlStatement
std::string schemaName() const std::string schemaName() const
{ {
if (!fTableName) return "UNKNOWN"; if (!fTableName) return "UNKNOWN";
return fTableName->fSchema; return fTableName->fSchema;
} }
QualifiedName *fTableName; QualifiedName* fTableName;
bool fCascade; bool fCascade;
}; };
@@ -1515,7 +1526,7 @@ struct TruncTableStatement : public SqlStatement
TruncTableStatement() : fTableName(0) TruncTableStatement() : fTableName(0)
{} {}
EXPORT TruncTableStatement(QualifiedName *qualifiedName); EXPORT TruncTableStatement(QualifiedName* qualifiedName);
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
EXPORT std::ostream& put(std::ostream& os) const; EXPORT std::ostream& put(std::ostream& os) const;
@@ -1528,10 +1539,11 @@ struct TruncTableStatement : public SqlStatement
std::string schemaName() const std::string schemaName() const
{ {
if (!fTableName) return "UNKNOWN"; if (!fTableName) return "UNKNOWN";
return fTableName->fSchema; return fTableName->fSchema;
} }
QualifiedName *fTableName; QualifiedName* fTableName;
}; };
/** @brief Represents the mark partition out of service statement /** @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 */ /** @brief You can't have a CreateTableStatement without a table defintion */
EXPORT MarkPartitionStatement(QualifiedName *qualifiedName); EXPORT MarkPartitionStatement(QualifiedName* qualifiedName);
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
EXPORT virtual std::ostream& put(std::ostream& os) const; EXPORT virtual std::ostream& put(std::ostream& os) const;
@@ -1560,7 +1572,7 @@ struct MarkPartitionStatement : public SqlStatement
delete fTableName; delete fTableName;
} }
QualifiedName *fTableName; ///< The table defintion QualifiedName* fTableName; ///< The table defintion
std::set<BRM::LogicalPartition> fPartitions; // partition numbers std::set<BRM::LogicalPartition> fPartitions; // partition numbers
}; };
@@ -1579,7 +1591,7 @@ struct RestorePartitionStatement : public SqlStatement
RestorePartitionStatement() : fTableName(0) RestorePartitionStatement() : fTableName(0)
{} {}
EXPORT RestorePartitionStatement(QualifiedName *qualifiedName); EXPORT RestorePartitionStatement(QualifiedName* qualifiedName);
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
EXPORT virtual std::ostream& put(std::ostream& os) const; EXPORT virtual std::ostream& put(std::ostream& os) const;
@@ -1589,7 +1601,7 @@ struct RestorePartitionStatement : public SqlStatement
delete fTableName; delete fTableName;
} }
QualifiedName *fTableName; ///< The table name. QualifiedName* fTableName; ///< The table name.
std::set<BRM::LogicalPartition> fPartitions; // partition numbers std::set<BRM::LogicalPartition> fPartitions; // partition numbers
}; };
@@ -1608,7 +1620,7 @@ struct DropPartitionStatement : public SqlStatement
DropPartitionStatement() : fTableName(0) DropPartitionStatement() : fTableName(0)
{} {}
EXPORT DropPartitionStatement(QualifiedName *qualifiedName); EXPORT DropPartitionStatement(QualifiedName* qualifiedName);
/** @brief Dump to stdout. */ /** @brief Dump to stdout. */
EXPORT virtual std::ostream& put(std::ostream& os) const; EXPORT virtual std::ostream& put(std::ostream& os) const;
@@ -1618,7 +1630,7 @@ struct DropPartitionStatement : public SqlStatement
delete fTableName; delete fTableName;
} }
QualifiedName *fTableName; ///< The table name. QualifiedName* fTableName; ///< The table name.
std::set<BRM::LogicalPartition> fPartitions; // partition numbers std::set<BRM::LogicalPartition> fPartitions; // partition numbers
}; };

View File

@@ -23,23 +23,24 @@
#include "ddlpkg.h" #include "ddlpkg.h"
namespace ddlpackage { namespace ddlpackage
using namespace std; {
using namespace std;
DropIndexStatement::~DropIndexStatement() DropIndexStatement::~DropIndexStatement()
{ {
delete fIndexName; delete fIndexName;
} }
DropIndexStatement::DropIndexStatement(QualifiedName *qualifiedName) : DropIndexStatement::DropIndexStatement(QualifiedName* qualifiedName) :
fIndexName(qualifiedName) fIndexName(qualifiedName)
{ {
} }
std::ostream& DropIndexStatement::put(std::ostream& os) const std::ostream& DropIndexStatement::put(std::ostream& os) const
{ {
os << "Drop Index: " << *fIndexName << endl; os << "Drop Index: " << *fIndexName << endl;
return os; return os;
} }
} }

View File

@@ -27,9 +27,10 @@
using namespace std; using namespace std;
namespace ddlpackage { namespace ddlpackage
{
DropPartitionStatement::DropPartitionStatement(QualifiedName *qualifiedName) : DropPartitionStatement::DropPartitionStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName) fTableName(qualifiedName)
{ {
} }
@@ -39,8 +40,10 @@ ostream& DropPartitionStatement::put(ostream& os) const
os << "Mark partitions out of service: " << *fTableName << endl; os << "Mark partitions out of service: " << *fTableName << endl;
os << " partitions: "; os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it; 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 << (*it) << " ";
os << endl; os << endl;
return os; return os;
} }

View File

@@ -27,9 +27,10 @@
using namespace std; using namespace std;
namespace ddlpackage { namespace ddlpackage
{
DropTableStatement::DropTableStatement(QualifiedName *qualifiedName, bool cascade) : DropTableStatement::DropTableStatement(QualifiedName* qualifiedName, bool cascade) :
fTableName(qualifiedName), fTableName(qualifiedName),
fCascade(cascade) fCascade(cascade)
{ {
@@ -41,7 +42,7 @@ ostream& DropTableStatement::put(ostream& os) const
return os; return os;
} }
TruncTableStatement::TruncTableStatement(QualifiedName *qualifiedName) : TruncTableStatement::TruncTableStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName) fTableName(qualifiedName)
{ {
} }

View File

@@ -43,6 +43,7 @@ int main(int argc, char* argv[])
po::variables_map vm; po::variables_map vm;
po::store (po::parse_command_line (argc, argv, desc), vm); po::store (po::parse_command_line (argc, argv, desc), vm);
po::notify (vm); po::notify (vm);
if (vm.count ("sql")) if (vm.count ("sql"))
sqlfile = vm["sql"].as <string> (); sqlfile = vm["sql"].as <string> ();
@@ -51,20 +52,23 @@ int main(int argc, char* argv[])
count = vm["count"].as<int>(); count = vm["count"].as<int>();
SqlFileParser parser; SqlFileParser parser;
if (vm.count ("bisond")) if (vm.count ("bisond"))
parser.SetDebug(true); parser.SetDebug(true);
parser.Parse(sqlfile); parser.Parse(sqlfile);
if(parser.Good()) { if (parser.Good())
const ParseTree &ptree = parser.GetParseTree(); {
const ParseTree& ptree = parser.GetParseTree();
cout << "Parser succeeded." << endl; cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl; cout << ptree.fList.size() << " " << "SQL statements" << endl;
cout << ptree; cout << ptree;
cout << endl; cout << endl;
} }
else { else
{
cout << "Parser failed." << endl; cout << "Parser failed." << endl;
} }

View File

@@ -27,9 +27,10 @@
using namespace std; using namespace std;
namespace ddlpackage { namespace ddlpackage
{
MarkPartitionStatement::MarkPartitionStatement(QualifiedName *qualifiedName) : MarkPartitionStatement::MarkPartitionStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName) fTableName(qualifiedName)
{ {
} }
@@ -39,8 +40,10 @@ ostream& MarkPartitionStatement::put(ostream& os) const
os << "Mark partition out of service: " << *fTableName; os << "Mark partition out of service: " << *fTableName;
os << " partitions: "; os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it; 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 << (*it) << " ";
os << endl; os << endl;
return os; return os;
} }

View File

@@ -50,18 +50,19 @@ std::string itoa(const int i);
// READ & WRITE STATEMENT TESTS // 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_table_object );
CPPUNIT_TEST( test_write_read_create_index_object ); CPPUNIT_TEST( test_write_read_create_index_object );
CPPUNIT_TEST( test_write_read_alter_table_object ); CPPUNIT_TEST( test_write_read_alter_table_object );
CPPUNIT_TEST( test_write_read_drop_table_object ); CPPUNIT_TEST( test_write_read_drop_table_object );
CPPUNIT_TEST( test_write_read_drop_index_object ); CPPUNIT_TEST( test_write_read_drop_index_object );
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
@@ -119,7 +120,7 @@ public:
CPPUNIT_ASSERT( DDL_CREATE == package_type ); CPPUNIT_ASSERT( DDL_CREATE == package_type );
CreateObjectDDLPackage *pObject = new CreateObjectDDLPackage(); CreateObjectDDLPackage* pObject = new CreateObjectDDLPackage();
pObject->Read( bs ); pObject->Read( bs );
@@ -170,7 +171,7 @@ public:
CPPUNIT_ASSERT( DDL_CREATE == package_type ); CPPUNIT_ASSERT( DDL_CREATE == package_type );
CreateObjectDDLPackage *pObject = new CreateObjectDDLPackage(); CreateObjectDDLPackage* pObject = new CreateObjectDDLPackage();
pObject->Read( bs ); pObject->Read( bs );
@@ -221,7 +222,7 @@ public:
CPPUNIT_ASSERT( DDL_ALTER == package_type ); CPPUNIT_ASSERT( DDL_ALTER == package_type );
AlterObjectDDLPackage *pObject = new AlterObjectDDLPackage(); AlterObjectDDLPackage* pObject = new AlterObjectDDLPackage();
pObject->Read( bs ); pObject->Read( bs );
@@ -272,7 +273,7 @@ public:
CPPUNIT_ASSERT( DDL_DROP == package_type ); CPPUNIT_ASSERT( DDL_DROP == package_type );
DropObjectDDLPackage *pObject = new DropObjectDDLPackage(); DropObjectDDLPackage* pObject = new DropObjectDDLPackage();
pObject->Read( bs ); pObject->Read( bs );
@@ -323,7 +324,7 @@ public:
CPPUNIT_ASSERT( DDL_DROP == package_type ); CPPUNIT_ASSERT( DDL_DROP == package_type );
DropObjectDDLPackage *pObject = new DropObjectDDLPackage(); DropObjectDDLPackage* pObject = new DropObjectDDLPackage();
pObject->Read( bs ); pObject->Read( bs );
@@ -336,13 +337,14 @@ public:
// PARSE STATEMENT TESTS // 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: private:
@@ -372,8 +374,8 @@ public:
fileBuffer = Buffer; fileBuffer = Buffer;
string::size_type pos = fileBuffer.find ("create ",0); string::size_type pos = fileBuffer.find ("create ", 0);
string::size_type pos1 = fileBuffer.find ("CREATE ",0); string::size_type pos1 = fileBuffer.find ("CREATE ", 0);
if (pos == string::npos && pos1 == string::npos ) if (pos == string::npos && pos1 == string::npos )
// end of file // end of file
@@ -384,7 +386,7 @@ public:
else else
pos_begin = pos1; pos_begin = pos1;
std::string DDLStatement = fileBuffer.substr (pos_begin,64000); std::string DDLStatement = fileBuffer.substr (pos_begin, 64000);
fileBuffer.append(";"); fileBuffer.append(";");
@@ -401,17 +403,19 @@ public:
delete pDDLPackage; delete pDDLPackage;
} }
fin.close(); 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: private:
@@ -441,8 +445,8 @@ public:
fileBuffer = Buffer; fileBuffer = Buffer;
string::size_type pos = fileBuffer.find ("create ",0); string::size_type pos = fileBuffer.find ("create ", 0);
string::size_type pos1 = fileBuffer.find ("CREATE ",0); string::size_type pos1 = fileBuffer.find ("CREATE ", 0);
if (pos == string::npos && pos1 == string::npos ) if (pos == string::npos && pos1 == string::npos )
// end of file // end of file
@@ -453,7 +457,7 @@ public:
else else
pos_begin = pos1; pos_begin = pos1;
std::string DDLStatement = fileBuffer.substr (pos_begin,64000); std::string DDLStatement = fileBuffer.substr (pos_begin, 64000);
fileBuffer.append(";"); fileBuffer.append(";");
@@ -470,19 +474,21 @@ public:
delete pDDLPackage; delete pDDLPackage;
} }
fin.close(); 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: private:
@@ -512,8 +518,8 @@ public:
fileBuffer = Buffer; fileBuffer = Buffer;
string::size_type pos = fileBuffer.find ("alter ",0); string::size_type pos = fileBuffer.find ("alter ", 0);
string::size_type pos1 = fileBuffer.find ("ALTER ",0); string::size_type pos1 = fileBuffer.find ("ALTER ", 0);
if (pos == string::npos && pos1 == string::npos ) if (pos == string::npos && pos1 == string::npos )
// end of file // end of file
@@ -524,7 +530,7 @@ public:
else else
pos_begin = pos1; pos_begin = pos1;
std::string DDLStatement = fileBuffer.substr (pos_begin,64000); std::string DDLStatement = fileBuffer.substr (pos_begin, 64000);
fileBuffer.append(";"); fileBuffer.append(";");
@@ -541,18 +547,20 @@ public:
delete pDDLPackage; delete pDDLPackage;
} }
fin.close(); 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: private:
@@ -583,8 +591,8 @@ public:
fileBuffer = Buffer; fileBuffer = Buffer;
string::size_type pos = fileBuffer.find ("drop ",0); string::size_type pos = fileBuffer.find ("drop ", 0);
string::size_type pos1 = fileBuffer.find ("DROP ",0); string::size_type pos1 = fileBuffer.find ("DROP ", 0);
if (pos == string::npos && pos1 == string::npos ) if (pos == string::npos && pos1 == string::npos )
// end of file // end of file
@@ -595,7 +603,7 @@ public:
else else
pos_begin = pos1; pos_begin = pos1;
std::string DDLStatement = fileBuffer.substr (pos_begin,64000); std::string DDLStatement = fileBuffer.substr (pos_begin, 64000);
fileBuffer.append(";"); fileBuffer.append(";");
@@ -612,18 +620,20 @@ public:
delete pDDLPackage; delete pDDLPackage;
} }
fin.close(); 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: private:
std::string fDDLStatement; std::string fDDLStatement;
@@ -654,8 +664,8 @@ public:
fileBuffer = Buffer; fileBuffer = Buffer;
string::size_type pos = fileBuffer.find ("drop ",0); string::size_type pos = fileBuffer.find ("drop ", 0);
string::size_type pos1 = fileBuffer.find ("DROP ",0); string::size_type pos1 = fileBuffer.find ("DROP ", 0);
if (pos == string::npos && pos1 == string::npos ) if (pos == string::npos && pos1 == string::npos )
// end of file // end of file
@@ -666,7 +676,7 @@ public:
else else
pos_begin = pos1; pos_begin = pos1;
std::string DDLStatement = fileBuffer.substr (pos_begin,64000); std::string DDLStatement = fileBuffer.substr (pos_begin, 64000);
fileBuffer.append(";"); fileBuffer.append(";");
@@ -683,6 +693,7 @@ public:
delete pDDLPackage; delete pDDLPackage;
} }
fin.close(); fin.close();
} }
@@ -698,11 +709,11 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DDLWriteReadTest );
#include <cppunit/extensions/TestFactoryRegistry.h> #include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h> #include <cppunit/ui/text/TestRunner.h>
int main(int argc, char *argv[]) int main(int argc, char* argv[])
{ {
CppUnit::TextUi::TestRunner runner; CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry(); CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() ); runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false ); bool wasSuccessful = runner.run( "", false );

View File

@@ -27,9 +27,10 @@
using namespace std; using namespace std;
namespace ddlpackage { namespace ddlpackage
{
RestorePartitionStatement::RestorePartitionStatement(QualifiedName *qualifiedName) : RestorePartitionStatement::RestorePartitionStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName) fTableName(qualifiedName)
{ {
} }
@@ -39,8 +40,10 @@ ostream& RestorePartitionStatement::put(ostream& os) const
os << "Mark partition out of service: " << *fTableName; os << "Mark partition out of service: " << *fTableName;
os << " partitions: "; os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it; 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 << (*it) << " ";
os << endl; os << endl;
return os; return os;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -36,94 +36,100 @@
#endif #endif
void scanner_finish(void* yyscanner); void scanner_finish(void* yyscanner);
void scanner_init(const char *str, void* yyscanner); void scanner_init(const char* str, void* yyscanner);
int ddllex_init_extra(void* user_defined,void** yyscanner); int ddllex_init_extra(void* user_defined, void** yyscanner);
int ddllex_destroy(void* yyscanner); int ddllex_destroy(void* yyscanner);
int ddlparse(ddlpackage::pass_to_bison* x); int ddlparse(ddlpackage::pass_to_bison* x);
void set_schema(std::string schema); void set_schema(std::string schema);
namespace ddlpackage { namespace ddlpackage
using namespace std; {
using namespace std;
SqlParser::SqlParser() : SqlParser::SqlParser() :
fStatus(-1), fStatus(-1),
fDebug(false), fDebug(false),
x(&fParseTree) x(&fParseTree)
{ {
} }
void SqlParser::SetDebug(bool debug) void SqlParser::SetDebug(bool debug)
{ {
fDebug = debug; fDebug = debug;
} }
void SqlParser::setDefaultSchema(std::string schema) void SqlParser::setDefaultSchema(std::string schema)
{ {
x.fDBSchema=schema; x.fDBSchema = schema;
} }
int SqlParser::Parse(const char* sqltext) int SqlParser::Parse(const char* sqltext)
{ {
ddllex_init_extra(&scanData, &x.scanner); ddllex_init_extra(&scanData, &x.scanner);
scanner_init(sqltext, x.scanner); scanner_init(sqltext, x.scanner);
fStatus = ddlparse(&x); fStatus = ddlparse(&x);
return fStatus; return fStatus;
} }
const ParseTree& SqlParser::GetParseTree(void) const ParseTree& SqlParser::GetParseTree(void)
{
if (!Good())
{ {
if(!Good()) {
throw logic_error("The ParseTree is invalid"); throw logic_error("The ParseTree is invalid");
} }
return fParseTree; return fParseTree;
} }
bool SqlParser::Good() bool SqlParser::Good()
{ {
return fStatus == 0; return fStatus == 0;
} }
SqlParser::~SqlParser() SqlParser::~SqlParser()
{ {
scanner_finish(x.scanner); // free scanner allocated memory scanner_finish(x.scanner); // free scanner allocated memory
ddllex_destroy(x.scanner); ddllex_destroy(x.scanner);
} }
SqlFileParser::SqlFileParser() : SqlFileParser::SqlFileParser() :
SqlParser() SqlParser()
{ {
} }
int SqlFileParser::Parse(const string& sqlfile) int SqlFileParser::Parse(const string& sqlfile)
{ {
fStatus = -1; fStatus = -1;
ifstream ifsql; ifstream ifsql;
ifsql.open(sqlfile.c_str()); ifsql.open(sqlfile.c_str());
if(!ifsql.is_open()) {
if (!ifsql.is_open())
{
perror(sqlfile.c_str()); perror(sqlfile.c_str());
return fStatus; return fStatus;
} }
char sqlbuf[1024*1024]; char sqlbuf[1024 * 1024];
unsigned length; unsigned length;
ifsql.seekg (0, ios::end); ifsql.seekg (0, ios::end);
length = ifsql.tellg(); length = ifsql.tellg();
ifsql.seekg (0, ios::beg); 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."); throw length_error("SqlFileParser has file size hard limit of 16K.");
} }
unsigned rcount; unsigned rcount;
rcount = ifsql.readsome(sqlbuf, sizeof(sqlbuf) - 1); rcount = ifsql.readsome(sqlbuf, sizeof(sqlbuf) - 1);
if(rcount < 0) if (rcount < 0)
return fStatus; return fStatus;
sqlbuf[rcount] = 0; sqlbuf[rcount] = 0;
@@ -133,5 +139,5 @@ namespace ddlpackage {
//cout << sqlbuf << endl; //cout << sqlbuf << endl;
return SqlParser::Parse(sqlbuf); return SqlParser::Parse(sqlbuf);
} }
} }

View File

@@ -81,7 +81,8 @@ struct scan_data
valbuf_t valbuf; valbuf_t valbuf;
}; };
struct pass_to_bison { struct pass_to_bison
{
ParseTree* fParseTree; ParseTree* fParseTree;
std::string fDBSchema; std::string fDBSchema;
void* scanner; void* scanner;

View File

@@ -25,22 +25,23 @@
#include "ddlpkg.h" #include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT #undef DDLPKG_DLLEXPORT
namespace ddlpackage { namespace ddlpackage
using namespace std; {
using namespace std;
static uint32_t sessionID = 1; static uint32_t sessionID = 1;
SqlStatement::SqlStatement() SqlStatement::SqlStatement()
{ {
fSessionID = sessionID; fSessionID = sessionID;
} }
SqlStatement::~SqlStatement() SqlStatement::~SqlStatement()
{ {
} }
ostream& operator<<(ostream &os, const SqlStatement& stmt) ostream& operator<<(ostream& os, const SqlStatement& stmt)
{ {
return stmt.put(os); return stmt.put(os);
} }
} }

View File

@@ -25,34 +25,39 @@
#include "ddlpkg.h" #include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT #undef DDLPKG_DLLEXPORT
namespace ddlpackage { namespace ddlpackage
using namespace std; {
using namespace std;
ostream &operator<<(ostream& os, const SqlStatementList &ssl) ostream& operator<<(ostream& os, const SqlStatementList& ssl)
{ {
vector<SqlStatement*>::const_iterator itr; vector<SqlStatement*>::const_iterator itr;
for(itr = ssl.fList.begin(); itr != ssl.fList.end(); ++itr) { for (itr = ssl.fList.begin(); itr != ssl.fList.end(); ++itr)
SqlStatement &stmt = **itr; {
SqlStatement& stmt = **itr;
os << stmt; os << stmt;
} }
return os; return os;
} }
void SqlStatementList::push_back(SqlStatement* v) void SqlStatementList::push_back(SqlStatement* v)
{ {
fList.push_back(v); fList.push_back(v);
} }
SqlStatementList::~SqlStatementList() SqlStatementList::~SqlStatementList()
{ {
vector<SqlStatement*>::iterator itr; vector<SqlStatement*>::iterator itr;
for(itr = fList.begin(); itr != fList.end(); ++itr) {
for (itr = fList.begin(); itr != fList.end(); ++itr)
{
delete *itr; delete *itr;
} }
} }
} }

View File

@@ -28,66 +28,79 @@
namespace ddlpackage namespace ddlpackage
{ {
using namespace std; using namespace std;
TableDef::~TableDef() TableDef::~TableDef()
{ {
{ {
ColumnDefList::iterator itr; ColumnDefList::iterator itr;
for(itr=fColumns.begin(); itr != fColumns.end(); itr++) {
for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
{
delete *itr; delete *itr;
} }
} }
{ {
TableConstraintDefList::iterator itr; TableConstraintDefList::iterator itr;
for(itr=fConstraints.begin(); itr != fConstraints.end(); itr++) {
for (itr = fConstraints.begin(); itr != fConstraints.end(); itr++)
{
delete *itr; delete *itr;
} }
} }
delete fQualifiedName; delete fQualifiedName;
} }
TableDef::TableDef(QualifiedName* name, TableElementList* elements, TableOptionMap* options) : TableDef::TableDef(QualifiedName* name, TableElementList* elements, TableOptionMap* options) :
fQualifiedName(name) fQualifiedName(name)
{
if (options)
{ {
if(options) {
fOptions = *options; fOptions = *options;
delete options; delete options;
} }
ColumnDef *column; ColumnDef* column;
TableConstraintDef *constraint; TableConstraintDef* constraint;
/* When parsing, it is necessary to collect ColumnDefs and /* When parsing, it is necessary to collect ColumnDefs and
TableConstraintDefs as TableElements. Here we separate TableConstraintDefs as TableElements. Here we separate
them out into separately typed lists. them out into separately typed lists.
*/ */
TableElementList::iterator itr; TableElementList::iterator itr;
for(itr = elements->begin(); itr != elements->end(); ++itr) {
for (itr = elements->begin(); itr != elements->end(); ++itr)
{
column = dynamic_cast<ColumnDef*>(*itr); column = dynamic_cast<ColumnDef*>(*itr);
if(column) {
if (column)
{
fColumns.push_back(column); fColumns.push_back(column);
} }
else { else
constraint = dynamic_cast<TableConstraintDef *>(*itr); {
if(constraint) { constraint = dynamic_cast<TableConstraintDef*>(*itr);
if (constraint)
{
fConstraints.push_back(constraint); fConstraints.push_back(constraint);
} }
} }
} }
delete elements; delete elements;
} }
/** \brief Put to ostream. */ /** \brief Put to ostream. */
ostream& operator<<(ostream& os, const TableDef& tableDef) ostream& operator<<(ostream& os, const TableDef& tableDef)
{ {
os << "CreateTable "; os << "CreateTable ";
if(tableDef.fQualifiedName->fSchema != "")
if (tableDef.fQualifiedName->fSchema != "")
//cout << tableDef.fQualifiedName->fSchema << "."; //cout << tableDef.fQualifiedName->fSchema << ".";
os << tableDef.fQualifiedName->fName os << tableDef.fQualifiedName->fName
<< " " << tableDef.fConstraints.size() << " " << tableDef.fConstraints.size()
@@ -96,7 +109,8 @@ namespace ddlpackage
{ {
ColumnDefList::const_iterator itr; ColumnDefList::const_iterator itr;
for(itr = tableDef.fColumns.begin();
for (itr = tableDef.fColumns.begin();
itr != tableDef.fColumns.end(); ++itr) itr != tableDef.fColumns.end(); ++itr)
{ {
ColumnDef* col = *itr; ColumnDef* col = *itr;
@@ -107,7 +121,8 @@ namespace ddlpackage
{ {
TableConstraintDefList::const_iterator itr; TableConstraintDefList::const_iterator itr;
for(itr = tableDef.fConstraints.begin();
for (itr = tableDef.fConstraints.begin();
itr != tableDef.fConstraints.end(); itr != tableDef.fConstraints.end();
++itr) ++itr)
{ {
@@ -118,139 +133,149 @@ namespace ddlpackage
pair<string, string> oval; pair<string, string> oval;
TableOptionMap::const_iterator oitr; TableOptionMap::const_iterator oitr;
os << "Table Options" << endl; os << "Table Options" << endl;
if(!tableDef.fOptions.empty()) {
if (!tableDef.fOptions.empty())
{
TableOptionMap::const_iterator oitr; 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; oval = *oitr;
os << " " << oval.first << "=" << oval.second << endl; os << " " << oval.first << "=" << oval.second << endl;
} }
} }
return os; return os;
} }
ostream& operator<<(ostream &os, const TableConstraintDef& constraint) ostream& operator<<(ostream& os, const TableConstraintDef& constraint)
{ {
return constraint.put(os); return constraint.put(os);
} }
std::ostream& TableConstraintDef::put(std::ostream& os) const std::ostream& TableConstraintDef::put(std::ostream& os) const
{ {
os << "No!!!" << endl; os << "No!!!" << endl;
return os; return os;
} }
TableConstraintDef::TableConstraintDef(DDL_CONSTRAINTS cType) : TableConstraintDef::TableConstraintDef(DDL_CONSTRAINTS cType) :
fConstraintType(cType) fConstraintType(cType)
{ {
} }
TableConstraintDef::TableConstraintDef() : TableConstraintDef::TableConstraintDef() :
fConstraintType(DDL_INVALID_CONSTRAINT) fConstraintType(DDL_INVALID_CONSTRAINT)
{ {
} }
TableCheckConstraintDef::TableCheckConstraintDef(const char *check) : TableCheckConstraintDef::TableCheckConstraintDef(const char* check) :
TableConstraintDef(DDL_CHECK), TableConstraintDef(DDL_CHECK),
fCheck(check) fCheck(check)
{ {
} }
std::ostream& TableCheckConstraintDef::put(std::ostream& os) const std::ostream& TableCheckConstraintDef::put(std::ostream& os) const
{ {
os << "Constraint: " os << "Constraint: "
<< ConstraintString[fConstraintType] << " "; << ConstraintString[fConstraintType] << " ";
os << "\"" << fCheck << "\""; os << "\"" << fCheck << "\"";
os << endl; os << endl;
return os; return os;
} }
TableUniqueConstraintDef::TableUniqueConstraintDef(ColumnNameList *columns) : TableUniqueConstraintDef::TableUniqueConstraintDef(ColumnNameList* columns) :
TableConstraintDef(DDL_UNIQUE), TableConstraintDef(DDL_UNIQUE),
fColumnNameList(*columns) fColumnNameList(*columns)
{ {
delete columns; delete columns;
} }
std::ostream& TableUniqueConstraintDef::put(std::ostream& os) const std::ostream& TableUniqueConstraintDef::put(std::ostream& os) const
{ {
os << "Constraint: " os << "Constraint: "
<< fName << " " << fName << " "
<< ConstraintString[fConstraintType] << " "; << ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
os << "("; os << "(";
for(itr = fColumnNameList.begin();
for (itr = fColumnNameList.begin();
itr != fColumnNameList.end(); itr != fColumnNameList.end();
++itr) ++itr)
{ {
os << *itr << " "; os << *itr << " ";
} }
os << ")"; os << ")";
return os; return os;
} }
TablePrimaryKeyConstraintDef::TablePrimaryKeyConstraintDef(ColumnNameList *columns) : TablePrimaryKeyConstraintDef::TablePrimaryKeyConstraintDef(ColumnNameList* columns) :
TableConstraintDef(DDL_PRIMARY_KEY), TableConstraintDef(DDL_PRIMARY_KEY),
fColumnNameList(*columns) fColumnNameList(*columns)
{ {
delete columns; delete columns;
} }
std::ostream& TablePrimaryKeyConstraintDef::put(std::ostream& os) const std::ostream& TablePrimaryKeyConstraintDef::put(std::ostream& os) const
{ {
os << "Constraint: " os << "Constraint: "
<< fName << " " << fName << " "
<< ConstraintString[fConstraintType] << " "; << ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
os << "("; os << "(";
for(itr = fColumnNameList.begin();
for (itr = fColumnNameList.begin();
itr != fColumnNameList.end(); itr != fColumnNameList.end();
++itr) ++itr)
{ {
os << *itr << " "; os << *itr << " ";
} }
os << ")"; os << ")";
return os; return os;
} }
TableReferencesConstraintDef::TableReferencesConstraintDef TableReferencesConstraintDef::TableReferencesConstraintDef
(ColumnNameList *columns, (ColumnNameList* columns,
QualifiedName *tableName, QualifiedName* tableName,
ColumnNameList *foreignColumns, ColumnNameList* foreignColumns,
DDL_MATCH_TYPE matchType, DDL_MATCH_TYPE matchType,
ReferentialAction *refAction) : ReferentialAction* refAction) :
TableConstraintDef(DDL_REFERENCES), TableConstraintDef(DDL_REFERENCES),
fColumns(*columns), fColumns(*columns),
fTableName(tableName), fTableName(tableName),
fForeignColumns(*foreignColumns), fForeignColumns(*foreignColumns),
fMatchType(matchType), fMatchType(matchType),
fRefAction(refAction) fRefAction(refAction)
{ {
delete columns; delete columns;
delete foreignColumns; delete foreignColumns;
} }
std::ostream& TableReferencesConstraintDef::put(std::ostream& os) const std::ostream& TableReferencesConstraintDef::put(std::ostream& os) const
{ {
os << "Constraint: " os << "Constraint: "
<< fName << " " << fName << " "
<< ConstraintString[fConstraintType] << " "; << ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
os << "lcols ("; os << "lcols (";
for(itr = fColumns.begin();
for (itr = fColumns.begin();
itr != fColumns.end(); itr != fColumns.end();
++itr) ++itr)
{ {
os << *itr << " "; os << *itr << " ";
} }
os << ")"; os << ")";
os << " ftable=" << *fTableName; os << " ftable=" << *fTableName;
@@ -258,36 +283,40 @@ namespace ddlpackage
os << " "; os << " ";
os << "fcols ("; os << "fcols (";
for(itr = fForeignColumns.begin();
for (itr = fForeignColumns.begin();
itr != fForeignColumns.end(); itr != fForeignColumns.end();
++itr) ++itr)
{ {
os << *itr << " "; os << *itr << " ";
} }
os << ")"; os << ")";
return 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; ColumnNameList::const_iterator itr;
os << '('; os << '(';
for(itr = columnNames.begin();
for (itr = columnNames.begin();
itr != columnNames.end(); itr != columnNames.end();
++itr) ++itr)
{ {
os << *itr << " "; os << *itr << " ";
} }
os << ')'; os << ')';
return os; return os;
} }
TableReferencesConstraintDef::~TableReferencesConstraintDef() TableReferencesConstraintDef::~TableReferencesConstraintDef()
{ {
delete fTableName; delete fTableName;
delete fRefAction; delete fRefAction;
} }
} }

View File

@@ -51,7 +51,8 @@ bool parse_file(char* fileName)
return parser.Good(); return parser.Good();
} }
class ParserTest : public CppUnit::TestFixture { class ParserTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(ParserTest); CPPUNIT_TEST_SUITE(ParserTest);
CPPUNIT_TEST(atac01); CPPUNIT_TEST(atac01);
CPPUNIT_TEST(atac05); CPPUNIT_TEST(atac05);
@@ -271,7 +272,7 @@ template<class T>
void u_sertest(T* x) void u_sertest(T* x)
{ {
ByteStream bs; ByteStream bs;
stringstream s1,s2; stringstream s1, s2;
auto_ptr<T> y(new T); auto_ptr<T> y(new T);
x->serialize(bs); x->serialize(bs);
@@ -296,7 +297,7 @@ template<class T>
void t_sertest(T* x) void t_sertest(T* x)
{ {
ByteStream bs; ByteStream bs;
stringstream s1,s2; stringstream s1, s2;
auto_ptr<T> y(new T); auto_ptr<T> y(new T);
x->serialize(bs); 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_SUITE(SerializeTest);
CPPUNIT_TEST(qname); CPPUNIT_TEST(qname);
@@ -375,7 +377,8 @@ public:
{ {
SqlFileParser p; SqlFileParser p;
p.Parse("sql/atrc01.sql"); p.Parse("sql/atrc01.sql");
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]); AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
@@ -389,7 +392,8 @@ public:
{ {
SqlFileParser p; SqlFileParser p;
p.Parse("sql/atmct01.sql"); p.Parse("sql/atmct01.sql");
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]); AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
@@ -403,7 +407,8 @@ public:
{ {
SqlFileParser p; SqlFileParser p;
p.Parse("sql/atrt01.sql"); p.Parse("sql/atrt01.sql");
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]); AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
@@ -416,7 +421,8 @@ public:
{ {
SqlFileParser p; SqlFileParser p;
p.Parse("sql/atdtc01.sql"); p.Parse("sql/atdtc01.sql");
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]); AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
@@ -429,7 +435,8 @@ public:
{ {
SqlFileParser p; SqlFileParser p;
p.Parse("sql/atmcdd01.sql"); p.Parse("sql/atmcdd01.sql");
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]); AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
@@ -442,7 +449,8 @@ public:
{ {
SqlFileParser p; SqlFileParser p;
p.Parse("sql/atmcsd01.sql"); p.Parse("sql/atmcsd01.sql");
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]); AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
@@ -456,7 +464,8 @@ public:
{ {
SqlFileParser p; SqlFileParser p;
p.Parse("sql/atdc01.sql"); p.Parse("sql/atdc01.sql");
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]); AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
@@ -469,7 +478,8 @@ public:
{ {
SqlFileParser p; SqlFileParser p;
p.Parse("sql/atatc01.sql"); p.Parse("sql/atatc01.sql");
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]); AlterTableStatement* stmt = dynamic_cast<AlterTableStatement*>(stmts[0]);
@@ -498,11 +508,13 @@ public:
files.push_back("sql/ct11.sql"); files.push_back("sql/ct11.sql");
vector<string>::const_iterator itr; vector<string>::const_iterator itr;
for(itr = files.begin(); itr != files.end(); ++itr)
for (itr = files.begin(); itr != files.end(); ++itr)
{ {
SqlFileParser p; SqlFileParser p;
p.Parse(*itr); p.Parse(*itr);
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]); CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]);
@@ -511,7 +523,8 @@ public:
ColumnDefList* columns = &(ct->fTableDef->fColumns); ColumnDefList* columns = &(ct->fTableDef->fColumns);
ColumnDefList::const_iterator itr; ColumnDefList::const_iterator itr;
for(itr = columns->begin();
for (itr = columns->begin();
itr != columns->end(); itr != columns->end();
++itr) ++itr)
{ {
@@ -544,11 +557,13 @@ public:
files.push_back("sql/ct11.sql"); files.push_back("sql/ct11.sql");
vector<string>::const_iterator itr; vector<string>::const_iterator itr;
for(itr = files.begin(); itr != files.end(); ++itr)
for (itr = files.begin(); itr != files.end(); ++itr)
{ {
SqlFileParser p; SqlFileParser p;
p.Parse(*itr); p.Parse(*itr);
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]); CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]);
@@ -577,7 +592,7 @@ public:
void qname() void qname()
{ {
cout << "Serialize test: QualifiedName" << endl; 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()); u_sertest<QualifiedName>(name.get());
} }
@@ -647,12 +662,14 @@ public:
files.push_back("sql/ct11.sql"); files.push_back("sql/ct11.sql");
vector<string>::const_iterator itr; 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; cout << "* * * Checking columndef serialization for " << *itr << endl;
SqlFileParser p; SqlFileParser p;
p.Parse(*itr); p.Parse(*itr);
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]); CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]);
@@ -664,7 +681,8 @@ public:
ColumnDefList* columns = &(ct->fTableDef->fColumns); ColumnDefList* columns = &(ct->fTableDef->fColumns);
ColumnDefList::const_iterator itr; ColumnDefList::const_iterator itr;
for(itr = columns->begin();
for (itr = columns->begin();
itr != columns->end(); itr != columns->end();
++itr) ++itr)
{ {
@@ -764,12 +782,14 @@ public:
files.push_back("sql/ct11.sql"); files.push_back("sql/ct11.sql");
vector<string>::const_iterator itr; 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; cout << "* * * Checking tabledef serialization for " << *itr << endl;
SqlFileParser p; SqlFileParser p;
p.Parse(*itr); p.Parse(*itr);
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]); CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]);
@@ -801,13 +821,15 @@ public:
files.push_back("sql/ct11.sql"); files.push_back("sql/ct11.sql");
vector<string>::const_iterator itr; 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; cout << "* * * Checking CreateTableStatement serialization for " << *itr << endl;
SqlFileParser p; SqlFileParser p;
p.setDefaultSchema("tpch"); p.setDefaultSchema("tpch");
p.Parse(*itr); p.Parse(*itr);
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]); CreateTableStatement* ct = dynamic_cast<CreateTableStatement*>(stmts[0]);
@@ -828,12 +850,14 @@ public:
files.push_back("sql/dt02.sql"); files.push_back("sql/dt02.sql");
vector<string>::const_iterator itr; 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; cout << "* * * Checking DropTableStatement serialization for " << *itr << endl;
SqlFileParser p; SqlFileParser p;
p.Parse(*itr); p.Parse(*itr);
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
DropTableStatement* stmt = dynamic_cast<DropTableStatement*>(stmts[0]); DropTableStatement* stmt = dynamic_cast<DropTableStatement*>(stmts[0]);
@@ -853,12 +877,14 @@ public:
files.push_back("sql/ci02.sql"); files.push_back("sql/ci02.sql");
vector<string>::const_iterator itr; 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; cout << "* * * Checking Create Index serialization for " << *itr << endl;
SqlFileParser p; SqlFileParser p;
p.Parse(*itr); p.Parse(*itr);
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
CreateIndexStatement* stmt = dynamic_cast<CreateIndexStatement*>(stmts[0]); CreateIndexStatement* stmt = dynamic_cast<CreateIndexStatement*>(stmts[0]);
@@ -877,12 +903,14 @@ public:
files.push_back("sql/di01.sql"); files.push_back("sql/di01.sql");
vector<string>::const_iterator itr; 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; cout << "* * * Checking Drop Index serialization for " << *itr << endl;
SqlFileParser p; SqlFileParser p;
p.Parse(*itr); p.Parse(*itr);
if(p.Good())
if (p.Good())
{ {
const ParseTree& stmts = p.GetParseTree(); const ParseTree& stmts = p.GetParseTree();
DropIndexStatement* stmt = dynamic_cast<DropIndexStatement*>(stmts[0]); DropIndexStatement* stmt = dynamic_cast<DropIndexStatement*>(stmts[0]);
@@ -903,11 +931,11 @@ CPPUNIT_TEST_SUITE_REGISTRATION(ParserTest);
#include <cppunit/extensions/TestFactoryRegistry.h> #include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h> #include <cppunit/ui/text/TestRunner.h>
int main(int argc, char *argv[]) int main(int argc, char* argv[])
{ {
CppUnit::TextUi::TestRunner runner; CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry(); CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() ); runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false ); bool wasSuccessful = runner.run( "", false );

File diff suppressed because it is too large Load Diff

View File

@@ -34,14 +34,14 @@
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
/** @brief specialization of a DDLPackageProcessor /** @brief specialization of a DDLPackageProcessor
* for interacting with the Write Engine * for interacting with the Write Engine
* to process alter table ddl statements. * to process alter table ddl statements.
*/ */
class AlterTableProcessor : public DDLPackageProcessor class AlterTableProcessor : public DDLPackageProcessor
{ {
public: public:
AlterTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){} AlterTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process an alter table statement /** @brief process an alter table statement
* *
* @param alterTableStmt the AlterTableStatement * @param alterTableStmt the AlterTableStatement
@@ -147,12 +147,12 @@ namespace ddlpackageprocessor
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId); 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); void rollBackAlter(const std::string& error, BRM::TxnID txnID, int sessionId, DDLResult& result, uint64_t uniqueId);
private: private:
}; };
} //namespace ddlpackageprocessor } //namespace ddlpackageprocessor

View File

@@ -56,8 +56,8 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
DETAIL_INFO(createIndexStmt); DETAIL_INFO(createIndexStmt);
BRM::TxnID txnID; BRM::TxnID txnID;
txnID.id= fTxnid.id; txnID.id = fTxnid.id;
txnID.valid= fTxnid.valid; txnID.valid = fTxnid.valid;
/*Check whether the table exists already. If not, it is assumed from primary key creating. /*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 This is based on the assumption that Front end is already error out if the user trys to
create index on non-existing table. */ create index on non-existing table. */
@@ -66,7 +66,9 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
tableName.table = (createIndexStmt.fTableName)->fName; tableName.table = (createIndexStmt.fTableName)->fName;
CalpontSystemCatalog::ROPair roPair; CalpontSystemCatalog::ROPair roPair;
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog( createIndexStmt.fSessionID ); boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog( createIndexStmt.fSessionID );
try {
try
{
roPair = systemCatalogPtr->tableRID( tableName ); roPair = systemCatalogPtr->tableRID( tableName );
} }
catch (exception& ex) catch (exception& ex)
@@ -80,10 +82,12 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
{ {
return result; return result;
} }
if ( roPair.objnum < 3000 ) if ( roPair.objnum < 3000 )
{ {
return result; return result;
} }
fPKName = createIndexStmt.fIndexName->fName; fPKName = createIndexStmt.fIndexName->fName;
int err = 0; int err = 0;
@@ -103,10 +107,12 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
VERBOSE_INFO("Writing meta data to SYSINDEX"); VERBOSE_INFO("Writing meta data to SYSINDEX");
bool multicol = false; bool multicol = false;
if ( createIndexStmt.fColumnNames.size() > 1 ) if ( createIndexStmt.fColumnNames.size() > 1 )
{ {
multicol = true; multicol = true;
} }
//validate index columns //validate index columns
CalpontSystemCatalog::TableColName tableColName; CalpontSystemCatalog::TableColName tableColName;
tableColName.schema = (createIndexStmt.fTableName)->fSchema; tableColName.schema = (createIndexStmt.fTableName)->fSchema;
@@ -118,6 +124,7 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
DDLIndexPopulator pop(&fWriteEngine, &fSessionManager, createIndexStmt.fSessionID, txnID.id, result, DDLIndexPopulator pop(&fWriteEngine, &fSessionManager, createIndexStmt.fSessionID, txnID.id, result,
fIdxOID, createIndexStmt.fColumnNames, *createIndexStmt.fTableName, fIdxOID, createIndexStmt.fColumnNames, *createIndexStmt.fTableName,
type, getDebugLevel()); type, getDebugLevel());
if ( multicol) if ( multicol)
{ {
for ( colIter = createIndexStmt.fColumnNames.begin(); colIter != createIndexStmt.fColumnNames.end(); colIter++) for ( colIter = createIndexStmt.fColumnNames.begin(); colIter != createIndexStmt.fColumnNames.end(); colIter++)
@@ -129,6 +136,7 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
colType = systemCatalogPtr->colType (oid ); colType = systemCatalogPtr->colType (oid );
totalWidth += (pop.isDictionaryType(colType)) ? 8 : colType.colWidth; totalWidth += (pop.isDictionaryType(colType)) ? 8 : colType.colWidth;
} }
if ( totalWidth > 32 ) if ( totalWidth > 32 )
{ {
stringstream ss; 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); //writeSysIndexMetaData(createIndexStmt.fSessionID, txnID.id, result, *createIndexStmt.fTableName, type, createIndexStmt.fIndexName->fName, multicol);
//fIdxOID values are set in writeSysIndexMetaData. //fIdxOID values are set in writeSysIndexMetaData.
@@ -179,14 +187,16 @@ try
// get the columns for the SYSCONSTRAINT table // get the columns for the SYSCONSTRAINT table
ColumnList sysConsColumns; ColumnList sysConsColumns;
ColumnList::const_iterator sysCons_iterator; 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(); sysCons_iterator = sysConsColumns.begin();
std::string idxData; std::string idxData;
while ( sysCons_iterator != sysConsColumns.end() ) while ( sysCons_iterator != sysConsColumns.end() )
{ {
column = *sysCons_iterator; column = *sysCons_iterator;
boost::algorithm::to_lower(column.tableColName.column); boost::algorithm::to_lower(column.tableColName.column);
isNull = false; isNull = false;
if (CONSTRAINTNAME_COL == column.tableColName.column) if (CONSTRAINTNAME_COL == column.tableColName.column)
{ {
idxData = createIndexStmt.fIndexName->fName; idxData = createIndexStmt.fIndexName->fName;
@@ -245,6 +255,7 @@ try
{ {
colTuple.data = tokenizeData(txnID.id, result, column.colType, colTuple.data); colTuple.data = tokenizeData(txnID.id, result, column.colType, colTuple.data);
} }
colStructs.push_back( colStruct ); colStructs.push_back( colStruct );
colTuples.push_back( colTuple ); colTuples.push_back( colTuple );
@@ -296,10 +307,11 @@ try
// get the columns for the SYSCONSTRAINTCOL table // get the columns for the SYSCONSTRAINTCOL table
ColumnList sysConsColColumns; ColumnList sysConsColColumns;
ColumnList::const_iterator sysConsCol_iterator; ColumnList::const_iterator sysConsCol_iterator;
getColumnsForTable(createIndexStmt.fSessionID, sysConsColTableName.schema,sysConsColTableName.table, sysConsColColumns); getColumnsForTable(createIndexStmt.fSessionID, sysConsColTableName.schema, sysConsColTableName.table, sysConsColColumns);
// write sysconstraintcol // write sysconstraintcol
sysConsCol_iterator = sysConsColColumns.begin(); sysConsCol_iterator = sysConsColColumns.begin();
std::string colData; std::string colData;
while ( sysConsCol_iterator != sysConsColColumns.end() ) while ( sysConsCol_iterator != sysConsColColumns.end() )
{ {
column = *sysConsCol_iterator; column = *sysConsCol_iterator;
@@ -368,7 +380,7 @@ try
{ {
return rollBackCreateIndex(errorString( "WE: Error inserting Column Record: ", error), txnID, createIndexStmt.fSessionID); return rollBackCreateIndex(errorString( "WE: Error inserting Column Record: ", error), txnID, createIndexStmt.fSessionID);
/* logging::Message::Args args; /* logging::Message::Args args;
logging::Message message(9); logging::Message message(9);
args.add("Error updating: "); args.add("Error updating: ");
args.add("calpont.sysconstraintcol"); args.add("calpont.sysconstraintcol");
@@ -388,12 +400,15 @@ try
VERBOSE_INFO("Creating index files"); VERBOSE_INFO("Creating index files");
err = fWriteEngine.createIndex( txnID.id, fIdxOID.treeOID, fIdxOID.listOID ); err = fWriteEngine.createIndex( txnID.id, fIdxOID.treeOID, fIdxOID.listOID );
if (err) if (err)
{ {
return rollBackCreateIndex(errorString("Write engine failed to create the new index. ", err), txnID, createIndexStmt.fSessionID); return rollBackCreateIndex(errorString("Write engine failed to create the new index. ", err), txnID, createIndexStmt.fSessionID);
} }
// new if BULK_LOAD close // new if BULK_LOAD close
err = pop.populateIndex(result); err = pop.populateIndex(result);
if ( err ) if ( err )
{ {
return rollBackCreateIndex(errorString("Failed to populate index with current data. ", err), txnID, createIndexStmt.fSessionID); return rollBackCreateIndex(errorString("Failed to populate index with current data. ", err), txnID, createIndexStmt.fSessionID);
@@ -405,6 +420,7 @@ try
DETAIL_INFO("Commiting transaction"); DETAIL_INFO("Commiting transaction");
err = fWriteEngine.commit( txnID.id ); err = fWriteEngine.commit( txnID.id );
if (err) if (err)
{ {
return rollBackCreateIndex(errorString("Failed to commit the create index transaction. ", err), txnID, createIndexStmt.fSessionID); return rollBackCreateIndex(errorString("Failed to commit the create index transaction. ", err), txnID, createIndexStmt.fSessionID);
@@ -412,7 +428,7 @@ try
fSessionManager.committed(txnID); fSessionManager.committed(txnID);
// original if BULK_LOAD close } // original if BULK_LOAD close }
} // try } // try
catch (exception& ex) catch (exception& ex)
{ {
@@ -455,8 +471,10 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::rollBackCreateIndex(const
void CreateIndexProcessor::rollBackIndex(BRM::TxnID& txnID, int sessionId) void CreateIndexProcessor::rollBackIndex(BRM::TxnID& txnID, int sessionId)
{ {
fWriteEngine.rollbackTran(txnID.id, sessionId); fWriteEngine.rollbackTran(txnID.id, sessionId);
fWriteEngine.dropIndex(txnID.id,fIdxOID.listOID, fIdxOID.treeOID); fWriteEngine.dropIndex(txnID.id, fIdxOID.listOID, fIdxOID.treeOID);
try {
try
{
//execplan::ObjectIDManager fObjectIDManager; //execplan::ObjectIDManager fObjectIDManager;
//fObjectIDManager.returnOIDs(fIdxOID.treeOID, fIdxOID.listOID); //fObjectIDManager.returnOIDs(fIdxOID.treeOID, fIdxOID.listOID);
} }
@@ -466,6 +484,7 @@ void CreateIndexProcessor::rollBackIndex(BRM::TxnID& txnID, int sessionId)
} }
catch (... ) catch (... )
{ } { }
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
} }

View File

@@ -29,26 +29,26 @@
const int BULK_LOAD = 1; const int BULK_LOAD = 1;
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
/** @brief specialization of a DDLPackageProcessor /** @brief specialization of a DDLPackageProcessor
* for interacting with the Write Engine to process * for interacting with the Write Engine to process
* create index ddl statements * create index ddl statements
*/ */
class CreateIndexProcessor : public DDLPackageProcessor class CreateIndexProcessor : public DDLPackageProcessor
{ {
public: public:
/** @brief process a create index statement /** @brief process a create index statement
* *
* @param createIndexStmt the create index statement * @param createIndexStmt the create index statement
*/ */
DDLResult processPackage(ddlpackage::CreateIndexStatement& createIndexStmt); DDLResult processPackage(ddlpackage::CreateIndexStatement& createIndexStmt);
protected: protected:
DDLResult rollBackCreateIndex(const std::string& error, BRM::TxnID& txnID, int sessionId); DDLResult rollBackCreateIndex(const std::string& error, BRM::TxnID& txnID, int sessionId);
void rollBackIndex(BRM::TxnID& txnID); void rollBackIndex(BRM::TxnID& txnID);
std::string errorString(const std::string& msg, int error); std::string errorString(const std::string& msg, int error);
private: private:
}; };
} //namespace ddlpackageprocessor } //namespace ddlpackageprocessor
#endif //CREATEINDEXPROCESSOR_H #endif //CREATEINDEXPROCESSOR_H

View File

@@ -55,11 +55,12 @@ CreateTableProcessor::DDLResult CreateTableProcessor::processPackage(
DDLResult result; DDLResult result;
BRM::TxnID txnID; BRM::TxnID txnID;
txnID.id= fTxnid.id; txnID.id = fTxnid.id;
txnID.valid= fTxnid.valid; txnID.valid = fTxnid.valid;
result.result = NO_ERROR; result.result = NO_ERROR;
int rc1 = 0; int rc1 = 0;
rc1 = fDbrm->isReadWrite(); rc1 = fDbrm->isReadWrite();
if (rc1 != 0 ) if (rc1 != 0 )
{ {
Message::Args args; Message::Args args;
@@ -71,16 +72,19 @@ CreateTableProcessor::DDLResult CreateTableProcessor::processPackage(
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
DETAIL_INFO(createTableStmt); DETAIL_INFO(createTableStmt);
ddlpackage::TableDef& tableDef = *createTableStmt.fTableDef; ddlpackage::TableDef& tableDef = *createTableStmt.fTableDef;
//If schema = CALPONTSYS, do not create table //If schema = CALPONTSYS, do not create table
boost::algorithm::to_lower(tableDef.fQualifiedName->fSchema); boost::algorithm::to_lower(tableDef.fQualifiedName->fSchema);
if (tableDef.fQualifiedName->fSchema == CALPONT_SCHEMA) if (tableDef.fQualifiedName->fSchema == CALPONT_SCHEMA)
{ {
//release the transaction //release the transaction
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
// Commit current transaction. // Commit current transaction.
// all DDL statements cause an implicut commit // all DDL statements cause an implicut commit
VERBOSE_INFO("Getting current txnID"); VERBOSE_INFO("Getting current txnID");
@@ -94,13 +98,14 @@ CreateTableProcessor::DDLResult CreateTableProcessor::processPackage(
execplan::CalpontSystemCatalog::ROPair roPair; execplan::CalpontSystemCatalog::ROPair roPair;
roPair.objnum = 0; roPair.objnum = 0;
ByteStream::byte rc = 0; ByteStream::byte rc = 0;
/** @Bug 217 */ /** @Bug 217 */
/** @Bug 225 */ /** @Bug 225 */
try try
{ {
roPair = systemCatalogPtr->tableRID(tableName); roPair = systemCatalogPtr->tableRID(tableName);
} }
catch (IDBExcept &ie) catch (IDBExcept& ie)
{ {
// TODO: What is and is not an error here? // TODO: What is and is not an error here?
if (ie.errorCode() == ERR_DATA_OFFLINE) if (ie.errorCode() == ERR_DATA_OFFLINE)
@@ -167,10 +172,19 @@ CreateTableProcessor::DDLResult CreateTableProcessor::processPackage(
#ifdef _MSC_VER #ifdef _MSC_VER
//FIXME: Why do we need to do this??? //FIXME: Why do we need to do this???
systemCatalogPtr->flushCache(); systemCatalogPtr->flushCache();
try { roPair = systemCatalogPtr->tableRID(tableName); }
catch (...) { roPair.objnum = 0; } try
{
roPair = systemCatalogPtr->tableRID(tableName);
}
catch (...)
{
roPair.objnum = 0;
}
if (roPair.objnum < 3000) if (roPair.objnum < 3000)
goto keepGoing; goto keepGoing;
#endif #endif
Message::Args args; Message::Args args;
Message message(9); Message message(9);
@@ -186,24 +200,27 @@ CreateTableProcessor::DDLResult CreateTableProcessor::processPackage(
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
#ifdef _MSC_VER #ifdef _MSC_VER
keepGoing: keepGoing:
#endif #endif
// Start a new transaction // Start a new transaction
VERBOSE_INFO("Starting 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); SQLLogger logger(stmt, fDDLLoggingId, createTableStmt.fSessionID, txnID.id);
std::string err; std::string err;
execplan::ObjectIDManager fObjectIDManager; execplan::ObjectIDManager fObjectIDManager;
OamCache * oamcache = OamCache::makeOamCache(); OamCache* oamcache = OamCache::makeOamCache();
string errorMsg; string errorMsg;
//get a unique number //get a unique number
uint64_t uniqueId = 0; uint64_t uniqueId = 0;
//Bug 5070. Added exception handling //Bug 5070. Added exception handling
try { try
{
uniqueId = fDbrm->getUnique64(); uniqueId = fDbrm->getUnique64();
} }
catch (std::exception& ex) catch (std::exception& ex)
@@ -230,6 +247,7 @@ keepGoing:
} }
fWEClient->addQueue(uniqueId); fWEClient->addQueue(uniqueId);
try try
{ {
//Allocate tableoid table identification //Allocate tableoid table identification
@@ -238,10 +256,12 @@ keepGoing:
VERBOSE_INFO("Allocating object IDs for columns"); VERBOSE_INFO("Allocating object IDs for columns");
uint32_t numColumns = tableDef.fColumns.size(); uint32_t numColumns = tableDef.fColumns.size();
uint32_t numDictCols = 0; uint32_t numDictCols = 0;
for (unsigned i=0; i < numColumns; i++)
for (unsigned i = 0; i < numColumns; i++)
{ {
int dataType; int dataType;
dataType = convertDataType(tableDef.fColumns[i]->fType->fType); dataType = convertDataType(tableDef.fColumns[i]->fType->fType);
if ( (dataType == CalpontSystemCatalog::CHAR && tableDef.fColumns[i]->fType->fLength > 8) || if ( (dataType == CalpontSystemCatalog::CHAR && tableDef.fColumns[i]->fType->fLength > 8) ||
(dataType == CalpontSystemCatalog::VARCHAR && tableDef.fColumns[i]->fType->fLength > 7) || (dataType == CalpontSystemCatalog::VARCHAR && tableDef.fColumns[i]->fType->fLength > 7) ||
(dataType == CalpontSystemCatalog::VARBINARY && 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) ) (dataType == CalpontSystemCatalog::TEXT && tableDef.fColumns[i]->fType->fLength > 7) )
numDictCols++; 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 #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 #endif
if (fStartingColOID < 0) if (fStartingColOID < 0)
{ {
result.result = CREATE_ERROR; result.result = CREATE_ERROR;
@@ -280,9 +302,10 @@ cout << fTxnid.id << " Create table allocOIDs got the starting oid " << fStartin
BRM::OID_t sysOid = 1001; BRM::OID_t sysOid = 1001;
//Find out where systable is //Find out where systable is
rc = fDbrm->getSysCatDBRoot(sysOid, dbRoot); rc = fDbrm->getSysCatDBRoot(sysOid, dbRoot);
if (rc != 0) if (rc != 0)
{ {
result.result =(ResultCode) rc; result.result = (ResultCode) rc;
Message::Args args; Message::Args args;
Message message(9); Message message(9);
args.add("Error while calling getSysCatDBRoot "); args.add("Error while calling getSysCatDBRoot ");
@@ -302,31 +325,38 @@ cout << fTxnid.id << " Create table allocOIDs got the starting oid " << fStartin
pmNum = (*dbRootPMMap)[dbRoot]; pmNum = (*dbRootPMMap)[dbRoot];
// MCOL-66 The DBRM can't handle concurrent DDL // MCOL-66 The DBRM can't handle concurrent DDL
boost::mutex::scoped_lock lk(dbrmMutex); boost::mutex::scoped_lock lk(dbrmMutex);
try try
{ {
#ifdef IDB_DDL_DEBUG #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 #endif
fWEClient->write(bytestream, (unsigned)pmNum); fWEClient->write(bytestream, (unsigned)pmNum);
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES"; errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
break; break;
} }
else { else
{
*bsIn >> rc; *bsIn >> rc;
if (rc != 0) {
if (rc != 0)
{
errorMsg.clear(); errorMsg.clear();
*bsIn >> errorMsg; *bsIn >> errorMsg;
#ifdef IDB_DDL_DEBUG #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 #endif
} }
break; break;
} }
} }
@@ -334,7 +364,7 @@ cout << fTxnid.id << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
catch (runtime_error& ex) //write error catch (runtime_error& ex) //write error
{ {
#ifdef IDB_DDL_DEBUG #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 #endif
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = ex.what(); errorMsg = ex.what();
@@ -343,26 +373,28 @@ cout << fTxnid.id << " create table got exception" << ex.what() << endl;
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
#ifdef IDB_DDL_DEBUG #ifdef IDB_DDL_DEBUG
cout << "create table got unknown exception" << endl; cout << "create table got unknown exception" << endl;
#endif #endif
} }
if (rc != 0) if (rc != 0)
{ {
#ifdef IDB_DDL_DEBUG #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 #endif
result.result =(ResultCode) rc; result.result = (ResultCode) rc;
Message::Args args; Message::Args args;
Message message(9); Message message(9);
args.add("(2)Create table failed due to "); args.add("(2)Create table failed due to ");
args.add(errorMsg); args.add(errorMsg);
message.format( args ); message.format( args );
result.message = message; result.message = message;
if (rc != NETWORK_ERROR) if (rc != NETWORK_ERROR)
{ {
rollBackTransaction( uniqueId, txnID, createTableStmt.fSessionID ); //What to do with the error code rollBackTransaction( uniqueId, txnID, createTableStmt.fSessionID ); //What to do with the error code
} }
//release transaction //release transaction
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
@@ -375,12 +407,17 @@ cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
bytestream << (uint32_t) createTableStmt.fSessionID; bytestream << (uint32_t) createTableStmt.fSessionID;
bytestream << (uint32_t)txnID.id; bytestream << (uint32_t)txnID.id;
bytestream << numColumns; 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; 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; uint8_t alterFlag = 0;
@@ -391,9 +428,10 @@ cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
sysOid = 1021; sysOid = 1021;
//Find out where syscolumn is //Find out where syscolumn is
rc = fDbrm->getSysCatDBRoot(sysOid, dbRoot); rc = fDbrm->getSysCatDBRoot(sysOid, dbRoot);
if (rc != 0) if (rc != 0)
{ {
result.result =(ResultCode) rc; result.result = (ResultCode) rc;
Message::Args args; Message::Args args;
Message message(9); Message message(9);
args.add("Error while calling getSysCatDBRoot "); args.add("Error while calling getSysCatDBRoot ");
@@ -408,31 +446,38 @@ cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
bytestream << (uint32_t)dbRoot; bytestream << (uint32_t)dbRoot;
tableDef.serialize(bytestream); tableDef.serialize(bytestream);
pmNum = (*dbRootPMMap)[dbRoot]; pmNum = (*dbRootPMMap)[dbRoot];
try try
{ {
#ifdef IDB_DDL_DEBUG #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 #endif
fWEClient->write(bytestream, (uint32_t)pmNum); fWEClient->write(bytestream, (uint32_t)pmNum);
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES"; errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
break; break;
} }
else { else
{
*bsIn >> rc; *bsIn >> rc;
if (rc != 0) {
if (rc != 0)
{
errorMsg.clear(); errorMsg.clear();
*bsIn >> errorMsg; *bsIn >> errorMsg;
#ifdef IDB_DDL_DEBUG #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 #endif
} }
break; break;
} }
} }
@@ -440,7 +485,7 @@ cout << fTxnid.id << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
catch (runtime_error& ex) //write error catch (runtime_error& ex) //write error
{ {
#ifdef IDB_DDL_DEBUG #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 #endif
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = ex.what(); errorMsg = ex.what();
@@ -449,26 +494,28 @@ cout << fTxnid.id << " create table got exception" << ex.what() << endl;
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
#ifdef IDB_DDL_DEBUG #ifdef IDB_DDL_DEBUG
cout << fTxnid.id << " create table got unknown exception" << endl; cout << fTxnid.id << " create table got unknown exception" << endl;
#endif #endif
} }
if (rc != 0) if (rc != 0)
{ {
#ifdef IDB_DDL_DEBUG #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 #endif
result.result =(ResultCode) rc; result.result = (ResultCode) rc;
Message::Args args; Message::Args args;
Message message(9); Message message(9);
args.add("(3)Create table failed due to "); args.add("(3)Create table failed due to ");
args.add(errorMsg); args.add(errorMsg);
message.format( args ); message.format( args );
result.message = message; result.message = message;
if (rc != NETWORK_ERROR) if (rc != NETWORK_ERROR)
{ {
rollBackTransaction( uniqueId, txnID, createTableStmt.fSessionID ); //What to do with the error code rollBackTransaction( uniqueId, txnID, createTableStmt.fSessionID ); //What to do with the error code
} }
//release transaction //release transaction
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
@@ -496,11 +543,13 @@ cout << fTxnid.id << " Create table WE_SVR_WRITE_CREATE_SYSCOLUMN: " << errorMsg
bytestream << (numColumns + numDictCols); bytestream << (numColumns + numDictCols);
unsigned colNum = 0; unsigned colNum = 0;
unsigned dictNum = 0; unsigned dictNum = 0;
while (iter != tableDefCols.end()) while (iter != tableDefCols.end())
{ {
colDefPtr = *iter; colDefPtr = *iter;
CalpontSystemCatalog::ColDataType dataType = convertDataType(colDefPtr->fType->fType); CalpontSystemCatalog::ColDataType dataType = convertDataType(colDefPtr->fType->fType);
if (dataType == CalpontSystemCatalog::DECIMAL || if (dataType == CalpontSystemCatalog::DECIMAL ||
dataType == CalpontSystemCatalog::UDECIMAL) dataType == CalpontSystemCatalog::UDECIMAL)
{ {
@@ -526,6 +575,7 @@ cout << fTxnid.id << " Create table WE_SVR_WRITE_CREATE_SYSCOLUMN: " << errorMsg
colDefPtr->fType->fLength = 8; colDefPtr->fType->fLength = 8;
} }
} }
bytestream << (fStartingColOID + (colNum++) + 1); bytestream << (fStartingColOID + (colNum++) + 1);
bytestream << (uint8_t) dataType; bytestream << (uint8_t) dataType;
bytestream << (uint8_t) false; 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 << (uint32_t) colDefPtr->fType->fLength;
bytestream << (uint16_t) useDBRoot; bytestream << (uint16_t) useDBRoot;
bytestream << (uint32_t) colDefPtr->fType->fCompressiontype; bytestream << (uint32_t) colDefPtr->fType->fCompressiontype;
if ( (dataType == CalpontSystemCatalog::CHAR && colDefPtr->fType->fLength > 8) || if ( (dataType == CalpontSystemCatalog::CHAR && colDefPtr->fType->fLength > 8) ||
(dataType == CalpontSystemCatalog::VARCHAR && colDefPtr->fType->fLength > 7) || (dataType == CalpontSystemCatalog::VARCHAR && colDefPtr->fType->fLength > 7) ||
(dataType == CalpontSystemCatalog::VARBINARY && colDefPtr->fType->fLength > 7) || (dataType == CalpontSystemCatalog::VARBINARY && colDefPtr->fType->fLength > 7) ||
(dataType == CalpontSystemCatalog::BLOB && colDefPtr->fType->fLength > 7) || (dataType == CalpontSystemCatalog::BLOB && colDefPtr->fType->fLength > 7) ||
(dataType == CalpontSystemCatalog::TEXT && 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) dataType;
bytestream << (uint8_t) true; bytestream << (uint8_t) true;
bytestream << (uint32_t) colDefPtr->fType->fLength; bytestream << (uint32_t) colDefPtr->fType->fLength;
bytestream << (uint16_t) useDBRoot; bytestream << (uint16_t) useDBRoot;
bytestream << (uint32_t) colDefPtr->fType->fCompressiontype; bytestream << (uint32_t) colDefPtr->fType->fCompressiontype;
} }
++iter; ++iter;
} }
//@Bug 4176. save oids to a log file for cleanup after fail over. //@Bug 4176. save oids to a log file for cleanup after fail over.
std::vector <CalpontSystemCatalog::OID> oidList; 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); oidList.push_back(fStartingColOID + i + 1);
}
bytestream << numDictCols;
for (unsigned i = 0; i <numDictCols; ++i)
{
oidList.push_back(fStartingColOID+numColumns+i+1);
} }
try { bytestream << numDictCols;
for (unsigned i = 0; i < numDictCols; ++i)
{
oidList.push_back(fStartingColOID + numColumns + i + 1);
}
try
{
createWriteDropLogFile( fStartingColOID, uniqueId, oidList ); createWriteDropLogFile( fStartingColOID, uniqueId, oidList );
} }
catch (std::exception& ex) catch (std::exception& ex)
{ {
result.result =(ResultCode) rc; result.result = (ResultCode) rc;
Message::Args args; Message::Args args;
Message message(9); Message message(9);
args.add("(4)Create table failed due to "); args.add("(4)Create table failed due to ");
args.add(ex.what()); args.add(ex.what());
message.format( args ); message.format( args );
result.message = message; result.message = message;
if (rc != NETWORK_ERROR) if (rc != NETWORK_ERROR)
{ {
rollBackTransaction( uniqueId, txnID, createTableStmt.fSessionID ); //What to do with the error code rollBackTransaction( uniqueId, txnID, createTableStmt.fSessionID ); //What to do with the error code
} }
//release transaction //release transaction
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
pmNum = (*dbRootPMMap)[useDBRoot]; pmNum = (*dbRootPMMap)[useDBRoot];
try try
{ {
#ifdef IDB_DDL_DEBUG #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 #endif
fWEClient->write(bytestream, pmNum); fWEClient->write(bytestream, pmNum);
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES"; errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
break; break;
} }
else { else
{
*bsIn >> rc; *bsIn >> rc;
if (rc != 0) {
if (rc != 0)
{
errorMsg.clear(); errorMsg.clear();
*bsIn >> errorMsg; *bsIn >> errorMsg;
#ifdef IDB_DDL_DEBUG #ifdef IDB_DDL_DEBUG
cout << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl; cout << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl;
#endif #endif
} }
break; break;
} }
} }
if (rc != 0) { if (rc != 0)
{
//drop the newly created files //drop the newly created files
bytestream.restart(); bytestream.restart();
bytestream << (ByteStream::byte) WE_SVR_WRITE_DROPFILES; bytestream << (ByteStream::byte) WE_SVR_WRITE_DROPFILES;
bytestream << uniqueId; bytestream << uniqueId;
bytestream << (uint32_t)(numColumns+numDictCols); bytestream << (uint32_t)(numColumns + numDictCols);
for (unsigned i = 0; i < (numColumns+numDictCols); i++)
for (unsigned i = 0; i < (numColumns + numDictCols); i++)
{ {
bytestream << (uint32_t)(fStartingColOID + i + 1); bytestream << (uint32_t)(fStartingColOID + i + 1);
} }
fWEClient->write(bytestream, pmNum); fWEClient->write(bytestream, pmNum);
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
break; break;
} }
else { else
{
break; break;
} }
} }
//@Bug 5464. Delete from extent map. //@Bug 5464. Delete from extent map.
fDbrm->deleteOIDs(oidList); fDbrm->deleteOIDs(oidList);
@@ -647,7 +720,7 @@ cout << "Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg << endl;
if (rc != 0) if (rc != 0)
{ {
#ifdef IDB_DDL_DEBUG #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 #endif
rollBackTransaction( uniqueId, txnID, createTableStmt.fSessionID); //What to do with the error code rollBackTransaction( uniqueId, txnID, createTableStmt.fSessionID); //What to do with the error code
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
@@ -676,8 +749,9 @@ cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
return result; return result;
} }
//fWEClient->removeQueue(uniqueId); //fWEClient->removeQueue(uniqueId);
if (rc !=0) if (rc != 0)
{ {
result.result = CREATE_ERROR; result.result = CREATE_ERROR;
Message::Args args; Message::Args args;
@@ -687,6 +761,7 @@ cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
message.format( args ); message.format( args );
result.message = message; result.message = message;
} }
return result; return result;
} }
@@ -709,6 +784,7 @@ void CreateTableProcessor::rollBackCreateTable(const string& error, BRM::TxnID t
fWriteEngine.rollbackTran(txnID.id, sessionId); fWriteEngine.rollbackTran(txnID.id, sessionId);
size_t size = tableDef.fColumns.size(); size_t size = tableDef.fColumns.size();
for (size_t i = 0; i < size; ++i) for (size_t i = 0; i < size; ++i)
{ {
fWriteEngine.dropColumn(txnID.id, fStartingColOID + 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(); DictionaryOIDList::const_iterator dictoid_iter = fDictionaryOIDList.begin();
while (dictoid_iter != fDictionaryOIDList.end()) while (dictoid_iter != fDictionaryOIDList.end())
{ {
DictOID dictOID = *dictoid_iter; DictOID dictOID = *dictoid_iter;
@@ -750,6 +827,7 @@ void CreateTableProcessor::rollBackCreateTable(const string& error, BRM::TxnID t
++dictoid_iter; ++dictoid_iter;
} }
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
} }

View File

@@ -43,7 +43,7 @@ class CreateTableProcessor : public DDLPackageProcessor
{ {
public: public:
CreateTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){} CreateTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a create table statement /** @brief process a create table statement
* *
* @param createTableStmt the CreateTableStatement * @param createTableStmt the CreateTableStatement

View File

@@ -52,20 +52,22 @@ using namespace messageqcpp;
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
bool DDLIndexPopulator::populateIndex(DDLPackageProcessor::DDLResult& result) bool DDLIndexPopulator::populateIndex(DDLPackageProcessor::DDLResult& result)
{ {
if (makeIndexStructs() ) if (makeIndexStructs() )
insertIndex(); insertIndex();
result = fResult; result = fResult;
return NO_ERROR != fResult.result; return NO_ERROR != fResult.result;
} }
bool DDLIndexPopulator::makeIndexStructs( ) bool DDLIndexPopulator::makeIndexStructs( )
{ {
CalpontSelectExecutionPlan csep; CalpontSelectExecutionPlan csep;
makeCsep(csep); makeCsep(csep);
ResourceManager *rm; ResourceManager* rm;
if (! fEC) if (! fEC)
{ {
fEC = DistributedEngineComm::instance(rm); fEC = DistributedEngineComm::instance(rm);
@@ -90,15 +92,18 @@ namespace ddlpackageprocessor
CalpontSystemCatalog::OID tableOid = (csc->tableRID ( tableName )).objnum; CalpontSystemCatalog::OID tableOid = (csc->tableRID ( tableName )).objnum;
CalpontSystemCatalog::NJLSysDataList sysDataList; CalpontSystemCatalog::NJLSysDataList sysDataList;
for (;;) for (;;)
{ {
TableBand band; TableBand band;
band = jbl->projectTable(tableOid); band = jbl->projectTable(tableOid);
if (band.getRowCount() == 0) if (band.getRowCount() == 0)
{ {
// No more bands, table is done // No more bands, table is done
break; break;
} }
band.convertToSysDataList(sysDataList, csc); band.convertToSysDataList(sysDataList, csc);
break; break;
} }
@@ -107,10 +112,12 @@ namespace ddlpackageprocessor
size_t i = 0; size_t i = 0;
vector<ColumnResult*>::const_iterator it; vector<ColumnResult*>::const_iterator it;
vector<int>::const_iterator oid_iter; vector<int>::const_iterator oid_iter;
for (it = sysDataList.begin(); it != sysDataList.end(); it++) for (it = sysDataList.begin(); it != sysDataList.end(); it++)
{ {
if (isUnique()) if (isUnique())
fUniqueColResultList.push_back(*it); fUniqueColResultList.push_back(*it);
for ( oid_iter = fOidList.begin(); oid_iter != fOidList.end(); oid_iter++ ) for ( oid_iter = fOidList.begin(); oid_iter != fOidList.end(); oid_iter++ )
{ {
if ( (*it)->ColumnOID() == *oid_iter ) if ( (*it)->ColumnOID() == *oid_iter )
@@ -119,17 +126,18 @@ namespace ddlpackageprocessor
addColumnData(*it, coltype, i); addColumnData(*it, coltype, i);
} }
} }
i++; i++;
} }
return (fIdxValueList.size() && NO_ERROR == fResult.result ); return (fIdxValueList.size() && NO_ERROR == fResult.result );
} }
void DDLIndexPopulator::makeCsep(CalpontSelectExecutionPlan& csep) void DDLIndexPopulator::makeCsep(CalpontSelectExecutionPlan& csep)
{ {
csep.sessionID(fSessionID); csep.sessionID(fSessionID);
@@ -146,6 +154,7 @@ namespace ddlpackageprocessor
string tableName(fTable.fSchema + "." + fTable.fName + "."); string tableName(fTable.fSchema + "." + fTable.fName + ".");
ColumnNameList::const_iterator cend = fColNames.end(); ColumnNameList::const_iterator cend = fColNames.end();
for (ColumnNameList::const_iterator cname = fColNames.begin(); cname != cend; ++cname) for (ColumnNameList::const_iterator cname = fColNames.begin(); cname != cend; ++cname)
{ {
string fullColName(tableName + *cname); string fullColName(tableName + *cname);
@@ -156,13 +165,14 @@ namespace ddlpackageprocessor
fOidList.push_back( oid ); fOidList.push_back( oid );
colMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(fullColName, srcp)); colMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(fullColName, srcp));
} }
csep.columnMap (colMap); csep.columnMap (colMap);
csep.returnedCols (colList); 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; IdxStruct idx;
idx.treeOid = fIdxOID.treeOID; idx.treeOid = fIdxOID.treeOID;
idx.listOid = fIdxOID.listOID; idx.listOid = fIdxOID.listOID;
@@ -179,6 +189,7 @@ namespace ddlpackageprocessor
{ {
if (1 == coltype.colWidth) idx.idxWidth = 1; if (1 == coltype.colWidth) idx.idxWidth = 1;
else idx.idxWidth = (coltype.colWidth > 4) ? 8 : 4; else idx.idxWidth = (coltype.colWidth > 4) ? 8 : 4;
idx.idxType = WR_CHAR; idx.idxType = WR_CHAR;
} }
else else
@@ -186,14 +197,14 @@ namespace ddlpackageprocessor
fIdxStructList.push_back(idx); fIdxStructList.push_back(idx);
return coltype; 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::IdxTupleList tupleList;
WriteEngine::IdxTuple tuple; WriteEngine::IdxTuple tuple;
for(int i=0;i < cr->dataCount(); ++i) for (int i = 0; i < cr->dataCount(); ++i)
{ {
WriteEngine::IdxTuple tuple ; WriteEngine::IdxTuple tuple ;
@@ -202,34 +213,36 @@ namespace ddlpackageprocessor
if (checkConstraints( tuple, colType, i, added)) if (checkConstraints( tuple, colType, i, added))
{ {
tupleList.push_back(tuple); tupleList.push_back(tuple);
if (! added ) if (! added )
fRidList.push_back(cr->GetRid(i)); fRidList.push_back(cr->GetRid(i));
} }
else else
break; break;
} }
if (tupleList.size()) if (tupleList.size())
fIdxValueList.push_back(tupleList); 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)) if (isDictionaryType(colType))
{ {
/* tuple.data = tokenizeData ( colType, cr->GetStringData(idx) );*/ /* tuple.data = tokenizeData ( colType, cr->GetStringData(idx) );*/
/* tuple.data = tokenizeData ( cr->GetRid(idx) );*/ /* tuple.data = tokenizeData ( cr->GetRid(idx) );*/
tuple.data = convertTokenData(cr->GetStringData(idx)); tuple.data = convertTokenData(cr->GetStringData(idx));
} }
else tuple.data = convertData( colType, cr, 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); string strData((size_t)fTOKENSIZE < data.length() ? data.substr(0, fTOKENSIZE) : data);
return strData; return strData;
} }
#if 0 #if 0
// Disabled this function as it is currently not used. // 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 // With iteration 17, the more common version of this getFileName() takes a
// partition and segment number in addition to an OID. openColumnFile // partition and segment number in addition to an OID. openColumnFile
// should perhaps be changed to use this updated version of getFileName(). // 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; FileOp fileOp;
char fileName[WriteEngine::FILE_NAME_SIZE]; char fileName[WriteEngine::FILE_NAME_SIZE];
if (WriteEngine::NO_ERROR == fileOp.getFileName(oid, fileName) ) if (WriteEngine::NO_ERROR == fileOp.getFileName(oid, fileName) )
{ {
fColumnFile.open(fileName); fColumnFile.open(fileName);
@@ -251,12 +265,12 @@ namespace ddlpackageprocessor
logError("Could not get column file name for data"); logError("Could not get column file name for data");
return false; return false;
} }
} }
#endif #endif
// Workaround to get original column token and not "retokenize" the string value // 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; int64_t byteOffset = rid * fTOKENSIZE;
ByteStream::byte inbuf[fTOKENSIZE]; ByteStream::byte inbuf[fTOKENSIZE];
fColumnFile.seekg(byteOffset, ios::beg); fColumnFile.seekg(byteOffset, ios::beg);
@@ -265,11 +279,11 @@ namespace ddlpackageprocessor
WriteEngine::Token token; WriteEngine::Token token;
memcpy(&token, inbuf, fTOKENSIZE); memcpy(&token, inbuf, fTOKENSIZE);
return token; 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; WriteEngine::DctnryTuple dictTuple;
if ( data.length() > (unsigned int)colType.colWidth ) if ( data.length() > (unsigned int)colType.colWidth )
@@ -285,29 +299,40 @@ namespace ddlpackageprocessor
dictTuple.sigValue = data.c_str(); dictTuple.sigValue = data.c_str();
dictTuple.sigSize = data.length(); dictTuple.sigSize = data.length();
int error = NO_ERROR; int error = NO_ERROR;
if ( NO_ERROR != (error = fWriteEngine->tokenize( fTxnID, dictStruct, dictTuple)) ) if ( NO_ERROR != (error = fWriteEngine->tokenize( fTxnID, dictStruct, dictTuple)) )
{ {
logError("Tokenization failed", error); logError("Tokenization failed", error);
} }
} }
return dictTuple.token; 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); uint64_t data = cr->GetData(idx);
switch( colType.colDataType )
switch ( colType.colDataType )
{ {
case CalpontSystemCatalog::BIT: case CalpontSystemCatalog::BIT:
case execplan::CalpontSystemCatalog::TINYINT: return *reinterpret_cast<char*>(&data); case execplan::CalpontSystemCatalog::TINYINT:
case execplan::CalpontSystemCatalog::SMALLINT: return *reinterpret_cast<short*>(&data); return *reinterpret_cast<char*>(&data);
case execplan::CalpontSystemCatalog::SMALLINT:
return *reinterpret_cast<short*>(&data);
case execplan::CalpontSystemCatalog::DATE: // @bug 375 case execplan::CalpontSystemCatalog::DATE: // @bug 375
case execplan::CalpontSystemCatalog::MEDINT: 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::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: case execplan::CalpontSystemCatalog::DECIMAL:
{ {
if (colType.colWidth <= CalpontSystemCatalog::FOUR_BYTE) return *reinterpret_cast<short*>(&data); if (colType.colWidth <= CalpontSystemCatalog::FOUR_BYTE) return *reinterpret_cast<short*>(&data);
@@ -317,47 +342,55 @@ namespace ddlpackageprocessor
else return *reinterpret_cast<long long*>(&data); else return *reinterpret_cast<long long*>(&data);
} }
case execplan::CalpontSystemCatalog::FLOAT: return *reinterpret_cast<float*>(&data); case execplan::CalpontSystemCatalog::FLOAT:
case execplan::CalpontSystemCatalog::DOUBLE: return *reinterpret_cast<double*>(&data); return *reinterpret_cast<float*>(&data);
case execplan::CalpontSystemCatalog::DOUBLE:
return *reinterpret_cast<double*>(&data);
case execplan::CalpontSystemCatalog::CHAR: case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::VARCHAR: case execplan::CalpontSystemCatalog::VARCHAR:
{ {
string strData(cr->GetStringData(idx) ); string strData(cr->GetStringData(idx) );
return *reinterpret_cast<string*>(&strData); return *reinterpret_cast<string*>(&strData);
} }
default: break;
default:
break;
} }
logError("Invalid column type"); logError("Invalid column type");
throw std::runtime_error("Invalid data"); throw std::runtime_error("Invalid data");
return *reinterpret_cast<long long*>(&data); return *reinterpret_cast<long long*>(&data);
} }
void DDLIndexPopulator::insertIndex( ) void DDLIndexPopulator::insertIndex( )
{ {
// @bug 359 use bulk load build // @bug 359 use bulk load build
int rc = (1 < fIdxStructList.size()) ? int rc = (1 < fIdxStructList.size()) ?
(void)0 (void)0
: (void)0; : (void)0;
if (rc) if (rc)
logError("Error inserting index values", 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 ) return ( (CalpontSystemCatalog::CHAR == colType.colDataType && 8 < colType.colWidth )
|| (CalpontSystemCatalog::VARCHAR == colType.colDataType && 7 < colType.colWidth ) || (CalpontSystemCatalog::VARCHAR == colType.colDataType && 7 < colType.colWidth )
|| (CalpontSystemCatalog::DECIMAL == colType.colDataType && 18 < colType.precision )); || (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: case DDL_INVALID_CONSTRAINT:
return true; return true;
@@ -366,6 +399,7 @@ namespace ddlpackageprocessor
case DDL_PRIMARY_KEY: case DDL_PRIMARY_KEY:
if ((size_t)column + 1 < fColNames.size() ) if ((size_t)column + 1 < fColNames.size() )
return true; return true;
return checkUnique( i, ctype ); return checkUnique( i, ctype );
case DDL_NOT_NULL: case DDL_NOT_NULL:
@@ -378,14 +412,15 @@ namespace ddlpackageprocessor
return true; //? return true; //?
} }
} }
// Check if the row of data at idx is already in fUniqueColResultList // 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) if (0 == idx)
return true; return true;
//Get row of data as each column result data at idx //Get row of data as each column result data at idx
size_t indexSize = fColNames.size(); size_t indexSize = fColNames.size();
vector <uint64_t> rowIntData(indexSize); vector <uint64_t> rowIntData(indexSize);
@@ -399,12 +434,15 @@ namespace ddlpackageprocessor
else else
rowIntData[i] = fUniqueColResultList[i]->GetData(idx); rowIntData[i] = fUniqueColResultList[i]->GetData(idx);
} }
//check if each value in the idx row is equal to each value in a previous row //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. // i is the row; j is the column.
bool unique = true; bool unique = true;
for (int i = 0; i < idx && unique; ++i) for (int i = 0; i < idx && unique; ++i)
{ {
bool equal = true; bool equal = true;
for (size_t j = 0; j < indexSize && equal; ++j) for (size_t j = 0; j < indexSize && equal; ++j)
{ {
if ( isStringType(colType.colDataType) ) if ( isStringType(colType.colDataType) )
@@ -416,25 +454,28 @@ namespace ddlpackageprocessor
equal = (static_cast<uint64_t>(fUniqueColResultList[j]->GetData(i)) == rowIntData[j]); equal = (static_cast<uint64_t>(fUniqueColResultList[j]->GetData(i)) == rowIntData[j]);
} }
} }
unique = ! equal; unique = ! equal;
} }
if (! unique) if (! unique)
{ {
stringstream ss; stringstream ss;
ss << idx; ss << idx;
logError("Unique Constraint violated on row: " + ss.str() ); logError("Unique Constraint violated on row: " + ss.str() );
} }
return unique; 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); any nullvalue = DDLNullValueForType(colType);
bool isNull = false; bool isNull = false;
switch( colType.colDataType ) switch ( colType.colDataType )
{ {
case CalpontSystemCatalog::BIT: case CalpontSystemCatalog::BIT:
break; break;
@@ -466,8 +507,10 @@ namespace ddlpackageprocessor
isNull = any_cast<long long>(data.data) == any_cast<long long>(nullvalue); isNull = any_cast<long long>(data.data) == any_cast<long long>(nullvalue);
else else
isNull = compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue)); isNull = compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue));
break; break;
} }
case execplan::CalpontSystemCatalog::FLOAT: case execplan::CalpontSystemCatalog::FLOAT:
isNull = any_cast<float>(data.data) == any_cast<float>(nullvalue); isNull = any_cast<float>(data.data) == any_cast<float>(nullvalue);
break; break;
@@ -494,9 +537,11 @@ namespace ddlpackageprocessor
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue); isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
else else
isNull = compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue)); isNull = compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue));
break; break;
} }
case execplan::CalpontSystemCatalog::VARCHAR: case execplan::CalpontSystemCatalog::VARCHAR:
{ {
if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE) if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE)
@@ -505,24 +550,29 @@ namespace ddlpackageprocessor
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue); isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
else else
isNull = compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue)); isNull = compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue));
break; break;
} }
default: default:
throw std::runtime_error("getNullValueForType: unkown column data type"); throw std::runtime_error("getNullValueForType: unkown column data type");
} }
if (isNull) if (isNull)
logError("Null value not allowed in index"); logError("Null value not allowed in index");
return ! isNull; return ! isNull;
} }
void DDLIndexPopulator::logError(const string& msg, int error) void DDLIndexPopulator::logError(const string& msg, int error)
{ {
Message::Args args; Message::Args args;
Message message(9); Message message(9);
args.add((string)__FILE__ + ": "); args.add((string)__FILE__ + ": ");
args.add(msg); args.add(msg);
if (error) if (error)
{ {
args.add("Error number: "); args.add("Error number: ");
@@ -533,7 +583,7 @@ namespace ddlpackageprocessor
fResult.result = DDLPackageProcessor::CREATE_ERROR; fResult.result = DDLPackageProcessor::CREATE_ERROR;
fResult.message = message; fResult.message = message;
} }
} //namespace } //namespace

View File

@@ -43,7 +43,8 @@
#include "joblistfactory.h" #include "joblistfactory.h"
namespace joblist { namespace joblist
{
class DistributedEngineComm; class DistributedEngineComm;
} }
@@ -85,20 +86,35 @@ public:
/** @brief Is it required to debug /** @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 /** @brief Get debug level
*/ */
const DDLPackageProcessor::DebugLevel getDebugLevel() const { return fDebugLevel; } const DDLPackageProcessor::DebugLevel getDebugLevel() const
{
return fDebugLevel;
}
/** @brief set distributedEngineComm pointer ( for /** @brief set distributedEngineComm pointer ( for
* loading index). * loading index).
*/ */
void setEngineComm(joblist::DistributedEngineComm* ec) { fEC = ec; } void setEngineComm(joblist::DistributedEngineComm* ec)
void setIdxOID(const DDLPackageProcessor::IndexOID& idxOID) { fIdxOID = idxOID; } {
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 /** @brief add data to the index from the statement
@@ -115,7 +131,7 @@ public:
void setConstraint(ddlpackage::DDL_CONSTRAINTS constraint); void setConstraint(ddlpackage::DDL_CONSTRAINTS constraint);
protected: protected:
/** @brief make the structures to update the index /** @brief make the structures to update the index
* *
@@ -148,7 +164,7 @@ public:
void insertIndex(); void insertIndex();
private: private:
DDLIndexPopulator(const DDLIndexPopulator& ); DDLIndexPopulator(const DDLIndexPopulator& );
void operator=(const DDLIndexPopulator& ); void operator=(const DDLIndexPopulator& );
/** @brief makes Calpont Select Execution Plan /** @brief makes Calpont Select Execution Plan
@@ -229,9 +245,15 @@ public:
*/ */
bool checkUnique(int i, const execplan::CalpontSystemCatalog::ColType& colType ); 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 /** @brief logs error and message
* *
* Updates result with message and sets it to CREATE_ERROR * Updates result with message and sets it to CREATE_ERROR

View File

@@ -86,7 +86,7 @@ DDLPackageProcessor::~DDLPackageProcessor()
delete fWEClient; 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) ColumnList& colList)
{ {
@@ -94,6 +94,7 @@ void DDLPackageProcessor::getColumnsForTable(uint32_t sessionID, std::string sc
tableName.schema = schema; tableName.schema = schema;
tableName.table = table; tableName.table = table;
std::string err; std::string err;
try try
{ {
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID); 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); const CalpontSystemCatalog::RIDList ridList = systemCatalogPtr->columnRIDs(tableName);
CalpontSystemCatalog::RIDList::const_iterator rid_iterator = ridList.begin(); CalpontSystemCatalog::RIDList::const_iterator rid_iterator = ridList.begin();
while (rid_iterator != ridList.end()) while (rid_iterator != ridList.end())
{ {
CalpontSystemCatalog::ROPair roPair = *rid_iterator; 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 // generated by Oracle. Use Oracle's PK name instead of making up our own
indexName = fPKName; indexName = fPKName;
break; break;
case ddlpackage::DDL_FOREIGN_KEY: case ddlpackage::DDL_FOREIGN_KEY:
case ddlpackage::DDL_REFERENCES: case ddlpackage::DDL_REFERENCES:
prefix = "fk_"; prefix = "fk_";
break; break;
case ddlpackage::DDL_UNIQUE: case ddlpackage::DDL_UNIQUE:
prefix = "uk_"; prefix = "uk_";
break; break;
case ddlpackage::DDL_CHECK: case ddlpackage::DDL_CHECK:
prefix = "ck_"; prefix = "ck_";
break; break;
case ddlpackage::DDL_NOT_NULL: case ddlpackage::DDL_NOT_NULL:
prefix = "nk_"; prefix = "nk_";
break; break;
@@ -287,6 +293,7 @@ std::string DDLPackageProcessor::buildTableConstraintName(const int oid,
if (type != ddlpackage::DDL_PRIMARY_KEY) if (type != ddlpackage::DDL_PRIMARY_KEY)
indexName = prefix + oid_number.str(); indexName = prefix + oid_number.str();
boost::to_lower(indexName); boost::to_lower(indexName);
return indexName; return indexName;
@@ -306,16 +313,20 @@ std::string DDLPackageProcessor::buildColumnConstraintName(const std::string& sc
case ddlpackage::DDL_PRIMARY_KEY: case ddlpackage::DDL_PRIMARY_KEY:
prefix = "pk_"; prefix = "pk_";
break; break;
case ddlpackage::DDL_FOREIGN_KEY: case ddlpackage::DDL_FOREIGN_KEY:
case ddlpackage::DDL_REFERENCES: case ddlpackage::DDL_REFERENCES:
prefix = "fk_"; prefix = "fk_";
break; break;
case ddlpackage::DDL_UNIQUE: case ddlpackage::DDL_UNIQUE:
prefix = "uk_"; prefix = "uk_";
break; break;
case ddlpackage::DDL_CHECK: case ddlpackage::DDL_CHECK:
prefix = "ck_"; prefix = "ck_";
break; break;
case ddlpackage::DDL_NOT_NULL: case ddlpackage::DDL_NOT_NULL:
prefix = "nk_"; prefix = "nk_";
break; break;
@@ -336,7 +347,7 @@ char DDLPackageProcessor::getConstraintCode(ddlpackage::DDL_CONSTRAINTS type)
{ {
char constraint_type; char constraint_type;
switch(type) switch (type)
{ {
case ddlpackage::DDL_PRIMARY_KEY: case ddlpackage::DDL_PRIMARY_KEY:
constraint_type = 'p'; constraint_type = 'p';
@@ -371,7 +382,8 @@ boost::any
DDLPackageProcessor::getNullValueForType(const execplan::CalpontSystemCatalog::ColType& colType) DDLPackageProcessor::getNullValueForType(const execplan::CalpontSystemCatalog::ColType& colType)
{ {
boost::any value; boost::any value;
switch(colType.colDataType)
switch (colType.colDataType)
{ {
case execplan::CalpontSystemCatalog::BIT: case execplan::CalpontSystemCatalog::BIT:
break; break;
@@ -431,6 +443,7 @@ DDLPackageProcessor::getNullValueForType(const execplan::CalpontSystemCatalog::C
} }
} }
break; break;
case execplan::CalpontSystemCatalog::FLOAT: case execplan::CalpontSystemCatalog::FLOAT:
case execplan::CalpontSystemCatalog::UFLOAT: case execplan::CalpontSystemCatalog::UFLOAT:
{ {
@@ -466,6 +479,7 @@ DDLPackageProcessor::getNullValueForType(const execplan::CalpontSystemCatalog::C
case execplan::CalpontSystemCatalog::CHAR: case execplan::CalpontSystemCatalog::CHAR:
{ {
std::string charnull; std::string charnull;
if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE) if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE)
{ {
//charnull = joblist::CHAR1NULL; //charnull = joblist::CHAR1NULL;
@@ -496,6 +510,7 @@ DDLPackageProcessor::getNullValueForType(const execplan::CalpontSystemCatalog::C
case execplan::CalpontSystemCatalog::VARCHAR: case execplan::CalpontSystemCatalog::VARCHAR:
{ {
std::string charnull; std::string charnull;
if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE) if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE)
{ {
//charnull = joblist::CHAR2NULL; //charnull = joblist::CHAR2NULL;
@@ -520,6 +535,7 @@ DDLPackageProcessor::getNullValueForType(const execplan::CalpontSystemCatalog::C
case execplan::CalpontSystemCatalog::VARBINARY: case execplan::CalpontSystemCatalog::VARBINARY:
{ {
std::string charnull; std::string charnull;
if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE) if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE)
{ {
//charnull = joblist::CHAR2NULL; //charnull = joblist::CHAR2NULL;
@@ -584,9 +600,10 @@ bool DDLPackageProcessor::isIndexConstraint(ddlpackage::DDL_CONSTRAINTS type)
{ {
bool indexConstraint = false; bool indexConstraint = false;
switch(type) switch (type)
{ {
case ddlpackage::DDL_PRIMARY_KEY: case ddlpackage::DDL_PRIMARY_KEY:
// @bug fix for #418, #416. Do not insert into sysindex // @bug fix for #418, #416. Do not insert into sysindex
//case ddlpackage::DDL_REFERENCES: //case ddlpackage::DDL_REFERENCES:
case ddlpackage::DDL_UNIQUE: case ddlpackage::DDL_UNIQUE:
@@ -605,7 +622,7 @@ void DDLPackageProcessor::getColumnReferences(ddlpackage::TableConstraintDef& ta
ddlpackage::ColumnNameList& columns) ddlpackage::ColumnNameList& columns)
{ {
switch(tableConstraint.fConstraintType) switch (tableConstraint.fConstraintType)
{ {
case ddlpackage::DDL_PRIMARY_KEY: case ddlpackage::DDL_PRIMARY_KEY:
{ {
@@ -647,6 +664,7 @@ boost::any DDLPackageProcessor::tokenizeData(execplan::CalpontSystemCatalog::SCN
std::string err("DDLPackageProcessor::tokenizeData "); std::string err("DDLPackageProcessor::tokenizeData ");
SUMMARY_INFO(err); SUMMARY_INFO(err);
boost::any value; boost::any value;
if (result.result == NO_ERROR) if (result.result == NO_ERROR)
{ {
@@ -680,11 +698,13 @@ boost::any DDLPackageProcessor::tokenizeData(execplan::CalpontSystemCatalog::SCN
dictTuple.sigValue = (unsigned char*)str.c_str(); dictTuple.sigValue = (unsigned char*)str.c_str();
dictTuple.sigSize = str.length(); dictTuple.sigSize = str.length();
int error = NO_ERROR; int error = NO_ERROR;
if (NO_ERROR != (error = fWriteEngine.tokenize(txnID, dictStruct, dictTuple, false))) // @bug 5572 HDFS tmp file if (NO_ERROR != (error = fWriteEngine.tokenize(txnID, dictStruct, dictTuple, false))) // @bug 5572 HDFS tmp file
{ {
WErrorCodes ec; WErrorCodes ec;
throw std::runtime_error("WE: Tokenization failed " + ec.errorString(error)); throw std::runtime_error("WE: Tokenization failed " + ec.errorString(error));
} }
WriteEngine::Token aToken = dictTuple.token; WriteEngine::Token aToken = dictTuple.token;
value = aToken; value = aToken;
@@ -695,13 +715,14 @@ boost::any DDLPackageProcessor::tokenizeData(execplan::CalpontSystemCatalog::SCN
err += ex.what(); err += ex.what();
throw std::runtime_error(err); throw std::runtime_error(err);
} }
catch(...) catch (...)
{ {
err += "Unknown exception caught, tokenizeData failed."; err += "Unknown exception caught, tokenizeData failed.";
throw std::runtime_error(err); throw std::runtime_error(err);
} }
} }
return value; return value;
} }
@@ -718,24 +739,30 @@ void DDLPackageProcessor::flushPrimprocCache(std::vector<execplan::CalpontSystem
LBIDRange_v::iterator it; LBIDRange_v::iterator it;
BRM::BlockList_t blockList; BRM::BlockList_t blockList;
execplan::CalpontSystemCatalog::SCN verID = 0; execplan::CalpontSystemCatalog::SCN verID = 0;
try try
{ {
while (iter != oidList.end()) while (iter != oidList.end())
{ {
WriteEngine::OID oid = *iter; WriteEngine::OID oid = *iter;
if (oid < 3000) if (oid < 3000)
{ {
++iter; ++iter;
continue; continue;
} }
//@Bug 1708 Flush primproc cache for associated lbids. //@Bug 1708 Flush primproc cache for associated lbids.
err = dbrm.lookup(oid, lbidRanges); err = dbrm.lookup(oid, lbidRanges);
if (err) if (err)
{ {
error = "DBRM lookUp error."; error = "DBRM lookUp error.";
throw std::runtime_error(error); throw std::runtime_error(error);
} }
blockList.clear(); blockList.clear();
for (it = lbidRanges.begin(); it != lbidRanges.end(); it++) for (it = lbidRanges.begin(); it != lbidRanges.end(); it++)
{ {
for (LBID_t lbid = it->start; lbid < (it->start + it->size); lbid++) 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)); blockList.push_back(BRM::LVP_t(lbid, verID));
} }
} }
//Need find a more efficient way to do this. //Need find a more efficient way to do this.
err = cacheutils::flushPrimProcBlocks (blockList); err = cacheutils::flushPrimProcBlocks (blockList);
//No need to handle this error as the error comes from timeout, not real error //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 << (ByteStream::byte)WE_SVR_WRITE_DROPFILES;
bytestream << uniqueId; bytestream << uniqueId;
bytestream << (uint32_t) oidList.size(); 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]; 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 rc = 0;
ByteStream::byte tmp8; ByteStream::byte tmp8;
string errorMsg; string errorMsg;
try {
try
{
fWEClient->write_to_all(bytestream); fWEClient->write_to_all(bytestream);
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
@@ -792,7 +823,9 @@ void DDLPackageProcessor::removeFiles(const uint64_t uniqueId, std::vector<execp
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
@@ -800,10 +833,13 @@ void DDLPackageProcessor::removeFiles(const uint64_t uniqueId, std::vector<execp
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = tmp8; rc = tmp8;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
@@ -823,7 +859,9 @@ void DDLPackageProcessor::removeFiles(const uint64_t uniqueId, std::vector<execp
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
throw std::runtime_error("Unknown error caught while deleting files."); throw std::runtime_error("Unknown error caught while deleting files.");
} }
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
if ( rc != 0) if ( rc != 0)
{ {
throw std::runtime_error(errorMsg); throw std::runtime_error(errorMsg);
@@ -844,6 +882,7 @@ void DDLPackageProcessor::createFiles(CalpontSystemCatalog::TableName aTableName
bytestream << (uint32_t)1; bytestream << (uint32_t)1;
bytestream << uniqueId; bytestream << uniqueId;
bytestream << numOids; bytestream << numOids;
for (unsigned col = 0; col < ridList.size(); col++) for (unsigned col = 0; col < ridList.size(); col++)
{ {
colType = systemCatalogPtr->colType(ridList[col].objnum); colType = systemCatalogPtr->colType(ridList[col].objnum);
@@ -853,6 +892,7 @@ void DDLPackageProcessor::createFiles(CalpontSystemCatalog::TableName aTableName
bytestream << (uint32_t) colType.colWidth; bytestream << (uint32_t) colType.colWidth;
bytestream << (uint16_t) useDBRoot; bytestream << (uint16_t) useDBRoot;
bytestream << (uint32_t) colType.compressionType; bytestream << (uint32_t) colType.compressionType;
if (colType.ddn.dictOID > 3000) if (colType.ddn.dictOID > 3000)
{ {
bytestream << (uint32_t) colType.ddn.dictOID; bytestream << (uint32_t) colType.ddn.dictOID;
@@ -863,11 +903,14 @@ void DDLPackageProcessor::createFiles(CalpontSystemCatalog::TableName aTableName
bytestream << (uint32_t) colType.compressionType; bytestream << (uint32_t) colType.compressionType;
} }
} }
ByteStream::byte rc = 0; ByteStream::byte rc = 0;
ByteStream::byte tmp8; ByteStream::byte tmp8;
string errorMsg; string errorMsg;
try {
OamCache * oamcache = OamCache::makeOamCache(); try
{
OamCache* oamcache = OamCache::makeOamCache();
boost::shared_ptr<std::map<int, int> > dbRootPMMap = oamcache->getDBRootToPMMap(); boost::shared_ptr<std::map<int, int> > dbRootPMMap = oamcache->getDBRootToPMMap();
int pmNum = (*dbRootPMMap)[useDBRoot]; int pmNum = (*dbRootPMMap)[useDBRoot];
@@ -877,6 +920,7 @@ void DDLPackageProcessor::createFiles(CalpontSystemCatalog::TableName aTableName
while (1) while (1)
{ {
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
@@ -884,12 +928,16 @@ void DDLPackageProcessor::createFiles(CalpontSystemCatalog::TableName aTableName
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = tmp8; rc = tmp8;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
} }
break; break;
} }
} }
@@ -904,7 +952,9 @@ void DDLPackageProcessor::createFiles(CalpontSystemCatalog::TableName aTableName
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
throw std::runtime_error("Unknown error caught while creating files."); throw std::runtime_error("Unknown error caught while creating files.");
} }
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
if ( rc != 0) if ( rc != 0)
throw std::runtime_error(errorMsg); 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++) for (uint32_t i = 0; i < oidList.size(); i++)
{ {
bs << (uint32_t)oidList[i]; bs << (uint32_t)oidList[i];
// add oid to LogicalPartition to form PartitionInfo // add oid to LogicalPartition to form PartitionInfo
for (partIt = partitions.begin(); partIt != partitions.end(); ++partIt) for (partIt = partitions.begin(); partIt != partitions.end(); ++partIt)
{ {
@@ -943,6 +994,7 @@ void DDLPackageProcessor::removePartitionFiles(std::vector<execplan::CalpontSyst
} }
bs << (uint32_t)partInfos.size(); bs << (uint32_t)partInfos.size();
for (uint32_t i = 0; i < partInfos.size(); i++) for (uint32_t i = 0; i < partInfos.size(); i++)
partInfos[i].serialize(bs); partInfos[i].serialize(bs);
@@ -955,6 +1007,7 @@ void DDLPackageProcessor::removePartitionFiles(std::vector<execplan::CalpontSyst
{ {
bsIn->restart(); bsIn->restart();
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
@@ -964,11 +1017,13 @@ void DDLPackageProcessor::removePartitionFiles(std::vector<execplan::CalpontSyst
else else
{ {
*bsIn >> rc; *bsIn >> rc;
if (rc != 0) if (rc != 0)
{ {
*bsIn >> errorMsg; *bsIn >> errorMsg;
break; break;
} }
pmCount--; pmCount--;
} }
} }
@@ -981,6 +1036,7 @@ void DDLPackageProcessor::removePartitionFiles(std::vector<execplan::CalpontSyst
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
throw std::runtime_error(errorMsg); throw std::runtime_error(errorMsg);
} }
//@Bug 2171,3327. Drop PrimProc fd cache //@Bug 2171,3327. Drop PrimProc fd cache
rc = cacheutils::dropPrimProcFdCache(); rc = cacheutils::dropPrimProcFdCache();
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
@@ -991,6 +1047,7 @@ void DDLPackageProcessor::removeExtents(std::vector<execplan::CalpontSystemCatal
SUMMARY_INFO("DDLPackageProcessor::removeExtents"); SUMMARY_INFO("DDLPackageProcessor::removeExtents");
int err = 0; int err = 0;
err = fDbrm->deleteOIDs(oidList); err = fDbrm->deleteOIDs(oidList);
if (err) if (err)
{ {
string errMsg; string errMsg;
@@ -1005,7 +1062,7 @@ void DDLPackageProcessor::createWriteDropLogFile(execplan::CalpontSystemCatalog:
{ {
SUMMARY_INFO("DDLPackageProcessor::createWriteDropLogFile"); SUMMARY_INFO("DDLPackageProcessor::createWriteDropLogFile");
//For shared nothing, the meta files are created under data1 with controllernode. //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(); std::string OAMParentModuleName = oamcache->getOAMParentModuleName();
OAMParentModuleName = OAMParentModuleName.substr(2, OAMParentModuleName.length()); OAMParentModuleName = OAMParentModuleName.substr(2, OAMParentModuleName.length());
int parentId = atoi(OAMParentModuleName.c_str()); int parentId = atoi(OAMParentModuleName.c_str());
@@ -1017,27 +1074,36 @@ void DDLPackageProcessor::createWriteDropLogFile(execplan::CalpontSystemCatalog:
bytestream << uniqueId; bytestream << uniqueId;
bytestream << (uint32_t)tableOid; bytestream << (uint32_t)tableOid;
bytestream << (uint32_t) oidList.size(); 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]; bytestream << (uint32_t)oidList[i];
} }
try {
try
{
fWEClient->write(bytestream, (uint32_t)parentId); fWEClient->write(bytestream, (uint32_t)parentId);
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while writting drop table Log"; errorMsg = "Lost connection to Write Engine Server while writting drop table Log";
break; break;
} }
else { else
{
*bsIn >> rc; *bsIn >> rc;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
} }
break; break;
} }
} }
@@ -1060,7 +1126,7 @@ void DDLPackageProcessor::createWriteDropLogFile(execplan::CalpontSystemCatalog:
void DDLPackageProcessor::deleteLogFile(LogFileType fileType, execplan::CalpontSystemCatalog::OID tableOid, uint64_t uniqueId) void DDLPackageProcessor::deleteLogFile(LogFileType fileType, execplan::CalpontSystemCatalog::OID tableOid, uint64_t uniqueId)
{ {
SUMMARY_INFO("DDLPackageProcessor::deleteLogFile"); SUMMARY_INFO("DDLPackageProcessor::deleteLogFile");
OamCache * oamcache = OamCache::makeOamCache(); OamCache* oamcache = OamCache::makeOamCache();
std::string OAMParentModuleName = oamcache->getOAMParentModuleName(); std::string OAMParentModuleName = oamcache->getOAMParentModuleName();
OAMParentModuleName = OAMParentModuleName.substr(2, OAMParentModuleName.length()); OAMParentModuleName = OAMParentModuleName.substr(2, OAMParentModuleName.length());
int parentId = atoi(OAMParentModuleName.c_str()); int parentId = atoi(OAMParentModuleName.c_str());
@@ -1073,23 +1139,31 @@ void DDLPackageProcessor::deleteLogFile(LogFileType fileType, execplan::CalpontS
bytestream << uniqueId; bytestream << uniqueId;
bytestream << (uint32_t) fileType; bytestream << (uint32_t) fileType;
bytestream << (uint32_t)tableOid; bytestream << (uint32_t)tableOid;
try {
try
{
fWEClient->write(bytestream, (uint32_t)parentId); fWEClient->write(bytestream, (uint32_t)parentId);
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while deleting DDL log"; errorMsg = "Lost connection to Write Engine Server while deleting DDL log";
break; break;
} }
else { else
{
*bsIn >> rc; *bsIn >> rc;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
} }
break; break;
} }
} }
@@ -1104,21 +1178,25 @@ void DDLPackageProcessor::deleteLogFile(LogFileType fileType, execplan::CalpontS
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Got unknown exception while deleting DDL Log." ; errorMsg = "Got unknown exception while deleting DDL Log." ;
} }
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
if ( rc != 0) if ( rc != 0)
{ {
throw std::runtime_error(errorMsg); 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"); SUMMARY_INFO("DDLPackageProcessor::fetchLogFile");
OamCache * oamcache = OamCache::makeOamCache(); OamCache* oamcache = OamCache::makeOamCache();
std::string OAMParentModuleName = oamcache->getOAMParentModuleName(); std::string OAMParentModuleName = oamcache->getOAMParentModuleName();
//Use a sensible default so that substr doesn't throw... //Use a sensible default so that substr doesn't throw...
if (OAMParentModuleName.empty()) if (OAMParentModuleName.empty())
OAMParentModuleName = "pm1"; OAMParentModuleName = "pm1";
int parentId = atoi(OAMParentModuleName.substr(2, OAMParentModuleName.length()).c_str()); int parentId = atoi(OAMParentModuleName.substr(2, OAMParentModuleName.length()).c_str());
ByteStream bytestream; ByteStream bytestream;
uint8_t rc = 0; uint8_t rc = 0;
@@ -1129,21 +1207,27 @@ void DDLPackageProcessor::fetchLogFile(TableLogInfo & tableLogInfos, uint64_t un
boost::shared_ptr<messageqcpp::ByteStream> bsIn; boost::shared_ptr<messageqcpp::ByteStream> bsIn;
bytestream << (ByteStream::byte)WE_SVR_FETCH_DDL_LOGS; bytestream << (ByteStream::byte)WE_SVR_FETCH_DDL_LOGS;
bytestream << uniqueId; bytestream << uniqueId;
try {
try
{
fWEClient->write(bytestream, (uint32_t)parentId); fWEClient->write(bytestream, (uint32_t)parentId);
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while deleting DDL log"; errorMsg = "Lost connection to Write Engine Server while deleting DDL log";
break; break;
} }
else { else
{
*bsIn >> rc; *bsIn >> rc;
*bsIn >> errorMsg; *bsIn >> errorMsg;
while ( bsIn->length() > 0 ) while ( bsIn->length() > 0 )
{ {
*bsIn >> tmp32; *bsIn >> tmp32;
@@ -1154,19 +1238,23 @@ void DDLPackageProcessor::fetchLogFile(TableLogInfo & tableLogInfos, uint64_t un
numOids = tmp32; numOids = tmp32;
OidList oidsList; OidList oidsList;
PartitionNums partitionNums; PartitionNums partitionNums;
for (unsigned i=0; i < numOids; i++)
for (unsigned i = 0; i < numOids; i++)
{ {
*bsIn >> tmp32; *bsIn >> tmp32;
oidsList.push_back(tmp32); oidsList.push_back(tmp32);
} }
*bsIn >> tmp32; *bsIn >> tmp32;
numPartitions = tmp32; numPartitions = tmp32;
BRM::LogicalPartition lp; BRM::LogicalPartition lp;
for (unsigned i=0; i < numPartitions; i++)
for (unsigned i = 0; i < numPartitions; i++)
{ {
lp.unserialize(*bsIn); lp.unserialize(*bsIn);
partitionNums.insert(lp); partitionNums.insert(lp);
} }
//build the tableloginfo //build the tableloginfo
LogInfo aLog; LogInfo aLog;
aLog.fileType = logFileType; aLog.fileType = logFileType;
@@ -1174,6 +1262,7 @@ void DDLPackageProcessor::fetchLogFile(TableLogInfo & tableLogInfos, uint64_t un
aLog.partitionNums = partitionNums; aLog.partitionNums = partitionNums;
tableLogInfos[tableOid] = aLog; tableLogInfos[tableOid] = aLog;
} }
break; break;
} }
} }
@@ -1188,7 +1277,9 @@ void DDLPackageProcessor::fetchLogFile(TableLogInfo & tableLogInfos, uint64_t un
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Got unknown exception while fetching DDL Log." ; errorMsg = "Got unknown exception while fetching DDL Log." ;
} }
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
if ( rc != 0) if ( rc != 0)
throw std::runtime_error(errorMsg); throw std::runtime_error(errorMsg);
@@ -1200,7 +1291,7 @@ void DDLPackageProcessor::createWritePartitionLogFile(execplan::CalpontSystemCat
{ {
SUMMARY_INFO("DDLPackageProcessor::createWritePartitionLogFile"); SUMMARY_INFO("DDLPackageProcessor::createWritePartitionLogFile");
fWEClient->addQueue(uniqueId); fWEClient->addQueue(uniqueId);
OamCache * oamcache = OamCache::makeOamCache(); OamCache* oamcache = OamCache::makeOamCache();
std::string OAMParentModuleName = oamcache->getOAMParentModuleName(); std::string OAMParentModuleName = oamcache->getOAMParentModuleName();
OAMParentModuleName = OAMParentModuleName.substr(2, OAMParentModuleName.length()); OAMParentModuleName = OAMParentModuleName.substr(2, OAMParentModuleName.length());
int parentId = atoi(OAMParentModuleName.c_str()); int parentId = atoi(OAMParentModuleName.c_str());
@@ -1218,27 +1309,36 @@ void DDLPackageProcessor::createWritePartitionLogFile(execplan::CalpontSystemCat
(*it).serialize(bytestream); (*it).serialize(bytestream);
bytestream << (uint32_t) oidList.size(); 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]; bytestream << (uint32_t)oidList[i];
} }
try {
try
{
fWEClient->write(bytestream, (uint32_t)parentId); fWEClient->write(bytestream, (uint32_t)parentId);
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while writing DDL drop partition log"; errorMsg = "Lost connection to Write Engine Server while writing DDL drop partition log";
break; break;
} }
else { else
{
*bsIn >> rc; *bsIn >> rc;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
} }
break; break;
} }
} }
@@ -1253,7 +1353,9 @@ void DDLPackageProcessor::createWritePartitionLogFile(execplan::CalpontSystemCat
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Got unknown exception while writting truncate Log." ; errorMsg = "Got unknown exception while writting truncate Log." ;
} }
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
if ( rc != 0) if ( rc != 0)
throw std::runtime_error(errorMsg); throw std::runtime_error(errorMsg);
} }
@@ -1262,7 +1364,7 @@ void DDLPackageProcessor::createWriteTruncateTableLogFile(execplan::CalpontSyste
{ {
SUMMARY_INFO("DDLPackageProcessor::createWriteTruncateTableLogFile"); SUMMARY_INFO("DDLPackageProcessor::createWriteTruncateTableLogFile");
//For shared nothing, the meta files are created under data1 with controllernode. //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(); std::string OAMParentModuleName = oamcache->getOAMParentModuleName();
OAMParentModuleName = OAMParentModuleName.substr(2, OAMParentModuleName.length()); OAMParentModuleName = OAMParentModuleName.substr(2, OAMParentModuleName.length());
int parentId = atoi(OAMParentModuleName.c_str()); int parentId = atoi(OAMParentModuleName.c_str());
@@ -1274,27 +1376,36 @@ void DDLPackageProcessor::createWriteTruncateTableLogFile(execplan::CalpontSyste
bytestream << uniqueId; bytestream << uniqueId;
bytestream << (uint32_t)tableOid; bytestream << (uint32_t)tableOid;
bytestream << (uint32_t) oidList.size(); 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]; bytestream << (uint32_t)oidList[i];
} }
try {
try
{
fWEClient->write(bytestream, (uint32_t)parentId); fWEClient->write(bytestream, (uint32_t)parentId);
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while writing truncate table log"; errorMsg = "Lost connection to Write Engine Server while writing truncate table log";
break; break;
} }
else { else
{
*bsIn >> rc; *bsIn >> rc;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
} }
break; break;
} }
} }
@@ -1320,17 +1431,20 @@ void DDLPackageProcessor::createOpenTruncateTableLogFile(execplan::CalpontSystem
SUMMARY_INFO("DDLPackageProcessor::createOpenTruncateTableLogFile"); SUMMARY_INFO("DDLPackageProcessor::createOpenTruncateTableLogFile");
//Build file name with tableOid. Currently, table oid is not returned and therefore not reused //Build file name with tableOid. Currently, table oid is not returned and therefore not reused
string prefix, error; string prefix, error;
config::Config *config = config::Config::makeConfig(); config::Config* config = config::Config::makeConfig();
prefix = config->getConfig("SystemConfig", "DBRMRoot"); prefix = config->getConfig("SystemConfig", "DBRMRoot");
if (prefix.length() == 0) {
if (prefix.length() == 0)
{
error = "Need a valid DBRMRoot entry in Calpont configuation file"; error = "Need a valid DBRMRoot entry in Calpont configuation file";
throw std::runtime_error(error); throw std::runtime_error(error);
} }
uint64_t pos = prefix.find_last_of ("/") ; uint64_t pos = prefix.find_last_of ("/") ;
if (pos != string::npos) 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 else
{ {
@@ -1338,6 +1452,7 @@ void DDLPackageProcessor::createOpenTruncateTableLogFile(execplan::CalpontSystem
throw std::runtime_error(error); throw std::runtime_error(error);
} }
std::ostringstream oss; std::ostringstream oss;
oss << tableOid; oss << tableOid;
fDDLLogFileName += "DDL_TRUNCATETABLE_Log_" + oss.str(); fDDLLogFileName += "DDL_TRUNCATETABLE_Log_" + oss.str();
@@ -1354,7 +1469,7 @@ void DDLPackageProcessor::removeIndexFiles(execplan::CalpontSystemCatalog::SCN t
DDLResult& result, DDLResult& result,
execplan::CalpontSystemCatalog::IndexOIDList& idxOIDList) execplan::CalpontSystemCatalog::IndexOIDList& idxOIDList)
{ {
/* SUMMARY_INFO("DDLPackageProcessor::removeIndexFiles"); /* SUMMARY_INFO("DDLPackageProcessor::removeIndexFiles");
if (result.result != NO_ERROR) if (result.result != NO_ERROR)
return; return;
@@ -1394,7 +1509,7 @@ void DDLPackageProcessor::removeIndexFiles(execplan::CalpontSystemCatalog::SCN t
error = "Unknown exception caught"; error = "Unknown exception caught";
throw std::runtime_error(error); throw std::runtime_error(error);
} }
*/ */
} }
@@ -1422,7 +1537,7 @@ void DDLPackageProcessor::updateSyscolumns(execplan::CalpontSystemCatalog::SCN t
colStructs.push_back(colStruct); colStructs.push_back(colStruct);
int error; int error;
std::string err; std::string err;
std::vector<void *> colOldValuesList1; std::vector<void*> colOldValuesList1;
try try
{ {
@@ -1455,12 +1570,15 @@ void DDLPackageProcessor::returnOIDs(execplan::CalpontSystemCatalog::RIDList& ri
CalpontSystemCatalog::ROPair roPair; CalpontSystemCatalog::ROPair roPair;
CalpontSystemCatalog::RIDList::const_iterator col_iter = ridList.begin(); CalpontSystemCatalog::RIDList::const_iterator col_iter = ridList.begin();
std::string err; std::string err;
try try
{ {
execplan::ObjectIDManager fObjectIDManager; execplan::ObjectIDManager fObjectIDManager;
while (col_iter != ridList.end()) while (col_iter != ridList.end())
{ {
roPair = *col_iter; roPair = *col_iter;
if (roPair.objnum < 3000) if (roPair.objnum < 3000)
{ {
++col_iter; ++col_iter;
@@ -1473,14 +1591,17 @@ void DDLPackageProcessor::returnOIDs(execplan::CalpontSystemCatalog::RIDList& ri
CalpontSystemCatalog::DictOID dictOID; CalpontSystemCatalog::DictOID dictOID;
CalpontSystemCatalog::DictOIDList::const_iterator dict_iter = dictOIDList.begin(); CalpontSystemCatalog::DictOIDList::const_iterator dict_iter = dictOIDList.begin();
while (dict_iter != dictOIDList.end()) while (dict_iter != dictOIDList.end())
{ {
dictOID = *dict_iter; dictOID = *dict_iter;
if (dictOID.dictOID < 3000) if (dictOID.dictOID < 3000)
{ {
++dict_iter; ++dict_iter;
continue; continue;
} }
fObjectIDManager.returnOID(dictOID.dictOID); fObjectIDManager.returnOID(dictOID.dictOID);
++dict_iter; ++dict_iter;
} }
@@ -1504,10 +1625,12 @@ void DDLPackageProcessor::findColumnData(uint32_t sessionID, execplan::CalpontSy
ColumnList columns; ColumnList columns;
ColumnList::const_iterator column_iterator; ColumnList::const_iterator column_iterator;
std::string err; std::string err;
try try
{ {
getColumnsForTable(sessionID, systableName.schema,systableName.table, columns); getColumnsForTable(sessionID, systableName.schema, systableName.table, columns);
column_iterator = columns.begin(); column_iterator = columns.begin();
while (column_iterator != columns.end()) while (column_iterator != columns.end())
{ {
sysCol = *column_iterator; sysCol = *column_iterator;
@@ -1517,6 +1640,7 @@ void DDLPackageProcessor::findColumnData(uint32_t sessionID, execplan::CalpontSy
{ {
break; break;
} }
++column_iterator; ++column_iterator;
} }
} }
@@ -1535,21 +1659,25 @@ void DDLPackageProcessor::findColumnData(uint32_t sessionID, execplan::CalpontSy
void DDLPackageProcessor::cleanString(string& s) void DDLPackageProcessor::cleanString(string& s)
{ {
string::size_type pos = s.find_first_not_of(" "); string::size_type pos = s.find_first_not_of(" ");
//stripe off space and ' or '' at beginning and end //stripe off space and ' or '' at beginning and end
if (pos < s.length()) 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()) if ((pos = s.find_last_of(" ")) < s.length())
{ {
s = s.substr(0, pos); s = s.substr(0, pos);
} }
} }
if (s[0] == '\'') if (s[0] == '\'')
{ {
s = s.substr(1, s.length()-2); s = s.substr(1, s.length() - 2);
if (s[0] == '\'') 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; int rc = 0;
ByteStream::byte tmp8; ByteStream::byte tmp8;
std::string errorMsg; std::string errorMsg;
while (1) while (1)
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = tmp8; rc = tmp8;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
@@ -1621,20 +1755,26 @@ int DDLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
fWEClient->write_to_all(bytestream); fWEClient->write_to_all(bytestream);
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
msgRecived = 0; msgRecived = 0;
while (1) while (1)
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = tmp8; rc = tmp8;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
@@ -1645,6 +1785,7 @@ int DDLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
} }
} }
} }
return rc; return rc;
} }

View File

@@ -88,9 +88,11 @@ public:
*/ */
enum ResultCode { NO_ERROR, CREATE_ERROR, ALTER_ERROR, DROP_ERROR, TRUNC_ERROR, 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, 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 */ NONE = 0, /** @brief No debug info */
SUMMARY = 1, /** @brief Summary level debug info */ SUMMARY = 1, /** @brief Summary level debug info */
DETAIL = 2, /** @brief A little detail debug info */ DETAIL = 2, /** @brief A little detail debug info */
@@ -166,9 +168,15 @@ public:
unsigned month : 4; unsigned month : 4;
unsigned year : 16; unsigned year : 16;
// NULL column value = 0xFFFFFFFE // 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 struct Date
{ {
int year : 16; int year : 16;
@@ -189,10 +197,18 @@ public:
unsigned month : 4; unsigned month : 4;
unsigned year : 16; unsigned year : 16;
// NULL column value = 0xFFFFFFFFFFFFFFFE // NULL column value = 0xFFFFFFFFFFFFFFFE
EXPORT dateTime( ) { year = 0xFFFF; month = 0xF; day = 0x3F; hour = 0x3F; minute = 0x3F; second = 0x3F; EXPORT dateTime( )
msecond = 0xFFFFE; } {
year = 0xFFFF;
month = 0xF;
day = 0x3F;
hour = 0x3F;
minute = 0x3F;
second = 0x3F;
msecond = 0xFFFFE;
}
}; };
/* /*
struct dateTime struct dateTime
{ {
int year : 16; int year : 16;
@@ -215,19 +231,34 @@ public:
struct NJLSysDataList struct NJLSysDataList
{ {
NJLSysDataVector sysDataVec; NJLSysDataVector sysDataVec;
EXPORT NJLSysDataList(){}; EXPORT NJLSysDataList() {};
EXPORT ~NJLSysDataList(); EXPORT ~NJLSysDataList();
NJLSysDataVector::const_iterator begin() {return sysDataVec.begin();} NJLSysDataVector::const_iterator begin()
NJLSysDataVector::const_iterator end() {return sysDataVec.end();} {
void push_back(execplan::ColumnResult* cr) {sysDataVec.push_back(cr);} return sysDataVec.begin();
unsigned int size() {return static_cast<unsigned int>(sysDataVec.size());} }
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) int findColumn(const execplan::CalpontSystemCatalog::OID& columnOID)
{ {
for(uint32_t i = 0; i < sysDataVec.size(); i++) { for (uint32_t i = 0; i < sysDataVec.size(); i++)
if(sysDataVec[i]->ColumnOID() == columnOID) { {
if (sysDataVec[i]->ColumnOID() == columnOID)
{
return i; return i;
} }
} }
return -1; return -1;
} }
}; };
@@ -250,28 +281,49 @@ public:
/** @brief Is it required to debug /** @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 /** @brief Get debug level
*/ */
const DebugLevel getDebugLevel() const { return fDebugLevel; } const DebugLevel getDebugLevel() const
{
return fDebugLevel;
}
/** @brief Set debug level /** @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 /** @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 /** @brief Get starting column oid that was allocated during table
* creation. * creation.
*/ */
int getStartingColumnOID() const { return fStartingColOID; } int getStartingColumnOID() const
{
return fStartingColOID;
}
/** @brief access and mutator of fPKName */ /** @brief access and mutator of fPKName */
const std::string PKName() const {return fPKName;} const std::string PKName() const
void PKName (const std::string PKName) {fPKName = PKName;} {
return fPKName;
}
void PKName (const std::string PKName)
{
fPKName = PKName;
}
/** @brief Flush primproc cache for associated lbids. /** @brief Flush primproc cache for associated lbids.
* *
* @param oidList the list of OIDs for * @param oidList the list of OIDs for
@@ -346,7 +398,7 @@ public:
/** @brief fetch log file infomation /** @brief fetch log file infomation
* *
*/ */
EXPORT void fetchLogFile(TableLogInfo & tableLogInfos, uint64_t uniqueId); EXPORT void fetchLogFile(TableLogInfo& tableLogInfos, uint64_t uniqueId);
BRM::TxnID fTxnid; BRM::TxnID fTxnid;
@@ -357,7 +409,7 @@ protected:
* @param table the table name * @param table the table name
* @param colList will contain the list of columns on return * @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 ); ColumnList& colList );
/** @brief convert parsed ddl data type to a system catalog data type /** @brief convert parsed ddl data type to a system catalog data type
@@ -452,9 +504,9 @@ protected:
* @param constraintList the table constrain list * @param constraintList the table constrain list
* @param qualifiedName the name of catalog, schema, object names * @param qualifiedName the name of catalog, schema, object names
*/ */
// void writeTableSysConstraintMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result, // void writeTableSysConstraintMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::TableConstraintDefList& constraintList, ddlpackage::QualifiedName& // ddlpackage::TableConstraintDefList& constraintList, ddlpackage::QualifiedName&
// qualifiedName, bool alterFlag=false ); // qualifiedName, bool alterFlag=false );
/** @brief write the table constraint meta data to the SYSCONSTRAINTCOL table /** @brief write the table constraint meta data to the SYSCONSTRAINTCOL table
* *
* @param txnID the transaction id * @param txnID the transaction id
@@ -462,9 +514,9 @@ protected:
* @param constraintList the table constrain list * @param constraintList the table constrain list
* @param qualifiedName the name of catalog, schema, object names * @param qualifiedName the name of catalog, schema, object names
*/ */
// void writeTableSysConstraintColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, // void writeTableSysConstraintColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
// const DDLResult& result, ddlpackage::TableConstraintDefList& constraintList, // const DDLResult& result, ddlpackage::TableConstraintDefList& constraintList,
// ddlpackage::QualifiedName& qualifiedName, bool alterFlag=false ); // ddlpackage::QualifiedName& qualifiedName, bool alterFlag=false );
/** @brief write the column constraint meta data to the SYSCONTRAINT table /** @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, // void writeColumnSysConstraintColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
// const DDLResult& result, ddlpackage::ColumnDefList& tableDefCols, // const DDLResult& result, ddlpackage::ColumnDefList& tableDefCols,
// ddlpackage::QualifiedName& qualifiedName); // ddlpackage::QualifiedName& qualifiedName);
/** @brief write the index meta data to the SYSINDEX table /** @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 * @param tableName the qualified name of the table whose constraints
* are to be removed * 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); // ddlpackage::QualifiedName& tableName);
/** @brief remove the constraint meta data from the SYSCONSTRAINT table /** @brief remove the constraint meta data from the SYSCONSTRAINT table
@@ -595,9 +647,9 @@ protected:
* @param result the result of the operation * @param result the result of the operation
* @param indexName the index name to be removed * @param indexName the index name to be removed
*/ */
// void removeSysIndexMetaDataForIndex(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, // void removeSysIndexMetaDataForIndex(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
// DDLResult& result, // DDLResult& result,
// execplan::CalpontSystemCatalog::IndexNameList& indexNameList); // execplan::CalpontSystemCatalog::IndexNameList& indexNameList);
/** @brief remove the column constraint meta data from the SYSCONSTRAINTCOL table /** @brief remove the column constraint meta data from the SYSCONSTRAINTCOL table
* *
@@ -643,7 +695,7 @@ protected:
* @param tableDefCols the table column definition list * @param tableDefCols the table column definition list
*/ */
void createColumnFiles(execplan::CalpontSystemCatalog::SCN txnID, const DDLResult& result, 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 /** @brief update the SYSCOLUMN table
* *
@@ -823,7 +875,7 @@ private:
template <class T> template <class T>
bool from_string(T& t, bool from_string(T& t,
const std::string& s, const std::string& s,
std::ios_base& (*f)(std::ios_base&)) std::ios_base & (*f)(std::ios_base&))
{ {
std::istringstream iss(s); std::istringstream iss(s);
return !(iss >> f >> t).fail(); return !(iss >> f >> t).fail();

View File

@@ -28,14 +28,15 @@
using namespace ddlpackage; using namespace ddlpackage;
namespace ddlpackageprocessor { namespace ddlpackageprocessor
{
DDLPackageProcessor* DDLPackageProcessorFactory:: DDLPackageProcessor* DDLPackageProcessorFactory::
makePackageProcessor(int packageType, ddlpackage::CalpontDDLPackage& cpackage) makePackageProcessor(int packageType, ddlpackage::CalpontDDLPackage& cpackage)
{ {
DDLPackageProcessor* ddlProcPtr = 0; DDLPackageProcessor* ddlProcPtr = 0;
switch( packageType ) switch ( packageType )
{ {
case DDL_CREATE: case DDL_CREATE:
ddlProcPtr = new CreatePackageProcessor(); ddlProcPtr = new CreatePackageProcessor();

View File

@@ -28,16 +28,18 @@
#include "ddlpackageprocessor.h" #include "ddlpackageprocessor.h"
namespace ddlpackageprocessor { namespace ddlpackageprocessor
{
/** @brief create a ddlPackageProcessor object from a CalpontddlPackage object /** @brief create a ddlPackageProcessor object from a CalpontddlPackage object
* *
*/ */
class DDLPackageProcessorFactory { class DDLPackageProcessorFactory
{
public: public:
/** @brief static ddlPackageProcessor constructor method /** @brief static ddlPackageProcessor constructor method
* *
* @param packageType the ddl Package type * @param packageType the ddl Package type
* @param cpackage the CalpontddlPackage from which the ddlPackageProcessor is constructed * @param cpackage the CalpontddlPackage from which the ddlPackageProcessor is constructed

View File

@@ -39,8 +39,8 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
CalpontSystemCatalog::IndexOID indexOID; CalpontSystemCatalog::IndexOID indexOID;
BRM::TxnID txnID; BRM::TxnID txnID;
txnID.id= fTxnid.id; txnID.id = fTxnid.id;
txnID.valid= fTxnid.valid; txnID.valid = fTxnid.valid;
DDLResult result; DDLResult result;
result.result = NO_ERROR; result.result = NO_ERROR;
@@ -60,6 +60,7 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
VERBOSE_INFO("Removing the SYSINDEX meta data"); VERBOSE_INFO("Removing the SYSINDEX meta data");
removeSysIndexMetaData(dropIndexStmt.fSessionID, txnID.id, result, *dropIndexStmt.fIndexName); removeSysIndexMetaData(dropIndexStmt.fSessionID, txnID.id, result, *dropIndexStmt.fIndexName);
if (result.result != NO_ERROR) if (result.result != NO_ERROR)
{ {
DETAIL_INFO("writeSysIndexMetaData failed"); DETAIL_INFO("writeSysIndexMetaData failed");
@@ -68,6 +69,7 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
VERBOSE_INFO("Removing the SYSINDEXCOL meta data"); VERBOSE_INFO("Removing the SYSINDEXCOL meta data");
removeSysIndexColMetaData(dropIndexStmt.fSessionID, txnID.id, result, *dropIndexStmt.fIndexName); removeSysIndexColMetaData(dropIndexStmt.fSessionID, txnID.id, result, *dropIndexStmt.fIndexName);
if (result.result != NO_ERROR) if (result.result != NO_ERROR)
{ {
DETAIL_INFO("writeSysIndexMetaData failed"); DETAIL_INFO("writeSysIndexMetaData failed");
@@ -76,7 +78,8 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
VERBOSE_INFO("Removing the index files"); 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) if (err)
{ {
DETAIL_INFO("WriteEngine dropIndex failed"); DETAIL_INFO("WriteEngine dropIndex failed");
@@ -88,11 +91,13 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
// register the changes // register the changes
err = fWriteEngine.commit( txnID.id ); err = fWriteEngine.commit( txnID.id );
if (err) if (err)
{ {
DETAIL_INFO("Failed to commit the drop index transaction"); DETAIL_INFO("Failed to commit the drop index transaction");
goto rollback; goto rollback;
} }
fSessionManager.committed(txnID); fSessionManager.committed(txnID);
//fObjectIDManager.returnOID(indexOID.objnum); //fObjectIDManager.returnOID(indexOID.objnum);
//fObjectIDManager.returnOID(indexOID.listOID); //fObjectIDManager.returnOID(indexOID.listOID);

View File

@@ -28,24 +28,24 @@
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
/** @brief specialization of a DDLPacakageProcessor /** @brief specialization of a DDLPacakageProcessor
* for interaction with the Write Engine to process * for interaction with the Write Engine to process
* drop index statements. * drop index statements.
*/ */
class DropIndexProcessor : public DDLPackageProcessor class DropIndexProcessor : public DDLPackageProcessor
{ {
public: public:
/** @brief process a drop index statement /** @brief process a drop index statement
* *
* @param dropIndexStmt the drop index statement * @param dropIndexStmt the drop index statement
*/ */
DDLResult processPackage(ddlpackage::DropIndexStatement& dropIndexStmt); DDLResult processPackage(ddlpackage::DropIndexStatement& dropIndexStmt);
protected: protected:
private: private:
}; };
} //namespace ddlpackageprocessor } //namespace ddlpackageprocessor
#endif //DROPINDEXPROCESSOR_H #endif //DROPINDEXPROCESSOR_H

View File

@@ -38,8 +38,8 @@ using namespace oam;
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
DropPartitionProcessor::DDLResult DropPartitionProcessor::processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt) DropPartitionProcessor::DDLResult DropPartitionProcessor::processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt)
{ {
SUMMARY_INFO("DropPartitionProcessor::processPackage"); SUMMARY_INFO("DropPartitionProcessor::processPackage");
DDLResult result; DDLResult result;
@@ -54,8 +54,9 @@ namespace ddlpackageprocessor
int rc = 0; int rc = 0;
rc = fDbrm->isReadWrite(); rc = fDbrm->isReadWrite();
BRM::TxnID txnID; BRM::TxnID txnID;
txnID.id= fTxnid.id; txnID.id = fTxnid.id;
txnID.valid= fTxnid.valid; txnID.valid = fTxnid.valid;
if (rc != 0 ) if (rc != 0 )
{ {
logging::Message::Args args; logging::Message::Args args;
@@ -80,7 +81,8 @@ namespace ddlpackageprocessor
uint64_t uniqueId = 0; uint64_t uniqueId = 0;
//Bug 5070. Added exception handling //Bug 5070. Added exception handling
try { try
{
uniqueId = fDbrm->getUnique64(); uniqueId = fDbrm->getUnique64();
} }
catch (std::exception& ex) catch (std::exception& ex)
@@ -106,7 +108,7 @@ namespace ddlpackageprocessor
return result; return result;
} }
string stmt = dropPartitionStmt.fSql + "|" + dropPartitionStmt.fTableName->fSchema +"|"; string stmt = dropPartitionStmt.fSql + "|" + dropPartitionStmt.fTableName->fSchema + "|";
SQLLogger logger(stmt, fDDLLoggingId, sessionID, txnID.id); SQLLogger logger(stmt, fDDLLoggingId, sessionID, txnID.id);
try try
@@ -119,22 +121,26 @@ namespace ddlpackageprocessor
tableName.schema = dropPartitionStmt.fTableName->fSchema; tableName.schema = dropPartitionStmt.fTableName->fSchema;
tableName.table = dropPartitionStmt.fTableName->fName; tableName.table = dropPartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID( tableName ); roPair = systemCatalogPtr->tableRID( tableName );
//@Bug 3054 check for system catalog //@Bug 3054 check for system catalog
if ( roPair.objnum < 3000 ) if ( roPair.objnum < 3000 )
{ {
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog."); throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
} }
int i = 0; int i = 0;
processID = ::getpid(); processID = ::getpid();
oam::OamCache * oamcache = OamCache::makeOamCache(); oam::OamCache* oamcache = OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds(); std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms; 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]); 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 ); uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
} }
catch (std::exception&) catch (std::exception&)
@@ -155,8 +161,8 @@ namespace ddlpackageprocessor
numTries = waitPeriod * 10; numTries = waitPeriod * 10;
struct timespec rm_ts; struct timespec rm_ts;
rm_ts.tv_sec = sleepTime/1000; rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime%1000 *1000000; rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++) for (; i < numTries; i++)
{ {
@@ -164,19 +170,22 @@ namespace ddlpackageprocessor
Sleep(rm_ts.tv_sec * 1000); Sleep(rm_ts.tv_sec * 1000);
#else #else
struct timespec abs_ts; struct timespec abs_ts;
do do
{ {
abs_ts.tv_sec = rm_ts.tv_sec; abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec; abs_ts.tv_nsec = rm_ts.tv_nsec;
} }
while(nanosleep(&abs_ts,&rm_ts) < 0); while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif #endif
// reset // reset
sessionID = dropPartitionStmt.fSessionID; sessionID = dropPartitionStmt.fSessionID;
txnID.id= fTxnid.id; txnID.id = fTxnid.id;
txnID.valid= fTxnid.valid; txnID.valid = fTxnid.valid;
processID = ::getpid(); processID = ::getpid();
processName = "DDLProc"; processName = "DDLProc";
try try
{ {
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING ); 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(processName);
args.add((uint64_t)processID); args.add((uint64_t)processID);
args.add((uint64_t)sessionID); 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); fSessionManager.rolledback(txnID);
return result; return result;
} }
@@ -225,12 +234,13 @@ namespace ddlpackageprocessor
dictOIDList = systemCatalogPtr->dictOIDs( userTableName ); dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format //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 ) if ( tableColRidList[i].objnum > 3000 )
oidList.push_back( tableColRidList[i].objnum ); 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 ) if ( dictOIDList[i].dictOID > 3000 )
oidList.push_back( dictOIDList[i].dictOID ); oidList.push_back( dictOIDList[i].dictOID );
@@ -239,7 +249,8 @@ namespace ddlpackageprocessor
//Mark the partition disabled from extent map //Mark the partition disabled from extent map
string emsg; string emsg;
rc = fDbrm->markPartitionForDeletion( oidList, dropPartitionStmt.fPartitions, 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_INVALID_OP_LAST_PARTITION &&
rc != BRM::ERR_NOT_EXIST_PARTITION) rc != BRM::ERR_NOT_EXIST_PARTITION)
{ {
@@ -262,6 +273,7 @@ namespace ddlpackageprocessor
} }
set<BRM::LogicalPartition>::iterator it; set<BRM::LogicalPartition>::iterator it;
for (it = dropPartitionStmt.fPartitions.begin(); it != dropPartitionStmt.fPartitions.end(); ++it) for (it = dropPartitionStmt.fPartitions.begin(); it != dropPartitionStmt.fPartitions.end(); ++it)
{ {
if (outOfServicePartitions.find(*it) != outOfServicePartitions.end()) if (outOfServicePartitions.find(*it) != outOfServicePartitions.end())
@@ -279,6 +291,7 @@ namespace ddlpackageprocessor
//Remove the partition from extent map //Remove the partition from extent map
emsg.clear(); emsg.clear();
rc = fDbrm->deletePartition( oidList, dropPartitionStmt.fPartitions, emsg); rc = fDbrm->deletePartition( oidList, dropPartitionStmt.fPartitions, emsg);
if ( rc != 0 ) if ( rc != 0 )
throw std::runtime_error(emsg); throw std::runtime_error(emsg);
} }
@@ -297,14 +310,19 @@ namespace ddlpackageprocessor
result.result = WARN_NO_PARTITION; result.result = WARN_NO_PARTITION;
else else
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = message; result.message = message;
try {
try
{
fDbrm->releaseTableLock(uniqueID); fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&) }
catch (std::exception&)
{ {
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
} }
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
@@ -322,32 +340,41 @@ namespace ddlpackageprocessor
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = message; result.message = message;
try {
try
{
fDbrm->releaseTableLock(uniqueID); fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&) }
catch (std::exception&)
{ {
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
} }
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
// Log the DDL statement
logging::logDDL(dropPartitionStmt.fSessionID, txnID.id, dropPartitionStmt.fSql, dropPartitionStmt.fOwner); // Log the DDL statement
//Remove the log file logging::logDDL(dropPartitionStmt.fSessionID, txnID.id, dropPartitionStmt.fSql, dropPartitionStmt.fOwner);
//release the transaction
try { //Remove the log file
fDbrm->releaseTableLock(uniqueID); //release the transaction
deleteLogFile(DROPPART_LOG, roPair.objnum, uniqueId); try
} catch (std::exception&) {
{ fDbrm->releaseTableLock(uniqueID);
result.result = DROP_ERROR; deleteLogFile(DROPPART_LOG, roPair.objnum, uniqueId);
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); }
fSessionManager.rolledback(txnID); catch (std::exception&)
return result; {
} result.result = DROP_ERROR;
fSessionManager.committed(txnID); result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
return result; fSessionManager.rolledback(txnID);
} return result;
}
fSessionManager.committed(txnID);
return result;
}
} }

View File

@@ -34,25 +34,25 @@
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
/** @brief specialization of a DDLPacakageProcessor /** @brief specialization of a DDLPacakageProcessor
* for interacting with the Write Engine to process * for interacting with the Write Engine to process
* drop table ddl statements. * drop table ddl statements.
*/ */
class DropPartitionProcessor : public DDLPackageProcessor class DropPartitionProcessor : public DDLPackageProcessor
{ {
public: public:
DropPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){} DropPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a drop table statement /** @brief process a drop table statement
* *
* @param dropTableStmt the drop table statement * @param dropTableStmt the drop table statement
*/ */
EXPORT DDLResult processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt); EXPORT DDLResult processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt);
protected: protected:
private: private:
}; };
} // namespace ddlpackageprocessor } // namespace ddlpackageprocessor
#undef EXPORT #undef EXPORT

View File

@@ -65,10 +65,11 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
VERBOSE_INFO("Getting current txnID"); VERBOSE_INFO("Getting current txnID");
ByteStream::byte rc = 0; ByteStream::byte rc = 0;
BRM::TxnID txnID; BRM::TxnID txnID;
txnID.id= fTxnid.id; txnID.id = fTxnid.id;
txnID.valid= fTxnid.valid; txnID.valid = fTxnid.valid;
int rc1 = 0; int rc1 = 0;
rc1= fDbrm->isReadWrite(); rc1 = fDbrm->isReadWrite();
if (rc1 != 0 ) if (rc1 != 0 )
{ {
Message::Args args; Message::Args args;
@@ -81,7 +82,7 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
return result; return result;
} }
string stmt = dropTableStmt.fSql + "|" + dropTableStmt.fTableName->fSchema +"|"; string stmt = dropTableStmt.fSql + "|" + dropTableStmt.fTableName->fSchema + "|";
SQLLogger logger(stmt, fDDLLoggingId, dropTableStmt.fSessionID, txnID.id); SQLLogger logger(stmt, fDDLLoggingId, dropTableStmt.fSessionID, txnID.id);
std::vector <CalpontSystemCatalog::OID> oidList; std::vector <CalpontSystemCatalog::OID> oidList;
@@ -91,8 +92,10 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
std::string errorMsg; std::string errorMsg;
ByteStream bytestream; ByteStream bytestream;
uint64_t uniqueId = 0; uint64_t uniqueId = 0;
//Bug 5070. Added exception handling //Bug 5070. Added exception handling
try { try
{
uniqueId = fDbrm->getUnique64(); uniqueId = fDbrm->getUnique64();
} }
catch (std::exception& ex) catch (std::exception& ex)
@@ -142,7 +145,7 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
{ {
roPair = systemCatalogPtr->tableRID(tableName); roPair = systemCatalogPtr->tableRID(tableName);
} }
catch (IDBExcept &ie) catch (IDBExcept& ie)
{ {
if (ie.errorCode() == ERR_TABLE_NOT_IN_CATALOG) if (ie.errorCode() == ERR_TABLE_NOT_IN_CATALOG)
{ {
@@ -179,12 +182,14 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
int i = 0; int i = 0;
std::vector<uint32_t> pms; 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]); pms.push_back((uint32_t)moduleIds[i]);
} }
try { try
{
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnid, BRM::LOADING ); tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnid, BRM::LOADING );
} }
catch (std::exception&) catch (std::exception&)
@@ -201,8 +206,8 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
numTries = waitPeriod * 10; numTries = waitPeriod * 10;
struct timespec rm_ts; struct timespec rm_ts;
rm_ts.tv_sec = sleepTime/1000; rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime%1000 *1000000; rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++) for (; i < numTries; i++)
{ {
@@ -210,14 +215,18 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
Sleep(rm_ts.tv_sec * 1000); Sleep(rm_ts.tv_sec * 1000);
#else #else
struct timespec abs_ts; struct timespec abs_ts;
do do
{ {
abs_ts.tv_sec = rm_ts.tv_sec; abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec; abs_ts.tv_nsec = rm_ts.tv_nsec;
} }
while(nanosleep(&abs_ts,&rm_ts) < 0); while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif #endif
try {
try
{
processID = ::getpid(); processID = ::getpid();
txnid = txnID.id; txnid = txnID.id;
sessionId = dropTableStmt.fSessionID;; sessionId = dropTableStmt.fSessionID;;
@@ -232,6 +241,7 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
if (tableLockId > 0) if (tableLockId > 0)
break; break;
} }
if (i >= numTries) //error out if (i >= numTries) //error out
{ {
Message::Args args; Message::Args args;
@@ -240,7 +250,7 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
args.add(processName); args.add(processName);
args.add((uint64_t)processID); args.add((uint64_t)processID);
args.add(sessionId); 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; Oam oam;
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format //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 ) if ( tableColRidList[i].objnum > 3000 )
oidList.push_back( tableColRidList[i].objnum ); 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 ) if ( dictOIDList[i].dictOID > 3000 )
oidList.push_back( dictOIDList[i].dictOID ); oidList.push_back( dictOIDList[i].dictOID );
@@ -279,7 +290,7 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
//get a unique number //get a unique number
VERBOSE_INFO("Removing the SYSTABLE meta data"); VERBOSE_INFO("Removing the SYSTABLE meta data");
//#ifdef IDB_DDL_DEBUG //#ifdef IDB_DDL_DEBUG
cout << fTxnid.id << " Removing the SYSTABLEs meta data" << endl; cout << fTxnid.id << " Removing the SYSTABLEs meta data" << endl;
//#endif //#endif
bytestream << (ByteStream::byte)WE_SVR_DELETE_SYSTABLE; bytestream << (ByteStream::byte)WE_SVR_DELETE_SYSTABLE;
bytestream << uniqueId; bytestream << uniqueId;
@@ -294,9 +305,10 @@ cout << fTxnid.id << " Removing the SYSTABLEs meta data" << endl;
uint16_t dbRoot; uint16_t dbRoot;
rc = fDbrm->getSysCatDBRoot(sysOid, dbRoot); rc = fDbrm->getSysCatDBRoot(sysOid, dbRoot);
if (rc != 0) if (rc != 0)
{ {
result.result =(ResultCode) rc; result.result = (ResultCode) rc;
Message::Args args; Message::Args args;
Message message(9); Message message(9);
args.add("Error while calling getSysCatDBRoot"); 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(); boost::shared_ptr<std::map<int, int> > dbRootPMMap = oamcache->getDBRootToPMMap();
pmNum = (*dbRootPMMap)[dbRoot]; pmNum = (*dbRootPMMap)[dbRoot];
try try
{ {
// #ifdef IDB_DDL_DEBUG // #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 //#endif
//cout << "deleting systable entries with txnid " << txnID.id << endl; //cout << "deleting systable entries with txnid " << txnID.id << endl;
fWEClient->write(bytestream, (uint32_t)pmNum); fWEClient->write(bytestream, (uint32_t)pmNum);
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES"; errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
break; break;
} }
else { else
{
*bsIn >> rc; *bsIn >> rc;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
} }
break; break;
} }
} }
@@ -338,7 +357,7 @@ cout << fTxnid.id << " Drop table sending WE_SVR_DELETE_SYSTABLES to pm " << pmN
catch (runtime_error& ex) //write error catch (runtime_error& ex) //write error
{ {
// #ifdef IDB_DDL_DEBUG // #ifdef IDB_DDL_DEBUG
cout << fTxnid.id << " Drop table got exception" << endl; cout << fTxnid.id << " Drop table got exception" << endl;
// #endif // #endif
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = ex.what(); errorMsg = ex.what();
@@ -347,7 +366,7 @@ cout << fTxnid.id << " Drop table got exception" << endl;
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
//#ifdef IDB_DDL_DEBUG //#ifdef IDB_DDL_DEBUG
cout << fTxnid.id << " Drop table got unknown exception" << endl; cout << fTxnid.id << " Drop table got unknown exception" << endl;
//#endif //#endif
} }
@@ -380,9 +399,10 @@ cout << fTxnid.id << " Drop table got unknown exception" << endl;
//Find out where syscolumn is //Find out where syscolumn is
sysOid = 1021; sysOid = 1021;
rc = fDbrm->getSysCatDBRoot(sysOid, dbRoot); rc = fDbrm->getSysCatDBRoot(sysOid, dbRoot);
if (rc != 0) if (rc != 0)
{ {
result.result =(ResultCode) rc; result.result = (ResultCode) rc;
Message::Args args; Message::Args args;
Message message(9); Message message(9);
args.add("Error while calling getSysCatDBRoot"); args.add("Error while calling getSysCatDBRoot");
@@ -394,27 +414,34 @@ cout << fTxnid.id << " Drop table got unknown exception" << endl;
} }
pmNum = (*dbRootPMMap)[dbRoot]; pmNum = (*dbRootPMMap)[dbRoot];
try try
{ {
//#ifdef IDB_DDL_DEBUG //#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 //#endif
fWEClient->write(bytestream, (unsigned)pmNum); fWEClient->write(bytestream, (unsigned)pmNum);
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES"; errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
break; break;
} }
else { else
{
*bsIn >> rc; *bsIn >> rc;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
} }
break; break;
} }
} }
@@ -422,7 +449,7 @@ cout << fTxnid.id << " Drop table sending WE_SVR_DELETE_SYSCOLUMN to pm " << pmN
catch (runtime_error& ex) //write error catch (runtime_error& ex) //write error
{ {
//#ifdef IDB_DDL_DEBUG //#ifdef IDB_DDL_DEBUG
cout << fTxnid.id << " Drop table got exception" << endl; cout << fTxnid.id << " Drop table got exception" << endl;
//#endif //#endif
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = ex.what(); errorMsg = ex.what();
@@ -431,7 +458,7 @@ cout << fTxnid.id << " Drop table got exception" << endl;
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
// #ifdef IDB_DDL_DEBUG // #ifdef IDB_DDL_DEBUG
cout << fTxnid.id << " Drop table got unknown exception" << endl; cout << fTxnid.id << " Drop table got unknown exception" << endl;
//#endif //#endif
} }
@@ -453,6 +480,7 @@ cout << fTxnid.id << " Drop table got unknown exception" << endl;
} }
rc = commitTransaction(uniqueId, txnID); rc = commitTransaction(uniqueId, txnID);
if (rc != 0) if (rc != 0)
{ {
cout << txnID.id << " rolledback transaction " << " and valid is " << txnID.valid << endl; 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("Drop table failed due to ");
args.add(ex.what()); args.add(ex.what());
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
try {
try
{
(void)fDbrm->releaseTableLock(tableLockId); (void)fDbrm->releaseTableLock(tableLockId);
} }
catch (std::exception&) catch (std::exception&)
{ {
args.add(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE)); args.add(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE));
} }
message.format( args ); message.format( args );
result.message = message; result.message = message;
fWEClient->removeQueue(uniqueId); 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("Drop table failed due to ");
args.add(errorMsg); args.add(errorMsg);
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
try {
try
{
(void)fDbrm->releaseTableLock(tableLockId); (void)fDbrm->releaseTableLock(tableLockId);
} }
catch (std::exception&) catch (std::exception&)
{ {
args.add(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE)); args.add(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE));
} }
message.format( args ); message.format( args );
result.message = message; result.message = message;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
return result; return result;
} }
try { try
{
(void)fDbrm->releaseTableLock(tableLockId); (void)fDbrm->releaseTableLock(tableLockId);
} }
catch (std::exception&) catch (std::exception&)
@@ -543,7 +578,8 @@ cout << fTxnid.id << " Drop table got unknown exception" << endl;
} }
//Save the oids to a file //Save the oids to a file
try { try
{
createWriteDropLogFile( roPair.objnum, uniqueId, oidList ); createWriteDropLogFile( roPair.objnum, uniqueId, oidList );
} }
catch (std::exception& ex) catch (std::exception& ex)
@@ -559,6 +595,7 @@ cout << fTxnid.id << " Drop table got unknown exception" << endl;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
return result; return result;
} }
// Bug 4208 Drop the PrimProcFDCache before droping the column files // Bug 4208 Drop the PrimProcFDCache before droping the column files
// FOr Windows, this ensures (most likely) that the column files have // FOr Windows, this ensures (most likely) that the column files have
// no open handles to hinder the deletion of the files. // 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 << (ByteStream::byte)WE_SVR_WRITE_DROPFILES;
bytestream << uniqueId; bytestream << uniqueId;
bytestream << (uint32_t) oidList.size(); 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]; bytestream << (uint32_t) oidList[i];
} }
//#ifdef IDB_DDL_DEBUG //#ifdef IDB_DDL_DEBUG
cout << fTxnid.id << " Drop table removing column files" << endl; cout << fTxnid.id << " Drop table removing column files" << endl;
//#endif //#endif
uint32_t msgRecived = 0; uint32_t msgRecived = 0;
try {
try
{
fWEClient->write_to_all(bytestream); fWEClient->write_to_all(bytestream);
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
ByteStream::byte tmp8; ByteStream::byte tmp8;
while (1) while (1)
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = tmp8; rc = tmp8;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
@@ -633,13 +680,14 @@ cout << fTxnid.id << " Drop table removing column files" << endl;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
return result; return result;
} }
//Drop PrimProc FD cache //Drop PrimProc FD cache
rc = cacheutils::dropPrimProcFdCache(); rc = cacheutils::dropPrimProcFdCache();
//Flush primProc cache //Flush primProc cache
rc = cacheutils::flushOIDsFromCache( oidList ); rc = cacheutils::flushOIDsFromCache( oidList );
//Delete extents from extent map //Delete extents from extent map
//#ifdef IDB_DDL_DEBUG //#ifdef IDB_DDL_DEBUG
cout << fTxnid.id << " Drop table deleteOIDs" << endl; cout << fTxnid.id << " Drop table deleteOIDs" << endl;
//#endif //#endif
rc = fDbrm->deleteOIDs(oidList); rc = fDbrm->deleteOIDs(oidList);
@@ -693,8 +741,9 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
int rc = 0; int rc = 0;
rc = fDbrm->isReadWrite(); rc = fDbrm->isReadWrite();
BRM::TxnID txnID; BRM::TxnID txnID;
txnID.id= fTxnid.id; txnID.id = fTxnid.id;
txnID.valid= fTxnid.valid; txnID.valid = fTxnid.valid;
if (rc != 0 ) if (rc != 0 )
{ {
Message::Args args; Message::Args args;
@@ -708,7 +757,7 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
} }
//@Bug 5765 log the schema. //@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); SQLLogger logger(stmt, fDDLLoggingId, truncTableStmt.fSessionID, txnID.id);
std::vector <CalpontSystemCatalog::OID> columnOidList; std::vector <CalpontSystemCatalog::OID> columnOidList;
@@ -724,8 +773,10 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
systemCatalogPtr->sessionID(truncTableStmt.fSessionID); systemCatalogPtr->sessionID(truncTableStmt.fSessionID);
CalpontSystemCatalog::TableInfo tableInfo; CalpontSystemCatalog::TableInfo tableInfo;
uint64_t uniqueId = 0; uint64_t uniqueId = 0;
//Bug 5070. Added exception handling //Bug 5070. Added exception handling
try { try
{
uniqueId = fDbrm->getUnique64(); uniqueId = fDbrm->getUnique64();
} }
catch (std::exception& ex) catch (std::exception& ex)
@@ -750,14 +801,16 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
fWEClient->addQueue(uniqueId); fWEClient->addQueue(uniqueId);
int pmNum = 1; int pmNum = 1;
boost::shared_ptr<messageqcpp::ByteStream> bsIn; boost::shared_ptr<messageqcpp::ByteStream> bsIn;
string errorMsg; string errorMsg;
uint32_t autoIncColOid = 0; uint32_t autoIncColOid = 0;
uint64_t tableLockId = 0; uint64_t tableLockId = 0;
OamCache * oamcache = OamCache::makeOamCache(); OamCache* oamcache = OamCache::makeOamCache();
std::vector<int> moduleIds = oamcache->getModuleIds(); std::vector<int> moduleIds = oamcache->getModuleIds();
try try
{ {
//check table lock //check table lock
@@ -771,11 +824,14 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
int i = 0; int i = 0;
std::vector<uint32_t> pms; 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]); pms.push_back((uint32_t)moduleIds[i]);
} }
try {
try
{
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnid, BRM::LOADING ); tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnid, BRM::LOADING );
} }
catch (std::exception&) catch (std::exception&)
@@ -792,8 +848,8 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
numTries = waitPeriod * 10; numTries = waitPeriod * 10;
struct timespec rm_ts; struct timespec rm_ts;
rm_ts.tv_sec = sleepTime/1000; rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime%1000 *1000000; rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++) for (; i < numTries; i++)
{ {
@@ -801,14 +857,18 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
Sleep(rm_ts.tv_sec * 1000); Sleep(rm_ts.tv_sec * 1000);
#else #else
struct timespec abs_ts; struct timespec abs_ts;
do do
{ {
abs_ts.tv_sec = rm_ts.tv_sec; abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec; abs_ts.tv_nsec = rm_ts.tv_nsec;
} }
while(nanosleep(&abs_ts,&rm_ts) < 0); while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif #endif
try {
try
{
processID = ::getpid(); processID = ::getpid();
txnid = txnID.id; txnid = txnID.id;
sessionId = truncTableStmt.fSessionID; sessionId = truncTableStmt.fSessionID;
@@ -823,15 +883,17 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
if (tableLockId > 0) if (tableLockId > 0)
break; break;
} }
if (i >= numTries) //error out if (i >= numTries) //error out
{ {
Message::Args args; Message::Args args;
args.add(processName); args.add(processName);
args.add((uint64_t)processID); args.add((uint64_t)processID);
args.add(sessionId); 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; CalpontSystemCatalog::TableName userTableName;
userTableName.schema = truncTableStmt.fTableName->fSchema; userTableName.schema = truncTableStmt.fTableName->fSchema;
userTableName.table = truncTableStmt.fTableName->fName; userTableName.table = truncTableStmt.fTableName->fName;
@@ -839,7 +901,8 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
tableColRidList = systemCatalogPtr->columnRIDs( userTableName ); tableColRidList = systemCatalogPtr->columnRIDs( userTableName );
dictOIDList = systemCatalogPtr->dictOIDs( 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 ) if ( tableColRidList[i].objnum > 3000 )
{ {
@@ -847,11 +910,13 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
allOidList.push_back( tableColRidList[i].objnum ); 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 ) if ( dictOIDList[i].dictOID > 3000 )
allOidList.push_back( dictOIDList[i].dictOID ); allOidList.push_back( dictOIDList[i].dictOID );
} }
//Check whether the table has autoincrement column //Check whether the table has autoincrement column
tableInfo = systemCatalogPtr->tableInfo(userTableName); tableInfo = systemCatalogPtr->tableInfo(userTableName);
} }
@@ -865,13 +930,16 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
args.add( ex.what() ); args.add( ex.what() );
args.add(""); args.add("");
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
try {
try
{
(void)fDbrm->releaseTableLock(tableLockId); (void)fDbrm->releaseTableLock(tableLockId);
} }
catch (std::exception&) catch (std::exception&)
{ {
args.add(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE)); args.add(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE));
} }
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
message.format( args ); message.format( args );
@@ -888,13 +956,16 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
args.add("Truncate table failed: "); args.add("Truncate table failed: ");
args.add( "encountered unkown exception" ); args.add( "encountered unkown exception" );
args.add(""); args.add("");
try {
try
{
(void)fDbrm->releaseTableLock(tableLockId); (void)fDbrm->releaseTableLock(tableLockId);
} }
catch (std::exception&) catch (std::exception&)
{ {
args.add(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE)); args.add(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE));
} }
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
message.format( args ); message.format( args );
@@ -904,7 +975,8 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
} }
//Save the oids to a file //Save the oids to a file
try { try
{
createWriteTruncateTableLogFile( roPair.objnum, uniqueId, allOidList); createWriteTruncateTableLogFile( roPair.objnum, uniqueId, allOidList);
} }
catch (std::exception& ex) catch (std::exception& ex)
@@ -916,11 +988,14 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
message.format( args ); message.format( args );
//@bug 4515 Release the tablelock as nothing has done to this table. //@bug 4515 Release the tablelock as nothing has done to this table.
try { try
{
(void)fDbrm->releaseTableLock(tableLockId); (void)fDbrm->releaseTableLock(tableLockId);
} }
catch (std::exception&) {} catch (std::exception&) {}
result.result = TRUNC_ERROR; result.result = TRUNC_ERROR;
result.message = message; result.message = message;
return result; return result;
@@ -932,9 +1007,11 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
// MCOL-66 The DBRM can't handle concurrent DDL // MCOL-66 The DBRM can't handle concurrent DDL
boost::mutex::scoped_lock lk(dbrmMutex); boost::mutex::scoped_lock lk(dbrmMutex);
try { try
{
//Disable extents first //Disable extents first
int rc1 = fDbrm->markAllPartitionForDeletion( allOidList); int rc1 = fDbrm->markAllPartitionForDeletion( allOidList);
if (rc1 != 0) if (rc1 != 0)
{ {
string errMsg; string errMsg;
@@ -951,13 +1028,16 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
bytestream << (ByteStream::byte)WE_SVR_WRITE_DROPFILES; bytestream << (ByteStream::byte)WE_SVR_WRITE_DROPFILES;
bytestream << uniqueId; bytestream << uniqueId;
bytestream << (uint32_t) allOidList.size(); 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]; bytestream << (uint32_t) allOidList[i];
} }
uint32_t msgRecived = 0; uint32_t msgRecived = 0;
try {
try
{
fWEClient->write_to_all(bytestream); fWEClient->write_to_all(bytestream);
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
@@ -966,17 +1046,22 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = tmp8; rc = tmp8;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
@@ -1018,6 +1103,7 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
deleteLogFile(TRUNCATE_LOG, roPair.objnum, uniqueId); deleteLogFile(TRUNCATE_LOG, roPair.objnum, uniqueId);
return result; return result;
} }
//Drop PrimProc FD cache //Drop PrimProc FD cache
rc = cacheutils::dropPrimProcFdCache(); rc = cacheutils::dropPrimProcFdCache();
//Flush primProc cache //Flush primProc cache
@@ -1063,8 +1149,10 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
for (unsigned col = 0; col < columnOidList.size(); col++) for (unsigned col = 0; col < columnOidList.size(); col++)
{ {
colType = systemCatalogPtr->colType(columnOidList[col]); colType = systemCatalogPtr->colType(columnOidList[col]);
if (colType.autoincrement) if (colType.autoincrement)
autoIncColOid = colType.columnOID; autoIncColOid = colType.columnOID;
bytestream << (uint32_t)columnOidList[col]; bytestream << (uint32_t)columnOidList[col];
bytestream << (uint8_t) colType.colDataType; bytestream << (uint8_t) colType.colDataType;
bytestream << (uint8_t) false; bytestream << (uint8_t) false;
@@ -1073,7 +1161,7 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
bytestream << (uint32_t) colType.compressionType; 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); colType = systemCatalogPtr->colTypeDct(dictOIDList[col].dictOID);
bytestream << (uint32_t) 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(); boost::shared_ptr<std::map<int, int> > dbRootPMMap = oamcache->getDBRootToPMMap();
pmNum = (*dbRootPMMap)[useDBRoot]; pmNum = (*dbRootPMMap)[useDBRoot];
try try
{ {
#ifdef IDB_DDL_DEBUG #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 #endif
fWEClient->write(bytestream, pmNum); fWEClient->write(bytestream, pmNum);
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES"; errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = tmp8; rc = tmp8;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
} }
break; break;
} }
} }
if (rc != 0) { if (rc != 0)
{
//drop the newly created files //drop the newly created files
bytestream.restart(); bytestream.restart();
bytestream << (ByteStream::byte) WE_SVR_WRITE_DROPFILES; bytestream << (ByteStream::byte) WE_SVR_WRITE_DROPFILES;
bytestream << uniqueId; bytestream << uniqueId;
bytestream << (uint32_t)(allOidList.size()); 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]); bytestream << (uint32_t)(allOidList[i]);
} }
fWEClient->write(bytestream, pmNum); fWEClient->write(bytestream, pmNum);
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
//rc = tmp8; //rc = tmp8;
break; break;
} }
} }
Message::Args args; Message::Args args;
Message message(1); Message message(1);
args.add( "Truncate table failed." ); 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"; errorMsg = "Lost connection to Write Engine Server";
} }
} }
#ifdef _MSC_VER #ifdef _MSC_VER
catch (std::exception&) catch (std::exception&)
{ {
//FIXME: Windows can't delete a file that's still open by another process //FIXME: Windows can't delete a file that's still open by another process
} }
#else #else
catch (std::exception& ex) catch (std::exception& ex)
{ {
@@ -1178,6 +1282,7 @@ cout << "Truncate table sending We_SVR_WRITE_CREATETABLEFILES to pm " << pmNum <
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
#endif #endif
catch ( ... ) catch ( ... )
{ {
@@ -1195,6 +1300,7 @@ cout << "Truncate table sending We_SVR_WRITE_CREATETABLEFILES to pm " << pmNum <
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
if (rc != 0) if (rc != 0)
{ {
rollBackTransaction( uniqueId, txnID, truncTableStmt.fSessionID); //What to do with the error code 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 //reset nextvalue to 1
WE_DDLCommandClient commandClient; WE_DDLCommandClient commandClient;
rc = commandClient.UpdateSyscolumnNextval(autoIncColOid,1); rc = commandClient.UpdateSyscolumnNextval(autoIncColOid, 1);
} }
// Log the DDL statement // Log the DDL statement
logDDL(truncTableStmt.fSessionID, txnID.id, truncTableStmt.fSql, truncTableStmt.fOwner); logDDL(truncTableStmt.fSessionID, txnID.id, truncTableStmt.fSql, truncTableStmt.fOwner);
try {
try
{
(void)fDbrm->releaseTableLock(tableLockId); (void)fDbrm->releaseTableLock(tableLockId);
} }
catch (std::exception&) catch (std::exception&)
@@ -1228,11 +1337,14 @@ cout << "Truncate table sending We_SVR_WRITE_CREATETABLEFILES to pm " << pmNum <
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
} }
//release the transaction //release the transaction
fSessionManager.committed(txnID); fSessionManager.committed(txnID);
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
//Remove the log file //Remove the log file
try { try
{
deleteLogFile(TRUNCATE_LOG, roPair.objnum, uniqueId); deleteLogFile(TRUNCATE_LOG, roPair.objnum, uniqueId);
} }
catch ( ... ) catch ( ... )

View File

@@ -34,45 +34,45 @@
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
/** @brief specialization of a DDLPacakageProcessor /** @brief specialization of a DDLPacakageProcessor
* for interacting with the Write Engine to process * for interacting with the Write Engine to process
* drop table ddl statements. * drop table ddl statements.
*/ */
class DropTableProcessor : public DDLPackageProcessor class DropTableProcessor : public DDLPackageProcessor
{ {
public: public:
DropTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){} DropTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a drop table statement /** @brief process a drop table statement
* *
* @param dropTableStmt the drop table statement * @param dropTableStmt the drop table statement
*/ */
EXPORT DDLResult processPackage(ddlpackage::DropTableStatement& dropTableStmt); 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 * for interacting with the Write Engine to process
* truncate table ddl statements. * truncate table ddl statements.
*/ */
class TruncTableProcessor : public DDLPackageProcessor class TruncTableProcessor : public DDLPackageProcessor
{ {
public: public:
TruncTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){} TruncTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a truncate table statement /** @brief process a truncate table statement
* *
* @param truncTableStmt the truncate table statement * @param truncTableStmt the truncate table statement
*/ */
EXPORT DDLResult processPackage(ddlpackage::TruncTableStatement& truncTableStmt); EXPORT DDLResult processPackage(ddlpackage::TruncTableStatement& truncTableStmt);
protected: protected:
private: private:
}; };
} // namespace ddlpackageprocessor } // namespace ddlpackageprocessor

View File

@@ -45,11 +45,12 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
VERBOSE_INFO(markPartitionStmt); VERBOSE_INFO(markPartitionStmt);
BRM::TxnID txnID; BRM::TxnID txnID;
txnID.id= fTxnid.id; txnID.id = fTxnid.id;
txnID.valid= fTxnid.valid; txnID.valid = fTxnid.valid;
int rc = 0; int rc = 0;
rc = fDbrm->isReadWrite(); rc = fDbrm->isReadWrite();
if (rc != 0 ) if (rc != 0 )
{ {
logging::Message::Args args; logging::Message::Args args;
@@ -61,12 +62,13 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
std::vector <CalpontSystemCatalog::OID> oidList; std::vector <CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList; CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList; CalpontSystemCatalog::DictOIDList dictOIDList;
std::string processName("DDLProc"); 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); SQLLogger logger(stmt, fDDLLoggingId, markPartitionStmt.fSessionID, txnID.id);
uint32_t processID = 0; uint32_t processID = 0;
@@ -84,22 +86,26 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
tableName.schema = markPartitionStmt.fTableName->fSchema; tableName.schema = markPartitionStmt.fTableName->fSchema;
tableName.table = markPartitionStmt.fTableName->fName; tableName.table = markPartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID( tableName ); roPair = systemCatalogPtr->tableRID( tableName );
//@Bug 3054 check for system catalog //@Bug 3054 check for system catalog
if ( roPair.objnum < 3000 ) if ( roPair.objnum < 3000 )
{ {
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog."); throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
} }
int i = 0; int i = 0;
processID = ::getpid(); processID = ::getpid();
oam::OamCache * oamcache = OamCache::makeOamCache(); oam::OamCache* oamcache = OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds(); std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms; 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]); 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 ); uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
} }
catch (std::exception&) catch (std::exception&)
@@ -119,8 +125,8 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
numTries = waitPeriod * 10; numTries = waitPeriod * 10;
struct timespec rm_ts; struct timespec rm_ts;
rm_ts.tv_sec = sleepTime/1000; rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime%1000 *1000000; rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++) for (; i < numTries; i++)
{ {
@@ -128,21 +134,24 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
Sleep(rm_ts.tv_sec * 1000); Sleep(rm_ts.tv_sec * 1000);
#else #else
struct timespec abs_ts; struct timespec abs_ts;
do do
{ {
abs_ts.tv_sec = rm_ts.tv_sec; abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec; abs_ts.tv_nsec = rm_ts.tv_nsec;
} }
while(nanosleep(&abs_ts,&rm_ts) < 0); while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif #endif
// reset // reset
sessionID = markPartitionStmt.fSessionID; sessionID = markPartitionStmt.fSessionID;
txnID.id= fTxnid.id; txnID.id = fTxnid.id;
txnID.valid= fTxnid.valid; txnID.valid = fTxnid.valid;
processID = ::getpid(); processID = ::getpid();
processName = "DDLProc"; processName = "DDLProc";
try { try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING ); uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
} }
catch (std::exception&) catch (std::exception&)
@@ -164,7 +173,7 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
args.add(processName); args.add(processName);
args.add((uint64_t)processID); args.add((uint64_t)processID);
args.add((uint64_t)sessionID); 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); fSessionManager.rolledback(txnID);
return result; return result;
} }
@@ -186,12 +195,13 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
dictOIDList = systemCatalogPtr->dictOIDs( userTableName ); dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format //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 ) if ( tableColRidList[i].objnum > 3000 )
oidList.push_back( tableColRidList[i].objnum ); 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 ) if ( dictOIDList[i].dictOID > 3000 )
oidList.push_back( dictOIDList[i].dictOID ); oidList.push_back( dictOIDList[i].dictOID );
@@ -200,6 +210,7 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
//Remove the partition from extent map //Remove the partition from extent map
string emsg; string emsg;
rc = fDbrm->markPartitionForDeletion( oidList, markPartitionStmt.fPartitions, emsg); rc = fDbrm->markPartitionForDeletion( oidList, markPartitionStmt.fPartitions, emsg);
if ( rc != 0 ) if ( rc != 0 )
{ {
throw std::runtime_error(emsg); throw std::runtime_error(emsg);
@@ -221,13 +232,17 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = message; result.message = message;
try {
try
{
fDbrm->releaseTableLock(uniqueID); fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&) }
catch (std::exception&)
{ {
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
} }
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
@@ -245,27 +260,36 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = message; result.message = message;
try {
try
{
fDbrm->releaseTableLock(uniqueID); fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&) }
catch (std::exception&)
{ {
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
} }
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
// Log the DDL statement // Log the DDL statement
logging::logDDL(markPartitionStmt.fSessionID, 0, markPartitionStmt.fSql, markPartitionStmt.fOwner); logging::logDDL(markPartitionStmt.fSessionID, 0, markPartitionStmt.fSql, markPartitionStmt.fOwner);
try {
try
{
fDbrm->releaseTableLock(uniqueID); fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&) }
catch (std::exception&)
{ {
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
fSessionManager.committed(txnID); fSessionManager.committed(txnID);
return result; return result;
} }

View File

@@ -42,7 +42,7 @@ namespace ddlpackageprocessor
class MarkPartitionProcessor : public DDLPackageProcessor class MarkPartitionProcessor : public DDLPackageProcessor
{ {
public: public:
MarkPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){} MarkPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a create table statement /** @brief process a create table statement
* *
* @param createTableStmt the CreateTableStatement * @param createTableStmt the CreateTableStatement

View File

@@ -63,7 +63,7 @@ class PopulateIndexTest
public: public:
PopulateIndexTest(DistributedEngineComm* ec) : fEC(ec) { } PopulateIndexTest(DistributedEngineComm* ec) : fEC(ec) { }
DistributedEngineComm *fEC; DistributedEngineComm* fEC;
void test_createindex() void test_createindex()
{ {
@@ -73,9 +73,10 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
cout << "Parser succeeded." << endl; cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl; cout << ptree.fList.size() << " " << "SQL statements" << endl;
@@ -85,7 +86,7 @@ public:
{ {
CreateIndexProcessor processor; CreateIndexProcessor processor;
processor.setDebugLevel(CreateIndexProcessor::VERBOSE); processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
CreateIndexProcessor::DDLResult result; CreateIndexProcessor::DDLResult result;
DISPLAY(stmt.fSessionID); DISPLAY(stmt.fSessionID);
@@ -93,7 +94,7 @@ public:
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
throw; throw;
} }
@@ -108,9 +109,10 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl; cout << ptree.fSqlText << endl;
try try
@@ -118,13 +120,13 @@ public:
CreateIndexProcessor processor; CreateIndexProcessor processor;
processor.setDebugLevel(CreateIndexProcessor::VERBOSE); processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
CreateIndexProcessor::DDLResult result; CreateIndexProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt)); result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
throw; throw;
} }
@@ -138,9 +140,10 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl; cout << ptree.fSqlText << endl;
try try
@@ -148,11 +151,11 @@ public:
CreateIndexProcessor processor; CreateIndexProcessor processor;
processor.setDebugLevel(CreateIndexProcessor::VERBOSE); processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
CreateIndexProcessor::DDLResult result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt)); CreateIndexProcessor::DDLResult result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
throw; throw;
} }
@@ -165,22 +168,24 @@ public:
cout << "Begining create table test: " << sqlbuf << endl; cout << "Begining create table test: " << sqlbuf << endl;
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl; cout << ptree.fSqlText << endl;
try try
{ {
CreateTableProcessor processor; CreateTableProcessor processor;
processor.setDebugLevel(CreateTableProcessor::VERBOSE); processor.setDebugLevel(CreateTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
CreateTableProcessor::DDLResult result; CreateTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<CreateTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<CreateTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
throw; throw;
} }
@@ -194,22 +199,24 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl; cout << ptree.fSqlText << endl;
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
throw; throw;
} }
@@ -225,22 +232,24 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl; cout << ptree.fSqlText << endl;
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
throw; throw;
} }
@@ -251,7 +260,7 @@ public:
}; };
int main( int argc, char **argv) int main( int argc, char** argv)
{ {
int DoAll = 0; int DoAll = 0;
int Do1 = 0; int Do1 = 0;
@@ -293,53 +302,54 @@ int main( int argc, char **argv)
cout << "Driver Test starting with " << argc << " parameters." << endl; 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; cout << "Arg " << i << ": " << argv[i] << endl;
} }
if (argc > 1) if (argc > 1)
{ {
if (strcmp(argv[1],"All") == 0) DoAll = 1; if (strcmp(argv[1], "All") == 0) DoAll = 1;
else if (strcmp(argv[1],"t1") == 0) Do1 = 1; else if (strcmp(argv[1], "t1") == 0) Do1 = 1;
else if (strcmp(argv[1],"t2") == 0) Do2 = 1; else if (strcmp(argv[1], "t2") == 0) Do2 = 1;
else if (strcmp(argv[1],"t3") == 0) Do3 = 1; else if (strcmp(argv[1], "t3") == 0) Do3 = 1;
else if (strcmp(argv[1],"t4") == 0) Do4 = 1; else if (strcmp(argv[1], "t4") == 0) Do4 = 1;
else if (strcmp(argv[1],"t5") == 0) Do5 = 1; else if (strcmp(argv[1], "t5") == 0) Do5 = 1;
else if (strcmp(argv[1],"t6") == 0) Do6 = 1; else if (strcmp(argv[1], "t6") == 0) Do6 = 1;
else if (strcmp(argv[1],"t7") == 0) Do7 = 1; else if (strcmp(argv[1], "t7") == 0) Do7 = 1;
else if (strcmp(argv[1],"t8") == 0) Do8 = 1; else if (strcmp(argv[1], "t8") == 0) Do8 = 1;
else if (strcmp(argv[1],"t9") == 0) Do9 = 1; else if (strcmp(argv[1], "t9") == 0) Do9 = 1;
else if (strcmp(argv[1],"t10") == 0) Do10 = 1; else if (strcmp(argv[1], "t10") == 0) Do10 = 1;
else if (strcmp(argv[1],"t11") == 0) Do11= 1; else if (strcmp(argv[1], "t11") == 0) Do11 = 1;
else if (strcmp(argv[1],"t12") == 0) Do12= 1; else if (strcmp(argv[1], "t12") == 0) Do12 = 1;
else if (strcmp(argv[1],"t13") == 0) Do13= 1; else if (strcmp(argv[1], "t13") == 0) Do13 = 1;
else if (strcmp(argv[1],"t14") == 0) Do14= 1; else if (strcmp(argv[1], "t14") == 0) Do14 = 1;
else if (strcmp(argv[1],"t15") == 0) Do15= 1; else if (strcmp(argv[1], "t15") == 0) Do15 = 1;
else if (strcmp(argv[1],"t16") == 0) Do16= 1; else if (strcmp(argv[1], "t16") == 0) Do16 = 1;
else if (strcmp(argv[1],"t17") == 0) Do17= 1; else if (strcmp(argv[1], "t17") == 0) Do17 = 1;
else if (strcmp(argv[1],"t18") == 0) Do18= 1; else if (strcmp(argv[1], "t18") == 0) Do18 = 1;
else if (strcmp(argv[1],"t19") == 0) Do19= 1; else if (strcmp(argv[1], "t19") == 0) Do19 = 1;
else if (strcmp(argv[1],"t20") == 0) Do20= 1; else if (strcmp(argv[1], "t20") == 0) Do20 = 1;
else if (strcmp(argv[1],"t21") == 0) Do21= 1; else if (strcmp(argv[1], "t21") == 0) Do21 = 1;
else if (strcmp(argv[1],"t22") == 0) Do22= 1; else if (strcmp(argv[1], "t22") == 0) Do22 = 1;
else if (strcmp(argv[1],"t23") == 0) Do23= 1; else if (strcmp(argv[1], "t23") == 0) Do23 = 1;
else if (strcmp(argv[1],"t24") == 0) Do24= 1; else if (strcmp(argv[1], "t24") == 0) Do24 = 1;
else if (strcmp(argv[1],"t25") == 0) Do25= 1; else if (strcmp(argv[1], "t25") == 0) Do25 = 1;
else if (strcmp(argv[1],"t26") == 0) Do26= 1; else if (strcmp(argv[1], "t26") == 0) Do26 = 1;
else if (strcmp(argv[1],"t27") == 0) Do27= 1; else if (strcmp(argv[1], "t27") == 0) Do27 = 1;
else if (strcmp(argv[1],"t28") == 0) Do28= 1; else if (strcmp(argv[1], "t28") == 0) Do28 = 1;
else if (strcmp(argv[1],"t29") == 0) Do29= 1; else if (strcmp(argv[1], "t29") == 0) Do29 = 1;
else if (strcmp(argv[1],"t30") == 0) Do30= 1; else if (strcmp(argv[1], "t30") == 0) Do30 = 1;
else if (strcmp(argv[1],"t31") == 0) Do31= 1; else if (strcmp(argv[1], "t31") == 0) Do31 = 1;
else if (strcmp(argv[1],"t32") == 0) Do32= 1; else if (strcmp(argv[1], "t32") == 0) Do32 = 1;
else if (strcmp(argv[1],"t33") == 0) Do33= 1; else if (strcmp(argv[1], "t33") == 0) Do33 = 1;
else if (strcmp(argv[1],"t34") == 0) Do34= 1; else if (strcmp(argv[1], "t34") == 0) Do34 = 1;
else if (strcmp(argv[1],"t35") == 0) Do35= 1; else if (strcmp(argv[1], "t35") == 0) Do35 = 1;
else if (strcmp(argv[1],"t36") == 0) Do35= 1; else if (strcmp(argv[1], "t36") == 0) Do35 = 1;
} }
PopulateIndexTest pit(DistributedEngineComm::instance()); PopulateIndexTest pit(DistributedEngineComm::instance());
boost::timer theTimer; boost::timer theTimer;
@@ -588,6 +598,7 @@ int main( int argc, char **argv)
cout << "t4" << endl; cout << "t4" << endl;
cout << endl; cout << endl;
} }
cout << "Create index test took :" << theTimer.elapsed() << " seconds to complete." << endl; cout << "Create index test took :" << theTimer.elapsed() << " seconds to complete." << endl;

View File

@@ -35,8 +35,8 @@ using namespace WriteEngine;
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
RestorePartitionProcessor::DDLResult RestorePartitionProcessor::processPackage(ddlpackage::RestorePartitionStatement& restorePartitionStmt) RestorePartitionProcessor::DDLResult RestorePartitionProcessor::processPackage(ddlpackage::RestorePartitionStatement& restorePartitionStmt)
{ {
SUMMARY_INFO("RestorePartitionProcessor::processPackage"); SUMMARY_INFO("RestorePartitionProcessor::processPackage");
DDLResult result; DDLResult result;
@@ -45,11 +45,12 @@ namespace ddlpackageprocessor
VERBOSE_INFO(restorePartitionStmt); VERBOSE_INFO(restorePartitionStmt);
BRM::TxnID txnID; BRM::TxnID txnID;
txnID.id= fTxnid.id; txnID.id = fTxnid.id;
txnID.valid= fTxnid.valid; txnID.valid = fTxnid.valid;
int rc = 0; int rc = 0;
rc = fDbrm->isReadWrite(); rc = fDbrm->isReadWrite();
if (rc != 0 ) if (rc != 0 )
{ {
logging::Message::Args args; logging::Message::Args args;
@@ -61,12 +62,13 @@ namespace ddlpackageprocessor
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
std::vector <CalpontSystemCatalog::OID> oidList; std::vector <CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList; CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList; CalpontSystemCatalog::DictOIDList dictOIDList;
std::string processName("DDLProc"); 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); SQLLogger logger(stmt, fDDLLoggingId, restorePartitionStmt.fSessionID, txnID.id);
uint32_t processID = 0; uint32_t processID = 0;
@@ -84,22 +86,26 @@ namespace ddlpackageprocessor
tableName.schema = restorePartitionStmt.fTableName->fSchema; tableName.schema = restorePartitionStmt.fTableName->fSchema;
tableName.table = restorePartitionStmt.fTableName->fName; tableName.table = restorePartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID( tableName ); roPair = systemCatalogPtr->tableRID( tableName );
//@Bug 3054 check for system catalog //@Bug 3054 check for system catalog
if ( roPair.objnum < 3000 ) if ( roPair.objnum < 3000 )
{ {
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog."); throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
} }
int i = 0; int i = 0;
processID = ::getpid(); processID = ::getpid();
oam::OamCache * oamcache = oam::OamCache::makeOamCache(); oam::OamCache* oamcache = oam::OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds(); std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms; 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]); 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 ); uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
} }
catch (std::exception&) catch (std::exception&)
@@ -119,8 +125,8 @@ namespace ddlpackageprocessor
numTries = waitPeriod * 10; numTries = waitPeriod * 10;
struct timespec rm_ts; struct timespec rm_ts;
rm_ts.tv_sec = sleepTime/1000; rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime%1000 *1000000; rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++) for (; i < numTries; i++)
{ {
@@ -128,21 +134,24 @@ namespace ddlpackageprocessor
Sleep(rm_ts.tv_sec * 1000); Sleep(rm_ts.tv_sec * 1000);
#else #else
struct timespec abs_ts; struct timespec abs_ts;
do do
{ {
abs_ts.tv_sec = rm_ts.tv_sec; abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec; abs_ts.tv_nsec = rm_ts.tv_nsec;
} }
while(nanosleep(&abs_ts,&rm_ts) < 0); while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif #endif
// reset // reset
sessionID = restorePartitionStmt.fSessionID; sessionID = restorePartitionStmt.fSessionID;
txnID.id= fTxnid.id; txnID.id = fTxnid.id;
txnID.valid= fTxnid.valid; txnID.valid = fTxnid.valid;
processID = ::getpid(); processID = ::getpid();
processName = "DDLProc"; processName = "DDLProc";
try { try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING ); uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
} }
catch (std::exception&) catch (std::exception&)
@@ -166,7 +175,7 @@ namespace ddlpackageprocessor
args.add(processName); args.add(processName);
args.add((uint64_t)processID); args.add((uint64_t)processID);
args.add((uint64_t)sessionID); 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); fSessionManager.rolledback(txnID);
return result; return result;
} }
@@ -188,12 +197,13 @@ namespace ddlpackageprocessor
dictOIDList = systemCatalogPtr->dictOIDs( userTableName ); dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format //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 ) if ( tableColRidList[i].objnum > 3000 )
oidList.push_back( tableColRidList[i].objnum ); 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 ) if ( dictOIDList[i].dictOID > 3000 )
oidList.push_back( dictOIDList[i].dictOID ); oidList.push_back( dictOIDList[i].dictOID );
@@ -202,6 +212,7 @@ namespace ddlpackageprocessor
//Remove the partition from extent map //Remove the partition from extent map
string emsg; string emsg;
rc = fDbrm->restorePartition( oidList, restorePartitionStmt.fPartitions, emsg); rc = fDbrm->restorePartition( oidList, restorePartitionStmt.fPartitions, emsg);
if ( rc != 0 ) if ( rc != 0 )
{ {
throw std::runtime_error(emsg); throw std::runtime_error(emsg);
@@ -221,13 +232,17 @@ namespace ddlpackageprocessor
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = message; result.message = message;
try {
try
{
fDbrm->releaseTableLock(uniqueID); fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&) }
catch (std::exception&)
{ {
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
} }
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
@@ -245,28 +260,37 @@ namespace ddlpackageprocessor
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = message; result.message = message;
try {
try
{
fDbrm->releaseTableLock(uniqueID); fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&) }
catch (std::exception&)
{ {
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
} }
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
// Log the DDL statement // Log the DDL statement
logging::logDDL(restorePartitionStmt.fSessionID, txnID.id, restorePartitionStmt.fSql, restorePartitionStmt.fOwner); logging::logDDL(restorePartitionStmt.fSessionID, txnID.id, restorePartitionStmt.fSql, restorePartitionStmt.fOwner);
try {
try
{
fDbrm->releaseTableLock(uniqueID); fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&) }
catch (std::exception&)
{ {
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
fSessionManager.committed(txnID); fSessionManager.committed(txnID);
return result; return result;
} }
} }

View File

@@ -34,25 +34,25 @@
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
/** @brief specialization of a DDLPacakageProcessor /** @brief specialization of a DDLPacakageProcessor
* for interacting with the Write Engine to process * for interacting with the Write Engine to process
* drop table ddl statements. * drop table ddl statements.
*/ */
class RestorePartitionProcessor : public DDLPackageProcessor class RestorePartitionProcessor : public DDLPackageProcessor
{ {
public: public:
RestorePartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){} RestorePartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a drop table statement /** @brief process a drop table statement
* *
* @param dropTableStmt the drop table statement * @param dropTableStmt the drop table statement
*/ */
EXPORT DDLResult processPackage(ddlpackage::RestorePartitionStatement& RestorePartitionStmt); EXPORT DDLResult processPackage(ddlpackage::RestorePartitionStatement& RestorePartitionStmt);
protected: protected:
private: private:
}; };
} // namespace ddlpackageprocessor } // namespace ddlpackageprocessor
#undef EXPORT #undef EXPORT

View File

@@ -404,55 +404,59 @@ public:
}; };
void destroySemaphores() void destroySemaphores()
{ {
key_t semkey; key_t semkey;
int sems, err; int sems, err;
semkey = 0x2149bdd2; semkey = 0x2149bdd2;
sems = semget(semkey, 2, 0666); sems = semget(semkey, 2, 0666);
if (sems != -1) if (sems != -1)
{ {
err = semctl(sems, 0, IPC_RMID); err = semctl(sems, 0, IPC_RMID);
if (err == -1) if (err == -1)
perror("tdriver: semctl"); perror("tdriver: semctl");
} }
} }
void destroyShmseg() void destroyShmseg()
{ {
key_t shmkey; key_t shmkey;
int shms, err; int shms, err;
shmkey = 0x2149bdd2; shmkey = 0x2149bdd2;
shms = shmget(shmkey, 0, 0666); shms = shmget(shmkey, 0, 0666);
if (shms != -1) if (shms != -1)
{ {
err = shmctl(shms, IPC_RMID, NULL); err = shmctl(shms, IPC_RMID, NULL);
if (err == -1 && errno != EINVAL) if (err == -1 && errno != EINVAL)
{ {
perror("tdriver: shmctl"); perror("tdriver: shmctl");
return; return;
} }
} }
} }
void setUp() void setUp()
{ {
destroySemaphores(); destroySemaphores();
destroyShmseg(); destroyShmseg();
unlink("/tmp/oidbitmap"); unlink("/tmp/oidbitmap");
SystemCatalogBuilder::build(); SystemCatalogBuilder::build();
} }
void tearDown() void tearDown()
{ {
destroySemaphores(); destroySemaphores();
destroyShmseg(); destroyShmseg();
unlink("/tmp/oidbitmap"); unlink("/tmp/oidbitmap");
} }
class DDLPackageProcessorTest : public CppUnit::TestFixture 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));"; std::string sqlbuf = "create table region( r_regionkey integer NOT NULL, r_name char(25) ,r_comment varchar(152));";
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
CreateTableProcessor processor; CreateTableProcessor processor;
processor.setDebugLevel(CreateTableProcessor::VERBOSE); processor.setDebugLevel(CreateTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
CreateTableProcessor::DDLResult result; CreateTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<CreateTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<CreateTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); 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) )"; 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; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
CreateTableProcessor processor; CreateTableProcessor processor;
processor.setDebugLevel(CreateTableProcessor::VERBOSE); processor.setDebugLevel(CreateTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
CreateTableStatement& ct = dynamic_cast<CreateTableStatement&>(stmt); CreateTableStatement& ct = dynamic_cast<CreateTableStatement&>(stmt);
@@ -548,12 +557,13 @@ public:
result = processor.processPackage(ct); result = processor.processPackage(ct);
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@@ -563,27 +573,29 @@ public:
std::string sqlbuf = "CREATE INDEX test_idx ON tpch.part (p_size)"; std::string sqlbuf = "CREATE INDEX test_idx ON tpch.part (p_size)";
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
CreateIndexProcessor processor; CreateIndexProcessor processor;
processor.setDebugLevel(CreateIndexProcessor::VERBOSE); processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
CreateIndexProcessor::DDLResult result; CreateIndexProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt)); result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@@ -593,27 +605,29 @@ public:
std::string sqlbuf = "CREATE UNIQUE INDEX test_idx ON tpch.part (p_mfgr)"; std::string sqlbuf = "CREATE UNIQUE INDEX test_idx ON tpch.part (p_mfgr)";
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
CreateIndexProcessor processor; CreateIndexProcessor processor;
processor.setDebugLevel(CreateIndexProcessor::VERBOSE); processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
CreateIndexProcessor::DDLResult result; CreateIndexProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt)); result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
void test_altertable_addacolumn() void test_altertable_addacolumn()
@@ -623,26 +637,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@@ -653,26 +670,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@@ -683,26 +703,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
void test_altertable_dropacolumn() void test_altertable_dropacolumn()
@@ -712,26 +735,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@@ -742,26 +768,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@@ -772,26 +801,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
void test_dropindex() void test_dropindex()
@@ -801,27 +833,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
DropIndexProcessor processor; DropIndexProcessor processor;
processor.setDebugLevel(DropIndexProcessor::VERBOSE); processor.setDebugLevel(DropIndexProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
DropIndexProcessor::DDLResult result; DropIndexProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<DropIndexStatement&>(stmt)); result = processor.processPackage(dynamic_cast<DropIndexStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
void test_altertable_renamecolumn() void test_altertable_renamecolumn()
@@ -831,26 +865,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@@ -862,26 +899,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
void test_altertable_addtableconstraint() void test_altertable_addtableconstraint()
@@ -891,26 +931,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@@ -921,26 +964,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@@ -951,26 +997,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
void test_altertable_dropcolumndefault() void test_altertable_dropcolumndefault()
@@ -980,26 +1029,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@@ -1010,26 +1062,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
AlterTableProcessor processor; AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE); processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result; AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@@ -1040,27 +1095,29 @@ public:
SqlParser parser; SqlParser parser;
parser.Parse(sqlbuf.c_str()); parser.Parse(sqlbuf.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ParseTree &ptree = parser.GetParseTree(); const ParseTree& ptree = parser.GetParseTree();
try try
{ {
DropTableProcessor processor; DropTableProcessor processor;
processor.setDebugLevel(DropTableProcessor::VERBOSE); processor.setDebugLevel(DropTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0]; SqlStatement& stmt = *ptree.fList[0];
DropTableProcessor::DDLResult result; DropTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<DropTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<DropTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
tearDown(); tearDown();
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@@ -1071,12 +1128,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DDLPackageProcessorTest );
#include <cppunit/extensions/TestFactoryRegistry.h> #include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h> #include <cppunit/ui/text/TestRunner.h>
int main( int argc, char **argv) int main( int argc, char** argv)
{ {
// Uncomment before running tests // Uncomment before running tests
//setUp(); //setUp();
CppUnit::TextUi::TestRunner runner; CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry(); CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() ); runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false ); bool wasSuccessful = runner.run( "", false );
return (wasSuccessful ? 0 : 1); return (wasSuccessful ? 0 : 1);

View File

@@ -50,22 +50,25 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackage(dmlpacka
std::string defaultSchema /*= ""*/) std::string defaultSchema /*= ""*/)
{ {
CalpontDMLPackage* packagePtr = 0; CalpontDMLPackage* packagePtr = 0;
try try
{ {
std::string dmlStatement = vpackage.get_DMLStatement(); std::string dmlStatement = vpackage.get_DMLStatement();
//@Bug 2680. DMLParser is not thread safe. //@Bug 2680. DMLParser is not thread safe.
boost::mutex::scoped_lock lk(fParserLock); boost::mutex::scoped_lock lk(fParserLock);
DMLParser parser; DMLParser parser;
if (defaultSchema.size()) if (defaultSchema.size())
{ {
parser.setDefaultSchema(defaultSchema); parser.setDefaultSchema(defaultSchema);
} }
parser.parse(dmlStatement.c_str()); parser.parse(dmlStatement.c_str());
if (parser.good()) if (parser.good())
{ {
const ParseTree &ptree = parser.getParseTree(); const ParseTree& ptree = parser.getParseTree();
SqlStatement* statementPtr = ptree[0]; SqlStatement* statementPtr = ptree[0];
int dmlStatementType = statementPtr->getStatementType(); int dmlStatementType = statementPtr->getStatementType();
@@ -122,32 +125,38 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackage(dmlpacka
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromBuffer(dmlpackage::VendorDMLStatement& vpackage) dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromBuffer(dmlpackage::VendorDMLStatement& vpackage)
{ {
CalpontDMLPackage* packagePtr = 0; CalpontDMLPackage* packagePtr = 0;
try try
{ {
int dmlStatementType = vpackage.get_DMLStatementType(); int dmlStatementType = vpackage.get_DMLStatementType();
switch (dmlStatementType) switch (dmlStatementType)
{ {
case DML_INSERT: case DML_INSERT:
packagePtr = new InsertDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID()); packagePtr = new InsertDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer (void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer
(),vpackage.get_Columns(), vpackage.get_Rows()); (), vpackage.get_Columns(), vpackage.get_Rows());
break; break;
case DML_UPDATE: case DML_UPDATE:
packagePtr = new UpdateDMLPackage(vpackage.get_SchemaName(), 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 (void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer
(),vpackage.get_Columns(), vpackage.get_Rows()); (), vpackage.get_Columns(), vpackage.get_Rows());
break; break;
case DML_DELETE: case DML_DELETE:
packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(), 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 (void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer
(),vpackage.get_Columns(), vpackage.get_Rows()); (), vpackage.get_Columns(), vpackage.get_Rows());
break; break;
case DML_COMMAND: case DML_COMMAND:
packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID() ); packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID() );
break; break;
default: default:
cerr << "makeCalpontDMLPackage: invalid statement type" << endl; cerr << "makeCalpontDMLPackage: invalid statement type" << endl;
break; break;
@@ -161,29 +170,35 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromBuffe
{ {
cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl; cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl;
} }
return packagePtr; return packagePtr;
} }
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromMysqlBuffer(dmlpackage::VendorDMLStatement& vpackage) dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromMysqlBuffer(dmlpackage::VendorDMLStatement& vpackage)
{ {
CalpontDMLPackage* packagePtr = 0; CalpontDMLPackage* packagePtr = 0;
try try
{ {
int dmlStatementType = vpackage.get_DMLStatementType(); int dmlStatementType = vpackage.get_DMLStatementType();
switch (dmlStatementType) switch (dmlStatementType)
{ {
case DML_INSERT: case DML_INSERT:
packagePtr = new InsertDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID()); 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()); (void)packagePtr->buildFromMysqlBuffer(vpackage.get_ColNames(), vpackage.get_values(), vpackage.get_Columns(), vpackage.get_Rows(), vpackage.get_nullValues());
break; break;
case DML_COMMAND: case DML_COMMAND:
packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID() ); packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID() );
break; break;
case DML_DELETE: case DML_DELETE:
packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(), packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(),
vpackage.get_DMLStatement(), vpackage.get_SessionID() ); vpackage.get_DMLStatement(), vpackage.get_SessionID() );
(void)packagePtr->buildFromMysqlBuffer(vpackage.get_ColNames(), vpackage.get_values(), vpackage.get_Columns(), vpackage.get_Rows(), vpackage.get_nullValues()); (void)packagePtr->buildFromMysqlBuffer(vpackage.get_ColNames(), vpackage.get_values(), vpackage.get_Columns(), vpackage.get_Rows(), vpackage.get_nullValues());
break; break;
default: default:
cerr << "makeCalpontDMLPackage: invalid statement type" << endl; cerr << "makeCalpontDMLPackage: invalid statement type" << endl;
break; break;
@@ -197,6 +212,7 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromMysql
{ {
cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl; cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl;
} }
return packagePtr; return packagePtr;
} }

View File

@@ -26,59 +26,62 @@ using namespace std;
namespace dmlpackage namespace dmlpackage
{ {
/** /**
* Constructors/Destructors * Constructors/Destructors
*/ */
CalpontDMLPackage::CalpontDMLPackage() CalpontDMLPackage::CalpontDMLPackage()
:fPlan(new messageqcpp::ByteStream()), fTable(0), fHasFilter(0), fLogging(true), fIsInsertSelect(false), fIsBatchInsert(false), fIsAutocommitOn(false), fTableOid(0) : 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 ) 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), fSessionID(sessionID), fPlan(new messageqcpp::ByteStream()), fTable(0), fHasFilter(false), fLogging(true), fIsInsertSelect(false),
fIsBatchInsert(false), fIsAutocommitOn(false), fIsWarnToError(false), fTableOid(0) fIsBatchInsert(false), fIsAutocommitOn(false), fIsWarnToError(false), fTableOid(0)
{ {
} }
CalpontDMLPackage::~CalpontDMLPackage() CalpontDMLPackage::~CalpontDMLPackage()
{ {
if ( 0 != fTable ) if ( 0 != fTable )
delete fTable; delete fTable;
} }
/* /*
* strip off whitespaces from a string * 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) if (pos == 0)
{ {
value = value.substr (pos+1,10000); value = value.substr (pos + 1, 10000);
} }
else else
{ // no more whitespace {
// no more whitespace
break; break;
} }
} }
return value;
}
void CalpontDMLPackage::initializeTable() return value;
{ }
void CalpontDMLPackage::initializeTable()
{
if (0 == fTable) if (0 == fTable)
{ {
fTable = new DMLTable(); fTable = new DMLTable();
fTable->set_SchemaName(fSchemaName); fTable->set_SchemaName(fSchemaName);
fTable->set_TableName(fTableName); fTable->set_TableName(fTableName);
} }
} }
} // namespace dmlpackage } // namespace dmlpackage

View File

@@ -36,13 +36,13 @@
namespace dmlpackage namespace dmlpackage
{ {
/** @brief abstract class that defines the general interface and /** @brief abstract class that defines the general interface and
* implemetation of a CalpontDMLPackage * implemetation of a CalpontDMLPackage
*/ */
class CalpontDMLPackage class CalpontDMLPackage
{ {
public: public:
/** @brief ctor /** @brief ctor
*/ */
CalpontDMLPackage(); CalpontDMLPackage();
@@ -98,57 +98,90 @@ namespace dmlpackage
/** @brief get the table object /** @brief get the table object
*/ */
DMLTable* get_Table() { return fTable; } DMLTable* get_Table()
{
return fTable;
}
/** @brief set the DML statement (the parsed statement) /** @brief set the DML statement (the parsed statement)
* *
* @param statement the dml statement to set * @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) /** @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) /** @brief set the SQL statement (the original SQL statement)
* *
* @param statement the SQL statement to set (the original SQL statement with quotes) * @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) /** @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 /** @brief get the logging flag
*/ */
const bool get_Logging() const { return fLogging; } const bool get_Logging() const
{
return fLogging;
}
/** @brief set the logging flag /** @brief set the logging flag
* *
* @param logging the logging flag to set * @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 /** @brief get the logending flag
*/ */
const bool get_Logending() const { return fLogending; } const bool get_Logending() const
{
return fLogending;
}
/** @brief set the logending flag /** @brief set the logending flag
* *
* @param logending the logending flag to set * @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 /** @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 /** @brief set the update column from column flag
* *
* @param logging the logging flag to set * @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 /** @brief set the Table name
* *
* @param tableName the name to set * @param tableName the name to set
@@ -156,13 +189,17 @@ namespace dmlpackage
void set_TableName( std::string& tableName ) void set_TableName( std::string& tableName )
{ {
fTableName = tableName; fTableName = tableName;
if(fTable != 0)
if (fTable != 0)
fTable->set_TableName(tableName); fTable->set_TableName(tableName);
} }
/** @brief get the Table name /** @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 /** @brief set the Schema name
* *
@@ -171,45 +208,76 @@ namespace dmlpackage
void set_SchemaName( std::string& schemaName ) void set_SchemaName( std::string& schemaName )
{ {
fSchemaName = schemaName; fSchemaName = schemaName;
if(fTable != 0)
if (fTable != 0)
fTable->set_SchemaName(schemaName); fTable->set_SchemaName(schemaName);
} }
/** @brief get the Schema name /** @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 /** @brief does this dml statement have a filter
*/ */
bool HasFilter() const { return fHasFilter; } bool HasFilter() const
void HasFilter( bool hasFilter) { fHasFilter = hasFilter; } {
return fHasFilter;
}
void HasFilter( bool hasFilter)
{
fHasFilter = hasFilter;
}
/** @brief get the filter statement /** @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 /** @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 /** @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 /** @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 /** @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 /** @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 /** @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 /** @brief get the ExecutionPlan associated with this package
*/ */
@@ -218,25 +286,61 @@ namespace dmlpackage
return fPlan; return fPlan;
} }
bool get_isInsertSelect() { return fIsInsertSelect; } bool get_isInsertSelect()
void set_isInsertSelect( const bool isInsertSelect ) { fIsInsertSelect = isInsertSelect; } {
return fIsInsertSelect;
}
void set_isInsertSelect( const bool isInsertSelect )
{
fIsInsertSelect = isInsertSelect;
}
bool get_isBatchInsert() { return fIsBatchInsert; } bool get_isBatchInsert()
void set_isBatchInsert( const bool isBatchInsert ) { fIsBatchInsert = isBatchInsert; } {
return fIsBatchInsert;
}
void set_isBatchInsert( const bool isBatchInsert )
{
fIsBatchInsert = isBatchInsert;
}
bool get_isAutocommitOn() { return fIsAutocommitOn; } bool get_isAutocommitOn()
void set_isAutocommitOn( const bool isAutocommitOn ) { fIsAutocommitOn = isAutocommitOn; } {
return fIsAutocommitOn;
}
void set_isAutocommitOn( const bool isAutocommitOn )
{
fIsAutocommitOn = isAutocommitOn;
}
bool get_isWarnToError() { return fIsWarnToError; } bool get_isWarnToError()
void set_isWarnToError( const bool isWarnToError ) { fIsWarnToError = isWarnToError; } {
return fIsWarnToError;
}
void set_isWarnToError( const bool isWarnToError )
{
fIsWarnToError = isWarnToError;
}
uint32_t getTableOid() { return fTableOid; } uint32_t getTableOid()
void setTableOid( const uint32_t tableOid ) { fTableOid = tableOid; } {
return fTableOid;
}
void setTableOid( const uint32_t tableOid )
{
fTableOid = tableOid;
}
void uuid(const boost::uuids::uuid& uuid) { fUuid = uuid; } void uuid(const boost::uuids::uuid& uuid)
const boost::uuids::uuid& uuid() const { return fUuid; } {
fUuid = uuid;
}
const boost::uuids::uuid& uuid() const
{
return fUuid;
}
protected: protected:
void initializeTable(); void initializeTable();
@@ -249,7 +353,7 @@ namespace dmlpackage
boost::uuids::uuid fUuid; boost::uuids::uuid fUuid;
execplan::CalpontSystemCatalog::SCN fTxnId; execplan::CalpontSystemCatalog::SCN fTxnId;
boost::shared_ptr<messageqcpp::ByteStream> fPlan; boost::shared_ptr<messageqcpp::ByteStream> fPlan;
DMLTable *fTable; DMLTable* fTable;
bool fHasFilter; bool fHasFilter;
bool fLogging; bool fLogging;
bool fLogending; bool fLogending;
@@ -261,6 +365,6 @@ namespace dmlpackage
bool fIsWarnToError; bool fIsWarnToError;
uint32_t fTableOid; uint32_t fTableOid;
WriteEngine::ChunkManager* fCM; WriteEngine::ChunkManager* fCM;
}; };
} }
#endif //CALPONTDMLPACKAGE_H #endif //CALPONTDMLPACKAGE_H

View File

@@ -32,18 +32,18 @@ using namespace std;
namespace dmlpackage namespace dmlpackage
{ {
CommandDMLPackage::CommandDMLPackage() CommandDMLPackage::CommandDMLPackage()
{} {}
CommandDMLPackage::CommandDMLPackage( std::string dmlStatement, int sessionID) CommandDMLPackage::CommandDMLPackage( std::string dmlStatement, int sessionID)
:CalpontDMLPackage( "", "", dmlStatement, sessionID) : CalpontDMLPackage( "", "", dmlStatement, sessionID)
{} {}
CommandDMLPackage::~CommandDMLPackage() CommandDMLPackage::~CommandDMLPackage()
{} {}
int CommandDMLPackage::write(messageqcpp::ByteStream& bytestream) int CommandDMLPackage::write(messageqcpp::ByteStream& bytestream)
{ {
int retval = 1; int retval = 1;
messageqcpp::ByteStream::byte package_type = DML_COMMAND; 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>(fIsAutocommitOn);
bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsBatchInsert); bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsBatchInsert);
return retval; return retval;
} }
int CommandDMLPackage::read(messageqcpp::ByteStream& bytestream) int CommandDMLPackage::read(messageqcpp::ByteStream& bytestream)
{ {
int retval = 1; int retval = 1;
messageqcpp::ByteStream::quadbyte session_id; messageqcpp::ByteStream::quadbyte session_id;
@@ -85,14 +85,14 @@ namespace dmlpackage
bytestream >> reinterpret_cast< messageqcpp::ByteStream::byte&>(fIsAutocommitOn); bytestream >> reinterpret_cast< messageqcpp::ByteStream::byte&>(fIsAutocommitOn);
bytestream >> reinterpret_cast< messageqcpp::ByteStream::byte&>(fIsBatchInsert); bytestream >> reinterpret_cast< messageqcpp::ByteStream::byte&>(fIsBatchInsert);
return retval; return retval;
} }
int CommandDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement) int CommandDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
{ {
CommandSqlStatement& cmdStmt = dynamic_cast<CommandSqlStatement&>(sqlStatement); CommandSqlStatement& cmdStmt = dynamic_cast<CommandSqlStatement&>(sqlStatement);
fDMLStatement = cmdStmt.fCommandText; fDMLStatement = cmdStmt.fCommandText;
return 1; return 1;
} }
} // namespace dmlpackage } // namespace dmlpackage

View File

@@ -36,13 +36,13 @@
namespace dmlpackage namespace dmlpackage
{ {
/** @brief concrete implementation of a CalpontDMLPackage /** @brief concrete implementation of a CalpontDMLPackage
* Specifically for representing COMMAND DML Statements * Specifically for representing COMMAND DML Statements
*/ */
class CommandDMLPackage : public CalpontDMLPackage class CommandDMLPackage : public CalpontDMLPackage
{ {
public: public:
/** @brief ctor /** @brief ctor
*/ */
EXPORT CommandDMLPackage(); EXPORT CommandDMLPackage();
@@ -72,7 +72,7 @@ namespace dmlpackage
* @param columns the number of columns in the buffer * @param columns the number of columns in the buffer
* @param rows the number of rows 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; return 1;
}; };
@@ -91,11 +91,11 @@ namespace dmlpackage
return 1; return 1;
}; };
protected: protected:
private: private:
}; };
} }

View File

@@ -38,7 +38,7 @@ DeleteDMLPackage::DeleteDMLPackage()
DeleteDMLPackage::DeleteDMLPackage(std::string schemaName, std::string tableName, DeleteDMLPackage::DeleteDMLPackage(std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID) std::string dmlStatement, int sessionID)
:CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID ) : CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID )
{} {}
DeleteDMLPackage::~DeleteDMLPackage() DeleteDMLPackage::~DeleteDMLPackage()
@@ -58,7 +58,7 @@ int DeleteDMLPackage::write(messageqcpp::ByteStream& bytestream)
fHasFilter = true; fHasFilter = true;
else else
fHasFilter = false; fHasFilter = false;
*/ */
messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter; messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter;
bytestream << hasFilter; bytestream << hasFilter;
@@ -67,11 +67,13 @@ int DeleteDMLPackage::write(messageqcpp::ByteStream& bytestream)
bytestream << fDMLStatement; bytestream << fDMLStatement;
bytestream << fSQLStatement; bytestream << fSQLStatement;
bytestream << fSchemaName; bytestream << fSchemaName;
if (fTable != 0) if (fTable != 0)
{ {
retval = fTable->write(bytestream); retval = fTable->write(bytestream);
} }
if(fHasFilter)
if (fHasFilter)
{ {
bytestream += *(fPlan.get()); bytestream += *(fPlan.get());
} }
@@ -103,7 +105,8 @@ int DeleteDMLPackage::read(messageqcpp::ByteStream& bytestream)
fTable = new DMLTable(); fTable = new DMLTable();
retval = fTable->read(bytestream); retval = fTable->read(bytestream);
if(fHasFilter)
if (fHasFilter)
{ {
fPlan.reset(new messageqcpp::ByteStream(bytestream)); fPlan.reset(new messageqcpp::ByteStream(bytestream));
} }
@@ -124,6 +127,7 @@ int DeleteDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
fHasFilter = true; fHasFilter = true;
fQueryString = deleteStmt.getQueryString(); fQueryString = deleteStmt.getQueryString();
} }
// else all rows are deleted // else all rows are deleted
return retval; return retval;
@@ -146,6 +150,7 @@ int DeleteDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
typedef boost::tokenizer<boost::char_separator<char> > tokenizer; typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(":"); boost::char_separator<char> sep(":");
tokenizer tokens(buffer, sep); tokenizer tokens(buffer, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{ {
dataList.push_back(StripLeadingWhitespace(*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; int n = 0;
for (int i=0; i < rows; i++)
for (int i = 0; i < rows; i++)
{ {
//get a new row //get a new row
Row aRow; Row aRow;
@@ -195,7 +201,7 @@ int DeleteDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
initializeTable(); initializeTable();
//The row already built from MySql parser. //The row already built from MySql parser.
/* Row *aRowPtr = new Row(); /* Row *aRowPtr = new Row();
std::string colName; std::string colName;
std::vector<std::string> colValList; std::vector<std::string> colValList;
for (int j = 0; j < columns; j++) for (int j = 0; j < columns; j++)

View File

@@ -36,13 +36,13 @@
namespace dmlpackage namespace dmlpackage
{ {
/** @brief concrete implementation of a CalpontDMLPackage /** @brief concrete implementation of a CalpontDMLPackage
* Specifically for representing DELETE DML Statements * Specifically for representing DELETE DML Statements
*/ */
class DeleteDMLPackage : public CalpontDMLPackage class DeleteDMLPackage : public CalpontDMLPackage
{ {
public: public:
/** @brief ctor /** @brief ctor
*/ */
@@ -94,11 +94,11 @@ namespace dmlpackage
*/ */
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues); EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues);
protected: protected:
private: private:
}; };
} }
#undef EXPORT #undef EXPORT

File diff suppressed because it is too large Load Diff

View File

@@ -36,9 +36,10 @@
/* Tokens. */ /* Tokens. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
# define 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. */ know about them. */
enum yytokentype { enum yytokentype
{
NAME = 258, NAME = 258,
STRING = 259, STRING = 259,
INTNUM = 260, INTNUM = 260,
@@ -127,7 +128,7 @@
WHERE = 343, WHERE = 343,
WITH = 344, WITH = 344,
WORK = 345 WORK = 345
}; };
#endif #endif
@@ -139,10 +140,10 @@ typedef union YYSTYPE
int intval; int intval;
double floatval; double floatval;
char *strval; char* strval;
int subtok; int subtok;
dmlpackage::SqlStatementList *sqlStmtList; dmlpackage::SqlStatementList* sqlStmtList;
dmlpackage::SqlStatement *sqlStmt; dmlpackage::SqlStatement* sqlStmt;
dmlpackage::TableName* tblName; dmlpackage::TableName* tblName;
dmlpackage::ColumnNameList* colNameList; dmlpackage::ColumnNameList* colNameList;
dmlpackage::ValuesOrQuery* valsOrQuery; dmlpackage::ValuesOrQuery* valsOrQuery;

File diff suppressed because it is too large Load Diff

View File

@@ -40,10 +40,12 @@ DMLColumn::DMLColumn(std::string name, std::string value, bool isFromCol, uint32
{ {
fName = name; fName = name;
fData = value; fData = value;
if (( strcasecmp(value.c_str(), "NULL") == 0) || (value.length() == 0) ) if (( strcasecmp(value.c_str(), "NULL") == 0) || (value.length() == 0) )
{ {
isNULL = true; isNULL = true;
} }
fisNULL = isNULL; fisNULL = isNULL;
fIsFromCol = isFromCol; fIsFromCol = isFromCol;
fFuncScale = funcScale; fFuncScale = funcScale;
@@ -69,6 +71,7 @@ int DMLColumn::read(messageqcpp::ByteStream& bytestream)
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fisNULL); bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fisNULL);
uint32_t vectorSize; uint32_t vectorSize;
bytestream >> vectorSize; bytestream >> vectorSize;
if (vectorSize > 0 ) if (vectorSize > 0 )
{ {
for ( uint32_t i = 0; i < vectorSize; i++ ) for ( uint32_t i = 0; i < vectorSize; i++ )
@@ -85,8 +88,9 @@ int DMLColumn::read(messageqcpp::ByteStream& bytestream)
else else
bytestream >> fData; //deprecated. bytestream >> fData; //deprecated.
if ( (fColValuesList.size() <1) && (fColValuesList.size() > 0) ) //deprecated. if ( (fColValuesList.size() < 1) && (fColValuesList.size() > 0) ) //deprecated.
fData =fColValuesList[0] ; //deprecated. fData = fColValuesList[0] ; //deprecated.
//bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fisNULL); //bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fisNULL);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsFromCol); bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsFromCol);
bytestream >> (uint32_t&) fFuncScale; bytestream >> (uint32_t&) fFuncScale;
@@ -100,6 +104,7 @@ int DMLColumn::write(messageqcpp::ByteStream& bytestream)
bytestream << static_cast<uint8_t>(fisNULL); bytestream << static_cast<uint8_t>(fisNULL);
uint32_t vectorSize = fColValuesList.size(); uint32_t vectorSize = fColValuesList.size();
bytestream << vectorSize; bytestream << vectorSize;
if (vectorSize > 0 ) if (vectorSize > 0 )
{ {
for ( uint32_t i = 0; i < vectorSize; i++ ) for ( uint32_t i = 0; i < vectorSize; i++ )
@@ -110,9 +115,10 @@ int DMLColumn::write(messageqcpp::ByteStream& bytestream)
} }
else else
bytestream << fData; //deprecated. bytestream << fData; //deprecated.
//bytestream << static_cast<uint8_t>(fisNULL); //bytestream << static_cast<uint8_t>(fisNULL);
bytestream << static_cast<uint8_t>(fIsFromCol); bytestream << static_cast<uint8_t>(fIsFromCol);
bytestream <<(uint32_t)fFuncScale; bytestream << (uint32_t)fFuncScale;
return retval; return retval;
} }

View File

@@ -52,12 +52,12 @@ public:
/** @brief ctor /** @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 /** @brief new ctor
* isNUll is currently not in use. It supposed to indicate whether each value is null or not. * 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 /** @brief dtor
*/ */
@@ -77,45 +77,75 @@ public:
/** @brief get the data for the column /** @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 /** @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 /** @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 /** @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 /** @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 /** @brief set the column name
*/ */
EXPORT void set_Name( std::string 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 /** @brief set the NULL flag
*/ */
void set_isnull( bool isNULL) void set_isnull( bool isNULL)
{ fisNULL = isNULL; } {
fisNULL = isNULL;
}
/** @brief set the fIsFromCol flag /** @brief set the fIsFromCol flag
*/ */
void set_isFromCol( bool isFromCol) void set_isFromCol( bool isFromCol)
{ fIsFromCol = isFromCol; } {
fIsFromCol = isFromCol;
}
/** @brief set the fFuncScale /** @brief set the fFuncScale
*/ */
void set_funcScale( uint32_t funcScale) void set_funcScale( uint32_t funcScale)
{ fFuncScale = funcScale; } {
fFuncScale = funcScale;
}
void set_Data ( std::string data) void set_Data ( std::string data)
{ fData = data; } {
fData = data;
}
void set_DataVector ( std::vector<std::string>& dataVec) void set_DataVector ( std::vector<std::string>& dataVec)
{ fColValuesList = dataVec; } {
fColValuesList = dataVec;
}
protected: protected:

View File

@@ -23,7 +23,8 @@
#include "dmlobject.h" #include "dmlobject.h"
namespace dmlpackage { namespace dmlpackage
{
DMLObject::DMLObject() DMLObject::DMLObject()
{ {

View File

@@ -29,10 +29,10 @@
namespace dmlpackage 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 std::string nullValue = "nvl";
//const size_t maxThreads = 100; //const size_t maxThreads = 100;
//const size_t queueSize = 200; //const size_t queueSize = 200;
} // namespace dmlpackage } // namespace dmlpackage
#endif //DMLPACKAGE_H #endif //DMLPACKAGE_H

View File

@@ -44,97 +44,105 @@ int dmlparse(void* yyscanner);
namespace dmlpackage namespace dmlpackage
{ {
using namespace std; using namespace std;
void scanner_finish(void* yyscanner); void scanner_finish(void* yyscanner);
void scanner_init(const char *str, void* yyscanner); void scanner_init(const char* str, void* yyscanner);
void grammar_init(dmlpackage::ParseTree* _ptree, bool); void grammar_init(dmlpackage::ParseTree* _ptree, bool);
valbuf_t get_valbuffer(void); valbuf_t get_valbuffer(void);
void free_copybuffer(); void free_copybuffer();
void set_defaultSchema(std::string schema); void set_defaultSchema(std::string schema);
DMLParser::DMLParser() : DMLParser::DMLParser() :
fStatus(-1), fDebug(false) fStatus(-1), fDebug(false)
{} {}
DMLParser::~DMLParser() DMLParser::~DMLParser()
{ {
scanner_finish(scanner); scanner_finish(scanner);
dmllex_destroy(scanner); dmllex_destroy(scanner);
} }
void DMLParser::setDebug(bool debug) void DMLParser::setDebug(bool debug)
{ {
fDebug = true; fDebug = true;
} }
int DMLParser::parse(const char* dmltext) int DMLParser::parse(const char* dmltext)
{ {
dmllex_init_extra(&scanData, &scanner); dmllex_init_extra(&scanData, &scanner);
scanner_init(dmltext, scanner); scanner_init(dmltext, scanner);
grammar_init(&fParseTree, fDebug); grammar_init(&fParseTree, fDebug);
fStatus = dmlparse(scanner); fStatus = dmlparse(scanner);
if (fStatus == 0) if (fStatus == 0)
{ {
char* str; char* str;
valbuf_t valueBuffer = get_valbuffer(); 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]; str = valueBuffer[i];
if(str)
if (str)
{ {
if (i > 0) if (i > 0)
fParseTree.fSqlText += " "; fParseTree.fSqlText += " ";
fParseTree.fSqlText += str; fParseTree.fSqlText += str;
} }
} }
} }
free_copybuffer(); free_copybuffer();
return fStatus; return fStatus;
} }
const ParseTree& DMLParser::getParseTree() const ParseTree& DMLParser::getParseTree()
{ {
if (!good()) if (!good())
{ {
throw logic_error("The ParseTree is invalid"); throw logic_error("The ParseTree is invalid");
} }
return fParseTree; return fParseTree;
} }
bool DMLParser::good() bool DMLParser::good()
{ {
return fStatus == 0; return fStatus == 0;
} }
void DMLParser::setDefaultSchema(std::string schema) void DMLParser::setDefaultSchema(std::string schema)
{ {
set_defaultSchema(schema); set_defaultSchema(schema);
} }
DMLFileParser::DMLFileParser() DMLFileParser::DMLFileParser()
:DMLParser() : DMLParser()
{} {}
int DMLFileParser::parse(const string& fileName) int DMLFileParser::parse(const string& fileName)
{ {
fStatus = -1; fStatus = -1;
ifstream ifdml; ifstream ifdml;
ifdml.open(fileName.c_str()); ifdml.open(fileName.c_str());
if (!ifdml.is_open()) if (!ifdml.is_open())
{ {
perror(fileName.c_str()); perror(fileName.c_str());
return fStatus; return fStatus;
} }
char dmlbuf[1024*1024];
char dmlbuf[1024 * 1024];
unsigned length; unsigned length;
ifdml.seekg(0, ios::end); ifdml.seekg(0, ios::end);
length = ifdml.tellg(); length = ifdml.tellg();
ifdml.seekg(0, ios::beg); ifdml.seekg(0, ios::beg);
if (length > sizeof(dmlbuf) - 1) if (length > sizeof(dmlbuf) - 1)
{ {
throw length_error("DMLFileParser has file size hard limit of 16K."); throw length_error("DMLFileParser has file size hard limit of 16K.");
@@ -142,6 +150,7 @@ namespace dmlpackage
unsigned rcount; unsigned rcount;
rcount = ifdml.readsome(dmlbuf, sizeof(dmlbuf) - 1); rcount = ifdml.readsome(dmlbuf, sizeof(dmlbuf) - 1);
if (rcount < 0) if (rcount < 0)
return fStatus; return fStatus;
@@ -152,11 +161,11 @@ namespace dmlpackage
//cout << dmlbuf << endl; //cout << dmlbuf << endl;
return DMLParser::parse(dmlbuf); return DMLParser::parse(dmlbuf);
} }
void end_sql(void) void end_sql(void)
{ {
} /* end_sql */ } /* end_sql */
} // dmlpackage } // dmlpackage

View File

@@ -31,27 +31,27 @@
namespace dmlpackage 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 // instance data for the parser
typedef std::vector<char*> valbuf_t; typedef std::vector<char*> valbuf_t;
struct scan_data struct scan_data
{ {
/* Handles to the buffer that the lexer uses internally */ /* Handles to the buffer that the lexer uses internally */
char* scanbuf; char* scanbuf;
void* scanbufhandle; // This is a YY_BUFFER_STATE defined in ddl-scan.cpp void* scanbufhandle; // This is a YY_BUFFER_STATE defined in ddl-scan.cpp
valbuf_t valbuf; valbuf_t valbuf;
}; };
/** @brief BISON parser wrapper class /** @brief BISON parser wrapper class
*/ */
class DMLParser class DMLParser
{ {
public: public:
/** @brief ctor /** @brief ctor
*/ */
DMLParser(); DMLParser();
@@ -81,24 +81,24 @@ namespace dmlpackage
*/ */
void setDebug(bool debug); void setDebug(bool debug);
protected: protected:
ParseTree fParseTree; ParseTree fParseTree;
int fStatus; int fStatus;
bool fDebug; bool fDebug;
void* scanner; // yyscan_t * needed for re-entrant flex scanner void* scanner; // yyscan_t * needed for re-entrant flex scanner
scan_data scanData; scan_data scanData;
private: private:
}; };
/** @brief specialization of the DMLParser class /** @brief specialization of the DMLParser class
* specifically for reading the dml statement * specifically for reading the dml statement
* from a file * from a file
*/ */
class DMLFileParser : public DMLParser class DMLFileParser : public DMLParser
{ {
public: public:
/** @brief ctor /** @brief ctor
*/ */
DMLFileParser(); DMLFileParser();
@@ -111,10 +111,10 @@ namespace dmlpackage
*/ */
int parse(const std::string& fileName); int parse(const std::string& fileName);
protected: protected:
private: private:
}; };
} }
#endif // DMLPARSER_H #endif // DMLPARSER_H

File diff suppressed because it is too large Load Diff

View File

@@ -123,7 +123,7 @@ public:
/** @brief dump to stdout. /** @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 /** @brief get the query string associated with the
* SqlStatement * SqlStatement
@@ -225,7 +225,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get a string representation of the query spec
*/ */
@@ -233,7 +233,10 @@ public:
/** @brief get the statement type - DML_INSERT /** @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; ValuesOrQuery* fValuesOrQueryPtr;
ColumnNameList fColumnList; ColumnNameList fColumnList;
@@ -267,7 +270,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the
* SET assignment_commalist opt_where_clause * SET assignment_commalist opt_where_clause
@@ -277,7 +280,10 @@ public:
/** @brief get the statement type - DML_UPDATE /** @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; ColumnAssignmentList* fColAssignmentListPtr;
WhereClause* fWhereClausePtr; WhereClause* fWhereClausePtr;
@@ -309,7 +315,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the WHERE clause
*/ */
@@ -317,7 +323,10 @@ public:
/** @brief get the statement type - DML_DELETE /** @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; WhereClause* fWhereClausePtr;
}; };
@@ -344,11 +353,14 @@ public:
/** @brief get the statement type - DML_COMMAND /** @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 /** @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 /** @brief get the COMMIT or ROLLBACK string
*/ */
@@ -382,7 +394,7 @@ public:
/** @brief dump to stdout /** @brief dump to stdout
*/ */
std::ostream& put(std::ostream &os) const; std::ostream& put(std::ostream& os) const;
std::string fName; std::string fName;
std::string fSchema; std::string fSchema;
@@ -399,7 +411,7 @@ class ColumnAssignment
public: public:
/** @brief dump to stdout /** @brief dump to stdout
*/ */
std::ostream& put(std::ostream &os) const; std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of /** @brief get the string representation of
* the column assignment * the column assignment
@@ -444,7 +456,7 @@ public:
/** @brief dump to stdout /** @brief dump to stdout
*/ */
std::ostream& put(std::ostream &os) const; std::ostream& put(std::ostream& os) const;
/** @brief get the string reperesentation of /** @brief get the string reperesentation of
* the ValuesList or the QuerySpec * the ValuesList or the QuerySpec
@@ -480,7 +492,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string represntation of the SELECT statement
*/ */
@@ -513,7 +525,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the FROM clause
*/ */
@@ -540,7 +552,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the WHERE clause
*/ */
@@ -569,7 +581,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the GROUP BY clause
*/ */
@@ -597,7 +609,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the HAVING clause
*/ */
@@ -618,7 +630,7 @@ class Escape
public: public:
/** @brief dump to stdout /** @brief dump to stdout
*/ */
std::ostream& put(std::ostream &os) const; std::ostream& put(std::ostream& os) const;
std::string fEscapeChar; std::string fEscapeChar;
}; };
@@ -653,7 +665,7 @@ public:
/** @brief dump to stdout /** @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 /** @param get the string representation of the predicate
*/ */
@@ -682,7 +694,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the COMPARISON
* predicate * predicate
@@ -717,7 +729,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the BETWEEN
* predicate * predicate
@@ -752,7 +764,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the LIKE
* predicate * predicate
@@ -786,7 +798,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the NULL test
* predicate * predicate
@@ -820,7 +832,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the IN
* predicate * predicate
@@ -853,7 +865,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the
* ALL or ANY predicate * ALL or ANY predicate
@@ -886,7 +898,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the EXISTS
* predicate * predicate
@@ -919,7 +931,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the striong representation of the
* search condition * search condition
@@ -965,7 +977,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the
* table expression * table expression
@@ -1013,7 +1025,7 @@ public:
/** @brief dump to stdout /** @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 /** @brief get the string representation of the
* query specification * query specification

View File

@@ -35,13 +35,14 @@ DMLTable::~DMLTable()
try try
{ {
RowList::iterator it = fRows.begin(); RowList::iterator it = fRows.begin();
while(it != fRows.end())
while (it != fRows.end())
{ {
delete *it; delete *it;
it++; it++;
} }
} }
catch(...) catch (...)
{ {
cout << "failed to delete the table rows" << endl; cout << "failed to delete the table rows" << endl;
} }
@@ -67,6 +68,7 @@ int DMLTable::read(messageqcpp::ByteStream& bytestream)
retval = aRow->read(bytestream); retval = aRow->read(bytestream);
fRows.push_back(aRow); fRows.push_back(aRow);
} }
return retval; return retval;
} }
@@ -82,6 +84,7 @@ int DMLTable::write(messageqcpp::ByteStream& bytestream)
//write the row list //write the row list
RowList::iterator rowListPtr; RowList::iterator rowListPtr;
rowListPtr = fRows.begin(); rowListPtr = fRows.begin();
for (; rowListPtr != fRows.end(); ++rowListPtr) for (; rowListPtr != fRows.end(); ++rowListPtr)
{ {
retval = (*rowListPtr)->write(bytestream); retval = (*rowListPtr)->write(bytestream);

View File

@@ -51,23 +51,38 @@ public:
/** @brief get the schema name /** @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 /** @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 /** @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 /** @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 /** @brief get the row list
*/ */
inline RowList& get_RowList() { return fRows; } inline RowList& get_RowList()
{
return fRows;
}
/** @brief read a DMLTable from a ByteStream /** @brief read a DMLTable from a ByteStream
* *

View File

@@ -44,6 +44,7 @@ int main(int argc, char* argv[])
po::variables_map vm; po::variables_map vm;
po::store (po::parse_command_line (argc, argv, desc), vm); po::store (po::parse_command_line (argc, argv, desc), vm);
po::notify (vm); po::notify (vm);
if (vm.count ("sql")) if (vm.count ("sql"))
sqlfile = vm["sql"].as <string> (); sqlfile = vm["sql"].as <string> ();
@@ -51,14 +52,15 @@ int main(int argc, char* argv[])
count = vm["count"].as<int>(); count = vm["count"].as<int>();
DMLFileParser parser; DMLFileParser parser;
if (vm.count ("bisond")) if (vm.count ("bisond"))
parser.setDebug(true); parser.setDebug(true);
parser.parse(sqlfile); parser.parse(sqlfile);
if(parser.good()) if (parser.good())
{ {
const ParseTree &ptree = parser.getParseTree(); const ParseTree& ptree = parser.getParseTree();
cout << "Parser succeeded." << endl; cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl; cout << ptree.fList.size() << " " << "SQL statements" << endl;
@@ -66,8 +68,10 @@ int main(int argc, char* argv[])
cout << ptree; cout << ptree;
SqlStatement* statementPtr = ptree[0]; SqlStatement* statementPtr = ptree[0];
if (statementPtr) if (statementPtr)
cout << statementPtr->getQueryString(); cout << statementPtr->getQueryString();
cout << endl; cout << endl;
} }
else else

View File

@@ -41,7 +41,7 @@ InsertDMLPackage::InsertDMLPackage()
InsertDMLPackage::InsertDMLPackage( std::string schemaName, std::string tableName, InsertDMLPackage::InsertDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID ) std::string dmlStatement, int sessionID )
:CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID ) : CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID )
{} {}
InsertDMLPackage::~InsertDMLPackage() InsertDMLPackage::~InsertDMLPackage()
@@ -64,10 +64,12 @@ int InsertDMLPackage::write(messageqcpp::ByteStream& bytestream)
bytestream << fSchemaName; bytestream << fSchemaName;
bytestream << (uint8_t)fLogging; bytestream << (uint8_t)fLogging;
bytestream << (uint8_t)fLogending; bytestream << (uint8_t)fLogending;
if (fTable != 0) if (fTable != 0)
{ {
retval = fTable->write(bytestream); retval = fTable->write(bytestream);
} }
bytestream << fTableOid; bytestream << fTableOid;
bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsInsertSelect); bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsInsertSelect);
bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsBatchInsert); 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; typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(","); boost::char_separator<char> sep(",");
tokenizer tokens(buffer, sep); tokenizer tokens(buffer, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{ {
dataList.push_back(StripLeadingWhitespace(*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; int n = 0;
for (int i=0; i < rows; i++)
for (int i = 0; i < rows; i++)
{ {
//get a new row //get a new row
Row *aRowPtr = new Row(); Row* aRowPtr = new Row();
std::string colName; std::string colName;
std::string colValue; std::string colValue;
for (int j = 0; j < columns; j++) for (int j = 0; j < columns; j++)
{ {
//Build a column list //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); DMLColumn* aColumn = new DMLColumn(colName, colValue, false);
(aRowPtr->get_ColumnList()).push_back(aColumn); (aRowPtr->get_ColumnList()).push_back(aColumn);
} }
//build a row list for a table //build a row list for a table
fTable->get_RowList().push_back(aRowPtr); fTable->get_RowList().push_back(aRowPtr);
} }
@@ -156,9 +162,10 @@ int InsertDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
int retval = 1; int retval = 1;
initializeTable(); initializeTable();
Row *aRowPtr = new Row(); Row* aRowPtr = new Row();
std::string colName; std::string colName;
std::vector<std::string> colValList; std::vector<std::string> colValList;
for (int j = 0; j < columns; j++) for (int j = 0; j < columns; j++)
{ {
//Build a column list //Build a column list
@@ -169,6 +176,7 @@ int InsertDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]); DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]);
(aRowPtr->get_ColumnList()).push_back(aColumn); (aRowPtr->get_ColumnList()).push_back(aColumn);
} }
//build a row list for a table //build a row list for a table
fTable->get_RowList().push_back(aRowPtr); fTable->get_RowList().push_back(aRowPtr);
aRowPtr = NULL; aRowPtr = NULL;
@@ -188,6 +196,7 @@ int InsertDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
initializeTable(); initializeTable();
bool isNULL = false; bool isNULL = false;
// only if we don't have a select statement // only if we don't have a select statement
if (0 == insertStmt.fValuesOrQueryPtr->fQuerySpecPtr) if (0 == insertStmt.fValuesOrQueryPtr->fQuerySpecPtr)
{ {
@@ -198,16 +207,20 @@ int InsertDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
{ {
ValuesList valuesList = insertStmt.fValuesOrQueryPtr->fValuesList; ValuesList valuesList = insertStmt.fValuesOrQueryPtr->fValuesList;
if (columnNameList.size() != valuesList.size()) if (columnNameList.size() != valuesList.size())
{ {
throw logic_error("Column names and values count mismatch!"); throw logic_error("Column names and values count mismatch!");
} }
Row* aRow = new Row(); Row* aRow = new Row();
for (unsigned int i = 0; i < columnNameList.size(); i++) 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); (aRow->get_ColumnList()).push_back(aColumn);
} }
fTable->get_RowList().push_back(aRow); fTable->get_RowList().push_back(aRow);
} }
@@ -218,9 +231,11 @@ int InsertDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
Row* aRow = new Row(); Row* aRow = new Row();
std::string colName = ""; std::string colName = "";
std::string colValue; std::string colValue;
while (iter != valuesList.end()) while (iter != valuesList.end())
{ {
colValue = *iter; colValue = *iter;
if ( strcasecmp(colValue.c_str(), "NULL") == 0) if ( strcasecmp(colValue.c_str(), "NULL") == 0)
{ {
isNULL = true; isNULL = true;
@@ -229,11 +244,13 @@ int InsertDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
{ {
isNULL = false; isNULL = false;
} }
DMLColumn *aColumn = new DMLColumn(colName,colValue, isNULL);
DMLColumn* aColumn = new DMLColumn(colName, colValue, isNULL);
(aRow->get_ColumnList()).push_back(aColumn); (aRow->get_ColumnList()).push_back(aColumn);
++iter; ++iter;
} }
fTable->get_RowList().push_back(aRow); fTable->get_RowList().push_back(aRow);
} }

View File

@@ -30,7 +30,7 @@ namespace dmlpackage
{ {
Row::Row() Row::Row()
:fRowID(std::numeric_limits<WriteEngine::RID>::max()) : fRowID(std::numeric_limits<WriteEngine::RID>::max())
{} {}
Row::~Row() Row::~Row()
@@ -39,17 +39,19 @@ Row::~Row()
{ {
delete fColumnList[i]; delete fColumnList[i];
} }
fColumnList.clear(); fColumnList.clear();
} }
Row::Row(const Row& row) 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); const DMLColumn* aColumn = row.get_ColumnAt(i);
DMLColumn* newColumn = new DMLColumn(aColumn->get_Name(), aColumn->get_Data()); DMLColumn* newColumn = new DMLColumn(aColumn->get_Name(), aColumn->get_Data());
fColumnList.push_back(newColumn); fColumnList.push_back(newColumn);
} }
fRowID = row.fRowID; fRowID = row.fRowID;
} }
int Row::read(messageqcpp::ByteStream& bytestream) int Row::read(messageqcpp::ByteStream& bytestream)
@@ -60,12 +62,14 @@ int Row::read(messageqcpp::ByteStream& bytestream)
set_RowID(rowID); set_RowID(rowID);
messageqcpp::ByteStream::quadbyte col_count; messageqcpp::ByteStream::quadbyte col_count;
bytestream >> col_count; bytestream >> col_count;
for (unsigned int i = 0; i < col_count; i++) for (unsigned int i = 0; i < col_count; i++)
{ {
DMLColumn* aColumn = new DMLColumn(); DMLColumn* aColumn = new DMLColumn();
retval = aColumn->read(bytestream); retval = aColumn->read(bytestream);
fColumnList.push_back(aColumn); fColumnList.push_back(aColumn);
} }
return retval; return retval;
} }
@@ -79,6 +83,7 @@ int Row::write(messageqcpp::ByteStream& bytestream)
colListPtr = fColumnList.begin(); colListPtr = fColumnList.begin();
messageqcpp::ByteStream::quadbyte col_count = fColumnList.size(); messageqcpp::ByteStream::quadbyte col_count = fColumnList.size();
bytestream << col_count; bytestream << col_count;
for (; colListPtr != fColumnList.end(); ++colListPtr) for (; colListPtr != fColumnList.end(); ++colListPtr)
{ {
retval = (*colListPtr)->write(bytestream); retval = (*colListPtr)->write(bytestream);

View File

@@ -71,19 +71,31 @@ public:
/** @brief get the list of columns in the row /** @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 /** @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 /** @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 /** @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 /** @brief get the column at the specified index
* *

View File

@@ -46,9 +46,10 @@ bool parse_file(char* fileName)
DMLFileParser parser; DMLFileParser parser;
parser.parse(fileName); parser.parse(fileName);
bool good = parser.good(); bool good = parser.good();
if (good) if (good)
{ {
const ParseTree &ptree = parser.getParseTree(); const ParseTree& ptree = parser.getParseTree();
cout << "Parser succeeded." << endl; cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl; cout << ptree.fList.size() << " " << "SQL statements" << endl;
@@ -56,8 +57,10 @@ bool parse_file(char* fileName)
cout << ptree; cout << ptree;
SqlStatement* statementPtr = ptree[0]; SqlStatement* statementPtr = ptree[0];
if (statementPtr) if (statementPtr)
cout << statementPtr->getQueryString(); cout << statementPtr->getQueryString();
cout << endl; cout << endl;
} }
@@ -87,25 +90,55 @@ public:
void tearDown() {} 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 class DMLTest : public CppUnit::TestFixture
@@ -154,6 +187,7 @@ public:
VendorDMLStatement dmlStmt(dmlStatement, 1); VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt); CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage ); CPPUNIT_ASSERT( 0 != pDMLPackage );
if ( pDMLPackage->HasFilter() ) if ( pDMLPackage->HasFilter() )
{ {
cout << "This INSERT statement has a filter:" << endl; cout << "This INSERT statement has a filter:" << endl;
@@ -180,7 +214,7 @@ public:
CPPUNIT_ASSERT( DML_INSERT == package_type ); CPPUNIT_ASSERT( DML_INSERT == package_type );
InsertDMLPackage *pObject = new InsertDMLPackage(); InsertDMLPackage* pObject = new InsertDMLPackage();
pObject->read( bs ); pObject->read( bs );
@@ -196,7 +230,7 @@ public:
cout << dmlStatement << endl; cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement,1); VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt); CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage ); CPPUNIT_ASSERT( 0 != pDMLPackage );
@@ -212,15 +246,17 @@ public:
cout << dmlStatement << endl; cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement,1); VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt); CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage ); CPPUNIT_ASSERT( 0 != pDMLPackage );
if (pDMLPackage->HasFilter()) if (pDMLPackage->HasFilter())
{ {
cout << "This DELETE statement has a filter:" << endl; cout << "This DELETE statement has a filter:" << endl;
cout << pDMLPackage->get_QueryString() << endl; cout << pDMLPackage->get_QueryString() << endl;
} }
write_DML_object(bytestream, pDMLPackage); write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage; delete pDMLPackage;
read_delete_object(bytestream); read_delete_object(bytestream);
@@ -235,7 +271,7 @@ public:
CPPUNIT_ASSERT( DML_DELETE == package_type ); CPPUNIT_ASSERT( DML_DELETE == package_type );
DeleteDMLPackage *pObject = new DeleteDMLPackage(); DeleteDMLPackage* pObject = new DeleteDMLPackage();
pObject->read( bs ); 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;"; std::string dmlStatement = "UPDATE tpch.part SET p_partno = 1, p_name = 'joe' where p_partno=2;";
cout << dmlStatement << endl; cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement,1); VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt); CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage ); CPPUNIT_ASSERT( 0 != pDMLPackage );
write_DML_object(bytestream, pDMLPackage); write_DML_object(bytestream, pDMLPackage);
@@ -267,6 +303,7 @@ public:
VendorDMLStatement dmlStmt(dmlStatement, 1); VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt); CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage ); CPPUNIT_ASSERT( 0 != pDMLPackage );
if (pDMLPackage->HasFilter()) if (pDMLPackage->HasFilter())
{ {
cout << "This UPDATE statement has a filter:" << endl; cout << "This UPDATE statement has a filter:" << endl;
@@ -286,7 +323,7 @@ public:
CPPUNIT_ASSERT( DML_UPDATE == package_type ); CPPUNIT_ASSERT( DML_UPDATE == package_type );
UpdateDMLPackage *pObject = new UpdateDMLPackage(); UpdateDMLPackage* pObject = new UpdateDMLPackage();
pObject->read( bs ); pObject->read( bs );
@@ -300,7 +337,7 @@ public:
std::string dmlStatement = "COMMIT;"; std::string dmlStatement = "COMMIT;";
cout << dmlStatement << endl; cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement,1); VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt); CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage ); CPPUNIT_ASSERT( 0 != pDMLPackage );
write_DML_object(bytestream, pDMLPackage); write_DML_object(bytestream, pDMLPackage);
@@ -315,7 +352,7 @@ public:
std::string dmlStatement = "ROLLBACK;"; std::string dmlStatement = "ROLLBACK;";
cout << dmlStatement << endl; cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement,1); VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt); CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage ); CPPUNIT_ASSERT( 0 != pDMLPackage );
write_DML_object(bytestream, pDMLPackage); write_DML_object(bytestream, pDMLPackage);
@@ -331,7 +368,7 @@ public:
CPPUNIT_ASSERT( DML_COMMAND == package_type ); CPPUNIT_ASSERT( DML_COMMAND == package_type );
CommandDMLPackage *pObject = new CommandDMLPackage(); CommandDMLPackage* pObject = new CommandDMLPackage();
pObject->read( bs ); pObject->read( bs );
@@ -346,10 +383,10 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DMLTest );
#include <cppunit/extensions/TestFactoryRegistry.h> #include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h> #include <cppunit/ui/text/TestRunner.h>
int main( int argc, char **argv) int main( int argc, char** argv)
{ {
CppUnit::TextUi::TestRunner runner; CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry(); CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() ); runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false ); bool wasSuccessful = runner.run( "", false );
return (wasSuccessful ? 0 : 1); return (wasSuccessful ? 0 : 1);

View File

@@ -38,7 +38,7 @@ UpdateDMLPackage::UpdateDMLPackage()
UpdateDMLPackage::UpdateDMLPackage(std::string schemaName, std::string tableName, UpdateDMLPackage::UpdateDMLPackage(std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID) std::string dmlStatement, int sessionID)
:CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID) : CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID)
{} {}
UpdateDMLPackage::~UpdateDMLPackage() UpdateDMLPackage::~UpdateDMLPackage()
@@ -52,12 +52,12 @@ int UpdateDMLPackage::write(messageqcpp::ByteStream& bytestream)
messageqcpp::ByteStream::quadbyte session_id = fSessionID; messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id; bytestream << session_id;
/* /*
if(fPlan != 0) if(fPlan != 0)
fHasFilter = true; fHasFilter = true;
else else
fHasFilter = false; fHasFilter = false;
*/ */
messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter; messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter;
bytestream << hasFilter; bytestream << hasFilter;
@@ -67,11 +67,13 @@ int UpdateDMLPackage::write(messageqcpp::ByteStream& bytestream)
bytestream << fSQLStatement; bytestream << fSQLStatement;
bytestream << fSchemaName; bytestream << fSchemaName;
bytestream << (uint8_t)fIsFromCol; bytestream << (uint8_t)fIsFromCol;
if (fTable != 0) if (fTable != 0)
{ {
retval = fTable->write(bytestream); retval = fTable->write(bytestream);
} }
if(fHasFilter)
if (fHasFilter)
{ {
bytestream += *(fPlan.get()); bytestream += *(fPlan.get());
} }
@@ -105,7 +107,8 @@ int UpdateDMLPackage::read(messageqcpp::ByteStream& bytestream)
fIsFromCol = (isFromCol != 0); fIsFromCol = (isFromCol != 0);
fTable = new DMLTable(); fTable = new DMLTable();
retval = fTable->read(bytestream); retval = fTable->read(bytestream);
if(fHasFilter)
if (fHasFilter)
{ {
fPlan.reset(new messageqcpp::ByteStream(bytestream)); 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. // Push one row always and let the filter happen on the proc side.
Row* rowPtr = new Row(); Row* rowPtr = new Row();
ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin(); ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin();
while (iter != updateStmt.fColAssignmentListPtr->end()) while (iter != updateStmt.fColAssignmentListPtr->end())
{ {
ColumnAssignment* colaPtr = *iter; ColumnAssignment* colaPtr = *iter;
@@ -138,7 +142,9 @@ int UpdateDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
++iter; ++iter;
} }
fTable->get_RowList().push_back(rowPtr); fTable->get_RowList().push_back(rowPtr);
if (0 != updateStmt.fWhereClausePtr) if (0 != updateStmt.fWhereClausePtr)
{ {
// We need to filter the rows...get row ids // 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; typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(":,"); boost::char_separator<char> sep(":,");
tokenizer tokens(buffer, sep); tokenizer tokens(buffer, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{ {
dataList.push_back(StripLeadingWhitespace(*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; int n = 0;
for (int i=0; i < rows; i++)
for (int i = 0; i < rows; i++)
{ {
//get a new row //get a new row
Row *aRowPtr = new Row(); Row* aRowPtr = new Row();
std::string colName; std::string colName;
std::string colValue; std::string colValue;
//get row ID from the buffer //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); DMLColumn* aColumn = new DMLColumn(colName, colValue);
(aRowPtr->get_ColumnList()).push_back(aColumn); (aRowPtr->get_ColumnList()).push_back(aColumn);
} }
//build a row list for a table //build a row list for a table
fTable->get_RowList().push_back(aRowPtr); fTable->get_RowList().push_back(aRowPtr);
} }
@@ -211,9 +220,10 @@ int UpdateDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
int retval = 1; int retval = 1;
initializeTable(); initializeTable();
Row *aRowPtr = new Row(); Row* aRowPtr = new Row();
std::string colName; std::string colName;
std::vector<std::string> colValList; std::vector<std::string> colValList;
for (int j = 0; j < columns; j++) for (int j = 0; j < columns; j++)
{ {
//Build a column list //Build a column list
@@ -224,6 +234,7 @@ int UpdateDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]); DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]);
(aRowPtr->get_ColumnList()).push_back(aColumn); (aRowPtr->get_ColumnList()).push_back(aColumn);
} }
//build a row list for a table //build a row list for a table
fTable->get_RowList().push_back(aRowPtr); fTable->get_RowList().push_back(aRowPtr);
return retval; return retval;
@@ -242,6 +253,7 @@ void UpdateDMLPackage::buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStm
// Push one row always and let the filter happen on the proc side. // Push one row always and let the filter happen on the proc side.
Row* rowPtr = new Row(); Row* rowPtr = new Row();
ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin(); ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin();
while (iter != updateStmt.fColAssignmentListPtr->end()) while (iter != updateStmt.fColAssignmentListPtr->end())
{ {
ColumnAssignment* colaPtr = *iter; ColumnAssignment* colaPtr = *iter;
@@ -250,6 +262,7 @@ void UpdateDMLPackage::buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStm
++iter; ++iter;
} }
fTable->get_RowList().push_back(rowPtr); fTable->get_RowList().push_back(rowPtr);
} }
} // namespace dmlpackage } // namespace dmlpackage

View File

@@ -36,13 +36,13 @@
namespace dmlpackage namespace dmlpackage
{ {
/** @brief concrete implementation of a CalpontDMLPackage /** @brief concrete implementation of a CalpontDMLPackage
* Specifically for representing UPDATE DML Statements * Specifically for representing UPDATE DML Statements
*/ */
class UpdateDMLPackage : public CalpontDMLPackage class UpdateDMLPackage : public CalpontDMLPackage
{ {
public: public:
/** @brief ctor /** @brief ctor
*/ */
EXPORT UpdateDMLPackage(); EXPORT UpdateDMLPackage();
@@ -96,11 +96,11 @@ namespace dmlpackage
void buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStmt ); void buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStmt );
protected: protected:
private: private:
}; };
} }
#undef EXPORT #undef EXPORT

View File

@@ -30,30 +30,30 @@ using namespace std;
namespace dmlpackage namespace dmlpackage
{ {
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int sessionID) VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int sessionID)
:fDMLStatement(dmlstatement),fSessionID(sessionID), fLogging(true),fLogending(true) : fDMLStatement(dmlstatement), fSessionID(sessionID), fLogging(true), fLogending(true)
{} {}
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, int sessionID) VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, int sessionID)
:fDMLStatement(dmlstatement), fDMLStatementType(stmttype), fSessionID(sessionID),fLogging(true),fLogending(true) : 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, std::string tName, std::string schema,
int rows, int columns, std::string buf, int rows, int columns, std::string buf,
int sessionID) int sessionID)
:fDMLStatement(dmlstatement), fDMLStatementType(stmttype), : fDMLStatement(dmlstatement), fDMLStatementType(stmttype),
fTableName(tName), fSchema(schema), fRows(rows), fColumns(columns), 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) ColNameList& colNameList, TableValuesMap& tableValuesMap, NullValuesBitset& nullValues, int sessionID)
:fDMLStatement(dmlstatement), fDMLStatementType(stmttype), : fDMLStatement(dmlstatement), fDMLStatementType(stmttype),
fTableName(tName), fSchema(schema), fRows(rows), fColumns(columns), 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()
{} {}
} }

View File

@@ -36,18 +36,18 @@
#endif #endif
namespace dmlpackage namespace dmlpackage
{ {
typedef std::vector<std::string> ColValuesList; typedef std::vector<std::string> ColValuesList;
typedef std::vector<std::string> ColNameList; typedef std::vector<std::string> ColNameList;
typedef std::map<uint32_t, ColValuesList> TableValuesMap; typedef std::map<uint32_t, ColValuesList> TableValuesMap;
typedef std::bitset<4096> NullValuesBitset; typedef std::bitset<4096> NullValuesBitset;
/** @brief describes the general interface /** @brief describes the general interface
* and implementation of a Vendor DML Statement * and implementation of a Vendor DML Statement
*/ */
class VendorDMLStatement class VendorDMLStatement
{ {
public: public:
/** @brief ctor /** @brief ctor
*/ */
EXPORT VendorDMLStatement(std::string dmlstatement, int sessionID); EXPORT VendorDMLStatement(std::string dmlstatement, int sessionID);
@@ -73,74 +73,134 @@ namespace dmlpackage
/** @brief Get the table name /** @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 /** @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 /** @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 /** @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 /** @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 /** @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 /** @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 /** @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 /** @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 /** @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 /** @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 /** @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 /** @brief Get the data buffer
*/ */
inline std::string& get_DataBuffer() { return fDataBuffer; } inline std::string& get_DataBuffer()
{
return fDataBuffer;
}
/** @brief Set the data buffer /** @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 /** @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 /** @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 ColNameList& get_ColNames()
inline TableValuesMap& get_values() { return fTableValuesMap; } {
return fColNameList;
}
inline TableValuesMap& get_values()
{
return fTableValuesMap;
}
/** @brief get the logging flag /** @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 /** @brief set the logging flag
* *
@@ -153,7 +213,10 @@ namespace dmlpackage
/** @brief get the logging flag /** @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 /** @brief set the logending flag
* *
@@ -164,9 +227,9 @@ namespace dmlpackage
fLogending = logending; fLogending = logending;
} }
protected: protected:
private: private:
std::string fDMLStatement; std::string fDMLStatement;
int fDMLStatementType; int fDMLStatementType;
std::string fTableName; std::string fTableName;
@@ -181,7 +244,7 @@ namespace dmlpackage
bool fLogging; bool fLogging;
bool fLogending; bool fLogending;
}; };
} }

View File

@@ -56,6 +56,7 @@ void AutoincrementData::removeAutoincrementData(uint32_t sessionID)
{ {
boost::mutex::scoped_lock lock(map_mutex); boost::mutex::scoped_lock lock(map_mutex);
AutoincDataMap::iterator it = fAutoincDataMap.find(sessionID); AutoincDataMap::iterator it = fAutoincDataMap.find(sessionID);
if (it != fAutoincDataMap.end()) if (it != fAutoincDataMap.end())
{ {
delete (*it).second; delete (*it).second;
@@ -81,14 +82,16 @@ long long AutoincrementData::getNextValue(uint32_t columnOid)
boost::mutex::scoped_lock lk(fOIDnextvalLock); boost::mutex::scoped_lock lk(fOIDnextvalLock);
long long nextValue = 0; long long nextValue = 0;
OIDNextValue::iterator it = fOidNextValueMap.find(columnOid); OIDNextValue::iterator it = fOidNextValueMap.find(columnOid);
if (it != fOidNextValueMap.end()) if (it != fOidNextValueMap.end())
{ {
nextValue = it->second; nextValue = it->second;
} }
return nextValue; return nextValue;
} }
AutoincrementData::OIDNextValue & AutoincrementData::getOidNextValueMap() AutoincrementData::OIDNextValue& AutoincrementData::getOidNextValueMap()
{ {
boost::mutex::scoped_lock lk(fOIDnextvalLock); boost::mutex::scoped_lock lk(fOIDnextvalLock);

View File

@@ -37,7 +37,7 @@ public:
static void removeAutoincrementData(uint32_t sessionID = 0); static void removeAutoincrementData(uint32_t sessionID = 0);
void setNextValue(uint32_t columnOid, long long nextValue); void setNextValue(uint32_t columnOid, long long nextValue);
long long getNextValue(uint32_t columnOid); long long getNextValue(uint32_t columnOid);
OIDNextValue & getOidNextValueMap(); OIDNextValue& getOidNextValueMap();
private: private:
/** Constuctors */ /** Constuctors */

View File

@@ -49,11 +49,11 @@ using namespace BRM;
namespace dmlpackageprocessor namespace dmlpackageprocessor
{ {
// Tracks active cleartablelock commands by storing set of table lock IDs // Tracks active cleartablelock commands by storing set of table lock IDs
/*static*/ std::set<uint64_t> /*static*/ std::set<uint64_t>
CommandPackageProcessor::fActiveClearTableLockCmds; CommandPackageProcessor::fActiveClearTableLockCmds;
/*static*/ boost::mutex /*static*/ boost::mutex
CommandPackageProcessor::fActiveClearTableLockCmdMutex; CommandPackageProcessor::fActiveClearTableLockCmdMutex;
DMLPackageProcessor::DMLResult DMLPackageProcessor::DMLResult
CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage) CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
@@ -70,8 +70,10 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
fSessionID = cpackage.get_SessionID(); fSessionID = cpackage.get_SessionID();
BRM::TxnID txnid = fSessionManager.getTxnID(cpackage.get_SessionID()); BRM::TxnID txnid = fSessionManager.getTxnID(cpackage.get_SessionID());
uint64_t uniqueId = 0; uint64_t uniqueId = 0;
//Bug 5070. Added exception handling //Bug 5070. Added exception handling
try { try
{
uniqueId = fDbrm->getUnique64(); uniqueId = fDbrm->getUnique64();
} }
catch (std::exception& ex) catch (std::exception& ex)
@@ -105,6 +107,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
logging::Message::Args args1; logging::Message::Args args1;
logging::Message msg(1); logging::Message msg(1);
Logger logger(logid.fSubsysID); Logger logger(logid.fSubsysID);
if (stmt != "CLEANUP") if (stmt != "CLEANUP")
{ {
args1.add("Start SQL statement: "); args1.add("Start SQL statement: ");
@@ -112,6 +115,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
msg.format( args1 ); msg.format( args1 );
logger.logMessage(LOG_TYPE_DEBUG, msg, logid); logger.logMessage(LOG_TYPE_DEBUG, msg, logid);
} }
//fWEClient->addQueue(uniqueId); //fWEClient->addQueue(uniqueId);
try try
{ {
@@ -125,6 +129,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
vector<LBID_t> lbidList; vector<LBID_t> lbidList;
fDbrm->getUncommittedExtentLBIDs(static_cast<VER_t>(txnid.id), lbidList); fDbrm->getUncommittedExtentLBIDs(static_cast<VER_t>(txnid.id), lbidList);
bool cpInvalidated = false; bool cpInvalidated = false;
//cout << "get a valid txnid " << txnid.id << " and stmt is " << stmt << " and isBachinsert is " << cpackage.get_isBatchInsert() << endl; //cout << "get a valid txnid " << txnid.id << " and stmt is " << stmt << " and isBachinsert is " << cpackage.get_isBatchInsert() << endl;
if ((stmt == "COMMIT") && (cpackage.get_isBatchInsert())) if ((stmt == "COMMIT") && (cpackage.get_isBatchInsert()))
{ {
@@ -132,9 +137,11 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(fSessionID); boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(fSessionID);
CalpontSystemCatalog::TableName tableName; CalpontSystemCatalog::TableName tableName;
tableName = systemCatalogPtr->tableName(cpackage.getTableOid()); tableName = systemCatalogPtr->tableName(cpackage.getTableOid());
try try
{ {
uint64_t nextVal = systemCatalogPtr->nextAutoIncrValue(tableName); uint64_t nextVal = systemCatalogPtr->nextAutoIncrValue(tableName);
if (nextVal != AUTOINCR_SATURATED) //need to update syscolumn if (nextVal != AUTOINCR_SATURATED) //need to update syscolumn
{ {
//get autoincrement column oid //get autoincrement column oid
@@ -146,6 +153,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
aDbrm->getAILock(columnOid); aDbrm->getAILock(columnOid);
nextVal = systemCatalogPtr->nextAutoIncrValue(tableName); //in case it has changed nextVal = systemCatalogPtr->nextAutoIncrValue(tableName); //in case it has changed
validNextVal = aDbrm->getAIValue(columnOid, &nextValInController); validNextVal = aDbrm->getAIValue(columnOid, &nextValInController);
if ((validNextVal) && (nextValInController > nextVal)) if ((validNextVal) && (nextValInController > nextVal))
{ {
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
@@ -154,6 +162,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
uint8_t rc = ddlClient.UpdateSyscolumnNextval(columnOid, nextValInController); uint8_t rc = ddlClient.UpdateSyscolumnNextval(columnOid, nextValInController);
//@bug 5894. Need release lock. //@bug 5894. Need release lock.
aDbrm->releaseAILock(columnOid); aDbrm->releaseAILock(columnOid);
if (rc != 0) if (rc != 0)
throw std::runtime_error("Error in UpdateSyscolumnNextval"); throw std::runtime_error("Error in UpdateSyscolumnNextval");
} }
@@ -168,20 +177,26 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
fSessionManager.rolledback( txnid ); fSessionManager.rolledback( txnid );
throw std::runtime_error(ex.what()); throw std::runtime_error(ex.what());
} }
//systemCatalogPtr->updateColinfoCache(nextValMap); //systemCatalogPtr->updateColinfoCache(nextValMap);
int weRc = 0; int weRc = 0;
if (cpackage.get_isAutocommitOn()) if (cpackage.get_isAutocommitOn())
{ {
weRc = commitBatchAutoOnTransaction(uniqueId, txnid, cpackage.getTableOid(), errorMsg); weRc = commitBatchAutoOnTransaction(uniqueId, txnid, cpackage.getTableOid(), errorMsg);
if (weRc != 0) if (weRc != 0)
BRM::errString(weRc, errorMsg); BRM::errString(weRc, errorMsg);
cpInvalidated = true; cpInvalidated = true;
} }
else else
{ {
weRc = fDbrm->vbCommit(txnid.id); weRc = fDbrm->vbCommit(txnid.id);
if (weRc != 0) if (weRc != 0)
BRM::errString(weRc, errorMsg); BRM::errString(weRc, errorMsg);
//weRc = commitBatchAutoOffTransaction(uniqueId, txnid, cpackage.getTableOid(), errorMsg); //weRc = commitBatchAutoOffTransaction(uniqueId, txnid, cpackage.getTableOid(), errorMsg);
} }
@@ -189,6 +204,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
{ {
throw std::runtime_error(errorMsg); throw std::runtime_error(errorMsg);
} }
logging::logCommand(cpackage.get_SessionID(), txnid.id, "COMMIT;"); logging::logCommand(cpackage.get_SessionID(), txnid.id, "COMMIT;");
fSessionManager.committed( txnid ); fSessionManager.committed( txnid );
//cout << "releasing transaction id for batchinsert" << txnid.id << endl; //cout << "releasing transaction id for batchinsert" << txnid.id << endl;
@@ -201,22 +217,27 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
CalpontSystemCatalog::TableName tableName; CalpontSystemCatalog::TableName tableName;
uint32_t tableOid = cpackage.getTableOid(); uint32_t tableOid = cpackage.getTableOid();
std::vector<TableLockInfo> tableLocks = fDbrm->getAllTableLocks(); std::vector<TableLockInfo> tableLocks = fDbrm->getAllTableLocks();
if (tableOid == 0) //special case: transaction commit for autocommit off and not following a dml statement immediately 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 tablelockMap = tablelockData->getOidTablelockMap();
TablelockData::OIDTablelock::iterator iter; TablelockData::OIDTablelock::iterator iter;
if (!tablelockMap.empty()) 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); iter = tablelockMap.find(tableLocks[k].tableOID);
if ( iter != tablelockMap.end() ) if ( iter != tablelockMap.end() )
{ {
tableName = systemCatalogPtr->tableName(tableLocks[k].tableOID); tableName = systemCatalogPtr->tableName(tableLocks[k].tableOID);
try try
{ {
uint64_t nextVal = systemCatalogPtr->nextAutoIncrValue(tableName); uint64_t nextVal = systemCatalogPtr->nextAutoIncrValue(tableName);
if (nextVal != AUTOINCR_SATURATED) //neet to update syscolumn if (nextVal != AUTOINCR_SATURATED) //neet to update syscolumn
{ {
//get autoincrement column oid //get autoincrement column oid
@@ -235,8 +256,9 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
queRemoved = true; queRemoved = true;
WE_DDLCommandClient ddlClient; WE_DDLCommandClient ddlClient;
uint8_t rc = ddlClient.UpdateSyscolumnNextval(columnOid, nextValInController,fSessionID); uint8_t rc = ddlClient.UpdateSyscolumnNextval(columnOid, nextValInController, fSessionID);
aDbrm->releaseAILock(columnOid); aDbrm->releaseAILock(columnOid);
if (rc != 0) if (rc != 0)
{ {
//for now //for now
@@ -266,9 +288,11 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
if (tableOid >= 3000) if (tableOid >= 3000)
{ {
tableName = systemCatalogPtr->tableName(tableOid); tableName = systemCatalogPtr->tableName(tableOid);
try try
{ {
uint64_t nextVal = systemCatalogPtr->nextAutoIncrValue(tableName); uint64_t nextVal = systemCatalogPtr->nextAutoIncrValue(tableName);
if (nextVal != AUTOINCR_SATURATED) //need to update syscolumn if (nextVal != AUTOINCR_SATURATED) //need to update syscolumn
{ {
//get autoincrement column oid //get autoincrement column oid
@@ -280,14 +304,16 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
aDbrm->getAILock(columnOid); aDbrm->getAILock(columnOid);
nextVal = systemCatalogPtr->nextAutoIncrValue(tableName); //in case it has changed nextVal = systemCatalogPtr->nextAutoIncrValue(tableName); //in case it has changed
validNextVal = aDbrm->getAIValue(columnOid, &nextValInController); validNextVal = aDbrm->getAIValue(columnOid, &nextValInController);
if ((validNextVal) && (nextValInController > (uint64_t)nextVal)) if ((validNextVal) && (nextValInController > (uint64_t)nextVal))
{ {
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
queRemoved = true; queRemoved = true;
WE_DDLCommandClient ddlClient; WE_DDLCommandClient ddlClient;
uint8_t rc = ddlClient.UpdateSyscolumnNextval(columnOid, nextValInController,fSessionID); uint8_t rc = ddlClient.UpdateSyscolumnNextval(columnOid, nextValInController, fSessionID);
aDbrm->releaseAILock(columnOid); aDbrm->releaseAILock(columnOid);
if (rc != 0) if (rc != 0)
{ {
//for now //for now
@@ -303,22 +329,26 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
{ {
//Rollback transaction, release tablelock //Rollback transaction, release tablelock
rollBackTransaction(uniqueId, txnid, fSessionID, errorMsg); 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 ) if ( tableLocks[k].tableOID == tableOid )
{ {
try { try
{
fDbrm->releaseTableLock(tableLocks[k].id); fDbrm->releaseTableLock(tableLocks[k].id);
} }
catch (std::exception&) catch (std::exception&)
{} {}
} }
} }
fSessionManager.rolledback( txnid ); fSessionManager.rolledback( txnid );
throw std::runtime_error(ex.what()); throw std::runtime_error(ex.what());
} }
} }
} }
int weRc = commitTransaction(uniqueId, txnid ); int weRc = commitTransaction(uniqueId, txnid );
logging::logCommand(cpackage.get_SessionID(), txnid.id, "COMMIT;"); logging::logCommand(cpackage.get_SessionID(), txnid.id, "COMMIT;");
@@ -330,6 +360,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
oss << "COMMIT failed: " << ec.errorString(weRc); oss << "COMMIT failed: " << ec.errorString(weRc);
throw std::runtime_error(oss.str()); throw std::runtime_error(oss.str());
} }
fSessionManager.committed( txnid ); fSessionManager.committed( txnid );
//cout << "commit releasing transaction id " << txnid.id << endl; //cout << "commit releasing transaction id " << txnid.id << endl;
} }
@@ -340,6 +371,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
//version rollback, Bulkrollback //version rollback, Bulkrollback
weRc = rollBackTransaction(uniqueId, txnid, fSessionID, errorMsg); weRc = rollBackTransaction(uniqueId, txnid, fSessionID, errorMsg);
if (weRc == 0) if (weRc == 0)
{ {
//@Bug 4560 invalidate cp first as bulkrollback will truncate the newly added lbids. //@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;"); logging::logCommand(cpackage.get_SessionID(), txnid.id, "ROLLBACK;");
if (weRc != 0) if (weRc != 0)
{ {
//@Bug 4524. Don't set to readonly. Just error out. //@Bug 4524. Don't set to readonly. Just error out.
@@ -368,6 +401,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
ml.logErrorMessage( message1 ); ml.logErrorMessage( message1 );
throw std::runtime_error(oss.str()); throw std::runtime_error(oss.str());
} }
fSessionManager.rolledback( txnid ); fSessionManager.rolledback( txnid );
//cout << "batch rollback releasing transaction id " << txnid.id << endl; //cout << "batch rollback releasing transaction id " << txnid.id << endl;
} }
@@ -376,6 +410,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
std::string errorMsg(""); std::string errorMsg("");
logging::logCommand(cpackage.get_SessionID(), txnid.id, "ROLLBACK;"); logging::logCommand(cpackage.get_SessionID(), txnid.id, "ROLLBACK;");
int weRc = rollBackTransaction(uniqueId, txnid, fSessionID, errorMsg); int weRc = rollBackTransaction(uniqueId, txnid, fSessionID, errorMsg);
if (weRc != 0) if (weRc != 0)
{ {
//cout << "Rollback failed" << endl; //cout << "Rollback failed" << endl;
@@ -390,6 +425,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
ml.logErrorMessage( message2 ); ml.logErrorMessage( message2 );
throw std::runtime_error(oss.str()); throw std::runtime_error(oss.str());
} }
fSessionManager.rolledback( txnid ); fSessionManager.rolledback( txnid );
//cout << "Rollback releasing transaction id " << txnid.id << endl; //cout << "Rollback releasing transaction id " << txnid.id << endl;
} }
@@ -418,7 +454,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
else if ( !cpackage.get_Logging()) else if ( !cpackage.get_Logging())
{ {
BRM::TxnID txnid = fSessionManager.getTxnID(cpackage.get_SessionID()); 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); SQLLogger sqlLogger(cpackage.get_DMLStatement(), DMLLoggingId, fSessionID, txnid.id);
//cout << "commandpackageprocessor Logging " << cpackage.get_DMLStatement()+ ";" << endl; //cout << "commandpackageprocessor Logging " << cpackage.get_DMLStatement()+ ";" << endl;
} }
@@ -465,23 +501,26 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
result.result = COMMAND_ERROR; result.result = COMMAND_ERROR;
result.message = message; result.message = message;
} }
if (!queRemoved) if (!queRemoved)
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
//release table lock //release table lock
if ((result.result == NO_ERROR) && ((stmt == "COMMIT") || (stmt == "ROLLBACK")) ) if ((result.result == NO_ERROR) && ((stmt == "COMMIT") || (stmt == "ROLLBACK")) )
{ {
TablelockData * tablelockData = TablelockData::makeTablelockData(fSessionID); TablelockData* tablelockData = TablelockData::makeTablelockData(fSessionID);
TablelockData::OIDTablelock tablelockMap = tablelockData->getOidTablelockMap(); TablelockData::OIDTablelock tablelockMap = tablelockData->getOidTablelockMap();
bool lockReleased = true; bool lockReleased = true;
if (!tablelockMap.empty()) if (!tablelockMap.empty())
{ {
TablelockData::OIDTablelock::iterator it = tablelockMap.begin(); TablelockData::OIDTablelock::iterator it = tablelockMap.begin();
while (it != tablelockMap.end()) while (it != tablelockMap.end())
{ {
try { try
{
lockReleased = fDbrm->releaseTableLock(it->second); lockReleased = fDbrm->releaseTableLock(it->second);
//cout << "releasing tablelock " << it->second << endl; //cout << "releasing tablelock " << it->second << endl;
} }
@@ -497,6 +536,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
result.result = COMMAND_ERROR; result.result = COMMAND_ERROR;
result.message = message; result.message = message;
} }
if (!lockReleased) //log an error if (!lockReleased) //log an error
{ {
ostringstream os; ostringstream os;
@@ -512,18 +552,22 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
ml.logErrorMessage(message); ml.logErrorMessage(message);
} }
//cout << "tablelock " << it->second << " is released" << endl; //cout << "tablelock " << it->second << " is released" << endl;
it++; it++;
} }
//@Bug 3557. Clean tablelock cache after commit/rollback. //@Bug 3557. Clean tablelock cache after commit/rollback.
TablelockData::removeTablelockData(cpackage.get_SessionID()); TablelockData::removeTablelockData(cpackage.get_SessionID());
} }
} }
VERBOSE_INFO("Finished processing Command DML Package"); VERBOSE_INFO("Finished processing Command DML Package");
//LoggingID logid( DMLLoggingId, fSessionID, txnid.id); //LoggingID logid( DMLLoggingId, fSessionID, txnid.id);
logging::Message::Args args2; logging::Message::Args args2;
logging::Message msg1(1); logging::Message msg1(1);
if (stmt != "CLEANUP") if (stmt != "CLEANUP")
{ {
args2.add("End SQL statement"); args2.add("End SQL statement");
@@ -531,6 +575,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
//Logger logger(logid.fSubsysID); //Logger logger(logid.fSubsysID);
logger.logMessage(LOG_TYPE_DEBUG, msg1, logid); logger.logMessage(LOG_TYPE_DEBUG, msg1, logid);
} }
return result; return result;
} }
@@ -572,74 +617,94 @@ void CommandPackageProcessor::viewTableLock(
unsigned int pidColumnWidth = 3; // "PID" unsigned int pidColumnWidth = 3; // "PID"
unsigned int sessionIDColumnWidth = 7; // "Session" unsigned int sessionIDColumnWidth = 7; // "Session"
unsigned int txnIDColumnWidth = 3; // "Txn" unsigned int txnIDColumnWidth = 3; // "Txn"
unsigned int createTimeColumnWidth= 12;// "CreationTime" unsigned int createTimeColumnWidth = 12; // "CreationTime"
unsigned int pmColumnWidth = 7; // "DBRoots" unsigned int pmColumnWidth = 7; // "DBRoots"
std::vector<std::string> createTimes; std::vector<std::string> createTimes;
char cTimeBuffer[1024]; char cTimeBuffer[1024];
for (unsigned idx=0; idx<tableLocks.size(); idx++) for (unsigned idx = 0; idx < tableLocks.size(); idx++)
{ {
if (tableLocks[idx].id > maxLockID) if (tableLocks[idx].id > maxLockID)
maxLockID = tableLocks[idx].id; maxLockID = tableLocks[idx].id;
if (tableLocks[idx].ownerName.length() > ownerColumnWidth) if (tableLocks[idx].ownerName.length() > ownerColumnWidth)
ownerColumnWidth = tableLocks[idx].ownerName.length(); ownerColumnWidth = tableLocks[idx].ownerName.length();
if (tableLocks[idx].ownerPID > maxPID) if (tableLocks[idx].ownerPID > maxPID)
maxPID = tableLocks[idx].ownerPID; maxPID = tableLocks[idx].ownerPID;
if (tableLocks[idx].ownerSessionID > maxSessionID) if (tableLocks[idx].ownerSessionID > maxSessionID)
maxSessionID = tableLocks[idx].ownerSessionID; maxSessionID = tableLocks[idx].ownerSessionID;
if (tableLocks[idx].ownerSessionID < minSessionID) if (tableLocks[idx].ownerSessionID < minSessionID)
minSessionID = tableLocks[idx].ownerSessionID; minSessionID = tableLocks[idx].ownerSessionID;
if (tableLocks[idx].ownerTxnID > maxTxnID) if (tableLocks[idx].ownerTxnID > maxTxnID)
maxTxnID = tableLocks[idx].ownerTxnID; maxTxnID = tableLocks[idx].ownerTxnID;
ctime_r( &tableLocks[idx].creationTime, cTimeBuffer ); 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 ); std::string cTimeStr( cTimeBuffer );
if (cTimeStr.length() > createTimeColumnWidth) if (cTimeStr.length() > createTimeColumnWidth)
createTimeColumnWidth = cTimeStr.length(); createTimeColumnWidth = cTimeStr.length();
createTimes.push_back( cTimeStr ); createTimes.push_back( cTimeStr );
std::ostringstream pms; //It is dbroots now 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) if (k > 0)
pms << ','; pms << ',';
pms << tableLocks[idx].dbrootList[k]; pms << tableLocks[idx].dbrootList[k];
} }
if (pms.str().length() > pmColumnWidth) if (pms.str().length() > pmColumnWidth)
pmColumnWidth = pms.str().length(); pmColumnWidth = pms.str().length();
} }
ownerColumnWidth += 2; ownerColumnWidth += 2;
pmColumnWidth += 2; pmColumnWidth += 2;
createTimeColumnWidth += 2; createTimeColumnWidth += 2;
std::ostringstream idString; std::ostringstream idString;
idString << maxLockID; idString << maxLockID;
if (idString.str().length() > lockIDColumnWidth) if (idString.str().length() > lockIDColumnWidth)
lockIDColumnWidth = idString.str().length(); lockIDColumnWidth = idString.str().length();
lockIDColumnWidth += 2; lockIDColumnWidth += 2;
std::ostringstream pidString; std::ostringstream pidString;
pidString << maxPID; pidString << maxPID;
if (pidString.str().length() > pidColumnWidth) if (pidString.str().length() > pidColumnWidth)
pidColumnWidth = pidString.str().length(); pidColumnWidth = pidString.str().length();
pidColumnWidth += 2; pidColumnWidth += 2;
const std::string sessionNoneStr("BulkLoad"); const std::string sessionNoneStr("BulkLoad");
std::ostringstream sessionString; std::ostringstream sessionString;
sessionString << maxSessionID; sessionString << maxSessionID;
if (sessionString.str().length() > sessionIDColumnWidth) if (sessionString.str().length() > sessionIDColumnWidth)
sessionIDColumnWidth = sessionString.str().length(); sessionIDColumnWidth = sessionString.str().length();
if ((minSessionID < 0) && if ((minSessionID < 0) &&
(sessionNoneStr.length() > sessionIDColumnWidth)) (sessionNoneStr.length() > sessionIDColumnWidth))
sessionIDColumnWidth = sessionNoneStr.length(); sessionIDColumnWidth = sessionNoneStr.length();
sessionIDColumnWidth += 2; sessionIDColumnWidth += 2;
const std::string txnNoneStr("n/a"); const std::string txnNoneStr("n/a");
std::ostringstream txnString; std::ostringstream txnString;
txnString << maxTxnID; txnString << maxTxnID;
if (txnString.str().length() > txnIDColumnWidth) if (txnString.str().length() > txnIDColumnWidth)
txnIDColumnWidth = txnString.str().length(); txnIDColumnWidth = txnString.str().length();
txnIDColumnWidth += 2; txnIDColumnWidth += 2;
// Make second pass through the table locks to build our result. // 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. // (on different PMs), so we don't exit loop after "first" match.
bool found = false; bool found = false;
ostringstream os; ostringstream os;
for (unsigned idx=0; idx<tableLocks.size(); idx++)
for (unsigned idx = 0; idx < tableLocks.size(); idx++)
{ {
if (roPair.objnum == (CalpontSystemCatalog::OID) if (roPair.objnum == (CalpontSystemCatalog::OID)
tableLocks[idx].tableOID) tableLocks[idx].tableOID)
{ {
std::ostringstream pms; 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) if (k > 0)
pms << ','; pms << ',';
pms << tableLocks[idx].dbrootList[k]; pms << tableLocks[idx].dbrootList[k];
} }
@@ -672,14 +740,14 @@ void CommandPackageProcessor::viewTableLock(
setw(pidColumnWidth) << "PID" << setw(pidColumnWidth) << "PID" <<
setw(sessionIDColumnWidth) << "Session" << setw(sessionIDColumnWidth) << "Session" <<
setw(txnIDColumnWidth) << "Txn" << setw(txnIDColumnWidth) << "Txn" <<
setw(createTimeColumnWidth)<< "CreationTime" << setw(createTimeColumnWidth) << "CreationTime" <<
setw(9) << "State" << setw(9) << "State" <<
setw(pmColumnWidth) << "DBRoots" << endl; setw(pmColumnWidth) << "DBRoots" << endl;
} }
os << " " << os << " " <<
setw(lockIDColumnWidth) << tableLocks[idx].id << setw(lockIDColumnWidth) << tableLocks[idx].id <<
setw(ownerColumnWidth) << tableLocks[idx].ownerName<< setw(ownerColumnWidth) << tableLocks[idx].ownerName <<
setw(pidColumnWidth) << tableLocks[idx].ownerPID; setw(pidColumnWidth) << tableLocks[idx].ownerPID;
// Log session ID, or "BulkLoad" if session is -1 // Log session ID, or "BulkLoad" if session is -1
@@ -696,9 +764,9 @@ void CommandPackageProcessor::viewTableLock(
os << setw(txnIDColumnWidth) << os << setw(txnIDColumnWidth) <<
tableLocks[idx].ownerTxnID; tableLocks[idx].ownerTxnID;
os << setw(createTimeColumnWidth)<< os << setw(createTimeColumnWidth) <<
createTimes[idx] << createTimes[idx] <<
setw(9) << ((tableLocks[idx].state==BRM::LOADING) ? setw(9) << ((tableLocks[idx].state == BRM::LOADING) ?
"LOADING" : "CLEANUP") << "LOADING" : "CLEANUP") <<
setw(pmColumnWidth) << pms.str(); setw(pmColumnWidth) << pms.str();
@@ -759,9 +827,11 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
bool bRemoveMetaErrFlag = false; bool bRemoveMetaErrFlag = false;
std::ostringstream combinedErrMsg; std::ostringstream combinedErrMsg;
try { try
{
// Make sure BRM is in READ-WRITE state before starting // Make sure BRM is in READ-WRITE state before starting
int brmRc = fDbrm->isReadWrite( ); int brmRc = fDbrm->isReadWrite( );
if (brmRc != BRM::ERR_OK) if (brmRc != BRM::ERR_OK)
{ {
std::string brmErrMsg; std::string brmErrMsg;
@@ -777,14 +847,15 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
oam::OamCache* oamCache = oam::OamCache::makeOamCache(); oam::OamCache* oamCache = oam::OamCache::makeOamCache();
oam::OamCache::dbRootPMMap_t dbRootPmMap = oamCache->getDBRootToPMMap(); 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; std::set<int> pmSet;
// Construct relevant list of PMs based on the DBRoots associated // Construct relevant list of PMs based on the DBRoots associated
// with the tableLock. // 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] ); mapIter = dbRootPmMap->find( lockInfo.dbrootList[k] );
if (mapIter != dbRootPmMap->end()) if (mapIter != dbRootPmMap->end())
{ {
int pm = mapIter->second; int pm = mapIter->second;
@@ -800,6 +871,7 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
} }
std::vector<int> pmList; std::vector<int> pmList;
for (std::set<int>::const_iterator setIter = pmSet.begin(); for (std::set<int>::const_iterator setIter = pmSet.begin();
setIter != pmSet.end(); setIter != pmSet.end();
++setIter) ++setIter)
@@ -809,12 +881,15 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
std::cout << "cleartablelock rollback for table lock " << tableLockID << std::cout << "cleartablelock rollback for table lock " << tableLockID <<
" being forwarded to PM(s): "; " 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) if (k > 0)
std::cout << ", "; std::cout << ", ";
std::cout << pmList[k]; std::cout << pmList[k];
} }
std::cout << std::endl; std::cout << std::endl;
// Perform bulk rollback if state is in LOADING state // Perform bulk rollback if state is in LOADING state
@@ -839,23 +914,28 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
bsOut << lockInfo.tableOID; bsOut << lockInfo.tableOID;
bsOut << tableName.toString(); bsOut << tableName.toString();
bsOut << APPLNAME; bsOut << APPLNAME;
for (unsigned j=0; j<pmList.size(); j++)
for (unsigned j = 0; j < pmList.size(); j++)
{ {
fWEClient->write(bsOut, pmList[j]); fWEClient->write(bsOut, pmList[j]);
} }
// Wait for "all" the responses, and accumulate any/all errors // Wait for "all" the responses, and accumulate any/all errors
unsigned int pmMsgCnt = 0; unsigned int pmMsgCnt = 0;
while (pmMsgCnt < pmList.size()) while (pmMsgCnt < pmList.size())
{ {
std::string rollbackErrMsg; std::string rollbackErrMsg;
bsIn.reset(new messageqcpp::ByteStream()); bsIn.reset(new messageqcpp::ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if (bsIn->length() == 0) if (bsIn->length() == 0)
{ {
bRemoveMetaErrFlag = true; bRemoveMetaErrFlag = true;
if (combinedErrMsg.str().length() > 0) if (combinedErrMsg.str().length() > 0)
combinedErrMsg << std::endl; combinedErrMsg << std::endl;
combinedErrMsg << "Network error, PM rollback; "; combinedErrMsg << "Network error, PM rollback; ";
} }
else else
@@ -873,14 +953,17 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
if (rc != 0) if (rc != 0)
{ {
bRemoveMetaErrFlag = true; bRemoveMetaErrFlag = true;
if (combinedErrMsg.str().empty()) if (combinedErrMsg.str().empty())
combinedErrMsg << "Rollback error; "; combinedErrMsg << "Rollback error; ";
else else
combinedErrMsg << std::endl; combinedErrMsg << std::endl;
combinedErrMsg << "[PM" << pmNum << "] " << combinedErrMsg << "[PM" << pmNum << "] " <<
rollbackErrMsg; rollbackErrMsg;
} }
} }
pmMsgCnt++; pmMsgCnt++;
} // end of while loop to process all responses to bulk rollback } // 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; WE_SVR_DML_BULKROLLBACK_CLEANUP;
bsOut << uniqueId; bsOut << uniqueId;
bsOut << lockInfo.tableOID; bsOut << lockInfo.tableOID;
for (unsigned j=0; j<pmList.size(); j++)
for (unsigned j = 0; j < pmList.size(); j++)
{ {
fWEClient->write(bsOut, pmList[j]); fWEClient->write(bsOut, pmList[j]);
} }
// Wait for "all" the responses, and accumulate any/all errors // Wait for "all" the responses, and accumulate any/all errors
unsigned int pmMsgCnt = 0; unsigned int pmMsgCnt = 0;
while (pmMsgCnt < pmList.size()) while (pmMsgCnt < pmList.size())
{ {
std::string fileDeleteErrMsg; std::string fileDeleteErrMsg;
bsIn.reset(new messageqcpp::ByteStream()); bsIn.reset(new messageqcpp::ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if (bsIn->length() == 0) if (bsIn->length() == 0)
{ {
bRemoveMetaErrFlag = true; bRemoveMetaErrFlag = true;
if (combinedErrMsg.str().length() > 0) if (combinedErrMsg.str().length() > 0)
combinedErrMsg << std::endl; combinedErrMsg << std::endl;
combinedErrMsg << "Network error, PM rollback cleanup; "; combinedErrMsg << "Network error, PM rollback cleanup; ";
} }
else else
@@ -943,14 +1031,17 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
if (rc != 0) if (rc != 0)
{ {
bRemoveMetaErrFlag = true; bRemoveMetaErrFlag = true;
if (combinedErrMsg.str().empty()) if (combinedErrMsg.str().empty())
combinedErrMsg << "Cleanup error; "; combinedErrMsg << "Cleanup error; ";
else else
combinedErrMsg << std::endl; combinedErrMsg << std::endl;
combinedErrMsg << "[PM" << pmNum << "] " << combinedErrMsg << "[PM" << pmNum << "] " <<
fileDeleteErrMsg; fileDeleteErrMsg;
} }
} }
pmMsgCnt++; pmMsgCnt++;
} // end of while loop to process all responses to rollback cleanup } // end of while loop to process all responses to rollback cleanup
@@ -972,11 +1063,13 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
std::ostringstream oss; std::ostringstream oss;
oss << "Table lock " << tableLockID << " for table " << oss << "Table lock " << tableLockID << " for table " <<
tableName.toString() << " is cleared."; tableName.toString() << " is cleared.";
//@Bug 4517. Release tablelock if remove meta files failed. //@Bug 4517. Release tablelock if remove meta files failed.
if (bRemoveMetaErrFlag) if (bRemoveMetaErrFlag)
{ {
oss << " Warning: " << combinedErrMsg.str(); oss << " Warning: " << combinedErrMsg.str();
} }
result.tableLockInfo = oss.str(); result.tableLockInfo = oss.str();
} }
else else
@@ -1006,6 +1099,7 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
msgArgs.add( tableName.toString() ); msgArgs.add( tableName.toString() );
msgArgs.add( tableLockID ); msgArgs.add( tableLockID );
std::string finalStatus; std::string finalStatus;
if (!bErrFlag) if (!bErrFlag)
{ {
finalStatus = "Completed successfully"; finalStatus = "Completed successfully";
@@ -1015,6 +1109,7 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
finalStatus = "Encountered errors: "; finalStatus = "Encountered errors: ";
finalStatus += combinedErrMsg.str(); finalStatus += combinedErrMsg.str();
} }
msgArgs.add( finalStatus ); msgArgs.add( finalStatus );
logMsg2.format( msgArgs ); logMsg2.format( msgArgs );
ml.logInfoMessage( logMsg2 ); ml.logInfoMessage( logMsg2 );
@@ -1048,6 +1143,7 @@ void CommandPackageProcessor::establishTableLockToClear( uint64_t tableLockID,
{ {
std::set<uint64_t>::const_iterator it = std::set<uint64_t>::const_iterator it =
fActiveClearTableLockCmds.find( tableLockID ); fActiveClearTableLockCmds.find( tableLockID );
if (it != fActiveClearTableLockCmds.end()) if (it != fActiveClearTableLockCmds.end())
{ {
throw std::runtime_error( std::string( "Lock in use. " throw std::runtime_error( std::string( "Lock in use. "
@@ -1063,6 +1159,7 @@ void CommandPackageProcessor::establishTableLockToClear( uint64_t tableLockID,
int32_t txnid = -1; int32_t txnid = -1;
bool ownerChanged = fDbrm->changeOwner( bool ownerChanged = fDbrm->changeOwner(
tableLockID, processName, processID, sessionID, txnid); tableLockID, processName, processID, sessionID, txnid);
if (!ownerChanged) if (!ownerChanged)
{ {
throw std::runtime_error( std::string( throw std::runtime_error( std::string(

View File

@@ -50,7 +50,7 @@ class CommandPackageProcessor : public DMLPackageProcessor
{ {
public: 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 /** @brief process an CommandDMLPackage
* *
* @param cpackage the CommandDMLPackage to process * @param cpackage the CommandDMLPackage to process

130
dbcon/dmlpackageproc/deletepackageprocessor.cpp Executable file → Normal file
View File

@@ -57,9 +57,9 @@ using namespace messageqcpp;
using namespace oam; using namespace oam;
namespace dmlpackageprocessor namespace dmlpackageprocessor
{ {
DMLPackageProcessor::DMLResult DMLPackageProcessor::DMLResult
DeletePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage) DeletePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
{ {
SUMMARY_INFO("DeletePackageProcessor::processPackage"); SUMMARY_INFO("DeletePackageProcessor::processPackage");
DMLResult result; DMLResult result;
@@ -71,10 +71,12 @@ namespace dmlpackageprocessor
fSessionID = cpackage.get_SessionID(); fSessionID = cpackage.get_SessionID();
//StopWatch timer; //StopWatch timer;
VERBOSE_INFO("DeletePackageProcessor is processing CalpontDMLPackage ..."); VERBOSE_INFO("DeletePackageProcessor is processing CalpontDMLPackage ...");
TablelockData * tablelockData = TablelockData::makeTablelockData(fSessionID); TablelockData* tablelockData = TablelockData::makeTablelockData(fSessionID);
uint64_t uniqueId = 0; uint64_t uniqueId = 0;
//Bug 5070. Added exception handling //Bug 5070. Added exception handling
try { try
{
uniqueId = fDbrm->getUnique64(); uniqueId = fDbrm->getUnique64();
} }
catch (std::exception& ex) catch (std::exception& ex)
@@ -111,6 +113,7 @@ namespace dmlpackageprocessor
aTableName.schema = schemaName; aTableName.schema = schemaName;
fWEClient->addQueue(uniqueId); fWEClient->addQueue(uniqueId);
execplan::CalpontSystemCatalog::ROPair roPair; execplan::CalpontSystemCatalog::ROPair roPair;
try try
{ {
string stmt = cpackage.get_SQLStatement() + "|" + schemaName + "|"; string stmt = cpackage.get_SQLStatement() + "|" + schemaName + "|";
@@ -122,6 +125,7 @@ namespace dmlpackageprocessor
roPair = csc->tableRID(aTableName); roPair = csc->tableRID(aTableName);
tableLockId = tablelockData->getTablelockId(roPair.objnum); //check whether this table is locked already for this session tableLockId = tablelockData->getTablelockId(roPair.objnum); //check whether this table is locked already for this session
if (tableLockId == 0) if (tableLockId == 0)
{ {
//cout << "tablelock is not found in cache " << endl; //cout << "tablelock is not found in cache " << endl;
@@ -130,15 +134,17 @@ namespace dmlpackageprocessor
std::string processName("DMLProc"); std::string processName("DMLProc");
int32_t sessionId = fSessionID; int32_t sessionId = fSessionID;
int i = 0; int i = 0;
OamCache * oamcache = OamCache::makeOamCache(); OamCache* oamcache = OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds(); std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms; 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]); pms.push_back((uint32_t)pmList[i]);
} }
try { try
{
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnId, BRM::LOADING ); tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnId, BRM::LOADING );
} }
catch (std::exception&) catch (std::exception&)
@@ -155,8 +161,8 @@ namespace dmlpackageprocessor
numTries = waitPeriod * 10; numTries = waitPeriod * 10;
struct timespec rm_ts; struct timespec rm_ts;
rm_ts.tv_sec = sleepTime/1000; rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime%1000 *1000000; rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++) for (; i < numTries; i++)
{ {
@@ -164,14 +170,18 @@ namespace dmlpackageprocessor
Sleep(rm_ts.tv_sec * 1000); Sleep(rm_ts.tv_sec * 1000);
#else #else
struct timespec abs_ts; struct timespec abs_ts;
do do
{ {
abs_ts.tv_sec = rm_ts.tv_sec; abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec; abs_ts.tv_nsec = rm_ts.tv_nsec;
} }
while(nanosleep(&abs_ts,&rm_ts) < 0); while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif #endif
try {
try
{
processID = ::getpid(); processID = ::getpid();
txnId = txnid.id; txnId = txnid.id;
sessionId = fSessionID; sessionId = fSessionID;
@@ -196,7 +206,7 @@ namespace dmlpackageprocessor
args.add(processName); args.add(processName);
args.add((uint64_t)processID); args.add((uint64_t)processID);
args.add(sessionId); 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); const CalpontSystemCatalog::RIDList ridList = csc->columnRIDs(aTableName);
CalpontSystemCatalog::RIDList::const_iterator rid_iterator = ridList.begin(); CalpontSystemCatalog::RIDList::const_iterator rid_iterator = ridList.begin();
CalpontSystemCatalog::ColType colType; CalpontSystemCatalog::ColType colType;
while (rid_iterator != ridList.end()) while (rid_iterator != ridList.end())
{ {
// If user hit ctrl+c in the mysql console, fRollbackPending will be true. // If user hit ctrl+c in the mysql console, fRollbackPending will be true.
@@ -215,8 +226,10 @@ namespace dmlpackageprocessor
result.result = JOB_CANCELED; result.result = JOB_CANCELED;
break; break;
} }
CalpontSystemCatalog::ROPair roPair = *rid_iterator; CalpontSystemCatalog::ROPair roPair = *rid_iterator;
colType = csc->colType(roPair.objnum); colType = csc->colType(roPair.objnum);
if (colType.autoincrement) if (colType.autoincrement)
{ {
try try
@@ -231,12 +244,14 @@ namespace dmlpackageprocessor
throw std::runtime_error(ex.what()); throw std::runtime_error(ex.what());
} }
} }
++rid_iterator; ++rid_iterator;
} }
uint64_t rowsProcessed = 0; uint64_t rowsProcessed = 0;
rowsProcessed = fixUpRows(cpackage, result, uniqueId, roPair.objnum); rowsProcessed = fixUpRows(cpackage, result, uniqueId, roPair.objnum);
//@Bug 4994 Cancelled job is not error //@Bug 4994 Cancelled job is not error
if (result.result == JOB_CANCELED) if (result.result == JOB_CANCELED)
throw std::runtime_error("Query execution was interrupted"); throw std::runtime_error("Query execution was interrupted");
@@ -259,6 +274,7 @@ namespace dmlpackageprocessor
{ {
result.result = DELETE_ERROR; result.result = DELETE_ERROR;
} }
result.message = Message(ex.what()); result.message = Message(ex.what());
} }
catch (...) catch (...)
@@ -275,16 +291,20 @@ namespace dmlpackageprocessor
result.result = DELETE_ERROR; result.result = DELETE_ERROR;
result.message = message; result.message = message;
} }
//timer.finish(); //timer.finish();
//@Bug 1886,2870 Flush VM cache only once per statement. //@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; int rc = 0;
if (result.result == NO_ERROR) if (result.result == NO_ERROR)
{ {
rc = flushDataFiles( result.result, oids, uniqueId, txnid, roPair.objnum); rc = flushDataFiles( result.result, oids, uniqueId, txnid, roPair.objnum);
if (rc != NO_ERROR) if (rc != NO_ERROR)
{ {
cerr << "UpdatePackageProcessor::processPackage: write data to disk failed" << endl; cerr << "UpdatePackageProcessor::processPackage: write data to disk failed" << endl;
if (!fRollbackPending) if (!fRollbackPending)
{ {
logging::Message::Args args; logging::Message::Args args;
@@ -298,8 +318,10 @@ namespace dmlpackageprocessor
result.result = UPDATE_ERROR; result.result = UPDATE_ERROR;
result.message = message; result.message = message;
} }
result.rowCount = 0; result.rowCount = 0;
rc = endTransaction(uniqueId, txnid, false); rc = endTransaction(uniqueId, txnid, false);
if ( (rc != NO_ERROR) && (!fRollbackPending)) if ( (rc != NO_ERROR) && (!fRollbackPending))
{ {
logging::Message::Args args; logging::Message::Args args;
@@ -344,10 +366,10 @@ namespace dmlpackageprocessor
VERBOSE_INFO("Finished Processing Delete DML Package"); VERBOSE_INFO("Finished Processing Delete DML Package");
return result; 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; ByteStream msg, msgBk, emsgBs;
rowgroup::RGData rgData; rowgroup::RGData rgData;
ByteStream::quadbyte qb = 4; ByteStream::quadbyte qb = 4;
@@ -356,28 +378,33 @@ namespace dmlpackageprocessor
uint64_t rowsProcessed = 0; uint64_t rowsProcessed = 0;
uint32_t dbroot = 1; uint32_t dbroot = 1;
bool metaData = false; bool metaData = false;
oam::OamCache * oamCache = oam::OamCache::makeOamCache(); oam::OamCache* oamCache = oam::OamCache::makeOamCache();
std::vector<int> fPMs = oamCache->getModuleIds(); std::vector<int> fPMs = oamCache->getModuleIds();
std::map<unsigned, bool> pmStateDel; std::map<unsigned, bool> pmStateDel;
string emsg; string emsg;
string emsgStr; string emsgStr;
bool err = false; bool err = false;
//boost::scoped_ptr<messageqcpp::MessageQueueClient> fExeMgr; //boost::scoped_ptr<messageqcpp::MessageQueueClient> fExeMgr;
//fExeMgr.reset( new messageqcpp::MessageQueueClient("ExeMgr1")); //fExeMgr.reset( new messageqcpp::MessageQueueClient("ExeMgr1"));
try { try
for (unsigned i=0; i<fPMs.size(); i++) {
for (unsigned i = 0; i < fPMs.size(); i++)
{ {
pmStateDel[fPMs[i]] = true; pmStateDel[fPMs[i]] = true;
} }
fExeMgr->write(msg); fExeMgr->write(msg);
fExeMgr->write(*(cpackage.get_ExecutionPlan())); fExeMgr->write(*(cpackage.get_ExecutionPlan()));
//cout << "sending to ExeMgr plan with length " << (cpackage.get_ExecutionPlan())->length() << endl; //cout << "sending to ExeMgr plan with length " << (cpackage.get_ExecutionPlan())->length() << endl;
msg.restart(); msg.restart();
emsgBs.restart(); emsgBs.restart();
msg = fExeMgr->read(); //error handling msg = fExeMgr->read(); //error handling
if (msg.length() == 4) if (msg.length() == 4)
{ {
msg >> qb; msg >> qb;
if (qb != 0) if (qb != 0)
err = true; err = true;
} }
@@ -386,6 +413,7 @@ namespace dmlpackageprocessor
qb = 999; qb = 999;
err = true; err = true;
} }
if (err) if (err)
{ {
logging::Message::Args args; logging::Message::Args args;
@@ -422,10 +450,12 @@ namespace dmlpackageprocessor
err = true; err = true;
break; break;
} }
msg.restart(); msg.restart();
msgBk.restart(); msgBk.restart();
msg = fExeMgr->read(); msg = fExeMgr->read();
msgBk = msg; msgBk = msg;
if ( msg.length() == 0 ) if ( msg.length() == 0 )
{ {
logging::Message::Args args; logging::Message::Args args;
@@ -462,6 +492,7 @@ namespace dmlpackageprocessor
rowGroup->setData(&rgData); rowGroup->setData(&rgData);
//rowGroup->setData(const_cast<uint8_t*>(msg.buf())); //rowGroup->setData(const_cast<uint8_t*>(msg.buf()));
err = (rowGroup->getStatus() != 0); err = (rowGroup->getStatus() != 0);
if (err) if (err)
{ {
//msgBk.advance(rowGroup->getDataSize()); //msgBk.advance(rowGroup->getDataSize());
@@ -483,22 +514,27 @@ namespace dmlpackageprocessor
//return rowsProcessed; //return rowsProcessed;
break; break;
} }
if (rowGroup->getRGData() == NULL) if (rowGroup->getRGData() == NULL)
{ {
msg.restart(); msg.restart();
} }
if (rowGroup->getRowCount() == 0) //done fetching if (rowGroup->getRowCount() == 0) //done fetching
{ {
err = receiveAll( result, uniqueId, fPMs, pmStateDel, tableOid); err = receiveAll( result, uniqueId, fPMs, pmStateDel, tableOid);
//return rowsProcessed; //return rowsProcessed;
break; break;
} }
if (rowGroup->getBaseRid() == (uint64_t) (-1)) if (rowGroup->getBaseRid() == (uint64_t) (-1))
{ {
continue; // @bug4247, not valid row ids, may from small side outer continue; // @bug4247, not valid row ids, may from small side outer
} }
dbroot = rowGroup->getDBRoot(); dbroot = rowGroup->getDBRoot();
err = processRowgroup(msgBk, result, uniqueId, cpackage, pmStateDel, metaData, dbroot); err = processRowgroup(msgBk, result, uniqueId, cpackage, pmStateDel, metaData, dbroot);
if (err) if (err)
{ {
DMLResult tmpResult; DMLResult tmpResult;
@@ -510,9 +546,11 @@ namespace dmlpackageprocessor
//return rowsProcessed; //return rowsProcessed;
break; break;
} }
rowsProcessed += rowGroup->getRowCount(); rowsProcessed += rowGroup->getRowCount();
} }
} }
if (fRollbackPending) if (fRollbackPending)
{ {
err = true; err = true;
@@ -556,6 +594,7 @@ namespace dmlpackageprocessor
msg << qb; msg << qb;
fExeMgr->write(msg); fExeMgr->write(msg);
} }
return rowsProcessed; return rowsProcessed;
} }
catch (runtime_error& ex) catch (runtime_error& ex)
@@ -592,9 +631,9 @@ namespace dmlpackageprocessor
} }
return rowsProcessed; 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) dmlpackage::CalpontDMLPackage& cpackage, std::map<unsigned, bool>& pmStateDel, bool isMeta, uint32_t dbroot)
{ {
bool rc = false; bool rc = false;
@@ -622,20 +661,26 @@ bool DeletePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
if (isMeta) //send to all PMs if (isMeta) //send to all PMs
{ {
fWEClient->write_to_all(bytestream); fWEClient->write_to_all(bytestream);
while (1) while (1)
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = true; rc = true;
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = (tmp8 != 0); rc = (tmp8 != 0);
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
break; break;
} }
@@ -643,12 +688,14 @@ bool DeletePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
msgRecived++; msgRecived++;
} }
} }
return rc; return rc;
} }
if (pmStateDel[pmNum]) if (pmStateDel[pmNum])
{ {
try { try
{
fWEClient->write(bytestream, (uint32_t)pmNum); fWEClient->write(bytestream, (uint32_t)pmNum);
//cout << "sent tp pm " << pmNum<<endl; //cout << "sent tp pm " << pmNum<<endl;
pmStateDel[pmNum] = false; pmStateDel[pmNum] = false;
@@ -681,15 +728,19 @@ bool DeletePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
try {
try
{
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = true; rc = true;
errorMsg = "Lost connection to Write Engine Server while deleting"; errorMsg = "Lost connection to Write Engine Server while deleting";
throw std::runtime_error(errorMsg); throw std::runtime_error(errorMsg);
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = (tmp8 != 0); rc = (tmp8 != 0);
*bsIn >> errorMsg; *bsIn >> errorMsg;
@@ -700,9 +751,12 @@ bool DeletePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
//cout << "received from pm " << (uint32_t)tmp32 << " and rc = " << rc << endl; //cout << "received from pm " << (uint32_t)tmp32 << " and rc = " << rc << endl;
pmStateDel[tmp32] = true; pmStateDel[tmp32] = true;
if (rc != 0) {
if (rc != 0)
{
throw std::runtime_error(errorMsg); throw std::runtime_error(errorMsg);
} }
if ( tmp32 == (uint32_t)pmNum ) if ( tmp32 == (uint32_t)pmNum )
{ {
fWEClient->write(bytestream, (uint32_t)pmNum); fWEClient->write(bytestream, (uint32_t)pmNum);
@@ -737,6 +791,7 @@ bool DeletePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
} }
} }
} }
return rc; return rc;
} }
@@ -746,7 +801,8 @@ bool DeletePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
//check how many message we need to receive //check how many message we need to receive
uint32_t messagesNotReceived = 0; uint32_t messagesNotReceived = 0;
bool err = false; bool err = false;
for (unsigned i=0; i<fPMs.size(); i++)
for (unsigned i = 0; i < fPMs.size(); i++)
{ {
if (!pmStateDel[fPMs[i]]) if (!pmStateDel[fPMs[i]])
messagesNotReceived++; messagesNotReceived++;
@@ -756,16 +812,18 @@ bool DeletePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
uint32_t msgReceived = 0; uint32_t msgReceived = 0;
ByteStream::byte tmp8; ByteStream::byte tmp8;
string errorMsg; string errorMsg;
if (messagesNotReceived > 0) if (messagesNotReceived > 0)
{ {
LoggingID logid( DMLLoggingId, fSessionID, fSessionID); LoggingID logid( DMLLoggingId, fSessionID, fSessionID);
if ( messagesNotReceived > fWEClient->getPmCount()) if ( messagesNotReceived > fWEClient->getPmCount())
{ {
logging::Message::Args args1; logging::Message::Args args1;
logging::Message msg(1); logging::Message msg(1);
args1.add("Delete outstanding messages exceed PM count , need to receive messages:PMcount = "); args1.add("Delete outstanding messages exceed PM count , need to receive messages:PMcount = ");
ostringstream oss; ostringstream oss;
oss << messagesNotReceived <<":"<<fPMCount; oss << messagesNotReceived << ":" << fPMCount;
args1.add(oss.str()); args1.add(oss.str());
msg.format( args1 ); msg.format( args1 );
logging::Logger logger(logid.fSubsysID); logging::Logger logger(logid.fSubsysID);
@@ -791,15 +849,19 @@ bool DeletePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
break; break;
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
try {
try
{
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
err = true; err = true;
errorMsg = "Lost connection to Write Engine Server while deleting"; errorMsg = "Lost connection to Write Engine Server while deleting";
throw std::runtime_error(errorMsg); throw std::runtime_error(errorMsg);
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
err = (tmp8 != 0); err = (tmp8 != 0);
*bsIn >> errorMsg; *bsIn >> errorMsg;
@@ -808,9 +870,11 @@ bool DeletePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
//cout << "Received response from pm " << tmp32 << endl; //cout << "Received response from pm " << tmp32 << endl;
pmStateDel[tmp32] = true; pmStateDel[tmp32] = true;
if (err) { if (err)
{
throw std::runtime_error(errorMsg); throw std::runtime_error(errorMsg);
} }
msgReceived++; msgReceived++;
result.stats.fBlocksChanged += blocksChanged; result.stats.fBlocksChanged += blocksChanged;
result.stats.fErrorNo = tmp8; result.stats.fErrorNo = tmp8;

View File

@@ -49,7 +49,7 @@ class DeletePackageProcessor : public DMLPackageProcessor
public: 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 /** @brief process a DeleteDMLPackage
* *
* @param cpackage the delete dml package to process * @param cpackage the delete dml package to process
@@ -71,8 +71,8 @@ private:
WriteEngine::RIDList& rowIDList, WriteEngine::ColValueList& colOldValuesList, WriteEngine::RIDList& rowIDList, WriteEngine::ColValueList& colOldValuesList,
DMLResult& result); DMLResult& result);
*/ */
bool processRowgroup(messageqcpp::ByteStream & aRowGroup, DMLResult& result, const uint64_t uniqueId, dmlpackage::CalpontDMLPackage& cpackage, std::map<unsigned, bool>& pmStateDel, 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 isMeta = false, uint32_t dbroot = 1);
/** @brief add all rows if we have no filter for the delete /** @brief add all rows if we have no filter for the delete

View File

@@ -66,33 +66,38 @@ const SOP opand(new Operator("and"));
namespace dmlpackageprocessor namespace dmlpackageprocessor
{ {
DMLPackageProcessor::~DMLPackageProcessor() DMLPackageProcessor::~DMLPackageProcessor()
{ {
//cout << "In DMLPackageProcessor destructor " << this << endl; //cout << "In DMLPackageProcessor destructor " << this << endl;
if (fWEClient) if (fWEClient)
delete fWEClient; delete fWEClient;
if (fExeMgr) if (fExeMgr)
delete fExeMgr; delete fExeMgr;
} }
//@bug 397 //@bug 397
void DMLPackageProcessor::cleanString(string& s) void DMLPackageProcessor::cleanString(string& s)
{ {
string::size_type pos = s.find_first_not_of(" "); string::size_type pos = s.find_first_not_of(" ");
//stripe off space and ' or '' at beginning and end //stripe off space and ' or '' at beginning and end
if ( pos < s.length() ) 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()) if ( (pos = s.find_last_of(" ")) < s.length())
{ {
s = s.substr(0, pos ); s = s.substr(0, pos );
} }
} }
if ( s[0] == '\'') if ( s[0] == '\'')
{ {
s = s.substr(1, s.length()-2); s = s.substr(1, s.length() - 2);
if ( s[0] == '\'') if ( s[0] == '\'')
s = s.substr(1, s.length()-2); s = s.substr(1, s.length() - 2);
} }
} }
#if 0 #if 0
@@ -134,6 +139,7 @@ boost::any DMLPackageProcessor::tokenizeData( execplan::CalpontSystemCatalog::SC
dictTuple.sigValue = data.c_str(); dictTuple.sigValue = data.c_str();
dictTuple.sigSize = data.length(); dictTuple.sigSize = data.length();
int error = NO_ERROR; int error = NO_ERROR;
if ( NO_ERROR != (error = fWriteEngine.tokenize( txnID, dictStruct, dictTuple)) ) if ( NO_ERROR != (error = fWriteEngine.tokenize( txnID, dictStruct, dictTuple)) )
{ {
retval = false; retval = false;
@@ -150,10 +156,12 @@ boost::any DMLPackageProcessor::tokenizeData( execplan::CalpontSystemCatalog::SC
result.result = TOKEN_ERROR; result.result = TOKEN_ERROR;
result.message = message; result.message = message;
} }
WriteEngine::Token aToken = dictTuple.token; WriteEngine::Token aToken = dictTuple.token;
value = aToken; value = aToken;
} }
} }
return value; return value;
} }
#endif #endif
@@ -169,6 +177,7 @@ void DMLPackageProcessor::getColumnsForTable(uint32_t sessionID, std::string sch
CalpontSystemCatalog::RIDList ridList = systemCatalogPtr->columnRIDs(tableName, true); CalpontSystemCatalog::RIDList ridList = systemCatalogPtr->columnRIDs(tableName, true);
CalpontSystemCatalog::RIDList::const_iterator rid_iterator = ridList.begin(); CalpontSystemCatalog::RIDList::const_iterator rid_iterator = ridList.begin();
while (rid_iterator != ridList.end()) while (rid_iterator != ridList.end())
{ {
CalpontSystemCatalog::ROPair roPair = *rid_iterator; CalpontSystemCatalog::ROPair roPair = *rid_iterator;
@@ -186,6 +195,7 @@ void DMLPackageProcessor::getColumnsForTable(uint32_t sessionID, std::string sch
char* DMLPackageProcessor::strlower(char* in) char* DMLPackageProcessor::strlower(char* in)
{ {
char* p = in; char* p = in;
if (p) if (p)
{ {
while (*p) while (*p)
@@ -194,6 +204,7 @@ char* DMLPackageProcessor::strlower(char* in)
p++; p++;
} }
} }
return in; return in;
} }
@@ -234,10 +245,11 @@ string DMLPackageProcessor::projectTableErrCodeToMsg(uint32_t ec)
return IDBErrorInfo::instance()->errorMsg(ec); return IDBErrorInfo::instance()->errorMsg(ec);
} }
bool DMLPackageProcessor::validateVarbinaryVal( std::string & inStr) bool DMLPackageProcessor::validateVarbinaryVal( std::string& inStr)
{ {
bool invalid = false; bool invalid = false;
for (unsigned i=0; i < inStr.length(); i++)
for (unsigned i = 0; i < inStr.length(); i++)
{ {
if (!isxdigit(inStr[i])) if (!isxdigit(inStr[i]))
{ {
@@ -246,6 +258,7 @@ bool DMLPackageProcessor::validateVarbinaryVal( std::string & inStr)
} }
} }
return invalid; return invalid;
} }
@@ -264,6 +277,7 @@ int DMLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
int rc = 0; int rc = 0;
//Check BRM status before processing. //Check BRM status before processing.
rc = fDbrm->isReadWrite(); rc = fDbrm->isReadWrite();
if (rc != 0 ) if (rc != 0 )
{ {
std::string brmMsg; std::string brmMsg;
@@ -282,16 +296,21 @@ int DMLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
bytestream << sessionID; bytestream << sessionID;
bytestream << (uint32_t)txnID.id; bytestream << (uint32_t)txnID.id;
uint32_t msgRecived = 0; uint32_t msgRecived = 0;
try {
try
{
fWEClient->write_to_all(bytestream); fWEClient->write_to_all(bytestream);
boost::shared_ptr<messageqcpp::ByteStream> bsIn; boost::shared_ptr<messageqcpp::ByteStream> bsIn;
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
ByteStream::byte tmp8; ByteStream::byte tmp8;
while (1) while (1)
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_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; //cout << "erroring out remove queue id " << uniqueId << endl;
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = tmp8; rc = tmp8;
if (rc != 0) {
if (rc != 0)
{
char szrc[20]; char szrc[20];
*bsIn >> errorMsg; *bsIn >> errorMsg;
errorMsg += " (WriteEngine returns error "; 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; rc = NETWORK_ERROR;
errorMsg = "Network error occured when rolling back blocks"; errorMsg = "Network error occured when rolling back blocks";
@@ -349,6 +371,7 @@ int DMLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
//delete fWEClient; //delete fWEClient;
// cout << "success. remove queue id " << uniqueId << endl; // cout << "success. remove queue id " << uniqueId << endl;
rc = fDbrm->getUncommittedLBIDs(txnID.id, lbidList); rc = fDbrm->getUncommittedLBIDs(txnID.id, lbidList);
if (rc != 0 ) if (rc != 0 )
{ {
std::string brmMsg; std::string brmMsg;
@@ -359,11 +382,13 @@ int DMLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
return rc; 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.start = lbidList[i];
range.size = 1; range.size = 1;
lbidRangeList.push_back(range); lbidRangeList.push_back(range);
} }
rc = fDbrm->vbRollback(txnID.id, lbidRangeList); rc = fDbrm->vbRollback(txnID.id, lbidRangeList);
if (rc != 0 ) if (rc != 0 )
@@ -379,7 +404,7 @@ int DMLPackageProcessor::rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID
return rc; 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 //collect hwm info from all pms and set them here. remove table metadata if all successful
ByteStream bytestream; ByteStream bytestream;
@@ -398,21 +423,27 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
ByteStream::byte tmp8; ByteStream::byte tmp8;
typedef std::vector<BRM::BulkSetHWMArg> BulkSetHWMArgs; typedef std::vector<BRM::BulkSetHWMArg> BulkSetHWMArgs;
std::vector<BulkSetHWMArgs> hwmArgsAllPms; std::vector<BulkSetHWMArgs> hwmArgsAllPms;
while (1) while (1)
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = tmp8; rc = tmp8;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
@@ -430,16 +461,19 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
} }
} }
} }
if (rc != 0) if (rc != 0)
return rc; return rc;
//set hwm //set hwm
std::vector<BRM::BulkSetHWMArg> allHwm; std::vector<BRM::BulkSetHWMArg> allHwm;
BulkSetHWMArgs::const_iterator itor; BulkSetHWMArgs::const_iterator itor;
//cout << "total hwmArgsAllPms size " << hwmArgsAllPms.size() << endl; //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(); itor = hwmArgsAllPms[i].begin();
while (itor != hwmArgsAllPms[i].end()) while (itor != hwmArgsAllPms[i].end())
{ {
allHwm.push_back(*itor); allHwm.push_back(*itor);
@@ -447,14 +481,17 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
itor++; itor++;
} }
} }
//set CP data before hwm. //set CP data before hwm.
//cout << "setting hwm allHwm size " << allHwm.size() << endl; //cout << "setting hwm allHwm size " << allHwm.size() << endl;
vector<BRM::LBID_t> lbidList; vector<BRM::LBID_t> lbidList;
if (idbdatafile::IDBPolicy::useHdfs()) if (idbdatafile::IDBPolicy::useHdfs())
{ {
BRM::LBID_t startLbid; 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); rc = fDbrm->lookupLocalStartLbid(allHwm[i].oid, allHwm[i].partNum, allHwm[i].segNum, allHwm[i].hwm, startLbid);
lbidList.push_back(startLbid); lbidList.push_back(startLbid);
@@ -462,10 +499,12 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
} }
else else
fDbrm->getUncommittedExtentLBIDs(static_cast<BRM::VER_t>(txnID.id), lbidList); 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 iter = lbidList.begin();
vector<BRM::LBID_t>::const_iterator end = lbidList.end(); vector<BRM::LBID_t>::const_iterator end = lbidList.end();
BRM::CPInfoList_t cpInfos; BRM::CPInfoList_t cpInfos;
BRM::CPInfo aInfo; BRM::CPInfo aInfo;
while (iter != end) while (iter != end)
{ {
aInfo.firstLbid = *iter; aInfo.firstLbid = *iter;
@@ -475,6 +514,7 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
cpInfos.push_back(aInfo); cpInfos.push_back(aInfo);
++iter; ++iter;
} }
std::vector<BRM::CPInfoMerge> mergeCPDataArgs; std::vector<BRM::CPInfoMerge> mergeCPDataArgs;
rc = fDbrm->bulkSetHWMAndCP(allHwm, cpInfos, mergeCPDataArgs, txnID.id); rc = fDbrm->bulkSetHWMAndCP(allHwm, cpInfos, mergeCPDataArgs, txnID.id);
fDbrm->takeSnapshot(); fDbrm->takeSnapshot();
@@ -484,10 +524,11 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
return rc; return rc;
bool stateChanged = true; bool stateChanged = true;
TablelockData * tablelockData = TablelockData::makeTablelockData(fSessionID); TablelockData* tablelockData = TablelockData::makeTablelockData(fSessionID);
uint64_t tablelockId = tablelockData->getTablelockId(tableOid); uint64_t tablelockId = tablelockData->getTablelockId(tableOid);
try { try
{
stateChanged = fDbrm->changeState(tablelockId, BRM::CLEANUP); stateChanged = fDbrm->changeState(tablelockId, BRM::CLEANUP);
} }
catch (std::exception&) catch (std::exception&)
@@ -506,17 +547,21 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
bytestream << tableOid; bytestream << tableOid;
msgRecived = 0; msgRecived = 0;
fWEClient->write_to_all(bytestream); fWEClient->write_to_all(bytestream);
while (1) while (1)
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
msgRecived++; 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, 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 //Bulkrollback, rollback blocks, vbrollback, change state, remove meta file
//cout << "In rollBackBatchAutoOnTransaction" << endl; //cout << "In rollBackBatchAutoOnTransaction" << endl;
std::vector<BRM::TableLockInfo> tableLocks; std::vector<BRM::TableLockInfo> tableLocks;
tableLocks = fDbrm->getAllTableLocks(); tableLocks = fDbrm->getAllTableLocks();
//cout << " Got all tablelocks" << endl; //cout << " Got all tablelocks" << endl;
unsigned idx=0; unsigned idx = 0;
string ownerName ("DMLProc batchinsert"); string ownerName ("DMLProc batchinsert");
uint64_t tableLockId = 0; uint64_t tableLockId = 0;
int rc = 0; int rc = 0;
for (; idx<tableLocks.size(); idx++)
for (; idx < tableLocks.size(); idx++)
{ {
if ((tableLocks[idx].ownerName == ownerName) && (tableLocks[idx].tableOID == tableOid)) 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 // 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 // while inserting. Not an error during rollback, but we don't
// want to do anything. // want to do anything.
return rc; return rc;
} }
//cout << "sending to WES" << endl; //cout << "sending to WES" << endl;
ByteStream bytestream; ByteStream bytestream;
fWEClient->addQueue(uniqueId); fWEClient->addQueue(uniqueId);
@@ -569,12 +616,15 @@ int DMLPackageProcessor::rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::
boost::shared_ptr<messageqcpp::ByteStream> bsIn; boost::shared_ptr<messageqcpp::ByteStream> bsIn;
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
ByteStream::byte tmp8; ByteStream::byte tmp8;
//cout << "waiting for reply from WES" << endl; //cout << "waiting for reply from WES" << endl;
while (1) while (1)
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
@@ -582,10 +632,13 @@ int DMLPackageProcessor::rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::
//cout << "erroring out remove queue id " << uniqueId << endl; //cout << "erroring out remove queue id " << uniqueId << endl;
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = tmp8; rc = tmp8;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
//cout << "erroring out remove queue id " << uniqueId << endl; //cout << "erroring out remove queue id " << uniqueId << endl;
@@ -595,11 +648,14 @@ int DMLPackageProcessor::rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::
msgRecived++; msgRecived++;
} }
} }
if (rc == 0) //change table lock state if (rc == 0) //change table lock state
{ {
bool stateChanged = true; bool stateChanged = true;
//cout << "changing tablelock state" << endl; //cout << "changing tablelock state" << endl;
try { try
{
stateChanged = fDbrm->changeState(tableLockId, BRM::CLEANUP); stateChanged = fDbrm->changeState(tableLockId, BRM::CLEANUP);
} }
catch (std::exception&) catch (std::exception&)
@@ -607,53 +663,61 @@ int DMLPackageProcessor::rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::
errorMsg = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); errorMsg = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
stateChanged = false; stateChanged = false;
} }
if (!stateChanged) if (!stateChanged)
{ {
rc = 1; rc = 1;
} }
} }
if ( rc !=0 ) if ( rc != 0 )
return rc; return rc;
bytestream.restart(); bytestream.restart();
bytestream << (ByteStream::byte)WE_SVR_BATCH_AUTOON_REMOVE_META; bytestream << (ByteStream::byte)WE_SVR_BATCH_AUTOON_REMOVE_META;
bytestream << uniqueId; bytestream << uniqueId;
bytestream << tableOid; bytestream << tableOid;
msgRecived = 0; msgRecived = 0;
fWEClient->write_to_all(bytestream); fWEClient->write_to_all(bytestream);
while (1) while (1)
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
//cout << "erroring out remove queue id " << uniqueId << endl; //cout << "erroring out remove queue id " << uniqueId << endl;
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
msgRecived++; msgRecived++;
} }
} }
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
return rc; 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; std::vector<BRM::TableLockInfo> tableLocks;
tableLocks = fDbrm->getAllTableLocks(); tableLocks = fDbrm->getAllTableLocks();
//cout << " Got all tablelocks" << endl; //cout << " Got all tablelocks" << endl;
unsigned idx=0; unsigned idx = 0;
string ownerName ("DMLProc batchinsert"); string ownerName ("DMLProc batchinsert");
uint64_t tableLockId = 0; uint64_t tableLockId = 0;
int rc = 0; int rc = 0;
boost::shared_ptr<messageqcpp::ByteStream> bsIn; boost::shared_ptr<messageqcpp::ByteStream> bsIn;
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
ByteStream::byte tmp8; ByteStream::byte tmp8;
for (; idx<tableLocks.size(); idx++)
for (; idx < tableLocks.size(); idx++)
{ {
if ((tableLocks[idx].ownerName == ownerName) && (tableLocks[idx].tableOID == tableOid)) 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 // 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 // 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; bool stateChanged = true;
//cout << "changing tablelock state" << endl; //cout << "changing tablelock state" << endl;
try { try
{
stateChanged = fDbrm->changeState(tableLockId, BRM::CLEANUP); stateChanged = fDbrm->changeState(tableLockId, BRM::CLEANUP);
} }
catch (std::exception&) catch (std::exception&)
@@ -680,11 +746,13 @@ int DMLPackageProcessor::commitBatchAutoOffTransaction(uint64_t uniqueId, BRM::T
errorMsg = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); errorMsg = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
stateChanged = false; stateChanged = false;
} }
if (!stateChanged) if (!stateChanged)
{ {
rc = 1; rc = 1;
} }
if ( rc !=0 )
if ( rc != 0 )
return rc; return rc;
ByteStream bytestream; ByteStream bytestream;
@@ -694,27 +762,32 @@ int DMLPackageProcessor::commitBatchAutoOffTransaction(uint64_t uniqueId, BRM::T
bytestream << tableOid; bytestream << tableOid;
uint32_t msgRecived = 0; uint32_t msgRecived = 0;
fWEClient->write_to_all(bytestream); fWEClient->write_to_all(bytestream);
while (1) while (1)
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
msgRecived++; msgRecived++;
} }
} }
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
return rc; return rc;
} }
int DMLPackageProcessor::rollBackBatchAutoOffTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID, 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; ByteStream bytestream;
fWEClient->addQueue(uniqueId); fWEClient->addQueue(uniqueId);
@@ -734,17 +807,22 @@ int DMLPackageProcessor::rollBackBatchAutoOffTransaction(uint64_t uniqueId, BRM:
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = tmp8; rc = tmp8;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
break; break;
@@ -757,7 +835,7 @@ int DMLPackageProcessor::rollBackBatchAutoOffTransaction(uint64_t uniqueId, BRM:
return rc; 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; //cout <<"in flushDataFiles" << endl;
ByteStream bytestream; ByteStream bytestream;
@@ -773,21 +851,28 @@ int DMLPackageProcessor::flushDataFiles (int rcIn, std::map<FID,FID> & columnOid
int rc = 0; int rc = 0;
ByteStream::byte tmp8; ByteStream::byte tmp8;
std::string errorMsg; std::string errorMsg;
try {
try
{
while (1) while (1)
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = tmp8; rc = tmp8;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
break; break;
} }
@@ -796,7 +881,8 @@ int DMLPackageProcessor::flushDataFiles (int rcIn, std::map<FID,FID> & columnOid
} }
} }
} }
catch (std::exception&) { catch (std::exception&)
{
} }
return rc; return rc;
@@ -817,21 +903,28 @@ int DMLPackageProcessor::endTransaction (uint64_t uniqueId, BRM::TxnID txnID, bo
int rc = 0; int rc = 0;
ByteStream::byte tmp8; ByteStream::byte tmp8;
std::string errorMsg; std::string errorMsg;
try {
try
{
while (1) while (1)
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
rc = tmp8; rc = tmp8;
if (rc != 0) {
if (rc != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
break; break;
} }
@@ -840,7 +933,8 @@ int DMLPackageProcessor::endTransaction (uint64_t uniqueId, BRM::TxnID txnID, bo
} }
} }
} }
catch (std::exception&) { catch (std::exception&)
{
} }
return rc; return rc;

View File

@@ -119,7 +119,7 @@ public:
std::string miniStats; std::string miniStats;
querystats::QueryStats stats; querystats::QueryStats stats;
DMLResult():result(NO_ERROR),rowCount(0){}; DMLResult(): result(NO_ERROR), rowCount(0) {};
}; };
/** @brief a structure to hold a date /** @brief a structure to hold a date
*/ */
@@ -130,7 +130,13 @@ public:
unsigned month : 4; unsigned month : 4;
unsigned year : 16; unsigned year : 16;
// NULL column value = 0xFFFFFFFE // 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 /** @brief a structure to hold a datetime
*/ */
@@ -144,15 +150,24 @@ public:
unsigned month : 4; unsigned month : 4;
unsigned year : 16; unsigned year : 16;
// NULL column value = 0xFFFFFFFFFFFFFFFE // NULL column value = 0xFFFFFFFFFFFFFFFE
dateTime( ) { year = 0xFFFF; month = 0xF; day = 0x3F; hour = 0x3F; minute = 0x3F; second = 0x3F; dateTime( )
msecond = 0xFFFFE; } {
year = 0xFFFF;
month = 0xF;
day = 0x3F;
hour = 0x3F;
minute = 0x3F;
second = 0x3F;
msecond = 0xFFFFE;
}
}; };
/** @brief ctor /** @brief ctor
*/ */
DMLPackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : fEC(0), DMLLoggingId(21), fRollbackPending(false), fDebugLevel(NONE) DMLPackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : fEC(0), DMLLoggingId(21), fRollbackPending(false), fDebugLevel(NONE)
{ {
try { try
{
fWEClient = new WriteEngine::WEClients(WriteEngine::WEClients::DMLPROC); fWEClient = new WriteEngine::WEClients(WriteEngine::WEClients::DMLPROC);
//std::cout << "In DMLPackageProcessor constructor " << this << std::endl; //std::cout << "In DMLPackageProcessor constructor " << this << std::endl;
fPMCount = fWEClient->getPmCount(); fPMCount = fWEClient->getPmCount();
@@ -162,7 +177,7 @@ public:
std::cout << "Cannot make connection to WES" << std::endl; std::cout << "Cannot make connection to WES" << std::endl;
} }
oam::OamCache * oamCache = oam::OamCache::makeOamCache(); oam::OamCache* oamCache = oam::OamCache::makeOamCache();
fDbRootPMMap = oamCache->getDBRootToPMMap(); fDbRootPMMap = oamCache->getDBRootToPMMap();
fDbrm = aDbrm; fDbrm = aDbrm;
fSessionID = sid; fSessionID = sid;
@@ -179,22 +194,34 @@ public:
/** @brief Is it required to debug /** @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 * @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); //int rollBackTransaction(uint64_t uniqueId, uint32_t txnID, uint32_t sessionID, std::string & errorMsg);
/** /**
* @brief Set debug level * @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 * @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 /** @brief process the dml package
* *
@@ -202,11 +229,14 @@ public:
*/ */
virtual DMLResult processPackage(dmlpackage::CalpontDMLPackage& cpackage) = 0; 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 * @brief convert a columns data, represnted as a string, to it's native
* data type * data type
@@ -262,11 +292,17 @@ public:
/** @brief Access the rollback pending flag /** @brief Access the rollback pending flag
*/ */
bool getRollbackPending() {return fRollbackPending;} bool getRollbackPending()
{
return fRollbackPending;
}
/** @brief Set the rollback pending flag /** @brief Set the rollback pending flag
*/ */
void setRollbackPending(bool rollback) {fRollbackPending = rollback;} void setRollbackPending(bool rollback)
{
fRollbackPending = rollback;
}
protected: protected:
/** @brief update the indexes on the target table /** @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 * @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, 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, std::vector<WriteEngine::RID> ridList,
WriteEngine::ColValueList& colValuesList, std::vector<std::string>& colNameList, const char updateFlag, WriteEngine::ColValueList& colValuesList, std::vector<std::string>& colNameList, const char updateFlag,
std::vector<dicStrValues>& dicStrValCols ); std::vector<dicStrValues>& dicStrValCols );
@@ -365,7 +401,7 @@ protected:
const std::string& schema, const std::string& schema,
const std::string& table, const std::string& table,
std::vector<WriteEngine::RID>& rowIDList, std::vector<WriteEngine::RID>& rowIDList,
std::vector<void *>& oldValueList, std::vector<void*>& oldValueList,
DMLResult& result ); DMLResult& result );
/** @brief validate that the rows deleted does not violate a reference (foreign key) constraint /** @brief validate that the rows deleted does not violate a reference (foreign key) constraint
@@ -381,7 +417,7 @@ protected:
const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo, const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo,
DMLResult& result ); DMLResult& result );
bool violatesReferenceConstraint_PK( std::vector<void *>& oldValueList, bool violatesReferenceConstraint_PK( std::vector<void*>& oldValueList,
const int totalRows, const int totalRows,
const execplan::CalpontSystemCatalog::ColType& colType, const execplan::CalpontSystemCatalog::ColType& colType,
unsigned int colOffset, unsigned int colOffset,
@@ -463,18 +499,18 @@ protected:
// bool validateNextValue(execplan::CalpontSystemCatalog::ColType colType, int64_t value, bool & offByOne); // 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 commitTransaction(uint64_t uniqueId, BRM::TxnID txnID);
int commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::TxnID txnID, const uint32_t tableOid, std::string & errorMsg); 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 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 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 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); int endTransaction (uint64_t uniqueId, BRM::TxnID txnID, bool success);
/** @brief the Session Manager interface /** @brief the Session Manager interface
*/ */
execplan::SessionManager fSessionManager; execplan::SessionManager fSessionManager;
joblist::DistributedEngineComm *fEC; joblist::DistributedEngineComm* fEC;
joblist::ResourceManager* fRM; joblist::ResourceManager* fRM;
char* strlower(char* in); char* strlower(char* in);
uint32_t fSessionID; uint32_t fSessionID;
@@ -505,7 +541,7 @@ private:
template <class T> template <class T>
bool from_string(T& t, bool from_string(T& t,
const std::string& s, const std::string& s,
std::ios_base& (*f)(std::ios_base&)) std::ios_base & (*f)(std::ios_base&))
{ {
std::istringstream iss(s); std::istringstream iss(s);
return !(iss >> f >> t).fail(); return !(iss >> f >> t).fail();

View File

@@ -31,14 +31,15 @@
using namespace dmlpackage; using namespace dmlpackage;
namespace dmlpackageprocessor { namespace dmlpackageprocessor
{
DMLPackageProcessor* DMLPackageProcessorFactory:: DMLPackageProcessor* DMLPackageProcessorFactory::
makePackageProcessor(int packageType, dmlpackage::CalpontDMLPackage& cpackage) makePackageProcessor(int packageType, dmlpackage::CalpontDMLPackage& cpackage)
{ {
DMLPackageProcessor* dmlProcPtr = 0; DMLPackageProcessor* dmlProcPtr = 0;
switch( packageType ) switch ( packageType )
{ {
case DML_INSERT: case DML_INSERT:
dmlProcPtr = new InsertPackageProcessor(); dmlProcPtr = new InsertPackageProcessor();

View File

@@ -33,16 +33,18 @@
#define EXPORT #define EXPORT
#endif #endif
namespace dmlpackageprocessor { namespace dmlpackageprocessor
{
/** @brief create a DMLPackageProcessor object from a CalpontDMLPackage object /** @brief create a DMLPackageProcessor object from a CalpontDMLPackage object
* *
*/ */
class DMLPackageProcessorFactory { class DMLPackageProcessorFactory
{
public: public:
/** @brief static DMLPackageProcessor constructor method /** @brief static DMLPackageProcessor constructor method
* *
* @param packageType the DML Package type * @param packageType the DML Package type
* @param cpackage the CalpontDMLPackage from which the DMLPackageProcessor is constructed * @param cpackage the CalpontDMLPackage from which the DMLPackageProcessor is constructed

View File

@@ -51,8 +51,8 @@ using namespace messageqcpp;
namespace dmlpackageprocessor namespace dmlpackageprocessor
{ {
DMLPackageProcessor::DMLResult InsertPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage & cpackage) DMLPackageProcessor::DMLResult InsertPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
{ {
SUMMARY_INFO("InsertPackageProcessor::processPackage"); SUMMARY_INFO("InsertPackageProcessor::processPackage");
DMLResult result; DMLResult result;
@@ -62,14 +62,14 @@ namespace dmlpackageprocessor
txnid.id = cpackage.get_TxnID(); txnid.id = cpackage.get_TxnID();
txnid.valid = true; txnid.valid = true;
fSessionID = cpackage.get_SessionID(); fSessionID = cpackage.get_SessionID();
DMLTable *tablePtr = cpackage.get_Table(); DMLTable* tablePtr = cpackage.get_Table();
LoggingID logid( DMLLoggingId, fSessionID, txnid.id); LoggingID logid( DMLLoggingId, fSessionID, txnid.id);
logging::Message::Args args1; logging::Message::Args args1;
logging::Message msg(1); logging::Message msg(1);
args1.add("Start SQL statement: "); args1.add("Start SQL statement: ");
ostringstream oss; ostringstream oss;
oss << cpackage.get_SQLStatement() << "; |" << tablePtr->get_SchemaName()<<"|"; oss << cpackage.get_SQLStatement() << "; |" << tablePtr->get_SchemaName() << "|";
args1.add(oss.str()); args1.add(oss.str());
msg.format( args1 ); msg.format( args1 );
@@ -80,8 +80,10 @@ namespace dmlpackageprocessor
//std::map<uint32_t,uint32_t> oids; //std::map<uint32_t,uint32_t> oids;
VERBOSE_INFO("Processing Insert DML Package..."); VERBOSE_INFO("Processing Insert DML Package...");
uint64_t uniqueId = 0; uint64_t uniqueId = 0;
//Bug 5070. Added exception handling //Bug 5070. Added exception handling
try { try
{
uniqueId = fDbrm->getUnique64(); uniqueId = fDbrm->getUnique64();
} }
catch (std::exception& ex) catch (std::exception& ex)
@@ -106,16 +108,17 @@ namespace dmlpackageprocessor
fSessionManager.rolledback(txnid); fSessionManager.rolledback(txnid);
return result; return result;
} }
uint64_t tableLockId = 0; uint64_t tableLockId = 0;
int rc = 0; int rc = 0;
std::string errorMsg; std::string errorMsg;
OamCache * oamcache = OamCache::makeOamCache(); OamCache* oamcache = OamCache::makeOamCache();
std::vector<int> moduleIds = oamcache->getModuleIds(); std::vector<int> moduleIds = oamcache->getModuleIds();
std::vector<uint32_t> pms; std::vector<uint32_t> pms;
try 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]); pms.push_back((uint32_t)moduleIds[i]);
} }
@@ -126,7 +129,8 @@ namespace dmlpackageprocessor
//cout << "DMLProc using syscatptr:sessionid = " << systemCatalogPtr <<":" << fSessionID<< endl; //cout << "DMLProc using syscatptr:sessionid = " << systemCatalogPtr <<":" << fSessionID<< endl;
CalpontSystemCatalog::TableName tableName; CalpontSystemCatalog::TableName tableName;
execplan::CalpontSystemCatalog::ROPair roPair; execplan::CalpontSystemCatalog::ROPair roPair;
TablelockData * tablelockData = TablelockData::makeTablelockData(fSessionID); TablelockData* tablelockData = TablelockData::makeTablelockData(fSessionID);
if (0 != tablePtr) if (0 != tablePtr)
{ {
//check table lock //check table lock
@@ -137,6 +141,7 @@ namespace dmlpackageprocessor
roPair = systemCatalogPtr->tableRID( tableName ); roPair = systemCatalogPtr->tableRID( tableName );
tableLockId = tablelockData->getTablelockId(roPair.objnum); //check whether this table is locked already for this session tableLockId = tablelockData->getTablelockId(roPair.objnum); //check whether this table is locked already for this session
if (tableLockId == 0) if (tableLockId == 0)
{ {
//cout << "tablelock is not found in cache, getting from dbrm" << endl; //cout << "tablelock is not found in cache, getting from dbrm" << endl;
@@ -146,7 +151,8 @@ namespace dmlpackageprocessor
std::string processName("DMLProc"); std::string processName("DMLProc");
int i = 0; int i = 0;
try { try
{
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnId, BRM::LOADING ); tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnId, BRM::LOADING );
} }
catch (std::exception&) catch (std::exception&)
@@ -163,8 +169,8 @@ namespace dmlpackageprocessor
numTries = waitPeriod * 10; numTries = waitPeriod * 10;
struct timespec rm_ts; struct timespec rm_ts;
rm_ts.tv_sec = sleepTime/1000; rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime%1000 *1000000; rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++) for (; i < numTries; i++)
{ {
@@ -172,14 +178,18 @@ namespace dmlpackageprocessor
Sleep(rm_ts.tv_sec * 1000); Sleep(rm_ts.tv_sec * 1000);
#else #else
struct timespec abs_ts; struct timespec abs_ts;
do do
{ {
abs_ts.tv_sec = rm_ts.tv_sec; abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec; abs_ts.tv_nsec = rm_ts.tv_nsec;
} }
while(nanosleep(&abs_ts,&rm_ts) < 0); while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif #endif
try {
try
{
processID = ::getpid(); processID = ::getpid();
txnId = txnid.id; txnId = txnid.id;
sessionId = fSessionID; sessionId = fSessionID;
@@ -194,6 +204,7 @@ namespace dmlpackageprocessor
if (tableLockId > 0) if (tableLockId > 0)
break; break;
} }
if (i >= numTries) //error out if (i >= numTries) //error out
{ {
result.result = INSERT_ERROR; result.result = INSERT_ERROR;
@@ -203,7 +214,7 @@ namespace dmlpackageprocessor
args.add(processName); args.add(processName);
args.add((uint64_t)processID); args.add((uint64_t)processID);
args.add(sessionId); 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 // 3. Map the selected DBRoot to the corresponding PM
CalpontSystemCatalog::RIDList ridList = systemCatalogPtr->columnRIDs(tableName, true); CalpontSystemCatalog::RIDList ridList = systemCatalogPtr->columnRIDs(tableName, true);
std::vector<BRM::EmDbRootHWMInfo_v> allInfo (pms.size()); std::vector<BRM::EmDbRootHWMInfo_v> allInfo (pms.size());
for (unsigned i = 0; i < pms.size(); i++) for (unsigned i = 0; i < pms.size(); i++)
{ {
rc = fDbrm->getDbRootHWMInfo((ridList[0].objnum), pms[i], allInfo[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; result.result = INSERT_ERROR;
ostringstream oss; ostringstream oss;
@@ -236,11 +249,12 @@ namespace dmlpackageprocessor
// have 0 blocks, then we select the first DBRoot // have 0 blocks, then we select the first DBRoot
BRM::EmDbRootHWMInfo tmp; BRM::EmDbRootHWMInfo tmp;
bool tmpSet = false; 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]; BRM::EmDbRootHWMInfo_v emDbRootHWMInfos = allInfo[i];
for (unsigned j=0; j < emDbRootHWMInfos.size(); j++) for (unsigned j = 0; j < emDbRootHWMInfos.size(); j++)
{ {
if (!tmpSet) if (!tmpSet)
{ {
@@ -260,6 +274,7 @@ namespace dmlpackageprocessor
// Select the PM to receive the row // Select the PM to receive the row
uint32_t dbroot; uint32_t dbroot;
if (tmpSet) if (tmpSet)
{ {
dbroot = tmp.dbRoot; dbroot = tmp.dbRoot;
@@ -295,23 +310,28 @@ namespace dmlpackageprocessor
boost::shared_ptr<messageqcpp::ByteStream> bsIn; boost::shared_ptr<messageqcpp::ByteStream> bsIn;
ByteStream::byte rc1; ByteStream::byte rc1;
try try
{ {
fWEClient->write(bytestream, (uint32_t)pmNum); fWEClient->write(bytestream, (uint32_t)pmNum);
#ifdef IDB_DML_DEBUG #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 #endif
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES"; errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
} }
else { else
{
*bsIn >> rc1; *bsIn >> rc1;
if (rc1 != 0) {
if (rc1 != 0)
{
*bsIn >> errorMsg; *bsIn >> errorMsg;
rc = rc1; rc = rc1;
} }
@@ -321,7 +341,7 @@ cout << "Single insert sending WE_SVR_SINGLE_INSERT to pm " << pmNum << endl;
catch (runtime_error& ex) //write error catch (runtime_error& ex) //write error
{ {
#ifdef IDB_DML_DEBUG #ifdef IDB_DML_DEBUG
cout << "Single insert got exception" << ex.what() << endl; cout << "Single insert got exception" << ex.what() << endl;
#endif #endif
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
errorMsg = ex.what(); errorMsg = ex.what();
@@ -331,9 +351,10 @@ cout << "Single insert got exception" << ex.what() << endl;
errorMsg = "Caught ... exception during single row insert"; errorMsg = "Caught ... exception during single row insert";
rc = NETWORK_ERROR; rc = NETWORK_ERROR;
#ifdef IDB_DML_DEBUG #ifdef IDB_DML_DEBUG
cout << "Single insert got unknown exception" << endl; cout << "Single insert got unknown exception" << endl;
#endif #endif
} }
// Log the insert statement. // Log the insert statement.
LoggingID logid( DMLLoggingId, fSessionID, txnid.id); LoggingID logid( DMLLoggingId, fSessionID, txnid.id);
logging::Message::Args args1; logging::Message::Args args1;
@@ -342,10 +363,10 @@ cout << "Single insert got unknown exception" << endl;
msg.format( args1 ); msg.format( args1 );
Logger logger(logid.fSubsysID); Logger logger(logid.fSubsysID);
logger.logMessage(LOG_TYPE_DEBUG, msg, logid); 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; cerr << "InsertPackageProcessor::processPackage: " << ex.what() << endl;
@@ -364,7 +385,7 @@ cout << "Single insert got unknown exception" << endl;
errorMsg = ex.what(); errorMsg = ex.what();
} }
} }
catch(...) catch (...)
{ {
cerr << "InsertPackageProcessor::processPackage: caught unknown exception!" << endl; cerr << "InsertPackageProcessor::processPackage: caught unknown exception!" << endl;
logging::Message::Args args; logging::Message::Args args;
@@ -379,7 +400,7 @@ cout << "Single insert got unknown exception" << endl;
result.message = message; result.message = message;
} }
if (( rc !=0) && (rc != IDBRANGE_WARNING)) if (( rc != 0) && (rc != IDBRANGE_WARNING))
{ {
logging::Message::Args args; logging::Message::Args args;
logging::Message message(1); logging::Message message(1);
@@ -406,7 +427,7 @@ cout << "Single insert got unknown exception" << endl;
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
VERBOSE_INFO("Finished Processing Insert DML Package"); VERBOSE_INFO("Finished Processing Insert DML Package");
return result; return result;
} }
} // namespace dmlpackageprocessor } // namespace dmlpackageprocessor

View File

@@ -48,7 +48,8 @@ class InsertPackageProcessor : public DMLPackageProcessor
{ {
public: 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 /** @brief process an InsertDMLPackage
* *

View File

@@ -59,6 +59,7 @@ void TablelockData::removeTablelockData(uint32_t sessionID)
{ {
boost::mutex::scoped_lock lock(map_mutex); boost::mutex::scoped_lock lock(map_mutex);
TablelockDataMap::iterator it = fTablelockDataMap.find(sessionID); TablelockDataMap::iterator it = fTablelockDataMap.find(sessionID);
if (it != fTablelockDataMap.end()) if (it != fTablelockDataMap.end())
{ {
delete (*it).second; delete (*it).second;
@@ -84,14 +85,16 @@ uint64_t TablelockData::getTablelockId(uint32_t tableOid)
boost::mutex::scoped_lock lk(fOIDTablelock); boost::mutex::scoped_lock lk(fOIDTablelock);
uint64_t tablelockId = 0; uint64_t tablelockId = 0;
OIDTablelock::iterator it = fOIDTablelockMap.find(tableOid); OIDTablelock::iterator it = fOIDTablelockMap.find(tableOid);
if (it != fOIDTablelockMap.end()) if (it != fOIDTablelockMap.end())
{ {
tablelockId = it->second; tablelockId = it->second;
} }
return tablelockId; return tablelockId;
} }
TablelockData::OIDTablelock & TablelockData::getOidTablelockMap() TablelockData::OIDTablelock& TablelockData::getOidTablelockMap()
{ {
boost::mutex::scoped_lock lk(fOIDTablelock); boost::mutex::scoped_lock lk(fOIDTablelock);

View File

@@ -45,7 +45,7 @@ public:
EXPORT static void removeTablelockData(uint32_t sessionID = 0); EXPORT static void removeTablelockData(uint32_t sessionID = 0);
EXPORT void setTablelock(uint32_t tableOid, uint64_t tablelockId); EXPORT void setTablelock(uint32_t tableOid, uint64_t tablelockId);
EXPORT uint64_t getTablelockId(uint32_t tableOid); EXPORT uint64_t getTablelockId(uint32_t tableOid);
OIDTablelock & getOidTablelockMap(); OIDTablelock& getOidTablelockMap();
private: private:
/** Constuctors */ /** Constuctors */

View File

@@ -458,21 +458,23 @@ public:
ddlpackage::SqlParser parser; ddlpackage::SqlParser parser;
parser.Parse(createText.c_str()); parser.Parse(createText.c_str());
if (parser.Good()) if (parser.Good())
{ {
const ddlpackage::ParseTree &ptree = parser.GetParseTree(); const ddlpackage::ParseTree& ptree = parser.GetParseTree();
try try
{ {
ddlpackageprocessor::CreateTableProcessor processor; ddlpackageprocessor::CreateTableProcessor processor;
processor.setDebugLevel(ddlpackageprocessor::CreateTableProcessor::VERBOSE); processor.setDebugLevel(ddlpackageprocessor::CreateTableProcessor::VERBOSE);
ddlpackage::SqlStatement &stmt = *ptree.fList[0]; ddlpackage::SqlStatement& stmt = *ptree.fList[0];
ddlpackageprocessor::CreateTableProcessor::DDLResult result; ddlpackageprocessor::CreateTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<ddlpackage::CreateTableStatement&>(stmt)); result = processor.processPackage(dynamic_cast<ddlpackage::CreateTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl; std::cout << "return: " << result.result << std::endl;
} }
catch(...) catch (...)
{ {
throw; throw;
@@ -493,9 +495,11 @@ void destroySemaphores()
semkey = 0x2149bdd2; semkey = 0x2149bdd2;
sems = semget(semkey, 2, 0666); sems = semget(semkey, 2, 0666);
if (sems != -1) if (sems != -1)
{ {
err = semctl(sems, 0, IPC_RMID); err = semctl(sems, 0, IPC_RMID);
if (err == -1) if (err == -1)
perror("tdriver: semctl"); perror("tdriver: semctl");
} }
@@ -508,9 +512,11 @@ void destroyShmseg()
shmkey = 0x2149bdd2; shmkey = 0x2149bdd2;
shms = shmget(shmkey, 0, 0666); shms = shmget(shmkey, 0, 0666);
if (shms != -1) if (shms != -1)
{ {
err = shmctl(shms, IPC_RMID, NULL); err = shmctl(shms, IPC_RMID, NULL);
if (err == -1 && errno != EINVAL) if (err == -1 && errno != EINVAL)
{ {
perror("tdriver: shmctl"); perror("tdriver: shmctl");
@@ -650,7 +656,7 @@ public:
cout << "\nDML statement:" << dmlStatement.c_str() << endl; cout << "\nDML statement:" << dmlStatement.c_str() << endl;
VendorDMLStatement dmlStmt(dmlStatement,1); VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt); CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage ); CPPUNIT_ASSERT( 0 != pDMLPackage );
@@ -676,7 +682,7 @@ public:
cout << "\nDML statement:" << dmlStatement.c_str() << endl; cout << "\nDML statement:" << dmlStatement.c_str() << endl;
VendorDMLStatement dmlStmt(dmlStatement,1); VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt); CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage ); CPPUNIT_ASSERT( 0 != pDMLPackage );
@@ -708,7 +714,7 @@ public:
CPPUNIT_ASSERT( DML_INSERT == package_type ); CPPUNIT_ASSERT( DML_INSERT == package_type );
InsertDMLPackage *pObject = new InsertDMLPackage(); InsertDMLPackage* pObject = new InsertDMLPackage();
pObject->read( bs ); pObject->read( bs );
@@ -720,6 +726,7 @@ public:
pkgProcPtr->setDebugLevel(DMLPackageProcessor::VERBOSE); pkgProcPtr->setDebugLevel(DMLPackageProcessor::VERBOSE);
DMLPackageProcessor::DMLResult result = pkgProcPtr->processPackage( *pObject ); DMLPackageProcessor::DMLResult result = pkgProcPtr->processPackage( *pObject );
if ( DMLPackageProcessor::NO_ERROR != result.result ) if ( DMLPackageProcessor::NO_ERROR != result.result )
{ {
cout << "Insert failed!" << endl; cout << "Insert failed!" << endl;
@@ -770,7 +777,7 @@ public:
cout << "\nDML statement:" << dmlStatement.c_str() << endl; cout << "\nDML statement:" << dmlStatement.c_str() << endl;
VendorDMLStatement dmlStmt(dmlStatement,1); VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt); CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage ); CPPUNIT_ASSERT( 0 != pDMLPackage );
@@ -801,7 +808,7 @@ public:
CPPUNIT_ASSERT( DML_DELETE == package_type ); CPPUNIT_ASSERT( DML_DELETE == package_type );
DeleteDMLPackage *pObject = new DeleteDMLPackage(); DeleteDMLPackage* pObject = new DeleteDMLPackage();
pObject->read( bs ); pObject->read( bs );
@@ -822,6 +829,7 @@ public:
ml.logDebugMessage( result.message ); ml.logDebugMessage( result.message );
} }
delete pkgProcPtr; delete pkgProcPtr;
delete pObject; delete pObject;
@@ -837,7 +845,7 @@ public:
cout << "\nDML statement:" << dmlStatement.c_str() << endl; cout << "\nDML statement:" << dmlStatement.c_str() << endl;
VendorDMLStatement dmlStmt(dmlStatement,1); VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt); CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage ); CPPUNIT_ASSERT( 0 != pDMLPackage );
@@ -866,6 +874,7 @@ public:
ByteStream bytestream; ByteStream bytestream;
std::vector<std::string>::const_iterator iter = commands.begin(); std::vector<std::string>::const_iterator iter = commands.begin();
while (iter != commands.end()) while (iter != commands.end())
{ {
std::string command = *iter; std::string command = *iter;
@@ -873,6 +882,7 @@ public:
VendorDMLStatement dml_command(command, 1); VendorDMLStatement dml_command(command, 1);
CalpontDMLPackage* dmlCommandPkgPtr = CalpontDMLFactory::makeCalpontDMLPackage(dml_command); CalpontDMLPackage* dmlCommandPkgPtr = CalpontDMLFactory::makeCalpontDMLPackage(dml_command);
if (dmlCommandPkgPtr) if (dmlCommandPkgPtr)
{ {
cout << "CalpontDMLFactory::makeCalpontDMLPackage: success" << endl; cout << "CalpontDMLFactory::makeCalpontDMLPackage: success" << endl;
@@ -900,7 +910,7 @@ public:
CPPUNIT_ASSERT( DML_COMMAND == package_type ); CPPUNIT_ASSERT( DML_COMMAND == package_type );
CommandDMLPackage *pObject = new CommandDMLPackage(); CommandDMLPackage* pObject = new CommandDMLPackage();
pObject->read( bs ); pObject->read( bs );
@@ -921,6 +931,7 @@ public:
ml.logDebugMessage( result.message ); ml.logDebugMessage( result.message );
} }
delete pkgProcPtr; delete pkgProcPtr;
delete pObject; delete pObject;
} }
@@ -967,7 +978,7 @@ public:
CPPUNIT_ASSERT( DML_UPDATE == package_type ); CPPUNIT_ASSERT( DML_UPDATE == package_type );
UpdateDMLPackage *pObject = new UpdateDMLPackage(); UpdateDMLPackage* pObject = new UpdateDMLPackage();
pObject->read( bs ); pObject->read( bs );
@@ -1002,13 +1013,13 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DMLPackageProcessorTest );
#include <cppunit/extensions/TestFactoryRegistry.h> #include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h> #include <cppunit/ui/text/TestRunner.h>
int main( int argc, char **argv) int main( int argc, char** argv)
{ {
// Uncomment before running tests // Uncomment before running tests
//setUp(); //setUp();
CppUnit::TextUi::TestRunner runner; CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry(); CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() ); runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false ); bool wasSuccessful = runner.run( "", false );

139
dbcon/dmlpackageproc/updatepackageprocessor.cpp Executable file → Normal file
View File

@@ -78,10 +78,12 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
txnid.valid = true; txnid.valid = true;
fSessionID = cpackage.get_SessionID(); fSessionID = cpackage.get_SessionID();
VERBOSE_INFO("Processing Update DML Package..."); VERBOSE_INFO("Processing Update DML Package...");
TablelockData * tablelockData = TablelockData::makeTablelockData(fSessionID); TablelockData* tablelockData = TablelockData::makeTablelockData(fSessionID);
uint64_t uniqueId = 0; uint64_t uniqueId = 0;
//Bug 5070. Added exception handling //Bug 5070. Added exception handling
try { try
{
uniqueId = fDbrm->getUnique64(); uniqueId = fDbrm->getUnique64();
} }
catch (std::exception& ex) catch (std::exception& ex)
@@ -116,6 +118,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
tableName.table = tablePtr->get_TableName(); tableName.table = tablePtr->get_TableName();
fWEClient->addQueue(uniqueId); fWEClient->addQueue(uniqueId);
execplan::CalpontSystemCatalog::ROPair roPair; execplan::CalpontSystemCatalog::ROPair roPair;
//#ifdef PROFILE //#ifdef PROFILE
// StopWatch timer; // StopWatch timer;
//#endif //#endif
@@ -126,7 +129,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
logging::Message msg(1); logging::Message msg(1);
args1.add("Start SQL statement: "); args1.add("Start SQL statement: ");
ostringstream oss; ostringstream oss;
oss << cpackage.get_SQLStatement() << "|" << tablePtr->get_SchemaName()<<"|"; oss << cpackage.get_SQLStatement() << "|" << tablePtr->get_SchemaName() << "|";
args1.add(oss.str()); args1.add(oss.str());
msg.format( args1 ); msg.format( args1 );
logging::Logger logger(logid.fSubsysID); logging::Logger logger(logid.fSubsysID);
@@ -134,10 +137,12 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
VERBOSE_INFO("The table name is:"); VERBOSE_INFO("The table name is:");
VERBOSE_INFO(tablePtr->get_TableName()); VERBOSE_INFO(tablePtr->get_TableName());
if (0 != tablePtr) if (0 != tablePtr)
{ {
// get the row(s) from the table // get the row(s) from the table
RowList rows = tablePtr->get_RowList(); RowList rows = tablePtr->get_RowList();
if (rows.size() == 0) if (rows.size() == 0)
{ {
SUMMARY_INFO("No row to update!"); SUMMARY_INFO("No row to update!");
@@ -147,6 +152,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
roPair = systemCatalogPtr->tableRID(tableName); roPair = systemCatalogPtr->tableRID(tableName);
tableLockId = tablelockData->getTablelockId(roPair.objnum); //check whether this table is locked already for this session tableLockId = tablelockData->getTablelockId(roPair.objnum); //check whether this table is locked already for this session
if (tableLockId == 0) if (tableLockId == 0)
{ {
//cout << "tablelock is not found in cache, getting from dbrm" << endl; //cout << "tablelock is not found in cache, getting from dbrm" << endl;
@@ -155,15 +161,17 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
int32_t sessionId = fSessionID; int32_t sessionId = fSessionID;
std::string processName("DMLProc"); std::string processName("DMLProc");
int i = 0; int i = 0;
OamCache * oamcache = OamCache::makeOamCache(); OamCache* oamcache = OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds(); std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms; 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]); pms.push_back((uint32_t)pmList[i]);
} }
try { try
{
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnId, BRM::LOADING ); tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnId, BRM::LOADING );
} }
catch (std::exception&) catch (std::exception&)
@@ -180,8 +188,8 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
numTries = waitPeriod * 10; numTries = waitPeriod * 10;
struct timespec rm_ts; struct timespec rm_ts;
rm_ts.tv_sec = sleepTime/1000; rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime%1000 *1000000; rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++) for (; i < numTries; i++)
{ {
@@ -189,14 +197,18 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
Sleep(rm_ts.tv_sec * 1000); Sleep(rm_ts.tv_sec * 1000);
#else #else
struct timespec abs_ts; struct timespec abs_ts;
do do
{ {
abs_ts.tv_sec = rm_ts.tv_sec; abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec; abs_ts.tv_nsec = rm_ts.tv_nsec;
} }
while(nanosleep(&abs_ts,&rm_ts) < 0); while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif #endif
try {
try
{
processID = ::getpid(); processID = ::getpid();
txnId = txnid.id; txnId = txnid.id;
sessionId = fSessionID; sessionId = fSessionID;
@@ -211,6 +223,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
if (tableLockId > 0) if (tableLockId > 0)
break; break;
} }
if (i >= numTries) //error out if (i >= numTries) //error out
{ {
result.result = UPDATE_ERROR; result.result = UPDATE_ERROR;
@@ -220,16 +233,18 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
args.add(processName); args.add(processName);
args.add((uint64_t)processID); args.add((uint64_t)processID);
args.add(sessionId); 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; //cout << " tablelock is obtained with id " << tableLockId << endl;
tablelockData->setTablelock(roPair.objnum, tableLockId); tablelockData->setTablelock(roPair.objnum, tableLockId);
//@Bug 4491 start AI sequence for autoincrement column //@Bug 4491 start AI sequence for autoincrement column
const CalpontSystemCatalog::RIDList ridList = systemCatalogPtr->columnRIDs(tableName); const CalpontSystemCatalog::RIDList ridList = systemCatalogPtr->columnRIDs(tableName);
CalpontSystemCatalog::RIDList::const_iterator rid_iterator = ridList.begin(); CalpontSystemCatalog::RIDList::const_iterator rid_iterator = ridList.begin();
CalpontSystemCatalog::ColType colType; CalpontSystemCatalog::ColType colType;
while (rid_iterator != ridList.end()) while (rid_iterator != ridList.end())
{ {
// If user hit ctrl+c in the mysql console, this will be true. // 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; result.result = JOB_CANCELED;
break; break;
} }
CalpontSystemCatalog::ROPair roPair = *rid_iterator; CalpontSystemCatalog::ROPair roPair = *rid_iterator;
colType = systemCatalogPtr->colType(roPair.objnum); colType = systemCatalogPtr->colType(roPair.objnum);
if (colType.autoincrement) if (colType.autoincrement)
{ {
try try
@@ -254,10 +271,12 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
throw std::runtime_error(ex.what()); throw std::runtime_error(ex.what());
} }
} }
++rid_iterator; ++rid_iterator;
} }
uint64_t rowsProcessed = 0; uint64_t rowsProcessed = 0;
if (!fRollbackPending) if (!fRollbackPending)
{ {
rowsProcessed = fixUpRows(cpackage, result, uniqueId, roPair.objnum); rowsProcessed = fixUpRows(cpackage, result, uniqueId, roPair.objnum);
@@ -291,6 +310,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
{ {
result.result = UPDATE_ERROR; result.result = UPDATE_ERROR;
} }
result.message = Message(ex.what()); result.message = Message(ex.what());
result.rowCount = 0; result.rowCount = 0;
LoggingID logid( DMLLoggingId, fSessionID, txnid.id); LoggingID logid( DMLLoggingId, fSessionID, txnid.id);
@@ -323,16 +343,19 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
logging::Logger logger(logid.fSubsysID); logging::Logger logger(logid.fSubsysID);
logger.logMessage(LOG_TYPE_DEBUG, msg, logid); logger.logMessage(LOG_TYPE_DEBUG, msg, logid);
} }
// timer.finish(); // timer.finish();
//@Bug 1886,2870 Flush VM cache only once per statement. send to all PMs. //@Bug 1886,2870 Flush VM cache only once per statement. send to all PMs.
//WriteEngineWrapper writeEngine; //WriteEngineWrapper writeEngine;
std::map<uint32_t,uint32_t> oids; std::map<uint32_t, uint32_t> oids;
int rc = 0; int rc = 0;
if (result.result == NO_ERROR || result.result == IDBRANGE_WARNING) if (result.result == NO_ERROR || result.result == IDBRANGE_WARNING)
{ {
if ((rc = flushDataFiles(NO_ERROR, oids, uniqueId, txnid, roPair.objnum)) != NO_ERROR) if ((rc = flushDataFiles(NO_ERROR, oids, uniqueId, txnid, roPair.objnum)) != NO_ERROR)
{ {
cerr << "UpdatePackageProcessor::processPackage: write data to disk failed" << endl; cerr << "UpdatePackageProcessor::processPackage: write data to disk failed" << endl;
if (!fRollbackPending) if (!fRollbackPending)
{ {
logging::Message::Args args; logging::Message::Args args;
@@ -347,6 +370,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
result.message = message; result.message = message;
result.rowCount = 0; result.rowCount = 0;
} }
rc = endTransaction(uniqueId, txnid, false); rc = endTransaction(uniqueId, txnid, false);
} }
else else
@@ -355,6 +379,7 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
rc = endTransaction(uniqueId, txnid, false); rc = endTransaction(uniqueId, txnid, false);
else else
rc = endTransaction(uniqueId, txnid, true); rc = endTransaction(uniqueId, txnid, true);
if (( rc != NO_ERROR) && (!fRollbackPending)) if (( rc != NO_ERROR) && (!fRollbackPending))
{ {
logging::Message::Args args; logging::Message::Args args;
@@ -378,13 +403,14 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
rc = flushDataFiles(result.result, oids, uniqueId, txnid, roPair.objnum); rc = flushDataFiles(result.result, oids, uniqueId, txnid, roPair.objnum);
rc = endTransaction(uniqueId, txnid, false); rc = endTransaction(uniqueId, txnid, false);
} }
//timer.finish(); //timer.finish();
/* if (result.result != IDBRANGE_WARNING) /* if (result.result != IDBRANGE_WARNING)
flushDataFiles(result.result, oids, uniqueId, txnid); flushDataFiles(result.result, oids, uniqueId, txnid);
else else
flushDataFiles(0, oids, uniqueId, txnid); flushDataFiles(0, oids, uniqueId, txnid);
*/ */
if (fRollbackPending) if (fRollbackPending)
{ {
result.result = JOB_CANCELED; result.result = JOB_CANCELED;
@@ -409,20 +435,23 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
uint64_t rowsProcessed = 0; uint64_t rowsProcessed = 0;
uint32_t dbroot = 1; uint32_t dbroot = 1;
bool metaData = false; bool metaData = false;
oam::OamCache * oamCache = oam::OamCache::makeOamCache(); oam::OamCache* oamCache = oam::OamCache::makeOamCache();
std::vector<int> fPMs = oamCache->getModuleIds(); std::vector<int> fPMs = oamCache->getModuleIds();
std::map<unsigned, bool> pmState; std::map<unsigned, bool> pmState;
string emsg; string emsg;
string emsgStr; string emsgStr;
bool err = false; bool err = false;
//boost::scoped_ptr<messageqcpp::MessageQueueClient> fExeMgr; //boost::scoped_ptr<messageqcpp::MessageQueueClient> fExeMgr;
//fExeMgr.reset( new messageqcpp::MessageQueueClient("ExeMgr1")); //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; pmState[fPMs[i]] = true;
} }
//timer.start("ExeMgr"); //timer.start("ExeMgr");
fExeMgr->write(msg); fExeMgr->write(msg);
fExeMgr->write(*(cpackage.get_ExecutionPlan())); fExeMgr->write(*(cpackage.get_ExecutionPlan()));
@@ -430,9 +459,11 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
msg.restart(); msg.restart();
emsgBs.restart(); emsgBs.restart();
msg = fExeMgr->read(); //error handling msg = fExeMgr->read(); //error handling
if (msg.length() == 4) if (msg.length() == 4)
{ {
msg >> qb; msg >> qb;
if (qb != 0) if (qb != 0)
err = true; err = true;
} }
@@ -441,6 +472,7 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
qb = 999; qb = 999;
err = true; err = true;
} }
if (err) if (err)
{ {
logging::Message::Args args; logging::Message::Args args;
@@ -455,6 +487,7 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
} }
emsgBs = fExeMgr->read(); emsgBs = fExeMgr->read();
if (emsgBs.length() == 0) if (emsgBs.length() == 0)
{ {
logging::Message::Args args; logging::Message::Args args;
@@ -469,16 +502,19 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
} }
emsgBs >> emsgStr; emsgBs >> emsgStr;
while (true) while (true)
{ {
if (fRollbackPending) if (fRollbackPending)
{ {
break; break;
} }
msg.restart(); msg.restart();
msgBk.restart(); msgBk.restart();
msg = fExeMgr->read(); msg = fExeMgr->read();
msgBk = msg; msgBk = msg;
if ( msg.length() == 0 ) if ( msg.length() == 0 )
{ {
cerr << "UpdatePackageProcessor::processPackage::fixupRows" << endl; cerr << "UpdatePackageProcessor::processPackage::fixupRows" << endl;
@@ -512,10 +548,12 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
//timer.stop("Meta"); //timer.stop("Meta");
continue; continue;
} }
rgData.deserialize(msg, true); rgData.deserialize(msg, true);
rowGroup->setData(&rgData); rowGroup->setData(&rgData);
//rowGroup->setData(const_cast<uint8_t*>(msg.buf())); //rowGroup->setData(const_cast<uint8_t*>(msg.buf()));
err = (rowGroup->getStatus() != 0); err = (rowGroup->getStatus() != 0);
if (err) if (err)
{ {
//msgBk.advance(rowGroup->getDataSize()); //msgBk.advance(rowGroup->getDataSize());
@@ -530,20 +568,22 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
result.message = message; result.message = message;
DMLResult tmpResult; DMLResult tmpResult;
receiveAll( tmpResult, uniqueId, fPMs, pmState, tableOid); receiveAll( tmpResult, uniqueId, fPMs, pmState, tableOid);
/* qb = 100; /* qb = 100;
//@Bug 4358 get rid of broken pipe error. //@Bug 4358 get rid of broken pipe error.
msg.restart(); msg.restart();
msg << qb; msg << qb;
fExeMgr->write(msg); fExeMgr->write(msg);
*/ //timer.finish(); */ //timer.finish();
//return rowsProcessed; //return rowsProcessed;
//err = true; //err = true;
break; break;
} }
if (rowGroup->getRGData() == NULL) if (rowGroup->getRGData() == NULL)
{ {
msg.restart(); msg.restart();
} }
if (rowGroup->getRowCount() == 0) //done fetching if (rowGroup->getRowCount() == 0) //done fetching
{ {
//timer.finish(); //timer.finish();
@@ -552,16 +592,20 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
//return rowsProcessed; //return rowsProcessed;
break; break;
} }
if (rowGroup->getBaseRid() == (uint64_t) (-1)) if (rowGroup->getBaseRid() == (uint64_t) (-1))
{ {
continue; // @bug4247, not valid row ids, may from small side outer continue; // @bug4247, not valid row ids, may from small side outer
} }
dbroot = rowGroup->getDBRoot(); dbroot = rowGroup->getDBRoot();
//cout << "dbroot in the rowgroup is " << dbroot << endl; //cout << "dbroot in the rowgroup is " << dbroot << endl;
//timer.start("processRowgroup"); //timer.start("processRowgroup");
err = processRowgroup(msgBk, result, uniqueId, cpackage, pmState, metaData, dbroot); err = processRowgroup(msgBk, result, uniqueId, cpackage, pmState, metaData, dbroot);
//timer.stop("processRowgroup"); //timer.stop("processRowgroup");
if (err) { if (err)
{
//timer.finish(); //timer.finish();
LoggingID logid( DMLLoggingId, fSessionID, cpackage.get_TxnID()); LoggingID logid( DMLLoggingId, fSessionID, cpackage.get_TxnID());
logging::Message::Args args1; logging::Message::Args args1;
@@ -578,17 +622,19 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
msg2.format( args2 ); msg2.format( args2 );
logger.logMessage(LOG_TYPE_DEBUG, msg2, logid); logger.logMessage(LOG_TYPE_DEBUG, msg2, logid);
//@Bug 4358 get rid of broken pipe error. //@Bug 4358 get rid of broken pipe error.
/* msg.restart(); /* msg.restart();
msg << qb; msg << qb;
fExeMgr->write(msg); fExeMgr->write(msg);
return rowsProcessed; return rowsProcessed;
*/ */
//err = true; //err = true;
break; break;
} }
rowsProcessed += rowGroup->getRowCount(); rowsProcessed += rowGroup->getRowCount();
} }
} }
if (fRollbackPending) if (fRollbackPending)
{ {
err = true; err = true;
@@ -610,6 +656,7 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
DMLResult tmpResult; DMLResult tmpResult;
receiveAll( tmpResult, uniqueId, fPMs, pmState, tableOid); receiveAll( tmpResult, uniqueId, fPMs, pmState, tableOid);
} }
// get stats from ExeMgr // get stats from ExeMgr
if (!err) if (!err)
{ {
@@ -631,6 +678,7 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
msg << qb; msg << qb;
fExeMgr->write(msg); fExeMgr->write(msg);
} }
return rowsProcessed; return rowsProcessed;
//stats.insert(); //stats.insert();
} }
@@ -666,11 +714,12 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
fExeMgr->write(msg); fExeMgr->write(msg);
return rowsProcessed; return rowsProcessed;
} }
//timer.finish(); //timer.finish();
return rowsProcessed; 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) dmlpackage::CalpontDMLPackage& cpackage, std::map<unsigned, bool>& pmState, bool isMeta, uint32_t dbroot)
{ {
bool rc = false; bool rc = false;
@@ -696,18 +745,23 @@ bool UpdatePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
{ {
cpackage.write(bytestream); cpackage.write(bytestream);
fWEClient->write_to_all(bytestream); fWEClient->write_to_all(bytestream);
while (1) while (1)
{ {
if (msgRecived == fWEClient->getPmCount()) if (msgRecived == fWEClient->getPmCount())
break; break;
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = true; rc = true;
break; break;
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
if (tmp8 > 0) if (tmp8 > 0)
{ {
*bsIn >> errorMsg; *bsIn >> errorMsg;
@@ -725,12 +779,14 @@ bool UpdatePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
msgRecived++; msgRecived++;
} }
} }
return rc; return rc;
} }
if (pmState[pmNum]) if (pmState[pmNum])
{ {
try { try
{
//cout << "sending rows to pm " << pmNum << " with msg length " << bytestream.length() << endl; //cout << "sending rows to pm " << pmNum << " with msg length " << bytestream.length() << endl;
fWEClient->write(bytestream, (uint32_t)pmNum); fWEClient->write(bytestream, (uint32_t)pmNum);
pmState[pmNum] = false; pmState[pmNum] = false;
@@ -763,8 +819,11 @@ bool UpdatePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
while (1) while (1)
{ {
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
try {
try
{
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
rc = true; rc = true;
@@ -775,6 +834,7 @@ bool UpdatePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
{ {
*bsIn >> tmp8; *bsIn >> tmp8;
*bsIn >> errorMsg; *bsIn >> errorMsg;
if (tmp8 == IDBRANGE_WARNING) if (tmp8 == IDBRANGE_WARNING)
{ {
result.result = IDBRANGE_WARNING; result.result = IDBRANGE_WARNING;
@@ -789,15 +849,18 @@ bool UpdatePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
result.stats.fErrorNo = tmp8; result.stats.fErrorNo = tmp8;
rc = (tmp8 != 0); rc = (tmp8 != 0);
} }
*bsIn >> tmp32; *bsIn >> tmp32;
//cout << "Received response from pm " << tmp32 << endl; //cout << "Received response from pm " << tmp32 << endl;
pmState[tmp32] = true; pmState[tmp32] = true;
*bsIn >> blocksChanged; *bsIn >> blocksChanged;
result.stats.fBlocksChanged += blocksChanged; result.stats.fBlocksChanged += blocksChanged;
if (rc != 0) if (rc != 0)
{ {
throw std::runtime_error(errorMsg); throw std::runtime_error(errorMsg);
} }
if (tmp32 == (uint32_t)pmNum) if (tmp32 == (uint32_t)pmNum)
{ {
//cout << "sending rows to pm " << pmNum << " with msg length " << bytestream.length() << endl; //cout << "sending rows to pm " << pmNum << " with msg length " << bytestream.length() << endl;
@@ -833,6 +896,7 @@ bool UpdatePackageProcessor::processRowgroup(ByteStream & aRowGroup, DMLResult&
} }
} }
} }
return rc; return rc;
} }
@@ -842,7 +906,8 @@ bool UpdatePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
//check how many message we need to receive //check how many message we need to receive
uint32_t messagesNotReceived = 0; uint32_t messagesNotReceived = 0;
bool err = false; bool err = false;
for (unsigned i=0; i<fPMs.size(); i++)
for (unsigned i = 0; i < fPMs.size(); i++)
{ {
if (!pmState[fPMs[i]]) if (!pmState[fPMs[i]])
messagesNotReceived++; messagesNotReceived++;
@@ -852,16 +917,18 @@ bool UpdatePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
ByteStream::byte tmp8; ByteStream::byte tmp8;
string errorMsg; string errorMsg;
uint32_t msgReceived = 0; uint32_t msgReceived = 0;
if (messagesNotReceived > 0) if (messagesNotReceived > 0)
{ {
LoggingID logid( DMLLoggingId, fSessionID, fSessionID); LoggingID logid( DMLLoggingId, fSessionID, fSessionID);
if ( messagesNotReceived > fWEClient->getPmCount()) if ( messagesNotReceived > fWEClient->getPmCount())
{ {
logging::Message::Args args1; logging::Message::Args args1;
logging::Message msg(1); logging::Message msg(1);
args1.add("Update outstanding messages exceed PM count , need to receive messages:PMcount = "); args1.add("Update outstanding messages exceed PM count , need to receive messages:PMcount = ");
ostringstream oss; ostringstream oss;
oss << messagesNotReceived <<":"<<fWEClient->getPmCount(); oss << messagesNotReceived << ":" << fWEClient->getPmCount();
args1.add(oss.str()); args1.add(oss.str());
msg.format( args1 ); msg.format( args1 );
logging::Logger logger(logid.fSubsysID); logging::Logger logger(logid.fSubsysID);
@@ -887,17 +954,22 @@ bool UpdatePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
break; break;
bsIn.reset(new ByteStream()); bsIn.reset(new ByteStream());
try {
try
{
fWEClient->read(uniqueId, bsIn); fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error if ( bsIn->length() == 0 ) //read error
{ {
err = true; err = true;
errorMsg = "Lost connection to Write Engine Server while updating"; errorMsg = "Lost connection to Write Engine Server while updating";
throw std::runtime_error(errorMsg); throw std::runtime_error(errorMsg);
} }
else { else
{
*bsIn >> tmp8; *bsIn >> tmp8;
*bsIn >> errorMsg; *bsIn >> errorMsg;
if (tmp8 == IDBRANGE_WARNING) if (tmp8 == IDBRANGE_WARNING)
{ {
result.result = IDBRANGE_WARNING; result.result = IDBRANGE_WARNING;
@@ -912,13 +984,17 @@ bool UpdatePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
result.stats.fErrorNo = tmp8; result.stats.fErrorNo = tmp8;
err = (tmp8 != 0); err = (tmp8 != 0);
} }
*bsIn >> tmp32; *bsIn >> tmp32;
*bsIn >> blocksChanged; *bsIn >> blocksChanged;
//cout << "Received response from pm " << tmp32 << endl; //cout << "Received response from pm " << tmp32 << endl;
pmState[tmp32] = true; pmState[tmp32] = true;
if (err) {
if (err)
{
throw std::runtime_error(errorMsg); throw std::runtime_error(errorMsg);
} }
msgReceived++; msgReceived++;
result.stats.fBlocksChanged += blocksChanged; result.stats.fBlocksChanged += blocksChanged;
} }
@@ -949,6 +1025,7 @@ bool UpdatePackageProcessor::receiveAll(DMLResult& result, const uint64_t unique
} }
} }
} }
return err; return err;
} }
} // namespace dmlpackageprocessor } // namespace dmlpackageprocessor

View File

@@ -45,7 +45,8 @@ class UpdatePackageProcessor : public DMLPackageProcessor
{ {
public: 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 /** @brief process an UpdateDMLPackage
* *
@@ -71,9 +72,9 @@ private:
* @param result the result of the operation * @param result the result of the operation
* @return the error code * @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); bool receiveAll(DMLResult& result, const uint64_t uniqueId, std::vector<int>& fPMs, std::map<unsigned, bool>& pmState, const uint32_t tableOid);
}; };
} }

View File

@@ -25,7 +25,8 @@
#ifndef DBCON_CALPONTSYSTEMCATALOG_H #ifndef DBCON_CALPONTSYSTEMCATALOG_H
#define DBCON_CALPONTSYSTEMCATALOG_H #define DBCON_CALPONTSYSTEMCATALOG_H
namespace dbcon { namespace dbcon
{
class CalpontSystemCatalog class CalpontSystemCatalog
{ {

View File

@@ -43,17 +43,19 @@ using namespace joblist;
#include "functioncolumn.h" #include "functioncolumn.h"
#include "objectreader.h" #include "objectreader.h"
namespace execplan { namespace execplan
{
void getAggCols(execplan::ParseTree* n, void* obj) void getAggCols(execplan::ParseTree* n, void* obj)
{ {
vector<AggregateColumn*>* list = reinterpret_cast< vector<AggregateColumn*>*>(obj); vector<AggregateColumn*>* list = reinterpret_cast< vector<AggregateColumn*>*>(obj);
TreeNode* tn = n->data(); TreeNode* tn = n->data();
AggregateColumn *sc = dynamic_cast<AggregateColumn*>(tn); AggregateColumn* sc = dynamic_cast<AggregateColumn*>(tn);
FunctionColumn *fc = dynamic_cast<FunctionColumn*>(tn); FunctionColumn* fc = dynamic_cast<FunctionColumn*>(tn);
ArithmeticColumn *ac = dynamic_cast<ArithmeticColumn*>(tn); ArithmeticColumn* ac = dynamic_cast<ArithmeticColumn*>(tn);
SimpleFilter *sf = dynamic_cast<SimpleFilter*>(tn); SimpleFilter* sf = dynamic_cast<SimpleFilter*>(tn);
ConstantFilter *cf = dynamic_cast<ConstantFilter*>(tn); ConstantFilter* cf = dynamic_cast<ConstantFilter*>(tn);
if (sc) if (sc)
{ {
list->push_back(sc); list->push_back(sc);
@@ -161,13 +163,17 @@ const string AggregateColumn::toString() const
output << "AggregateColumn " << data() << endl; output << "AggregateColumn " << data() << endl;
output << "func/distinct: " << (int)fAggOp << "/" << fDistinct << endl; output << "func/distinct: " << (int)fAggOp << "/" << fDistinct << endl;
output << "expressionId=" << fExpressionId << endl; output << "expressionId=" << fExpressionId << endl;
if (fAlias.length() > 0) output << "/Alias: " << fAlias << endl; if (fAlias.length() > 0) output << "/Alias: " << fAlias << endl;
if (fFunctionParms == 0) if (fFunctionParms == 0)
output << "No arguments" << endl; output << "No arguments" << endl;
else else
output << *fFunctionParms << endl; output << *fFunctionParms << endl;
if (fConstCol) if (fConstCol)
output << *fConstCol; output << *fConstCol;
return output.str(); return output.str();
} }
@@ -184,20 +190,27 @@ void AggregateColumn::serialize(messageqcpp::ByteStream& b) const
ReturnedColumn::serialize(b); ReturnedColumn::serialize(b);
b << fFunctionName; b << fFunctionName;
b << static_cast<uint8_t>(fAggOp); b << static_cast<uint8_t>(fAggOp);
if (fFunctionParms == 0) if (fFunctionParms == 0)
b << (uint8_t) ObjectReader::NULL_CLASS; b << (uint8_t) ObjectReader::NULL_CLASS;
else else
fFunctionParms->serialize(b); fFunctionParms->serialize(b);
b << static_cast<uint32_t>(fGroupByColList.size()); b << static_cast<uint32_t>(fGroupByColList.size());
for (rcit = fGroupByColList.begin(); rcit != fGroupByColList.end(); ++rcit) for (rcit = fGroupByColList.begin(); rcit != fGroupByColList.end(); ++rcit)
(*rcit)->serialize(b); (*rcit)->serialize(b);
b << static_cast<uint32_t>(fProjectColList.size()); b << static_cast<uint32_t>(fProjectColList.size());
for (rcit = fProjectColList.begin(); rcit != fProjectColList.end(); ++rcit) for (rcit = fProjectColList.begin(); rcit != fProjectColList.end(); ++rcit)
(*rcit)->serialize(b); (*rcit)->serialize(b);
b << fData; b << fData;
//b << fAlias; //b << fAlias;
b << fTableAlias; b << fTableAlias;
b << static_cast<const ByteStream::doublebyte>(fAsc); b << static_cast<const ByteStream::doublebyte>(fAsc);
if (fConstCol.get() == 0) if (fConstCol.get() == 0)
b << (uint8_t) ObjectReader::NULL_CLASS; b << (uint8_t) ObjectReader::NULL_CLASS;
else else
@@ -218,20 +231,26 @@ void AggregateColumn::unserialize(messageqcpp::ByteStream& b)
messageqcpp::ByteStream::quadbyte size; messageqcpp::ByteStream::quadbyte size;
messageqcpp::ByteStream::quadbyte i; messageqcpp::ByteStream::quadbyte i;
ReturnedColumn *rc; ReturnedColumn* rc;
b >> size; b >> size;
for (i = 0; i < size; i++) {
for (i = 0; i < size; i++)
{
rc = dynamic_cast<ReturnedColumn*>(ObjectReader::createTreeNode(b)); rc = dynamic_cast<ReturnedColumn*>(ObjectReader::createTreeNode(b));
SRCP srcp(rc); SRCP srcp(rc);
fGroupByColList.push_back(srcp); fGroupByColList.push_back(srcp);
} }
b >> size; b >> size;
for (i = 0; i < size; i++) {
for (i = 0; i < size; i++)
{
rc = dynamic_cast<ReturnedColumn*>(ObjectReader::createTreeNode(b)); rc = dynamic_cast<ReturnedColumn*>(ObjectReader::createTreeNode(b));
SRCP srcp(rc); SRCP srcp(rc);
fProjectColList.push_back(srcp); fProjectColList.push_back(srcp);
} }
b >> fData; b >> fData;
//b >> fAlias; //b >> fAlias;
b >> fTableAlias; b >> fTableAlias;
@@ -241,18 +260,23 @@ void AggregateColumn::unserialize(messageqcpp::ByteStream& b)
bool AggregateColumn::operator==(const AggregateColumn& t) const bool AggregateColumn::operator==(const AggregateColumn& t) const
{ {
const ReturnedColumn *rc1, *rc2; const ReturnedColumn* rc1, *rc2;
rc1 = static_cast<const ReturnedColumn*>(this); rc1 = static_cast<const ReturnedColumn*>(this);
rc2 = static_cast<const ReturnedColumn*>(&t); rc2 = static_cast<const ReturnedColumn*>(&t);
if (*rc1 != *rc2) if (*rc1 != *rc2)
return false; return false;
if (fFunctionName != t.fFunctionName) if (fFunctionName != t.fFunctionName)
return false; return false;
if (fAggOp == COUNT_ASTERISK && t.fAggOp == COUNT_ASTERISK) if (fAggOp == COUNT_ASTERISK && t.fAggOp == COUNT_ASTERISK)
return true; return true;
if (fAggOp != t.fAggOp) if (fAggOp != t.fAggOp)
return false; return false;
if (fFunctionParms.get() != NULL && t.fFunctionParms.get() != NULL) if (fFunctionParms.get() != NULL && t.fFunctionParms.get() != NULL)
{ {
if (*fFunctionParms.get() != t.fFunctionParms.get()) 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) else if (fFunctionParms.get() != NULL || t.fFunctionParms.get() != NULL)
return false; return false;
//if (fAlias != t.fAlias) //if (fAlias != t.fAlias)
// return false; // return false;
if (fTableAlias != t.fTableAlias) if (fTableAlias != t.fTableAlias)
return false; return false;
if (fData != t.fData) if (fData != t.fData)
return false; return false;
if (fAsc != t.fAsc) if (fAsc != t.fAsc)
return false; return false;
if ((fConstCol.get() != NULL && t.fConstCol.get() == NULL) || if ((fConstCol.get() != NULL && t.fConstCol.get() == NULL) ||
(fConstCol.get() == NULL && t.fConstCol.get() != NULL) || (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())) *(fConstCol.get()) != t.fConstCol.get()))
return false; return false;
return true; return true;
} }
bool AggregateColumn::operator==(const TreeNode* t) const bool AggregateColumn::operator==(const TreeNode* t) const
{ {
const AggregateColumn *ac; const AggregateColumn* ac;
ac = dynamic_cast<const AggregateColumn*>(t); ac = dynamic_cast<const AggregateColumn*>(t);
if (ac == NULL) if (ac == NULL)
return false; return false;
return *this == *ac; return *this == *ac;
} }
@@ -311,13 +342,17 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
isNull = true; isNull = true;
else else
fResult.intVal = row.getUintField<4>(fInputIndex); fResult.intVal = row.getUintField<4>(fInputIndex);
break; break;
case CalpontSystemCatalog::DATETIME: case CalpontSystemCatalog::DATETIME:
if (row.equals<8>(DATETIMENULL, fInputIndex)) if (row.equals<8>(DATETIMENULL, fInputIndex))
isNull = true; isNull = true;
else else
fResult.intVal = row.getUintField<8>(fInputIndex); fResult.intVal = row.getUintField<8>(fInputIndex);
break; break;
case CalpontSystemCatalog::CHAR: case CalpontSystemCatalog::CHAR:
case CalpontSystemCatalog::VARCHAR: case CalpontSystemCatalog::VARCHAR:
case CalpontSystemCatalog::STRINT: case CalpontSystemCatalog::STRINT:
@@ -329,20 +364,26 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
isNull = true; isNull = true;
else else
fResult.origIntVal = row.getUintField<1>(fInputIndex); fResult.origIntVal = row.getUintField<1>(fInputIndex);
break; break;
case 2: case 2:
if (row.equals<2>(CHAR2NULL, fInputIndex)) if (row.equals<2>(CHAR2NULL, fInputIndex))
isNull = true; isNull = true;
else else
fResult.origIntVal = row.getUintField<2>(fInputIndex); fResult.origIntVal = row.getUintField<2>(fInputIndex);
break; break;
case 3: case 3:
case 4: case 4:
if (row.equals<4>(CHAR4NULL, fInputIndex)) if (row.equals<4>(CHAR4NULL, fInputIndex))
isNull = true; isNull = true;
else else
fResult.origIntVal = row.getUintField<4>(fInputIndex); fResult.origIntVal = row.getUintField<4>(fInputIndex);
break; break;
case 5: case 5:
case 6: case 6:
case 7: case 7:
@@ -351,72 +392,95 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
isNull = true; isNull = true;
else else
fResult.origIntVal = row.getUintField<8>(fInputIndex); fResult.origIntVal = row.getUintField<8>(fInputIndex);
break; break;
default: default:
if (row.equals(CPNULLSTRMARK, fInputIndex)) if (row.equals(CPNULLSTRMARK, fInputIndex))
isNull = true; isNull = true;
else else
fResult.strVal = row.getStringField(fInputIndex); fResult.strVal = row.getStringField(fInputIndex);
// stringColVal is padded with '\0' to colWidth so can't use str.length() // stringColVal is padded with '\0' to colWidth so can't use str.length()
if (strlen(fResult.strVal.c_str()) == 0) if (strlen(fResult.strVal.c_str()) == 0)
isNull = true; isNull = true;
break; break;
} }
if (fResultType.colDataType == CalpontSystemCatalog::STRINT) if (fResultType.colDataType == CalpontSystemCatalog::STRINT)
fResult.intVal = uint64ToStr(fResult.origIntVal); fResult.intVal = uint64ToStr(fResult.origIntVal);
else else
fResult.intVal = atoll((char*)&fResult.origIntVal); fResult.intVal = atoll((char*)&fResult.origIntVal);
break; break;
case CalpontSystemCatalog::BIGINT: case CalpontSystemCatalog::BIGINT:
if (row.equals<8>(BIGINTNULL, fInputIndex)) if (row.equals<8>(BIGINTNULL, fInputIndex))
isNull = true; isNull = true;
else else
fResult.intVal = row.getIntField<8>(fInputIndex); fResult.intVal = row.getIntField<8>(fInputIndex);
break; break;
case CalpontSystemCatalog::UBIGINT: case CalpontSystemCatalog::UBIGINT:
if (row.equals<8>(UBIGINTNULL, fInputIndex)) if (row.equals<8>(UBIGINTNULL, fInputIndex))
isNull = true; isNull = true;
else else
fResult.uintVal = row.getUintField<8>(fInputIndex); fResult.uintVal = row.getUintField<8>(fInputIndex);
break; break;
case CalpontSystemCatalog::INT: case CalpontSystemCatalog::INT:
case CalpontSystemCatalog::MEDINT: case CalpontSystemCatalog::MEDINT:
if (row.equals<4>(INTNULL, fInputIndex)) if (row.equals<4>(INTNULL, fInputIndex))
isNull = true; isNull = true;
else else
fResult.intVal = row.getIntField<4>(fInputIndex); fResult.intVal = row.getIntField<4>(fInputIndex);
break; break;
case CalpontSystemCatalog::UINT: case CalpontSystemCatalog::UINT:
case CalpontSystemCatalog::UMEDINT: case CalpontSystemCatalog::UMEDINT:
if (row.equals<4>(UINTNULL, fInputIndex)) if (row.equals<4>(UINTNULL, fInputIndex))
isNull = true; isNull = true;
else else
fResult.uintVal = row.getUintField<4>(fInputIndex); fResult.uintVal = row.getUintField<4>(fInputIndex);
break; break;
case CalpontSystemCatalog::SMALLINT: case CalpontSystemCatalog::SMALLINT:
if (row.equals<2>(SMALLINTNULL, fInputIndex)) if (row.equals<2>(SMALLINTNULL, fInputIndex))
isNull = true; isNull = true;
else else
fResult.intVal = row.getIntField<2>(fInputIndex); fResult.intVal = row.getIntField<2>(fInputIndex);
break; break;
case CalpontSystemCatalog::USMALLINT: case CalpontSystemCatalog::USMALLINT:
if (row.equals<2>(USMALLINTNULL, fInputIndex)) if (row.equals<2>(USMALLINTNULL, fInputIndex))
isNull = true; isNull = true;
else else
fResult.uintVal = row.getUintField<2>(fInputIndex); fResult.uintVal = row.getUintField<2>(fInputIndex);
break; break;
case CalpontSystemCatalog::TINYINT: case CalpontSystemCatalog::TINYINT:
if (row.equals<1>(TINYINTNULL, fInputIndex)) if (row.equals<1>(TINYINTNULL, fInputIndex))
isNull = true; isNull = true;
else else
fResult.intVal = row.getIntField<1>(fInputIndex); fResult.intVal = row.getIntField<1>(fInputIndex);
break; break;
case CalpontSystemCatalog::UTINYINT: case CalpontSystemCatalog::UTINYINT:
if (row.equals<1>(UTINYINTNULL, fInputIndex)) if (row.equals<1>(UTINYINTNULL, fInputIndex))
isNull = true; isNull = true;
else else
fResult.uintVal = row.getUintField<1>(fInputIndex); fResult.uintVal = row.getUintField<1>(fInputIndex);
break; break;
//In this case, we're trying to load a double output column with float data. This is the //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 when you do sum(floatcol), e.g.
case CalpontSystemCatalog::FLOAT: case CalpontSystemCatalog::FLOAT:
@@ -425,14 +489,18 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
isNull = true; isNull = true;
else else
fResult.floatVal = row.getFloatField(fInputIndex); fResult.floatVal = row.getFloatField(fInputIndex);
break; break;
case CalpontSystemCatalog::DOUBLE: case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UDOUBLE: case CalpontSystemCatalog::UDOUBLE:
if (row.equals<8>(DOUBLENULL, fInputIndex)) if (row.equals<8>(DOUBLENULL, fInputIndex))
isNull = true; isNull = true;
else else
fResult.doubleVal = row.getDoubleField(fInputIndex); fResult.doubleVal = row.getDoubleField(fInputIndex);
break; break;
case CalpontSystemCatalog::DECIMAL: case CalpontSystemCatalog::DECIMAL:
case CalpontSystemCatalog::UDECIMAL: case CalpontSystemCatalog::UDECIMAL:
switch (fResultType.colWidth) switch (fResultType.colWidth)
@@ -445,7 +513,9 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
fResult.decimalVal.value = row.getIntField<1>(fInputIndex); fResult.decimalVal.value = row.getIntField<1>(fInputIndex);
fResult.decimalVal.scale = (unsigned)fResultType.scale; fResult.decimalVal.scale = (unsigned)fResultType.scale;
} }
break; break;
case 2: case 2:
if (row.equals<2>(SMALLINTNULL, fInputIndex)) if (row.equals<2>(SMALLINTNULL, fInputIndex))
isNull = true; isNull = true;
@@ -454,7 +524,9 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
fResult.decimalVal.value = row.getIntField<2>(fInputIndex); fResult.decimalVal.value = row.getIntField<2>(fInputIndex);
fResult.decimalVal.scale = (unsigned)fResultType.scale; fResult.decimalVal.scale = (unsigned)fResultType.scale;
} }
break; break;
case 4: case 4:
if (row.equals<4>(INTNULL, fInputIndex)) if (row.equals<4>(INTNULL, fInputIndex))
isNull = true; isNull = true;
@@ -463,7 +535,9 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
fResult.decimalVal.value = row.getIntField<4>(fInputIndex); fResult.decimalVal.value = row.getIntField<4>(fInputIndex);
fResult.decimalVal.scale = (unsigned)fResultType.scale; fResult.decimalVal.scale = (unsigned)fResultType.scale;
} }
break; break;
default: default:
if (row.equals<8>(BIGINTNULL, fInputIndex)) if (row.equals<8>(BIGINTNULL, fInputIndex))
isNull = true; isNull = true;
@@ -472,18 +546,23 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
fResult.decimalVal.value = (int64_t)row.getUintField<8>(fInputIndex); fResult.decimalVal.value = (int64_t)row.getUintField<8>(fInputIndex);
fResult.decimalVal.scale = (unsigned)fResultType.scale; fResult.decimalVal.scale = (unsigned)fResultType.scale;
} }
break; break;
} }
break; break;
case CalpontSystemCatalog::VARBINARY: case CalpontSystemCatalog::VARBINARY:
case CalpontSystemCatalog::BLOB: case CalpontSystemCatalog::BLOB:
isNull = true; isNull = true;
break; break;
default: // treat as int64 default: // treat as int64
if (row.equals<8>(BIGINTNULL, fInputIndex)) if (row.equals<8>(BIGINTNULL, fInputIndex))
isNull = true; isNull = true;
else else
fResult.intVal = row.getUintField<8>(fInputIndex); fResult.intVal = row.getUintField<8>(fInputIndex);
break; break;
} }
} }
@@ -491,7 +570,7 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
/*static*/ /*static*/
AggregateColumn::AggOp AggregateColumn::agname2num(const string& agname) AggregateColumn::AggOp AggregateColumn::agname2num(const string& agname)
{ {
/* /*
NOOP = 0, NOOP = 0,
COUNT_ASTERISK, COUNT_ASTERISK,
COUNT, COUNT,
@@ -511,35 +590,49 @@ AggregateColumn::AggOp AggregateColumn::agname2num(const string& agname)
BIT_OR, BIT_OR,
BIT_XOR, BIT_XOR,
GROUP_CONCAT GROUP_CONCAT
*/ */
string lfn(agname); string lfn(agname);
algorithm::to_lower(lfn); algorithm::to_lower(lfn);
if (lfn == "count(*)") if (lfn == "count(*)")
return COUNT_ASTERISK; return COUNT_ASTERISK;
if (lfn == "count") if (lfn == "count")
return COUNT; return COUNT;
if (lfn == "sum") if (lfn == "sum")
return SUM; return SUM;
if (lfn == "avg") if (lfn == "avg")
return AVG; return AVG;
if (lfn == "min") if (lfn == "min")
return MIN; return MIN;
if (lfn == "max") if (lfn == "max")
return MAX; return MAX;
if (lfn == "std") if (lfn == "std")
return STDDEV_POP; return STDDEV_POP;
if (lfn == "stddev_pop") if (lfn == "stddev_pop")
return STDDEV_POP; return STDDEV_POP;
if (lfn == "stddev_samp") if (lfn == "stddev_samp")
return STDDEV_SAMP; return STDDEV_SAMP;
if (lfn == "stddev") if (lfn == "stddev")
return STDDEV_POP; return STDDEV_POP;
if (lfn == "var_pop") if (lfn == "var_pop")
return VAR_POP; return VAR_POP;
if (lfn == "var_samp") if (lfn == "var_samp")
return VAR_SAMP; return VAR_SAMP;
if (lfn == "variance") if (lfn == "variance")
return VAR_POP; return VAR_POP;
return NOOP; return NOOP;
} }

94
dbcon/execplan/aggregatecolumn.h Executable file → Normal file
View File

@@ -29,14 +29,16 @@
#include "calpontselectexecutionplan.h" #include "calpontselectexecutionplan.h"
#include "returnedcolumn.h" #include "returnedcolumn.h"
namespace messageqcpp { namespace messageqcpp
{
class ByteStream; class ByteStream;
} }
/** /**
* Namespace * Namespace
*/ */
namespace execplan { namespace execplan
{
/** /**
* @brief A class to represent a aggregate return column * @brief A class to represent a aggregate return column
@@ -44,7 +46,8 @@ namespace execplan {
* This class is a specialization of class ReturnedColumn that * This class is a specialization of class ReturnedColumn that
* handles an aggregate function call (e.g., SUM, COUNT, MIN, MAX). * handles an aggregate function call (e.g., SUM, COUNT, MIN, MAX).
*/ */
class AggregateColumn : public ReturnedColumn { class AggregateColumn : public ReturnedColumn
{
public: public:
/** /**
@@ -94,27 +97,27 @@ public:
/** /**
* ctor * ctor
*/ */
AggregateColumn(const AggOp aggop, ReturnedColumn* parm, const uint32_t sessionID=0); AggregateColumn(const AggOp aggop, ReturnedColumn* parm, const uint32_t sessionID = 0);
/** /**
* ctor * 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 * 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 * 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 * ctor
*/ */
AggregateColumn( const AggregateColumn& rhs, const uint32_t sessionID=0 ); AggregateColumn( const AggregateColumn& rhs, const uint32_t sessionID = 0 );
/** /**
* Destructors * Destructors
@@ -140,11 +143,17 @@ public:
/** /**
* accessor * accessor
*/ */
virtual const uint8_t aggOp() const {return fAggOp;} virtual const uint8_t aggOp() const
{
return fAggOp;
}
/** /**
* accessor * accessor
*/ */
virtual void aggOp(const uint8_t aggOp) {fAggOp = aggOp;} virtual void aggOp(const uint8_t aggOp)
{
fAggOp = aggOp;
}
/** get function parms /** get function parms
* *
@@ -176,29 +185,47 @@ public:
/** /**
* table alias name * table alias name
*/ */
virtual const std::string tableAlias() const { return fTableAlias; } virtual const std::string tableAlias() const
{
return fTableAlias;
}
/** /**
* table alias name * table alias name
*/ */
virtual void tableAlias (const std::string& tableAlias) { fTableAlias = tableAlias; } virtual void tableAlias (const std::string& tableAlias)
{
fTableAlias = tableAlias;
}
/** /**
* ASC flag * ASC flag
*/ */
inline virtual const bool asc() const { return fAsc; } inline virtual const bool asc() const
{
return fAsc;
}
/** /**
* ASC flag * 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 * 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 * 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 * Overloaded stream operator
@@ -243,26 +270,44 @@ public:
virtual bool operator!=(const AggregateColumn& t) const; virtual bool operator!=(const AggregateColumn& t) const;
/** @brief push back arg to group by column list*/ /** @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*/ /** @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 * accessor
*/ */
virtual const ColumnList& groupByColList() const { return fGroupByColList;} virtual const ColumnList& groupByColList() const
{
return fGroupByColList;
}
/** /**
* accessor * accessor
*/ */
virtual const ColumnList& projectColList() const { return fProjectColList;} virtual const ColumnList& projectColList() const
{
return fProjectColList;
}
/** @brief constant argument for aggregate with constant */ /** @brief constant argument for aggregate with constant */
inline const SRCP constCol() const { return fConstCol; } inline const SRCP constCol() const
{
return fConstCol;
}
/** /**
* accessor * 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 * convert an aggregate name to an AggOp enum
@@ -270,7 +315,10 @@ public:
static AggOp agname2num(const std::string&); static AggOp agname2num(const std::string&);
virtual bool hasAggregate(); virtual bool hasAggregate();
virtual bool hasWindowFunc() {return false;} virtual bool hasWindowFunc()
{
return false;
}
protected: protected:
std::string fFunctionName; // deprecated field std::string fFunctionName; // deprecated field

View File

@@ -41,7 +41,8 @@ using namespace messageqcpp;
#include "aggregatecolumn.h" #include "aggregatecolumn.h"
#include "windowfunctioncolumn.h" #include "windowfunctioncolumn.h"
namespace { namespace
{
/** print the tree /** print the tree
* *
* this function is mostly for debug purpose * 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 * Constructors/Destructors
@@ -91,6 +93,7 @@ ArithmeticColumn::~ArithmeticColumn()
{ {
if (fExpression != NULL) if (fExpression != NULL)
delete fExpression; delete fExpression;
fExpression = NULL; fExpression = NULL;
} }
@@ -102,6 +105,7 @@ void ArithmeticColumn::expression(ParseTree*& expression)
{ {
if (fExpression != NULL) if (fExpression != NULL)
delete fExpression; delete fExpression;
fExpression = expression; fExpression = expression;
expression = 0; expression = 0;
} }
@@ -116,18 +120,20 @@ void ArithmeticColumn::buildTree()
//string fData = ReturnedColumn::data(); //string fData = ReturnedColumn::data();
try { try
{
while (fData[i]) while (fData[i])
{ {
if (isdigit(fData[i]) || fData[i] == '.') if (isdigit(fData[i]) || fData[i] == '.')
{ {
string num; string num;
while (isdigit(fData[i]) || fData[i] == '.') while (isdigit(fData[i]) || fData[i] == '.')
{ {
num.push_back(fData[i++]); num.push_back(fData[i++]);
} }
ConstantColumn *cc = new ConstantColumn(num, ConstantColumn::NUM); ConstantColumn* cc = new ConstantColumn(num, ConstantColumn::NUM);
t.value = cc; t.value = cc;
tokens.push_back(t); tokens.push_back(t);
@@ -144,23 +150,23 @@ void ArithmeticColumn::buildTree()
// t.is_operator now indicate the previous token type // t.is_operator now indicate the previous token type
// if prev token is operand, then this '(' is func_open // if prev token is operand, then this '(' is func_open
// otherwise, this '(' is open // otherwise, this '(' is open
if (fData[i] == '(' && fData[i+1] != '-' && !t.is_operator()) if (fData[i] == '(' && fData[i + 1] != '-' && !t.is_operator())
{ {
// open '(' // open '('
Operator *op1 = new Operator("("); Operator* op1 = new Operator("(");
t.value = op1; t.value = op1;
tokens.push_back(t); tokens.push_back(t);
//This is not complete... we shouldn't be creating TreeNodes //This is not complete... we shouldn't be creating TreeNodes
string param = nextToken(++i, ')'); string param = nextToken(++i, ')');
TreeNode *tn = new TreeNodeImpl(param); TreeNode* tn = new TreeNodeImpl(param);
t.value = tn; t.value = tn;
tokens.push_back(t); tokens.push_back(t);
// close ')' // close ')'
Operator *op2 = new Operator(")"); Operator* op2 = new Operator(")");
t.value = op2; t.value = op2;
tokens.push_back(t); tokens.push_back(t);
continue; continue;
@@ -173,7 +179,8 @@ void ArithmeticColumn::buildTree()
op = "||"; op = "||";
else else
op.push_back(fData[i]); op.push_back(fData[i]);
Operator *oper = new Operator(op);
Operator* oper = new Operator(op);
t.value = oper; t.value = oper;
tokens.push_back(t); tokens.push_back(t);
@@ -187,22 +194,24 @@ void ArithmeticColumn::buildTree()
{ {
//This is not complete... we shouldn't be creating TreeNodes //This is not complete... we shouldn't be creating TreeNodes
string param = nextToken(++i, ')'); string param = nextToken(++i, ')');
TreeNode *sc = new TreeNodeImpl(param); TreeNode* sc = new TreeNodeImpl(param);
t.value = sc; t.value = sc;
tokens.push_back(t); tokens.push_back(t);
// close ')' // close ')'
Operator *oper = new Operator(")"); Operator* oper = new Operator(")");
t.value = oper; t.value = oper;
tokens.push_back(t); tokens.push_back(t);
} }
continue; continue;
} }
else if (isalpha(fData[i]) || fData[i] == '_' ) else if (isalpha(fData[i]) || fData[i] == '_' )
{ {
string identifier; string identifier;
while (isalnum(fData[i]) || while (isalnum(fData[i]) ||
fData[i] == '_' || fData[i] == '_' ||
fData[i] == '.' ) fData[i] == '.' )
@@ -210,7 +219,7 @@ void ArithmeticColumn::buildTree()
identifier.push_back(fData[i++]); identifier.push_back(fData[i++]);
} }
SimpleColumn *sc = new SimpleColumn(identifier, fSessionID ); SimpleColumn* sc = new SimpleColumn(identifier, fSessionID );
t.value = sc; t.value = sc;
tokens.push_back(t); tokens.push_back(t);
@@ -220,12 +229,13 @@ void ArithmeticColumn::buildTree()
else if (fData[i] == '\'') else if (fData[i] == '\'')
{ {
string literal = nextToken(++i, '\''); string literal = nextToken(++i, '\'');
ConstantColumn *cc = new ConstantColumn (literal, ConstantColumn::LITERAL); ConstantColumn* cc = new ConstantColumn (literal, ConstantColumn::LITERAL);
t.value = cc; t.value = cc;
tokens.push_back(t); tokens.push_back(t);
continue; continue;
} }
++i; ++i;
} }
@@ -234,16 +244,17 @@ void ArithmeticColumn::buildTree()
catch (const invalid_argument& e) catch (const invalid_argument& e)
{ {
// clean up tokens // 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; delete tokens[i].value;
tokens[i].value = 0; tokens[i].value = 0;
} }
throw runtime_error(e.what()); 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 token;
// string fData = ReturnedColumn::data(); // 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 ')' // increment num when get '(' and decrement when get ')'
// to find the mathing ')' when num = 0 // to find the mathing ')' when num = 0
int num = 1; int num = 1;
for (; pos < fData.length(); ) for (; pos < fData.length(); )
{ {
if (end == ')') if (end == ')')
@@ -259,6 +271,7 @@ const string ArithmeticColumn::nextToken(string::size_type &pos, char end) const
num++; num++;
else if (fData[pos] == ')') else if (fData[pos] == ')')
num--; num--;
if (num == 0) if (num == 0)
{ {
pos++; pos++;
@@ -273,6 +286,7 @@ const string ArithmeticColumn::nextToken(string::size_type &pos, char end) const
return token; return token;
} }
} }
token.push_back(fData[pos++]); token.push_back(fData[pos++]);
} }
@@ -293,12 +307,15 @@ const string ArithmeticColumn::toString() const
{ {
ostringstream oss; ostringstream oss;
oss << "ArithmeticColumn: "; oss << "ArithmeticColumn: ";
if (fAlias.length() > 0) oss << "Alias: " << fAlias << endl; if (fAlias.length() > 0) oss << "Alias: " << fAlias << endl;
if (fExpression != 0) fExpression->walk(walkfn, oss); if (fExpression != 0) fExpression->walk(walkfn, oss);
oss << "expressionId=" << fExpressionId << endl; oss << "expressionId=" << fExpressionId << endl;
oss << "joinInfo=" << fJoinInfo << " returnAll=" << fReturnAll << " sequence#=" << fSequence << endl; oss << "joinInfo=" << fJoinInfo << " returnAll=" << fReturnAll << " sequence#=" << fSequence << endl;
oss << "resultType=" << colDataTypeToString(fResultType.colDataType) << "|" << fResultType.colWidth << oss << "resultType=" << colDataTypeToString(fResultType.colDataType) << "|" << fResultType.colWidth <<
endl; endl;
return oss.str(); return oss.str();
} }
@@ -316,8 +333,10 @@ void ArithmeticColumn::unserialize(messageqcpp::ByteStream& b)
{ {
ObjectReader::checkType(b, ObjectReader::ARITHMETICCOLUMN); ObjectReader::checkType(b, ObjectReader::ARITHMETICCOLUMN);
ReturnedColumn::unserialize(b); ReturnedColumn::unserialize(b);
if (fExpression != NULL) if (fExpression != NULL)
delete fExpression; delete fExpression;
fExpression = ObjectReader::createParseTree(b); fExpression = ObjectReader::createParseTree(b);
b >> fTableAlias; b >> fTableAlias;
b >> fData; b >> fData;
@@ -333,34 +352,43 @@ void ArithmeticColumn::unserialize(messageqcpp::ByteStream& b)
bool ArithmeticColumn::operator==(const ArithmeticColumn& t) const bool ArithmeticColumn::operator==(const ArithmeticColumn& t) const
{ {
const ReturnedColumn *rc1, *rc2; const ReturnedColumn* rc1, *rc2;
rc1 = static_cast<const ReturnedColumn*>(this); rc1 = static_cast<const ReturnedColumn*>(this);
rc2 = static_cast<const ReturnedColumn*>(&t); rc2 = static_cast<const ReturnedColumn*>(&t);
if (*rc1 != *rc2) if (*rc1 != *rc2)
return false; return false;
if (fExpression != NULL && t.fExpression != NULL) {
if (fExpression != NULL && t.fExpression != NULL)
{
if (*fExpression != *t.fExpression) if (*fExpression != *t.fExpression)
return false; return false;
} }
else if (fExpression != NULL || t.fExpression != NULL) else if (fExpression != NULL || t.fExpression != NULL)
return false; return false;
if (fAlias != t.fAlias) if (fAlias != t.fAlias)
return false; return false;
if (fTableAlias != t.fTableAlias) if (fTableAlias != t.fTableAlias)
return false; return false;
if (fData != t.fData) if (fData != t.fData)
return false; return false;
return true; return true;
} }
bool ArithmeticColumn::operator==(const TreeNode* t) const bool ArithmeticColumn::operator==(const TreeNode* t) const
{ {
const ArithmeticColumn *o; const ArithmeticColumn* o;
o = dynamic_cast<const ArithmeticColumn*>(t); o = dynamic_cast<const ArithmeticColumn*>(t);
if (o == NULL) if (o == NULL)
return false; return false;
return *this == *o; return *this == *o;
} }
@@ -377,10 +405,13 @@ bool ArithmeticColumn::operator!=(const TreeNode* t) const
bool ArithmeticColumn::hasAggregate() bool ArithmeticColumn::hasAggregate()
{ {
if (fHasAggregate) return true; if (fHasAggregate) return true;
fAggColumnList.clear(); fAggColumnList.clear();
fExpression->walk(getAggCols, &fAggColumnList); fExpression->walk(getAggCols, &fAggColumnList);
if (!fAggColumnList.empty()) if (!fAggColumnList.empty())
fHasAggregate = true; fHasAggregate = true;
return fHasAggregate; return fHasAggregate;
} }
@@ -388,8 +419,10 @@ bool ArithmeticColumn::hasWindowFunc()
{ {
fWindowFunctionColumnList.clear(); fWindowFunctionColumnList.clear();
fExpression->walk(getWindowFunctionCols, &fWindowFunctionColumnList); fExpression->walk(getWindowFunctionCols, &fWindowFunctionColumnList);
if (fWindowFunctionColumnList.empty()) if (fWindowFunctionColumnList.empty())
return false; return false;
return true; return true;
} }
@@ -400,6 +433,7 @@ void ArithmeticColumn::setDerivedTable()
fDerivedTable = ""; fDerivedTable = "";
return; return;
} }
if (fExpression) if (fExpression)
{ {
fExpression->setDerivedTable(); fExpression->setDerivedTable();
@@ -423,17 +457,20 @@ bool ArithmeticColumn::singleTable(CalpontSystemCatalog::TableAliasName& tan)
{ {
tan.clear(); tan.clear();
setSimpleColumnList(); setSimpleColumnList();
for (uint32_t i = 0; i < fSimpleColumnList.size(); i++) for (uint32_t i = 0; i < fSimpleColumnList.size(); i++)
{ {
CalpontSystemCatalog::TableAliasName stan(fSimpleColumnList[i]->schemaName(), CalpontSystemCatalog::TableAliasName stan(fSimpleColumnList[i]->schemaName(),
fSimpleColumnList[i]->tableName(), fSimpleColumnList[i]->tableName(),
fSimpleColumnList[i]->tableAlias(), fSimpleColumnList[i]->tableAlias(),
fSimpleColumnList[i]->viewName()); fSimpleColumnList[i]->viewName());
if (tan.table.empty()) if (tan.table.empty())
tan = stan; tan = stan;
else if (stan != tan) else if (stan != tan)
return false; return false;
} }
return true; return true;
} }

View File

@@ -34,9 +34,10 @@
/** /**
* Namespace * Namespace
*/ */
namespace execplan { namespace execplan
class SimpleColumn; {
class AggregateColumn; class SimpleColumn;
class AggregateColumn;
/** /**
* @brief A class to represent a arithmetic expression return column * @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 * This class is a specialization of class ReturnedColumn that
* handles an arithmetic expression. * handles an arithmetic expression.
*/ */
class ArithmeticColumn : public ReturnedColumn { class ArithmeticColumn : public ReturnedColumn
{
public: public:
ArithmeticColumn(); ArithmeticColumn();
ArithmeticColumn( const std::string& sql, const uint32_t sessionID=0 ); ArithmeticColumn( const std::string& sql, const uint32_t sessionID = 0 );
ArithmeticColumn( const ArithmeticColumn& rhs, const uint32_t sessionID=0 ); ArithmeticColumn( const ArithmeticColumn& rhs, const uint32_t sessionID = 0 );
virtual ~ArithmeticColumn(); virtual ~ArithmeticColumn();
inline ParseTree* expression() const inline ParseTree* expression() const
@@ -84,22 +86,34 @@ public:
/** /**
* get asc flag * get asc flag
*/ */
inline const bool asc() const { return fAsc; } inline const bool asc() const
{
return fAsc;
}
/** /**
* set asc flag * 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 * 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 * 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 * virtual stream method
@@ -155,7 +169,9 @@ public:
virtual void setDerivedTable(); virtual void setDerivedTable();
virtual void replaceRealCol(std::vector<SRCP>&); virtual void replaceRealCol(std::vector<SRCP>&);
virtual const std::vector<SimpleColumn*>& simpleColumnList() const virtual const std::vector<SimpleColumn*>& simpleColumnList() const
{ return fSimpleColumnList; } {
return fSimpleColumnList;
}
virtual void setSimpleColumnList(); virtual void setSimpleColumnList();
/** /**
@@ -186,7 +202,7 @@ private:
* return the retrived token. curPos reference is updated to the * return the retrived token. curPos reference is updated to the
* new position after end char * 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 * * F&E framework *

View File

@@ -28,12 +28,16 @@
using namespace std; using namespace std;
namespace { namespace
{
/**@brief util struct for converting string to lower case */ /**@brief util struct for converting string to lower case */
struct to_lower struct to_lower
{ {
char operator() (char c) const { return tolower(c); } char operator() (char c) const
{
return tolower(c);
}
}; };
//Trim any leading/trailing ws //Trim any leading/trailing ws
@@ -41,16 +45,21 @@ const string lrtrim(const string& in)
{ {
string::size_type p1; string::size_type p1;
p1 = in.find_first_not_of(" \t\n"); p1 = in.find_first_not_of(" \t\n");
if (p1 == string::npos) p1 = 0; if (p1 == string::npos) p1 = 0;
string::size_type p2; string::size_type p2;
p2 = in.find_last_not_of(" \t\n"); p2 = in.find_last_not_of(" \t\n");
if (p2 == string::npos) p2 = in.size() - 1; if (p2 == string::npos) p2 = in.size() - 1;
return string(in, p1, (p2 - p1 + 1)); return string(in, p1, (p2 - p1 + 1));
} }
} }
namespace execplan { namespace execplan
{
/** /**
* Constructors/Destructors * 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 * friend function
*/ */
ostream& operator<<(ostream &output, const ArithmeticOperator& rhs) ostream& operator<<(ostream& output, const ArithmeticOperator& rhs)
{ {
output << rhs.toString(); output << rhs.toString();
output << "opType=" << rhs.operationType().colDataType << endl; output << "opType=" << rhs.operationType().colDataType << endl;
@@ -104,16 +113,19 @@ bool ArithmeticOperator::operator==(const ArithmeticOperator& t) const
{ {
if (fData == t.fData) if (fData == t.fData)
return true; return true;
return false; return false;
} }
bool ArithmeticOperator::operator==(const TreeNode* t) const bool ArithmeticOperator::operator==(const TreeNode* t) const
{ {
const ArithmeticOperator *o; const ArithmeticOperator* o;
o = dynamic_cast<const ArithmeticOperator*>(t); o = dynamic_cast<const ArithmeticOperator*>(t);
if (o == NULL) if (o == NULL)
return false; return false;
return *this == *o; return *this == *o;
} }
@@ -140,6 +152,7 @@ void ArithmeticOperator::operationType(const Type& l, const Type& r)
fOperationType = fResultType; fOperationType = fResultType;
break; break;
} }
case execplan::CalpontSystemCatalog::INT: case execplan::CalpontSystemCatalog::INT:
case execplan::CalpontSystemCatalog::MEDINT: case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::TINYINT: case execplan::CalpontSystemCatalog::TINYINT:
@@ -147,6 +160,7 @@ void ArithmeticOperator::operationType(const Type& l, const Type& r)
fOperationType.colDataType = execplan::CalpontSystemCatalog::DECIMAL; fOperationType.colDataType = execplan::CalpontSystemCatalog::DECIMAL;
fOperationType.scale = l.scale; fOperationType.scale = l.scale;
break; break;
default: default:
fOperationType.colDataType = execplan::CalpontSystemCatalog::DOUBLE; fOperationType.colDataType = execplan::CalpontSystemCatalog::DOUBLE;
} }
@@ -162,6 +176,7 @@ void ArithmeticOperator::operationType(const Type& l, const Type& r)
fOperationType = fResultType; fOperationType = fResultType;
break; break;
} }
case execplan::CalpontSystemCatalog::INT: case execplan::CalpontSystemCatalog::INT:
case execplan::CalpontSystemCatalog::MEDINT: case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::TINYINT: case execplan::CalpontSystemCatalog::TINYINT:
@@ -169,6 +184,7 @@ void ArithmeticOperator::operationType(const Type& l, const Type& r)
fOperationType.colDataType = execplan::CalpontSystemCatalog::DECIMAL; fOperationType.colDataType = execplan::CalpontSystemCatalog::DECIMAL;
fOperationType.scale = r.scale; fOperationType.scale = r.scale;
break; break;
default: default:
fOperationType.colDataType = execplan::CalpontSystemCatalog::DOUBLE; fOperationType.colDataType = execplan::CalpontSystemCatalog::DOUBLE;
} }

View File

@@ -32,13 +32,16 @@
#include "operator.h" #include "operator.h"
#include "parsetree.h" #include "parsetree.h"
namespace messageqcpp { namespace messageqcpp
{
class ByteStream; class ByteStream;
} }
namespace execplan { namespace execplan
{
class ArithmeticOperator : public Operator { class ArithmeticOperator : public Operator
{
public: public:
ArithmeticOperator(); ArithmeticOperator();
@@ -100,22 +103,22 @@ public:
evaluate(row, isNull, lop, rop); evaluate(row, isNull, lop, rop);
return TreeNode::getStrVal(); 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); evaluate(row, isNull, lop, rop);
return TreeNode::getIntVal(); 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); evaluate(row, isNull, lop, rop);
return TreeNode::getUintVal(); 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); evaluate(row, isNull, lop, rop);
return TreeNode::getFloatVal(); 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); evaluate(row, isNull, lop, rop);
return TreeNode::getDoubleVal(); return TreeNode::getDoubleVal();
@@ -138,17 +141,17 @@ public:
return TreeNode::getDecimalVal(); 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); evaluate(row, isNull, lop, rop);
return TreeNode::getDateIntVal(); 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); evaluate(row, isNull, lop, rop);
return TreeNode::getDatetimeIntVal(); 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); evaluate(row, isNull, lop, rop);
return TreeNode::getBoolVal(); return TreeNode::getBoolVal();
@@ -175,6 +178,7 @@ inline void ArithmeticOperator::evaluate(rowgroup::Row& row, bool& isNull, Parse
case execplan::CalpontSystemCatalog::TINYINT: case execplan::CalpontSystemCatalog::TINYINT:
fResult.intVal = execute(lop->getIntVal(row, isNull), rop->getIntVal(row, isNull), isNull); fResult.intVal = execute(lop->getIntVal(row, isNull), rop->getIntVal(row, isNull), isNull);
break; break;
case execplan::CalpontSystemCatalog::UBIGINT: case execplan::CalpontSystemCatalog::UBIGINT:
case execplan::CalpontSystemCatalog::UINT: case execplan::CalpontSystemCatalog::UINT:
case execplan::CalpontSystemCatalog::UMEDINT: case execplan::CalpontSystemCatalog::UMEDINT:
@@ -182,14 +186,17 @@ inline void ArithmeticOperator::evaluate(rowgroup::Row& row, bool& isNull, Parse
case execplan::CalpontSystemCatalog::UTINYINT: case execplan::CalpontSystemCatalog::UTINYINT:
fResult.uintVal = execute(lop->getUintVal(row, isNull), rop->getUintVal(row, isNull), isNull); fResult.uintVal = execute(lop->getUintVal(row, isNull), rop->getUintVal(row, isNull), isNull);
break; break;
case execplan::CalpontSystemCatalog::DOUBLE: case execplan::CalpontSystemCatalog::DOUBLE:
case execplan::CalpontSystemCatalog::FLOAT: case execplan::CalpontSystemCatalog::FLOAT:
fResult.doubleVal = execute(lop->getDoubleVal(row, isNull), rop->getDoubleVal(row, isNull), isNull); fResult.doubleVal = execute(lop->getDoubleVal(row, isNull), rop->getDoubleVal(row, isNull), isNull);
break; break;
case execplan::CalpontSystemCatalog::DECIMAL: case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL: case execplan::CalpontSystemCatalog::UDECIMAL:
execute (fResult.decimalVal, lop->getDecimalVal(row, isNull), rop->getDecimalVal(row, isNull), isNull); execute (fResult.decimalVal, lop->getDecimalVal(row, isNull), rop->getDecimalVal(row, isNull), isNull);
break; break;
default: default:
{ {
std::ostringstream oss; std::ostringstream oss;
@@ -206,16 +213,21 @@ inline result_t ArithmeticOperator::execute(result_t op1, result_t op2, bool& is
{ {
case OP_ADD: case OP_ADD:
return op1 + op2; return op1 + op2;
case OP_SUB: case OP_SUB:
return op1 - op2; return op1 - op2;
case OP_MUL: case OP_MUL:
return op1 * op2; return op1 * op2;
case OP_DIV: case OP_DIV:
if (op2) if (op2)
return op1 / op2; return op1 / op2;
else else
isNull = true; isNull = true;
return 0; return 0;
default: default:
{ {
std::ostringstream oss; std::ostringstream oss;
@@ -235,63 +247,76 @@ inline void ArithmeticOperator::execute(IDB_Decimal& result, IDB_Decimal op1, ID
result.value = op1.value + op2.value; result.value = op1.value + op2.value;
break; break;
} }
if (result.scale >= op1.scale) if (result.scale >= op1.scale)
op1.value *= IDB_pow[result.scale-op1.scale]; op1.value *= IDB_pow[result.scale - op1.scale];
else else
op1.value = (int64_t)(op1.value > 0 ? 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) if (result.scale >= op2.scale)
op2.value *= IDB_pow[result.scale-op2.scale]; op2.value *= IDB_pow[result.scale - op2.scale];
else else
op2.value = (int64_t)(op2.value > 0 ? 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; result.value = op1.value + op2.value;
break; break;
case OP_SUB: case OP_SUB:
if (result.scale == op1.scale && result.scale == op2.scale) if (result.scale == op1.scale && result.scale == op2.scale)
{ {
result.value = op1.value - op2.value; result.value = op1.value - op2.value;
break; break;
} }
if (result.scale >= op1.scale) if (result.scale >= op1.scale)
op1.value *= IDB_pow[result.scale-op1.scale]; op1.value *= IDB_pow[result.scale - op1.scale];
else else
op1.value = (int64_t)(op1.value > 0 ? 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) if (result.scale >= op2.scale)
op2.value *= IDB_pow[result.scale-op2.scale]; op2.value *= IDB_pow[result.scale - op2.scale];
else else
op2.value = (int64_t)(op2.value > 0 ? 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; result.value = op1.value - op2.value;
break; break;
case OP_MUL: case OP_MUL:
if (result.scale >= op1.scale + op2.scale) 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 else
result.value = (int64_t)(( (op1.value > 0 && op2.value >0) || (op1.value < 0 && op2.value < 0) ? 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 :
(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; break;
case OP_DIV: case OP_DIV:
if (op2.value == 0) if (op2.value == 0)
{ {
isNull = true; isNull = true;
break; break;
} }
if (result.scale >= op1.scale - op2.scale) if (result.scale >= op1.scale - op2.scale)
result.value = (int64_t)(( (op1.value > 0 && op2.value >0) || (op1.value < 0 && op2.value < 0) ? 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 :
(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 else
result.value = (int64_t)(( (op1.value > 0 && op2.value >0) || (op1.value < 0 && op2.value < 0) ? 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 :
(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; break;
default: default:
{ {
std::ostringstream oss; std::ostringstream oss;

Some files were not shown because too many files have changed in this diff Show More