1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +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,7 +25,8 @@
#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):
@ -39,7 +40,9 @@ namespace ddlpackage {
{ {
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;
} }
} }
@ -49,9 +52,11 @@ namespace ddlpackage {
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;
} }
@ -205,6 +210,7 @@ namespace ddlpackage {
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;
} }
@ -219,15 +225,19 @@ namespace ddlpackage {
*/ */
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; delete tableElements;
} }
@ -235,6 +245,7 @@ namespace ddlpackage {
{ {
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)
@ -261,6 +272,7 @@ namespace ddlpackage {
{ {
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)

View File

@ -28,7 +28,8 @@
#include "ddlpkg.h" #include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT #undef DDLPKG_DLLEXPORT
namespace ddlpackage { namespace ddlpackage
{
using namespace std; using namespace std;
@ -37,7 +38,9 @@ namespace ddlpackage {
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;
} }
} }
@ -48,10 +51,12 @@ namespace ddlpackage {
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;
} }
@ -74,7 +79,8 @@ namespace ddlpackage {
{ {
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,9 +93,11 @@ 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;
} }
@ -107,6 +115,7 @@ namespace ddlpackage {
<< 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 << "\"";
@ -116,9 +125,12 @@ namespace ddlpackage {
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;
} }
@ -141,6 +153,7 @@ namespace ddlpackage {
os << "NULL"; os << "NULL";
else else
os << defaultValue.fValue; os << defaultValue.fValue;
return os; return os;
} }

View File

@ -23,7 +23,8 @@
#include "ddlpkg.h" #include "ddlpkg.h"
namespace ddlpackage { namespace ddlpackage
{
using namespace std; using namespace std;
CreateIndexStatement::CreateIndexStatement(): CreateIndexStatement::CreateIndexStatement():

View File

@ -27,7 +27,8 @@
#include "ddlpkg.h" #include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT #undef DDLPKG_DLLEXPORT
namespace ddlpackage { namespace ddlpackage
{
using namespace std; using namespace std;

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,8 @@
# 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,

View File

@ -305,7 +305,8 @@ static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
#define YY_NUM_RULES 85 #define YY_NUM_RULES 85
#define YY_END_OF_BUFFER 86 #define YY_END_OF_BUFFER 86
static yyconst short int yy_accept[393] = static yyconst short int yy_accept[393] =
{ 0, {
0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
86, 85, 81, 80, 83, 13, 83, 83, 83, 16, 86, 85, 81, 80, 83, 13, 83, 83, 83, 16,
82, 84, 82, 82, 82, 82, 82, 82, 82, 82, 82, 84, 82, 82, 82, 82, 82, 82, 82, 82,
@ -353,7 +354,8 @@ static yyconst short int yy_accept[393] =
} ; } ;
static yyconst int yy_ec[256] = static yyconst int yy_ec[256] =
{ 0, {
0,
1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 2, 4, 1, 1, 1, 1, 1, 1, 1, 1, 2, 4, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -385,7 +387,8 @@ static yyconst int yy_ec[256] =
} ; } ;
static yyconst int yy_meta[41] = static yyconst int yy_meta[41] =
{ 0, {
0,
1, 1, 2, 2, 3, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 1, 1, 1, 1, 1,
1, 1, 3, 3, 1, 3, 3, 3, 3, 3, 1, 1, 3, 3, 1, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
@ -393,7 +396,8 @@ static yyconst int yy_meta[41] =
} ; } ;
static yyconst short int yy_base[400] = static yyconst short int yy_base[400] =
{ 0, {
0,
0, 0, 33, 35, 428, 427, 428, 427, 426, 425, 0, 0, 33, 35, 428, 427, 428, 427, 426, 425,
431, 438, 43, 46, 438, 438, 39, 42, 417, 44, 431, 438, 43, 46, 438, 438, 39, 42, 417, 44,
0, 438, 40, 405, 45, 49, 31, 36, 56, 408, 0, 438, 40, 405, 45, 49, 31, 36, 56, 408,
@ -441,7 +445,8 @@ static yyconst short int yy_base[400] =
} ; } ;
static yyconst short int yy_def[400] = static yyconst short int yy_def[400] =
{ 0, {
0,
392, 1, 393, 393, 394, 394, 395, 395, 393, 393, 392, 1, 393, 393, 394, 394, 395, 395, 393, 393,
392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392,
396, 392, 396, 396, 396, 396, 396, 396, 396, 396, 396, 392, 396, 396, 396, 396, 396, 396, 396, 396,
@ -489,7 +494,8 @@ static yyconst short int yy_def[400] =
} ; } ;
static yyconst short int yy_nxt[479] = static yyconst short int yy_nxt[479] =
{ 0, {
0,
12, 13, 14, 13, 12, 15, 16, 15, 15, 17, 12, 13, 14, 13, 12, 15, 16, 15, 15, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 21, 21, 29, 21, 30, 21, 31, 32, 33, 28, 21, 21, 29, 21, 30, 21, 31, 32, 33,
@ -545,7 +551,8 @@ static yyconst short int yy_nxt[479] =
} ; } ;
static yyconst short int yy_chk[479] = static yyconst short int yy_chk[479] =
{ 0, {
0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -850,20 +857,25 @@ YY_DECL
yy_current_state = yy_start; yy_current_state = yy_start;
yy_match: yy_match:
do do
{ {
register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
if ( yy_accept[yy_current_state] ) if ( yy_accept[yy_current_state] )
{ {
yy_last_accepting_state = yy_current_state; yy_last_accepting_state = yy_current_state;
yy_last_accepting_cpos = yy_cp; yy_last_accepting_cpos = yy_cp;
} }
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 393 ) if ( yy_current_state >= 393 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp; ++yy_cp;
} }
@ -871,8 +883,10 @@ yy_match:
yy_find_action: yy_find_action:
yy_act = yy_accept[yy_current_state]; yy_act = yy_accept[yy_current_state];
if ( yy_act == 0 ) if ( yy_act == 0 )
{ /* have to back up */ {
/* have to back up */
yy_cp = yy_last_accepting_cpos; yy_cp = yy_last_accepting_cpos;
yy_current_state = yy_last_accepting_state; yy_current_state = yy_last_accepting_state;
yy_act = yy_accept[yy_current_state]; yy_act = yy_accept[yy_current_state];
@ -885,7 +899,8 @@ do_action: /* This label is used only to access EOF actions. */
switch ( yy_act ) switch ( yy_act )
{ /* beginning of action switch */ {
/* beginning of action switch */
case 0: /* must back up */ case 0: /* must back up */
/* undo the effects of YY_DO_BEFORE_ACTION */ /* undo the effects of YY_DO_BEFORE_ACTION */
*yy_cp = yy_hold_char; *yy_cp = yy_hold_char;
@ -897,42 +912,52 @@ case 1:
YY_RULE_SETUP YY_RULE_SETUP
{return ACTION;} {return ACTION;}
YY_BREAK YY_BREAK
case 2: case 2:
YY_RULE_SETUP YY_RULE_SETUP
{return ADD;} {return ADD;}
YY_BREAK YY_BREAK
case 3: case 3:
YY_RULE_SETUP YY_RULE_SETUP
{return ALTER;} {return ALTER;}
YY_BREAK YY_BREAK
case 4: case 4:
YY_RULE_SETUP YY_RULE_SETUP
{return AUTO_INCREMENT;} {return AUTO_INCREMENT;}
YY_BREAK YY_BREAK
case 5: case 5:
YY_RULE_SETUP YY_RULE_SETUP
{return CASCADE;} {return CASCADE;}
YY_BREAK YY_BREAK
case 6: case 6:
YY_RULE_SETUP YY_RULE_SETUP
{return IDB_CHAR;} {return IDB_CHAR;}
YY_BREAK YY_BREAK
case 7: case 7:
YY_RULE_SETUP YY_RULE_SETUP
{return IDB_CHAR;} {return IDB_CHAR;}
YY_BREAK YY_BREAK
case 8: case 8:
YY_RULE_SETUP YY_RULE_SETUP
{return BIGINT;} {return BIGINT;}
YY_BREAK YY_BREAK
case 9: case 9:
YY_RULE_SETUP YY_RULE_SETUP
{BEGIN(check1); return CHECK;} {BEGIN(check1); return CHECK;}
YY_BREAK YY_BREAK
case 10: case 10:
YY_RULE_SETUP YY_RULE_SETUP
{BEGIN(check2); return '(';} {BEGIN(check2); return '(';}
YY_BREAK YY_BREAK
case 11: case 11:
*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ *yy_cp = yy_hold_char; /* undo effects of setting up yytext */
yy_c_buf_p = yy_cp -= 1; yy_c_buf_p = yy_cp -= 1;
@ -940,14 +965,17 @@ YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP YY_RULE_SETUP
{BEGIN(check1); ddllval.str = scanner_copy(ddltext); return CP_SEARCH_CONDITION_TEXT;} {BEGIN(check1); ddllval.str = scanner_copy(ddltext); return CP_SEARCH_CONDITION_TEXT;}
YY_BREAK YY_BREAK
case 12: case 12:
YY_RULE_SETUP YY_RULE_SETUP
{BEGIN(0); return ')';} {BEGIN(0); return ')';}
YY_BREAK YY_BREAK
case 13: case 13:
YY_RULE_SETUP YY_RULE_SETUP
{BEGIN(inquote); return yytext[0];} {BEGIN(inquote); return yytext[0];}
YY_BREAK YY_BREAK
case 14: case 14:
*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ *yy_cp = yy_hold_char; /* undo effects of setting up yytext */
yy_c_buf_p = yy_cp -= 1; yy_c_buf_p = yy_cp -= 1;
@ -955,296 +983,368 @@ YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP YY_RULE_SETUP
{BEGIN(endquote); ddllval.str = scanner_copy(ddltext); return SCONST;} {BEGIN(endquote); ddllval.str = scanner_copy(ddltext); return SCONST;}
YY_BREAK YY_BREAK
case 15: case 15:
YY_RULE_SETUP YY_RULE_SETUP
{BEGIN(0); return yytext[0];} {BEGIN(0); return yytext[0];}
YY_BREAK YY_BREAK
case 16: case 16:
YY_RULE_SETUP YY_RULE_SETUP
{ddllval.str = scanner_copy(ddltext); return ICONST;} {ddllval.str = scanner_copy(ddltext); return ICONST;}
YY_BREAK YY_BREAK
case 17: case 17:
YY_RULE_SETUP YY_RULE_SETUP
{ddllval.str = scanner_copy(ddltext); return FCONST;} {ddllval.str = scanner_copy(ddltext); return FCONST;}
YY_BREAK YY_BREAK
case 18: case 18:
YY_RULE_SETUP YY_RULE_SETUP
{ddllval.str = scanner_copy(ddltext); return FCONST;} {ddllval.str = scanner_copy(ddltext); return FCONST;}
YY_BREAK YY_BREAK
case 19: case 19:
YY_RULE_SETUP YY_RULE_SETUP
{return COMMENT;} {return COMMENT;}
YY_BREAK YY_BREAK
case 20: case 20:
YY_RULE_SETUP YY_RULE_SETUP
{return COLUMN;} {return COLUMN;}
YY_BREAK YY_BREAK
case 21: case 21:
YY_RULE_SETUP YY_RULE_SETUP
{return COLUMNS;} {return COLUMNS;}
YY_BREAK YY_BREAK
case 22: case 22:
YY_RULE_SETUP YY_RULE_SETUP
{return CONSTRAINT;} {return CONSTRAINT;}
YY_BREAK YY_BREAK
case 23: case 23:
YY_RULE_SETUP YY_RULE_SETUP
{return CONSTRAINTS;} {return CONSTRAINTS;}
YY_BREAK YY_BREAK
case 24: case 24:
YY_RULE_SETUP YY_RULE_SETUP
{return CREATE;} {return CREATE;}
YY_BREAK YY_BREAK
case 25: case 25:
YY_RULE_SETUP YY_RULE_SETUP
{return CURRENT_USER;} {return CURRENT_USER;}
YY_BREAK YY_BREAK
case 26: case 26:
YY_RULE_SETUP YY_RULE_SETUP
{ddllval.str = strdup("date"); return DATE;} {ddllval.str = strdup("date"); return DATE;}
YY_BREAK YY_BREAK
case 27: case 27:
YY_RULE_SETUP YY_RULE_SETUP
{return DATETIME;} {return DATETIME;}
YY_BREAK YY_BREAK
case 28: case 28:
YY_RULE_SETUP YY_RULE_SETUP
{return DECIMAL;} {return DECIMAL;}
YY_BREAK YY_BREAK
case 29: case 29:
YY_RULE_SETUP YY_RULE_SETUP
{return DECIMAL;} {return DECIMAL;}
YY_BREAK YY_BREAK
case 30: case 30:
YY_RULE_SETUP YY_RULE_SETUP
{return DEFAULT;} {return DEFAULT;}
YY_BREAK YY_BREAK
case 31: case 31:
YY_RULE_SETUP YY_RULE_SETUP
{return DEFERRABLE;} {return DEFERRABLE;}
YY_BREAK YY_BREAK
case 32: case 32:
YY_RULE_SETUP YY_RULE_SETUP
{return DEFERRED;} {return DEFERRED;}
YY_BREAK YY_BREAK
case 33: case 33:
YY_RULE_SETUP YY_RULE_SETUP
{return IDB_DELETE;} {return IDB_DELETE;}
YY_BREAK YY_BREAK
case 34: case 34:
YY_RULE_SETUP YY_RULE_SETUP
{return DROP;} {return DROP;}
YY_BREAK YY_BREAK
case 35: case 35:
YY_RULE_SETUP YY_RULE_SETUP
{return ENGINE;} {return ENGINE;}
YY_BREAK YY_BREAK
case 36: case 36:
YY_RULE_SETUP YY_RULE_SETUP
{return FOREIGN;} {return FOREIGN;}
YY_BREAK YY_BREAK
case 37: case 37:
YY_RULE_SETUP YY_RULE_SETUP
{return FULL;} {return FULL;}
YY_BREAK YY_BREAK
case 38: case 38:
YY_RULE_SETUP YY_RULE_SETUP
{return IMMEDIATE;} {return IMMEDIATE;}
YY_BREAK YY_BREAK
case 39: case 39:
YY_RULE_SETUP YY_RULE_SETUP
{return INDEX;} {return INDEX;}
YY_BREAK YY_BREAK
case 40: case 40:
YY_RULE_SETUP YY_RULE_SETUP
{return INITIALLY;} {return INITIALLY;}
YY_BREAK YY_BREAK
case 41: case 41:
YY_RULE_SETUP YY_RULE_SETUP
{return IDB_INT;} {return IDB_INT;}
YY_BREAK YY_BREAK
case 42: case 42:
YY_RULE_SETUP YY_RULE_SETUP
{return INTEGER;} {return INTEGER;}
YY_BREAK YY_BREAK
case 43: case 43:
YY_RULE_SETUP YY_RULE_SETUP
{return KEY;} {return KEY;}
YY_BREAK YY_BREAK
case 44: case 44:
YY_RULE_SETUP YY_RULE_SETUP
{return MATCH;} {return MATCH;}
YY_BREAK YY_BREAK
case 45: case 45:
YY_RULE_SETUP YY_RULE_SETUP
{return MAX_ROWS;} {return MAX_ROWS;}
YY_BREAK YY_BREAK
case 46: case 46:
YY_RULE_SETUP YY_RULE_SETUP
{return MIN_ROWS;} {return MIN_ROWS;}
YY_BREAK YY_BREAK
case 47: case 47:
YY_RULE_SETUP YY_RULE_SETUP
{return MODIFY;} {return MODIFY;}
YY_BREAK YY_BREAK
case 48: case 48:
YY_RULE_SETUP YY_RULE_SETUP
{return NO;} {return NO;}
YY_BREAK YY_BREAK
case 49: case 49:
YY_RULE_SETUP YY_RULE_SETUP
{return NOT;} {return NOT;}
YY_BREAK YY_BREAK
case 50: case 50:
YY_RULE_SETUP YY_RULE_SETUP
{return NULL_TOK;} {return NULL_TOK;}
YY_BREAK YY_BREAK
case 51: case 51:
YY_RULE_SETUP YY_RULE_SETUP
{return NUMERIC;} {return NUMERIC;}
YY_BREAK YY_BREAK
case 52: case 52:
YY_RULE_SETUP YY_RULE_SETUP
{return ON;} {return ON;}
YY_BREAK YY_BREAK
case 53: case 53:
YY_RULE_SETUP YY_RULE_SETUP
{return PARTIAL;} {return PARTIAL;}
YY_BREAK YY_BREAK
case 54: case 54:
YY_RULE_SETUP YY_RULE_SETUP
{return PRECISION;} {return PRECISION;}
YY_BREAK YY_BREAK
case 55: case 55:
YY_RULE_SETUP YY_RULE_SETUP
{return PRIMARY;} {return PRIMARY;}
YY_BREAK YY_BREAK
case 56: case 56:
YY_RULE_SETUP YY_RULE_SETUP
{return REFERENCES;} {return REFERENCES;}
YY_BREAK YY_BREAK
case 57: case 57:
YY_RULE_SETUP YY_RULE_SETUP
{return RENAME;} {return RENAME;}
YY_BREAK YY_BREAK
case 58: case 58:
YY_RULE_SETUP YY_RULE_SETUP
{return RESTRICT;} {return RESTRICT;}
YY_BREAK YY_BREAK
case 59: case 59:
YY_RULE_SETUP YY_RULE_SETUP
{return SESSION_USER;} {return SESSION_USER;}
YY_BREAK YY_BREAK
case 60: case 60:
YY_RULE_SETUP YY_RULE_SETUP
{return SYSTEM_USER;} {return SYSTEM_USER;}
YY_BREAK YY_BREAK
case 61: case 61:
YY_RULE_SETUP YY_RULE_SETUP
{return SET;} {return SET;}
YY_BREAK YY_BREAK
case 62: case 62:
YY_RULE_SETUP YY_RULE_SETUP
{return SMALLINT;} {return SMALLINT;}
YY_BREAK YY_BREAK
case 63: case 63:
YY_RULE_SETUP YY_RULE_SETUP
{return TABLE;} {return TABLE;}
YY_BREAK YY_BREAK
case 64: case 64:
YY_RULE_SETUP YY_RULE_SETUP
{return TINYINT;} {return TINYINT;}
YY_BREAK YY_BREAK
case 65: case 65:
YY_RULE_SETUP YY_RULE_SETUP
{return TO;} {return TO;}
YY_BREAK YY_BREAK
case 66: case 66:
YY_RULE_SETUP YY_RULE_SETUP
{return UNIQUE;} {return UNIQUE;}
YY_BREAK YY_BREAK
case 67: case 67:
YY_RULE_SETUP YY_RULE_SETUP
{return UNSIGNED;} {return UNSIGNED;}
YY_BREAK YY_BREAK
case 68: case 68:
YY_RULE_SETUP YY_RULE_SETUP
{return UPDATE;} {return UPDATE;}
YY_BREAK YY_BREAK
case 69: case 69:
YY_RULE_SETUP YY_RULE_SETUP
{return USER;} {return USER;}
YY_BREAK YY_BREAK
case 70: case 70:
YY_RULE_SETUP YY_RULE_SETUP
{return VARCHAR;} {return VARCHAR;}
YY_BREAK YY_BREAK
case 71: case 71:
YY_RULE_SETUP YY_RULE_SETUP
{return IDB_FLOAT;} {return IDB_FLOAT;}
YY_BREAK YY_BREAK
case 72: case 72:
YY_RULE_SETUP YY_RULE_SETUP
{return DOUBLE;} {return DOUBLE;}
YY_BREAK YY_BREAK
case 73: case 73:
YY_RULE_SETUP YY_RULE_SETUP
{return REAL;} {return REAL;}
YY_BREAK YY_BREAK
case 74: case 74:
YY_RULE_SETUP YY_RULE_SETUP
{return CHARSET;} {return CHARSET;}
YY_BREAK YY_BREAK
case 75: case 75:
YY_RULE_SETUP YY_RULE_SETUP
{return IDB_IF;} {return IDB_IF;}
YY_BREAK YY_BREAK
case 76: case 76:
YY_RULE_SETUP YY_RULE_SETUP
{return EXISTS;} {return EXISTS;}
YY_BREAK YY_BREAK
case 77: case 77:
YY_RULE_SETUP YY_RULE_SETUP
{return CHANGE;} {return CHANGE;}
YY_BREAK YY_BREAK
case 78: case 78:
YY_RULE_SETUP YY_RULE_SETUP
{return TRUNCATE;} {return TRUNCATE;}
YY_BREAK YY_BREAK
case 79: case 79:
YY_RULE_SETUP YY_RULE_SETUP
{return VARBINARY;} {return VARBINARY;}
YY_BREAK YY_BREAK
case 80: case 80:
YY_RULE_SETUP YY_RULE_SETUP
{ lineno++;} { lineno++;}
YY_BREAK YY_BREAK
case 81: case 81:
YY_RULE_SETUP YY_RULE_SETUP
{ {
/* ignore */ /* ignore */
} }
YY_BREAK YY_BREAK
case 82: case 82:
YY_RULE_SETUP YY_RULE_SETUP
{ddllval.str = scanner_copy(ddltext); return IDENT;} {ddllval.str = scanner_copy(ddltext); return IDENT;}
YY_BREAK YY_BREAK
case 83: case 83:
YY_RULE_SETUP YY_RULE_SETUP
{ {
return ddltext[0]; return ddltext[0];
} }
YY_BREAK YY_BREAK
case 84: case 84:
YY_RULE_SETUP YY_RULE_SETUP
{ {
/* ignore */ /* ignore */
} }
YY_BREAK YY_BREAK
case 85: case 85:
YY_RULE_SETUP YY_RULE_SETUP
ECHO; ECHO;
YY_BREAK YY_BREAK
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(check1): case YY_STATE_EOF(check1):
case YY_STATE_EOF(check2): case YY_STATE_EOF(check2):
@ -1285,7 +1385,8 @@ case YY_STATE_EOF(endquote):
* in input(). * in input().
*/ */
if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
{ /* This was really a NUL. */ {
/* This was really a NUL. */
yy_state_type yy_next_state; yy_state_type yy_next_state;
yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
@ -1348,6 +1449,7 @@ case YY_STATE_EOF(endquote):
if ( ! yy_did_buffer_switch_on_eof ) if ( ! yy_did_buffer_switch_on_eof )
YY_NEW_FILE; YY_NEW_FILE;
} }
break; break;
} }
@ -1371,6 +1473,7 @@ case YY_STATE_EOF(endquote):
yy_bp = yytext_ptr + YY_MORE_ADJ; yy_bp = yytext_ptr + YY_MORE_ADJ;
goto yy_find_action; goto yy_find_action;
} }
break; break;
} }
@ -1402,7 +1505,8 @@ static int yy_get_next_buffer()
"fatal flex scanner internal error--end of buffer missed" ); "fatal flex scanner internal error--end of buffer missed" );
if ( yy_current_buffer->yy_fill_buffer == 0 ) if ( yy_current_buffer->yy_fill_buffer == 0 )
{ /* Don't try to fill the buffer, so this is an EOF. */ {
/* Don't try to fill the buffer, so this is an EOF. */
if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
{ {
/* We matched a single character, the EOB, so /* We matched a single character, the EOB, so
@ -1440,7 +1544,8 @@ static int yy_get_next_buffer()
yy_current_buffer->yy_buf_size - number_to_move - 1; yy_current_buffer->yy_buf_size - number_to_move - 1;
while ( num_to_read <= 0 ) while ( num_to_read <= 0 )
{ /* Not enough room in the buffer - grow it. */ {
/* Not enough room in the buffer - grow it. */
#ifdef YY_USES_REJECT #ifdef YY_USES_REJECT
YY_FATAL_ERROR( YY_FATAL_ERROR(
"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); "input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
@ -1532,17 +1637,21 @@ static yy_state_type yy_get_previous_state()
for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
{ {
register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
if ( yy_accept[yy_current_state] ) if ( yy_accept[yy_current_state] )
{ {
yy_last_accepting_state = yy_current_state; yy_last_accepting_state = yy_current_state;
yy_last_accepting_cpos = yy_cp; yy_last_accepting_cpos = yy_cp;
} }
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 393 ) if ( yy_current_state >= 393 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
} }
@ -1567,17 +1676,21 @@ yy_state_type yy_current_state;
register char* yy_cp = yy_c_buf_p; register char* yy_cp = yy_c_buf_p;
register YY_CHAR yy_c = 1; register YY_CHAR yy_c = 1;
if ( yy_accept[yy_current_state] ) if ( yy_accept[yy_current_state] )
{ {
yy_last_accepting_state = yy_current_state; yy_last_accepting_state = yy_current_state;
yy_last_accepting_cpos = yy_cp; yy_last_accepting_cpos = yy_cp;
} }
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 393 ) if ( yy_current_state >= 393 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 392); yy_is_jam = (yy_current_state == 392);
@ -1600,7 +1713,8 @@ register char *yy_bp;
*yy_cp = yy_hold_char; *yy_cp = yy_hold_char;
if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
{ /* need to shift things up to make room */ {
/* need to shift things up to make room */
/* +2 for EOB chars. */ /* +2 for EOB chars. */
register int number_to_move = yy_n_chars + 2; register int number_to_move = yy_n_chars + 2;
register char* dest = &yy_current_buffer->yy_ch_buf[ register char* dest = &yy_current_buffer->yy_ch_buf[
@ -1651,7 +1765,8 @@ static int input()
*yy_c_buf_p = '\0'; *yy_c_buf_p = '\0';
else else
{ /* need more input */ {
/* need more input */
int offset = yy_c_buf_p - yytext_ptr; int offset = yy_c_buf_p - yytext_ptr;
++yy_c_buf_p; ++yy_c_buf_p;
@ -1680,6 +1795,7 @@ static int input()
if ( ! yy_did_buffer_switch_on_eof ) if ( ! yy_did_buffer_switch_on_eof )
YY_NEW_FILE; YY_NEW_FILE;
#ifdef __cplusplus #ifdef __cplusplus
return yyinput(); return yyinput();
#else #else
@ -1772,6 +1888,7 @@ int size;
YY_BUFFER_STATE b; YY_BUFFER_STATE b;
b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
if ( ! b ) if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
@ -1781,6 +1898,7 @@ int size;
* we need to put in 2 end-of-buffer characters. * we need to put in 2 end-of-buffer characters.
*/ */
b->yy_ch_buf = (char*) yy_flex_alloc( b->yy_buf_size + 2 ); b->yy_ch_buf = (char*) yy_flex_alloc( b->yy_buf_size + 2 );
if ( ! b->yy_ch_buf ) if ( ! b->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
@ -1893,6 +2011,7 @@ yy_size_t size;
return 0; return 0;
b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
if ( ! b ) if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
@ -1922,6 +2041,7 @@ yyconst char *yy_str;
#endif #endif
{ {
int len; int len;
for ( len = 0; yy_str[len]; ++len ) for ( len = 0; yy_str[len]; ++len )
; ;
@ -1947,6 +2067,7 @@ int len;
/* Get memory for full buffer, including space for trailing EOB's. */ /* Get memory for full buffer, including space for trailing EOB's. */
n = len + 2; n = len + 2;
buf = (char*) yy_flex_alloc( n ); buf = (char*) yy_flex_alloc( n );
if ( ! buf ) if ( ! buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
@ -1956,6 +2077,7 @@ int len;
buf[len] = buf[len + 1] = YY_END_OF_BUFFER_CHAR; buf[len] = buf[len + 1] = YY_END_OF_BUFFER_CHAR;
b = yy_scan_buffer( buf, n ); b = yy_scan_buffer( buf, n );
if ( ! b ) if ( ! b )
YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
@ -2067,6 +2189,7 @@ int n;
#endif #endif
{ {
register int i; register int i;
for ( i = 0; i < n; ++i ) for ( i = 0; i < n; ++i )
s1[i] = s2[i]; s1[i] = s2[i];
} }
@ -2081,6 +2204,7 @@ yyconst char *s;
#endif #endif
{ {
register int n; register int n;
for ( n = 0; s[n]; ++n ) for ( n = 0; s[n]; ++n )
; ;
@ -2184,20 +2308,27 @@ void scanner_finish(void)
yy_delete_buffer(scanbufhandle); yy_delete_buffer(scanbufhandle);
free(scanbuf); free(scanbuf);
unsigned int i; unsigned int i;
for(i=0; i<valbuf.size(); i++) {
for (i = 0; i < valbuf.size(); i++)
{
str = valbuf[i]; str = valbuf[i];
if(str) {
if (str)
{
// std::cout << "valbuf:(" << str << ")" << std::endl; // std::cout << "valbuf:(" << str << ")" << std::endl;
free(valbuf[i]); free(valbuf[i]);
} }
} }
valbuf.clear(); valbuf.clear();
} }
char* scanner_copy (char* str) char* scanner_copy (char* str)
{ {
char* nv = strdup(str); char* nv = strdup(str);
if (nv) if (nv)
valbuf.push_back(nv); valbuf.push_back(nv);
return nv; return nv;
} }

View File

@ -53,8 +53,10 @@ namespace ddlpackage
{ {
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;
} }
@ -68,15 +70,18 @@ namespace ddlpackage
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;
} }
@ -104,20 +109,25 @@ namespace ddlpackage
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;

View File

@ -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
@ -137,7 +139,8 @@ const std::string ConstraintAttrStrings[] =
}; };
enum DDL_REFERENTIAL_ACTION { enum DDL_REFERENTIAL_ACTION
{
DDL_CASCADE, DDL_CASCADE,
DDL_SET_NULL, DDL_SET_NULL,
DDL_SET_DEFAULT, DDL_SET_DEFAULT,
@ -155,7 +158,8 @@ const std::string ReferentialActionStrings[] =
"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
@ -172,7 +176,8 @@ const std::string MatchTypeStrings[] =
/** @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,
@ -199,7 +204,8 @@ const std::string ConstraintString[] =
/** @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,
@ -325,7 +331,8 @@ const int DDLDatatypeLength[] =
-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,
@ -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;
} }
@ -935,6 +943,7 @@ struct AtaRenameColumn : public AlterTableAction
{ {
if (comment) if (comment)
fComment = comment; fComment = comment;
fDefaultValue = 0; fDefaultValue = 0;
} }
@ -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;
} }
@ -1495,6 +1505,7 @@ 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;
} }
@ -1528,6 +1539,7 @@ 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;
} }

View File

@ -23,7 +23,8 @@
#include "ddlpkg.h" #include "ddlpkg.h"
namespace ddlpackage { namespace ddlpackage
{
using namespace std; using namespace std;
DropIndexStatement::~DropIndexStatement() DropIndexStatement::~DropIndexStatement()

View File

@ -27,7 +27,8 @@
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,7 +27,8 @@
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),

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,12 +52,14 @@ 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;
@ -64,7 +67,8 @@ int main(int argc, char* argv[])
cout << ptree; cout << ptree;
cout << endl; cout << endl;
} }
else { else
{
cout << "Parser failed." << endl; cout << "Parser failed." << endl;
} }

View File

@ -27,7 +27,8 @@
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,7 +50,8 @@ 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 );
@ -336,7 +337,8 @@ 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 );
@ -401,11 +403,13 @@ 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 );
@ -470,13 +474,15 @@ 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 );
@ -541,12 +547,14 @@ 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 );
@ -612,12 +620,14 @@ 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 );
@ -683,6 +693,7 @@ public:
delete pDDLPackage; delete pDDLPackage;
} }
fin.close(); fin.close();
} }

View File

@ -27,7 +27,8 @@
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;
} }

View File

@ -51,7 +51,9 @@ void read_vec(vector<T*>& v, ByteStream& bs)
T* x; T* x;
quadbyte count; quadbyte count;
bs >> count; bs >> count;
while(count--) {
while (count--)
{
x = new T; x = new T;
x->unserialize(bs); x->unserialize(bs);
v.push_back(x); v.push_back(x);
@ -122,6 +124,7 @@ int AlterTableStatement::unserialize(ByteStream& bytestream)
// read alter action list // read alter action list
quadbyte action_count; quadbyte action_count;
bytestream >> action_count; bytestream >> action_count;
for ( unsigned int i = 0; i < action_count; i++ ) for ( unsigned int i = 0; i < action_count; i++ )
{ {
// read action type // read action type
@ -134,65 +137,78 @@ int AlterTableStatement::unserialize(ByteStream& bytestream)
ata->unserialize(bytestream); ata->unserialize(bytestream);
fActions.push_back( ata ); fActions.push_back( ata );
break; break;
case DDL_ATA_ADD_COLUMNS: case DDL_ATA_ADD_COLUMNS:
ata = new AtaAddColumns(); ata = new AtaAddColumns();
ata->unserialize(bytestream); ata->unserialize(bytestream);
fActions.push_back( ata ); fActions.push_back( ata );
break; break;
case DDL_ATA_DROP_COLUMN: case DDL_ATA_DROP_COLUMN:
ata = new AtaDropColumn(); ata = new AtaDropColumn();
ata->unserialize(bytestream); ata->unserialize(bytestream);
fActions.push_back( ata ); fActions.push_back( ata );
break; break;
case DDL_ATA_DROP_COLUMNS: case DDL_ATA_DROP_COLUMNS:
ata = new AtaDropColumns(); ata = new AtaDropColumns();
ata->unserialize(bytestream); ata->unserialize(bytestream);
fActions.push_back( ata ); fActions.push_back( ata );
break; break;
case DDL_ATA_ADD_TABLE_CONSTRAINT: case DDL_ATA_ADD_TABLE_CONSTRAINT:
ata = new AtaAddTableConstraint(); ata = new AtaAddTableConstraint();
ata->unserialize(bytestream); ata->unserialize(bytestream);
fActions.push_back( ata ); fActions.push_back( ata );
break; break;
case DDL_ATA_SET_COLUMN_DEFAULT: case DDL_ATA_SET_COLUMN_DEFAULT:
ata = new AtaSetColumnDefault(); ata = new AtaSetColumnDefault();
ata->unserialize(bytestream); ata->unserialize(bytestream);
fActions.push_back( ata ); fActions.push_back( ata );
break; break;
case DDL_ATA_DROP_COLUMN_DEFAULT: case DDL_ATA_DROP_COLUMN_DEFAULT:
ata = new AtaDropColumnDefault(); ata = new AtaDropColumnDefault();
ata->unserialize(bytestream); ata->unserialize(bytestream);
fActions.push_back( ata ); fActions.push_back( ata );
break; break;
case DDL_ATA_DROP_TABLE_CONSTRAINT: case DDL_ATA_DROP_TABLE_CONSTRAINT:
ata = new AtaDropTableConstraint(); ata = new AtaDropTableConstraint();
ata->unserialize(bytestream); ata->unserialize(bytestream);
fActions.push_back( ata ); fActions.push_back( ata );
break; break;
case DDL_ATA_RENAME_TABLE: case DDL_ATA_RENAME_TABLE:
ata = new AtaRenameTable(); ata = new AtaRenameTable();
ata->unserialize(bytestream); ata->unserialize(bytestream);
fActions.push_back( ata ); fActions.push_back( ata );
break; break;
case DDL_ATA_RENAME_COLUMN: case DDL_ATA_RENAME_COLUMN:
ata = new AtaRenameColumn(); ata = new AtaRenameColumn();
ata->unserialize(bytestream); ata->unserialize(bytestream);
fActions.push_back( ata ); fActions.push_back( ata );
break; break;
case DDL_ATA_MODIFY_COLUMN_TYPE: case DDL_ATA_MODIFY_COLUMN_TYPE:
ata = new AtaModifyColumnType(); ata = new AtaModifyColumnType();
ata->unserialize(bytestream); ata->unserialize(bytestream);
fActions.push_back( ata ); fActions.push_back( ata );
break; break;
case DDL_ATA_TABLE_COMMENT: case DDL_ATA_TABLE_COMMENT:
ata = new AtaTableComment(); ata = new AtaTableComment();
ata->unserialize(bytestream); ata->unserialize(bytestream);
fActions.push_back( ata ); fActions.push_back( ata );
break; break;
default: default:
throw ("Bad typecode for AlterTableAction"); throw ("Bad typecode for AlterTableAction");
break; break;
} }
bytestream >> fSessionID; bytestream >> fSessionID;
bytestream >> fSql; bytestream >> fSql;
bytestream >> fOwner; bytestream >> fOwner;
@ -253,6 +269,7 @@ int CreateIndexStatement::unserialize(ByteStream& bytestream)
std::string columnname; std::string columnname;
for ( unsigned int i = 0; i < column_count; i++ ) for ( unsigned int i = 0; i < column_count; i++ )
{ {
bytestream >> columnname; bytestream >> columnname;
@ -286,6 +303,7 @@ int CreateIndexStatement::serialize(ByteStream& bytestream)
// write column name list // write column name list
bytestream << (quadbyte) fColumnNames.size(); bytestream << (quadbyte) fColumnNames.size();
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
for (itr = fColumnNames.begin(); for (itr = fColumnNames.begin();
itr != fColumnNames.end(); itr != fColumnNames.end();
++itr) ++itr)
@ -494,6 +512,7 @@ int MarkPartitionStatement::unserialize(ByteStream& bytestream)
uint32_t size = 0; uint32_t size = 0;
bytestream >> size; bytestream >> size;
BRM::LogicalPartition part; BRM::LogicalPartition part;
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
{ {
part.unserialize(bytestream); part.unserialize(bytestream);
@ -525,6 +544,7 @@ int MarkPartitionStatement::serialize(ByteStream& bytestream)
bytestream << (uint32_t)fPartitions.size(); bytestream << (uint32_t)fPartitions.size();
set<BRM::LogicalPartition>::iterator it; set<BRM::LogicalPartition>::iterator it;
for (it = fPartitions.begin(); it != fPartitions.end(); ++it) for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
(*it).serialize(bytestream); (*it).serialize(bytestream);
@ -555,6 +575,7 @@ int DropPartitionStatement::unserialize(ByteStream& bytestream)
uint32_t size = 0; uint32_t size = 0;
bytestream >> size; bytestream >> size;
BRM::LogicalPartition part; BRM::LogicalPartition part;
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
{ {
part.unserialize(bytestream); part.unserialize(bytestream);
@ -584,6 +605,7 @@ int DropPartitionStatement::serialize(ByteStream& bytestream)
bytestream << fOwner; bytestream << fOwner;
bytestream << (uint32_t)fPartitions.size(); bytestream << (uint32_t)fPartitions.size();
set<BRM::LogicalPartition>::iterator it; set<BRM::LogicalPartition>::iterator it;
for (it = fPartitions.begin(); it != fPartitions.end(); ++it) for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
(*it).serialize(bytestream); (*it).serialize(bytestream);
@ -614,6 +636,7 @@ int RestorePartitionStatement::unserialize(ByteStream& bytestream)
uint32_t size = 0; uint32_t size = 0;
bytestream >> size; bytestream >> size;
BRM::LogicalPartition part; BRM::LogicalPartition part;
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
{ {
part.unserialize(bytestream); part.unserialize(bytestream);
@ -644,6 +667,7 @@ int RestorePartitionStatement::serialize(ByteStream& bytestream)
bytestream << (uint32_t)fPartitions.size(); bytestream << (uint32_t)fPartitions.size();
set<BRM::LogicalPartition>::iterator it; set<BRM::LogicalPartition>::iterator it;
for (it = fPartitions.begin(); it != fPartitions.end(); ++it) for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
(*it).serialize(bytestream); (*it).serialize(bytestream);
@ -722,6 +746,7 @@ int AtaDropColumns::unserialize(ByteStream& bytestream)
quadbyte count; quadbyte count;
bytestream >> count; bytestream >> count;
string colName; string colName;
while (count--) while (count--)
{ {
bytestream >> colName; bytestream >> colName;
@ -742,6 +767,7 @@ int AtaDropColumns::serialize(ByteStream& bytestream)
bytestream << (quadbyte) fColumns.size(); bytestream << (quadbyte) fColumns.size();
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
for (itr = fColumns.begin(); itr != fColumns.end(); itr++) for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
{ {
bytestream << *itr; bytestream << *itr;
@ -771,14 +797,17 @@ int AtaAddTableConstraint::unserialize(ByteStream& bytestream)
fTableConstraint = new TableUniqueConstraintDef; fTableConstraint = new TableUniqueConstraintDef;
fTableConstraint->unserialize(bytestream); fTableConstraint->unserialize(bytestream);
break; break;
case DDL_TABLE_PRIMARY_CONSTRAINT_DEF: case DDL_TABLE_PRIMARY_CONSTRAINT_DEF:
fTableConstraint = new TablePrimaryKeyConstraintDef; fTableConstraint = new TablePrimaryKeyConstraintDef;
fTableConstraint->unserialize(bytestream); fTableConstraint->unserialize(bytestream);
break; break;
case DDL_TABLE_CHECK_CONSTRAINT_DEF: case DDL_TABLE_CHECK_CONSTRAINT_DEF:
fTableConstraint = new TableCheckConstraintDef; fTableConstraint = new TableCheckConstraintDef;
fTableConstraint->unserialize(bytestream); fTableConstraint->unserialize(bytestream);
break; break;
case DDL_TABLE_REFERENCES_CONSTRAINT_DEF: case DDL_TABLE_REFERENCES_CONSTRAINT_DEF:
fTableConstraint = new TableReferencesConstraintDef; fTableConstraint = new TableReferencesConstraintDef;
fTableConstraint->unserialize(bytestream); fTableConstraint->unserialize(bytestream);
@ -1032,8 +1061,10 @@ int AtaRenameColumn::unserialize(ByteStream& bytestream)
// read column names // read column names
bytestream >> fName; bytestream >> fName;
bytestream >> fNewName; bytestream >> fNewName;
if (!fNewType) if (!fNewType)
fNewType = new ColumnType(DDL_INT); fNewType = new ColumnType(DDL_INT);
fNewType->unserialize(bytestream); fNewType->unserialize(bytestream);
read_vec<ColumnConstraintDef>(fConstraints, bytestream); read_vec<ColumnConstraintDef>(fConstraints, bytestream);
@ -1044,13 +1075,16 @@ int AtaRenameColumn::unserialize(ByteStream& bytestream)
quadbyte type; quadbyte type;
bytestream >> type; bytestream >> type;
if(type == DDL_NULL) { if (type == DDL_NULL)
{
fDefaultValue = 0; fDefaultValue = 0;
} }
else { else
{
fDefaultValue = new ColumnDefaultValue(); fDefaultValue = new ColumnDefaultValue();
fDefaultValue->unserialize(bytestream); fDefaultValue->unserialize(bytestream);
} }
return ret; return ret;
} }
@ -1062,20 +1096,25 @@ int AtaRenameColumn::serialize(ByteStream& bytestream)
bytestream << (quadbyte) DDL_ATA_RENAME_COLUMN; bytestream << (quadbyte) DDL_ATA_RENAME_COLUMN;
bytestream << fName; bytestream << fName;
bytestream << fNewName; bytestream << fNewName;
if (!fNewType) if (!fNewType)
fNewType = new ColumnType(DDL_INT); fNewType = new ColumnType(DDL_INT);
fNewType->serialize(bytestream); fNewType->serialize(bytestream);
// serialize column constraints. // serialize column constraints.
write_vec<ColumnConstraintDef>(fConstraints, bytestream); write_vec<ColumnConstraintDef>(fConstraints, bytestream);
if(0 == fDefaultValue) { if (0 == fDefaultValue)
{
bytestream << (quadbyte)DDL_NULL; bytestream << (quadbyte)DDL_NULL;
} }
else { else
{
bytestream << (quadbyte)DDL_COLUMN_DEFAULT_VALUE; bytestream << (quadbyte)DDL_COLUMN_DEFAULT_VALUE;
fDefaultValue->serialize( bytestream ); fDefaultValue->serialize( bytestream );
} }
return ret; return ret;
} }
@ -1259,10 +1298,12 @@ int ColumnDef::unserialize(ByteStream& bytestream)
quadbyte type; quadbyte type;
bytestream >> type; bytestream >> type;
if(type == DDL_NULL) { if (type == DDL_NULL)
{
fDefaultValue = 0; fDefaultValue = 0;
} }
else { else
{
fDefaultValue = new ColumnDefaultValue(); fDefaultValue = new ColumnDefaultValue();
fDefaultValue->unserialize(bytestream); fDefaultValue->unserialize(bytestream);
} }
@ -1284,10 +1325,12 @@ int ColumnDef::serialize(ByteStream& bytestream)
// serialize column constraints. // serialize column constraints.
write_vec<ColumnConstraintDef>(fConstraints, bytestream); write_vec<ColumnConstraintDef>(fConstraints, bytestream);
if(0 == fDefaultValue) { if (0 == fDefaultValue)
{
bytestream << (quadbyte)DDL_NULL; bytestream << (quadbyte)DDL_NULL;
} }
else { else
{
bytestream << (quadbyte)DDL_COLUMN_DEFAULT_VALUE; bytestream << (quadbyte)DDL_COLUMN_DEFAULT_VALUE;
fDefaultValue->serialize( bytestream ); fDefaultValue->serialize( bytestream );
} }
@ -1371,6 +1414,7 @@ int TableUniqueConstraintDef::serialize(ByteStream& bytestream)
bytestream << (quadbyte) fColumnNameList.size(); bytestream << (quadbyte) fColumnNameList.size();
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
for (itr = fColumnNameList.begin(); itr != fColumnNameList.end(); ++itr) for (itr = fColumnNameList.begin(); itr != fColumnNameList.end(); ++itr)
{ {
bytestream << *itr; bytestream << *itr;
@ -1415,6 +1459,7 @@ int TablePrimaryKeyConstraintDef::serialize(ByteStream& bytestream)
bytestream << (quadbyte) fColumnNameList.size(); bytestream << (quadbyte) fColumnNameList.size();
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
for (itr = fColumnNameList.begin(); itr != fColumnNameList.end(); ++itr) for (itr = fColumnNameList.begin(); itr != fColumnNameList.end(); ++itr)
{ {
bytestream << *itr; bytestream << *itr;
@ -1482,7 +1527,9 @@ int TableReferencesConstraintDef::unserialize(ByteStream& bytestream)
// Local columns // Local columns
bytestream >> count; bytestream >> count;
while(count-- > 0) {
while (count-- > 0)
{
bytestream >> str; bytestream >> str;
fColumns.push_back(str); fColumns.push_back(str);
} }
@ -1493,7 +1540,9 @@ int TableReferencesConstraintDef::unserialize(ByteStream& bytestream)
// Foreign columns // Foreign columns
bytestream >> count; bytestream >> count;
while(count-- > 0) {
while (count-- > 0)
{
bytestream >> str; bytestream >> str;
fForeignColumns.push_back(str); fForeignColumns.push_back(str);
} }
@ -1506,10 +1555,13 @@ int TableReferencesConstraintDef::unserialize(ByteStream& bytestream)
// Ref Action // Ref Action
quadbyte sertype; quadbyte sertype;
bytestream >> sertype; bytestream >> sertype;
if(sertype == DDL_NULL) {
if (sertype == DDL_NULL)
{
fRefAction = 0; fRefAction = 0;
} }
else { else
{
fRefAction = new ReferentialAction(); fRefAction = new ReferentialAction();
fRefAction->unserialize(bytestream); fRefAction->unserialize(bytestream);
} }
@ -1528,6 +1580,7 @@ int TableReferencesConstraintDef::serialize(ByteStream& bytestream)
size = fColumns.size(); size = fColumns.size();
bytestream << size; bytestream << size;
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
for (itr = fColumns.begin(); itr != fColumns.end(); ++itr) for (itr = fColumns.begin(); itr != fColumns.end(); ++itr)
bytestream << *itr; bytestream << *itr;
@ -1537,6 +1590,7 @@ int TableReferencesConstraintDef::serialize(ByteStream& bytestream)
// Foreign columns // Foreign columns
size = fForeignColumns.size(); size = fForeignColumns.size();
bytestream << size; bytestream << size;
for (itr = fForeignColumns.begin(); itr != fForeignColumns.end(); ++itr) for (itr = fForeignColumns.begin(); itr != fForeignColumns.end(); ++itr)
bytestream << *itr; bytestream << *itr;
@ -1544,10 +1598,12 @@ int TableReferencesConstraintDef::serialize(ByteStream& bytestream)
bytestream << (quadbyte) fMatchType; bytestream << (quadbyte) fMatchType;
// Ref action // Ref action
if(0 == fRefAction) { if (0 == fRefAction)
{
bytestream << (quadbyte) DDL_NULL; bytestream << (quadbyte) DDL_NULL;
} }
else { else
{
bytestream << (quadbyte) DDL_REF_ACTION; bytestream << (quadbyte) DDL_REF_ACTION;
fRefAction->serialize(bytestream); fRefAction->serialize(bytestream);
} }
@ -1618,21 +1674,25 @@ int TableDef::unserialize(ByteStream& bytestream)
constraint->unserialize(bytestream); constraint->unserialize(bytestream);
fConstraints.push_back( constraint ); fConstraints.push_back( constraint );
break; break;
case DDL_TABLE_PRIMARY_CONSTRAINT_DEF: case DDL_TABLE_PRIMARY_CONSTRAINT_DEF:
constraint = new TablePrimaryKeyConstraintDef(); constraint = new TablePrimaryKeyConstraintDef();
constraint->unserialize(bytestream); constraint->unserialize(bytestream);
fConstraints.push_back( constraint ); fConstraints.push_back( constraint );
break; break;
case DDL_TABLE_REFERENCES_CONSTRAINT_DEF: case DDL_TABLE_REFERENCES_CONSTRAINT_DEF:
constraint = new TableReferencesConstraintDef(); constraint = new TableReferencesConstraintDef();
constraint->unserialize(bytestream); constraint->unserialize(bytestream);
fConstraints.push_back( constraint ); fConstraints.push_back( constraint );
break; break;
case DDL_TABLE_CHECK_CONSTRAINT_DEF: case DDL_TABLE_CHECK_CONSTRAINT_DEF:
constraint = new TableCheckConstraintDef(); constraint = new TableCheckConstraintDef();
constraint->unserialize(bytestream); constraint->unserialize(bytestream);
fConstraints.push_back( constraint ); fConstraints.push_back( constraint );
break; break;
default: default:
throw ("Bad typecode for TableConstraintDef"); throw ("Bad typecode for TableConstraintDef");
break; break;
@ -1641,6 +1701,7 @@ int TableDef::unserialize(ByteStream& bytestream)
// read option maps list // read option maps list
bytestream >> count; bytestream >> count;
for ( unsigned int i = 0; i < count; i++ ) for ( unsigned int i = 0; i < count; i++ )
{ {
// read option map // read option map
@ -1669,6 +1730,7 @@ int TableDef::serialize(ByteStream& bytestream)
bytestream << size; bytestream << size;
TableConstraintDefList::const_iterator itr; TableConstraintDefList::const_iterator itr;
for (itr = fConstraints.begin(); for (itr = fConstraints.begin();
itr != fConstraints.end(); itr != fConstraints.end();
++itr) ++itr)
@ -1683,6 +1745,7 @@ int TableDef::serialize(ByteStream& bytestream)
pair<string, string> oval; pair<string, string> oval;
TableOptionMap::const_iterator itr2; TableOptionMap::const_iterator itr2;
for (itr2 = fOptions.begin(); for (itr2 = fOptions.begin();
itr2 != fOptions.end(); itr2 != fOptions.end();
++itr2) ++itr2)

View File

@ -41,7 +41,8 @@ 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() :
@ -73,9 +74,11 @@ namespace ddlpackage {
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;
} }
@ -105,7 +108,9 @@ namespace ddlpackage {
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;
} }
@ -116,7 +121,8 @@ namespace ddlpackage {
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.");
} }

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,7 +25,8 @@
#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;

View File

@ -25,7 +25,8 @@
#include "ddlpkg.h" #include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT #undef DDLPKG_DLLEXPORT
namespace ddlpackage { namespace ddlpackage
{
using namespace std; using namespace std;
@ -33,10 +34,12 @@ namespace ddlpackage {
{ {
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;
} }
@ -50,7 +53,9 @@ namespace ddlpackage {
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

@ -35,13 +35,17 @@ namespace ddlpackage
{ {
{ {
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;
} }
} }
@ -53,7 +57,8 @@ namespace ddlpackage
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;
} }
@ -66,14 +71,21 @@ namespace ddlpackage
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); constraint = dynamic_cast<TableConstraintDef*>(*itr);
if(constraint) {
if (constraint)
{
fConstraints.push_back(constraint); fConstraints.push_back(constraint);
} }
} }
@ -87,6 +99,7 @@ namespace ddlpackage
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
@ -96,6 +109,7 @@ 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)
{ {
@ -107,6 +121,7 @@ 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,10 +133,14 @@ 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(); for (oitr = tableDef.fOptions.begin();
oitr != tableDef.fOptions.end(); ++oitr) { oitr != tableDef.fOptions.end(); ++oitr)
{
oval = *oitr; oval = *oitr;
os << " " << oval.first << "=" << oval.second << endl; os << " " << oval.first << "=" << oval.second << endl;
} }
@ -186,12 +205,14 @@ namespace ddlpackage
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;
} }
@ -210,12 +231,14 @@ namespace ddlpackage
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;
@ -245,12 +268,14 @@ namespace ddlpackage
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,12 +283,14 @@ 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;
@ -272,12 +299,14 @@ namespace ddlpackage
{ {
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;
} }

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);
@ -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,6 +377,7 @@ 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();
@ -389,6 +392,7 @@ 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();
@ -403,6 +407,7 @@ 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();
@ -416,6 +421,7 @@ 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();
@ -429,6 +435,7 @@ 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();
@ -442,6 +449,7 @@ 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();
@ -456,6 +464,7 @@ 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();
@ -469,6 +478,7 @@ 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();
@ -498,10 +508,12 @@ 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();
@ -511,6 +523,7 @@ 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,10 +557,12 @@ 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();
@ -647,11 +662,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)
{ {
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();
@ -664,6 +681,7 @@ 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,11 +782,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)
{ {
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();
@ -801,12 +821,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 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();
@ -828,11 +850,13 @@ 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();
@ -853,11 +877,13 @@ 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();
@ -877,11 +903,13 @@ 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();

File diff suppressed because it is too large Load Diff

View File

@ -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;
@ -182,11 +190,13 @@ try
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 );
@ -300,6 +311,7 @@ try
// 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;
@ -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);
@ -456,7 +472,9 @@ 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

@ -60,6 +60,7 @@ CreateTableProcessor::DDLResult CreateTableProcessor::processPackage(
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,6 +98,7 @@ 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
@ -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,6 +200,7 @@ CreateTableProcessor::DDLResult CreateTableProcessor::processPackage(
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; return result;
} }
#ifdef _MSC_VER #ifdef _MSC_VER
keepGoing: keepGoing:
#endif #endif
@ -202,8 +217,10 @@ keepGoing:
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,6 +302,7 @@ 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;
@ -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;
} }
} }
@ -359,10 +389,12 @@ cout << fTxnid.id << " Create table We_SVR_WRITE_CREATETABLEFILES: " << errorMsg
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,11 +407,16 @@ 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) {
for (unsigned i = 0; i < numColumns; ++i)
{
bytestream << (uint32_t)(fStartingColOID + i + 1); bytestream << (uint32_t)(fStartingColOID + i + 1);
} }
bytestream << numDictCols; bytestream << numDictCols;
for (unsigned i = 0; i <numDictCols; ++i) {
for (unsigned i = 0; i < numDictCols; ++i)
{
bytestream << (uint32_t)(fStartingColOID + numColumns + i + 1); bytestream << (uint32_t)(fStartingColOID + numColumns + i + 1);
} }
@ -391,6 +428,7 @@ 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;
@ -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;
} }
} }
@ -465,10 +510,12 @@ cout << fTxnid.id << " Create table WE_SVR_WRITE_CREATE_SYSCOLUMN: " << errorMsg
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,6 +583,7 @@ 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) ||
@ -546,21 +597,27 @@ cout << fTxnid.id << " Create table WE_SVR_WRITE_CREATE_SYSCOLUMN: " << errorMsg
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; bytestream << numDictCols;
for (unsigned i = 0; i < numDictCols; ++i) for (unsigned i = 0; i < numDictCols; ++i)
{ {
oidList.push_back(fStartingColOID + numColumns + i + 1); oidList.push_back(fStartingColOID + numColumns + i + 1);
} }
try { try
{
createWriteDropLogFile( fStartingColOID, uniqueId, oidList ); createWriteDropLogFile( fStartingColOID, uniqueId, oidList );
} }
catch (std::exception& ex) catch (std::exception& ex)
@ -572,68 +629,84 @@ cout << fTxnid.id << " Create table WE_SVR_WRITE_CREATE_SYSCOLUMN: " << errorMsg
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);
@ -676,6 +749,7 @@ 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)
{ {
@ -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

@ -56,6 +56,7 @@ namespace ddlpackageprocessor
{ {
if (makeIndexStructs() ) if (makeIndexStructs() )
insertIndex(); insertIndex();
result = fResult; result = fResult;
return NO_ERROR != fResult.result; return NO_ERROR != fResult.result;
} }
@ -66,6 +67,7 @@ namespace ddlpackageprocessor
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,6 +126,7 @@ namespace ddlpackageprocessor
addColumnData(*it, coltype, i); addColumnData(*it, coltype, i);
} }
} }
i++; i++;
} }
@ -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,6 +165,7 @@ 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);
} }
@ -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
@ -202,12 +213,14 @@ 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);
} }
@ -241,6 +254,7 @@ namespace ddlpackageprocessor
{ {
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);
@ -285,11 +299,13 @@ 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;
} }
@ -298,16 +314,25 @@ namespace ddlpackageprocessor
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,16 +342,23 @@ 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");
@ -341,6 +373,7 @@ namespace ddlpackageprocessor
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 );
@ -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:
@ -386,6 +420,7 @@ namespace ddlpackageprocessor
{ {
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,14 +454,17 @@ 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;
} }
@ -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,13 +550,17 @@ 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;
} }
@ -523,6 +572,7 @@ namespace ddlpackageprocessor
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: ");

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
@ -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

@ -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;
@ -371,6 +382,7 @@ 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:
@ -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;
@ -587,6 +603,7 @@ bool DDLPackageProcessor::isIndexConstraint(ddlpackage::DDL_CONSTRAINTS type)
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:
@ -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;
@ -702,6 +722,7 @@ boost::any DDLPackageProcessor::tokenizeData(execplan::CalpontSystemCatalog::SCN
} }
} }
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,6 +802,7 @@ 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,10 +903,13 @@ 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 {
try
{
OamCache* oamcache = OamCache::makeOamCache(); 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;
@ -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;
} }
} }
@ -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,7 +1178,9 @@ 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);
@ -1116,9 +1192,11 @@ void DDLPackageProcessor::fetchLogFile(TableLogInfo & tableLogInfos, uint64_t un
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);
@ -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);
} }
@ -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;
} }
} }
@ -1322,12 +1433,15 @@ void DDLPackageProcessor::createOpenTruncateTableLogFile(execplan::CalpontSystem
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
@ -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();
@ -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,19 +1659,23 @@ 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,7 +168,13 @@ 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
@ -189,8 +197,16 @@ 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
@ -217,17 +233,32 @@ public:
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

View File

@ -28,7 +28,8 @@
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)

View File

@ -28,12 +28,14 @@
#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:

View File

@ -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");
@ -77,6 +79,7 @@ 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

@ -56,6 +56,7 @@ namespace ddlpackageprocessor
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)
@ -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&)
@ -164,12 +170,14 @@ 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;
@ -177,6 +185,7 @@ namespace ddlpackageprocessor
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 );
@ -230,6 +239,7 @@ namespace ddlpackageprocessor
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 )
@ -239,6 +249,7 @@ 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,30 +340,39 @@ 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(dropPartitionStmt.fSessionID, txnID.id, dropPartitionStmt.fSql, dropPartitionStmt.fOwner); logging::logDDL(dropPartitionStmt.fSessionID, txnID.id, dropPartitionStmt.fSql, dropPartitionStmt.fOwner);
//Remove the log file //Remove the log file
//release the transaction //release the transaction
try { try
{
fDbrm->releaseTableLock(uniqueID); fDbrm->releaseTableLock(uniqueID);
deleteLogFile(DROPPART_LOG, roPair.objnum, uniqueId); deleteLogFile(DROPPART_LOG, roPair.objnum, 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

@ -69,6 +69,7 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
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;
@ -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)
@ -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&)
@ -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;
@ -270,6 +280,7 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackage(ddlpackage::Dro
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 )
@ -294,6 +305,7 @@ 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;
@ -309,6 +321,7 @@ 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
@ -316,21 +329,27 @@ cout << fTxnid.id << " Drop table sending WE_SVR_DELETE_SYSTABLES to pm " << pmN
//#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;
} }
} }
@ -380,6 +399,7 @@ 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;
@ -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;
} }
} }
@ -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,6 +680,7 @@ 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
@ -695,6 +743,7 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
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;
@ -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,6 +801,7 @@ 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;
@ -758,6 +810,7 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
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&)
@ -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,6 +883,7 @@ 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;
@ -832,6 +893,7 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackage(ddlpackage::T
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,6 +901,7 @@ 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;
@ -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
@ -1208,9 +1314,12 @@ cout << "Truncate table sending We_SVR_WRITE_CREATETABLEFILES to pm " << pmNum <
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

@ -50,6 +50,7 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
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,6 +62,7 @@ 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;
@ -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&)
@ -128,12 +134,14 @@ 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;
@ -142,7 +150,8 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
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&)
@ -191,6 +200,7 @@ MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpack
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 )
@ -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

@ -73,6 +73,7 @@ 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();
@ -108,6 +109,7 @@ 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();
@ -138,6 +140,7 @@ 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();
@ -165,10 +168,12 @@ 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;
@ -194,10 +199,12 @@ 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;
@ -225,10 +232,12 @@ 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;
@ -340,6 +349,7 @@ int main( int argc, char **argv)
} }
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

@ -50,6 +50,7 @@ namespace ddlpackageprocessor
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,6 +62,7 @@ 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;
@ -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&)
@ -128,12 +134,14 @@ 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;
@ -142,7 +150,8 @@ namespace ddlpackageprocessor
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&)
@ -193,6 +202,7 @@ namespace ddlpackageprocessor
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 )
@ -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,27 +260,36 @@ 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

@ -411,9 +411,11 @@ public:
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");
} }
@ -428,9 +430,11 @@ public:
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");
@ -496,9 +500,11 @@ 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;
@ -516,6 +522,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@ -528,9 +535,11 @@ 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;
@ -554,6 +563,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@ -563,6 +573,7 @@ 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();
@ -584,6 +595,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@ -593,6 +605,7 @@ 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();
@ -614,6 +627,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
void test_altertable_addacolumn() void test_altertable_addacolumn()
@ -623,9 +637,11 @@ 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;
@ -643,6 +659,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@ -653,9 +670,11 @@ 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;
@ -673,6 +692,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@ -683,9 +703,11 @@ 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;
@ -703,6 +725,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
void test_altertable_dropacolumn() void test_altertable_dropacolumn()
@ -712,9 +735,11 @@ 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;
@ -732,6 +757,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@ -742,9 +768,11 @@ 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;
@ -762,6 +790,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@ -772,9 +801,11 @@ 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;
@ -792,6 +823,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
void test_dropindex() void test_dropindex()
@ -801,6 +833,7 @@ 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();
@ -822,6 +855,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
void test_altertable_renamecolumn() void test_altertable_renamecolumn()
@ -831,9 +865,11 @@ 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;
@ -851,6 +887,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@ -862,9 +899,11 @@ 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;
@ -882,6 +921,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
void test_altertable_addtableconstraint() void test_altertable_addtableconstraint()
@ -891,9 +931,11 @@ 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;
@ -911,6 +953,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@ -921,9 +964,11 @@ 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;
@ -941,6 +986,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@ -951,9 +997,11 @@ 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;
@ -971,6 +1019,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
void test_altertable_dropcolumndefault() void test_altertable_dropcolumndefault()
@ -980,9 +1029,11 @@ 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;
@ -1000,6 +1051,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@ -1010,9 +1062,11 @@ 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;
@ -1030,6 +1084,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }
@ -1040,6 +1095,7 @@ 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();
@ -1061,6 +1117,7 @@ public:
throw; throw;
} }
} }
tearDown(); tearDown();
} }

View File

@ -50,16 +50,19 @@ 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())
@ -122,9 +125,11 @@ 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:
@ -132,22 +137,26 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromBuffe
(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

@ -59,15 +59,18 @@ namespace dmlpackage
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; return value;
} }

View File

@ -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,23 +286,59 @@ 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:

View File

@ -67,10 +67,12 @@ 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,6 +105,7 @@ 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,6 +158,7 @@ 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

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,8 @@
# 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,

View File

@ -305,7 +305,8 @@ static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
#define YY_NUM_RULES 103 #define YY_NUM_RULES 103
#define YY_END_OF_BUFFER 104 #define YY_END_OF_BUFFER 104
static yyconst short int yy_accept[394] = static yyconst short int yy_accept[394] =
{ 0, {
0,
0, 0, 0, 0, 0, 0, 104, 103, 101, 100, 0, 0, 0, 0, 0, 0, 104, 103, 101, 100,
97, 90, 90, 90, 90, 93, 103, 86, 84, 87, 97, 90, 90, 90, 90, 93, 103, 86, 84, 87,
91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
@ -353,7 +354,8 @@ static yyconst short int yy_accept[394] =
} ; } ;
static yyconst int yy_ec[256] = static yyconst int yy_ec[256] =
{ 0, {
0,
1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -385,7 +387,8 @@ static yyconst int yy_ec[256] =
} ; } ;
static yyconst int yy_meta[42] = static yyconst int yy_meta[42] =
{ 0, {
0,
1, 1, 2, 1, 1, 1, 1, 1, 1, 3, 1, 1, 2, 1, 1, 1, 1, 1, 1, 3,
1, 1, 1, 1, 3, 4, 4, 4, 4, 4, 1, 1, 1, 1, 3, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
@ -394,7 +397,8 @@ static yyconst int yy_meta[42] =
} ; } ;
static yyconst short int yy_base[401] = static yyconst short int yy_base[401] =
{ 0, {
0,
0, 0, 425, 424, 423, 422, 426, 431, 40, 431, 0, 0, 425, 424, 423, 422, 426, 431, 40, 431,
431, 431, 36, 39, 415, 41, 0, 39, 431, 411, 431, 431, 36, 39, 415, 41, 0, 39, 431, 411,
28, 23, 43, 47, 20, 48, 39, 407, 51, 0, 28, 23, 43, 47, 20, 48, 39, 407, 51, 0,
@ -442,7 +446,8 @@ static yyconst short int yy_base[401] =
} ; } ;
static yyconst short int yy_def[401] = static yyconst short int yy_def[401] =
{ 0, {
0,
393, 1, 394, 394, 395, 395, 393, 393, 393, 393, 393, 1, 394, 394, 395, 395, 393, 393, 393, 393,
393, 393, 393, 393, 393, 393, 396, 393, 393, 393, 393, 393, 393, 393, 393, 393, 396, 393, 393, 393,
397, 397, 397, 397, 397, 397, 397, 397, 397, 397, 397, 397, 397, 397, 397, 397, 397, 397, 397, 397,
@ -490,7 +495,8 @@ static yyconst short int yy_def[401] =
} ; } ;
static yyconst short int yy_nxt[473] = static yyconst short int yy_nxt[473] =
{ 0, {
0,
8, 9, 10, 9, 11, 12, 13, 14, 15, 16, 8, 9, 10, 9, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 8, 21, 22, 23, 24, 25, 17, 18, 19, 20, 8, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
@ -546,7 +552,8 @@ static yyconst short int yy_nxt[473] =
} ; } ;
static yyconst short int yy_chk[473] = static yyconst short int yy_chk[473] =
{ 0, {
0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -644,7 +651,8 @@ using namespace dmlpackage;
void dmlerror(char const* s); void dmlerror(char const* s);
namespace dmlpackage { namespace dmlpackage
{
int lineno = 1; int lineno = 1;
@ -855,20 +863,25 @@ YY_DECL
yy_current_state = yy_start; yy_current_state = yy_start;
yy_match: yy_match:
do do
{ {
register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
if ( yy_accept[yy_current_state] ) if ( yy_accept[yy_current_state] )
{ {
yy_last_accepting_state = yy_current_state; yy_last_accepting_state = yy_current_state;
yy_last_accepting_cpos = yy_cp; yy_last_accepting_cpos = yy_cp;
} }
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 394 ) if ( yy_current_state >= 394 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp; ++yy_cp;
} }
@ -876,8 +889,10 @@ yy_match:
yy_find_action: yy_find_action:
yy_act = yy_accept[yy_current_state]; yy_act = yy_accept[yy_current_state];
if ( yy_act == 0 ) if ( yy_act == 0 )
{ /* have to back up */ {
/* have to back up */
yy_cp = yy_last_accepting_cpos; yy_cp = yy_last_accepting_cpos;
yy_current_state = yy_last_accepting_state; yy_current_state = yy_last_accepting_state;
yy_act = yy_accept[yy_current_state]; yy_act = yy_accept[yy_current_state];
@ -890,7 +905,8 @@ do_action: /* This label is used only to access EOF actions. */
switch ( yy_act ) switch ( yy_act )
{ /* beginning of action switch */ {
/* beginning of action switch */
case 0: /* must back up */ case 0: /* must back up */
/* undo the effects of YY_DO_BEFORE_ACTION */ /* undo the effects of YY_DO_BEFORE_ACTION */
*yy_cp = yy_hold_char; *yy_cp = yy_hold_char;
@ -1230,6 +1246,7 @@ case 83:
YY_RULE_SETUP YY_RULE_SETUP
TOK(WORK) TOK(WORK)
YY_BREAK YY_BREAK
/* punctuation */ /* punctuation */
case 84: case 84:
case 85: case 85:
@ -1244,11 +1261,13 @@ case 90:
YY_RULE_SETUP YY_RULE_SETUP
{ TOK(yytext[0]) } { TOK(yytext[0]) }
YY_BREAK YY_BREAK
/* names */ /* names */
case 91: case 91:
YY_RULE_SETUP YY_RULE_SETUP
{ TOK(NAME) } { TOK(NAME) }
YY_BREAK YY_BREAK
/* parameters */ /* parameters */
case 92: case 92:
YY_RULE_SETUP YY_RULE_SETUP
@ -1256,6 +1275,7 @@ YY_RULE_SETUP
return PARAMETER; return PARAMETER;
} }
YY_BREAK YY_BREAK
/* numbers */ /* numbers */
case 93: case 93:
case 94: case 94:
@ -1263,14 +1283,17 @@ case 95:
YY_RULE_SETUP YY_RULE_SETUP
{ TOK(INTNUM) } { TOK(INTNUM) }
YY_BREAK YY_BREAK
case 96: case 96:
YY_RULE_SETUP YY_RULE_SETUP
{ TOK(APPROXNUM) } { TOK(APPROXNUM) }
YY_BREAK YY_BREAK
case 97: case 97:
YY_RULE_SETUP YY_RULE_SETUP
{BEGIN(inquote);} {BEGIN(inquote);}
YY_BREAK YY_BREAK
case 98: case 98:
*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ *yy_cp = yy_hold_char; /* undo effects of setting up yytext */
yy_c_buf_p = yy_cp -= 1; yy_c_buf_p = yy_cp -= 1;
@ -1278,28 +1301,34 @@ YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP YY_RULE_SETUP
{BEGIN(endquote); TOK(STRING) } {BEGIN(endquote); TOK(STRING) }
YY_BREAK YY_BREAK
case 99: case 99:
YY_RULE_SETUP YY_RULE_SETUP
{BEGIN(0);} {BEGIN(0);}
YY_BREAK YY_BREAK
/* @bug 1870. Since MySQL parser will error out all the unterminated string, we don't actually need it here. */ /* @bug 1870. Since MySQL parser will error out all the unterminated string, we don't actually need it here. */
/* '[^'\n]*$ { dmlerror("Unterminated string"); } */ /* '[^'\n]*$ { dmlerror("Unterminated string"); } */
case 100: case 100:
YY_RULE_SETUP YY_RULE_SETUP
{ lineno++;} { lineno++;}
YY_BREAK YY_BREAK
case 101: case 101:
YY_RULE_SETUP YY_RULE_SETUP
; /* white space */ ; /* white space */
YY_BREAK YY_BREAK
case 102: case 102:
YY_RULE_SETUP YY_RULE_SETUP
; /* comment */ ; /* comment */
YY_BREAK YY_BREAK
case 103: case 103:
YY_RULE_SETUP YY_RULE_SETUP
ECHO; ECHO;
YY_BREAK YY_BREAK
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(inquote): case YY_STATE_EOF(inquote):
case YY_STATE_EOF(endquote): case YY_STATE_EOF(endquote):
@ -1338,7 +1367,8 @@ case YY_STATE_EOF(endquote):
* in input(). * in input().
*/ */
if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
{ /* This was really a NUL. */ {
/* This was really a NUL. */
yy_state_type yy_next_state; yy_state_type yy_next_state;
yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
@ -1401,6 +1431,7 @@ case YY_STATE_EOF(endquote):
if ( ! yy_did_buffer_switch_on_eof ) if ( ! yy_did_buffer_switch_on_eof )
YY_NEW_FILE; YY_NEW_FILE;
} }
break; break;
} }
@ -1424,6 +1455,7 @@ case YY_STATE_EOF(endquote):
yy_bp = yytext_ptr + YY_MORE_ADJ; yy_bp = yytext_ptr + YY_MORE_ADJ;
goto yy_find_action; goto yy_find_action;
} }
break; break;
} }
@ -1455,7 +1487,8 @@ static int yy_get_next_buffer()
"fatal flex scanner internal error--end of buffer missed" ); "fatal flex scanner internal error--end of buffer missed" );
if ( yy_current_buffer->yy_fill_buffer == 0 ) if ( yy_current_buffer->yy_fill_buffer == 0 )
{ /* Don't try to fill the buffer, so this is an EOF. */ {
/* Don't try to fill the buffer, so this is an EOF. */
if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
{ {
/* We matched a single character, the EOB, so /* We matched a single character, the EOB, so
@ -1493,7 +1526,8 @@ static int yy_get_next_buffer()
yy_current_buffer->yy_buf_size - number_to_move - 1; yy_current_buffer->yy_buf_size - number_to_move - 1;
while ( num_to_read <= 0 ) while ( num_to_read <= 0 )
{ /* Not enough room in the buffer - grow it. */ {
/* Not enough room in the buffer - grow it. */
#ifdef YY_USES_REJECT #ifdef YY_USES_REJECT
YY_FATAL_ERROR( YY_FATAL_ERROR(
"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); "input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
@ -1585,17 +1619,21 @@ static yy_state_type yy_get_previous_state()
for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
{ {
register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
if ( yy_accept[yy_current_state] ) if ( yy_accept[yy_current_state] )
{ {
yy_last_accepting_state = yy_current_state; yy_last_accepting_state = yy_current_state;
yy_last_accepting_cpos = yy_cp; yy_last_accepting_cpos = yy_cp;
} }
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 394 ) if ( yy_current_state >= 394 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
} }
@ -1620,17 +1658,21 @@ yy_state_type yy_current_state;
register char* yy_cp = yy_c_buf_p; register char* yy_cp = yy_c_buf_p;
register YY_CHAR yy_c = 1; register YY_CHAR yy_c = 1;
if ( yy_accept[yy_current_state] ) if ( yy_accept[yy_current_state] )
{ {
yy_last_accepting_state = yy_current_state; yy_last_accepting_state = yy_current_state;
yy_last_accepting_cpos = yy_cp; yy_last_accepting_cpos = yy_cp;
} }
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 394 ) if ( yy_current_state >= 394 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 393); yy_is_jam = (yy_current_state == 393);
@ -1653,7 +1695,8 @@ register char *yy_bp;
*yy_cp = yy_hold_char; *yy_cp = yy_hold_char;
if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
{ /* need to shift things up to make room */ {
/* need to shift things up to make room */
/* +2 for EOB chars. */ /* +2 for EOB chars. */
register int number_to_move = yy_n_chars + 2; register int number_to_move = yy_n_chars + 2;
register char* dest = &yy_current_buffer->yy_ch_buf[ register char* dest = &yy_current_buffer->yy_ch_buf[
@ -1704,7 +1747,8 @@ static int input()
*yy_c_buf_p = '\0'; *yy_c_buf_p = '\0';
else else
{ /* need more input */ {
/* need more input */
int offset = yy_c_buf_p - yytext_ptr; int offset = yy_c_buf_p - yytext_ptr;
++yy_c_buf_p; ++yy_c_buf_p;
@ -1733,6 +1777,7 @@ static int input()
if ( ! yy_did_buffer_switch_on_eof ) if ( ! yy_did_buffer_switch_on_eof )
YY_NEW_FILE; YY_NEW_FILE;
#ifdef __cplusplus #ifdef __cplusplus
return yyinput(); return yyinput();
#else #else
@ -1825,6 +1870,7 @@ int size;
YY_BUFFER_STATE b; YY_BUFFER_STATE b;
b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
if ( ! b ) if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
@ -1834,6 +1880,7 @@ int size;
* we need to put in 2 end-of-buffer characters. * we need to put in 2 end-of-buffer characters.
*/ */
b->yy_ch_buf = (char*) yy_flex_alloc( b->yy_buf_size + 2 ); b->yy_ch_buf = (char*) yy_flex_alloc( b->yy_buf_size + 2 );
if ( ! b->yy_ch_buf ) if ( ! b->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
@ -1946,6 +1993,7 @@ yy_size_t size;
return 0; return 0;
b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
if ( ! b ) if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
@ -1975,6 +2023,7 @@ yyconst char *yy_str;
#endif #endif
{ {
int len; int len;
for ( len = 0; yy_str[len]; ++len ) for ( len = 0; yy_str[len]; ++len )
; ;
@ -2000,6 +2049,7 @@ int len;
/* Get memory for full buffer, including space for trailing EOB's. */ /* Get memory for full buffer, including space for trailing EOB's. */
n = len + 2; n = len + 2;
buf = (char*) yy_flex_alloc( n ); buf = (char*) yy_flex_alloc( n );
if ( ! buf ) if ( ! buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
@ -2009,6 +2059,7 @@ int len;
buf[len] = buf[len + 1] = YY_END_OF_BUFFER_CHAR; buf[len] = buf[len + 1] = YY_END_OF_BUFFER_CHAR;
b = yy_scan_buffer( buf, n ); b = yy_scan_buffer( buf, n );
if ( ! b ) if ( ! b )
YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
@ -2120,6 +2171,7 @@ int n;
#endif #endif
{ {
register int i; register int i;
for ( i = 0; i < n; ++i ) for ( i = 0; i < n; ++i )
s1[i] = s2[i]; s1[i] = s2[i];
} }
@ -2134,6 +2186,7 @@ yyconst char *s;
#endif #endif
{ {
register int n; register int n;
for ( n = 0; s[n]; ++n ) for ( n = 0; s[n]; ++n )
; ;
@ -2195,7 +2248,8 @@ void dmlerror(char const *s)
printf("yyerror: %d: %s at %s\n", lineno, s, yytext); printf("yyerror: %d: %s at %s\n", lineno, s, yytext);
} }
namespace dmlpackage { namespace dmlpackage
{
static valbuf_t valbuf; static valbuf_t valbuf;
@ -2244,21 +2298,28 @@ void scanner_finish(void)
yy_delete_buffer(scanbufhandle); yy_delete_buffer(scanbufhandle);
free(scanbuf); free(scanbuf);
unsigned int i; unsigned int i;
for(i=0; i<valbuf.size(); i++) {
for (i = 0; i < valbuf.size(); i++)
{
str = valbuf[i]; str = valbuf[i];
if(str) {
if (str)
{
//std::cout << "valbuf:(" << str << ")" << std::endl; //std::cout << "valbuf:(" << str << ")" << std::endl;
free(valbuf[i]); free(valbuf[i]);
} }
} }
valbuf.clear(); valbuf.clear();
} }
char* scanner_copy (char* str) char* scanner_copy (char* str)
{ {
char* nv = strdup(str); char* nv = strdup(str);
if (nv) if (nv)
valbuf.push_back(nv); valbuf.push_back(nv);
return nv; return nv;
} }

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++ )
@ -87,6 +90,7 @@ int DMLColumn::read(messageqcpp::ByteStream& bytestream)
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,6 +115,7 @@ 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;

View File

@ -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

@ -75,6 +75,7 @@ namespace dmlpackage
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;
@ -83,14 +84,17 @@ namespace dmlpackage
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;
} }
@ -101,6 +105,7 @@ namespace dmlpackage
{ {
throw logic_error("The ParseTree is invalid"); throw logic_error("The ParseTree is invalid");
} }
return fParseTree; return fParseTree;
} }
@ -125,16 +130,19 @@ namespace dmlpackage
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;

View File

@ -37,6 +37,7 @@ namespace dmlpackage
SqlStatement& stmt = **itr; SqlStatement& stmt = **itr;
os << stmt; os << stmt;
} }
return os; return os;
} }
@ -48,6 +49,7 @@ namespace dmlpackage
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;
@ -132,6 +134,7 @@ namespace dmlpackage
} }
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
for (itr = fColumnList.begin(); itr != fColumnList.end(); ++itr) for (itr = fColumnList.begin(); itr != fColumnList.end(); ++itr)
{ {
os << *itr << endl; os << *itr << endl;
@ -142,6 +145,7 @@ namespace dmlpackage
fValuesOrQueryPtr->put(os); fValuesOrQueryPtr->put(os);
} }
return os; return os;
} }
@ -178,14 +182,17 @@ namespace dmlpackage
if (0 != fColAssignmentListPtr) if (0 != fColAssignmentListPtr)
{ {
ColumnAssignmentList::iterator iter = fColAssignmentListPtr->begin(); ColumnAssignmentList::iterator iter = fColAssignmentListPtr->begin();
while (iter != fColAssignmentListPtr->end()) while (iter != fColAssignmentListPtr->end())
{ {
delete *iter; delete *iter;
++iter; ++iter;
} }
fColAssignmentListPtr->clear(); fColAssignmentListPtr->clear();
delete fColAssignmentListPtr; delete fColAssignmentListPtr;
} }
if (0 != fWhereClausePtr) if (0 != fWhereClausePtr)
{ {
delete fWhereClausePtr; delete fWhereClausePtr;
@ -195,14 +202,17 @@ namespace dmlpackage
ostream& UpdateSqlStatement::put(ostream& os) const ostream& UpdateSqlStatement::put(ostream& os) const
{ {
os << "Update " << endl; os << "Update " << endl;
if (0 != fNamePtr) if (0 != fNamePtr)
{ {
fNamePtr->put(os); fNamePtr->put(os);
} }
if (0 != fColAssignmentListPtr) if (0 != fColAssignmentListPtr)
{ {
os << "SET " << endl; os << "SET " << endl;
ColumnAssignmentList::const_iterator iter = fColAssignmentListPtr->begin(); ColumnAssignmentList::const_iterator iter = fColAssignmentListPtr->begin();
while (iter != fColAssignmentListPtr->end()) while (iter != fColAssignmentListPtr->end())
{ {
ColumnAssignment* cola = *iter; ColumnAssignment* cola = *iter;
@ -210,10 +220,12 @@ namespace dmlpackage
++iter; ++iter;
} }
} }
if (0 != fWhereClausePtr) if (0 != fWhereClausePtr)
{ {
fWhereClausePtr->put(os); fWhereClausePtr->put(os);
} }
return os; return os;
} }
@ -225,16 +237,19 @@ namespace dmlpackage
{ {
query_string += "SET "; query_string += "SET ";
ColumnAssignmentList::const_iterator iter = fColAssignmentListPtr->begin(); ColumnAssignmentList::const_iterator iter = fColAssignmentListPtr->begin();
while (iter != fColAssignmentListPtr->end()) while (iter != fColAssignmentListPtr->end())
{ {
ColumnAssignment* cola = *iter; ColumnAssignment* cola = *iter;
query_string += cola->getColumnAssignmentString(); query_string += cola->getColumnAssignmentString();
++iter; ++iter;
if (iter != fColAssignmentListPtr->end()) if (iter != fColAssignmentListPtr->end())
query_string += ","; query_string += ",";
} }
} }
if (0 != fWhereClausePtr) if (0 != fWhereClausePtr)
{ {
query_string += " "; query_string += " ";
@ -276,10 +291,12 @@ namespace dmlpackage
{ {
fNamePtr->put(os); fNamePtr->put(os);
} }
if (0 != fWhereClausePtr) if (0 != fWhereClausePtr)
{ {
fWhereClausePtr->put(os); fWhereClausePtr->put(os);
} }
return os; return os;
} }
@ -338,6 +355,7 @@ namespace dmlpackage
{ {
if (fSchema != "") if (fSchema != "")
os << fSchema << "."; os << fSchema << ".";
os << fName << endl; os << fName << endl;
return os; return os;
} }
@ -391,6 +409,7 @@ namespace dmlpackage
ostream& ValuesOrQuery::put(ostream& os) const ostream& ValuesOrQuery::put(ostream& os) const
{ {
ValuesList::const_iterator iter = fValuesList.begin(); ValuesList::const_iterator iter = fValuesList.begin();
while ( iter != fValuesList.end() ) while ( iter != fValuesList.end() )
{ {
os << *iter << endl; os << *iter << endl;
@ -441,6 +460,7 @@ namespace dmlpackage
{ {
if (0 != fSelectFilterPtr) if (0 != fSelectFilterPtr)
delete fSelectFilterPtr; delete fSelectFilterPtr;
if (0 != fTableExpressionPtr) if (0 != fTableExpressionPtr)
delete fTableExpressionPtr; delete fTableExpressionPtr;
} }
@ -451,6 +471,7 @@ namespace dmlpackage
{ {
fSelectFilterPtr->put(os); fSelectFilterPtr->put(os);
} }
if (0 != fTableExpressionPtr) if (0 != fTableExpressionPtr)
{ {
fTableExpressionPtr->put(os); fTableExpressionPtr->put(os);
@ -467,15 +488,18 @@ namespace dmlpackage
string QuerySpec::getQueryString() const string QuerySpec::getQueryString() const
{ {
std::string query_string; std::string query_string;
if (0 != fSelectFilterPtr) if (0 != fSelectFilterPtr)
{ {
query_string += fSelectFilterPtr->getSelectString(); query_string += fSelectFilterPtr->getSelectString();
} }
if (0 != fTableExpressionPtr) if (0 != fTableExpressionPtr)
{ {
query_string += " "; query_string += " ";
query_string += fTableExpressionPtr->getTableExpressionString(); query_string += fTableExpressionPtr->getTableExpressionString();
} }
if (fOptionAllOrDistinct != "") if (fOptionAllOrDistinct != "")
{ {
query_string += " "; query_string += " ";
@ -508,13 +532,16 @@ namespace dmlpackage
{ {
os << "SELECT" << endl; os << "SELECT" << endl;
ColumnNameList::const_iterator iter = fColumnList.begin(); ColumnNameList::const_iterator iter = fColumnList.begin();
while ( iter != fColumnList.end() ) while ( iter != fColumnList.end() )
{ {
os << *iter << endl; os << *iter << endl;
++iter; ++iter;
} }
if (0 == fColumnList.size()) if (0 == fColumnList.size())
os << "*" << endl; os << "*" << endl;
return os; return os;
} }
@ -522,13 +549,16 @@ namespace dmlpackage
{ {
std::string select_filter = "SELECT "; std::string select_filter = "SELECT ";
ColumnNameList::const_iterator iter = fColumnList.begin(); ColumnNameList::const_iterator iter = fColumnList.begin();
while ( iter != fColumnList.end() ) while ( iter != fColumnList.end() )
{ {
select_filter += *iter; select_filter += *iter;
++iter; ++iter;
if (iter != fColumnList.end()) if (iter != fColumnList.end())
select_filter += ","; select_filter += ",";
} }
if (0 == fColumnList.size()) if (0 == fColumnList.size())
select_filter += "*"; select_filter += "*";
@ -556,10 +586,13 @@ namespace dmlpackage
{ {
if (0 != fFromClausePtr) if (0 != fFromClausePtr)
delete fFromClausePtr; delete fFromClausePtr;
if (0 != fWhereClausePtr) if (0 != fWhereClausePtr)
delete fWhereClausePtr; delete fWhereClausePtr;
if (0 != fGroupByPtr) if (0 != fGroupByPtr)
delete fGroupByPtr; delete fGroupByPtr;
if (0 != fHavingPtr) if (0 != fHavingPtr)
delete fHavingPtr; delete fHavingPtr;
@ -571,14 +604,17 @@ namespace dmlpackage
{ {
fFromClausePtr->put(os); fFromClausePtr->put(os);
} }
if (0 != fWhereClausePtr) if (0 != fWhereClausePtr)
{ {
fWhereClausePtr->put(os); fWhereClausePtr->put(os);
} }
if (0 != fGroupByPtr) if (0 != fGroupByPtr)
{ {
fGroupByPtr->put(os); fGroupByPtr->put(os);
} }
if (0 != fHavingPtr) if (0 != fHavingPtr)
{ {
fHavingPtr->put(os); fHavingPtr->put(os);
@ -590,20 +626,24 @@ namespace dmlpackage
string TableExpression::getTableExpressionString() const string TableExpression::getTableExpressionString() const
{ {
std::string table_expression; std::string table_expression;
if (0 != fFromClausePtr) if (0 != fFromClausePtr)
{ {
table_expression += fFromClausePtr->getFromClauseString(); table_expression += fFromClausePtr->getFromClauseString();
} }
if (0 != fWhereClausePtr) if (0 != fWhereClausePtr)
{ {
table_expression += " "; table_expression += " ";
table_expression += fWhereClausePtr->getWhereClauseString(); table_expression += fWhereClausePtr->getWhereClauseString();
} }
if (0 != fGroupByPtr) if (0 != fGroupByPtr)
{ {
table_expression += " "; table_expression += " ";
table_expression += fGroupByPtr->getGroupByClauseString(); table_expression += fGroupByPtr->getGroupByClauseString();
} }
if (0 != fHavingPtr) if (0 != fHavingPtr)
{ {
table_expression += " "; table_expression += " ";
@ -630,12 +670,14 @@ namespace dmlpackage
if (0 != fTableListPtr) if (0 != fTableListPtr)
{ {
TableNameList::iterator iter = fTableListPtr->begin(); TableNameList::iterator iter = fTableListPtr->begin();
while ( iter != fTableListPtr->end() ) while ( iter != fTableListPtr->end() )
{ {
TableName* tableNamePtr = *iter; TableName* tableNamePtr = *iter;
delete tableNamePtr; delete tableNamePtr;
++iter; ++iter;
} }
fTableListPtr->clear(); fTableListPtr->clear();
delete fTableListPtr; delete fTableListPtr;
} }
@ -648,6 +690,7 @@ namespace dmlpackage
if (0 != fTableListPtr) if (0 != fTableListPtr)
{ {
TableNameList::const_iterator iter = fTableListPtr->begin(); TableNameList::const_iterator iter = fTableListPtr->begin();
while ( iter != fTableListPtr->end() ) while ( iter != fTableListPtr->end() )
{ {
TableName* tableNamePtr = *iter; TableName* tableNamePtr = *iter;
@ -655,30 +698,37 @@ namespace dmlpackage
++iter; ++iter;
} }
} }
return os; return os;
} }
string FromClause::getFromClauseString() const string FromClause::getFromClauseString() const
{ {
std::string from_clause = "FROM "; std::string from_clause = "FROM ";
if (0 != fTableListPtr) if (0 != fTableListPtr)
{ {
TableNameList::const_iterator iter = fTableListPtr->begin(); TableNameList::const_iterator iter = fTableListPtr->begin();
while (iter != fTableListPtr->end()) while (iter != fTableListPtr->end())
{ {
TableName* tableNamePtr = *iter; TableName* tableNamePtr = *iter;
if (tableNamePtr->fSchema != "") if (tableNamePtr->fSchema != "")
{ {
from_clause += tableNamePtr->fSchema; from_clause += tableNamePtr->fSchema;
from_clause += "."; from_clause += ".";
} }
from_clause += tableNamePtr->fName; from_clause += tableNamePtr->fName;
++iter; ++iter;
if (iter != fTableListPtr->end()) if (iter != fTableListPtr->end())
from_clause += ","; from_clause += ",";
} }
} }
return from_clause; return from_clause;
} }
@ -701,6 +751,7 @@ namespace dmlpackage
ostream& WhereClause::put(ostream& os) const ostream& WhereClause::put(ostream& os) const
{ {
os << "WHERE" << endl; os << "WHERE" << endl;
if (0 != fSearchConditionPtr) if (0 != fSearchConditionPtr)
{ {
fSearchConditionPtr->put(os); fSearchConditionPtr->put(os);
@ -712,11 +763,13 @@ namespace dmlpackage
string WhereClause::getWhereClauseString() const string WhereClause::getWhereClauseString() const
{ {
std::string where_clause = "WHERE"; std::string where_clause = "WHERE";
if (0 != fSearchConditionPtr) if (0 != fSearchConditionPtr)
{ {
where_clause += " "; where_clause += " ";
where_clause += fSearchConditionPtr->getSearchConditionString(); where_clause += fSearchConditionPtr->getSearchConditionString();
} }
return where_clause; return where_clause;
} }
@ -738,16 +791,19 @@ namespace dmlpackage
ostream& HavingClause::put(ostream& os) const ostream& HavingClause::put(ostream& os) const
{ {
os << "HAVING" << endl; os << "HAVING" << endl;
if (0 != fSearchConditionPtr) if (0 != fSearchConditionPtr)
{ {
fSearchConditionPtr->put(os); fSearchConditionPtr->put(os);
} }
return os; return os;
} }
string HavingClause::getHavingClauseString() const string HavingClause::getHavingClauseString() const
{ {
std::string having_clause = "HAVING"; std::string having_clause = "HAVING";
if (0 != fSearchConditionPtr) if (0 != fSearchConditionPtr)
{ {
having_clause += " "; having_clause += " ";
@ -776,28 +832,34 @@ namespace dmlpackage
ostream& GroupByClause::put(ostream& os) const ostream& GroupByClause::put(ostream& os) const
{ {
os << "GROUP BY" << endl; os << "GROUP BY" << endl;
if (0 != fColumnNamesListPtr) if (0 != fColumnNamesListPtr)
{ {
ColumnNameList::const_iterator iter = fColumnNamesListPtr->begin(); ColumnNameList::const_iterator iter = fColumnNamesListPtr->begin();
if (iter != fColumnNamesListPtr->end()) if (iter != fColumnNamesListPtr->end())
{ {
os << *iter << endl; os << *iter << endl;
++iter; ++iter;
} }
} }
return os; return os;
} }
string GroupByClause::getGroupByClauseString() const string GroupByClause::getGroupByClauseString() const
{ {
std::string group_by_clause = "GROUP BY "; std::string group_by_clause = "GROUP BY ";
if (0 != fColumnNamesListPtr) if (0 != fColumnNamesListPtr)
{ {
ColumnNameList::const_iterator iter = fColumnNamesListPtr->begin(); ColumnNameList::const_iterator iter = fColumnNamesListPtr->begin();
if (iter != fColumnNamesListPtr->end()) if (iter != fColumnNamesListPtr->end())
{ {
group_by_clause += *iter; group_by_clause += *iter;
++iter; ++iter;
if (iter != fColumnNamesListPtr->end()) if (iter != fColumnNamesListPtr->end())
group_by_clause += ","; group_by_clause += ",";
} }
@ -830,10 +892,12 @@ namespace dmlpackage
{ {
delete fPredicatePtr; delete fPredicatePtr;
} }
if (0 != fLHSearchConditionPtr) if (0 != fLHSearchConditionPtr)
{ {
delete fLHSearchConditionPtr; delete fLHSearchConditionPtr;
} }
if (0 != fRHSearchConditionPtr) if (0 != fRHSearchConditionPtr)
{ {
delete fRHSearchConditionPtr; delete fRHSearchConditionPtr;
@ -852,6 +916,7 @@ namespace dmlpackage
{ {
fLHSearchConditionPtr->put(os); fLHSearchConditionPtr->put(os);
} }
if (0 != fRHSearchConditionPtr) if (0 != fRHSearchConditionPtr)
{ {
os << fOperator << endl; os << fOperator << endl;
@ -864,15 +929,18 @@ namespace dmlpackage
string SearchCondition::getSearchConditionString() const string SearchCondition::getSearchConditionString() const
{ {
std::string search_condition; std::string search_condition;
if (0 != fPredicatePtr) if (0 != fPredicatePtr)
{ {
search_condition += fPredicatePtr->getPredicateString(); search_condition += fPredicatePtr->getPredicateString();
} }
if (0 != fLHSearchConditionPtr) if (0 != fLHSearchConditionPtr)
{ {
search_condition += fLHSearchConditionPtr->getSearchConditionString(); search_condition += fLHSearchConditionPtr->getSearchConditionString();
search_condition += " "; search_condition += " ";
} }
if (0 != fRHSearchConditionPtr) if (0 != fRHSearchConditionPtr)
{ {
search_condition += fOperator; search_condition += fOperator;
@ -906,6 +974,7 @@ namespace dmlpackage
{ {
fSubQuerySpecPtr->put(os); fSubQuerySpecPtr->put(os);
} }
//cout << ")" << endl; //cout << ")" << endl;
return os; return os;
} }
@ -914,11 +983,13 @@ namespace dmlpackage
{ {
std::string exists_predicate = "EXISTS"; std::string exists_predicate = "EXISTS";
exists_predicate += "("; exists_predicate += "(";
if (0 != fSubQuerySpecPtr) if (0 != fSubQuerySpecPtr)
{ {
exists_predicate += " "; exists_predicate += " ";
exists_predicate += fSubQuerySpecPtr->getQueryString(); exists_predicate += fSubQuerySpecPtr->getQueryString();
} }
exists_predicate += ")"; exists_predicate += ")";
return exists_predicate; return exists_predicate;
} }
@ -949,6 +1020,7 @@ namespace dmlpackage
{ {
fSubQuerySpecPtr->put(os); fSubQuerySpecPtr->put(os);
} }
return os; return os;
} }
@ -991,6 +1063,7 @@ namespace dmlpackage
os << "(" << endl; os << "(" << endl;
AtomList::const_iterator iter = fAtomList.begin(); AtomList::const_iterator iter = fAtomList.begin();
while (iter != fAtomList.end()) while (iter != fAtomList.end())
{ {
os << *iter << endl; os << *iter << endl;
@ -1016,13 +1089,16 @@ namespace dmlpackage
in_predicate += "("; in_predicate += "(";
AtomList::const_iterator iter = fAtomList.begin(); AtomList::const_iterator iter = fAtomList.begin();
while (iter != fAtomList.end()) while (iter != fAtomList.end())
{ {
in_predicate += *iter; in_predicate += *iter;
++iter; ++iter;
if (iter != fAtomList.end()) if (iter != fAtomList.end())
in_predicate += ","; in_predicate += ",";
} }
if (0 != fSubQuerySpecPtr) if (0 != fSubQuerySpecPtr)
{ {
in_predicate += fSubQuerySpecPtr->getQueryString(); in_predicate += fSubQuerySpecPtr->getQueryString();

View File

@ -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;
@ -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;
@ -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,7 +353,10 @@ 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
*/ */

View File

@ -35,6 +35,7 @@ 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;
@ -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,6 +52,7 @@ 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);
@ -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

@ -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);
} }
@ -159,6 +165,7 @@ int InsertDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
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

@ -39,6 +39,7 @@ Row::~Row()
{ {
delete fColumnList[i]; delete fColumnList[i];
} }
fColumnList.clear(); fColumnList.clear();
} }
@ -50,6 +51,7 @@ Row::Row(const Row& row)
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,6 +46,7 @@ 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();
@ -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;
@ -216,11 +250,13 @@ public:
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);
@ -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;

View File

@ -67,10 +67,12 @@ 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,6 +107,7 @@ 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,6 +180,7 @@ 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
@ -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);
} }
@ -214,6 +223,7 @@ int UpdateDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
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

@ -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
* *

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,10 +82,12 @@ 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;
} }

View File

@ -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
@ -237,6 +258,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
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,6 +304,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 > (uint64_t)nextVal)) if ((validNextVal) && (nextValInController > (uint64_t)nextVal))
{ {
fWEClient->removeQueue(uniqueId); fWEClient->removeQueue(uniqueId);
@ -288,6 +313,7 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
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;
} }
@ -465,6 +501,7 @@ 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);
@ -478,10 +515,12 @@ CommandPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
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;
} }
@ -581,65 +626,85 @@ void CommandPackageProcessor::viewTableLock(
{ {
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];
} }
@ -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;
@ -785,6 +855,7 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
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,6 +914,7 @@ 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]);
@ -846,16 +922,20 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
// 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,6 +992,7 @@ 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]);
@ -916,16 +1000,20 @@ void CommandPackageProcessor::clearTableLock( uint64_t uniqueId,
// 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(

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

@ -73,8 +73,10 @@ namespace dmlpackageprocessor
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;
@ -133,12 +137,14 @@ namespace dmlpackageprocessor
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&)
@ -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;
@ -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;
@ -362,22 +384,27 @@ namespace dmlpackageprocessor
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)
@ -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,6 +801,7 @@ 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]])
@ -756,9 +812,11 @@ 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;
@ -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

@ -71,6 +71,7 @@ namespace 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;
} }
@ -79,18 +80,22 @@ namespace dmlpackageprocessor
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);
} }
@ -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;
} }
@ -237,6 +248,7 @@ string DMLPackageProcessor::projectTableErrCodeToMsg(uint32_t 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 ";
@ -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 )
@ -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,13 +481,16 @@ 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);
@ -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();
@ -487,7 +527,8 @@ int DMLPackageProcessor::commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::Tx
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++;
} }
@ -539,6 +584,7 @@ int DMLPackageProcessor::rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::
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))
@ -555,6 +601,7 @@ int DMLPackageProcessor::rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::
// 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,6 +663,7 @@ 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;
@ -615,28 +672,34 @@ int DMLPackageProcessor::rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::
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;
} }
@ -653,6 +716,7 @@ int DMLPackageProcessor::commitBatchAutoOffTransaction(uint64_t uniqueId, BRM::T
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))
@ -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,10 +746,12 @@ 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;
@ -694,21 +762,26 @@ 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;
} }
@ -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;
@ -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

@ -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();
@ -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,7 +229,10 @@ 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);
@ -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

View File

@ -31,7 +31,8 @@
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)

View File

@ -33,12 +33,14 @@
#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:

View File

@ -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,6 +108,7 @@ 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;
@ -127,6 +130,7 @@ namespace dmlpackageprocessor
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&)
@ -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;
@ -220,9 +231,11 @@ 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;
@ -236,6 +249,7 @@ 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];
@ -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,6 +310,7 @@ 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);
@ -304,14 +320,18 @@ cout << "Single insert sending WE_SVR_SINGLE_INSERT to pm " << pmNum << endl;
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;
} }
@ -334,6 +354,7 @@ cout << "Single insert got exception" << ex.what() << endl;
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;

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,10 +85,12 @@ 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;
} }

View File

@ -458,9 +458,11 @@ 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;
@ -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");
@ -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;
@ -822,6 +829,7 @@ public:
ml.logDebugMessage( result.message ); ml.logDebugMessage( result.message );
} }
delete pkgProcPtr; delete pkgProcPtr;
delete pObject; delete pObject;
@ -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;
@ -921,6 +931,7 @@ public:
ml.logDebugMessage( result.message ); ml.logDebugMessage( result.message );
} }
delete pkgProcPtr; delete pkgProcPtr;
delete pObject; delete pObject;
} }

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

