You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-01 06:46:55 +03:00
Reformat all code to coding standard
This commit is contained in:
@ -42,157 +42,178 @@ bool dflg;
|
||||
|
||||
void usage()
|
||||
{
|
||||
cout << "usage: dmldriver [-vhd] [-c intvl] [-f file] [-s sid] [-t flgs] [-r file] [-p cnt] [sql_text]" << endl;
|
||||
cout << " -c intvl \tcommit every intvl statements" << endl;
|
||||
cout << " -f file \tread statements from file (max 15KB/stmt)" << endl;
|
||||
cout << " -s sid \tset sid as session id" << endl;
|
||||
cout << " -t flgs \tset trace flags" << endl;
|
||||
cout << " -v \tdisplay affected row count(s)" << endl;
|
||||
cout << " -d \tdisplay debug info" << endl;
|
||||
cout << " -r file \tread orderkeys from file for TPC-H RF2" << endl;
|
||||
cout << " -p cnt \tpack cnt orderkeys into each delete stmt (only w/ -r)" << endl;
|
||||
cout << " -e schema\tset the schema name (only w/ -r)" << endl;
|
||||
cout << " -h \tdisplay this help text" << endl;
|
||||
cout << "usage: dmldriver [-vhd] [-c intvl] [-f file] [-s sid] [-t flgs] [-r file] [-p cnt] [sql_text]" << endl;
|
||||
cout << " -c intvl \tcommit every intvl statements" << endl;
|
||||
cout << " -f file \tread statements from file (max 15KB/stmt)" << endl;
|
||||
cout << " -s sid \tset sid as session id" << endl;
|
||||
cout << " -t flgs \tset trace flags" << endl;
|
||||
cout << " -v \tdisplay affected row count(s)" << endl;
|
||||
cout << " -d \tdisplay debug info" << endl;
|
||||
cout << " -r file \tread orderkeys from file for TPC-H RF2" << endl;
|
||||
cout << " -p cnt \tpack cnt orderkeys into each delete stmt (only w/ -r)" << endl;
|
||||
cout << " -e schema\tset the schema name (only w/ -r)" << endl;
|
||||
cout << " -h \tdisplay this help text" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int c;
|
||||
int c;
|
||||
|
||||
opterr = 0;
|
||||
opterr = 0;
|
||||
|
||||
vflg = false;
|
||||
dflg = false;
|
||||
vflg = false;
|
||||
dflg = false;
|
||||
|
||||
bool fflg = false;
|
||||
string infilename;
|
||||
bool fflg = false;
|
||||
string infilename;
|
||||
|
||||
int cIntvl = numeric_limits<int>::max();
|
||||
int cIntvl = numeric_limits<int>::max();
|
||||
|
||||
uint32_t sessionID = time(0) & 0x7fffffff;
|
||||
uint32_t sessionID = time(0) & 0x7fffffff;
|
||||
|
||||
bool rflg = false;
|
||||
bool rflg = false;
|
||||
|
||||
int packCnt = 1;
|
||||
int packCnt = 1;
|
||||
|
||||
uint32_t tflg = 0;
|
||||
uint32_t tflg = 0;
|
||||
|
||||
string schema;
|
||||
string schema;
|
||||
|
||||
while ((c = getopt(argc, argv, "e:t:s:c:f:r:p:vhd")) != EOF)
|
||||
switch (c)
|
||||
{
|
||||
case 'v':
|
||||
vflg = true;
|
||||
break;
|
||||
case 'd':
|
||||
dflg = true;
|
||||
break;
|
||||
case 'f':
|
||||
fflg = true;
|
||||
infilename = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
cIntvl = static_cast<int>(strtol(optarg, 0, 0));
|
||||
break;
|
||||
case 's':
|
||||
sessionID = static_cast<uint32_t>(strtoul(optarg, 0, 0));
|
||||
break;
|
||||
case 't':
|
||||
tflg = static_cast<uint32_t>(strtoul(optarg, 0, 0));
|
||||
break;
|
||||
case 'r':
|
||||
rflg = true;
|
||||
infilename = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
packCnt = static_cast<int>(strtol(optarg, 0, 0));
|
||||
break;
|
||||
case 'e':
|
||||
schema = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
return (c == 'h' ? 0 : 1);
|
||||
break;
|
||||
}
|
||||
while ((c = getopt(argc, argv, "e:t:s:c:f:r:p:vhd")) != EOF)
|
||||
switch (c)
|
||||
{
|
||||
case 'v':
|
||||
vflg = true;
|
||||
break;
|
||||
|
||||
if (!fflg && !rflg && ((argc - optind) < 1))
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
case 'd':
|
||||
dflg = true;
|
||||
break;
|
||||
|
||||
if (fflg && rflg)
|
||||
{
|
||||
cout << "-f and -r are mutually exclusive!" << endl << endl;
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
case 'f':
|
||||
fflg = true;
|
||||
infilename = optarg;
|
||||
break;
|
||||
|
||||
if (!schema.empty() && !rflg)
|
||||
{
|
||||
cout << "-e requires -r!" << endl << endl;
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
case 'c':
|
||||
cIntvl = static_cast<int>(strtol(optarg, 0, 0));
|
||||
break;
|
||||
|
||||
string stmtStr;
|
||||
if (!fflg && !rflg)
|
||||
stmtStr = argv[optind++];
|
||||
case 's':
|
||||
sessionID = static_cast<uint32_t>(strtoul(optarg, 0, 0));
|
||||
break;
|
||||
|
||||
int rc = 0;
|
||||
case 't':
|
||||
tflg = static_cast<uint32_t>(strtoul(optarg, 0, 0));
|
||||
break;
|
||||
|
||||
dmlif::DMLIF dmlif(sessionID, tflg, dflg, vflg);
|
||||
case 'r':
|
||||
rflg = true;
|
||||
infilename = optarg;
|
||||
break;
|
||||
|
||||
if (fflg)
|
||||
{
|
||||
ifstream ifs(infilename.c_str());
|
||||
if (!ifs.good())
|
||||
{
|
||||
cerr << "Error accessing file " << infilename << endl;
|
||||
return 1;
|
||||
}
|
||||
const streamsize ilinelen = 15 * 1024;
|
||||
scoped_array<char> iline(new char[ilinelen]);
|
||||
int cnt = 0;
|
||||
for (;;)
|
||||
{
|
||||
ifs.getline(iline.get(), ilinelen);
|
||||
if (ifs.eof())
|
||||
break;
|
||||
rc = dmlif.sendOne(iline.get());
|
||||
if (rc != 0)
|
||||
break;
|
||||
cnt++;
|
||||
if ((cnt % cIntvl) == 0)
|
||||
dmlif.sendOne("COMMIT;");
|
||||
}
|
||||
}
|
||||
else if (rflg)
|
||||
{
|
||||
ifstream ifs(infilename.c_str());
|
||||
if (!ifs.good())
|
||||
{
|
||||
cerr << "Error accessing file " << infilename << endl;
|
||||
return 1;
|
||||
}
|
||||
if (schema.empty())
|
||||
schema = "tpch";
|
||||
tpch::RF2 rf2(schema, sessionID, tflg, cIntvl, packCnt, dflg, vflg);
|
||||
rc = rf2.run(ifs);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = dmlif.sendOne(stmtStr);
|
||||
}
|
||||
case 'p':
|
||||
packCnt = static_cast<int>(strtol(optarg, 0, 0));
|
||||
break;
|
||||
|
||||
if (rc == 0)
|
||||
dmlif.sendOne("COMMIT;");
|
||||
case 'e':
|
||||
schema = optarg;
|
||||
break;
|
||||
|
||||
return 0;
|
||||
case 'h':
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
return (c == 'h' ? 0 : 1);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!fflg && !rflg && ((argc - optind) < 1))
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (fflg && rflg)
|
||||
{
|
||||
cout << "-f and -r are mutually exclusive!" << endl << endl;
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!schema.empty() && !rflg)
|
||||
{
|
||||
cout << "-e requires -r!" << endl << endl;
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
string stmtStr;
|
||||
|
||||
if (!fflg && !rflg)
|
||||
stmtStr = argv[optind++];
|
||||
|
||||
int rc = 0;
|
||||
|
||||
dmlif::DMLIF dmlif(sessionID, tflg, dflg, vflg);
|
||||
|
||||
if (fflg)
|
||||
{
|
||||
ifstream ifs(infilename.c_str());
|
||||
|
||||
if (!ifs.good())
|
||||
{
|
||||
cerr << "Error accessing file " << infilename << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const streamsize ilinelen = 15 * 1024;
|
||||
scoped_array<char> iline(new char[ilinelen]);
|
||||
int cnt = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
ifs.getline(iline.get(), ilinelen);
|
||||
|
||||
if (ifs.eof())
|
||||
break;
|
||||
|
||||
rc = dmlif.sendOne(iline.get());
|
||||
|
||||
if (rc != 0)
|
||||
break;
|
||||
|
||||
cnt++;
|
||||
|
||||
if ((cnt % cIntvl) == 0)
|
||||
dmlif.sendOne("COMMIT;");
|
||||
}
|
||||
}
|
||||
else if (rflg)
|
||||
{
|
||||
ifstream ifs(infilename.c_str());
|
||||
|
||||
if (!ifs.good())
|
||||
{
|
||||
cerr << "Error accessing file " << infilename << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (schema.empty())
|
||||
schema = "tpch";
|
||||
|
||||
tpch::RF2 rf2(schema, sessionID, tflg, cIntvl, packCnt, dflg, vflg);
|
||||
rc = rf2.run(ifs);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = dmlif.sendOne(stmtStr);
|
||||
}
|
||||
|
||||
if (rc == 0)
|
||||
dmlif.sendOne("COMMIT;");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -52,9 +52,9 @@ namespace dmlif
|
||||
{
|
||||
|
||||
DMLIF::DMLIF(uint32_t sessionid, uint32_t tflg, bool dflg, bool vflg) :
|
||||
fSessionID(sessionid), fTflg(tflg), fDflg(dflg), fVflg(vflg), fOPt(0), fLPt(0)
|
||||
fSessionID(sessionid), fTflg(tflg), fDflg(dflg), fVflg(vflg), fOPt(0), fLPt(0)
|
||||
{
|
||||
fMqp.reset(new MessageQueueClient("DMLProc"));
|
||||
fMqp.reset(new MessageQueueClient("DMLProc"));
|
||||
}
|
||||
|
||||
DMLIF::~DMLIF()
|
||||
@ -63,270 +63,308 @@ DMLIF::~DMLIF()
|
||||
|
||||
int DMLIF::sendOne(const string& stmt)
|
||||
{
|
||||
int rc;
|
||||
int rc;
|
||||
|
||||
string tStmt(stmt);
|
||||
if (*tStmt.rbegin() != ';')
|
||||
tStmt += ";";
|
||||
string tStmt(stmt);
|
||||
|
||||
VendorDMLStatement dmlStmt(tStmt, fSessionID);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
if (pDMLPackage == 0)
|
||||
{
|
||||
cerr << "Failed to parse statement: " << tStmt << endl;
|
||||
return -1;
|
||||
}
|
||||
if (*tStmt.rbegin() != ';')
|
||||
tStmt += ";";
|
||||
|
||||
string queryString = pDMLPackage->get_QueryString();
|
||||
if (fDflg) cout << "qs: >" << queryString << '<' << endl;
|
||||
VendorDMLStatement dmlStmt(tStmt, fSessionID);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
|
||||
string dmlStatement = pDMLPackage->get_DMLStatement();
|
||||
if (fDflg) cout << "DML: " << dmlStatement << endl;
|
||||
bool isDML = true;
|
||||
if (dmlStatement == "COMMIT" || dmlStatement == "ROLLBACK")
|
||||
{
|
||||
isDML = false;
|
||||
}
|
||||
if (pDMLPackage == 0)
|
||||
{
|
||||
cerr << "Failed to parse statement: " << tStmt << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (isDML)
|
||||
{
|
||||
char_separator<char> sep(" ");
|
||||
tokenizer<char_separator<char> > tok(queryString, sep);
|
||||
tokenizer<char_separator<char> >::iterator iter = tok.begin();
|
||||
idbassert(iter != tok.end());
|
||||
string where = *iter; ++iter;
|
||||
idbassert(iter != tok.end());
|
||||
string col1 = *iter; ++iter;
|
||||
idbassert(iter != tok.end());
|
||||
string op = *iter; ++iter;
|
||||
idbassert(iter != tok.end());
|
||||
string col2 = *iter; ++iter;
|
||||
idbassert(iter == tok.end());
|
||||
if (fDflg) cout << "SQL: " << pDMLPackage->get_SQLStatement() << endl;
|
||||
if (fDflg) cout << "hf: " << pDMLPackage->HasFilter() << endl;
|
||||
DMLTable* tp = pDMLPackage->get_Table();
|
||||
if (fDflg) cout << "sn: " << tp->get_SchemaName() << " tn: " << tp->get_TableName() << endl;
|
||||
if (fDflg) cout << "row count: " << tp->get_RowList().size() << endl;
|
||||
SRCP srcp(new SimpleColumn(tp->get_SchemaName(), tp->get_TableName(), col1, fSessionID));
|
||||
CalpontSelectExecutionPlan::ColumnMap cm;
|
||||
cm.insert(make_pair(col1, srcp));
|
||||
pDMLPackage->get_ExecutionPlan()->columnMap(cm);
|
||||
CalpontSelectExecutionPlan::ReturnedColumnList rcl;
|
||||
rcl.push_back(srcp);
|
||||
pDMLPackage->get_ExecutionPlan()->returnedCols(rcl);
|
||||
pDMLPackage->get_ExecutionPlan()->sessionID(fSessionID);
|
||||
pDMLPackage->get_ExecutionPlan()->traceFlags(fTflg);
|
||||
SessionManager sm;
|
||||
BRM::TxnID txnid = sm.getTxnID(fSessionID);
|
||||
if (!txnid.valid)
|
||||
txnid = sm.newTxnID(fSessionID);
|
||||
pDMLPackage->get_ExecutionPlan()->txnID(txnid.id);
|
||||
pDMLPackage->get_ExecutionPlan()->verID(sm.verID());
|
||||
ParseTree* pt = new ParseTree();
|
||||
ReturnedColumn* rc1 = srcp->clone();
|
||||
ReturnedColumn* rc2 = new ConstantColumn(col2, ConstantColumn::NUM);
|
||||
SOP sop(new Operator(op));
|
||||
SimpleFilter* sf = new SimpleFilter(sop, rc1, rc2);
|
||||
pt->data(sf);
|
||||
pDMLPackage->get_ExecutionPlan()->filters(pt);
|
||||
if (fDflg) cout << "ep: " << *pDMLPackage->get_ExecutionPlan() << endl;
|
||||
}
|
||||
string queryString = pDMLPackage->get_QueryString();
|
||||
|
||||
ByteStream bytestream;
|
||||
pDMLPackage->write(bytestream);
|
||||
delete pDMLPackage;
|
||||
ByteStream::octbyte rows;
|
||||
if (fDflg) cout << "qs: >" << queryString << '<' << endl;
|
||||
|
||||
rc = DMLSend(bytestream, rows);
|
||||
string dmlStatement = pDMLPackage->get_DMLStatement();
|
||||
|
||||
if (isDML && fVflg)
|
||||
cout << rows << " rows affected" << endl;
|
||||
if (fDflg) cout << "DML: " << dmlStatement << endl;
|
||||
|
||||
return rc;
|
||||
bool isDML = true;
|
||||
|
||||
if (dmlStatement == "COMMIT" || dmlStatement == "ROLLBACK")
|
||||
{
|
||||
isDML = false;
|
||||
}
|
||||
|
||||
if (isDML)
|
||||
{
|
||||
char_separator<char> sep(" ");
|
||||
tokenizer<char_separator<char> > tok(queryString, sep);
|
||||
tokenizer<char_separator<char> >::iterator iter = tok.begin();
|
||||
idbassert(iter != tok.end());
|
||||
string where = *iter;
|
||||
++iter;
|
||||
idbassert(iter != tok.end());
|
||||
string col1 = *iter;
|
||||
++iter;
|
||||
idbassert(iter != tok.end());
|
||||
string op = *iter;
|
||||
++iter;
|
||||
idbassert(iter != tok.end());
|
||||
string col2 = *iter;
|
||||
++iter;
|
||||
idbassert(iter == tok.end());
|
||||
|
||||
if (fDflg) cout << "SQL: " << pDMLPackage->get_SQLStatement() << endl;
|
||||
|
||||
if (fDflg) cout << "hf: " << pDMLPackage->HasFilter() << endl;
|
||||
|
||||
DMLTable* tp = pDMLPackage->get_Table();
|
||||
|
||||
if (fDflg) cout << "sn: " << tp->get_SchemaName() << " tn: " << tp->get_TableName() << endl;
|
||||
|
||||
if (fDflg) cout << "row count: " << tp->get_RowList().size() << endl;
|
||||
|
||||
SRCP srcp(new SimpleColumn(tp->get_SchemaName(), tp->get_TableName(), col1, fSessionID));
|
||||
CalpontSelectExecutionPlan::ColumnMap cm;
|
||||
cm.insert(make_pair(col1, srcp));
|
||||
pDMLPackage->get_ExecutionPlan()->columnMap(cm);
|
||||
CalpontSelectExecutionPlan::ReturnedColumnList rcl;
|
||||
rcl.push_back(srcp);
|
||||
pDMLPackage->get_ExecutionPlan()->returnedCols(rcl);
|
||||
pDMLPackage->get_ExecutionPlan()->sessionID(fSessionID);
|
||||
pDMLPackage->get_ExecutionPlan()->traceFlags(fTflg);
|
||||
SessionManager sm;
|
||||
BRM::TxnID txnid = sm.getTxnID(fSessionID);
|
||||
|
||||
if (!txnid.valid)
|
||||
txnid = sm.newTxnID(fSessionID);
|
||||
|
||||
pDMLPackage->get_ExecutionPlan()->txnID(txnid.id);
|
||||
pDMLPackage->get_ExecutionPlan()->verID(sm.verID());
|
||||
ParseTree* pt = new ParseTree();
|
||||
ReturnedColumn* rc1 = srcp->clone();
|
||||
ReturnedColumn* rc2 = new ConstantColumn(col2, ConstantColumn::NUM);
|
||||
SOP sop(new Operator(op));
|
||||
SimpleFilter* sf = new SimpleFilter(sop, rc1, rc2);
|
||||
pt->data(sf);
|
||||
pDMLPackage->get_ExecutionPlan()->filters(pt);
|
||||
|
||||
if (fDflg) cout << "ep: " << *pDMLPackage->get_ExecutionPlan() << endl;
|
||||
}
|
||||
|
||||
ByteStream bytestream;
|
||||
pDMLPackage->write(bytestream);
|
||||
delete pDMLPackage;
|
||||
ByteStream::octbyte rows;
|
||||
|
||||
rc = DMLSend(bytestream, rows);
|
||||
|
||||
if (isDML && fVflg)
|
||||
cout << rows << " rows affected" << endl;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int DMLIF::DMLSend(ByteStream& bytestream, ByteStream::octbyte& rows)
|
||||
{
|
||||
ByteStream::byte b;
|
||||
string errorMsg;
|
||||
try
|
||||
{
|
||||
fMqp->connect();
|
||||
fMqp->write(bytestream);
|
||||
bytestream = fMqp->read();
|
||||
fMqp->shutdown();
|
||||
if (fDflg) cout << "read " << bytestream.length() << " bytes from DMLProc" << endl;
|
||||
bytestream >> b;
|
||||
if (fDflg) cout << "b = " << (int)b << endl;
|
||||
bytestream >> rows;
|
||||
if (fDflg) cout << "rows = " << rows << endl;
|
||||
bytestream >> errorMsg;
|
||||
if (fDflg) cout << "errorMsg = " << errorMsg << endl;
|
||||
}
|
||||
catch (runtime_error& rex)
|
||||
{
|
||||
cerr << "runtime_error in engine: " << rex.what() << endl;
|
||||
return -1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
cerr << "uknown error in engine" << endl;
|
||||
return -1;
|
||||
}
|
||||
ByteStream::byte b;
|
||||
string errorMsg;
|
||||
|
||||
if (b != 0)
|
||||
{
|
||||
cerr << "DMLProc error: " << errorMsg << endl;
|
||||
return -1;
|
||||
}
|
||||
try
|
||||
{
|
||||
fMqp->connect();
|
||||
fMqp->write(bytestream);
|
||||
bytestream = fMqp->read();
|
||||
fMqp->shutdown();
|
||||
|
||||
return 0;
|
||||
if (fDflg) cout << "read " << bytestream.length() << " bytes from DMLProc" << endl;
|
||||
|
||||
bytestream >> b;
|
||||
|
||||
if (fDflg) cout << "b = " << (int)b << endl;
|
||||
|
||||
bytestream >> rows;
|
||||
|
||||
if (fDflg) cout << "rows = " << rows << endl;
|
||||
|
||||
bytestream >> errorMsg;
|
||||
|
||||
if (fDflg) cout << "errorMsg = " << errorMsg << endl;
|
||||
}
|
||||
catch (runtime_error& rex)
|
||||
{
|
||||
cerr << "runtime_error in engine: " << rex.what() << endl;
|
||||
return -1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
cerr << "uknown error in engine" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (b != 0)
|
||||
{
|
||||
cerr << "DMLProc error: " << errorMsg << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DMLIF::rf2Start(const string& sn)
|
||||
{
|
||||
fSchema = sn;
|
||||
fOFilterStr = "";
|
||||
fLFilterStr = "";
|
||||
fOPt = 0;
|
||||
fLPt = 0;
|
||||
fSchema = sn;
|
||||
fOFilterStr = "";
|
||||
fLFilterStr = "";
|
||||
fOPt = 0;
|
||||
fLPt = 0;
|
||||
}
|
||||
|
||||
void DMLIF::rf2Add(int64_t okey)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << okey;
|
||||
string okeyStr(oss.str());
|
||||
ostringstream oss;
|
||||
oss << okey;
|
||||
string okeyStr(oss.str());
|
||||
|
||||
if (fOFilterStr.empty())
|
||||
{
|
||||
fOFilterStr = "o_orderkey=" + okeyStr;
|
||||
ReturnedColumn* rc1 = new SimpleColumn(fSchema, "orders", "o_orderkey", fSessionID);
|
||||
ReturnedColumn* rc2 = new ConstantColumn(okeyStr, ConstantColumn::NUM);
|
||||
SOP sop(new Operator("="));
|
||||
ConstantFilter* cf = new ConstantFilter(sop, rc1, rc2);
|
||||
sop.reset(new Operator("or"));
|
||||
cf->op(sop);
|
||||
fOPt = new ParseTree(cf);
|
||||
}
|
||||
else
|
||||
{
|
||||
fOFilterStr += " or o_orderkey=" + okeyStr;
|
||||
ReturnedColumn* rc1 = new SimpleColumn(fSchema, "orders", "o_orderkey", fSessionID);
|
||||
ReturnedColumn* rc2 = new ConstantColumn(okeyStr, ConstantColumn::NUM);
|
||||
SOP sop(new Operator("="));
|
||||
ConstantFilter* cf = dynamic_cast<ConstantFilter*>(fOPt->data());
|
||||
cf->pushFilter(new SimpleFilter(sop, rc1, rc2));
|
||||
}
|
||||
if (fLFilterStr.empty())
|
||||
{
|
||||
fLFilterStr = "l_orderkey=" + okeyStr;
|
||||
ReturnedColumn* rc1 = new SimpleColumn(fSchema, "lineitem", "l_orderkey", fSessionID);
|
||||
ReturnedColumn* rc2 = new ConstantColumn(okeyStr, ConstantColumn::NUM);
|
||||
SOP sop(new Operator("="));
|
||||
ConstantFilter* cf = new ConstantFilter(sop, rc1, rc2);
|
||||
sop.reset(new Operator("or"));
|
||||
cf->op(sop);
|
||||
fLPt = new ParseTree(cf);
|
||||
}
|
||||
else
|
||||
{
|
||||
fLFilterStr += " or l_orderkey=" + okeyStr;
|
||||
ReturnedColumn* rc1 = new SimpleColumn(fSchema, "lineitem", "l_orderkey", fSessionID);
|
||||
ReturnedColumn* rc2 = new ConstantColumn(okeyStr, ConstantColumn::NUM);
|
||||
SOP sop(new Operator("="));
|
||||
ConstantFilter* cf = dynamic_cast<ConstantFilter*>(fLPt->data());
|
||||
cf->pushFilter(new SimpleFilter(sop, rc1, rc2));
|
||||
}
|
||||
if (fOFilterStr.empty())
|
||||
{
|
||||
fOFilterStr = "o_orderkey=" + okeyStr;
|
||||
ReturnedColumn* rc1 = new SimpleColumn(fSchema, "orders", "o_orderkey", fSessionID);
|
||||
ReturnedColumn* rc2 = new ConstantColumn(okeyStr, ConstantColumn::NUM);
|
||||
SOP sop(new Operator("="));
|
||||
ConstantFilter* cf = new ConstantFilter(sop, rc1, rc2);
|
||||
sop.reset(new Operator("or"));
|
||||
cf->op(sop);
|
||||
fOPt = new ParseTree(cf);
|
||||
}
|
||||
else
|
||||
{
|
||||
fOFilterStr += " or o_orderkey=" + okeyStr;
|
||||
ReturnedColumn* rc1 = new SimpleColumn(fSchema, "orders", "o_orderkey", fSessionID);
|
||||
ReturnedColumn* rc2 = new ConstantColumn(okeyStr, ConstantColumn::NUM);
|
||||
SOP sop(new Operator("="));
|
||||
ConstantFilter* cf = dynamic_cast<ConstantFilter*>(fOPt->data());
|
||||
cf->pushFilter(new SimpleFilter(sop, rc1, rc2));
|
||||
}
|
||||
|
||||
if (fLFilterStr.empty())
|
||||
{
|
||||
fLFilterStr = "l_orderkey=" + okeyStr;
|
||||
ReturnedColumn* rc1 = new SimpleColumn(fSchema, "lineitem", "l_orderkey", fSessionID);
|
||||
ReturnedColumn* rc2 = new ConstantColumn(okeyStr, ConstantColumn::NUM);
|
||||
SOP sop(new Operator("="));
|
||||
ConstantFilter* cf = new ConstantFilter(sop, rc1, rc2);
|
||||
sop.reset(new Operator("or"));
|
||||
cf->op(sop);
|
||||
fLPt = new ParseTree(cf);
|
||||
}
|
||||
else
|
||||
{
|
||||
fLFilterStr += " or l_orderkey=" + okeyStr;
|
||||
ReturnedColumn* rc1 = new SimpleColumn(fSchema, "lineitem", "l_orderkey", fSessionID);
|
||||
ReturnedColumn* rc2 = new ConstantColumn(okeyStr, ConstantColumn::NUM);
|
||||
SOP sop(new Operator("="));
|
||||
ConstantFilter* cf = dynamic_cast<ConstantFilter*>(fLPt->data());
|
||||
cf->pushFilter(new SimpleFilter(sop, rc1, rc2));
|
||||
}
|
||||
}
|
||||
|
||||
int DMLIF::rf2Send()
|
||||
{
|
||||
if (fOFilterStr.empty())
|
||||
return -1;
|
||||
if (fOFilterStr.empty())
|
||||
return -1;
|
||||
|
||||
int rc = 0;
|
||||
string dmlstr;
|
||||
dmlstr = "delete from " + fSchema + ".orders where " + fOFilterStr + ';';
|
||||
if (fDflg) cout << dmlstr << endl;
|
||||
int rc = 0;
|
||||
string dmlstr;
|
||||
dmlstr = "delete from " + fSchema + ".orders where " + fOFilterStr + ';';
|
||||
|
||||
VendorDMLStatement dmlStmt(dmlstr, fSessionID);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
if (pDMLPackage == 0)
|
||||
{
|
||||
cerr << "Failed to parse statement: " << dmlstr << endl;
|
||||
return -1;
|
||||
}
|
||||
if (fDflg) cout << dmlstr << endl;
|
||||
|
||||
SRCP srcp(new SimpleColumn(fSchema, "orders", "o_orderkey", fSessionID));
|
||||
CalpontSelectExecutionPlan::ColumnMap cm;
|
||||
cm.insert(make_pair("o_orderkey", srcp));
|
||||
pDMLPackage->get_ExecutionPlan()->columnMap(cm);
|
||||
CalpontSelectExecutionPlan::ReturnedColumnList rcl;
|
||||
rcl.push_back(srcp);
|
||||
pDMLPackage->get_ExecutionPlan()->returnedCols(rcl);
|
||||
pDMLPackage->get_ExecutionPlan()->sessionID(fSessionID);
|
||||
pDMLPackage->get_ExecutionPlan()->traceFlags(fTflg);
|
||||
SessionManager sm;
|
||||
BRM::TxnID txnid = sm.getTxnID(fSessionID);
|
||||
if (!txnid.valid)
|
||||
txnid = sm.newTxnID(fSessionID);
|
||||
pDMLPackage->get_ExecutionPlan()->txnID(txnid.id);
|
||||
pDMLPackage->get_ExecutionPlan()->verID(sm.verID());
|
||||
pDMLPackage->get_ExecutionPlan()->filters(fOPt);
|
||||
if (fDflg) cout << "ep: " << *pDMLPackage->get_ExecutionPlan() << endl;
|
||||
VendorDMLStatement dmlStmt(dmlstr, fSessionID);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
|
||||
|
||||
ByteStream bytestream;
|
||||
pDMLPackage->write(bytestream);
|
||||
delete pDMLPackage;
|
||||
pDMLPackage = 0;
|
||||
ByteStream::octbyte rows = 0;
|
||||
if (pDMLPackage == 0)
|
||||
{
|
||||
cerr << "Failed to parse statement: " << dmlstr << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = DMLSend(bytestream, rows);
|
||||
SRCP srcp(new SimpleColumn(fSchema, "orders", "o_orderkey", fSessionID));
|
||||
CalpontSelectExecutionPlan::ColumnMap cm;
|
||||
cm.insert(make_pair("o_orderkey", srcp));
|
||||
pDMLPackage->get_ExecutionPlan()->columnMap(cm);
|
||||
CalpontSelectExecutionPlan::ReturnedColumnList rcl;
|
||||
rcl.push_back(srcp);
|
||||
pDMLPackage->get_ExecutionPlan()->returnedCols(rcl);
|
||||
pDMLPackage->get_ExecutionPlan()->sessionID(fSessionID);
|
||||
pDMLPackage->get_ExecutionPlan()->traceFlags(fTflg);
|
||||
SessionManager sm;
|
||||
BRM::TxnID txnid = sm.getTxnID(fSessionID);
|
||||
|
||||
if (fVflg)
|
||||
cout << rows << " rows affected" << endl;
|
||||
if (!txnid.valid)
|
||||
txnid = sm.newTxnID(fSessionID);
|
||||
|
||||
dmlstr = "delete from " + fSchema + ".lineitem where " + fLFilterStr + ';';
|
||||
if (fDflg) cout << dmlstr << endl;
|
||||
pDMLPackage->get_ExecutionPlan()->txnID(txnid.id);
|
||||
pDMLPackage->get_ExecutionPlan()->verID(sm.verID());
|
||||
pDMLPackage->get_ExecutionPlan()->filters(fOPt);
|
||||
|
||||
VendorDMLStatement dmlStmt1(dmlstr, fSessionID);
|
||||
pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt1);
|
||||
if (pDMLPackage == 0)
|
||||
{
|
||||
cerr << "Failed to parse statement: " << dmlstr << endl;
|
||||
return -1;
|
||||
}
|
||||
if (fDflg) cout << "ep: " << *pDMLPackage->get_ExecutionPlan() << endl;
|
||||
|
||||
srcp.reset(new SimpleColumn(fSchema, "lineitem", "l_orderkey", fSessionID));
|
||||
cm.clear();
|
||||
cm.insert(make_pair("l_orderkey", srcp));
|
||||
pDMLPackage->get_ExecutionPlan()->columnMap(cm);
|
||||
rcl.clear();
|
||||
rcl.push_back(srcp);
|
||||
pDMLPackage->get_ExecutionPlan()->returnedCols(rcl);
|
||||
pDMLPackage->get_ExecutionPlan()->sessionID(fSessionID);
|
||||
pDMLPackage->get_ExecutionPlan()->traceFlags(fTflg);
|
||||
txnid = sm.getTxnID(fSessionID);
|
||||
if (!txnid.valid)
|
||||
txnid = sm.newTxnID(fSessionID);
|
||||
pDMLPackage->get_ExecutionPlan()->txnID(txnid.id);
|
||||
pDMLPackage->get_ExecutionPlan()->verID(sm.verID());
|
||||
pDMLPackage->get_ExecutionPlan()->filters(fLPt);
|
||||
if (fDflg) cout << "ep: " << *pDMLPackage->get_ExecutionPlan() << endl;
|
||||
ByteStream bytestream;
|
||||
pDMLPackage->write(bytestream);
|
||||
delete pDMLPackage;
|
||||
pDMLPackage = 0;
|
||||
ByteStream::octbyte rows = 0;
|
||||
|
||||
bytestream.reset();
|
||||
pDMLPackage->write(bytestream);
|
||||
delete pDMLPackage;
|
||||
pDMLPackage = 0;
|
||||
rows = 0;
|
||||
rc = DMLSend(bytestream, rows);
|
||||
|
||||
rc = DMLSend(bytestream, rows);
|
||||
if (fVflg)
|
||||
cout << rows << " rows affected" << endl;
|
||||
|
||||
if (fVflg)
|
||||
cout << rows << " rows affected" << endl;
|
||||
dmlstr = "delete from " + fSchema + ".lineitem where " + fLFilterStr + ';';
|
||||
|
||||
return 0;
|
||||
if (fDflg) cout << dmlstr << endl;
|
||||
|
||||
VendorDMLStatement dmlStmt1(dmlstr, fSessionID);
|
||||
pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt1);
|
||||
|
||||
if (pDMLPackage == 0)
|
||||
{
|
||||
cerr << "Failed to parse statement: " << dmlstr << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
srcp.reset(new SimpleColumn(fSchema, "lineitem", "l_orderkey", fSessionID));
|
||||
cm.clear();
|
||||
cm.insert(make_pair("l_orderkey", srcp));
|
||||
pDMLPackage->get_ExecutionPlan()->columnMap(cm);
|
||||
rcl.clear();
|
||||
rcl.push_back(srcp);
|
||||
pDMLPackage->get_ExecutionPlan()->returnedCols(rcl);
|
||||
pDMLPackage->get_ExecutionPlan()->sessionID(fSessionID);
|
||||
pDMLPackage->get_ExecutionPlan()->traceFlags(fTflg);
|
||||
txnid = sm.getTxnID(fSessionID);
|
||||
|
||||
if (!txnid.valid)
|
||||
txnid = sm.newTxnID(fSessionID);
|
||||
|
||||
pDMLPackage->get_ExecutionPlan()->txnID(txnid.id);
|
||||
pDMLPackage->get_ExecutionPlan()->verID(sm.verID());
|
||||
pDMLPackage->get_ExecutionPlan()->filters(fLPt);
|
||||
|
||||
if (fDflg) cout << "ep: " << *pDMLPackage->get_ExecutionPlan() << endl;
|
||||
|
||||
bytestream.reset();
|
||||
pDMLPackage->write(bytestream);
|
||||
delete pDMLPackage;
|
||||
pDMLPackage = 0;
|
||||
rows = 0;
|
||||
|
||||
rc = DMLSend(bytestream, rows);
|
||||
|
||||
if (fVflg)
|
||||
cout << rows << " rows affected" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,35 +33,35 @@ namespace dmlif
|
||||
class DMLIF
|
||||
{
|
||||
public:
|
||||
DMLIF(uint32_t sessionid, uint32_t tflg=0, bool dflg=false, bool vflg=false);
|
||||
~DMLIF();
|
||||
DMLIF(uint32_t sessionid, uint32_t tflg = 0, bool dflg = false, bool vflg = false);
|
||||
~DMLIF();
|
||||
|
||||
int sendOne(const std::string& stmt);
|
||||
int sendOne(const std::string& stmt);
|
||||
|
||||
void rf2Start(const std::string& sn);
|
||||
void rf2Add(int64_t okey);
|
||||
int rf2Send();
|
||||
void rf2Start(const std::string& sn);
|
||||
void rf2Add(int64_t okey);
|
||||
int rf2Send();
|
||||
|
||||
protected:
|
||||
int DMLSend(messageqcpp::ByteStream& bytestream, messageqcpp::ByteStream::octbyte& rows);
|
||||
int DMLSend(messageqcpp::ByteStream& bytestream, messageqcpp::ByteStream::octbyte& rows);
|
||||
|
||||
private:
|
||||
//DMLIF(const DMLIF& rhs);
|
||||
//DMLIF& operator=(const DMLIF& rhs);
|
||||
//DMLIF(const DMLIF& rhs);
|
||||
//DMLIF& operator=(const DMLIF& rhs);
|
||||
|
||||
uint32_t fSessionID;
|
||||
uint32_t fTflg;
|
||||
bool fDflg;
|
||||
bool fVflg;
|
||||
uint32_t fSessionID;
|
||||
uint32_t fTflg;
|
||||
bool fDflg;
|
||||
bool fVflg;
|
||||
|
||||
boost::scoped_ptr<messageqcpp::MessageQueueClient> fMqp;
|
||||
boost::scoped_ptr<messageqcpp::MessageQueueClient> fMqp;
|
||||
|
||||
std::string fSchema;
|
||||
std::string fOFilterStr;
|
||||
std::string fLFilterStr;
|
||||
std::string fSchema;
|
||||
std::string fOFilterStr;
|
||||
std::string fLFilterStr;
|
||||
|
||||
execplan::ParseTree* fOPt;
|
||||
execplan::ParseTree* fLPt;
|
||||
execplan::ParseTree* fOPt;
|
||||
execplan::ParseTree* fLPt;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ using namespace boost;
|
||||
namespace tpch
|
||||
{
|
||||
|
||||
RF2::RF2(const string& sn, uint32_t sid, uint32_t tflg, int c, int p, bool d, bool v) :
|
||||
fSchema(sn), fSessionID(sid), fTflg(tflg), fIntvl(c), fPack(p), fDflg(d), fVflg(v)
|
||||
RF2::RF2(const string& sn, uint32_t sid, uint32_t tflg, int c, int p, bool d, bool v) :
|
||||
fSchema(sn), fSessionID(sid), fTflg(tflg), fIntvl(c), fPack(p), fDflg(d), fVflg(v)
|
||||
{
|
||||
}
|
||||
|
||||
@ -41,38 +41,47 @@ RF2::~RF2()
|
||||
|
||||
int RF2::run(istream& in)
|
||||
{
|
||||
const streamsize ilinelen = 1024;
|
||||
scoped_array<char> iline(new char[ilinelen]);
|
||||
int cnt = 0;
|
||||
dmlif::DMLIF dmlif(fSessionID, fTflg, fDflg, fVflg);
|
||||
for (;;)
|
||||
{
|
||||
dmlif.rf2Start(fSchema);
|
||||
for (int i = 0; i < fPack; i++)
|
||||
{
|
||||
in.getline(iline.get(), ilinelen);
|
||||
if (in.eof())
|
||||
break;
|
||||
typedef char_separator<char> cs;
|
||||
typedef tokenizer<cs> tk;
|
||||
cs sep("|");
|
||||
tk tok(string(iline.get()), sep);
|
||||
tk::iterator iter = tok.begin();
|
||||
idbassert(iter != tok.end());
|
||||
string keystr = *iter; ++iter;
|
||||
//idbassert(iter == tok.end());
|
||||
int64_t okey = strtol(keystr.c_str(), 0, 0);
|
||||
dmlif.rf2Add(okey);
|
||||
}
|
||||
dmlif.rf2Send();
|
||||
cnt++;
|
||||
if ((cnt % fIntvl) == 0)
|
||||
dmlif.sendOne("COMMIT;");
|
||||
if (in.eof())
|
||||
break;
|
||||
}
|
||||
dmlif.sendOne("COMMIT;");
|
||||
return 0;
|
||||
const streamsize ilinelen = 1024;
|
||||
scoped_array<char> iline(new char[ilinelen]);
|
||||
int cnt = 0;
|
||||
dmlif::DMLIF dmlif(fSessionID, fTflg, fDflg, fVflg);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
dmlif.rf2Start(fSchema);
|
||||
|
||||
for (int i = 0; i < fPack; i++)
|
||||
{
|
||||
in.getline(iline.get(), ilinelen);
|
||||
|
||||
if (in.eof())
|
||||
break;
|
||||
|
||||
typedef char_separator<char> cs;
|
||||
typedef tokenizer<cs> tk;
|
||||
cs sep("|");
|
||||
tk tok(string(iline.get()), sep);
|
||||
tk::iterator iter = tok.begin();
|
||||
idbassert(iter != tok.end());
|
||||
string keystr = *iter;
|
||||
++iter;
|
||||
//idbassert(iter == tok.end());
|
||||
int64_t okey = strtol(keystr.c_str(), 0, 0);
|
||||
dmlif.rf2Add(okey);
|
||||
}
|
||||
|
||||
dmlif.rf2Send();
|
||||
cnt++;
|
||||
|
||||
if ((cnt % fIntvl) == 0)
|
||||
dmlif.sendOne("COMMIT;");
|
||||
|
||||
if (in.eof())
|
||||
break;
|
||||
}
|
||||
|
||||
dmlif.sendOne("COMMIT;");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,23 +32,23 @@ namespace tpch
|
||||
class RF2
|
||||
{
|
||||
public:
|
||||
RF2(const std::string& sn, uint32_t sid, uint32_t tflg=0, int c=std::numeric_limits<int>::max(),
|
||||
int p=1, bool d=false, bool v=false);
|
||||
~RF2();
|
||||
RF2(const std::string& sn, uint32_t sid, uint32_t tflg = 0, int c = std::numeric_limits<int>::max(),
|
||||
int p = 1, bool d = false, bool v = false);
|
||||
~RF2();
|
||||
|
||||
int run(std::istream& in);
|
||||
int run(std::istream& in);
|
||||
|
||||
private:
|
||||
//RF2(const RF2& rhs);
|
||||
//RF2& operator=(const RF2& rhs);
|
||||
//RF2(const RF2& rhs);
|
||||
//RF2& operator=(const RF2& rhs);
|
||||
|
||||
std::string fSchema;
|
||||
uint32_t fSessionID;
|
||||
uint32_t fTflg;
|
||||
int fIntvl;
|
||||
int fPack;
|
||||
bool fDflg;
|
||||
bool fVflg;
|
||||
std::string fSchema;
|
||||
uint32_t fSessionID;
|
||||
uint32_t fTflg;
|
||||
int fIntvl;
|
||||
int fPack;
|
||||
bool fDflg;
|
||||
bool fVflg;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user