@ -80,8 +80,10 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
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
@ -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;
@ -158,12 +164,14 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
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&)
@ -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;
@ -224,12 +237,14 @@ UpdatePackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
} }
} }
} }
//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,6 +403,7 @@ 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)
@ -415,14 +441,17 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
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());
@ -540,10 +578,12 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
//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;
@ -586,9 +630,11 @@ uint64_t UpdatePackageProcessor::fixUpRows(dmlpackage::CalpontDMLPackage& cpacka
//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,6 +714,7 @@ 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;
} }
@ -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,6 +906,7 @@ 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]])
@ -852,9 +917,11 @@ 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;
@ -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
* *

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,7 +43,8 @@ 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)
{ {
@ -54,6 +55,7 @@ void getAggCols(execplan::ParseTree* n, void* obj)
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
@ -221,17 +234,23 @@ void AggregateColumn::unserialize(messageqcpp::ByteStream& b)
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;
@ -245,14 +264,19 @@ bool AggregateColumn::operator==(const AggregateColumn& t) const
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,19 +284,24 @@ 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;
} }
@ -281,8 +310,10 @@ 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;
} }
} }
@ -514,32 +593,46 @@ AggregateColumn::AggOp AggregateColumn::agname2num(const string& agname)
*/ */
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;
} }

84
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:
/** /**
@ -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,12 +120,14 @@ 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++]);
@ -173,6 +179,7 @@ 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;
@ -197,12 +204,14 @@ void ArithmeticColumn::buildTree()
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] == '.' )
@ -226,6 +235,7 @@ void ArithmeticColumn::buildTree()
tokens.push_back(t); tokens.push_back(t);
continue; continue;
} }
++i; ++i;
} }
@ -239,6 +249,7 @@ void ArithmeticColumn::buildTree()
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());
} }
} }
@ -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,8 +307,11 @@ 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 <<
@ -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;
@ -337,20 +356,27 @@ bool ArithmeticColumn::operator==(const ArithmeticColumn& t) const
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;
} }
@ -359,8 +385,10 @@ 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,7 +34,8 @@
/** /**
* Namespace * Namespace
*/ */
namespace execplan { namespace execplan
{
class SimpleColumn; class SimpleColumn;
class AggregateColumn; class AggregateColumn;
@ -44,7 +45,8 @@ 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 );
@ -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();
/** /**

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
@ -104,6 +113,7 @@ bool ArithmeticOperator::operator==(const ArithmeticOperator& t) const
{ {
if (fData == t.fData) if (fData == t.fData)
return true; return true;
return false; return false;
} }
@ -112,8 +122,10 @@ 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();
@ -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,40 +247,48 @@ 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)];
@ -276,13 +296,16 @@ inline void ArithmeticOperator::execute(IDB_Decimal& result, IDB_Decimal op1, ID
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 :
@ -291,7 +314,9 @@ inline void ArithmeticOperator::execute(IDB_Decimal& result, IDB_Decimal op1, ID
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;

View File

@ -45,7 +45,8 @@ extern "C" void init_demangler(int, int, int);
using namespace execplan; using namespace execplan;
class ExecPlanTest : public CppUnit::TestFixture { class ExecPlanTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( ExecPlanTest ); CPPUNIT_TEST_SUITE( ExecPlanTest );
@ -61,17 +62,21 @@ public:
char* r; char* r;
static bool is_init = false; static bool is_init = false;
const char* mname = typeid(*(n->data())).name(); const char* mname = typeid(*(n->data())).name();
if (!is_init) if (!is_init)
{ {
::init_demangler(0, 0, 0); ::init_demangler(0, 0, 0);
is_init = true; is_init = true;
} }
r = ::cplus_demangle_with_style(mname, 7, 27); r = ::cplus_demangle_with_style(mname, 7, 27);
if (r != 0) if (r != 0)
{ {
//cout << "mangle: " << mname << " demangle: " << r << endl; //cout << "mangle: " << mname << " demangle: " << r << endl;
::free(r); ::free(r);
} }
if (typeid(*(n->data())) == typeid(SimpleFilter)) if (typeid(*(n->data())) == typeid(SimpleFilter))
{ {
cout << "SimpleFilter: " << endl; cout << "SimpleFilter: " << endl;
@ -81,6 +86,7 @@ public:
const Operator* op = sf->op(); const Operator* op = sf->op();
cout << '\t' << lhs->data() << ' ' << op->data() << ' ' << rhs->data(); cout << '\t' << lhs->data() << ' ' << op->data() << ' ' << rhs->data();
cout << endl << "\t\t"; cout << endl << "\t\t";
if (typeid(*lhs) == typeid(SimpleColumn)) if (typeid(*lhs) == typeid(SimpleColumn))
{ {
cout << "SimpleColumn: " << lhs->data() << " / "; cout << "SimpleColumn: " << lhs->data() << " / ";
@ -93,7 +99,9 @@ public:
{ {
cout << "UNK: " << lhs->data() << " / "; cout << "UNK: " << lhs->data() << " / ";
} }
cout << "Operator: " << op->data() << " / "; cout << "Operator: " << op->data() << " / ";
if (typeid(*rhs) == typeid(SimpleColumn)) if (typeid(*rhs) == typeid(SimpleColumn))
{ {
cout << "SimpleColumn: " << rhs->data(); cout << "SimpleColumn: " << rhs->data();
@ -117,16 +125,20 @@ public:
{ {
cout << mname << " -x-: "; cout << mname << " -x-: ";
} }
cout << endl; cout << endl;
} }
void setUp() { void setUp()
{
} }
void tearDown() { void tearDown()
{
} }
void selectExecutionPlan_1() { void selectExecutionPlan_1()
{
cout << "SQL: select r_regionkey from region, nation where n_regionkey = r_regionkey and n_regionkey = 2;" << endl; cout << "SQL: select r_regionkey from region, nation where n_regionkey = r_regionkey and n_regionkey = 2;" << endl;
CalpontSelectExecutionPlan csep; CalpontSelectExecutionPlan csep;
CalpontSelectExecutionPlan::ReturnedColumnList colList; CalpontSelectExecutionPlan::ReturnedColumnList colList;

View File

@ -23,7 +23,8 @@
#include "calpontexecutionplan.h" #include "calpontexecutionplan.h"
namespace execplan{ namespace execplan
{
/** /**
* Constructors/Destructors * Constructors/Destructors
*/ */

View File

@ -27,14 +27,16 @@
#include <string> #include <string>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
namespace messageqcpp { namespace messageqcpp
{
class ByteStream; class ByteStream;
} }
/** /**
* Namespace * Namespace
*/ */
namespace execplan { namespace execplan
{
/** /**
* ******************************* Abstract Class **************************** * ******************************* Abstract Class ****************************
* CalpontExecutionPlan does not have any pure virtual methods, but its author * CalpontExecutionPlan does not have any pure virtual methods, but its author
@ -42,7 +44,8 @@ namespace execplan {
* Inherit from it instead and create only objects from the derived classes * Inherit from it instead and create only objects from the derived classes
* ***************************************************************************** * *****************************************************************************
*/ */
class CalpontExecutionPlan { class CalpontExecutionPlan
{
/** /**
* Public stuff * Public stuff
*/ */

View File

@ -26,7 +26,8 @@
#include "vendorexecutionplan.h" #include "vendorexecutionplan.h"
#include "calpontselectexecutionplan.h" #include "calpontselectexecutionplan.h"
namespace execplan { namespace execplan
{
//CalpontExecutionPlan* CalpontExecutionPlanFactory::makeCalpontExecutionPlan(const VendorExecutionPlan* vplan) //CalpontExecutionPlan* CalpontExecutionPlanFactory::makeCalpontExecutionPlan(const VendorExecutionPlan* vplan)
//{ //{

View File

@ -28,9 +28,11 @@
#include "calpontexecutionplan.h" #include "calpontexecutionplan.h"
#include "vendorexecutionplan.h" #include "vendorexecutionplan.h"
namespace execplan { namespace execplan
{
class CalpontExecutionPlanFactory { class CalpontExecutionPlanFactory
{
public: public:
//static CalpontExecutionPlan* makeCalpontExecutionPlan(const VendorExecutionPlan* vplan); //static CalpontExecutionPlan* makeCalpontExecutionPlan(const VendorExecutionPlan* vplan);

View File

@ -39,11 +39,16 @@ using namespace messageqcpp;
#include "querytele.h" #include "querytele.h"
using namespace querytele; using namespace querytele;
namespace { namespace
{
template<class T> struct deleter : public unary_function<T&, void> template<class T> struct deleter : public unary_function<T&, void>
{ {
void operator()(T& x) { delete x; x = 0; } void operator()(T& x)
{
delete x;
x = 0;
}
}; };
} }
@ -159,8 +164,10 @@ CalpontSelectExecutionPlan::~CalpontSelectExecutionPlan()
{ {
if (fFilters != NULL) if (fFilters != NULL)
delete fFilters; delete fFilters;
if (fHaving != NULL) if (fHaving != NULL)
delete fHaving; delete fHaving;
fFilters = NULL; fFilters = NULL;
fHaving = NULL; fHaving = NULL;
} }
@ -182,6 +189,7 @@ void CalpontSelectExecutionPlan::filterTokenList( FilterTokenList& filterTokenLi
t.value = filterTokenList[i]; t.value = filterTokenList[i];
tokens.push_back(t); tokens.push_back(t);
} }
if (tokens.size() > 0) if (tokens.size() > 0)
filters(parser.parse(tokens.begin(), tokens.end())); filters(parser.parse(tokens.begin(), tokens.end()));
} }
@ -199,6 +207,7 @@ void CalpontSelectExecutionPlan::havingTokenList( const FilterTokenList& havingT
t.value = havingTokenList[i]; t.value = havingTokenList[i];
tokens.push_back(t); tokens.push_back(t);
} }
if (tokens.size() > 0) if (tokens.size() > 0)
having(parser.parse(tokens.begin(), tokens.end())); having(parser.parse(tokens.begin(), tokens.end()));
} }
@ -208,8 +217,10 @@ string CalpontSelectExecutionPlan::toString() const
ostringstream output; ostringstream output;
output << ">SELECT " ; output << ">SELECT " ;
if (distinct()) if (distinct())
output << "DISTINCT "; output << "DISTINCT ";
output << "limit: " << limitStart() << " - " << limitNum() << endl; output << "limit: " << limitStart() << " - " << limitNum() << endl;
switch (location()) switch (location())
@ -217,12 +228,15 @@ string CalpontSelectExecutionPlan::toString() const
case CalpontSelectExecutionPlan::MAIN: case CalpontSelectExecutionPlan::MAIN:
output << "MAIN" << endl; output << "MAIN" << endl;
break; break;
case CalpontSelectExecutionPlan::FROM: case CalpontSelectExecutionPlan::FROM:
output << "FROM" << endl; output << "FROM" << endl;
break; break;
case CalpontSelectExecutionPlan::WHERE: case CalpontSelectExecutionPlan::WHERE:
output << "WHERE" << endl; output << "WHERE" << endl;
break; break;
case CalpontSelectExecutionPlan::HAVING: case CalpontSelectExecutionPlan::HAVING:
output << "HAVING" << endl; output << "HAVING" << endl;
break; break;
@ -232,13 +246,16 @@ string CalpontSelectExecutionPlan::toString() const
CalpontSelectExecutionPlan::ReturnedColumnList retCols = returnedCols(); CalpontSelectExecutionPlan::ReturnedColumnList retCols = returnedCols();
output << ">>Returned Columns" << endl; output << ">>Returned Columns" << endl;
uint32_t seq = 0; uint32_t seq = 0;
for (unsigned int i = 0; i < retCols.size(); i++) for (unsigned int i = 0; i < retCols.size(); i++)
{ {
output << *retCols[i] << endl; output << *retCols[i] << endl;
if (retCols[i]->colSource() & SELECT_SUB) if (retCols[i]->colSource() & SELECT_SUB)
{ {
output << "select sub -- " << endl; output << "select sub -- " << endl;
CalpontSelectExecutionPlan* plan = dynamic_cast<CalpontSelectExecutionPlan*>(fSelectSubList[seq++].get()); CalpontSelectExecutionPlan* plan = dynamic_cast<CalpontSelectExecutionPlan*>(fSelectSubList[seq++].get());
if (plan) if (plan)
output << "{" << *plan << "}" << endl; output << "{" << *plan << "}" << endl;
} }
@ -248,6 +265,7 @@ string CalpontSelectExecutionPlan::toString() const
CalpontSelectExecutionPlan::TableList tables = tableList(); CalpontSelectExecutionPlan::TableList tables = tableList();
output << ">>From Tables" << endl; output << ">>From Tables" << endl;
seq = 0; seq = 0;
for (unsigned int i = 0; i < tables.size(); i++) for (unsigned int i = 0; i < tables.size(); i++)
{ {
// derived table // derived table
@ -255,6 +273,7 @@ string CalpontSelectExecutionPlan::toString() const
{ {
output << "derived table - " << tables[i].alias << endl; output << "derived table - " << tables[i].alias << endl;
CalpontSelectExecutionPlan* plan = dynamic_cast<CalpontSelectExecutionPlan*>(fDerivedTableList[seq++].get()); CalpontSelectExecutionPlan* plan = dynamic_cast<CalpontSelectExecutionPlan*>(fDerivedTableList[seq++].get());
if (plan) if (plan)
output << "{" << *plan << "}" << endl; output << "{" << *plan << "}" << endl;
} }
@ -266,6 +285,7 @@ string CalpontSelectExecutionPlan::toString() const
// Filters // Filters
output << ">>Filters" << endl; output << ">>Filters" << endl;
if (filters() != 0) if (filters() != 0)
filters()->walk (ParseTree::print, output); filters()->walk (ParseTree::print, output);
else else
@ -273,9 +293,11 @@ string CalpontSelectExecutionPlan::toString() const
// Group by columns // Group by columns
const CalpontSelectExecutionPlan::GroupByColumnList& gbc = groupByCols(); const CalpontSelectExecutionPlan::GroupByColumnList& gbc = groupByCols();
if (gbc.size() > 0) if (gbc.size() > 0)
{ {
output << ">>Group By Columns" << endl; output << ">>Group By Columns" << endl;
for (unsigned int i = 0; i < gbc.size(); i++) for (unsigned int i = 0; i < gbc.size(); i++)
output << *gbc[i] << endl; output << *gbc[i] << endl;
} }
@ -289,12 +311,15 @@ string CalpontSelectExecutionPlan::toString() const
// Order by columns // Order by columns
const CalpontSelectExecutionPlan::OrderByColumnList& obc = orderByCols(); const CalpontSelectExecutionPlan::OrderByColumnList& obc = orderByCols();
if (obc.size() > 0) if (obc.size() > 0)
{ {
output << ">>Order By Columns" << endl; output << ">>Order By Columns" << endl;
for (unsigned int i = 0; i < obc.size(); i++) for (unsigned int i = 0; i < obc.size(); i++)
output << *obc[i] << endl; output << *obc[i] << endl;
} }
output << "SessionID: " << fSessionID << endl; output << "SessionID: " << fSessionID << endl;
output << "TxnID: " << fTxnID << endl; output << "TxnID: " << fTxnID << endl;
output << "VerID: " << fVerID << endl; output << "VerID: " << fVerID << endl;
@ -306,17 +331,21 @@ string CalpontSelectExecutionPlan::toString() const
output << "--- Column Map ---" << endl; output << "--- Column Map ---" << endl;
CalpontSelectExecutionPlan::ColumnMap::const_iterator iter; CalpontSelectExecutionPlan::ColumnMap::const_iterator iter;
for (iter = columnMap().begin(); iter != columnMap().end(); iter++) for (iter = columnMap().begin(); iter != columnMap().end(); iter++)
output << (*iter).first << " : " << (*iter).second << endl; output << (*iter).first << " : " << (*iter).second << endl;
output << "UUID: " << fUuid << endl; output << "UUID: " << fUuid << endl;
output << "QueryType: " << queryType() << endl; output << "QueryType: " << queryType() << endl;
if (!unionVec().empty()) if (!unionVec().empty())
output << "\n--- Union Unit ---" << endl; output << "\n--- Union Unit ---" << endl;
for (unsigned i = 0; i < unionVec().size(); i++) for (unsigned i = 0; i < unionVec().size(); i++)
{ {
CalpontSelectExecutionPlan* plan = CalpontSelectExecutionPlan* plan =
dynamic_cast<CalpontSelectExecutionPlan*>(unionVec()[i].get()); dynamic_cast<CalpontSelectExecutionPlan*>(unionVec()[i].get());
if (plan) if (plan)
output << "{" << *plan << "}\n" << endl; output << "{" << *plan << "}\n" << endl;
} }
@ -330,23 +359,32 @@ string CalpontSelectExecutionPlan::queryTypeToString(const uint32_t queryType)
{ {
case SELECT: case SELECT:
return "SELECT"; return "SELECT";
case UPDATE: case UPDATE:
return "UPDATE"; return "UPDATE";
case DELETE: case DELETE:
return "DELETE"; return "DELETE";
case INSERT_SELECT: case INSERT_SELECT:
return "INSERT_SELECT"; return "INSERT_SELECT";
case CREATE_TABLE: case CREATE_TABLE:
return "CREATE_TABLE"; return "CREATE_TABLE";
case DROP_TABLE: case DROP_TABLE:
return "DROP_TABLE"; return "DROP_TABLE";
case ALTER_TABLE: case ALTER_TABLE:
return "ALTER_TABLE"; return "ALTER_TABLE";
case INSERT: case INSERT:
return "INSERT"; return "INSERT";
case LOAD_DATA_INFILE: case LOAD_DATA_INFILE:
return "LOAD_DATA_INFILE"; return "LOAD_DATA_INFILE";
} }
return "UNKNOWN"; return "UNKNOWN";
} }
@ -360,10 +398,12 @@ void CalpontSelectExecutionPlan::serialize(messageqcpp::ByteStream& b) const
b << static_cast<ObjectReader::id_t>(ObjectReader::CALPONTSELECTEXECUTIONPLAN); b << static_cast<ObjectReader::id_t>(ObjectReader::CALPONTSELECTEXECUTIONPLAN);
b << static_cast<uint32_t>(fReturnedCols.size()); b << static_cast<uint32_t>(fReturnedCols.size());
for (rcit = fReturnedCols.begin(); rcit != fReturnedCols.end(); ++rcit) for (rcit = fReturnedCols.begin(); rcit != fReturnedCols.end(); ++rcit)
(*rcit)->serialize(b); (*rcit)->serialize(b);
b << static_cast<uint32_t>(fTableList.size()); b << static_cast<uint32_t>(fTableList.size());
for (tit = fTableList.begin(); tit != fTableList.end(); ++tit) for (tit = fTableList.begin(); tit != fTableList.end(); ++tit)
{ {
(*tit).serialize(b); (*tit).serialize(b);
@ -372,20 +412,24 @@ void CalpontSelectExecutionPlan::serialize(messageqcpp::ByteStream& b) const
ObjectReader::writeParseTree(fFilters, b); ObjectReader::writeParseTree(fFilters, b);
b << static_cast<uint32_t>(fSubSelects.size()); b << static_cast<uint32_t>(fSubSelects.size());
for (uint32_t i = 0; i < fSubSelects.size(); i++) for (uint32_t i = 0; i < fSubSelects.size(); i++)
fSubSelects[i]->serialize(b); fSubSelects[i]->serialize(b);
b << static_cast<uint32_t>(fGroupByCols.size()); b << static_cast<uint32_t>(fGroupByCols.size());
for (rcit = fGroupByCols.begin(); rcit != fGroupByCols.end(); ++rcit) for (rcit = fGroupByCols.begin(); rcit != fGroupByCols.end(); ++rcit)
(*rcit)->serialize(b); (*rcit)->serialize(b);
ObjectReader::writeParseTree(fHaving, b); ObjectReader::writeParseTree(fHaving, b);
b << static_cast<uint32_t>(fOrderByCols.size()); b << static_cast<uint32_t>(fOrderByCols.size());
for (rcit = fOrderByCols.begin(); rcit != fOrderByCols.end(); ++rcit) for (rcit = fOrderByCols.begin(); rcit != fOrderByCols.end(); ++rcit)
(*rcit)->serialize(b); (*rcit)->serialize(b);
b << static_cast<uint32_t>(fColumnMap.size()); b << static_cast<uint32_t>(fColumnMap.size());
for (mapiter = fColumnMap.begin(); mapiter != fColumnMap.end(); ++mapiter) for (mapiter = fColumnMap.begin(); mapiter != fColumnMap.end(); ++mapiter)
{ {
b << (*mapiter).first; b << (*mapiter).first;
@ -393,6 +437,7 @@ void CalpontSelectExecutionPlan::serialize(messageqcpp::ByteStream& b) const
} }
b << static_cast<uint32_t>(frmParms.size()); b << static_cast<uint32_t>(frmParms.size());
for (RMParmVec::const_iterator it = frmParms.begin(); it != frmParms.end(); ++it) for (RMParmVec::const_iterator it = frmParms.begin(); it != frmParms.end(); ++it)
{ {
b << it->sessionId; b << it->sessionId;
@ -418,6 +463,7 @@ void CalpontSelectExecutionPlan::serialize(messageqcpp::ByteStream& b) const
// for union // for union
b << (uint8_t)fDistinctUnionNum; b << (uint8_t)fDistinctUnionNum;
b << (uint32_t)fUnionVec.size(); b << (uint32_t)fUnionVec.size();
for (uint32_t i = 0; i < fUnionVec.size(); i++) for (uint32_t i = 0; i < fUnionVec.size(); i++)
fUnionVec[i]->serialize(b); fUnionVec[i]->serialize(b);
@ -425,6 +471,7 @@ void CalpontSelectExecutionPlan::serialize(messageqcpp::ByteStream& b) const
// for FROM subquery // for FROM subquery
b << static_cast<uint32_t>(fDerivedTableList.size()); b << static_cast<uint32_t>(fDerivedTableList.size());
for (uint32_t i = 0; i < fDerivedTableList.size(); i++) for (uint32_t i = 0; i < fDerivedTableList.size(); i++)
fDerivedTableList[i]->serialize(b); fDerivedTableList[i]->serialize(b);
@ -433,6 +480,7 @@ void CalpontSelectExecutionPlan::serialize(messageqcpp::ByteStream& b) const
b << static_cast<const ByteStream::byte>(fHasOrderBy); b << static_cast<const ByteStream::byte>(fHasOrderBy);
b << static_cast<uint32_t>(fSelectSubList.size()); b << static_cast<uint32_t>(fSelectSubList.size());
for (uint32_t i = 0; i < fSelectSubList.size(); i++) for (uint32_t i = 0; i < fSelectSubList.size(); i++)
fSelectSubList[i]->serialize(b); fSelectSubList[i]->serialize(b);
@ -471,11 +519,14 @@ void CalpontSelectExecutionPlan::unserialize(messageqcpp::ByteStream& b)
fDerivedTableList.clear(); fDerivedTableList.clear();
fSelectSubList.clear(); fSelectSubList.clear();
if (fFilters != 0) { if (fFilters != 0)
{
delete fFilters; delete fFilters;
fFilters = 0; fFilters = 0;
} }
if (fHaving != 0) {
if (fHaving != 0)
{
delete fHaving; delete fHaving;
fHaving = 0; fHaving = 0;
} }
@ -484,7 +535,9 @@ void CalpontSelectExecutionPlan::unserialize(messageqcpp::ByteStream& b)
messageqcpp::ByteStream::quadbyte i; messageqcpp::ByteStream::quadbyte i;
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);
fReturnedCols.push_back(srcp); fReturnedCols.push_back(srcp);
@ -492,6 +545,7 @@ void CalpontSelectExecutionPlan::unserialize(messageqcpp::ByteStream& b)
b >> size; b >> size;
CalpontSystemCatalog::TableAliasName tan; CalpontSystemCatalog::TableAliasName tan;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
tan.unserialize(b); tan.unserialize(b);
@ -501,13 +555,17 @@ void CalpontSelectExecutionPlan::unserialize(messageqcpp::ByteStream& b)
fFilters = ObjectReader::createParseTree(b); fFilters = ObjectReader::createParseTree(b);
b >> size; b >> size;
for (i = 0; i < size; i++) {
for (i = 0; i < size; i++)
{
cep = ObjectReader::createExecutionPlan(b); cep = ObjectReader::createExecutionPlan(b);
fSubSelects.push_back(SCEP(cep)); fSubSelects.push_back(SCEP(cep));
} }
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);
fGroupByCols.push_back(srcp); fGroupByCols.push_back(srcp);
@ -516,14 +574,18 @@ void CalpontSelectExecutionPlan::unserialize(messageqcpp::ByteStream& b)
fHaving = ObjectReader::createParseTree(b); fHaving = ObjectReader::createParseTree(b);
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);
fOrderByCols.push_back(srcp); fOrderByCols.push_back(srcp);
} }
b >> size; b >> size;
for (i = 0; i < size; i++) {
for (i = 0; i < size; i++)
{
b >> colName; b >> colName;
rc = dynamic_cast<ReturnedColumn*>(ObjectReader::createTreeNode(b)); rc = dynamic_cast<ReturnedColumn*>(ObjectReader::createTreeNode(b));
SRCP srcp(rc); SRCP srcp(rc);
@ -534,7 +596,9 @@ void CalpontSelectExecutionPlan::unserialize(messageqcpp::ByteStream& b)
messageqcpp::ByteStream::doublebyte id; messageqcpp::ByteStream::doublebyte id;
messageqcpp::ByteStream::quadbyte sessionId; messageqcpp::ByteStream::quadbyte sessionId;
messageqcpp::ByteStream::octbyte memory; messageqcpp::ByteStream::octbyte memory;
for (i = 0; i < size; i++) {
for (i = 0; i < size; i++)
{
b >> sessionId; b >> sessionId;
b >> id; b >> id;
b >> memory; b >> memory;
@ -560,15 +624,18 @@ void CalpontSelectExecutionPlan::unserialize(messageqcpp::ByteStream& b)
// for union // for union
b >> (uint8_t&)(fDistinctUnionNum); b >> (uint8_t&)(fDistinctUnionNum);
b >> size; b >> size;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
cep = ObjectReader::createExecutionPlan(b); cep = ObjectReader::createExecutionPlan(b);
fUnionVec.push_back(SCEP(cep)); fUnionVec.push_back(SCEP(cep));
} }
b >> (uint64_t&)fSubType; b >> (uint64_t&)fSubType;
// for FROM subquery // for FROM subquery
b >> size; b >> size;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
cep = ObjectReader::createExecutionPlan(b); cep = ObjectReader::createExecutionPlan(b);
@ -581,6 +648,7 @@ void CalpontSelectExecutionPlan::unserialize(messageqcpp::ByteStream& b)
// for SELECT subquery // for SELECT subquery
b >> size; b >> size;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
cep = ObjectReader::createExecutionPlan(b); cep = ObjectReader::createExecutionPlan(b);
@ -617,13 +685,15 @@ bool CalpontSelectExecutionPlan::operator==(const CalpontSelectExecutionPlan& t)
//fReturnedCols //fReturnedCols
if (fReturnedCols.size() != t.fReturnedCols.size()) if (fReturnedCols.size() != t.fReturnedCols.size())
return false; return false;
for (rcit = fReturnedCols.begin(), rcit2 = t.fReturnedCols.begin(); for (rcit = fReturnedCols.begin(), rcit2 = t.fReturnedCols.begin();
rcit != fReturnedCols.end(); ++rcit, ++rcit2) rcit != fReturnedCols.end(); ++rcit, ++rcit2)
if (**rcit != **rcit2) if (**rcit != **rcit2)
return false; return false;
//fFilters //fFilters
if (fFilters != NULL && t.fFilters != NULL) { if (fFilters != NULL && t.fFilters != NULL)
{
if (*fFilters != *t.fFilters) if (*fFilters != *t.fFilters)
return false; return false;
} }
@ -633,6 +703,7 @@ bool CalpontSelectExecutionPlan::operator==(const CalpontSelectExecutionPlan& t)
//fSubSelects //fSubSelects
if (fSubSelects.size() != t.fSubSelects.size()) if (fSubSelects.size() != t.fSubSelects.size())
return false; return false;
for (sit = fSubSelects.begin(), sit2 = t.fSubSelects.begin(); for (sit = fSubSelects.begin(), sit2 = t.fSubSelects.begin();
sit != fSubSelects.end(); ++sit, ++sit2) sit != fSubSelects.end(); ++sit, ++sit2)
if (*((*sit).get()) != (*sit2).get()) if (*((*sit).get()) != (*sit2).get())
@ -641,13 +712,15 @@ bool CalpontSelectExecutionPlan::operator==(const CalpontSelectExecutionPlan& t)
//fGroupByCols //fGroupByCols
if (fGroupByCols.size() != t.fGroupByCols.size()) if (fGroupByCols.size() != t.fGroupByCols.size())
return false; return false;
for (rcit = fGroupByCols.begin(), rcit2 = t.fGroupByCols.begin(); for (rcit = fGroupByCols.begin(), rcit2 = t.fGroupByCols.begin();
rcit != fGroupByCols.end(); ++rcit, ++rcit2) rcit != fGroupByCols.end(); ++rcit, ++rcit2)
if (**rcit != **rcit2) if (**rcit != **rcit2)
return false; return false;
//fHaving //fHaving
if (fHaving != NULL && t.fHaving != NULL) { if (fHaving != NULL && t.fHaving != NULL)
{
if (*fHaving != *t.fHaving) if (*fHaving != *t.fHaving)
return false; return false;
} }
@ -657,6 +730,7 @@ bool CalpontSelectExecutionPlan::operator==(const CalpontSelectExecutionPlan& t)
//fOrderByCols //fOrderByCols
if (fOrderByCols.size() != t.fOrderByCols.size()) if (fOrderByCols.size() != t.fOrderByCols.size())
return false; return false;
for (rcit = fOrderByCols.begin(), rcit2 = t.fOrderByCols.begin(); for (rcit = fOrderByCols.begin(), rcit2 = t.fOrderByCols.begin();
rcit != fOrderByCols.end(); ++rcit, ++rcit2) rcit != fOrderByCols.end(); ++rcit, ++rcit2)
if (**rcit != **rcit2) if (**rcit != **rcit2)
@ -665,6 +739,7 @@ bool CalpontSelectExecutionPlan::operator==(const CalpontSelectExecutionPlan& t)
//fColumnMap //fColumnMap
if (fColumnMap.size() != t.fColumnMap.size()) if (fColumnMap.size() != t.fColumnMap.size())
return false; return false;
for (map_it = fColumnMap.begin(), map_it2 = t.fColumnMap.begin(); for (map_it = fColumnMap.begin(), map_it2 = t.fColumnMap.begin();
map_it != fColumnMap.end(); ++map_it, ++map_it2) map_it != fColumnMap.end(); ++map_it, ++map_it2)
if (*(map_it->second) != *(map_it2->second)) if (*(map_it->second) != *(map_it2->second))
@ -672,26 +747,36 @@ bool CalpontSelectExecutionPlan::operator==(const CalpontSelectExecutionPlan& t)
if (fTableAlias != t.fTableAlias) if (fTableAlias != t.fTableAlias)
return false; return false;
if (fLocation != t.fLocation) if (fLocation != t.fLocation)
return false; return false;
if (fDependent != t.fDependent) if (fDependent != t.fDependent)
return false; return false;
// Trace flags don't affect equivalency? // Trace flags don't affect equivalency?
//if (fTraceFlags != t.fTraceFlags) return false; //if (fTraceFlags != t.fTraceFlags) return false;
if (fStatementID != t.fStatementID) if (fStatementID != t.fStatementID)
return false; return false;
if (fSubType != t.fSubType) if (fSubType != t.fSubType)
return false; return false;
if (fPriority != t.fPriority) if (fPriority != t.fPriority)
return false; return false;
if (fStringTableThreshold != t.fStringTableThreshold) if (fStringTableThreshold != t.fStringTableThreshold)
return false; return false;
if (fDJSSmallSideLimit != t.fDJSSmallSideLimit) if (fDJSSmallSideLimit != t.fDJSSmallSideLimit)
return false; return false;
if (fDJSLargeSideLimit != t.fDJSLargeSideLimit) if (fDJSLargeSideLimit != t.fDJSLargeSideLimit)
return false; return false;
if (fDJSPartitionSize != t.fDJSPartitionSize) if (fDJSPartitionSize != t.fDJSPartitionSize)
return false; return false;
if (fUMMemLimit != t.fUMMemLimit) if (fUMMemLimit != t.fUMMemLimit)
return false; return false;
@ -703,8 +788,10 @@ bool CalpontSelectExecutionPlan::operator==(const CalpontExecutionPlan* t) const
const CalpontSelectExecutionPlan* ac; const CalpontSelectExecutionPlan* ac;
ac = dynamic_cast<const CalpontSelectExecutionPlan*>(t); ac = dynamic_cast<const CalpontSelectExecutionPlan*>(t);
if (ac == NULL) if (ac == NULL)
return false; return false;
return *this == *ac; return *this == *ac;
} }
@ -724,6 +811,7 @@ void CalpontSelectExecutionPlan::columnMap (const ColumnMap& columnMap)
fColumnMap.erase(fColumnMap.begin(), fColumnMap.end()); fColumnMap.erase(fColumnMap.begin(), fColumnMap.end());
SRCP srcp; SRCP srcp;
for (map_it2 = columnMap.begin(); map_it2 != columnMap.end(); ++map_it2) for (map_it2 = columnMap.begin(); map_it2 != columnMap.end(); ++map_it2)
{ {
srcp.reset(map_it2->second->clone()); srcp.reset(map_it2->second->clone());

View File

@ -47,7 +47,8 @@
/** /**
* Namespace * Namespace
*/ */
namespace execplan { namespace execplan
{
enum RM_PARMS enum RM_PARMS
{ {
@ -72,7 +73,8 @@ typedef boost::shared_ptr<CalpontSelectExecutionPlan> SCSEP;
* This class is a concrete implementation of a CalpontExecutionPlan * This class is a concrete implementation of a CalpontExecutionPlan
* specifically describing a SQL select activity. * specifically describing a SQL select activity.
*/ */
class CalpontSelectExecutionPlan : public CalpontExecutionPlan { class CalpontSelectExecutionPlan : public CalpontExecutionPlan
{
/** /**
* Public stuff * Public stuff
@ -191,23 +193,46 @@ public:
/** /**
* returned column list * returned column list
*/ */
const ReturnedColumnList& returnedCols() const { return fReturnedCols; } const ReturnedColumnList& returnedCols() const
ReturnedColumnList& returnedCols() { return fReturnedCols; } {
return fReturnedCols;
}
ReturnedColumnList& returnedCols()
{
return fReturnedCols;
}
void returnedCols (const ReturnedColumnList& returnedCols) void returnedCols (const ReturnedColumnList& returnedCols)
{ fReturnedCols = returnedCols; } {
fReturnedCols = returnedCols;
}
/** /**
* Are we in local PM only query mode? * Are we in local PM only query mode?
*/ */
const uint32_t localQuery() const { return fLocalQuery; } const uint32_t localQuery() const
void localQuery (const uint32_t localQuery) { fLocalQuery = localQuery; } {
return fLocalQuery;
}
void localQuery (const uint32_t localQuery)
{
fLocalQuery = localQuery;
}
/** /**
* filters parse tree * filters parse tree
*/ */
const ParseTree* filters() const { return fFilters; } const ParseTree* filters() const
ParseTree* filters() { return fFilters; } {
void filters (ParseTree* filters) { fFilters = filters; } return fFilters;
}
ParseTree* filters()
{
return fFilters;
}
void filters (ParseTree* filters)
{
fFilters = filters;
}
/** filter token list /** filter token list
* Set filter list field and build filters tree from the filter list * Set filter list field and build filters tree from the filter list
@ -220,186 +245,445 @@ public:
/** /**
* sub select list * sub select list
*/ */
const SelectList& subSelects() const { return fSubSelects; } const SelectList& subSelects() const
void subSelects (const SelectList& subSelects){ fSubSelects = subSelects; } {
return fSubSelects;
}
void subSelects (const SelectList& subSelects)
{
fSubSelects = subSelects;
}
/** /**
* group by column list * group by column list
*/ */
const GroupByColumnList& groupByCols() const { return fGroupByCols; } const GroupByColumnList& groupByCols() const
GroupByColumnList& groupByCols() { return fGroupByCols; } {
return fGroupByCols;
}
GroupByColumnList& groupByCols()
{
return fGroupByCols;
}
void groupByCols( const GroupByColumnList& groupByCols) void groupByCols( const GroupByColumnList& groupByCols)
{ fGroupByCols = groupByCols; } {
fGroupByCols = groupByCols;
}
/** /**
* order by column list * order by column list
*/ */
const OrderByColumnList& orderByCols() const { return fOrderByCols; } const OrderByColumnList& orderByCols() const
OrderByColumnList& orderByCols() { return fOrderByCols; } {
return fOrderByCols;
}
OrderByColumnList& orderByCols()
{
return fOrderByCols;
}
void orderByCols( const OrderByColumnList& orderByCols) void orderByCols( const OrderByColumnList& orderByCols)
{ fOrderByCols = orderByCols; } {
fOrderByCols = orderByCols;
}
/** /**
* table alias * table alias
*/ */
const std::string& tableAlias() const { return fTableAlias; } const std::string& tableAlias() const
void tableAlias (const std::string& tableAlias) { fTableAlias = tableAlias; } {
return fTableAlias;
}
void tableAlias (const std::string& tableAlias)
{
fTableAlias = tableAlias;
}
/** /**
* location of this select * location of this select
*/ */
const int location () const { return fLocation; } const int location () const
void location (const int location) { fLocation = location; } {
return fLocation;
}
void location (const int location)
{
fLocation = location;
}
/** /**
* dependence of this select * dependence of this select
*/ */
const bool dependent() const { return fDependent; } const bool dependent() const
void dependent (const bool dependent) { fDependent = dependent; } {
return fDependent;
}
void dependent (const bool dependent)
{
fDependent = dependent;
}
/** /**
* having filter parse tree * having filter parse tree
*/ */
inline const ParseTree* having() const { return fHaving; } inline const ParseTree* having() const
inline ParseTree* having() { return fHaving; } {
inline void having (ParseTree* having) { fHaving = having; } return fHaving;
}
inline ParseTree* having()
{
return fHaving;
}
inline void having (ParseTree* having)
{
fHaving = having;
}
/** having filter token list /** having filter token list
* Set filter list field and build filters tree from the filter list * Set filter list field and build filters tree from the filter list
* This is an alternative way to build filter tree. Hide the parser * This is an alternative way to build filter tree. Hide the parser
* from the user * from the user
*/ */
const FilterTokenList& havingTokenList() const { return fHavingTokenList; } const FilterTokenList& havingTokenList() const
{
return fHavingTokenList;
}
void havingTokenList (const FilterTokenList& havingTokenList); void havingTokenList (const FilterTokenList& havingTokenList);
/** column map /** column map
* all the columns appeared on query * all the columns appeared on query
*/ */
const ColumnMap& columnMap() const {return fColumnMap;} const ColumnMap& columnMap() const
{
return fColumnMap;
}
/** assign the static fColMap to non-static fColumnMap. map-wise copy */ /** assign the static fColMap to non-static fColumnMap. map-wise copy */
void columnMap (const ColumnMap& columnMap); void columnMap (const ColumnMap& columnMap);
/** assign a regular map object to non-static fColumnMap. pure assignment */ /** assign a regular map object to non-static fColumnMap. pure assignment */
// @note this is to fix memory leak in CSC, becasue no static map is needed there. // @note this is to fix memory leak in CSC, becasue no static map is needed there.
inline void columnMapNonStatic (const ColumnMap& columnMap) {fColumnMap = columnMap;} inline void columnMapNonStatic (const ColumnMap& columnMap)
{
fColumnMap = columnMap;
}
/** sql representation of this select query /** sql representation of this select query
* *
*/ */
const std::string data() const { return fData; } const std::string data() const
void data ( const std::string data ) { fData = data; } {
return fData;
}
void data ( const std::string data )
{
fData = data;
}
/** session id /** session id
* *
*/ */
const uint32_t sessionID() const { return fSessionID; } const uint32_t sessionID() const
void sessionID ( const uint32_t sessionID ) { fSessionID = sessionID; } {
return fSessionID;
}
void sessionID ( const uint32_t sessionID )
{
fSessionID = sessionID;
}
/** transaction id /** transaction id
* *
*/ */
const int txnID() const { return fTxnID; } const int txnID() const
void txnID ( const int txnID ) { fTxnID = txnID; } {
return fTxnID;
}
void txnID ( const int txnID )
{
fTxnID = txnID;
}
/** version id /** version id
* *
*/ */
const BRM::QueryContext verID() const { return fVerID; } const BRM::QueryContext verID() const
void verID ( const BRM::QueryContext verID ) { fVerID = verID; } {
return fVerID;
}
void verID ( const BRM::QueryContext verID )
{
fVerID = verID;
}
inline static ColumnMap& colMap() {return fColMap;} inline static ColumnMap& colMap()
{
return fColMap;
}
inline std::string& schemaName() { return fSchemaName; } inline std::string& schemaName()
inline void schemaName(const std::string& schemaName) { fSchemaName = schemaName; } {
return fSchemaName;
}
inline void schemaName(const std::string& schemaName)
{
fSchemaName = schemaName;
}
inline std::string& tableName() { return fTableName; } inline std::string& tableName()
inline void tableName(const std::string& tableName) { fTableName = tableName; } {
return fTableName;
}
inline void tableName(const std::string& tableName)
{
fTableName = tableName;
}
inline void traceOn(bool traceOn) __attribute__((deprecated)) inline void traceOn(bool traceOn) __attribute__((deprecated))
{ if (traceOn) fTraceFlags |= TRACE_LOG; else fTraceFlags &= ~TRACE_LOG; } {
inline bool traceOn() const { return (traceFlags() & TRACE_LOG); } if (traceOn) fTraceFlags |= TRACE_LOG;
else fTraceFlags &= ~TRACE_LOG;
}
inline bool traceOn() const
{
return (traceFlags() & TRACE_LOG);
}
inline uint32_t traceFlags() const { return fTraceFlags; } inline uint32_t traceFlags() const
inline void traceFlags(uint32_t traceFlags) { fTraceFlags = traceFlags; } {
return fTraceFlags;
}
inline void traceFlags(uint32_t traceFlags)
{
fTraceFlags = traceFlags;
}
const uint32_t statementID() const { return fStatementID; } const uint32_t statementID() const
void statementID (const uint32_t statementID) {fStatementID = statementID;} {
return fStatementID;
}
void statementID (const uint32_t statementID)
{
fStatementID = statementID;
}
const RMParmVec& rmParms() { return frmParms; } const RMParmVec& rmParms()
{
return frmParms;
}
void rmParms (const RMParmVec& parms); void rmParms (const RMParmVec& parms);
const TableList& tableList() const { return fTableList; } const TableList& tableList() const
void tableList (const TableList& tableList) { fTableList = tableList; } {
return fTableList;
}
void tableList (const TableList& tableList)
{
fTableList = tableList;
}
const SelectList& derivedTableList() const { return fDerivedTableList; } const SelectList& derivedTableList() const
void derivedTableList(SelectList& derivedTableList) { fDerivedTableList = derivedTableList; } {
return fDerivedTableList;
}
void derivedTableList(SelectList& derivedTableList)
{
fDerivedTableList = derivedTableList;
}
const bool distinct() const {return fDistinct;} const bool distinct() const
void distinct(const bool distinct) {fDistinct = distinct;} {
return fDistinct;
}
void distinct(const bool distinct)
{
fDistinct = distinct;
}
void overrideLargeSideEstimate (const bool over) {fOverrideLargeSideEstimate = over;} void overrideLargeSideEstimate (const bool over)
const bool overrideLargeSideEstimate() const { return fOverrideLargeSideEstimate; } {
fOverrideLargeSideEstimate = over;
}
const bool overrideLargeSideEstimate() const
{
return fOverrideLargeSideEstimate;
}
void unionVec(const SelectList& unionVec) { fUnionVec = unionVec; } void unionVec(const SelectList& unionVec)
const SelectList& unionVec() const { return fUnionVec; } {
SelectList& unionVec() { return fUnionVec; } fUnionVec = unionVec;
}
const SelectList& unionVec() const
{
return fUnionVec;
}
SelectList& unionVec()
{
return fUnionVec;
}
void distinctUnionNum(const uint8_t distinctUnionNum) { fDistinctUnionNum = distinctUnionNum; } void distinctUnionNum(const uint8_t distinctUnionNum)
const uint8_t distinctUnionNum() const { return fDistinctUnionNum; } {
fDistinctUnionNum = distinctUnionNum;
}
const uint8_t distinctUnionNum() const
{
return fDistinctUnionNum;
}
void subType(const uint64_t subType) { fSubType = subType; } void subType(const uint64_t subType)
const uint64_t subType() const { return fSubType; } {
fSubType = subType;
}
const uint64_t subType() const
{
return fSubType;
}
void derivedTbAlias(const std::string derivedTbAlias) { fDerivedTbAlias = derivedTbAlias; } void derivedTbAlias(const std::string derivedTbAlias)
const std::string derivedTbAlias() const { return fDerivedTbAlias; } {
fDerivedTbAlias = derivedTbAlias;
}
const std::string derivedTbAlias() const
{
return fDerivedTbAlias;
}
void limitStart(const uint64_t limitStart) { fLimitStart = limitStart; } void limitStart(const uint64_t limitStart)
const uint64_t limitStart() const { return fLimitStart; } {
fLimitStart = limitStart;
}
const uint64_t limitStart() const
{
return fLimitStart;
}
void limitNum(const uint64_t limitNum) { fLimitNum = limitNum; } void limitNum(const uint64_t limitNum)
const uint64_t limitNum() const { return fLimitNum; } {
fLimitNum = limitNum;
}
const uint64_t limitNum() const
{
return fLimitNum;
}
void hasOrderBy(const bool hasOrderBy) { fHasOrderBy = hasOrderBy; } void hasOrderBy(const bool hasOrderBy)
const bool hasOrderBy() const { return fHasOrderBy; } {
fHasOrderBy = hasOrderBy;
}
const bool hasOrderBy() const
{
return fHasOrderBy;
}
void selectSubList(const SelectList& selectSubList) { fSelectSubList = selectSubList; } void selectSubList(const SelectList& selectSubList)
const SelectList& selectSubList() const { return fSelectSubList; } {
fSelectSubList = selectSubList;
}
const SelectList& selectSubList() const
{
return fSelectSubList;
}
void subSelectList(const std::vector<execplan::SCSEP>& subSelectList) { fSubSelectList = subSelectList; } void subSelectList(const std::vector<execplan::SCSEP>& subSelectList)
const std::vector<execplan::SCSEP>& subSelectList() const { return fSubSelectList; } {
fSubSelectList = subSelectList;
}
const std::vector<execplan::SCSEP>& subSelectList() const
{
return fSubSelectList;
}
void stringScanThreshold(uint64_t n) { fStringScanThreshold = n; } void stringScanThreshold(uint64_t n)
uint64_t stringScanThreshold() const { return fStringScanThreshold; } {
fStringScanThreshold = n;
}
uint64_t stringScanThreshold() const
{
return fStringScanThreshold;
}
// query type. return string for easy stats insert // query type. return string for easy stats insert
void queryType(const uint32_t queryType) { fQueryType = queryType; } void queryType(const uint32_t queryType)
const std::string queryType() const { return queryTypeToString(fQueryType); } {
fQueryType = queryType;
}
const std::string queryType() const
{
return queryTypeToString(fQueryType);
}
static std::string queryTypeToString(const uint32_t queryType); static std::string queryTypeToString(const uint32_t queryType);
void priority(uint32_t p) { fPriority = p; } void priority(uint32_t p)
uint32_t priority() const { return fPriority; } {
fPriority = p;
}
uint32_t priority() const
{
return fPriority;
}
void stringTableThreshold(uint32_t t) { fStringTableThreshold = t; } void stringTableThreshold(uint32_t t)
uint32_t stringTableThreshold() const { return fStringTableThreshold; } {
fStringTableThreshold = t;
}
uint32_t stringTableThreshold() const
{
return fStringTableThreshold;
}
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;
}
void djsSmallSideLimit(uint64_t l) { fDJSSmallSideLimit = l; } void djsSmallSideLimit(uint64_t l)
uint64_t djsSmallSideLimit() { return fDJSSmallSideLimit; } {
fDJSSmallSideLimit = l;
}
uint64_t djsSmallSideLimit()
{
return fDJSSmallSideLimit;
}
void djsLargeSideLimit(uint64_t l) { fDJSLargeSideLimit = l; } void djsLargeSideLimit(uint64_t l)
uint64_t djsLargeSideLimit() { return fDJSLargeSideLimit; } {
fDJSLargeSideLimit = l;
}
uint64_t djsLargeSideLimit()
{
return fDJSLargeSideLimit;
}
void djsPartitionSize(uint64_t l) { fDJSPartitionSize = l; } void djsPartitionSize(uint64_t l)
uint64_t djsPartitionSize() { return fDJSPartitionSize; } {
fDJSPartitionSize = l;
}
uint64_t djsPartitionSize()
{
return fDJSPartitionSize;
}
void umMemLimit(uint64_t l) { fUMMemLimit = l; } void umMemLimit(uint64_t l)
int64_t umMemLimit() { return fUMMemLimit; } {
fUMMemLimit = l;
}
int64_t umMemLimit()
{
return fUMMemLimit;
}
void isDML(bool b) { fIsDML = b; } void isDML(bool b)
bool isDML() { return fIsDML; } {
fIsDML = b;
}
bool isDML()
{
return fIsDML;
}
/** /**
* The serialization interface * The serialization interface
@ -451,7 +735,10 @@ public:
* FIXME: add a setter and make this work for really big session ids * FIXME: add a setter and make this work for really big session ids
* @return true/false * @return true/false
*/ */
virtual bool isInternal() const { return ((fSessionID & 0x80000000) != 0); } virtual bool isInternal() const
{
return ((fSessionID & 0x80000000) != 0);
}
/** /**
* Protected stuff * Protected stuff
@ -603,7 +890,10 @@ private:
*/ */
inline std::ostream& operator<<(std::ostream& os, const CalpontSelectExecutionPlan& rhs) inline std::ostream& operator<<(std::ostream& os, const CalpontSelectExecutionPlan& rhs)
{ os << rhs.toString(); return os; } {
os << rhs.toString();
return os;
}
} }
#endif //CALPONTSELECTEXECUTIONPLAN_H #endif //CALPONTSELECTEXECUTIONPLAN_H

411
dbcon/execplan/calpontsystemcatalog.cpp Executable file → Normal file

File diff suppressed because it is too large Load Diff

128
dbcon/execplan/calpontsystemcatalog.h Executable file → Normal file
View File

@ -207,12 +207,16 @@ public:
{ {
if (dictOID != t.dictOID) if (dictOID != t.dictOID)
return false; return false;
if (listOID != t.listOID) if (listOID != t.listOID)
return false; return false;
if (treeOID != t.treeOID) if (treeOID != t.treeOID)
return false; return false;
if (compressionType != t.compressionType) if (compressionType != t.compressionType)
return false; return false;
return true; return true;
} }
bool operator!=(const DictOID& t) const bool operator!=(const DictOID& t) const
@ -231,15 +235,28 @@ public:
NJLSysDataVector sysDataVec; NJLSysDataVector sysDataVec;
NJLSysDataList() {}; NJLSysDataList() {};
~NJLSysDataList(); ~NJLSysDataList();
NJLSysDataVector::const_iterator begin() const {return sysDataVec.begin();} NJLSysDataVector::const_iterator begin() const
NJLSysDataVector::const_iterator end() const {return sysDataVec.end();} {
void push_back(ColumnResult* cr) {sysDataVec.push_back(cr);} return sysDataVec.begin();
NJLSysDataVector::size_type size() const {return sysDataVec.size();} }
NJLSysDataVector::const_iterator end() const
{
return sysDataVec.end();
}
void push_back(ColumnResult* cr)
{
sysDataVec.push_back(cr);
}
NJLSysDataVector::size_type size() const
{
return sysDataVec.size();
}
NJLSysDataVector::size_type findColumn(const OID& columnOID) const NJLSysDataVector::size_type findColumn(const OID& columnOID) const
{ {
for (NJLSysDataVector::size_type i = 0; i < sysDataVec.size(); i++) for (NJLSysDataVector::size_type i = 0; i < sysDataVec.size(); i++)
if (sysDataVec[i]->ColumnOID() == columnOID) if (sysDataVec[i]->ColumnOID() == columnOID)
return i; return i;
return -1; return -1;
} }
}; };
@ -314,18 +331,25 @@ public:
//order these with the most likely first //order these with the most likely first
if (columnOID != t.columnOID) if (columnOID != t.columnOID)
return false; return false;
if (colPosition != t.colPosition) if (colPosition != t.colPosition)
return false; return false;
if (ddn != t.ddn) if (ddn != t.ddn)
return false; return false;
if (colWidth != t.colWidth) if (colWidth != t.colWidth)
return false; return false;
if (scale != t.scale) if (scale != t.scale)
return false; return false;
if (precision != t.precision) if (precision != t.precision)
return false; return false;
if (constraintType != t.constraintType) if (constraintType != t.constraintType)
return false; return false;
return true; return true;
} }
@ -409,14 +433,22 @@ public:
bool fIsInfiniDB; bool fIsInfiniDB;
void clear(); void clear();
bool operator<(const TableAliasName& rhs) const; bool operator<(const TableAliasName& rhs) const;
bool operator>=(const TableAliasName& rhs) const { return !(*this < rhs); } bool operator>=(const TableAliasName& rhs) const
{
return !(*this < rhs);
}
bool operator==(const TableAliasName& rhs) const bool operator==(const TableAliasName& rhs) const
{ return (schema == rhs.schema && {
return (schema == rhs.schema &&
table == rhs.table && table == rhs.table &&
alias == rhs.alias && alias == rhs.alias &&
view == rhs.view && view == rhs.view &&
fIsInfiniDB == rhs.fIsInfiniDB); } fIsInfiniDB == rhs.fIsInfiniDB);
bool operator!=(const TableAliasName& rhs) const { return !(*this == rhs); } }
bool operator!=(const TableAliasName& rhs) const
{
return !(*this == rhs);
}
void serialize(messageqcpp::ByteStream&) const; void serialize(messageqcpp::ByteStream&) const;
void unserialize(messageqcpp::ByteStream&); void unserialize(messageqcpp::ByteStream&);
friend std::ostream& operator<<(std::ostream& os, const TableAliasName& rhs); friend std::ostream& operator<<(std::ostream& os, const TableAliasName& rhs);
@ -435,13 +467,24 @@ public:
std::string table; std::string table;
int64_t create_date; int64_t create_date;
bool operator<(const TableName& rhs) const; bool operator<(const TableName& rhs) const;
bool operator>=(const TableName& rhs) const { return !(*this < rhs); } bool operator>=(const TableName& rhs) const
{
return !(*this < rhs);
}
bool operator==(const TableName& rhs) const bool operator==(const TableName& rhs) const
{ return (schema == rhs.schema && table == rhs.table); } {
bool operator!=(const TableName& rhs) const { return !(*this == rhs); } return (schema == rhs.schema && table == rhs.table);
}
bool operator!=(const TableName& rhs) const
{
return !(*this == rhs);
}
const std::string toString() const; const std::string toString() const;
friend std::ostream& operator<<(std::ostream& os, const TableName& rhs) friend std::ostream& operator<<(std::ostream& os, const TableName& rhs)
{ os << rhs.toString(); return os; } {
os << rhs.toString();
return os;
}
}; };
/** the structure passed into get RID for Index values /** the structure passed into get RID for Index values
@ -766,13 +809,25 @@ public:
/** sessionid access and mutator methods /** sessionid access and mutator methods
* *
*/ */
const uint32_t sessionID() const { return fSessionID; } const uint32_t sessionID() const
void sessionID (uint32_t sessionID) { fSessionID = sessionID; } {
return fSessionID;
}
void sessionID (uint32_t sessionID)
{
fSessionID = sessionID;
}
/** identity access and mutator methods /** identity access and mutator methods
* *
*/ */
const int identity() const { return fIdentity; } const int identity() const
void identity (int identity) { fIdentity = identity; } {
return fIdentity;
}
void identity (int identity)
{
fIdentity = identity;
}
/** return the column position /** return the column position
* *
@ -937,6 +992,7 @@ inline bool isNumeric(const execplan::CalpontSystemCatalog::ColDataType type)
case execplan::CalpontSystemCatalog::UDOUBLE: case execplan::CalpontSystemCatalog::UDOUBLE:
case execplan::CalpontSystemCatalog::UDECIMAL: case execplan::CalpontSystemCatalog::UDECIMAL:
return true; return true;
default: default:
return false; return false;
} }
@ -952,6 +1008,7 @@ inline bool isUnsigned(const execplan::CalpontSystemCatalog::ColDataType type)
case execplan::CalpontSystemCatalog::UINT: case execplan::CalpontSystemCatalog::UINT:
case execplan::CalpontSystemCatalog::UBIGINT: case execplan::CalpontSystemCatalog::UBIGINT:
return true; return true;
default: default:
return false; return false;
} }
@ -967,6 +1024,7 @@ inline bool isSignedInteger(const execplan::CalpontSystemCatalog::ColDataType ty
case execplan::CalpontSystemCatalog::INT: case execplan::CalpontSystemCatalog::INT:
case execplan::CalpontSystemCatalog::BIGINT: case execplan::CalpontSystemCatalog::BIGINT:
return true; return true;
default: default:
return false; return false;
} }
@ -981,11 +1039,14 @@ inline bool isNull(int64_t val, const execplan::CalpontSystemCatalog::ColType& c
case execplan::CalpontSystemCatalog::TINYINT: case execplan::CalpontSystemCatalog::TINYINT:
{ {
if ((int8_t) joblist::TINYINTNULL == val) ret = true; if ((int8_t) joblist::TINYINTNULL == val) ret = true;
break; break;
} }
case execplan::CalpontSystemCatalog::CHAR: case execplan::CalpontSystemCatalog::CHAR:
{ {
int colWidth = ct.colWidth; int colWidth = ct.colWidth;
if (colWidth <= 8) if (colWidth <= 8)
{ {
if ((colWidth == 1) && ((int8_t) joblist::CHAR1NULL == val)) ret = true ; if ((colWidth == 1) && ((int8_t) joblist::CHAR1NULL == val)) ret = true ;
@ -997,13 +1058,17 @@ inline bool isNull(int64_t val, const execplan::CalpontSystemCatalog::ColType& c
{ {
throw std::logic_error("Not a int column."); throw std::logic_error("Not a int column.");
} }
break; break;
} }
case execplan::CalpontSystemCatalog::SMALLINT: case execplan::CalpontSystemCatalog::SMALLINT:
{ {
if ((int16_t) joblist::SMALLINTNULL == val) ret = true; if ((int16_t) joblist::SMALLINTNULL == val) ret = true;
break; break;
} }
case execplan::CalpontSystemCatalog::DECIMAL: case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL: case execplan::CalpontSystemCatalog::UDECIMAL:
{ {
@ -1012,61 +1077,82 @@ inline bool isNull(int64_t val, const execplan::CalpontSystemCatalog::ColType& c
case 1: case 1:
{ {
if ((int8_t)joblist::TINYINTNULL == val) ret = true; if ((int8_t)joblist::TINYINTNULL == val) ret = true;
break; break;
} }
case 2: case 2:
{ {
if ((int16_t)joblist::SMALLINTNULL == val) ret = true; if ((int16_t)joblist::SMALLINTNULL == val) ret = true;
break; break;
} }
case 4: case 4:
{ {
if ((int32_t)joblist::INTNULL == val) ret = true; if ((int32_t)joblist::INTNULL == val) ret = true;
break; break;
} }
default: default:
{ {
if ((int64_t)joblist::BIGINTNULL == val) ret = true; if ((int64_t)joblist::BIGINTNULL == val) ret = true;
break; break;
} }
} }
} }
case execplan::CalpontSystemCatalog::DOUBLE: case execplan::CalpontSystemCatalog::DOUBLE:
case execplan::CalpontSystemCatalog::UDOUBLE: case execplan::CalpontSystemCatalog::UDOUBLE:
{ {
if ((int64_t)joblist::DOUBLENULL == val) ret = true; if ((int64_t)joblist::DOUBLENULL == val) ret = true;
break; break;
} }
case execplan::CalpontSystemCatalog::MEDINT: case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::INT: case execplan::CalpontSystemCatalog::INT:
{ {
if ((int32_t)joblist::INTNULL == val) ret = true; if ((int32_t)joblist::INTNULL == val) ret = true;
break; break;
} }
case execplan::CalpontSystemCatalog::FLOAT: case execplan::CalpontSystemCatalog::FLOAT:
case execplan::CalpontSystemCatalog::UFLOAT: case execplan::CalpontSystemCatalog::UFLOAT:
{ {
if ((int32_t)joblist::FLOATNULL == val) ret = true; if ((int32_t)joblist::FLOATNULL == val) ret = true;
break; break;
} }
case execplan::CalpontSystemCatalog::DATE: case execplan::CalpontSystemCatalog::DATE:
{ {
if ((int32_t) joblist::DATENULL == val) ret = true; if ((int32_t) joblist::DATENULL == val) ret = true;
break; break;
} }
case execplan::CalpontSystemCatalog::BIGINT: case execplan::CalpontSystemCatalog::BIGINT:
{ {
if ((int64_t)joblist::BIGINTNULL == val) ret = true; if ((int64_t)joblist::BIGINTNULL == val) ret = true;
break; break;
} }
case execplan::CalpontSystemCatalog::DATETIME: case execplan::CalpontSystemCatalog::DATETIME:
{ {
if ((int64_t)joblist::DATETIMENULL == val) ret = true; if ((int64_t)joblist::DATETIMENULL == val) ret = true;
break; break;
} }
case execplan::CalpontSystemCatalog::VARCHAR: case execplan::CalpontSystemCatalog::VARCHAR:
{ {
int colWidth = ct.colWidth; int colWidth = ct.colWidth;
if (colWidth <= 8) if (colWidth <= 8)
{ {
if ((colWidth < 3) && ((int16_t) joblist::CHAR2NULL == val)) ret = true; if ((colWidth < 3) && ((int16_t) joblist::CHAR2NULL == val)) ret = true;
@ -1077,29 +1163,39 @@ inline bool isNull(int64_t val, const execplan::CalpontSystemCatalog::ColType& c
{ {
throw std::logic_error("Not a int column."); throw std::logic_error("Not a int column.");
} }
break; break;
} }
case execplan::CalpontSystemCatalog::UTINYINT: case execplan::CalpontSystemCatalog::UTINYINT:
{ {
if (joblist::UTINYINTNULL == (uint8_t)val) ret = true; if (joblist::UTINYINTNULL == (uint8_t)val) ret = true;
break; break;
} }
case execplan::CalpontSystemCatalog::USMALLINT: case execplan::CalpontSystemCatalog::USMALLINT:
{ {
if (joblist::USMALLINTNULL == (uint16_t)val) ret = true; if (joblist::USMALLINTNULL == (uint16_t)val) ret = true;
break; break;
} }
case execplan::CalpontSystemCatalog::UMEDINT: case execplan::CalpontSystemCatalog::UMEDINT:
case execplan::CalpontSystemCatalog::UINT: case execplan::CalpontSystemCatalog::UINT:
{ {
if (joblist::UINTNULL == (uint32_t)val) ret = true; if (joblist::UINTNULL == (uint32_t)val) ret = true;
break; break;
} }
case execplan::CalpontSystemCatalog::UBIGINT: case execplan::CalpontSystemCatalog::UBIGINT:
{ {
if (joblist::UBIGINTNULL == (uint64_t)val) ret = true; if (joblist::UBIGINTNULL == (uint64_t)val) ret = true;
break; break;
} }
default: default:
break; break;
} }

View File

@ -66,6 +66,7 @@ string ClientRotator::getModule()
if (moduleFile.is_open()) if (moduleFile.is_open())
getline (moduleFile, module); getline (moduleFile, module);
moduleFile.close(); moduleFile.close();
return module; return module;
} }
@ -82,6 +83,7 @@ ClientRotator::ClientRotator(uint32_t sid, const std::string& name, bool localQu
{ {
if (! fCf) if (! fCf)
throw runtime_error((string)__FILE__ + ": No configuration file"); throw runtime_error((string)__FILE__ + ": No configuration file");
fDebug = static_cast<int>(Config::fromText(fCf->getConfig("CalpontConnector", "DebugLevel"))); fDebug = static_cast<int>(Config::fromText(fCf->getConfig("CalpontConnector", "DebugLevel")));
} }
@ -98,6 +100,7 @@ void ClientRotator::loadClients()
if (!fLocalQuery && pmWithUM) if (!fLocalQuery && pmWithUM)
{ {
string module = getModule(); string module = getModule();
if (!module.empty() && (module[0] == 'P' || module[0] == 'p')) if (!module.empty() && (module[0] == 'P' || module[0] == 'p'))
fLocalQuery = true; fLocalQuery = true;
} }
@ -113,20 +116,25 @@ void ClientRotator::loadClients()
size_t pos = fName.length(); size_t pos = fName.length();
string str; string str;
int i = 1; int i = 1;
do do
{ {
ss.seekp(pos); ss.seekp(pos);
ss << i++; ss << i++;
str = fCf->getConfig(ss.str(), "Port"); str = fCf->getConfig(ss.str(), "Port");
if (str.length() ) if (str.length() )
{ {
string moduleStr = fCf->getConfig(ss.str(), "Module"); string moduleStr = fCf->getConfig(ss.str(), "Module");
// "if the system is not running in a 'PM with UM' config, the module type is unspecified, or the // "if the system is not running in a 'PM with UM' config, the module type is unspecified, or the
// module is specified as a UM, use it" // module is specified as a UM, use it"
if (!pmWithUM || moduleStr.empty() || moduleStr[0] == 'u' || moduleStr[0] == 'U') if (!pmWithUM || moduleStr.empty() || moduleStr[0] == 'u' || moduleStr[0] == 'U')
fClients.push_back(ss.str()); fClients.push_back(ss.str());
} }
} while ( str.length() ); }
while ( str.length() );
if (fClients.empty()) if (fClients.empty())
throw runtime_error((string)__FILE__ + ": No configuration tags for " + fName + "\n"); throw runtime_error((string)__FILE__ + ": No configuration tags for " + fName + "\n");
} }
@ -155,6 +163,7 @@ void ClientRotator::write(const ByteStream& msg)
{ {
if (!fClient) if (!fClient)
connect(); connect();
try try
{ {
fClient->write(msg); fClient->write(msg);
@ -181,6 +190,7 @@ ByteStream ClientRotator::read()
mutex::scoped_lock lk(fClientLock); mutex::scoped_lock lk(fClientLock);
ByteStream bs; ByteStream bs;
if (!fClient) if (!fClient)
connect(); connect();
@ -205,6 +215,7 @@ ByteStream ClientRotator::read()
} }
#if 0 #if 0
try //one more time... try //one more time...
{ {
delete fClient; delete fClient;
@ -222,6 +233,7 @@ ByteStream ClientRotator::read()
#endif #endif
throw; throw;
} }
#endif #endif
return bs; return bs;
} }
@ -270,7 +282,8 @@ bool ClientRotator::exeConnect( const string& clientName )
writeToLog( __LINE__, "Connecting to " + clientName + " with sessionId " + ss.str(), 0); writeToLog( __LINE__, "Connecting to " + clientName + " with sessionId " + ss.str(), 0);
} }
try { try
{
if (!fClient->connect()) if (!fClient->connect())
{ {
delete fClient; delete fClient;
@ -278,11 +291,13 @@ bool ClientRotator::exeConnect( const string& clientName )
return false; return false;
} }
} }
catch(...) { catch (...)
{
delete fClient; delete fClient;
fClient = 0; fClient = 0;
return false; return false;
} }
return true; return true;
} }
@ -297,21 +312,26 @@ void ClientRotator::connectList(double timeout)
idbassert(!fClients.empty()); idbassert(!fClients.empty());
uint16_t idx = fSessionId % fClients.size(); uint16_t idx = fSessionId % fClients.size();
if (++idx >= fClients.size() ) if (++idx >= fClients.size() )
idx = 0; idx = 0;
timer runTime; timer runTime;
while ( runTime.elapsed() < timeout) while ( runTime.elapsed() < timeout)
{ {
try try
{ {
if (exeConnect(fClients.at(idx++))) if (exeConnect(fClients.at(idx++)))
return; return;
if (fClients.size() == idx) if (fClients.size() == idx)
idx = 0; idx = 0;
} }
catch (... ) catch (... )
{ } { }
} }
#ifdef LOG_TO_CERR #ifdef LOG_TO_CERR
cerr << "Could not get a " << fName << " connection.\n"; cerr << "Could not get a " << fName << " connection.\n";
#endif #endif
@ -330,6 +350,7 @@ void ClientRotator::writeToLog(int line, const string& msg, bool critical) const
args.add(line); args.add(line);
args.add(msg); args.add(msg);
m.format(args); m.format(args);
if (critical) if (critical)
ml.logCriticalMessage(m); ml.logCriticalMessage(m);
else if (fDebug) else if (fDebug)

View File

@ -91,23 +91,38 @@ public:
/** @brief getClient /** @brief getClient
*/ */
messageqcpp::MessageQueueClient* getClient() const { return fClient; } messageqcpp::MessageQueueClient* getClient() const
{
return fClient;
}
/** @brief getSessionId /** @brief getSessionId
*/ */
uint32_t getSessionId() const { return fSessionId; } uint32_t getSessionId() const
{
return fSessionId;
}
/** @brief setSessionId /** @brief setSessionId
*/ */
void setSessionId(uint32_t sid) { fSessionId = sid; } void setSessionId(uint32_t sid)
{
fSessionId = sid;
}
friend std::ostream& operator<<(std::ostream& output, const ClientRotator& rhs); friend std::ostream& operator<<(std::ostream& output, const ClientRotator& rhs);
/** @brief reset fClient */ /** @brief reset fClient */
void resetClient(); void resetClient();
bool localQuery() { return fLocalQuery; } bool localQuery()
void localQuery(bool localQuery) { fLocalQuery = localQuery; } {
return fLocalQuery;
}
void localQuery(bool localQuery)
{
fLocalQuery = localQuery;
}
static std::string getModule(); static std::string getModule();
private: private:

View File

@ -29,7 +29,8 @@
#include <string> #include <string>
#include <stdint.h> #include <stdint.h>
namespace execplan { namespace execplan
{
/** @file /** @file
This serves as a bridge between the new and old joblist code. This serves as a bridge between the new and old joblist code.
@ -47,34 +48,57 @@ public:
// the other defaults are OK. // the other defaults are OK.
int64_t GetData(uint32_t index) const int64_t GetData(uint32_t index) const
{ return intData[index]; } {
return intData[index];
}
void PutData(int64_t d) void PutData(int64_t d)
{ intData.push_back(d); dcount++; } {
intData.push_back(d);
dcount++;
}
const std::string& GetStringData(uint32_t index) const const std::string& GetStringData(uint32_t index) const
{ return stringData[index]; } {
return stringData[index];
}
void PutStringData(const std::string& s) void PutStringData(const std::string& s)
{ stringData.push_back(s); dcount++; } {
stringData.push_back(s);
dcount++;
}
int ColumnOID() const int ColumnOID() const
{ return oid; } {
return oid;
}
void SetColumnOID(int o) void SetColumnOID(int o)
{ oid = o; } {
oid = o;
}
uint64_t GetRid(uint32_t index) const uint64_t GetRid(uint32_t index) const
{ return rids[index]; } {
return rids[index];
}
void PutRid(uint64_t rid) void PutRid(uint64_t rid)
{ rids.push_back(rid); } {
rids.push_back(rid);
}
void PutRidOnly(uint64_t rid) void PutRidOnly(uint64_t rid)
{ rids.push_back(rid); dcount++; } {
rids.push_back(rid);
dcount++;
}
int dataCount() const int dataCount() const
{ return dcount; } {
return dcount;
}
private: private:
//defaults okay //defaults okay

View File

@ -33,7 +33,8 @@ using namespace messageqcpp;
#include "dataconvert.h" #include "dataconvert.h"
#include "calpontsystemcatalog.h" #include "calpontsystemcatalog.h"
namespace execplan { namespace execplan
{
/** /**
* Constructors/Destructors * Constructors/Destructors
*/ */
@ -83,6 +84,7 @@ ConstantColumn::ConstantColumn(const string& sql, TYPE type) :
{ {
fResultType.colDataType = CalpontSystemCatalog::BIGINT; fResultType.colDataType = CalpontSystemCatalog::BIGINT;
} }
fResultType.colWidth = 8; fResultType.colWidth = 8;
} }
else else
@ -227,8 +229,10 @@ ConstantColumn::ConstantColumn(const uint64_t val, TYPE type) :
ConstantColumn::~ConstantColumn() ConstantColumn::~ConstantColumn()
{ {
#ifndef _MSC_VER #ifndef _MSC_VER
if (fRegex.get() != NULL) if (fRegex.get() != NULL)
regfree(fRegex.get()); regfree(fRegex.get());
#endif #endif
} }
@ -237,15 +241,19 @@ const string ConstantColumn::toString() const
ostringstream oss; ostringstream oss;
oss << "ConstantColumn: " << fConstval << " intVal=" << fResult.intVal << " uintVal=" << fResult.uintVal; oss << "ConstantColumn: " << fConstval << " intVal=" << fResult.intVal << " uintVal=" << fResult.uintVal;
oss << '('; oss << '(';
if (fType == LITERAL) if (fType == LITERAL)
oss << 'l'; oss << 'l';
else if (fType == NUM) else if (fType == NUM)
oss << 'n'; oss << 'n';
else else
oss << "null"; oss << "null";
oss << ')'; oss << ')';
oss << " resultType=" << colDataTypeToString(fResultType.colDataType); oss << " resultType=" << colDataTypeToString(fResultType.colDataType);
if (fAlias.length() > 0) oss << "/Alias: " << fAlias; if (fAlias.length() > 0) oss << "/Alias: " << fAlias;
return oss.str(); return oss.str();
} }
@ -310,18 +318,25 @@ bool ConstantColumn::operator==(const ConstantColumn& t) const
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 (fConstval != t.fConstval) if (fConstval != t.fConstval)
return false; return false;
if (fType != t.fType) if (fType != t.fType)
return false; return false;
if (fAlias != t.fAlias) if (fAlias != t.fAlias)
return false; return false;
if (fData != t.fData) if (fData != t.fData)
return false; return false;
if (fReturnAll != t.fReturnAll) if (fReturnAll != t.fReturnAll)
return false; return false;
return true; return true;
} }
@ -330,8 +345,10 @@ bool ConstantColumn::operator==(const TreeNode* t) const
const ConstantColumn* o; const ConstantColumn* o;
o = dynamic_cast<const ConstantColumn*>(t); o = dynamic_cast<const ConstantColumn*>(t);
if (o == NULL) if (o == NULL)
return false; return false;
return *this == *o; return *this == *o;
} }

View File

@ -28,21 +28,24 @@
#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 constant return column * @brief A class to represent a constant return column
* *
* This class is a specialization of class ReturnedColumn that * This class is a specialization of class ReturnedColumn that
* handles a constant column such as number and literal string. * handles a constant column such as number and literal string.
*/ */
class ConstantColumn : public ReturnedColumn { class ConstantColumn : public ReturnedColumn
{
public: public:
enum TYPE enum TYPE
@ -81,19 +84,31 @@ public:
/** /**
* accessor * accessor
*/ */
inline unsigned int type() const { return fType; } inline unsigned int type() const
{
return fType;
}
/** /**
* accessor * accessor
*/ */
inline void type (unsigned int type) { fType = type; } inline void type (unsigned int type)
{
fType = type;
}
/** /**
* accessor * accessor
*/ */
inline const std::string& constval() const { return fConstval; } inline const std::string& constval() const
{
return fConstval;
}
/** /**
* accessor * accessor
*/ */
inline void constval(const std::string& constval) { fConstval = constval; } inline void constval(const std::string& constval)
{
fConstval = constval;
}
/** /**
* accessor * accessor
*/ */
@ -101,7 +116,10 @@ public:
/** /**
* accessor * accessor
*/ */
virtual void data(const std::string data) { fData = data; } virtual void data(const std::string data)
{
fData = data;
}
/** /**
* accessor * accessor
*/ */
@ -111,7 +129,10 @@ public:
* *
* deep copy of this pointer and return the copy * deep copy of this pointer and return the copy
*/ */
inline virtual ConstantColumn* clone() const {return new ConstantColumn (*this);} inline virtual ConstantColumn* clone() const
{
return new ConstantColumn (*this);
}
/* /*
* The serialization interface * The serialization interface
@ -153,10 +174,16 @@ public:
*/ */
bool operator!=(const ConstantColumn& t) const; bool operator!=(const ConstantColumn& t) const;
virtual bool hasWindowFunc() {return false;} virtual bool hasWindowFunc()
{
return false;
}
/** Constant column on the filte can always be moved into derived table */ /** Constant column on the filte can always be moved into derived table */
virtual void setDerivedTable() { fDerivedTable = "*"; } virtual void setDerivedTable()
{
fDerivedTable = "*";
}
private: private:
std::string fConstval; std::string fConstval;
@ -257,11 +284,13 @@ public:
virtual int32_t getDateIntVal(rowgroup::Row& row, bool& isNull) virtual int32_t getDateIntVal(rowgroup::Row& row, bool& isNull)
{ {
isNull = isNull || (fType == NULLDATA); isNull = isNull || (fType == NULLDATA);
if (!fResult.valueConverted) if (!fResult.valueConverted)
{ {
fResult.intVal = dataconvert::DataConvert::stringToDate(fResult.strVal); fResult.intVal = dataconvert::DataConvert::stringToDate(fResult.strVal);
fResult.valueConverted = true; fResult.valueConverted = true;
} }
return fResult.intVal; return fResult.intVal;
} }
/** /**
@ -270,21 +299,29 @@ public:
virtual int64_t getDatetimeIntVal(rowgroup::Row& row, bool& isNull) virtual int64_t getDatetimeIntVal(rowgroup::Row& row, bool& isNull)
{ {
isNull = isNull || (fType == NULLDATA); isNull = isNull || (fType == NULLDATA);
if (!fResult.valueConverted) if (!fResult.valueConverted)
{ {
fResult.intVal = dataconvert::DataConvert::stringToDatetime(fResult.strVal); fResult.intVal = dataconvert::DataConvert::stringToDatetime(fResult.strVal);
fResult.valueConverted = true; fResult.valueConverted = true;
} }
return fResult.intVal; return fResult.intVal;
} }
/** /**
* F&E * F&E
*/ */
inline float getFloatVal() const { return fResult.floatVal; } inline float getFloatVal() const
{
return fResult.floatVal;
}
/** /**
* F&E * F&E
*/ */
inline double getDoubleVal() const { return fResult.doubleVal; } inline double getDoubleVal() const
{
return fResult.doubleVal;
}
}; };

View File

@ -37,14 +37,19 @@ using namespace std;
#include "aggregatecolumn.h" #include "aggregatecolumn.h"
#include "windowfunctioncolumn.h" #include "windowfunctioncolumn.h"
namespace { namespace
{
template<class T> struct deleter : public unary_function<T&, void> template<class T> struct deleter : public unary_function<T&, void>
{ {
void operator()(T& x) { delete x; } void operator()(T& x)
{
delete x;
}
}; };
} }
namespace execplan { namespace execplan
{
/** /**
* Constructors/Destructors * Constructors/Destructors
@ -76,6 +81,7 @@ ConstantFilter::ConstantFilter(const ConstantFilter& rhs):
fSimpleColumnList.clear(); fSimpleColumnList.clear();
fWindowFunctionColumnList.clear(); fWindowFunctionColumnList.clear();
SSFP ssfp; SSFP ssfp;
for (uint32_t i = 0; i < rhs.fFilterList.size(); i++) for (uint32_t i = 0; i < rhs.fFilterList.size(); i++)
{ {
ssfp.reset(rhs.fFilterList[i]->clone()); ssfp.reset(rhs.fFilterList[i]->clone());
@ -104,9 +110,13 @@ const string ConstantFilter::toString() const
{ {
ostringstream output; ostringstream output;
output << "ConstantFilter" << endl; output << "ConstantFilter" << endl;
if (fOp) output << " " << *fOp << endl; if (fOp) output << " " << *fOp << endl;
if (!fFunctionName.empty()) output << " Func: " << fFunctionName << endl; if (!fFunctionName.empty()) output << " Func: " << fFunctionName << endl;
if (fCol) output << " " << *fCol << endl; if (fCol) output << " " << *fCol << endl;
for (unsigned int i = 0; i < fFilterList.size(); i++) for (unsigned int i = 0; i < fFilterList.size(); i++)
output << " " << *fFilterList[i] << endl; output << " " << *fFilterList[i] << endl;
@ -133,10 +143,12 @@ bool ConstantFilter::hasAggregate()
} }
} }
} }
if (!fAggColumnList.empty()) if (!fAggColumnList.empty())
{ {
return true; return true;
} }
return false; return false;
} }
@ -145,17 +157,22 @@ void ConstantFilter::serialize(messageqcpp::ByteStream& b) const
FilterList::const_iterator it; FilterList::const_iterator it;
b << static_cast<ObjectReader::id_t>(ObjectReader::CONSTANTFILTER); b << static_cast<ObjectReader::id_t>(ObjectReader::CONSTANTFILTER);
Filter::serialize(b); Filter::serialize(b);
if (fOp != NULL) if (fOp != NULL)
fOp->serialize(b); fOp->serialize(b);
else else
b << static_cast<ObjectReader::id_t>(ObjectReader::NULL_CLASS); b << static_cast<ObjectReader::id_t>(ObjectReader::NULL_CLASS);
if (fCol != NULL) if (fCol != NULL)
fCol->serialize(b); fCol->serialize(b);
else else
b << static_cast<ObjectReader::id_t>(ObjectReader::NULL_CLASS); b << static_cast<ObjectReader::id_t>(ObjectReader::NULL_CLASS);
b << static_cast<uint32_t>(fFilterList.size()); b << static_cast<uint32_t>(fFilterList.size());
for (it = fFilterList.begin(); it != fFilterList.end(); it++) for (it = fFilterList.begin(); it != fFilterList.end(); it++)
(*it)->serialize(b); (*it)->serialize(b);
b << fFunctionName; b << fFunctionName;
} }
@ -173,7 +190,9 @@ void ConstantFilter::unserialize(messageqcpp::ByteStream& b)
fSimpleColumnList.clear(); fSimpleColumnList.clear();
fAggColumnList.clear(); fAggColumnList.clear();
fWindowFunctionColumnList.clear(); fWindowFunctionColumnList.clear();
for (i = 0; i < size; i++) {
for (i = 0; i < size; i++)
{
sf = dynamic_cast<SimpleFilter*>(ObjectReader::createTreeNode(b)); sf = dynamic_cast<SimpleFilter*>(ObjectReader::createTreeNode(b));
SSFP ssfp(sf); SSFP ssfp(sf);
fFilterList.push_back(ssfp); fFilterList.push_back(ssfp);
@ -187,6 +206,7 @@ void ConstantFilter::unserialize(messageqcpp::ByteStream& b)
ssfp->windowfunctionColumnList().begin(), ssfp->windowfunctionColumnList().begin(),
ssfp->windowfunctionColumnList().end()); ssfp->windowfunctionColumnList().end());
} }
b >> fFunctionName; b >> fFunctionName;
} }
@ -197,10 +217,12 @@ bool ConstantFilter::operator==(const ConstantFilter& t) const
f1 = static_cast<const Filter*>(this); f1 = static_cast<const Filter*>(this);
f2 = static_cast<const Filter*>(&t); f2 = static_cast<const Filter*>(&t);
if (*f1 != *f2) if (*f1 != *f2)
return false; return false;
if (fOp != NULL) { if (fOp != NULL)
{
if (*fOp != *t.fOp) if (*fOp != *t.fOp)
return false; return false;
} }
@ -210,6 +232,7 @@ bool ConstantFilter::operator==(const ConstantFilter& t) const
//fFilterList //fFilterList
if (fFilterList.size() != t.fFilterList.size()) if (fFilterList.size() != t.fFilterList.size())
return false; return false;
for (it = fFilterList.begin(), it2 = t.fFilterList.begin(); for (it = fFilterList.begin(), it2 = t.fFilterList.begin();
it != fFilterList.end(); ++it, ++it2) it != fFilterList.end(); ++it, ++it2)
{ {
@ -225,8 +248,10 @@ bool ConstantFilter::operator==(const TreeNode* t) const
const ConstantFilter* o; const ConstantFilter* o;
o = dynamic_cast<const ConstantFilter*>(t); o = dynamic_cast<const ConstantFilter*>(t);
if (o == NULL) if (o == NULL)
return false; return false;
return *this == *o; return *this == *o;
} }
@ -247,6 +272,7 @@ void ConstantFilter::setDerivedTable()
fDerivedTable = ""; fDerivedTable = "";
return; return;
} }
fDerivedTable = fCol->derivedTable(); fDerivedTable = fCol->derivedTable();
} }
@ -254,6 +280,7 @@ void ConstantFilter::replaceRealCol(std::vector<SRCP>& derivedColList)
{ {
ReturnedColumn* tmp = derivedColList[fCol->colPosition()]->clone(); ReturnedColumn* tmp = derivedColList[fCol->colPosition()]->clone();
fCol.reset(tmp); fCol.reset(tmp);
for (unsigned i = 0; i < fFilterList.size(); i++) for (unsigned i = 0; i < fFilterList.size(); i++)
fFilterList[i]->replaceRealCol(derivedColList); fFilterList[i]->replaceRealCol(derivedColList);
} }
@ -266,6 +293,7 @@ const std::vector<SimpleColumn*>& ConstantFilter::simpleColumnList()
void ConstantFilter::setSimpleColumnList() void ConstantFilter::setSimpleColumnList()
{ {
fSimpleColumnList.clear(); fSimpleColumnList.clear();
for (uint32_t i = 0; i < fFilterList.size(); i++) for (uint32_t i = 0; i < fFilterList.size(); i++)
{ {
fFilterList[i]->setSimpleColumnList(); fFilterList[i]->setSimpleColumnList();

View File

@ -36,7 +36,8 @@
/** /**
* Namespace * Namespace
*/ */
namespace execplan { namespace execplan
{
class ReturnedColumn; class ReturnedColumn;
class AggregateColumn; class AggregateColumn;
@ -52,7 +53,8 @@ class WindowFunctionColumn;
* operator (either "and" or "or"). This class is introduced for * operator (either "and" or "or"). This class is introduced for
* easy operation combine for primitive processor. * easy operation combine for primitive processor.
*/ */
class ConstantFilter : public Filter { class ConstantFilter : public Filter
{
public: public:
/** /**
@ -78,17 +80,39 @@ public:
/** /**
* Accessor Methods * Accessor Methods
*/ */
const FilterList& filterList() const {return fFilterList;} const FilterList& filterList() const
void filterList( const FilterList& filterList) {fFilterList = filterList; } {
const SOP& op() const {return fOp;} return fFilterList;
void op(const SOP& op){fOp = op;} }
const SRCP& col() const {return fCol;} void filterList( const FilterList& filterList)
void col(const SRCP& col) {fCol = col;} {
fFilterList = filterList;
}
const SOP& op() const
{
return fOp;
}
void op(const SOP& op)
{
fOp = op;
}
const SRCP& col() const
{
return fCol;
}
void col(const SRCP& col)
{
fCol = col;
}
/** /**
* Operations * Operations
*/ */
void pushFilter (SimpleFilter* sf) {SSFP ssfp(sf); fFilterList.push_back(ssfp);} void pushFilter (SimpleFilter* sf)
{
SSFP ssfp(sf);
fFilterList.push_back(ssfp);
}
//virtual const std::string data() const; //virtual const std::string data() const;
virtual const std::string toString() const; virtual const std::string toString() const;
@ -142,13 +166,19 @@ public:
* *
* get the function name for this function column * get the function name for this function column
*/ */
std::string functionName() const { return fFunctionName; } std::string functionName() const
{
return fFunctionName;
}
/** set function name /** set function name
* *
* set the function name for this function column * set the function name for this function column
*/ */
void functionName(const std::string& functionName) { fFunctionName = functionName; } void functionName(const std::string& functionName)
{
fFunctionName = functionName;
}
void setDerivedTable(); void setDerivedTable();
virtual void replaceRealCol(std::vector<SRCP>&); virtual void replaceRealCol(std::vector<SRCP>&);
@ -178,7 +208,10 @@ public:
void setSimpleColumnList(); void setSimpleColumnList();
// get all aggregate columns involved in this column // get all aggregate columns involved in this column
const std::vector<AggregateColumn*>& aggColumnList() const { return fAggColumnList; } const std::vector<AggregateColumn*>& aggColumnList() const
{
return fAggColumnList;
}
private: private:
std::vector<SimpleColumn*> fSimpleColumnList; std::vector<SimpleColumn*> fSimpleColumnList;
@ -194,12 +227,16 @@ inline bool ConstantFilter::getBoolVal(rowgroup::Row& row, bool& isNull)
for (uint32_t i = 0; i < fFilterList.size(); i++) for (uint32_t i = 0; i < fFilterList.size(); i++)
if (!fFilterList[i]->getBoolVal(row, isNull)) if (!fFilterList[i]->getBoolVal(row, isNull))
return false; return false;
return true; return true;
case OP_OR: case OP_OR:
for (uint32_t i = 0; i < fFilterList.size(); i++) for (uint32_t i = 0; i < fFilterList.size(); i++)
if (fFilterList[i]->getBoolVal(row, isNull)) if (fFilterList[i]->getBoolVal(row, isNull))
return true; return true;
return false; return false;
default: default:
{ {
std::ostringstream oss; std::ostringstream oss;

View File

@ -29,7 +29,8 @@ using namespace std;
using namespace messageqcpp; using namespace messageqcpp;
#include "objectreader.h" #include "objectreader.h"
namespace execplan { namespace execplan
{
/** /**
* Constructors/Destructors * Constructors/Destructors
*/ */
@ -76,10 +77,12 @@ void ExistsFilter::serialize(messageqcpp::ByteStream& b) const
{ {
b << static_cast<ObjectReader::id_t>(ObjectReader::EXISTSFILTER); b << static_cast<ObjectReader::id_t>(ObjectReader::EXISTSFILTER);
Filter::serialize(b); Filter::serialize(b);
if (fSub.get() != NULL) if (fSub.get() != NULL)
fSub->serialize(b); fSub->serialize(b);
else else
b << static_cast<ObjectReader::id_t>(ObjectReader::NULL_CLASS); b << static_cast<ObjectReader::id_t>(ObjectReader::NULL_CLASS);
b << static_cast<const ByteStream::doublebyte>(fNotExists); b << static_cast<const ByteStream::doublebyte>(fNotExists);
b << static_cast<const ByteStream::doublebyte>(fCorrelated); b << static_cast<const ByteStream::doublebyte>(fCorrelated);
} }
@ -99,12 +102,16 @@ bool ExistsFilter::operator==(const ExistsFilter& t) const
f1 = static_cast<const Filter*>(this); f1 = static_cast<const Filter*>(this);
f2 = static_cast<const Filter*>(&t); f2 = static_cast<const Filter*>(&t);
if (*f1 != *f2) if (*f1 != *f2)
return false; return false;
if (*(fSub.get()) != t.fSub.get()) if (*(fSub.get()) != t.fSub.get())
return false; return false;
if (fNotExists != t.fNotExists) if (fNotExists != t.fNotExists)
return false; return false;
if (fCorrelated != t.fCorrelated) if (fCorrelated != t.fCorrelated)
return false; return false;
@ -116,8 +123,10 @@ bool ExistsFilter::operator==(const TreeNode* t) const
const ExistsFilter* o; const ExistsFilter* o;
o = dynamic_cast<const ExistsFilter*>(t); o = dynamic_cast<const ExistsFilter*>(t);
if (o == NULL) if (o == NULL)
return false; return false;
return *this == *o; return *this == *o;
} }

View File

@ -32,14 +32,16 @@
/** /**
* Namespace * Namespace
*/ */
namespace execplan { namespace execplan
{
/** /**
* @brief A class to represent a exists predicate * @brief A class to represent a exists predicate
* *
* This class is a specialization of class Filter that handles a * This class is a specialization of class Filter that handles a
* exists predicate like "exists (select col2 from table2)" * exists predicate like "exists (select col2 from table2)"
*/ */
class ExistsFilter : public Filter { class ExistsFilter : public Filter
{
/** /**
* Public stuff * Public stuff
*/ */
@ -55,14 +57,32 @@ public:
/** /**
* Accessor Methods * Accessor Methods
*/ */
const SCSEP& sub() const { return fSub; } const SCSEP& sub() const
void sub (SCSEP& sub) { fSub = sub; } {
return fSub;
}
void sub (SCSEP& sub)
{
fSub = sub;
}
const bool notExists() const { return fNotExists; } const bool notExists() const
void notExists (const bool notExists) { fNotExists = notExists; } {
return fNotExists;
}
void notExists (const bool notExists)
{
fNotExists = notExists;
}
const bool correlated() const { return fCorrelated; } const bool correlated() const
void correlated(const bool correlated) { fCorrelated = correlated; } {
return fCorrelated;
}
void correlated(const bool correlated)
{
fCorrelated = correlated;
}
/** /**
* Overloaded stream operator * Overloaded stream operator

View File

@ -34,7 +34,8 @@
#include <iterator> #include <iterator>
//#include <parsetree.h> //#include <parsetree.h>
namespace expression { namespace expression
{
enum precedence { none, lower, equal, higher }; enum precedence { none, lower, equal, higher };
struct not_an_acceptor_tag {}; struct not_an_acceptor_tag {};
@ -42,7 +43,8 @@ namespace expression {
struct accumulating_acceptor_tag {}; struct accumulating_acceptor_tag {};
template<typename Acceptor> template<typename Acceptor>
struct acceptor_traits { struct acceptor_traits
{
typedef typename Acceptor::acceptor_category acceptor_category; typedef typename Acceptor::acceptor_category acceptor_category;
typedef typename Acceptor::input_symbol_type input_symbol_type; typedef typename Acceptor::input_symbol_type input_symbol_type;
typedef typename Acceptor::result_type result_type; typedef typename Acceptor::result_type result_type;
@ -61,7 +63,8 @@ namespace expression {
enum associativity { non_associative, left_associative, right_associative }; enum associativity { non_associative, left_associative, right_associative };
struct default_expression_parser_error_policy { struct default_expression_parser_error_policy
{
template<typename Operand> template<typename Operand>
void invalid_operand_position(Operand) void invalid_operand_position(Operand)
{ {
@ -113,7 +116,8 @@ namespace expression {
expression_acceptor<Token, Operand, Operator, Policy, OperandStack, \ expression_acceptor<Token, Operand, Operator, Policy, OperandStack, \
OperatorStack> OperatorStack>
namespace detail { namespace detail
{
enum action {shift, reduce, prec, prec_assoc, invalid}; enum action {shift, reduce, prec, prec_assoc, invalid};
// Current larser state // Current larser state
@ -123,7 +127,8 @@ namespace expression {
const int pre_positions = prefix | open; const int pre_positions = prefix | open;
const int post_positions = postfix | close | infix | function_open; const int post_positions = postfix | close | infix | function_open;
const action parse_action[6][6] = { const action parse_action[6][6] =
{
/* prefix postfix infix open close func open */ /* prefix postfix infix open close func open */
/* prefix */ { shift, prec, prec, shift, reduce, prec }, /* prefix */ { shift, prec, prec, shift, reduce, prec },
/* postfix */ { invalid, reduce, reduce, reduce, reduce, reduce }, /* postfix */ { invalid, reduce, reduce, reduce, reduce, reduce },
@ -141,9 +146,11 @@ namespace expression {
typename OperandStack = std::stack<Operand>, typename OperandStack = std::stack<Operand>,
typename OperatorStack = std::stack<Operator> typename OperatorStack = std::stack<Operator>
> >
class expression_acceptor { class expression_acceptor
{
private: private:
class assignment_proxy { class assignment_proxy
{
public: public:
explicit assignment_proxy(expression_acceptor* acceptor) : explicit assignment_proxy(expression_acceptor* acceptor) :
m_expression_acceptor(acceptor) {} m_expression_acceptor(acceptor) {}
@ -180,12 +187,24 @@ namespace expression {
{ {
} }
assignment_proxy operator*() { return assignment_proxy(this); } assignment_proxy operator*()
expression_acceptor& operator++() { return *this; } {
expression_acceptor& operator++(int) { return *this; } return assignment_proxy(this);
}
expression_acceptor& operator++()
{
return *this;
}
expression_acceptor& operator++(int)
{
return *this;
}
bool accepted(); bool accepted();
bool trapped() { return m_state == rejected; } bool trapped()
{
return m_state == rejected;
}
operator Operand() operator Operand()
{ {
@ -209,31 +228,38 @@ namespace expression {
EXP_TEMPLATE EXP_TEMPLATE
bool EXP_ACCEPTOR::accepted() bool EXP_ACCEPTOR::accepted()
{ {
if (m_state == accepting) { if (m_state == accepting)
{
return true; return true;
} }
else if (m_state == rejected) { else if (m_state == rejected)
{
return false; return false;
} }
else if (m_state == lookahead) { else if (m_state == lookahead)
{
m_state = post_operand; m_state = post_operand;
int position = m_policy.positions(m_ambiguous_operator); int position = m_policy.positions(m_ambiguous_operator);
parse_operator(m_policy.as_operator(m_ambiguous_operator, parse_operator(m_policy.as_operator(m_ambiguous_operator,
position & (postfix | close))); position & (postfix | close)));
} }
while (!m_operator_stack.empty() && m_state != rejected) { while (!m_operator_stack.empty() && m_state != rejected)
{
do_reduce(); do_reduce();
} }
if (m_state == rejected) { if (m_state == rejected)
{
return false; return false;
} }
else if (m_operand_stack.size() > 1 || !m_operator_stack.empty()) { else if (m_operand_stack.size() > 1 || !m_operator_stack.empty())
{
m_state = rejected; m_state = rejected;
return false; return false;
} }
else { else
{
m_state = accepting; m_state = accepting;
return true; return true;
} }
@ -247,28 +273,33 @@ namespace expression {
if (m_state == rejected) if (m_state == rejected)
return; return;
if (m_policy.is_operator(t)) { if (m_policy.is_operator(t))
{
int operator_positions = m_policy.positions(t); int operator_positions = m_policy.positions(t);
if (m_state == lookahead) { if (m_state == lookahead)
{
bool could_be_pre = ((operator_positions & pre_positions) != 0); bool could_be_pre = ((operator_positions & pre_positions) != 0);
bool could_be_post = ((operator_positions & post_positions) != 0); bool could_be_post = ((operator_positions & post_positions) != 0);
int ambiguous_position = m_policy.positions(m_ambiguous_operator); int ambiguous_position = m_policy.positions(m_ambiguous_operator);
if ( (could_be_pre && could_be_post) || if ( (could_be_pre && could_be_post) ||
(!could_be_pre && !could_be_post) ) { (!could_be_pre && !could_be_post) )
{
m_policy.ambiguity(m_ambiguous_operator, t); m_policy.ambiguity(m_ambiguous_operator, t);
m_state = rejected; m_state = rejected;
return; return;
} }
else if (could_be_pre) { else if (could_be_pre)
{
ambiguous_position &= (infix | function_open); ambiguous_position &= (infix | function_open);
parse_operator(m_policy.as_operator(m_ambiguous_operator, parse_operator(m_policy.as_operator(m_ambiguous_operator,
ambiguous_position)); ambiguous_position));
m_state = pre_operand; m_state = pre_operand;
} }
else { else
{
ambiguous_position &= (postfix | close); ambiguous_position &= (postfix | close);
parse_operator(m_policy.as_operator(m_ambiguous_operator, parse_operator(m_policy.as_operator(m_ambiguous_operator,
ambiguous_position)); ambiguous_position));
@ -280,7 +311,9 @@ namespace expression {
(m_state == pre_operand) ? pre_positions : post_positions; (m_state == pre_operand) ? pre_positions : post_positions;
int positions = operator_positions & valid_positions; int positions = operator_positions & valid_positions;
switch (positions) {
switch (positions)
{
case infix: case infix:
case function_open: case function_open:
m_state = pre_operand; m_state = pre_operand;
@ -307,20 +340,24 @@ namespace expression {
return; return;
} }
} }
else { else
if (m_state == lookahead) { {
if (m_state == lookahead)
{
int positions = m_policy.positions(m_ambiguous_operator); int positions = m_policy.positions(m_ambiguous_operator);
positions &= (infix | function_open); positions &= (infix | function_open);
parse_operator(m_policy.as_operator(m_ambiguous_operator, parse_operator(m_policy.as_operator(m_ambiguous_operator,
positions)); positions));
m_state = post_operand; m_state = post_operand;
} }
else if (m_state == post_operand) { else if (m_state == post_operand)
{
m_policy.invalid_operand_position(m_policy.as_operand(t)); m_policy.invalid_operand_position(m_policy.as_operand(t));
m_state = rejected; m_state = rejected;
return; return;
} }
else { else
{
m_state = post_operand; m_state = post_operand;
} }
@ -331,7 +368,8 @@ namespace expression {
EXP_TEMPLATE EXP_TEMPLATE
inline int EXP_ACCEPTOR::operator_type_index(int position) inline int EXP_ACCEPTOR::operator_type_index(int position)
{ {
switch (position) { switch (position)
{
case prefix: case prefix:
return 0; return 0;
@ -358,16 +396,19 @@ namespace expression {
EXP_TEMPLATE EXP_TEMPLATE
void EXP_ACCEPTOR::parse_operator(const Operator& cur_operator) void EXP_ACCEPTOR::parse_operator(const Operator& cur_operator)
{ {
if (m_operator_stack.empty()) { if (m_operator_stack.empty())
{
m_operator_stack.push(cur_operator); m_operator_stack.push(cur_operator);
} }
else { else
{
int cur_index = operator_type_index(m_policy.position(cur_operator)); int cur_index = operator_type_index(m_policy.position(cur_operator));
Operator& prev_operator = m_operator_stack.top(); Operator& prev_operator = m_operator_stack.top();
int prev_index = operator_type_index(m_policy.position(prev_operator)); int prev_index = operator_type_index(m_policy.position(prev_operator));
switch (parse_action[prev_index][cur_index]) { switch (parse_action[prev_index][cur_index])
{
case shift: case shift:
m_operator_stack.push(cur_operator); m_operator_stack.push(cur_operator);
break; break;
@ -378,7 +419,8 @@ namespace expression {
break; break;
case prec: case prec:
switch (m_policy.precedence(prev_operator, cur_operator)) { switch (m_policy.precedence(prev_operator, cur_operator))
{
case lower: case lower:
m_operator_stack.push(cur_operator); m_operator_stack.push(cur_operator);
break; break;
@ -393,10 +435,12 @@ namespace expression {
m_state = rejected; m_state = rejected;
return; return;
} }
break; break;
case prec_assoc: case prec_assoc:
switch (m_policy.precedence(prev_operator, cur_operator)) { switch (m_policy.precedence(prev_operator, cur_operator))
{
case lower: case lower:
m_operator_stack.push(cur_operator); m_operator_stack.push(cur_operator);
break; break;
@ -407,7 +451,8 @@ namespace expression {
break; break;
case equal: case equal:
switch(m_policy.associativity(prev_operator, cur_operator)) { switch (m_policy.associativity(prev_operator, cur_operator))
{
case left_associative: case left_associative:
do_reduce(); do_reduce();
parse_operator(cur_operator); parse_operator(cur_operator);
@ -423,6 +468,7 @@ namespace expression {
m_state = rejected; m_state = rejected;
return; return;
} }
break; break;
default: default:
@ -430,6 +476,7 @@ namespace expression {
m_state = rejected; m_state = rejected;
return; return;
} }
break; break;
case invalid: case invalid:
@ -446,11 +493,13 @@ namespace expression {
Operator op = m_operator_stack.top(); Operator op = m_operator_stack.top();
m_operator_stack.pop(); m_operator_stack.pop();
switch (m_policy.position(op)) { switch (m_policy.position(op))
{
case prefix: case prefix:
case postfix: case postfix:
{ {
if (m_operand_stack.empty()) { if (m_operand_stack.empty())
{
m_policy.missing_operand(op); m_policy.missing_operand(op);
m_state = rejected; m_state = rejected;
return; return;
@ -465,7 +514,8 @@ namespace expression {
case infix: case infix:
{ {
if (m_operand_stack.size() < 2) { if (m_operand_stack.size() < 2)
{
m_policy.missing_operand(op); m_policy.missing_operand(op);
m_state = rejected; m_state = rejected;
return; return;
@ -487,13 +537,15 @@ namespace expression {
return; return;
case close: case close:
if (m_operator_stack.empty()) { if (m_operator_stack.empty())
{
m_policy.unbalanced_confix(op); m_policy.unbalanced_confix(op);
m_state = rejected; m_state = rejected;
return; return;
} }
if (m_operand_stack.empty()) { if (m_operand_stack.empty())
{
m_policy.missing_operand(op); m_policy.missing_operand(op);
m_state = rejected; m_state = rejected;
return; return;
@ -506,8 +558,10 @@ namespace expression {
Operand operand = m_operand_stack.top(); Operand operand = m_operand_stack.top();
m_operand_stack.pop(); m_operand_stack.pop();
if (m_policy.position(open) == function_open) { if (m_policy.position(open) == function_open)
if (m_operand_stack.empty()) { {
if (m_operand_stack.empty())
{
m_policy.missing_operand(open); m_policy.missing_operand(open);
m_state = rejected; m_state = rejected;
return; return;
@ -520,10 +574,12 @@ namespace expression {
m_policy.reduce(function, open, operand, op) m_policy.reduce(function, open, operand, op)
); );
} }
else { else
{
m_operand_stack.push(m_policy.reduce(open, op, operand)); m_operand_stack.push(m_policy.reduce(open, op, operand));
} }
} }
return; return;
default: default:
@ -552,7 +608,8 @@ namespace expression {
typename OperandStack = std::stack<Operand>, typename OperandStack = std::stack<Operand>,
typename OperatorStack = std::stack<Operator> typename OperatorStack = std::stack<Operator>
> >
class expression_parser { class expression_parser
{
public: public:
typedef detail::EXP_ACCEPTOR acceptor; typedef detail::EXP_ACCEPTOR acceptor;
typedef Token token_type; typedef Token token_type;
@ -568,13 +625,18 @@ namespace expression {
template<typename InputIterator> template<typename InputIterator>
Operand parse(InputIterator first, InputIterator last) Operand parse(InputIterator first, InputIterator last)
{ {
try { try
{
#if _MSC_VER > 1600 #if _MSC_VER > 1600
return std::_Copy_impl(first, last, start());} return std::_Copy_impl(first, last, start());
}
#else #else
return std::copy(first, last, start());} return std::copy(first, last, start());
}
#endif #endif
catch (const std::runtime_error&) { catch (const std::runtime_error&)
{
m_policy.cleanup(operandStack, operatorStack); m_policy.cleanup(operandStack, operatorStack);
throw; throw;
} }
@ -586,10 +648,12 @@ namespace expression {
// this is to chean up the pointers in the stack when exception // this is to chean up the pointers in the stack when exception
// is thrown. the exception is then passed to the upper level. // is thrown. the exception is then passed to the upper level.
// changed by Zhixuan Zhu 07/03/06 // changed by Zhixuan Zhu 07/03/06
try { try
{
return acceptor(m_policy, operandStack, operatorStack); return acceptor(m_policy, operandStack, operatorStack);
} catch (const std::runtime_error&) }
catch (const std::runtime_error&)
{ {
m_policy.cleanup(operandStack, operatorStack); m_policy.cleanup(operandStack, operatorStack);
throw; throw;

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