├── LICENSE ├── Makefile ├── README.md ├── chBenchmark.cpp └── src ├── AnalyticalStatistic.cpp ├── AnalyticalStatistic.h ├── Config.cpp ├── Config.h ├── DataSource.cpp ├── DataSource.h ├── DbcTools.cpp ├── DbcTools.h ├── Log.cpp ├── Log.h ├── Queries.cpp ├── Queries.h ├── Schema.cpp ├── Schema.h ├── TransactionalStatistic.cpp ├── TransactionalStatistic.h ├── Transactions.cpp ├── Transactions.h ├── TupleGen.cpp ├── TupleGen.h └── dialect ├── Dialect.h ├── DialectStrategy.cpp ├── DialectStrategy.h ├── HanaDialect.h └── MySqlDialect.h /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Florian Wolf, SAP AG 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #Copyright 2014 Florian Wolf, SAP AG 2 | # 3 | #Licensed under the Apache License, Version 2.0 (the "License"); 4 | #you may not use this file except in compliance with the License. 5 | #You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | #Unless required by applicable law or agreed to in writing, software 10 | #distributed under the License is distributed on an "AS IS" BASIS, 11 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | #See the License for the specific language governing permissions and 13 | #limitations under the License. 14 | 15 | CC=g++ 16 | CXXFLAGS=-c -std=c++11 -O2 -Wall -g 17 | LDFLAGS=-lodbc -pthread 18 | 19 | SOURCES=src/AnalyticalStatistic.cpp src/TransactionalStatistic.cpp src/dialect/DialectStrategy.cpp src/Config.cpp src/Log.cpp src/DbcTools.cpp src/DataSource.cpp src/TupleGen.cpp src/Schema.cpp src/Queries.cpp src/Transactions.cpp chBenchmark.cpp 20 | OBJECTS=$(SOURCES:.cpp=.o) 21 | EXECUTABLE=chBenchmark 22 | 23 | all: $(SOURCES) $(EXECUTABLE) 24 | 25 | $(EXECUTABLE): $(OBJECTS) 26 | $(CC) $(OBJECTS) -o $@ $(LDFLAGS) 27 | 28 | .cpp.o: 29 | $(CC) $(CXXFLAGS) $< -o $@ -I/usr/local/unixODBC/include 30 | 31 | clean: 32 | rm *.o 33 | rm src/*.o 34 | rm src/dialect/*.o 35 | rm chBenchmark 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | This is a runnable and robust version of CH-benchmark focusing on Hybrid Transactional/Analytical Processing which was originally published by 3 | [The Mixed Workload CH-benCHmark.](https://db.in.tum.de/research/projects/CHbenCHmark/?lang=en) 4 | 5 | We committed program optimization and solved several bugs related to memory leaks and now this repo is finely adapted to latest version of software and hardware systems. 6 | 7 | 8 | 9 | ## Getting Started 10 | 11 | This implementation of the CH-benCHmark was created for the UNIX platform. It uses unixODBC 12 | and pthreads. 13 | Additionally, it can handle different SQL dialects. 14 | 15 | 16 | 17 | 18 | To build it: 19 | 20 | requirements are: 21 | 22 | - libodbc and libodbc-dev (Ubuntu 18.04 and above) 23 | - GNU make (version 3.81+) 24 | - c++11 compiler (gcc 4.7 and above) 25 | 26 | 27 | ```bash 28 | 1. Adjust "Makefile" if needed, for example: 29 | - CC to appropriate c++11 compiler 30 | - add -L/path/to/libodbc/directory to LDFLAGS 31 | 32 | 2. make 33 | ``` 34 | 35 | 36 | 37 | To run it: 38 | 39 | ```bash 40 | 1. Make sure all required libraries can be found, for example: 41 | - export LD_LIBRARY_PATH=/path/to/libodbc/directory 42 | 43 | 2. Make sure you can connect to the system under test using unixODBC's "isql": 44 | - isql yourDataSourceName yourDatabaseUser yourPassword 45 | 46 | 3. Create initial database as CSV files: 47 | chBenchmark 48 | -csv 49 | -wh 50 | -pa 51 | 52 | example: chBenchmark -csv -wh 50 -pa /path/to/any/directory 53 | 54 | 4. Run test: 55 | chBenchmark 56 | -run 57 | -dsn 58 | -usr 59 | -pwd 60 | -a 61 | -t 62 | -wd 63 | -td 64 | -pa 65 | -op 66 | 67 | example: chBenchmark -run -dsn yourDataSourceName -usr yourDatabaseUser -pwd yourPassword 68 | -a 5 -t 10 -wd 60 -td 300 -pa /path/to/any/directory -op /path/to/any/directory 69 | ``` 70 | 71 | 72 | # Contributing 73 | 74 | This project so far provides DIALECT support for [SAP HANA](https://www.sap.com/sea/products/s4hana-erp.html?%20campaigncode=crm-ya22-int-1273119&source=ppc-sg-google_ads-search-71700000089530855-58700007563534098-s4hana_s4em-s4erp--&dfa=1&gclid=Cj0KCQiA64GRBhCZARIsAHOLriLy7FuLrAHo0F2Jfyq_iz_XwfOzbgO0qhZDXC_szZqYKHz_TKXDyF8aAjuSEALw_wcB&gclsrc=aw.ds) and [MySQL](https://www.mysql.com/). We welcome anyone to complete dialect support for other HTAP databases. 75 | 76 | To add a new dialect: 77 | 78 | - put a new dialect file in the "dialect" directory 79 | - implement the interface given in "dialect/Dialect.h" 80 | - see "dialect/HanaDialect.h" as example 81 | - modify the "DialectStrategy::getInstance()" function in "dialect/DialectStrategy.cpp" 82 | 83 | -------------------------------------------------------------------------------- /chBenchmark.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "src/AnalyticalStatistic.h" 18 | #include "src/Config.h" 19 | #include "src/DataSource.h" 20 | #include "src/DbcTools.h" 21 | #include "src/Log.h" 22 | #include "src/Queries.h" 23 | #include "src/Schema.h" 24 | #include "src/TransactionalStatistic.h" 25 | #include "src/Transactions.h" 26 | #include "src/TupleGen.h" 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | using namespace std; 37 | 38 | bool dbgen(){ 39 | 40 | DataSource::initialize(); 41 | TupleGen::openOutputFiles(); 42 | 43 | for(int iId=1; iId<=100000; iId++){ 44 | //Item 45 | TupleGen::genItem(iId); 46 | } 47 | 48 | int oId; 49 | int olCount; 50 | string customerTime = ""; 51 | string orderTime; 52 | for(int wId=1; wId<=Config::getWarehouseCount(); wId++){ 53 | //Warehouse 54 | TupleGen::genWarehouse(wId); 55 | 56 | for(int iId=1; iId<=100000; iId++){ 57 | //Stock 58 | TupleGen::genStock(iId, wId); 59 | } 60 | 61 | for(int dId=1; dId<=10; dId++){ 62 | //District 63 | TupleGen::genDistrict(dId, wId); 64 | for(int cId=1; cId<=3000; cId++){ 65 | //Customer 66 | if(customerTime == "") 67 | customerTime = DataSource::getCurrentTimeString(); 68 | TupleGen::genCustomer(cId, dId, wId,customerTime); 69 | 70 | //History 71 | TupleGen::genHistory(cId, dId, wId); 72 | 73 | //Order 74 | oId = DataSource::permute(cId,1,3000); 75 | olCount = DataSource::nextOderlineCount(); 76 | orderTime = DataSource::getCurrentTimeString(); 77 | TupleGen::genOrder(oId, dId, wId, cId, olCount, orderTime); 78 | 79 | for(int olNumber=1; olNumber<=olCount; olNumber++){ 80 | //Orderline 81 | TupleGen::genOrderline(oId, dId, wId, olNumber, orderTime); 82 | } 83 | 84 | //Neworder 85 | if(oId>2100){ 86 | TupleGen::genNeworder(oId, dId, wId); 87 | } 88 | } 89 | } 90 | } 91 | 92 | //Region 93 | for(int rId=0; rId<5; rId++){ 94 | TupleGen::genRegion(rId,DataSource::getRegion(rId)); 95 | } 96 | 97 | //Nation 98 | for(int i=0; i<62; i++){ 99 | TupleGen::genNation(DataSource::getNation(i)); 100 | } 101 | 102 | //Supplier 103 | for(int suId=0; suId<10000; suId++){ 104 | TupleGen::genSupplier(suId); 105 | } 106 | 107 | TupleGen::closeOutputFiles(); 108 | 109 | return 1; 110 | } 111 | 112 | typedef struct _threadParameters{ 113 | pthread_barrier_t* barStart; 114 | int* runState; 115 | int threadId; 116 | SQLHENV* hEnv; 117 | void* stat; 118 | } threadParameters; 119 | 120 | void* analyticalThread(void* args){ 121 | 122 | threadParameters* prm = (threadParameters*) args; 123 | AnalyticalStatistic* aStat = (AnalyticalStatistic*) prm->stat; 124 | 125 | bool b; 126 | long query=0; 127 | int q=0; 128 | 129 | SQLHDBC hDBC = 0; 130 | if(!DbcTools::connect(*(prm->hEnv), hDBC)){ 131 | exit(1); 132 | } 133 | 134 | Queries* queries = new Queries(); 135 | if(!queries->prepareStatements(hDBC)){ 136 | exit(1); 137 | } 138 | 139 | pthread_barrier_wait(prm->barStart); 140 | 141 | if(*(prm->runState)==1){ 142 | Log::l1() << Log::tm() << "-analytical " << prm->threadId << ": start warmup\n"; 143 | while(*(prm->runState)==1){ 144 | q=(query%22)+1; 145 | 146 | Log::l1() << Log::tm() << "-analytical " << prm->threadId << ": TPC-H " << q << "\n"; 147 | queries->executeTPCH(hDBC,q); 148 | query++; 149 | } 150 | } 151 | if(*(prm->runState)==2){ 152 | Log::l1() << Log::tm() << "-analytical " << prm->threadId << ": start test\n"; 153 | while(*(prm->runState)==2){ 154 | q=(query%22)+1; 155 | 156 | Log::l1() << Log::tm() << "-analytical " << prm->threadId << ": TPC-H " << q << "\n"; 157 | b = queries->executeTPCH(hDBC,q); 158 | aStat->executeTPCHSuccess(q,b); 159 | query++; 160 | } 161 | } 162 | 163 | Log::l1() << Log::tm() << "-analytical " << prm->threadId << ": exit\n"; 164 | return NULL; 165 | } 166 | 167 | void* transactionalThread(void* args){ 168 | 169 | threadParameters* prm = (threadParameters*) args; 170 | TransactionalStatistic* tStat = (TransactionalStatistic*) prm->stat; 171 | 172 | SQLHDBC hDBC = 0; 173 | if(!DbcTools::connect(*(prm->hEnv), hDBC)){ 174 | exit(1); 175 | } 176 | 177 | Transactions* transactions = new Transactions(); 178 | if(!transactions->prepareStatements(hDBC)){ 179 | exit(1); 180 | } 181 | 182 | bool b; 183 | int decision=0; 184 | 185 | if(DbcTools::autoCommitOff(hDBC)){ 186 | 187 | pthread_barrier_wait(prm->barStart); 188 | 189 | if(*(prm->runState)==1){ 190 | Log::l1() << Log::tm() << "-transactional " << prm->threadId << ": start warmup\n"; 191 | while(*(prm->runState)==1){ 192 | DataSource::randomUniformInt(1,100,decision); 193 | if(decision<=44 && (*(prm->runState)==1)){ 194 | Log::l1() << Log::tm() << "-transactional " << prm->threadId << ": NewOrder\n"; 195 | transactions->executeNewOrder(hDBC); 196 | } 197 | DataSource::randomUniformInt(1,100,decision); 198 | if(decision<=44 && (*(prm->runState)==1)){ 199 | Log::l1() << Log::tm() << "-transactional " << prm->threadId << ": Payment\n"; 200 | // 201 | transactions->executePayment(hDBC); 202 | } 203 | DataSource::randomUniformInt(1,100,decision); 204 | if(decision<=4 && (*(prm->runState)==1)){ 205 | Log::l1() << Log::tm() << "-transactional " << prm->threadId << ": OrderStatus\n"; 206 | transactions->executeOrderStatus(hDBC); 207 | } 208 | DataSource::randomUniformInt(1,100,decision); 209 | if(decision<=4 && (*(prm->runState)==1)){ 210 | Log::l1() << Log::tm() << "-transactional " << prm->threadId << ": Delivery\n"; 211 | transactions->executeDelivery(hDBC); 212 | } 213 | DataSource::randomUniformInt(1,100,decision); 214 | if(decision<=4 && (*(prm->runState)==1)){ 215 | Log::l1() << Log::tm() << "-transactional " << prm->threadId << ": StockLevel\n"; 216 | transactions->executeStockLevel(hDBC); 217 | } 218 | } 219 | } 220 | 221 | if(*(prm->runState)==2){ 222 | Log::l1() << Log::tm() << "-transactional " << prm->threadId << ": start test\n"; 223 | while(*(prm->runState)==2){ 224 | DataSource::randomUniformInt(1,100,decision); 225 | if(decision<=44 && (*(prm->runState)==2)){ 226 | Log::l1() << Log::tm() << "-transactional " << prm->threadId << ": NewOrder\n"; 227 | b = transactions->executeNewOrder(hDBC); 228 | tStat->executeTPCCSuccess(1,b); 229 | } 230 | DataSource::randomUniformInt(1,100,decision); 231 | if(decision<=44 && (*(prm->runState)==2)){ 232 | Log::l1() << Log::tm() << "-transactional " << prm->threadId << ": Payment\n"; 233 | b = transactions->executePayment(hDBC); 234 | tStat->executeTPCCSuccess(2,b); 235 | } 236 | DataSource::randomUniformInt(1,100,decision); 237 | if(decision<=4 && (*(prm->runState)==2)){ 238 | Log::l1() << Log::tm() << "-transactional " << prm->threadId << ": OrderStatus\n"; 239 | b = transactions->executeOrderStatus(hDBC); 240 | tStat->executeTPCCSuccess(3,b); 241 | } 242 | DataSource::randomUniformInt(1,100,decision); 243 | if(decision<=4 && (*(prm->runState)==2)){ 244 | Log::l1() << Log::tm() << "-transactional " << prm->threadId << ": Delivery\n"; 245 | b = transactions->executeDelivery(hDBC); 246 | tStat->executeTPCCSuccess(4,b); 247 | } 248 | DataSource::randomUniformInt(1,100,decision); 249 | if(decision<=4 && (*(prm->runState)==2)){ 250 | Log::l1() << Log::tm() << "-transactional " << prm->threadId << ": StockLevel\n"; 251 | b = transactions->executeStockLevel(hDBC); 252 | tStat->executeTPCCSuccess(5,b); 253 | } 254 | } 255 | } 256 | } 257 | 258 | Log::l1() << Log::tm() << "-transactional " << prm->threadId << ": exit\n"; 259 | return NULL; 260 | } 261 | 262 | int main(int argc, char* argv[]){ 263 | 264 | //Read config from comand line parameters 265 | if(!Config::initialize(argc,argv)) 266 | return 1; 267 | 268 | 269 | //1. Creating initial database as CSV's 270 | if(Config::getType()==1){ 271 | cout << "Generating initial database:" << endl; 272 | if(!dbgen()){ 273 | cout << "-failed" << endl; 274 | return 1; 275 | } 276 | cout << "-succeeded" << endl; 277 | } 278 | 279 | //2. Run main chBenchmark 280 | else if(Config::getType()==2){ 281 | 282 | //Initialization 283 | Log::l2() << Log::tm() << "Databasesystem:\n-initializing\n"; 284 | 285 | //connect to DBS 286 | SQLHENV hEnv = 0; 287 | DbcTools::setEnv(hEnv); 288 | SQLHDBC hDBC = 0; 289 | if(!DbcTools::connect(hEnv, hDBC)){ 290 | return 1; 291 | } 292 | 293 | //create a statement handle for initializing DBS 294 | SQLHSTMT hStmt = 0; 295 | SQLAllocHandle(SQL_HANDLE_STMT, hDBC, &hStmt); 296 | 297 | //create database schema 298 | Log::l2() << Log::tm() << "Schema creation:\n"; 299 | if(!Schema::createSchema(hStmt)){ 300 | return 1; 301 | } 302 | 303 | //import initial database from csv files 304 | Log::l2() << Log::tm() << "CSV import:\n"; 305 | if(!Schema::importCSV(hStmt)){ 306 | return 1; 307 | } 308 | 309 | //detect warehouse count of loaded initial database 310 | if(!Config::warehouseDetection(hStmt)){ 311 | return 1; 312 | } 313 | 314 | //perform a check to ensure that initial database was imported correctly 315 | if(!Schema::check(hStmt)){ 316 | return 1; 317 | } 318 | 319 | //fire additional preparation statements 320 | Log::l2() << Log::tm() << "Additional Preparation:\n"; 321 | if(!Schema::additionalPreparation(hStmt)){ 322 | return 1; 323 | } 324 | 325 | SQLFreeHandle(SQL_HANDLE_STMT, hStmt); 326 | SQLDisconnect(hDBC); 327 | SQLFreeHandle(SQL_HANDLE_DBC, hDBC); 328 | 329 | DataSource::initialize(); 330 | 331 | int runState = 0; //0=dont_run 1=warmup 2=run 332 | unsigned int count=Config::getAnalyticalClients()+Config::getTransactionalClients()+1; 333 | pthread_barrier_t barStart; 334 | pthread_barrier_init(&barStart,NULL,count); 335 | 336 | //start analytical threads and create a statistic object for each thread 337 | AnalyticalStatistic* aStat[Config::getAnalyticalClients()]; 338 | pthread_t apt[Config::getAnalyticalClients()]; 339 | threadParameters aprm[Config::getAnalyticalClients()]; 340 | for(int i=0; iaddResult(analyticalResults); 379 | } 380 | for(int i=0; iaddResult(transcationalResults); 382 | } 383 | 384 | unsigned long long qphh=analyticalResults*3600/Config::getTestDurationInS(); 385 | unsigned long long tpmc=transcationalResults*60/Config::getTestDurationInS(); 386 | 387 | ofstream resultStream; 388 | resultStream.open( (Config::getOutputPath()+"/Results.csv").c_str() ); 389 | resultStream << "System Under Test:" << Config::getDataSourceName() << endl; 390 | resultStream << "Analytical Clients:" << Config::getAnalyticalClients() << endl; 391 | resultStream << "Transactional Clients:" << Config::getTransactionalClients() << endl; 392 | resultStream << "Warmup Duration in [s]:" << Config::getWarmupDurationInS() << endl; 393 | resultStream << "Test Duration in [s]:" << Config::getTestDurationInS() << endl; 394 | resultStream << "Warehouses:" << Config::getWarehouseCount() << endl; 395 | resultStream << endl; 396 | resultStream << "OLAP Throughput in [QphH]:" << qphh << endl; 397 | resultStream << "OLTP Throughput in [tpmC]:" << tpmc << endl; 398 | resultStream.close(); 399 | Log::l2() << Log::tm() << "-results written to: " << Config::getOutputPath() << "/Results.csv\n"; 400 | 401 | Log::l2() << Log::tm() << "Wait for clients to return from database calls:\n"; 402 | for(int i=0; i\n" 418 | " -pa \n" 419 | "\n2. Run test:\n" 420 | " chBenchmark\n" 421 | " -run\n" 422 | " -dsn \n" 423 | " -usr \n" 424 | " -pwd \n" 425 | " -a \n" 426 | " -t \n" 427 | " -wd \n" 428 | " -td \n" 429 | " -pa \n" 430 | " -op \n\n"; 431 | } 432 | else{ 433 | return 1; 434 | } 435 | 436 | return 0; 437 | } 438 | -------------------------------------------------------------------------------- /src/AnalyticalStatistic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "AnalyticalStatistic.h" 18 | 19 | using namespace std; 20 | 21 | AnalyticalStatistic::AnalyticalStatistic(){ 22 | for(int i=0; i<22; i++){ 23 | executeTPCHSuccessCount[i] = 0; 24 | executeTPCHFailCount[i] = 0; 25 | } 26 | } 27 | 28 | void AnalyticalStatistic::addResult(unsigned long long& analyticalResults){ 29 | for(int i=0; i<22; i++){ 30 | analyticalResults += executeTPCHSuccessCount[i]; 31 | } 32 | } 33 | 34 | void AnalyticalStatistic::executeTPCHSuccess(int queryNumber, bool success){ 35 | if(success) 36 | executeTPCHSuccessCount[queryNumber-1]++; 37 | else 38 | executeTPCHFailCount[queryNumber-1]++; 39 | } 40 | -------------------------------------------------------------------------------- /src/AnalyticalStatistic.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef ANALYTICALSTATISTIC_H 18 | #define ANALYTICALSTATISTIC_H 19 | 20 | class AnalyticalStatistic { 21 | 22 | private: 23 | unsigned long long executeTPCHSuccessCount[22]; 24 | unsigned long long executeTPCHFailCount[22]; 25 | 26 | public: 27 | AnalyticalStatistic(); 28 | void addResult(unsigned long long& analyticalResults); 29 | void executeTPCHSuccess(int queryNumber, bool success); 30 | 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/Config.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "Config.h" 18 | #include "DbcTools.h" 19 | #include "Log.h" 20 | #include "dialect/DialectStrategy.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | using namespace std; 28 | 29 | int Config::TYPE; 30 | 31 | string Config::DATA_SOURCE_NAME; 32 | string Config::DBS_USER; 33 | string Config::DBS_PASSWORD; 34 | 35 | int Config::ANALYTICAL_CLIENTS=-1; 36 | int Config::TRANSACTIONAL_CLIENTS=-1; 37 | 38 | int Config::WAREHOUSE_COUNT=-1; 39 | int Config::WARMUP_DURATION_IN_S=-1; 40 | int Config::TEST_DURATION_IN_S=-1; 41 | string Config::INITIAL_DB_CREATION_PATH; 42 | string Config::OUTPUT_PATH; 43 | 44 | 45 | int Config::is(const char* value, int argc, char* argv[]){ 46 | for(int i=1; igetSelectCountWarehouse()); 170 | 171 | int temp = 0; 172 | SQLLEN nIdicator = 0; 173 | SQLCHAR buf[1024] = {0}; 174 | DbcTools::fetch(hStmt, buf, &nIdicator, 1, temp); 175 | WAREHOUSE_COUNT = temp; 176 | if(WAREHOUSE_COUNT == 0){ 177 | Log::l2() << Log::tm() << "-detecting warehouses failed\n"; 178 | return 0; 179 | } 180 | Log::l1() << Log::tm() << "-detected warehouses: " << WAREHOUSE_COUNT << "\n"; 181 | 182 | return 1; 183 | } 184 | 185 | int Config::getType(){ 186 | return TYPE; 187 | } 188 | 189 | string Config::getDataSourceName(){ 190 | return DATA_SOURCE_NAME; 191 | } 192 | 193 | string Config::getDbsUser(){ 194 | return DBS_USER; 195 | } 196 | 197 | string Config::getDbsPassword(){ 198 | return DBS_PASSWORD; 199 | } 200 | 201 | int Config::getAnalyticalClients(){ 202 | return ANALYTICAL_CLIENTS; 203 | } 204 | 205 | int Config::getTransactionalClients(){ 206 | return TRANSACTIONAL_CLIENTS; 207 | } 208 | 209 | int Config::getWarmupDurationInS(){ 210 | return WARMUP_DURATION_IN_S; 211 | } 212 | 213 | int Config::getTestDurationInS(){ 214 | return TEST_DURATION_IN_S; 215 | } 216 | 217 | int Config::getWarehouseCount(){ 218 | return WAREHOUSE_COUNT; 219 | } 220 | 221 | string Config::getInitialDbCreationPath(){ 222 | return INITIAL_DB_CREATION_PATH; 223 | } 224 | 225 | string Config::getOutputPath(){ 226 | return OUTPUT_PATH; 227 | } 228 | 229 | char Config::getCsvDelim(){ 230 | return CSV_DELIMITER; 231 | } 232 | 233 | -------------------------------------------------------------------------------- /src/Config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef CONFIG_H 18 | #define CONFIG_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | class Config{ 26 | 27 | private: 28 | static int TYPE; 29 | 30 | static std::string DATA_SOURCE_NAME; 31 | static std::string DBS_USER; 32 | static std::string DBS_PASSWORD; 33 | 34 | static int ANALYTICAL_CLIENTS; 35 | static int TRANSACTIONAL_CLIENTS; 36 | 37 | static int WARMUP_DURATION_IN_S; 38 | static int TEST_DURATION_IN_S; 39 | static int WAREHOUSE_COUNT; 40 | static std::string INITIAL_DB_CREATION_PATH; 41 | static std::string OUTPUT_PATH; 42 | 43 | static const char CSV_DELIMITER = '|'; 44 | 45 | static int is(const char* value, int argc, char* argv[]); 46 | static bool is(const char* value, int argc, char* argv[], int* dest); 47 | static bool is(const char* value, int argc, char* argv[], std::string* dest); 48 | 49 | public: 50 | static bool initialize(int argc, char* argv[]); 51 | static bool warehouseDetection(SQLHSTMT& hStmt); 52 | 53 | static int getType(); 54 | 55 | static std::string getDataSourceName(); 56 | static std::string getDbsUser(); 57 | static std::string getDbsPassword(); 58 | 59 | static int getAnalyticalClients(); 60 | static int getTransactionalClients(); 61 | 62 | static int getWarmupDurationInS(); 63 | static int getTestDurationInS(); 64 | static int getWarehouseCount(); 65 | 66 | static std::string getOutputPath(); 67 | static std::string getInitialDbCreationPath(); 68 | static char getCsvDelim(); 69 | 70 | }; 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/DataSource.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "Config.h" 18 | #include "DataSource.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | 28 | 29 | const Nation DataSource::nations[]={ 30 | {48, "ALGERIA", 0},{49, "ARGENTINA", 1},{50, "BRAZIL", 1}, {51, "CANADA", 1}, 31 | {52, "EGYPT", 4},{53, "ETHIOPIA", 0},{54, "FRANCE", 3},{55, "GERMANY", 3}, 32 | {56, "INDIA", 2},{57, "INDONESIA", 2}, 33 | 34 | {65, "IRAN", 4},{66, "IRAQ", 4},{67, "JAPAN", 2},{68, "JORDAN", 4}, 35 | {69, "KENYA", 0},{70, "MOROCCO", 0},{71, "MOZAMBIQUE", 0},{72, "PERU", 1}, 36 | {73, "CHINA", 2},{74, "ROMANIA", 3},{75, "SAUDI ARABIA", 4},{76, "VIETNAM", 2}, 37 | {77, "RUSSIA", 3},{78, "UNITED KINGDOM", 3},{79, "UNITED STATES", 1}, 38 | {80, "CHINA", 2},{81, "PAKISTAN", 2},{82, "BANGLADESH", 2},{83, "MEXICO", 1}, 39 | {84, "PHILIPPINES", 2},{85, "THAILAND", 2},{86, "ITALY", 3},{87, "SOUTH AFRICA", 0}, 40 | {88, "SOUTH KOREA", 2},{89, "COLOMBIA", 1},{90, "SPAIN", 3}, 41 | 42 | {97, "UKRAINE", 3},{98, "POLAND", 3},{99, "SUDAN", 0},{100, "UZBEKISTAN", 2}, 43 | {101, "MALAYSIA", 2},{102, "VENEZUELA", 1},{103, "NEPAL", 2},{104, "AFGHANISTAN", 2}, 44 | {105, "NORTH KOREA", 2},{106, "TAIWAN", 2},{107, "GHANA", 0},{108, "IVORY COAST", 0}, 45 | {109, "SYRIA", 4},{110, "MADAGASCAR", 0},{111, "CAMEROON", 0},{112, "SRI LANKA", 2}, 46 | {113, "ROMANIA", 3},{114, "NETHERLANDS", 3},{115, "CAMBODIA", 2},{116, "BELGIUM", 3}, 47 | {117, "GREECE", 3},{118, "PORTUGAL", 3},{119, "ISRAEL", 4},{120, "FINLAND", 3}, 48 | {121, "SINGAPORE", 2},{122, "NORWAY", 3} 49 | }; 50 | 51 | const char* DataSource::regions[]={"AFRICA","AMERICA","ASIA","EUROPE", "MIDDLE EAST"}; 52 | 53 | vector DataSource::cLastParts={ 54 | "BAR", "OUGHT", "ABLE", "PRI", "PRES", "ESE", "ANTI", "CALLY", "ATION", "EING" 55 | }; 56 | 57 | vector DataSource::tpchNouns={ 58 | "foxes", "ideas", "theodolites", "pinto beans", 59 | "instructions", "dependencies", "excuses", "platelets", 60 | "asymptotes", "courts", "dolphins", "multipliers", 61 | "sauternes", "warthogs", "frets", "dinos", 62 | "attainments", "somas", "Tiresias'", "patterns", 63 | "forges", "braids", "hockey players", "frays", 64 | "warhorses", "dugouts", "notornis", "epitaphs", 65 | "pearls", "tithes", "waters", "orbits", 66 | "gifts", "sheaves", "depths", "sentiments", 67 | "decoys", "realms", "pains", "grouches", 68 | "escapades" 69 | }; 70 | 71 | vector DataSource::tpchVerbs={ 72 | "sleep", "wake", "are", "cajole", 73 | "haggle", "nag", "use", "boost", 74 | "affix", "detect", "integrate", "maintain", 75 | "nod", "was", "lose", "sublate", 76 | "solve", "thrash", "promise", "engage", 77 | "hinder", "print", "x-ray", "breach", 78 | "eat", "grow", "impress", "mold", 79 | "poach", "serve", "run", "dazzle", 80 | "snooze", "doze", "unwind", "kindle", 81 | "play", "hang", "believe", "doubt" 82 | }; 83 | 84 | vector DataSource::tpchAdjectives={ 85 | "furious", "sly", "careful", "blithe", 86 | "quick", "fluffy", "slow", "quiet", 87 | "ruthless", "thin", "close", "dogged", 88 | "daring", "brave", "stealthy", "permanent", 89 | "enticing", "idle", "busy", "regular", 90 | "final", "ironic", "even", "bold", 91 | "silent" 92 | }; 93 | 94 | vector DataSource::tpchAdverbs={ 95 | "sometimes", "always", "never", "furiously", 96 | "slyly", "carefully", "blithely", "quickly", 97 | "fluffily", "slowly", "quietly", "ruthlessly", 98 | "thinly", "closely", "doggedly", "daringly", 99 | "bravely", "stealthily", "permanently", "enticingly", 100 | "idly", "busily", "regularly", "finally", 101 | "ironically", "evenly", "boldly", "silently" 102 | }; 103 | 104 | vector DataSource::tpchPrepositions={ 105 | "about", "above", "according to", "across", 106 | "after", "against", "along", "alongside of", 107 | "among", "around", "at", "atop", 108 | "before", "behind", "beneath", "beside", 109 | "besides", "between", "beyond", "by", 110 | "despite", "during", "except", "for", 111 | "from", "in place of", "inside", "instead of", 112 | "into", "near", "of", "on", 113 | "outside", "over", "past", "since", 114 | "through", "throughout", "to", "toward", 115 | "under", "until", "up", "upon", 116 | "without", "with", "within" 117 | }; 118 | 119 | vector DataSource::tpchTerminators={ 120 | ".", ";", ":", "?", "!", "--" 121 | }; 122 | 123 | vector DataSource::tpchAuxiliaries={ 124 | "do", "may", "might", "shall", 125 | "will", "would", "can", "could", 126 | "should", "ought to", "must", "will have to", 127 | "shall have to", "could have to", "should have to", "must have to", 128 | "need to", "try to" 129 | }; 130 | 131 | int DataSource::lastOlCount = 0; 132 | 133 | string DataSource::tpchText(int length){ 134 | string s=" "; 135 | for(int i=0; i<25; i++) 136 | s = s + (i==0?"":" ") + tpchSentence(); 137 | int pos = randomUniformInt(0,s.length()-length); 138 | return s.substr(pos,length); 139 | } 140 | 141 | string DataSource::tpchSentence(){ 142 | if(randomTrue(1/5)) 143 | return tpchNounPhrase() + " " + tpchVerbPhrase() + " " + 144 | tpchTerminators[randomUniformInt(0,tpchTerminators.size()-1)]; 145 | else if(randomTrue(1/5)) 146 | return tpchNounPhrase() + " " + tpchVerbPhrase() + " " + 147 | tpchPrepositionalPhrase() + " " + tpchTerminators[randomUniformInt(0,tpchTerminators.size()-1)]; 148 | else if(randomTrue(1/5)) 149 | return tpchNounPhrase() + " " + tpchVerbPhrase() + " " + 150 | tpchNounPhrase() + " " + tpchTerminators[randomUniformInt(0,tpchTerminators.size()-1)]; 151 | else if(randomTrue(1/5)) 152 | return tpchNounPhrase() + " " + tpchPrepositionalPhrase() + " " + 153 | tpchVerbPhrase() + " " + tpchNounPhrase() + " " + tpchTerminators[randomUniformInt(0,tpchTerminators.size()-1)]; 154 | else 155 | return tpchNounPhrase() + " " + tpchPrepositionalPhrase() + " " + tpchVerbPhrase() + " " + 156 | tpchPrepositionalPhrase() + " " + tpchTerminators[randomUniformInt(0,tpchTerminators.size()-1)]; 157 | } 158 | 159 | string DataSource::tpchNounPhrase(){ 160 | if(randomTrue(1/4)) 161 | return string(tpchNouns[randomUniformInt(0,tpchNouns.size()-1)]); 162 | else if(randomTrue(1/4)) 163 | return string(tpchAdjectives[randomUniformInt(0,tpchAdjectives.size()-1)]) + " " + 164 | tpchNouns[randomUniformInt(0,tpchNouns.size()-1)]; 165 | else if(randomTrue(1/4)) 166 | return string(tpchAdjectives[randomUniformInt(0,tpchAdjectives.size()-1)]) + ", " + 167 | tpchAdjectives[randomUniformInt(0,tpchAdjectives.size()-1)] + " " + tpchNouns[randomUniformInt(0,tpchNouns.size()-1)]; 168 | else 169 | return string(tpchAdverbs[randomUniformInt(0,tpchAdverbs.size()-1)]) + " " + 170 | tpchAdjectives[randomUniformInt(0,tpchAdjectives.size()-1)] + " " + tpchNouns[randomUniformInt(0,tpchNouns.size()-1)]; 171 | } 172 | 173 | string DataSource::tpchVerbPhrase(){ 174 | if(randomTrue(1/4)) 175 | return string(tpchVerbs[randomUniformInt(0,tpchVerbs.size()-1)]); 176 | else if(randomTrue(1/4)) 177 | return string(tpchAuxiliaries[randomUniformInt(0,tpchAuxiliaries.size()-1)]) + " " + 178 | tpchVerbs[randomUniformInt(0,tpchVerbs.size()-1)]; 179 | else if(randomTrue(1/4)) 180 | return string(tpchVerbs[randomUniformInt(0,tpchVerbs.size()-1)]) + " " + tpchAdverbs[randomUniformInt(0,tpchAdverbs.size()-1)]; 181 | else 182 | return string(tpchAuxiliaries[randomUniformInt(0,tpchAuxiliaries.size()-1)]) + " " + 183 | tpchVerbs[randomUniformInt(0,tpchVerbs.size()-1)] + " " + tpchAdverbs[randomUniformInt(0,tpchAdverbs.size()-1)]; 184 | } 185 | 186 | string DataSource::tpchPrepositionalPhrase(){ 187 | return string(tpchPrepositions[randomUniformInt(0,tpchPrepositions.size()-1)]) + " the " + tpchNounPhrase(); 188 | } 189 | 190 | void DataSource::initialize(){ 191 | srand(1382350201); 192 | } 193 | 194 | bool DataSource::randomTrue(double probability){ 195 | double value = rand() / double(RAND_MAX); 196 | return value < probability; 197 | } 198 | 199 | int DataSource::randomUniformInt(int minValue, int maxValue){ 200 | return (rand()%(maxValue-minValue+1))+minValue; 201 | } 202 | 203 | void DataSource::randomUniformInt(int minValue, int maxValue, int& ret){ 204 | ret = (rand()%(maxValue-minValue+1))+minValue; 205 | } 206 | 207 | void DataSource::randomNonUniformInt(int A, int x, int y, int C, int& ret){ 208 | ret = ((((randomUniformInt(0,A)|randomUniformInt(x,y))+C)%(y-x+1))+x); 209 | } 210 | 211 | void DataSource::randomDouble(double minValue, double maxValue, int decimals, double& ret){ 212 | int min = int(minValue * pow(10.0,decimals)); 213 | int max = int(maxValue * pow(10.0,decimals)); 214 | ret = double(randomUniformInt(min,max))/pow(10.0,decimals); 215 | } 216 | 217 | int DataSource::permute(int value, int low, int high){ 218 | int range = high - low + 1; 219 | return ((value*9973)%range)+low; 220 | } 221 | 222 | void DataSource::getCurrentTimestamp(SQL_TIMESTAMP_STRUCT& ret){ 223 | time_t rawtime; 224 | time (&rawtime); 225 | tm* timeinfo = localtime (&rawtime); 226 | 227 | ret.year = timeinfo->tm_year + 1900; 228 | ret.month = timeinfo->tm_mon + 1; 229 | ret.day = timeinfo->tm_mday; 230 | ret.hour = timeinfo->tm_hour; 231 | ret.minute = timeinfo->tm_min; 232 | ret.second = timeinfo->tm_sec; 233 | ret.fraction = 0; 234 | } 235 | 236 | void DataSource::genCLast(int value, string& ret){ 237 | ret = ""; 238 | ret += cLastParts[value / 100]; 239 | value %= 100; 240 | ret += cLastParts[value / 10]; 241 | value %= 10; 242 | ret += cLastParts[value]; 243 | } 244 | 245 | void DataSource::randomCLast(string& ret){ 246 | int value=0; 247 | randomNonUniformInt(255,0,999,173,value); 248 | genCLast(value,ret); 249 | } 250 | 251 | void DataSource::getRemoteWId(int& currentWId, int& ret){ 252 | if(Config::getWarehouseCount()==1){ 253 | ret = currentWId; 254 | } 255 | else{ 256 | ret = currentWId; 257 | while(ret == currentWId) 258 | randomUniformInt(1,Config::getWarehouseCount(),ret); 259 | } 260 | } 261 | 262 | int DataSource::nextOderlineCount(){ 263 | if(lastOlCount==0){ 264 | randomUniformInt(5,15,lastOlCount); 265 | return 20-lastOlCount; 266 | } 267 | 268 | int temp = lastOlCount; 269 | lastOlCount = 0; 270 | return temp; 271 | } 272 | 273 | 274 | void DataSource::addNumeric(int length, ofstream& stream, bool delimiter){ 275 | string s = ""; 276 | for(int i=0; i'9'&&rand<'A') || (rand>'Z'&&rand<'a')) 290 | randomUniformInt('0','z',rand); 291 | s+=rand; 292 | } 293 | stream << s; 294 | if(delimiter) 295 | stream << Config::getCsvDelim(); 296 | } 297 | 298 | void DataSource::addAlphanumeric64(int length, ofstream& stream, bool delimiter){ 299 | string s = ""; 300 | int rand; 301 | for(int i=0; i'9'&&rand< 63 ) || (rand>'Z'&&rand<'a')) 304 | randomUniformInt('0','z',rand); 305 | s+=rand; 306 | } 307 | stream << s; 308 | if(delimiter) 309 | stream << Config::getCsvDelim(); 310 | } 311 | 312 | 313 | void DataSource::addAlphanumeric64(int minLength, int maxLength, ofstream& stream, bool delimiter){ 314 | addAlphanumeric64(randomUniformInt(minLength,maxLength),stream,delimiter); 315 | } 316 | 317 | void DataSource::addAlphanumeric64Original(int minLength, int maxLength, ofstream& stream, bool delimiter){ 318 | int rLength=0; 319 | randomUniformInt(minLength,maxLength,rLength); 320 | int rPosition=0; 321 | randomUniformInt(0,rLength-8,rPosition); 322 | addAlphanumeric64(rPosition,stream,0); 323 | stream << "ORIGINAL"; 324 | addAlphanumeric64(rLength-8-rPosition,stream,0); 325 | if(delimiter) 326 | stream << Config::getCsvDelim(); 327 | } 328 | 329 | 330 | void DataSource::addTextString(int minLength, int maxLength, ofstream& stream, bool delimiter){ 331 | stream << tpchText(randomUniformInt(minLength,maxLength)); 332 | if(delimiter) 333 | stream << Config::getCsvDelim(); 334 | } 335 | 336 | void DataSource::addTextStringCustomer(int minLength, int maxLength, const char* action, ofstream& stream, bool delimiter){ 337 | int rLength=0; 338 | randomUniformInt(minLength,maxLength,rLength); 339 | int l1=0; 340 | randomUniformInt(0,rLength-10-8,l1); 341 | int l2=0; 342 | randomUniformInt(0,rLength-l1-10-8,l2); 343 | int l3 = rLength-l1-l2-18; 344 | stream << tpchText(l1); 345 | stream << "Customer"; 346 | stream << tpchText(l2); 347 | stream << action; 348 | stream << tpchText(l3); 349 | if(delimiter) 350 | stream << Config::getCsvDelim(); 351 | } 352 | 353 | void DataSource::addInt(int minValue, int maxValue, ofstream& stream, bool delimiter){ 354 | stream << randomUniformInt(minValue, maxValue); 355 | if(delimiter) 356 | stream << Config::getCsvDelim(); 357 | } 358 | 359 | void DataSource::addDouble(double minValue, double maxValue, int decimals, ofstream& stream, bool delimiter){ 360 | double d = 0; 361 | randomDouble(minValue,maxValue,decimals,d); 362 | stream << d; 363 | if(delimiter) 364 | stream << Config::getCsvDelim(); 365 | } 366 | 367 | void DataSource::addNId(ofstream& stream, bool delimiter){ 368 | int rand=0; 369 | while(rand==0 || (rand>'9'&&rand<'A') || (rand>'Z'&&rand<'a')) 370 | randomUniformInt('0','z',rand); 371 | stream << rand; 372 | if(delimiter) 373 | stream << Config::getCsvDelim(); 374 | } 375 | 376 | void DataSource::addWDCZip(ofstream& stream, bool delimiter){ 377 | addNumeric(4,stream,0); 378 | stream << "11111"; 379 | if(delimiter) 380 | stream << Config::getCsvDelim(); 381 | } 382 | 383 | void DataSource::addSuPhone(int& suId, ofstream& stream, bool delimiter){ 384 | int country_code = (suId%90)+10; //ensure length 2 385 | stream << country_code << "-"; 386 | addInt(100,999,stream,0); 387 | stream << "-"; 388 | addInt(100,999,stream,0); 389 | stream << "-"; 390 | addInt(1000,9999,stream,0); 391 | if(delimiter) 392 | stream << Config::getCsvDelim(); 393 | } 394 | 395 | string DataSource::getCurrentTimeString(){ 396 | time_t rawtime; 397 | struct tm * timeinfo; 398 | char buffer [24]; 399 | time (&rawtime); 400 | timeinfo = localtime (&rawtime); 401 | strftime (buffer,80,"%F %X",timeinfo); 402 | return string(buffer); 403 | } 404 | 405 | string DataSource::randomAlphanumeric62(int length){ 406 | string s = ""; 407 | int rand; 408 | for(int i=0; i'9'&&rand<'A') || (rand>'Z'&&rand<'a')) 411 | randomUniformInt('0','z',rand); 412 | s+=rand; 413 | } 414 | return s; 415 | } 416 | 417 | string DataSource::strLeadingZero(int i, int zeros){ 418 | stringstream ss; 419 | ss << setw(zeros) << setfill('0') << i; 420 | return ss.str(); 421 | } 422 | 423 | Nation DataSource::getNation(int i){ 424 | return nations[i]; 425 | } 426 | 427 | const char* DataSource::getRegion(int i){ 428 | return regions[i]; 429 | } 430 | -------------------------------------------------------------------------------- /src/DataSource.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef DATASOURCE_H 18 | #define DATASOURCE_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | struct Nation{ 28 | int id; 29 | std::string name; 30 | int rId; 31 | }; 32 | 33 | class DataSource{ 34 | 35 | private: 36 | static std::vector cLastParts; 37 | static std::vector tpchNouns; 38 | static std::vector tpchVerbs; 39 | static std::vector tpchAdjectives; 40 | static std::vector tpchAdverbs; 41 | static std::vector tpchPrepositions; 42 | static std::vector tpchTerminators; 43 | static std::vector tpchAuxiliaries; 44 | static const Nation nations[]; 45 | static const char* regions[]; 46 | static int lastOlCount; 47 | 48 | static std::string tpchText(int length); 49 | static std::string tpchSentence(); 50 | static std::string tpchNounPhrase(); 51 | static std::string tpchVerbPhrase(); 52 | static std::string tpchPrepositionalPhrase(); 53 | 54 | public: 55 | static void initialize(); 56 | static bool randomTrue(double probability); 57 | static int randomUniformInt(int minValue, int maxValue); 58 | static void randomUniformInt(int minValue, int maxValue, int& ret); 59 | static void randomNonUniformInt(int A, int x, int y, int C, int& ret); 60 | static void randomDouble(double minValue, double maxValue, int decimals, double& ret); 61 | static int permute(int value, int low, int high); 62 | static void getCurrentTimestamp(SQL_TIMESTAMP_STRUCT& ret); 63 | static void genCLast(int value, std::string& ret); 64 | static void randomCLast(std::string& ret); 65 | static void getRemoteWId(int& currentWId, int& ret); 66 | static int nextOderlineCount(); 67 | static void addNumeric(int length, std::ofstream& stream, bool delimiter); 68 | static void addAlphanumeric62(int length, std::ofstream& stream, bool delimiter); 69 | static void addAlphanumeric64(int length, std::ofstream& stream, bool delimiter); 70 | static void addAlphanumeric64(int minLength, int maxLength, std::ofstream& stream, bool delimiter); 71 | static void addAlphanumeric64Original(int minLength, int maxLength, std::ofstream& stream, bool delimiter); 72 | static void addTextString(int minLength, int maxLength, std::ofstream& stream, bool delimiter); 73 | static void addTextStringCustomer(int minLength, int maxLength, const char* action, std::ofstream& stream, bool delimiter); 74 | static void addInt(int minValue, int maxValue, std::ofstream& stream, bool delimiter); 75 | static void addDouble(double minValue, double maxValue, int decimals, std::ofstream& stream, bool delimiter); 76 | static void addNId(std::ofstream& stream, bool delimiter); 77 | static void addWDCZip(std::ofstream& stream, bool delimiter); 78 | static void addSuPhone(int& suId, std::ofstream& stream, bool delimiter); 79 | static std::string getCurrentTimeString(); 80 | static std::string randomAlphanumeric62(int length); 81 | static std::string strLeadingZero(int i, int zeros); 82 | static Nation getNation(int i); 83 | static const char* getRegion(int i); 84 | 85 | }; 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/DbcTools.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "Config.h" 18 | #include "DbcTools.h" 19 | #include "Log.h" 20 | 21 | using namespace std; 22 | 23 | bool DbcTools::fetch(SQLHSTMT& hStmt, SQLCHAR* buf, SQLLEN* nIdicator, int pos){ 24 | SQLRETURN ret = SQLFetch(hStmt); 25 | if(reviewReturn(hStmt,SQL_HANDLE_STMT,ret)){ 26 | ret = SQLGetData(hStmt, pos, SQL_C_CHAR, buf, 1024, nIdicator); 27 | if(reviewReturn(hStmt,SQL_HANDLE_STMT,ret)){ 28 | return 1; 29 | } 30 | } 31 | Log::l1() << Log::tm() << "-fetch failed\n"; 32 | return 0; 33 | } 34 | 35 | bool DbcTools::setEnv(SQLHENV& hEnv){ 36 | SQLRETURN ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv); 37 | if(reviewReturn(hEnv,SQL_HANDLE_ENV,ret,1)){ 38 | ret = SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0); 39 | if(reviewReturn(hEnv,SQL_HANDLE_ENV,ret,1)) 40 | return 1; 41 | } 42 | Log::l2() << Log::tm() << "-environment not set\n"; 43 | return 0; 44 | } 45 | 46 | bool DbcTools::connect(SQLHENV& hEnv, SQLHDBC& hDBC){ 47 | SQLRETURN ret = SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hDBC); 48 | if(reviewReturn(hDBC,SQL_HANDLE_DBC,ret,1)){ 49 | ret = SQLConnect(hDBC, (SQLCHAR*) Config::getDataSourceName().c_str(), SQL_NTS, (SQLCHAR*) Config::getDbsUser().c_str(), SQL_NTS, (SQLCHAR*) Config::getDbsPassword().c_str(), SQL_NTS); 50 | if(reviewReturn(hDBC,SQL_HANDLE_DBC,ret,1)){ 51 | Log::l1() << Log::tm() << "-dbs connected\n"; 52 | return 1; 53 | } 54 | } 55 | Log::l2() << Log::tm() << "-dbs not connected\n"; 56 | return 0; 57 | } 58 | 59 | bool DbcTools::autoCommitOff(SQLHDBC& hDBC){ 60 | SQLRETURN ret = SQLSetConnectAttr(hDBC, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, SQL_NTS); 61 | if(reviewReturn(hDBC,SQL_HANDLE_DBC,ret,1)) 62 | return 1; 63 | Log::l2() << Log::tm() << "-autoCommitOff failed\n"; 64 | return 0; 65 | } 66 | 67 | bool DbcTools::allocAndPrepareStmt(SQLHDBC& hDBC, SQLHSTMT& hStmt, const char* stmt){ 68 | if(hStmt!=0){ 69 | SQLFreeHandle(SQL_HANDLE_STMT,hStmt); 70 | hStmt=0; 71 | } 72 | if(SQL_SUCCESS==SQLAllocHandle(SQL_HANDLE_STMT, hDBC, &hStmt)){ 73 | if(SQL_SUCCESS==SQLPrepare(hStmt, (unsigned char*) stmt, SQL_NTS)) 74 | return 1; 75 | } 76 | Log::l1() << Log::tm() << "-prepare statement failed:\n" << stmt << "\n"; 77 | return 0; 78 | } 79 | 80 | bool DbcTools::resetStatement(SQLHSTMT& hStmt){ 81 | SQLRETURN ret = SQLFreeStmt(hStmt, SQL_CLOSE); 82 | if(reviewReturn(hStmt,SQL_HANDLE_STMT,ret)){ 83 | ret=SQLFreeStmt(hStmt, SQL_UNBIND); 84 | if(reviewReturn(hStmt,SQL_HANDLE_STMT,ret)){ 85 | ret=SQLFreeStmt(hStmt, SQL_RESET_PARAMS); 86 | if(reviewReturn(hStmt,SQL_HANDLE_STMT,ret)){ 87 | return 1; 88 | } 89 | } 90 | } 91 | return 0; 92 | } 93 | 94 | bool DbcTools::bind(SQLHSTMT& hStmt, int pos, int& value){ 95 | SQLRETURN ret = SQLBindParameter(hStmt, pos, SQL_PARAM_INPUT, SQL_C_DEFAULT, SQL_INTEGER, 0, 0, &value, 0, 0); 96 | if(reviewReturn(hStmt,SQL_HANDLE_STMT,ret)) 97 | return 1; 98 | Log::l1() << Log::tm() << "-bind int failed\n"; 99 | return 0; 100 | } 101 | 102 | bool DbcTools::bind(SQLHSTMT& hStmt, int pos, double& value){ 103 | SQLRETURN ret = SQLBindParameter(hStmt, pos, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_DOUBLE, 0, 0, &value, 0, 0); 104 | if(reviewReturn(hStmt,SQL_HANDLE_STMT,ret)) 105 | return 1; 106 | Log::l1() << Log::tm() << "-bind double failed\n"; 107 | return 0; 108 | } 109 | 110 | bool DbcTools::bind(SQLHSTMT& hStmt, int pos, int bufferLength, char* buffer){ 111 | SQLRETURN ret = SQLBindParameter(hStmt, pos, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, bufferLength, 0, buffer, 0, 0); 112 | if(reviewReturn(hStmt,SQL_HANDLE_STMT,ret)) 113 | return 1; 114 | Log::l1() << Log::tm() << "-bind string failed\n"; 115 | return 0; 116 | } 117 | 118 | bool DbcTools::bind(SQLHSTMT& hStmt, int pos, SQL_TIMESTAMP_STRUCT& ts){ 119 | SQLRETURN ret = SQLBindParameter(hStmt, pos, SQL_PARAM_INPUT, SQL_C_TYPE_TIMESTAMP, SQL_TIMESTAMP, 0, 0, &ts, 0, 0); 120 | if(reviewReturn(hStmt,SQL_HANDLE_STMT,ret)) 121 | return 1; 122 | Log::l1() << Log::tm() << "-bind timestamp failed\n"; 123 | return 0; 124 | } 125 | 126 | bool DbcTools::executePreparedStatement(SQLHSTMT& hStmt){ 127 | SQLRETURN ret = SQLExecute(hStmt); 128 | if(reviewReturn(hStmt,SQL_HANDLE_STMT,ret)){ 129 | return 1; 130 | } 131 | Log::l1() << Log::tm() << "-prepared statement failed\n"; 132 | return 0; 133 | } 134 | 135 | bool DbcTools::executeServiceStatement(SQLHSTMT& hStmt, const char* stmt, bool showError){ 136 | if(resetStatement(hStmt)){ 137 | SQLRETURN ret = SQLExecDirect(hStmt, (SQLCHAR*) stmt, SQL_NTS); 138 | if(reviewReturn(hStmt, SQL_HANDLE_STMT, ret, 1)) 139 | return 1; 140 | } 141 | if(showError) 142 | Log::l2() << Log::tm() << "-service statement failed:\n " << stmt << "\n"; 143 | else 144 | Log::l1() << Log::tm() << "-service statement failed:\n " << stmt << "\n"; 145 | return 0; 146 | } 147 | 148 | bool DbcTools::reviewReturn(SQLHANDLE& handle, SQLSMALLINT handleType, SQLRETURN& ret, bool showError){ 149 | 150 | if(SQL_SUCCESS == ret){ 151 | return 1; 152 | } 153 | 154 | SQLCHAR sql_state_buffer[10] = {0}; 155 | SQLINTEGER native_error=0; 156 | SQLCHAR message_text_buffer[4096] = {0}; 157 | SQLSMALLINT text_length=0; 158 | 159 | SQLGetDiagRec(handleType,handle,1,sql_state_buffer,&native_error, message_text_buffer,4096,&text_length); 160 | 161 | if(SQL_SUCCESS_WITH_INFO == ret){ 162 | if(showError) 163 | Log::l2() << Log::tm() << "-info:\n SQL_SUCCESS_WITH_INFO\n SQLSTATE: " << (const char*)sql_state_buffer << "\n NATIVE ERROR: " << native_error << "\n MESSAGE TEXT: " << (const char*)message_text_buffer << "\n"; 164 | else 165 | Log::l1() << Log::tm() << "-info:\n SQL_SUCCESS_WITH_INFO\n SQLSTATE: " << (const char*)sql_state_buffer << "\n NATIVE ERROR: " << native_error << "\n MESSAGE TEXT: " << (const char*)message_text_buffer << "\n"; 166 | return 1; 167 | } 168 | string s = ""; 169 | if(SQL_NEED_DATA == ret){ 170 | s = "SQL_NEED_DATA"; 171 | } 172 | else if(SQL_STILL_EXECUTING == ret){ 173 | s = "SQL_STILL_EXECUTING"; 174 | } 175 | else if(SQL_ERROR == ret){ 176 | s = "SQL_ERROR"; 177 | } 178 | else if(SQL_NO_DATA == ret){ 179 | s = "SQL_NO_DATA"; 180 | } 181 | else if(SQL_INVALID_HANDLE == ret){ 182 | s = "SQL_INVALID_HANDLE"; 183 | } 184 | else{ 185 | s = "UNEXPECTED ODBC RETURN"; 186 | } 187 | if(showError) 188 | Log::l2() << Log::tm() << "-bad return:\n " << s << "\n SQLSTATE: " << (const char*)sql_state_buffer << "\n NATIVE ERROR: " << native_error << "\n MESSAGE TEXT: " << (const char*)message_text_buffer << "\n"; 189 | else 190 | Log::l1() << Log::tm() << "-bad return:\n " << s << "\n SQLSTATE: " << (const char*)sql_state_buffer << "\n NATIVE ERROR: " << native_error << "\n MESSAGE TEXT: " << (const char*)message_text_buffer << "\n"; 191 | return 0; 192 | } 193 | 194 | bool DbcTools::fetch(SQLHSTMT& hStmt, SQLCHAR* buf, SQLLEN* nIdicator, int pos, string& value){ 195 | if(fetch(hStmt, buf, nIdicator, pos)){ 196 | value = string((char*)buf); 197 | return 1; 198 | } 199 | return 0; 200 | } 201 | 202 | bool DbcTools::fetch(SQLHSTMT& hStmt, SQLCHAR* buf, SQLLEN* nIdicator, int pos, int& value){ 203 | if(fetch(hStmt, buf, nIdicator, pos)){ 204 | value = strtol ((char*)buf,NULL,0); 205 | return 1; 206 | } 207 | return 0; 208 | } 209 | 210 | bool DbcTools::fetch(SQLHSTMT& hStmt, SQLCHAR* buf, SQLLEN* nIdicator, int pos, double& value){ 211 | if(fetch(hStmt, buf, nIdicator, pos)){ 212 | value = atof ((char*)buf); 213 | return 1; 214 | } 215 | return 0; 216 | } 217 | 218 | bool DbcTools::commit(SQLHDBC& hDBC){ 219 | Log::l1() << Log::tm() << "-commit\n"; 220 | SQLRETURN ret = SQLEndTran(SQL_HANDLE_DBC,hDBC,SQL_COMMIT); 221 | if(reviewReturn(hDBC,SQL_HANDLE_DBC,ret)){ 222 | return 1; 223 | } 224 | Log::l1() << Log::tm() << "-commit failed\n"; 225 | return 0; 226 | } 227 | 228 | bool DbcTools::rollback(SQLHDBC& hDBC){ 229 | Log::l1() << Log::tm() << "-rollback\n"; 230 | SQLRETURN ret = SQLEndTran(SQL_HANDLE_DBC,hDBC,SQL_ROLLBACK); 231 | if(reviewReturn(hDBC,SQL_HANDLE_DBC,ret)){ 232 | return 1; 233 | } 234 | Log::l1() << Log::tm() << "-rollback failed\n"; 235 | return 0; 236 | } 237 | -------------------------------------------------------------------------------- /src/DbcTools.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef DBCTOOLS_H 18 | #define DBCTOOLS_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | class DbcTools{ 26 | 27 | private: 28 | static bool fetch(SQLHSTMT& hStmt, SQLCHAR* buf, SQLLEN* nIdicator, int pos); 29 | static bool reviewReturn(SQLHANDLE& handle, SQLSMALLINT handleType, SQLRETURN& ret, bool showError=0); 30 | 31 | public: 32 | static bool setEnv(SQLHENV& hEnv); 33 | static bool connect(SQLHENV& hEnv, SQLHDBC& hDBC); 34 | static bool autoCommitOff(SQLHDBC& hDBC); 35 | static bool allocAndPrepareStmt(SQLHDBC& hDBC, SQLHSTMT& hStmt, const char* stmt); 36 | static bool resetStatement(SQLHSTMT& hStmt); 37 | static bool bind(SQLHSTMT& hStmt, int pos, int& value); 38 | static bool bind(SQLHSTMT& hStmt, int pos, double& value); 39 | static bool bind(SQLHSTMT& hStmt, int pos, int bufferLength, char* buffer); 40 | static bool bind(SQLHSTMT& hStmt, int pos, SQL_TIMESTAMP_STRUCT& ts); 41 | static bool executePreparedStatement(SQLHSTMT& hStmt); 42 | static bool executeServiceStatement(SQLHSTMT& hStmt, const char* stmt, bool showError=1); 43 | static bool fetch(SQLHSTMT& hStmt, SQLCHAR* buf, SQLLEN* nIdicator, int pos, std::string& value); 44 | static bool fetch(SQLHSTMT& hStmt, SQLCHAR* buf, SQLLEN* nIdicator, int pos, int& value); 45 | static bool fetch(SQLHSTMT& hStmt, SQLCHAR* buf, SQLLEN* nIdicator, int pos, double& value); 46 | static bool commit(SQLHDBC& hDBC); 47 | static bool rollback(SQLHDBC& hDBC); 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/Log.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "Log.h" 18 | #include "Config.h" 19 | 20 | #define WRITE_LOG_FILE 21 | 22 | using namespace std; 23 | 24 | LogTime Log::lt; 25 | Log1 Log::log1; 26 | Log2 Log::log2; 27 | ofstream Log::logStream; 28 | 29 | LogTime& Log::tm(){ 30 | return lt; 31 | } 32 | 33 | Log1& Log::l1(){ 34 | return log1; 35 | } 36 | 37 | Log2& Log::l2(){ 38 | return log2; 39 | } 40 | 41 | ofstream* Log::getLogStream(){ 42 | if(!logStream.is_open()) 43 | logStream.open( (Config::getOutputPath()+"/log").c_str() ); 44 | return &logStream; 45 | } 46 | 47 | 48 | Log1& operator<<(Log1& l, LogTime& lt){ 49 | time_t rawtime; 50 | time (&rawtime); 51 | struct tm * timeinfo = localtime (&rawtime); 52 | char buffer [24]; 53 | strftime (buffer,24,"%r: ",timeinfo); 54 | #ifdef WRITE_LOG_FILE 55 | *Log::getLogStream() << buffer; 56 | Log::getLogStream()->flush(); 57 | #endif 58 | return l; 59 | }; 60 | 61 | Log1& operator<<(Log1& l, const char* c){ 62 | #ifdef WRITE_LOG_FILE 63 | *Log::getLogStream() << c; 64 | Log::getLogStream()->flush(); 65 | #endif 66 | return l; 67 | }; 68 | 69 | Log1& operator<<(Log1& l, string s){ 70 | #ifdef WRITE_LOG_FILE 71 | *Log::getLogStream() << s; 72 | Log::getLogStream()->flush(); 73 | #endif 74 | return l; 75 | }; 76 | 77 | Log1& operator<<(Log1& l, double d){ 78 | #ifdef WRITE_LOG_FILE 79 | *Log::getLogStream() << d; 80 | Log::getLogStream()->flush(); 81 | #endif 82 | return l; 83 | }; 84 | 85 | 86 | Log2& operator<<(Log2& l, LogTime& lt){ 87 | time_t rawtime; 88 | time (&rawtime); 89 | struct tm * timeinfo = localtime (&rawtime); 90 | char buffer [24]; 91 | strftime (buffer,24,"%r: ",timeinfo); 92 | 93 | #ifdef WRITE_LOG_FILE 94 | *Log::getLogStream() << buffer; 95 | Log::getLogStream()->flush(); 96 | #endif 97 | return l; 98 | }; 99 | 100 | Log2& operator<<(Log2& l,const char* c){ 101 | cout << c; 102 | cout.flush(); 103 | #ifdef WRITE_LOG_FILE 104 | *Log::getLogStream() << c; 105 | Log::getLogStream()->flush(); 106 | #endif 107 | return l; 108 | }; 109 | 110 | Log2& operator<<(Log2& l,string s){ 111 | cout << s; 112 | cout.flush(); 113 | #ifdef WRITE_LOG_FILE 114 | *Log::getLogStream() << s; 115 | Log::getLogStream()->flush(); 116 | #endif 117 | return l; 118 | }; 119 | 120 | Log2& operator<<(Log2& l,double d){ 121 | cout << d; 122 | cout.flush(); 123 | #ifdef WRITE_LOG_FILE 124 | *Log::getLogStream() << d; 125 | Log::getLogStream()->flush(); 126 | #endif 127 | return l; 128 | }; 129 | -------------------------------------------------------------------------------- /src/Log.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef LOG_H 18 | #define LOG_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | class LogTime{ 25 | 26 | }; 27 | 28 | class Log1{ 29 | 30 | }; 31 | 32 | class Log2{ 33 | 34 | }; 35 | 36 | class Log{ 37 | 38 | private: 39 | static LogTime lt; 40 | static Log1 log1; 41 | static Log2 log2; 42 | static std::ofstream logStream; 43 | 44 | public: 45 | static LogTime& tm(); 46 | static Log1& l1(); 47 | static Log2& l2(); 48 | static std::ofstream* getLogStream(); 49 | }; 50 | 51 | Log1& operator<<(Log1& l, LogTime& lt); 52 | Log1& operator<<(Log1& l, const char* c); 53 | Log1& operator<<(Log1& l, std::string s); 54 | Log1& operator<<(Log1& l, double d); 55 | 56 | Log2& operator<<(Log2& l, LogTime& lt); 57 | Log2& operator<<(Log2& l,const char* c); 58 | Log2& operator<<(Log2& l,std::string s); 59 | Log2& operator<<(Log2& l,double d); 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/Queries.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "Config.h" 18 | #include "DbcTools.h" 19 | #include "Log.h" 20 | #include "Queries.h" 21 | #include "dialect/DialectStrategy.h" 22 | 23 | using namespace std; 24 | 25 | bool Queries::prepareStatements(SQLHDBC& hDBC){ 26 | 27 | for(int i = 0; i < 22; i++){ 28 | if(!DbcTools::allocAndPrepareStmt(hDBC, odbc_queries[i], DialectStrategy::getInstance()->getTpchQueryStrings()[i])){ 29 | Log::l2() << Log::tm() << "-prepare statements failed\n"; 30 | return 0; 31 | } 32 | } 33 | Log::l1() << Log::tm() << "-prepare statements succeeded\n"; 34 | return 1; 35 | } 36 | 37 | bool Queries::executeTPCH(SQLHDBC& hDBC,int& i){ 38 | //先加上prepare 39 | if(!DbcTools::allocAndPrepareStmt(hDBC, odbc_queries[i-1], DialectStrategy::getInstance()->getTpchQueryStrings()[i-1])){ 40 | Log::l2() << Log::tm() << "-prepare statements failed\n"; 41 | return 0; 42 | } 43 | if(DbcTools::resetStatement(odbc_queries[i-1])){ 44 | return DbcTools::executePreparedStatement(odbc_queries[i-1]); 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /src/Queries.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef QUERIES_H 18 | #define QUERIES_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | class Queries{ 25 | 26 | private: 27 | SQLHSTMT odbc_queries[22] = {0}; 28 | 29 | public: 30 | bool prepareStatements(SQLHDBC& hDBC); 31 | bool executeTPCH(SQLHDBC& hDBC,int& i); 32 | 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/Schema.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "Config.h" 18 | #include "Schema.h" 19 | #include "DbcTools.h" 20 | #include "Log.h" 21 | #include "dialect/DialectStrategy.h" 22 | 23 | #include 24 | 25 | using namespace std; 26 | 27 | bool Schema::check(SQLHSTMT& hStmt, const char* query, int& cnt){ 28 | 29 | SQLLEN nIdicator = 0; 30 | SQLCHAR buf[128] = {0}; 31 | 32 | if(!DbcTools::executeServiceStatement(hStmt, query)){ 33 | Log::l2() << Log::tm()<< "-determine count failed\n"; 34 | return 0; 35 | } 36 | if(!DbcTools::fetch(hStmt, buf, &nIdicator, 1, cnt)){ 37 | Log::l2() << Log::tm()<< "-determine count failed\n"; 38 | return 0; 39 | } 40 | if(cnt==0){ 41 | Log::l2() << Log::tm()<< "-determine count failed\n"; 42 | return 0; 43 | } 44 | return 1; 45 | } 46 | 47 | bool Schema::createSchema(SQLHSTMT& hStmt){ 48 | 49 | for(unsigned int i = 0; i < DialectStrategy::getInstance()->getDropExistingSchemaStatements().size(); i++){ 50 | DbcTools::executeServiceStatement(hStmt, DialectStrategy::getInstance()->getDropExistingSchemaStatements()[i],0); 51 | } 52 | 53 | for(unsigned int i = 0; i < DialectStrategy::getInstance()->getCreateSchemaStatements().size(); i++){ 54 | if(!DbcTools::executeServiceStatement(hStmt, DialectStrategy::getInstance()->getCreateSchemaStatements()[i])){ 55 | Log::l2() << Log::tm()<< "-failed\n"; 56 | return 0; 57 | } 58 | } 59 | 60 | Log::l2() << Log::tm()<< "-succeeded\n"; 61 | return 1; 62 | } 63 | 64 | bool Schema::importCSV(SQLHSTMT& hStmt){ 65 | 66 | if(DialectStrategy::getInstance()->getImportPrefix().size() != DialectStrategy::getInstance()->getImportSuffix().size()){ 67 | Log::l2() << Log::tm() << "-failed (different size of ImportPrefix and ImportSuffix vector in dialect class)\n"; 68 | return 0; 69 | } 70 | 71 | for(unsigned int i = 0; i < DialectStrategy::getInstance()->getImportPrefix().size(); i++){ 72 | if(!DbcTools::executeServiceStatement(hStmt, string(DialectStrategy::getInstance()->getImportPrefix()[i] + Config::getInitialDbCreationPath() + DialectStrategy::getInstance()->getImportSuffix()[i]).c_str())){ 73 | Log::l2() << Log::tm() << "-failed\n"; 74 | return 0; 75 | } 76 | } 77 | 78 | Log::l2() << Log::tm() << "-succeeded\n"; 79 | return 1; 80 | } 81 | 82 | bool Schema::check(SQLHSTMT& hStmt){ 83 | 84 | int wh=0; 85 | if(!check(hStmt,DialectStrategy::getInstance()->getSelectCountWarehouse(), wh)) 86 | return 0; 87 | 88 | int ds=0; 89 | if(!check(hStmt,DialectStrategy::getInstance()->getSelectCountDistrict(), ds)) 90 | return 0; 91 | if(ds!=10*wh){ 92 | Log::l2() << Log::tm()<< "-check failed (#DISTRICT: "<< ds <<")\n"; 93 | return 0; 94 | } 95 | 96 | int cs=0; 97 | if(!check(hStmt,DialectStrategy::getInstance()->getSelectCountCustomer(), cs)) 98 | return 0; 99 | if(cs!=30000*wh){ 100 | Log::l2() << Log::tm()<< "-check failed (#CUSTOMER: " << cs << ")\n"; 101 | return 0; 102 | } 103 | 104 | int od=0; 105 | if(!check(hStmt,DialectStrategy::getInstance()->getSelectCountOrder(), od)) 106 | return 0; 107 | if(od!=30000*wh){ 108 | Log::l2() << Log::tm()<< "-check failed (#ORDER: " << od << ")\n"; 109 | return 0; 110 | } 111 | 112 | int ol=0; 113 | if(!check(hStmt,DialectStrategy::getInstance()->getSelectCountOrderline(), ol)) 114 | return 0; 115 | if(ol!=300000*wh){ 116 | Log::l2() << Log::tm()<< "-check failed (#ORDERLINE: "<< ol <<")\n"; 117 | return 0; 118 | } 119 | 120 | int no=0; 121 | if(!check(hStmt,DialectStrategy::getInstance()->getSelectCountNeworder(), no)) 122 | return 0; 123 | if(no!=9000*wh){ 124 | Log::l2() << Log::tm()<< "-check failed (#NEWORDER: " << no <<")\n"; 125 | return 0; 126 | } 127 | 128 | int hs=0; 129 | if(!check(hStmt,DialectStrategy::getInstance()->getSelectCountHistory(), hs)) 130 | return 0; 131 | if(hs!=30000*wh){ 132 | Log::l2() << Log::tm()<< "-check failed (#HISTORY: " << hs <<")\n"; 133 | return 0; 134 | } 135 | 136 | int st=0; 137 | if(!check(hStmt,DialectStrategy::getInstance()->getSelectCountStock(), st)) 138 | return 0; 139 | if(st!=100000*wh){ 140 | Log::l2() << Log::tm()<< "-check failed (#STOCK: " << st <<")\n"; 141 | return 0; 142 | } 143 | 144 | int it=0; 145 | if(!check(hStmt,DialectStrategy::getInstance()->getSelectCountItem(), it)) 146 | return 0; 147 | if(it!=100000){ 148 | Log::l2() << Log::tm() << "-check failed (#ITEM: " << it <<")\n"; 149 | return 0; 150 | } 151 | 152 | int sp=0; 153 | if(!check(hStmt,DialectStrategy::getInstance()->getSelectCountSupplier(), sp)) 154 | return 0; 155 | if(sp!=10000){ 156 | Log::l2() << Log::tm() << "-check failed (#SUPPLIER: " << sp <<")\n"; 157 | return 0; 158 | } 159 | 160 | int na=0; 161 | if(!check(hStmt,DialectStrategy::getInstance()->getSelectCountNation(), na)) 162 | return 0; 163 | if(na!=62){ 164 | Log::l2() << Log::tm() << "-check failed (#NATION: " << na <<")\n"; 165 | return 0; 166 | } 167 | 168 | int rg=0; 169 | if(!check(hStmt,DialectStrategy::getInstance()->getSelectCountRegion(), rg)) 170 | return 0; 171 | if(rg!=5){ 172 | Log::l2() << Log::tm() << "-check failed (#REGION: " << rg <<")\n"; 173 | return 0;; 174 | } 175 | 176 | Log::l2() << Log::tm() << "-check with " << wh << " warehouses succeeded\n"; 177 | return 1; 178 | } 179 | 180 | bool Schema::additionalPreparation(SQLHSTMT& hStmt){ 181 | 182 | for(unsigned int i = 0; i < DialectStrategy::getInstance()->getAdditionalPreparationStatements().size(); i++){ 183 | if(!DbcTools::executeServiceStatement(hStmt, DialectStrategy::getInstance()->getAdditionalPreparationStatements()[i])){ 184 | Log::l2() << Log::tm() << "-failed\n"; 185 | return 0; 186 | } 187 | } 188 | Log::l2() << Log::tm() << "-succeeded\n"; 189 | return 1; 190 | } 191 | 192 | -------------------------------------------------------------------------------- /src/Schema.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef SCHEMA_H 18 | #define SCHEMA_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | class Schema{ 25 | 26 | private: 27 | static bool check(SQLHSTMT& hStmt, const char* query, int& cnt); 28 | 29 | public: 30 | static bool createSchema(SQLHSTMT& hStmt); 31 | static bool importCSV(SQLHSTMT& hStmt); 32 | static bool check(SQLHSTMT& hStmt); 33 | static bool additionalPreparation(SQLHSTMT& hStmt); 34 | 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/TransactionalStatistic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "TransactionalStatistic.h" 18 | 19 | using namespace std; 20 | 21 | TransactionalStatistic::TransactionalStatistic(){ 22 | for(int i=0; i<5; i++){ 23 | executeTPCCSuccessCount[i] = 0; 24 | executeTPCCFailCount[i] = 0; 25 | } 26 | } 27 | 28 | void TransactionalStatistic::addResult(unsigned long long& transcationalResults){ 29 | transcationalResults += executeTPCCSuccessCount[0]; 30 | } 31 | 32 | void TransactionalStatistic::executeTPCCSuccess(int transactionNumber, bool success){ 33 | if(success) 34 | executeTPCCSuccessCount[transactionNumber-1]++; 35 | else 36 | executeTPCCFailCount[transactionNumber-1]++; 37 | } 38 | -------------------------------------------------------------------------------- /src/TransactionalStatistic.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef TRANSACTIONALSTATISTIC_H 18 | #define TRANSACTIONALSTATISTIC_H 19 | 20 | class TransactionalStatistic{ 21 | 22 | private: 23 | unsigned long long executeTPCCSuccessCount[5]; 24 | unsigned long long executeTPCCFailCount[5]; 25 | 26 | public: 27 | TransactionalStatistic(); 28 | void addResult(unsigned long long& transcationalResults); 29 | void executeTPCCSuccess(int transactionNumber, bool success); 30 | 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/Transactions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "Config.h" 18 | #include "DbcTools.h" 19 | #include "DataSource.h" 20 | #include "Log.h" 21 | #include "Transactions.h" 22 | #include "dialect/DialectStrategy.h" 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace std; 29 | 30 | bool Transactions::prepare(SQLHDBC& hDBC){ 31 | 32 | //NewOrder: 33 | if(!DbcTools::allocAndPrepareStmt(hDBC, noWarehouseSelect, DialectStrategy::getInstance()->getNoWarehouseSelect())) 34 | return 0; 35 | if(!DbcTools::allocAndPrepareStmt(hDBC, noDistrictSelect, DialectStrategy::getInstance()->getNoDistrictSelect())) 36 | return 0; 37 | if(!DbcTools::allocAndPrepareStmt(hDBC, noDistrictUpdate, DialectStrategy::getInstance()->getNoDistrictUpdate())) 38 | return 0; 39 | if(!DbcTools::allocAndPrepareStmt(hDBC, noCustomerSelect, DialectStrategy::getInstance()->getNoCustomerSelect())) 40 | return 0; 41 | if(!DbcTools::allocAndPrepareStmt(hDBC, noItemSelect, DialectStrategy::getInstance()->getNoItemSelect())) 42 | return 0; 43 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[0], DialectStrategy::getInstance()->getNoStockSelect01())) 44 | return 0; 45 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[1], DialectStrategy::getInstance()->getNoStockSelect02())) 46 | return 0; 47 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[2], DialectStrategy::getInstance()->getNoStockSelect03())) 48 | return 0; 49 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[3], DialectStrategy::getInstance()->getNoStockSelect04())) 50 | return 0; 51 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[4], DialectStrategy::getInstance()->getNoStockSelect05())) 52 | return 0; 53 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[5], DialectStrategy::getInstance()->getNoStockSelect06())) 54 | return 0; 55 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[6], DialectStrategy::getInstance()->getNoStockSelect07())) 56 | return 0; 57 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[7], DialectStrategy::getInstance()->getNoStockSelect08())) 58 | return 0; 59 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[8], DialectStrategy::getInstance()->getNoStockSelect09())) 60 | return 0; 61 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[9], DialectStrategy::getInstance()->getNoStockSelect10())) 62 | return 0; 63 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockUpdates[0], DialectStrategy::getInstance()->getNoStockUpdate01())) 64 | return 0; 65 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockUpdates[1], DialectStrategy::getInstance()->getNoStockUpdate02())) 66 | return 0; 67 | if(!DbcTools::allocAndPrepareStmt(hDBC, noOrderlineInsert, DialectStrategy::getInstance()->getNoOrderlineInsert())) 68 | return 0; 69 | if(!DbcTools::allocAndPrepareStmt(hDBC, noOrderInsert, DialectStrategy::getInstance()->getNoOrderInsert())) 70 | return 0; 71 | if(!DbcTools::allocAndPrepareStmt(hDBC, noNewOrderInsert, DialectStrategy::getInstance()->getNoNewOrderInsert())) 72 | return 0; 73 | 74 | //Payment: 75 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmWarehouseSelect, DialectStrategy::getInstance()->getPmWarehouseSelect())) 76 | return 0; 77 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmWarehouseUpdate, DialectStrategy::getInstance()->getPmWarehouseUpdate())) 78 | return 0; 79 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmDistrictSelect, DialectStrategy::getInstance()->getPmDistrictSelect())) 80 | return 0; 81 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmDistrictUpdate, DialectStrategy::getInstance()->getPmDistrictUpdate())) 82 | return 0; 83 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmCustomerSelect1, DialectStrategy::getInstance()->getPmCustomerSelect1())) 84 | return 0; 85 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmCustomerSelect2, DialectStrategy::getInstance()->getPmCustomerSelect2())) 86 | return 0; 87 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmCustomerSelect3, DialectStrategy::getInstance()->getPmCustomerSelect3())) 88 | return 0; 89 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmCustomerUpdate1, DialectStrategy::getInstance()->getPmCustomerUpdate1())) 90 | return 0; 91 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmCustomerSelect4, DialectStrategy::getInstance()->getPmCustomerSelect4())) 92 | return 0; 93 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmCustomerUpdate2, DialectStrategy::getInstance()->getPmCustomerUpdate2())) 94 | return 0; 95 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmHistoryInsert, DialectStrategy::getInstance()->getPmHistoryInsert())) 96 | return 0; 97 | 98 | //OrderStatus: 99 | if(!DbcTools::allocAndPrepareStmt(hDBC, osCustomerSelect1, DialectStrategy::getInstance()->getOsCustomerSelect1())) 100 | return 0; 101 | if(!DbcTools::allocAndPrepareStmt(hDBC, osCustomerSelect2, DialectStrategy::getInstance()->getOsCustomerSelect2())) 102 | return 0; 103 | if(!DbcTools::allocAndPrepareStmt(hDBC, osCustomerSelect3, DialectStrategy::getInstance()->getOsCustomerSelect3())) 104 | return 0; 105 | if(!DbcTools::allocAndPrepareStmt(hDBC, osOrderSelect, DialectStrategy::getInstance()->getOsOrderSelect())) 106 | return 0; 107 | if(!DbcTools::allocAndPrepareStmt(hDBC, osOrderlineSelect, DialectStrategy::getInstance()->getOsOrderlineSelect())) 108 | return 0; 109 | 110 | //Delivery 111 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlNewOrderSelect, DialectStrategy::getInstance()->getDlNewOrderSelect())) 112 | return 0; 113 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlNewOrderDelete, DialectStrategy::getInstance()->getDlNewOrderDelete())) 114 | return 0; 115 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlOrderSelect, DialectStrategy::getInstance()->getDlOrderSelect())) 116 | return 0; 117 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlOrderUpdate, DialectStrategy::getInstance()->getDlOrderUpdate())) 118 | return 0; 119 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlOrderlineUpdate, DialectStrategy::getInstance()->getDlOrderlineUpdate())) 120 | return 0; 121 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlOrderlineSelect, DialectStrategy::getInstance()->getDlOrderlineSelect())) 122 | return 0; 123 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlCustomerUpdate, DialectStrategy::getInstance()->getDlCustomerUpdate())) 124 | return 0; 125 | 126 | //StockLevel 127 | if(!DbcTools::allocAndPrepareStmt(hDBC, slDistrictSelect, DialectStrategy::getInstance()->getSlDistrictSelect())) 128 | return 0; 129 | if(!DbcTools::allocAndPrepareStmt(hDBC, slStockSelect, DialectStrategy::getInstance()->getSlStockSelect())) 130 | return 0; 131 | 132 | return 1; 133 | 134 | } 135 | bool Transactions::prepareNewOrder(SQLHDBC& hDBC){ 136 | //NewOrder 137 | if(!DbcTools::allocAndPrepareStmt(hDBC, noWarehouseSelect, DialectStrategy::getInstance()->getNoWarehouseSelect())) 138 | return 0; 139 | if(!DbcTools::allocAndPrepareStmt(hDBC, noDistrictSelect, DialectStrategy::getInstance()->getNoDistrictSelect())) 140 | return 0; 141 | if(!DbcTools::allocAndPrepareStmt(hDBC, noDistrictUpdate, DialectStrategy::getInstance()->getNoDistrictUpdate())) 142 | return 0; 143 | if(!DbcTools::allocAndPrepareStmt(hDBC, noCustomerSelect, DialectStrategy::getInstance()->getNoCustomerSelect())) 144 | return 0; 145 | if(!DbcTools::allocAndPrepareStmt(hDBC, noItemSelect, DialectStrategy::getInstance()->getNoItemSelect())) 146 | return 0; 147 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[0], DialectStrategy::getInstance()->getNoStockSelect01())) 148 | return 0; 149 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[1], DialectStrategy::getInstance()->getNoStockSelect02())) 150 | return 0; 151 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[2], DialectStrategy::getInstance()->getNoStockSelect03())) 152 | return 0; 153 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[3], DialectStrategy::getInstance()->getNoStockSelect04())) 154 | return 0; 155 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[4], DialectStrategy::getInstance()->getNoStockSelect05())) 156 | return 0; 157 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[5], DialectStrategy::getInstance()->getNoStockSelect06())) 158 | return 0; 159 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[6], DialectStrategy::getInstance()->getNoStockSelect07())) 160 | return 0; 161 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[7], DialectStrategy::getInstance()->getNoStockSelect08())) 162 | return 0; 163 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[8], DialectStrategy::getInstance()->getNoStockSelect09())) 164 | return 0; 165 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockSelects[9], DialectStrategy::getInstance()->getNoStockSelect10())) 166 | return 0; 167 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockUpdates[0], DialectStrategy::getInstance()->getNoStockUpdate01())) 168 | return 0; 169 | if(!DbcTools::allocAndPrepareStmt(hDBC, noStockUpdates[1], DialectStrategy::getInstance()->getNoStockUpdate02())) 170 | return 0; 171 | if(!DbcTools::allocAndPrepareStmt(hDBC, noOrderlineInsert, DialectStrategy::getInstance()->getNoOrderlineInsert())) 172 | return 0; 173 | if(!DbcTools::allocAndPrepareStmt(hDBC, noOrderInsert, DialectStrategy::getInstance()->getNoOrderInsert())) 174 | return 0; 175 | if(!DbcTools::allocAndPrepareStmt(hDBC, noNewOrderInsert, DialectStrategy::getInstance()->getNoNewOrderInsert())) 176 | return 0; 177 | } 178 | bool Transactions::preparePayment(SQLHDBC& hDBC){ 179 | //Payment 180 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmWarehouseSelect, DialectStrategy::getInstance()->getPmWarehouseSelect())) 181 | return 0; 182 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmWarehouseUpdate, DialectStrategy::getInstance()->getPmWarehouseUpdate())) 183 | return 0; 184 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmDistrictSelect, DialectStrategy::getInstance()->getPmDistrictSelect())) 185 | return 0; 186 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmDistrictUpdate, DialectStrategy::getInstance()->getPmDistrictUpdate())) 187 | return 0; 188 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmCustomerSelect1, DialectStrategy::getInstance()->getPmCustomerSelect1())) 189 | return 0; 190 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmCustomerSelect2, DialectStrategy::getInstance()->getPmCustomerSelect2())) 191 | return 0; 192 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmCustomerSelect3, DialectStrategy::getInstance()->getPmCustomerSelect3())) 193 | return 0; 194 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmCustomerUpdate1, DialectStrategy::getInstance()->getPmCustomerUpdate1())) 195 | return 0; 196 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmCustomerSelect4, DialectStrategy::getInstance()->getPmCustomerSelect4())) 197 | return 0; 198 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmCustomerUpdate2, DialectStrategy::getInstance()->getPmCustomerUpdate2())) 199 | return 0; 200 | if(!DbcTools::allocAndPrepareStmt(hDBC, pmHistoryInsert, DialectStrategy::getInstance()->getPmHistoryInsert())) 201 | return 0; 202 | } 203 | bool Transactions::prepareOrderStatus(SQLHDBC& hDBC){ 204 | //OrderStatus: 205 | if(!DbcTools::allocAndPrepareStmt(hDBC, osCustomerSelect1, DialectStrategy::getInstance()->getOsCustomerSelect1())) 206 | return 0; 207 | if(!DbcTools::allocAndPrepareStmt(hDBC, osCustomerSelect2, DialectStrategy::getInstance()->getOsCustomerSelect2())) 208 | return 0; 209 | if(!DbcTools::allocAndPrepareStmt(hDBC, osCustomerSelect3, DialectStrategy::getInstance()->getOsCustomerSelect3())) 210 | return 0; 211 | if(!DbcTools::allocAndPrepareStmt(hDBC, osOrderSelect, DialectStrategy::getInstance()->getOsOrderSelect())) 212 | return 0; 213 | if(!DbcTools::allocAndPrepareStmt(hDBC, osOrderlineSelect, DialectStrategy::getInstance()->getOsOrderlineSelect())) 214 | return 0; 215 | } 216 | bool Transactions::prepareDelivery(SQLHDBC& hDBC){ 217 | //Delivery 218 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlNewOrderSelect, DialectStrategy::getInstance()->getDlNewOrderSelect())) 219 | return 0; 220 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlNewOrderDelete, DialectStrategy::getInstance()->getDlNewOrderDelete())) 221 | return 0; 222 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlOrderSelect, DialectStrategy::getInstance()->getDlOrderSelect())) 223 | return 0; 224 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlOrderUpdate, DialectStrategy::getInstance()->getDlOrderUpdate())) 225 | return 0; 226 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlOrderlineUpdate, DialectStrategy::getInstance()->getDlOrderlineUpdate())) 227 | return 0; 228 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlOrderlineSelect, DialectStrategy::getInstance()->getDlOrderlineSelect())) 229 | return 0; 230 | if(!DbcTools::allocAndPrepareStmt(hDBC, dlCustomerUpdate, DialectStrategy::getInstance()->getDlCustomerUpdate())) 231 | return 0; 232 | } 233 | bool Transactions::prepareStockLevel(SQLHDBC& hDBC){ 234 | //StockLevel 235 | if(!DbcTools::allocAndPrepareStmt(hDBC, slDistrictSelect, DialectStrategy::getInstance()->getSlDistrictSelect())) 236 | return 0; 237 | if(!DbcTools::allocAndPrepareStmt(hDBC, slStockSelect, DialectStrategy::getInstance()->getSlStockSelect())) 238 | return 0; 239 | 240 | } 241 | 242 | 243 | 244 | bool Transactions::prepareStatements(SQLHDBC& hDBC){ 245 | if(!prepare(hDBC)){ 246 | Log::l2() << Log::tm() << "-prepare statements failed\n"; 247 | return 0; 248 | } 249 | Log::l1() << Log::tm() << "-prepare statements succeeded\n"; 250 | return 1; 251 | } 252 | 253 | bool Transactions::executeNewOrder(SQLHDBC& hDBC){ 254 | prepareNewOrder(hDBC); 255 | struct OrderLine{ 256 | int olIId; 257 | int olSupplyWId; 258 | bool olIsRemote; 259 | int olQuantity; 260 | }; 261 | 262 | //2.4.1.1 263 | int wId = 0; 264 | DataSource::randomUniformInt(1,Config::getWarehouseCount(), wId); 265 | //2.4.1.2 266 | int dId = 0; 267 | DataSource::randomUniformInt(1,10,dId); 268 | int cId = 0; 269 | DataSource::randomNonUniformInt(1023,1,3000,867,cId); 270 | //2.4.1.3 271 | int olCount = 0; 272 | DataSource::randomUniformInt(5,15,olCount); 273 | //2.4.1.4 274 | int randomRollback = 0; 275 | DataSource::randomUniformInt(1,100,randomRollback); 276 | //2.4.1.5 277 | int allLocal=1; 278 | OrderLine oLines[olCount]; 279 | for(int i=0; igetNoStockSelect05())) 394 | return 0; 395 | DbcTools::resetStatement(noStockSelects[dId-1]); 396 | DbcTools::bind(noStockSelects[dId-1],1,oLines[i].olIId); 397 | DbcTools::bind(noStockSelects[dId-1],2,oLines[i].olSupplyWId); 398 | if(!DbcTools::executePreparedStatement(noStockSelects[dId-1])){ 399 | DbcTools::rollback(hDBC); 400 | return 0; 401 | } 402 | sQuantity = 0; 403 | sDist = ""; 404 | if(SQL_SUCCESS==SQLFetch(noStockSelects[dId-1])){ 405 | if(SQL_SUCCESS==SQLGetData(noStockSelects[dId-1],1,SQL_C_CHAR,buf,1024,&nIdicator)){ 406 | sQuantity = strtol ((char*)buf,NULL,0); 407 | } 408 | else{ 409 | DbcTools::rollback(hDBC); 410 | return 0; 411 | } 412 | 413 | if(SQL_SUCCESS==SQLGetData(noStockSelects[dId-1],2,SQL_C_CHAR,buf,1024,&nIdicator)){ 414 | sDist = string((char*)buf); 415 | } 416 | else{ 417 | DbcTools::rollback(hDBC); 418 | return 0; 419 | } 420 | } 421 | else{ 422 | DbcTools::rollback(hDBC); 423 | return 0; 424 | } 425 | 426 | DbcTools::resetStatement(noStockUpdates[(oLines[i].olIsRemote?1:0)]); 427 | DbcTools::bind(noStockUpdates[(oLines[i].olIsRemote?1:0)],1, oLines[i].olQuantity); 428 | int tmp1 = 0; 429 | if(oLines[i].olQuantity<=sQuantity-10) 430 | tmp1 = sQuantity-oLines[i].olQuantity; 431 | else 432 | tmp1 = sQuantity-oLines[i].olQuantity+91; 433 | DbcTools::bind(noStockUpdates[(oLines[i].olIsRemote?1:0)],2, tmp1); 434 | DbcTools::bind(noStockUpdates[(oLines[i].olIsRemote?1:0)],3, oLines[i].olIId); 435 | DbcTools::bind(noStockUpdates[(oLines[i].olIsRemote?1:0)],4, oLines[i].olSupplyWId); 436 | if(!DbcTools::executePreparedStatement(noStockUpdates[(oLines[i].olIsRemote?1:0)])){ 437 | DbcTools::rollback(hDBC); 438 | return 0; 439 | } 440 | 441 | DbcTools::resetStatement(noOrderlineInsert); 442 | DbcTools::bind(noOrderlineInsert,1,dNextOId); 443 | DbcTools::bind(noOrderlineInsert,2,dId); 444 | DbcTools::bind(noOrderlineInsert,3,wId); 445 | tmp1 = i+1; 446 | DbcTools::bind(noOrderlineInsert,4,tmp1); 447 | DbcTools::bind(noOrderlineInsert,5,(oLines[i].olIId)); 448 | DbcTools::bind(noOrderlineInsert,6,(oLines[i].olSupplyWId)); 449 | DbcTools::bind(noOrderlineInsert,7,(oLines[i].olQuantity)); 450 | tmp2 = iPrice*oLines[i].olQuantity; 451 | DbcTools::bind(noOrderlineInsert,8,tmp2); 452 | //日志1 453 | char buffer[24]; 454 | //strcpy(buffer,sDist.c_str()); 455 | memcpy(buffer,sDist.c_str(),sizeof(buffer)); 456 | DbcTools::bind(noOrderlineInsert,9,24,buffer); 457 | if(!DbcTools::executePreparedStatement(noOrderlineInsert)){ 458 | DbcTools::rollback(hDBC); 459 | return 0; 460 | } 461 | } 462 | 463 | //COMMIT 464 | if(DbcTools::commit(hDBC)){ 465 | return 1; 466 | } 467 | DbcTools::rollback(hDBC); 468 | return 0; 469 | } 470 | 471 | bool Transactions::executePayment(SQLHDBC& hDBC){ 472 | //这里提前放出来查询准备 473 | preparePayment(hDBC); 474 | // 475 | 476 | //2.5.1.1 477 | int wId = 0; 478 | DataSource::randomUniformInt(1,Config::getWarehouseCount(),wId); 479 | //2.5.1.2 480 | int dId = 0; 481 | DataSource::randomUniformInt(1,10,dId); 482 | 483 | int x = 0; 484 | DataSource::randomUniformInt(1,100,x); 485 | int cDId = 0; 486 | int cWId = 0; 487 | if(x<=85){ 488 | cDId = dId; 489 | cWId = wId; 490 | } 491 | else{ 492 | DataSource::randomUniformInt(1,10,cDId); 493 | DataSource::getRemoteWId(wId,cWId); 494 | } 495 | 496 | int y = 0; 497 | DataSource::randomUniformInt(1,100,y); 498 | int cId = 0; 499 | string cLast = ""; 500 | if(y<=60){ 501 | DataSource::randomCLast(cLast); 502 | } 503 | else{ 504 | DataSource::randomNonUniformInt(1023,1,3000,867,cId); 505 | } 506 | 507 | //2.5.1.3 508 | double hAmount = 0; 509 | DataSource::randomDouble(1.00,5000.00,2,hAmount); 510 | 511 | //2.5.1.4 512 | SQL_TIMESTAMP_STRUCT hDate; 513 | DataSource::getCurrentTimestamp(hDate); 514 | 515 | SQLLEN nIdicator = 0; 516 | SQLCHAR buf[1024] = {0}; 517 | 518 | //BEGIN TRANSACTION 519 | DbcTools::resetStatement(pmWarehouseSelect); 520 | DbcTools::bind(pmWarehouseSelect,1,wId); 521 | if(!DbcTools::executePreparedStatement(pmWarehouseSelect)){ 522 | DbcTools::rollback(hDBC); 523 | return 0; 524 | } 525 | string wName=""; 526 | if(!DbcTools::fetch(pmWarehouseSelect,buf,&nIdicator,1,wName)){ 527 | DbcTools::rollback(hDBC); 528 | return 0; 529 | } 530 | 531 | DbcTools::resetStatement(pmWarehouseUpdate); 532 | DbcTools::bind(pmWarehouseUpdate,1,hAmount); 533 | DbcTools::bind(pmWarehouseUpdate,2,wId); 534 | if(!DbcTools::executePreparedStatement(pmWarehouseUpdate)){ 535 | DbcTools::rollback(hDBC); 536 | return 0; 537 | } 538 | 539 | DbcTools::resetStatement(pmDistrictSelect); 540 | DbcTools::bind(pmDistrictSelect,1,wId); 541 | DbcTools::bind(pmDistrictSelect,2,dId); 542 | if(!DbcTools::executePreparedStatement(pmDistrictSelect)){ 543 | DbcTools::rollback(hDBC); 544 | return 0; 545 | } 546 | string dName=""; 547 | if(!DbcTools::fetch(pmDistrictSelect,buf,&nIdicator,1,dName)){ 548 | DbcTools::rollback(hDBC); 549 | return 0; 550 | } 551 | 552 | DbcTools::resetStatement(pmDistrictUpdate); 553 | DbcTools::bind(pmDistrictUpdate,1,hAmount); 554 | DbcTools::bind(pmDistrictUpdate,2,wId); 555 | DbcTools::bind(pmDistrictUpdate,3,dId); 556 | if(!DbcTools::executePreparedStatement(pmDistrictUpdate)){ 557 | DbcTools::rollback(hDBC); 558 | return 0; 559 | } 560 | string cCredit; 561 | if(y<=60){ //Case 2 562 | DbcTools::resetStatement(pmCustomerSelect1); 563 | char buffer1[16]; 564 | memcpy(buffer1,cLast.c_str(),sizeof(buffer1)); 565 | //strcpy(buffer1,cLast.c_str()); 566 | DbcTools::bind(pmCustomerSelect1,1,16,buffer1); 567 | DbcTools::bind(pmCustomerSelect1,2,cDId); 568 | DbcTools::bind(pmCustomerSelect1,3,cWId); 569 | if(!DbcTools::executePreparedStatement(pmCustomerSelect1)){ 570 | DbcTools::rollback(hDBC); 571 | return 0; 572 | } 573 | int count = 0; 574 | if(!DbcTools::fetch(pmCustomerSelect1,buf,&nIdicator,1,count)){ 575 | DbcTools::rollback(hDBC); 576 | return 0; 577 | } 578 | 579 | DbcTools::resetStatement(pmCustomerSelect2); 580 | char buffer2[16]; 581 | memcpy(buffer2,cLast.c_str(),sizeof(buffer2)); 582 | // strcpy(buffer2,cLast.c_str()); 583 | DbcTools::bind(pmCustomerSelect2,1,16,buffer2); 584 | DbcTools::bind(pmCustomerSelect2,2,cDId); 585 | DbcTools::bind(pmCustomerSelect2,3,cWId); 586 | if(!DbcTools::executePreparedStatement(pmCustomerSelect2)){ 587 | DbcTools::rollback(hDBC); 588 | return 0; 589 | } 590 | cId = 0; 591 | cCredit = ""; 592 | for(int i=0; i < ((count+1)/2)-1; i++){ //move cursor 593 | SQLFetch(pmCustomerSelect2); 594 | } 595 | if(SQL_SUCCESS==SQLFetch(pmCustomerSelect2)){ 596 | if(SQL_SUCCESS==SQLGetData(pmCustomerSelect2,1,SQL_C_CHAR,buf,1024,&nIdicator)) 597 | cId = strtol ((char*)buf,NULL,0); 598 | else{ 599 | DbcTools::rollback(hDBC); 600 | return 0; 601 | } 602 | if(SQL_SUCCESS==SQLGetData(pmCustomerSelect2,11,SQL_C_CHAR,buf,1024,&nIdicator)) 603 | cCredit = string((char*)buf); 604 | else{ 605 | DbcTools::rollback(hDBC); 606 | return 0; 607 | } 608 | } 609 | else{ 610 | DbcTools::rollback(hDBC); 611 | return 0; 612 | } 613 | } 614 | else{ //Case 1 615 | DbcTools::resetStatement(pmCustomerSelect3); 616 | DbcTools::bind(pmCustomerSelect3,1,cId); 617 | DbcTools::bind(pmCustomerSelect3,2,cDId); 618 | DbcTools::bind(pmCustomerSelect3,3,cWId); 619 | if(!DbcTools::executePreparedStatement(pmCustomerSelect3)){ 620 | DbcTools::rollback(hDBC); 621 | return 0; 622 | } 623 | cCredit = ""; 624 | if(!DbcTools::fetch(pmCustomerSelect3,buf,&nIdicator,11,cCredit)){ 625 | DbcTools::rollback(hDBC); 626 | return 0; 627 | } 628 | } 629 | 630 | DbcTools::resetStatement(pmCustomerUpdate1); 631 | DbcTools::bind(pmCustomerUpdate1,1,hAmount); 632 | DbcTools::bind(pmCustomerUpdate1,2,hAmount); 633 | DbcTools::bind(pmCustomerUpdate1,3,cId); 634 | DbcTools::bind(pmCustomerUpdate1,4,cDId); 635 | DbcTools::bind(pmCustomerUpdate1,5,cWId); 636 | if(!DbcTools::executePreparedStatement(pmCustomerUpdate1)){ 637 | DbcTools::rollback(hDBC); 638 | return 0; 639 | } 640 | 641 | if(cCredit=="BC"){ 642 | DbcTools::resetStatement(pmCustomerSelect4); 643 | DbcTools::bind(pmCustomerSelect4,1,cId); 644 | DbcTools::bind(pmCustomerSelect4,2,cDId); 645 | DbcTools::bind(pmCustomerSelect4,3,cWId); 646 | if(!DbcTools::executePreparedStatement(pmCustomerSelect4)){ 647 | DbcTools::rollback(hDBC); 648 | return 0; 649 | } 650 | string cData = ""; 651 | if(!DbcTools::fetch(pmCustomerSelect4,buf,&nIdicator,1,cData)){ 652 | DbcTools::rollback(hDBC); 653 | return 0; 654 | } 655 | cData = to_string(cId)+","+to_string(cDId)+","+to_string(cWId)+","+to_string(dId)+","+to_string(wId)+","+to_string(hAmount)+","+cData; 656 | if(cData.length()>500) 657 | cData = cData.substr(0,500); 658 | 659 | DbcTools::resetStatement(pmCustomerUpdate2); 660 | char buffer3[500]; 661 | //strcpy(buffer3,cData.c_str()); 662 | memcpy(buffer3,cData.c_str(),sizeof(buffer3)); 663 | 664 | DbcTools::bind(pmCustomerUpdate2,1,500,buffer3); 665 | DbcTools::bind(pmCustomerUpdate2,2,cId); 666 | DbcTools::bind(pmCustomerUpdate2,3,cDId); 667 | DbcTools::bind(pmCustomerUpdate2,4,cWId); 668 | if(!DbcTools::executePreparedStatement(pmCustomerUpdate2)){ 669 | DbcTools::rollback(hDBC); 670 | return 0; 671 | } 672 | } 673 | 674 | string hData = wName + " " + dName; 675 | 676 | DbcTools::resetStatement(pmHistoryInsert); 677 | DbcTools::bind(pmHistoryInsert,1,cId); 678 | DbcTools::bind(pmHistoryInsert,2,cDId); 679 | DbcTools::bind(pmHistoryInsert,3,cWId); 680 | DbcTools::bind(pmHistoryInsert,4,dId); 681 | DbcTools::bind(pmHistoryInsert,5,wId); 682 | DbcTools::bind(pmHistoryInsert,6,hDate); 683 | DbcTools::bind(pmHistoryInsert,7,hAmount); 684 | char buffer4[24]; 685 | //strcpy(buffer4,hData.c_str()); 686 | memcpy(buffer4,hData.c_str(),sizeof(buffer4)); 687 | DbcTools::bind(pmHistoryInsert,8,24,buffer4); 688 | if(!DbcTools::executePreparedStatement(pmHistoryInsert)){ 689 | DbcTools::rollback(hDBC); 690 | return 0; 691 | } 692 | 693 | //COMMIT 694 | if(DbcTools::commit(hDBC)){ 695 | return 1; 696 | } 697 | DbcTools::rollback(hDBC); 698 | return 0; 699 | } 700 | 701 | bool Transactions::executeOrderStatus(SQLHDBC& hDBC){ 702 | prepareOrderStatus(hDBC); 703 | //2.6.1.1 704 | int wId = 0; 705 | DataSource::randomUniformInt(1,Config::getWarehouseCount(), wId); 706 | //2.6.1.2 707 | int dId = 0; 708 | DataSource::randomUniformInt(1,10,dId); 709 | int y = 0; 710 | DataSource::randomUniformInt(1,100,y); 711 | int cId = 0; 712 | string cLast = ""; 713 | if(y<=60){ 714 | DataSource::randomCLast(cLast); 715 | } 716 | else{ 717 | DataSource::randomNonUniformInt(1023,1,3000,867,cId); 718 | } 719 | 720 | SQLLEN nIdicator = 0; 721 | SQLCHAR buf[1024] = {0}; 722 | 723 | //BEGIN TRANSACTION 724 | if(y<=60){ //Case 2 725 | DbcTools::resetStatement(osCustomerSelect1); 726 | char buffer1[16]; 727 | //strcpy(buffer1,cLast.c_str()); 728 | memcpy(buffer1,cLast.c_str(),sizeof(buffer1)); 729 | DbcTools::bind(osCustomerSelect1,1,16,buffer1); 730 | DbcTools::bind(osCustomerSelect1,2,dId); 731 | DbcTools::bind(osCustomerSelect1,3,wId); 732 | if(!DbcTools::executePreparedStatement(osCustomerSelect1)){ 733 | DbcTools::rollback(hDBC); 734 | return 0; 735 | } 736 | int count = 0; 737 | if(!DbcTools::fetch(osCustomerSelect1, buf, &nIdicator, 1, count)){ 738 | DbcTools::rollback(hDBC); 739 | return 0; 740 | } 741 | 742 | DbcTools::resetStatement(osCustomerSelect2); 743 | char buffer2[16]; 744 | //strcpy(buffer2,cLast.c_str()); 745 | memcpy(buffer2,cLast.c_str(),sizeof(buffer2)); 746 | DbcTools::bind(osCustomerSelect2,1,16,buffer2); 747 | DbcTools::bind(osCustomerSelect2,2,dId); 748 | DbcTools::bind(osCustomerSelect2,3,wId); 749 | if(!DbcTools::executePreparedStatement(osCustomerSelect2)){ 750 | DbcTools::rollback(hDBC); 751 | return 0; 752 | } 753 | 754 | for(int i=0; i < ((count+1)/2)-1;i++){ //move cursor 755 | SQLFetch(osCustomerSelect2); 756 | } 757 | if(!DbcTools::fetch(osCustomerSelect2, buf, &nIdicator, 1, cId)){ 758 | DbcTools::rollback(hDBC); 759 | return 0; 760 | } 761 | } 762 | else{ //Case 1 763 | DbcTools::resetStatement(osCustomerSelect3); 764 | DbcTools::bind(osCustomerSelect3,1,cId); 765 | DbcTools::bind(osCustomerSelect3,2,dId); 766 | DbcTools::bind(osCustomerSelect3,3,wId); 767 | if(!DbcTools::executePreparedStatement(osCustomerSelect3)){ 768 | DbcTools::rollback(hDBC); 769 | return 0; 770 | } 771 | } 772 | 773 | DbcTools::resetStatement(osOrderSelect); 774 | DbcTools::bind(osOrderSelect,1,wId); 775 | DbcTools::bind(osOrderSelect,2,dId); 776 | DbcTools::bind(osOrderSelect,3,cId); 777 | DbcTools::bind(osOrderSelect,4,wId); 778 | DbcTools::bind(osOrderSelect,5,dId); 779 | DbcTools::bind(osOrderSelect,6,cId); 780 | if(!DbcTools::executePreparedStatement(osOrderSelect)){ 781 | DbcTools::rollback(hDBC); 782 | return 0; 783 | } 784 | int oId = 0; 785 | if(!DbcTools::fetch(osOrderSelect, buf, &nIdicator, 1, oId)){ 786 | DbcTools::rollback(hDBC); 787 | return 0; 788 | } 789 | 790 | DbcTools::resetStatement(osOrderlineSelect); 791 | DbcTools::bind(osOrderlineSelect,1,wId); 792 | DbcTools::bind(osOrderlineSelect,2,dId); 793 | DbcTools::bind(osOrderlineSelect,3,oId); 794 | if(!DbcTools::executePreparedStatement(osOrderlineSelect)){ 795 | DbcTools::rollback(hDBC); 796 | return 0; 797 | } 798 | 799 | //COMMIT 800 | if(DbcTools::commit(hDBC)){ 801 | return 1; 802 | } 803 | DbcTools::rollback(hDBC); 804 | return 0; 805 | } 806 | 807 | bool Transactions::executeDelivery(SQLHDBC& hDBC){ 808 | 809 | //2.7.1.1 810 | int wId = 0; 811 | DataSource::randomUniformInt(1,Config::getWarehouseCount(), wId); 812 | //2.7.1.2 813 | int oCarrierId = 0; 814 | DataSource::randomUniformInt(1,10,oCarrierId); 815 | //2.7.1.3 816 | SQL_TIMESTAMP_STRUCT olDeliveryD; 817 | DataSource::getCurrentTimestamp(olDeliveryD); 818 | 819 | SQLLEN nIdicator = 0; 820 | SQLCHAR buf[1024] = {0}; 821 | 822 | //BEGIN TRANSACTION 823 | int noOId; 824 | int oCId; 825 | double olAmount; 826 | for(int dId=1; dId <=10; dId++){ 827 | prepareDelivery(hDBC); 828 | DbcTools::resetStatement(dlNewOrderSelect); 829 | DbcTools::bind(dlNewOrderSelect,1,wId); 830 | DbcTools::bind(dlNewOrderSelect,2,dId); 831 | DbcTools::bind(dlNewOrderSelect,3,wId); 832 | DbcTools::bind(dlNewOrderSelect,4,dId); 833 | if(!DbcTools::executePreparedStatement(dlNewOrderSelect)){ 834 | DbcTools::rollback(hDBC); 835 | return 0; 836 | } 837 | noOId = 0; 838 | if(SQL_SUCCESS==SQLFetch(dlNewOrderSelect)){ 839 | if(SQL_SUCCESS==SQLGetData(dlNewOrderSelect,1,SQL_C_CHAR,buf,1024,&nIdicator)) 840 | noOId = strtol ((char*)buf,NULL,0); 841 | else{ 842 | DbcTools::rollback(hDBC); 843 | return 0; 844 | } 845 | } 846 | else //If no matching row is found, then the delivery of an order for this district is skipped. 847 | continue; 848 | 849 | DbcTools::resetStatement(dlNewOrderDelete); 850 | DbcTools::bind(dlNewOrderDelete,1,wId); 851 | DbcTools::bind(dlNewOrderDelete,2,dId); 852 | DbcTools::bind(dlNewOrderDelete,3,noOId); 853 | if(!DbcTools::executePreparedStatement(dlNewOrderDelete)){ 854 | DbcTools::rollback(hDBC); 855 | return 0; 856 | } 857 | 858 | DbcTools::resetStatement(dlOrderSelect); 859 | DbcTools::bind(dlOrderSelect,1,wId); 860 | DbcTools::bind(dlOrderSelect,2,dId); 861 | DbcTools::bind(dlOrderSelect,3,noOId); 862 | if(!DbcTools::executePreparedStatement(dlOrderSelect)){ 863 | DbcTools::rollback(hDBC); 864 | return 0; 865 | } 866 | oCId = 0; 867 | if(!DbcTools::fetch(dlOrderSelect, buf, &nIdicator, 1, oCId)){ 868 | DbcTools::rollback(hDBC); 869 | return 0; 870 | } 871 | 872 | DbcTools::resetStatement(dlOrderUpdate); 873 | DbcTools::bind(dlOrderUpdate,1,oCarrierId); 874 | DbcTools::bind(dlOrderUpdate,2,wId); 875 | DbcTools::bind(dlOrderUpdate,3,dId); 876 | DbcTools::bind(dlOrderUpdate,4,noOId); 877 | if(!DbcTools::executePreparedStatement(dlOrderUpdate)){ 878 | DbcTools::rollback(hDBC); 879 | return 0; 880 | } 881 | 882 | DbcTools::resetStatement(dlOrderlineUpdate); 883 | DbcTools::bind(dlOrderlineUpdate,1,olDeliveryD); 884 | DbcTools::bind(dlOrderlineUpdate,2,wId); 885 | DbcTools::bind(dlOrderlineUpdate,3,dId); 886 | DbcTools::bind(dlOrderlineUpdate,4,noOId); 887 | if(!DbcTools::executePreparedStatement(dlOrderlineUpdate)){ 888 | DbcTools::rollback(hDBC); 889 | return 0; 890 | } 891 | 892 | DbcTools::resetStatement(dlOrderlineSelect); 893 | DbcTools::bind(dlOrderlineSelect,1,wId); 894 | DbcTools::bind(dlOrderlineSelect,2,dId); 895 | DbcTools::bind(dlOrderlineSelect,3,noOId); 896 | if(!DbcTools::executePreparedStatement(dlOrderlineSelect)){ 897 | DbcTools::rollback(hDBC); 898 | return 0; 899 | } 900 | olAmount = 0; 901 | if(!DbcTools::fetch(dlOrderlineSelect, buf, &nIdicator, 1, olAmount)){ 902 | DbcTools::rollback(hDBC); 903 | return 0; 904 | } 905 | 906 | DbcTools::resetStatement(dlCustomerUpdate); 907 | DbcTools::bind(dlCustomerUpdate,1,olAmount); 908 | DbcTools::bind(dlCustomerUpdate,2,oCId); 909 | DbcTools::bind(dlCustomerUpdate,3,dId); 910 | DbcTools::bind(dlCustomerUpdate,4,wId); 911 | if(!DbcTools::executePreparedStatement(dlCustomerUpdate)){ 912 | DbcTools::rollback(hDBC); 913 | return 0; 914 | } 915 | 916 | //COMMIT 917 | if(!DbcTools::commit(hDBC)){ 918 | DbcTools::rollback(hDBC); 919 | return 0; 920 | } 921 | } 922 | return 1; 923 | } 924 | 925 | bool Transactions::executeStockLevel(SQLHDBC& hDBC){ 926 | prepareStockLevel(hDBC); 927 | //2.8.1.1 928 | int wId = 0; 929 | DataSource::randomUniformInt(1,Config::getWarehouseCount(), wId); 930 | int dId = 0; 931 | DataSource::randomUniformInt(1,10, dId); 932 | //2.8.1.2 933 | int threshold = 0; 934 | DataSource::randomUniformInt(10,20,threshold); 935 | 936 | SQLLEN nIdicator = 0; 937 | SQLCHAR buf[1024] = {0}; 938 | 939 | //BEGIN TRANSACTION 940 | DbcTools::resetStatement(slDistrictSelect); 941 | DbcTools::bind(slDistrictSelect,1,wId); 942 | DbcTools::bind(slDistrictSelect,2,dId); 943 | if(!DbcTools::executePreparedStatement(slDistrictSelect)){ 944 | DbcTools::rollback(hDBC); 945 | return 0; 946 | } 947 | int dNextOId=0; 948 | if(!DbcTools::fetch(slDistrictSelect, buf, &nIdicator, 1, dNextOId)){ 949 | DbcTools::rollback(hDBC); 950 | return 0; 951 | } 952 | 953 | DbcTools::resetStatement(slStockSelect); 954 | DbcTools::bind(slStockSelect,1,wId); 955 | DbcTools::bind(slStockSelect,2,dId); 956 | DbcTools::bind(slStockSelect,3,dNextOId); 957 | int tmp = dNextOId-20; 958 | DbcTools::bind(slStockSelect,4,tmp); 959 | DbcTools::bind(slStockSelect,5,wId); 960 | DbcTools::bind(slStockSelect,6,threshold); 961 | //日志4 962 | if(!DbcTools::executePreparedStatement(slStockSelect)){ 963 | DbcTools::rollback(hDBC); 964 | return 0; 965 | } 966 | 967 | //COMMIT 968 | if(DbcTools::commit(hDBC)){ 969 | return 1; 970 | } 971 | DbcTools::rollback(hDBC); 972 | return 0; 973 | } 974 | -------------------------------------------------------------------------------- /src/Transactions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef TRANSACTIONS_H 18 | #define TRANSACTIONS_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | class Transactions{ 25 | 26 | private: 27 | SQLHSTMT noWarehouseSelect = 0; 28 | SQLHSTMT noDistrictSelect = 0; 29 | SQLHSTMT noDistrictUpdate = 0; 30 | SQLHSTMT noCustomerSelect = 0; 31 | SQLHSTMT noItemSelect = 0; 32 | SQLHSTMT noStockSelects[10] = {0,0,0,0,0,0,0,0,0,0}; 33 | SQLHSTMT noStockUpdates[2] = {0,0}; 34 | SQLHSTMT noOrderlineInsert = 0; 35 | SQLHSTMT noOrderInsert = 0; 36 | SQLHSTMT noNewOrderInsert = 0; 37 | 38 | SQLHSTMT pmWarehouseSelect = 0; 39 | SQLHSTMT pmWarehouseUpdate = 0; 40 | SQLHSTMT pmDistrictSelect = 0; 41 | SQLHSTMT pmDistrictUpdate = 0; 42 | SQLHSTMT pmCustomerSelect1 = 0; 43 | SQLHSTMT pmCustomerSelect2 = 0; 44 | SQLHSTMT pmCustomerSelect3 = 0; 45 | SQLHSTMT pmCustomerUpdate1 = 0; 46 | SQLHSTMT pmCustomerSelect4 = 0; 47 | SQLHSTMT pmCustomerUpdate2 = 0; 48 | SQLHSTMT pmHistoryInsert = 0; 49 | 50 | SQLHSTMT osCustomerSelect1 = 0; 51 | SQLHSTMT osCustomerSelect2 = 0; 52 | SQLHSTMT osCustomerSelect3 = 0; 53 | SQLHSTMT osOrderSelect = 0; 54 | SQLHSTMT osOrderlineSelect = 0; 55 | 56 | SQLHSTMT dlNewOrderSelect = 0; 57 | SQLHSTMT dlNewOrderDelete = 0; 58 | SQLHSTMT dlOrderSelect = 0; 59 | SQLHSTMT dlOrderUpdate = 0; 60 | SQLHSTMT dlOrderlineUpdate = 0; 61 | SQLHSTMT dlOrderlineSelect = 0; 62 | SQLHSTMT dlCustomerUpdate = 0; 63 | 64 | SQLHSTMT slDistrictSelect = 0; 65 | SQLHSTMT slStockSelect = 0; 66 | 67 | bool prepare(SQLHDBC& hDBC); 68 | bool prepareNewOrder(SQLHDBC& hDBC); 69 | bool preparePayment(SQLHDBC& hDBC); 70 | bool prepareOrderStatus(SQLHDBC& hDBC); 71 | bool prepareDelivery(SQLHDBC& hDBC); 72 | bool prepareStockLevel(SQLHDBC& hDBC); 73 | 74 | public: 75 | bool prepareStatements(SQLHDBC& hDBC); 76 | 77 | bool executeNewOrder(SQLHDBC& hDBC); 78 | bool executePayment(SQLHDBC& hDBC); 79 | bool executeOrderStatus(SQLHDBC& hDBC); 80 | bool executeDelivery(SQLHDBC& hDBC); 81 | bool executeStockLevel(SQLHDBC& hDBC); 82 | 83 | }; 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /src/TupleGen.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "Config.h" 18 | #include "TupleGen.h" 19 | 20 | using namespace std; 21 | 22 | ofstream TupleGen::warehouseStream; 23 | ofstream TupleGen::districtStream; 24 | ofstream TupleGen::customerStream; 25 | ofstream TupleGen::historyStream; 26 | ofstream TupleGen::neworderStream; 27 | ofstream TupleGen::orderStream; 28 | ofstream TupleGen::orderlineStream; 29 | ofstream TupleGen::itemStream; 30 | ofstream TupleGen::stockStream; 31 | ofstream TupleGen::nationStream; 32 | ofstream TupleGen::supplierStream; 33 | ofstream TupleGen::regionStream; 34 | 35 | void TupleGen::openOutputFiles(){ 36 | warehouseStream.open( (Config::getInitialDbCreationPath()+"/WAREHOUSE.tbl").c_str() ); 37 | districtStream.open( (Config::getInitialDbCreationPath()+"/DISTRICT.tbl").c_str() ); 38 | customerStream.open( (Config::getInitialDbCreationPath()+"/CUSTOMER.tbl").c_str() ); 39 | historyStream.open( (Config::getInitialDbCreationPath()+"/HISTORY.tbl").c_str() ); 40 | neworderStream.open( (Config::getInitialDbCreationPath()+"/NEWORDER.tbl").c_str() ); 41 | orderStream.open( (Config::getInitialDbCreationPath()+"/ORDER.tbl").c_str() ); 42 | orderlineStream.open( (Config::getInitialDbCreationPath()+"/ORDERLINE.tbl").c_str() ); 43 | itemStream.open( (Config::getInitialDbCreationPath()+"/ITEM.tbl").c_str() ); 44 | stockStream.open( (Config::getInitialDbCreationPath()+"/STOCK.tbl").c_str() ); 45 | nationStream.open( (Config::getInitialDbCreationPath()+"/NATION.tbl").c_str() ); 46 | supplierStream.open( (Config::getInitialDbCreationPath()+"/SUPPLIER.tbl").c_str() ); 47 | regionStream.open( (Config::getInitialDbCreationPath()+"/REGION.tbl").c_str() ); 48 | } 49 | 50 | void TupleGen::closeOutputFiles(){ 51 | warehouseStream.close(); 52 | districtStream.close(); 53 | customerStream.close(); 54 | historyStream.close(); 55 | neworderStream.close(); 56 | orderStream.close(); 57 | orderlineStream.close(); 58 | itemStream.close(); 59 | stockStream.close(); 60 | nationStream.close(); 61 | supplierStream.close(); 62 | regionStream.close(); 63 | } 64 | 65 | void TupleGen::genWarehouse(int& wId){ 66 | warehouseStream << wId << Config::getCsvDelim(); //W_ID 67 | DataSource::addAlphanumeric64(6,10,warehouseStream,1); //W_NAME 68 | DataSource::addAlphanumeric64(10,20,warehouseStream,1); //W_STREET_1 69 | DataSource::addAlphanumeric64(10,20,warehouseStream,1); //W_STREET_2 70 | DataSource::addAlphanumeric64(10,20,warehouseStream,1); //W_CITY 71 | DataSource::addAlphanumeric62(2,warehouseStream,1); //W_STATE 72 | DataSource::addWDCZip(warehouseStream,1); //W_ZIP 73 | DataSource::addDouble(0.0,0.2,4,warehouseStream,1); //W_TAX 74 | warehouseStream << "300000.00"; //W_YTD 75 | warehouseStream << endl; 76 | } 77 | 78 | void TupleGen::genDistrict(int& dId, int& wId){ 79 | districtStream << dId << Config::getCsvDelim(); //D_ID 80 | districtStream << wId << Config::getCsvDelim(); //D_W_ID 81 | DataSource::addAlphanumeric64(6,10,districtStream,1); //D_NAME 82 | DataSource::addAlphanumeric64(10,20,districtStream,1); //D_STREET_1 83 | DataSource::addAlphanumeric64(10,20,districtStream,1); //D_STREET_2 84 | DataSource::addAlphanumeric64(10,20,districtStream,1); //D_CITY 85 | DataSource::addAlphanumeric62(2,districtStream,1); //D_STATE 86 | DataSource::addWDCZip(districtStream,1); //D_ZIP 87 | DataSource::addDouble(0.0,0.2,4,districtStream,1); //D_TAX 88 | districtStream << "30000.00" << Config::getCsvDelim(); //D_YTD 89 | districtStream << "3001"; //D_NEXT_O_ID 90 | districtStream << endl; 91 | } 92 | 93 | void TupleGen::genCustomer(int& cId, int& dId, int& wId, string& customerTime){ 94 | string cLast=""; 95 | if(cId<=1000) 96 | DataSource::genCLast(cId-1,cLast); 97 | else 98 | DataSource::randomCLast(cLast); 99 | 100 | string cState = DataSource::randomAlphanumeric62(2); 101 | 102 | customerStream << cId << Config::getCsvDelim(); //C_ID 103 | customerStream << dId << Config::getCsvDelim(); //C_D_ID 104 | customerStream << wId << Config::getCsvDelim(); //C_W_ID 105 | DataSource::addAlphanumeric64(8,16,customerStream,1); //C_FIRST 106 | customerStream << "OE" << Config::getCsvDelim(); //C_MIDDLE 107 | customerStream << cLast << Config::getCsvDelim(); //C_LAST 108 | DataSource::addAlphanumeric64(10,20,customerStream,1); //C_STREET_1 109 | DataSource::addAlphanumeric64(10,20,customerStream,1); //C_STREET_2 110 | DataSource::addAlphanumeric64(10,20,customerStream,1); //C_CITY 111 | customerStream << cState << Config::getCsvDelim(); //C_STATE 112 | DataSource::addWDCZip(customerStream,1); //C_ZIP 113 | DataSource::addNumeric(16,customerStream,1); //C_PHONE 114 | customerStream << customerTime << Config::getCsvDelim(); //C_SINCE - date/time given by the os when the CUSTOMER table was populated 115 | customerStream << (DataSource::randomTrue(0.1)?"BC":"GC") << Config::getCsvDelim(); //C_CREDIT 116 | customerStream << "50000.00" << Config::getCsvDelim(); //C_CREDIT_LIM 117 | DataSource::addDouble(0.0,0.5,4,customerStream,1); //C_DISCOUNT 118 | customerStream << "-10.00" << Config::getCsvDelim(); //C_BALANCE 119 | customerStream << "10.00" << Config::getCsvDelim(); //C_YTD_PAYMENT 120 | customerStream << "1" << Config::getCsvDelim(); //C_PAYMENT_CNT 121 | customerStream << "0" << Config::getCsvDelim(); //C_DELIVERY_CNT 122 | DataSource::addAlphanumeric64(300,500,customerStream,1); //C_DATA 123 | customerStream << (int)(cState.c_str())[0]; //C_N_NATIONKEY 124 | customerStream << endl; 125 | } 126 | 127 | void TupleGen::genHistory(int& cId, int& dId, int& wId){ 128 | historyStream << cId << Config::getCsvDelim(); //H_C_ID 129 | historyStream << dId << Config::getCsvDelim(); //H_C_D_ID 130 | historyStream << wId << Config::getCsvDelim(); //H_C_W_ID 131 | historyStream << dId << Config::getCsvDelim(); //H_D_ID 132 | historyStream << wId << Config::getCsvDelim(); //H_W_ID 133 | historyStream << DataSource::getCurrentTimeString() << Config::getCsvDelim(); //H_DATE - current date and time 134 | historyStream << "10.00" << Config::getCsvDelim(); //H_AMOUNT 135 | DataSource::addAlphanumeric64(12,24,historyStream,0); //H_DATA 136 | historyStream << endl; 137 | } 138 | 139 | void TupleGen::genNeworder(int& oId, int& dId, int& wId){ 140 | neworderStream << oId << Config::getCsvDelim(); //NO_O_ID 141 | neworderStream << dId << Config::getCsvDelim(); //NO_D_ID 142 | neworderStream << wId; //NO_W_ID 143 | neworderStream << endl; 144 | } 145 | 146 | void TupleGen::genOrder(int& oId, int& dId, int& wId, int& cId, int& olCount, string& orderTime){ 147 | orderStream << oId << Config::getCsvDelim(); //O_ID 148 | orderStream << dId << Config::getCsvDelim(); //O_D_ID 149 | orderStream << wId << Config::getCsvDelim(); //O_W_ID 150 | orderStream << cId << Config::getCsvDelim(); //O_C_ID 151 | orderStream << orderTime << Config::getCsvDelim(); //O_ENTRY_D - current date/ time given by the os 152 | if(oId<=2100) //O_CARRIER_ID - random within [1 .. 10] if O_ID <= 2100, null otherwise 153 | DataSource::addInt(1,10,orderStream,1); 154 | else 155 | orderStream << "" << Config::getCsvDelim(); 156 | orderStream << olCount << Config::getCsvDelim(); //O_OL_CNT 157 | orderStream << "1"; //O_ALL_LOCAL 158 | orderStream << endl; 159 | } 160 | 161 | void TupleGen::genOrderline(int& oId, int& dId, int& wId, int& olNumber, string& orderTime){ 162 | orderlineStream << oId << Config::getCsvDelim(); //OL_O_ID 163 | orderlineStream << dId << Config::getCsvDelim(); //OL_D_ID 164 | orderlineStream << wId << Config::getCsvDelim(); //OL_W_ID 165 | orderlineStream << olNumber << Config::getCsvDelim(); //OL_NUMBER 166 | DataSource::addInt(1,100000,orderlineStream,1); //OL_I_ID 167 | orderlineStream << wId << Config::getCsvDelim(); //OL_SUPPLY_W_ID 168 | orderlineStream << (oId<=2100?orderTime:"") << Config::getCsvDelim(); //OL_DELIVERY_D = O_ENTRY_D if OL_O_ID <= 2100, null otherwise 169 | orderlineStream << "5" << Config::getCsvDelim(); //OL_QUANTITY 170 | if(oId<=2100) //OL_AMOUNT = 0.00 if OL_O_ID <= 2100, random within [0.01..9999.99] otherwise 171 | orderlineStream << "0.00" << Config::getCsvDelim(); 172 | else 173 | DataSource::addDouble(0.01,9999.99,2,orderlineStream,1); 174 | DataSource::addAlphanumeric64(24,orderlineStream,0); //OL_DIST_INFO 175 | orderlineStream << endl; 176 | } 177 | 178 | void TupleGen::genItem(int& iId){ 179 | itemStream << iId << Config::getCsvDelim(); //I_ID 180 | DataSource::addInt(1,10000,itemStream,1); //I_IM_ID 181 | DataSource::addAlphanumeric64(14,24,itemStream,1); //I_NAME 182 | DataSource::addDouble(1.0,100.0,2,itemStream,1); //I_PRICE 183 | if(DataSource::randomTrue(0.1)) //I_DATA 184 | DataSource::addAlphanumeric64Original(26,50,itemStream,0); 185 | else 186 | DataSource::addAlphanumeric64(26,50,itemStream,0); 187 | itemStream << endl; 188 | } 189 | 190 | void TupleGen::genStock(int& iId, int& wId){ 191 | stockStream << iId << Config::getCsvDelim(); //S_I_ID 192 | stockStream << wId << Config::getCsvDelim(); //S_W_ID 193 | DataSource::addInt(10,100,stockStream,1); //S_QUANTITY 194 | DataSource::addAlphanumeric64(24,stockStream,1); //S_DIST_01 195 | DataSource::addAlphanumeric64(24,stockStream,1); //S_DIST_02 196 | DataSource::addAlphanumeric64(24,stockStream,1); //S_DIST_03 197 | DataSource::addAlphanumeric64(24,stockStream,1); //S_DIST_04 198 | DataSource::addAlphanumeric64(24,stockStream,1); //S_DIST_05 199 | DataSource::addAlphanumeric64(24,stockStream,1); //S_DIST_06 200 | DataSource::addAlphanumeric64(24,stockStream,1); //S_DIST_07 201 | DataSource::addAlphanumeric64(24,stockStream,1); //S_DIST_08 202 | DataSource::addAlphanumeric64(24,stockStream,1); //S_DIST_09 203 | DataSource::addAlphanumeric64(24,stockStream,1); //S_DIST_10 204 | stockStream << "0" << Config::getCsvDelim(); //S_YTD 205 | stockStream << "0" << Config::getCsvDelim(); //S_ORDER_CNT 206 | stockStream << "0" << Config::getCsvDelim(); //S_REMOTE_CNT 207 | if(DataSource::randomTrue(0.1)) //S_DATA 208 | DataSource::addAlphanumeric64Original(26,50,stockStream,1); 209 | else 210 | DataSource::addAlphanumeric64(26,50,stockStream,1); 211 | stockStream << ((iId*wId)%10000); //S_SU_SUPPKEY - no TPC-C/CH-benCHmark spec 212 | stockStream << endl; 213 | } 214 | 215 | void TupleGen::genNation(Nation n){ 216 | nationStream << n.id << Config::getCsvDelim(); //N_NATIONKEY 217 | nationStream << n.name << Config::getCsvDelim(); //N_NAME 218 | nationStream << n.rId << Config::getCsvDelim(); //N_REGIONKEY 219 | DataSource::addTextString(31,114,nationStream,0); //N_COMMENT 220 | nationStream << endl; 221 | } 222 | 223 | void TupleGen::genSupplier(int& suId){ 224 | supplierStream << suId << Config::getCsvDelim(); //SU_SUPPKEY 225 | supplierStream << "Supplier#" << DataSource::strLeadingZero(suId,9) << Config::getCsvDelim(); //SU_NAME 226 | DataSource::addAlphanumeric64(10,40,supplierStream,1); //SU_ADDRESS 227 | DataSource::addNId(supplierStream,1); //SU_NATIONKEY 228 | DataSource::addSuPhone(suId,supplierStream,1); //SU_PHONE 229 | DataSource::addDouble(-999.99,9999.99,2,supplierStream,1); //SU_ACCTBAL 230 | if((suId+7)%1893 == 0) //no spec //SU_COMMENT: 5 rows "Customer%Recommends" + 5 rows "Customer%Complaints" 231 | DataSource::addTextStringCustomer(25,100,"Complaints",supplierStream,0); 232 | else if((suId+13)%1983 == 0) //no spec 233 | DataSource::addTextStringCustomer(25,100,"Recommends",supplierStream,0); 234 | else 235 | DataSource::addTextString(25,100,supplierStream,0); 236 | supplierStream << endl; 237 | } 238 | 239 | void TupleGen::genRegion(int& rId, const char* rName){ 240 | regionStream << rId << Config::getCsvDelim(); //R_REGIONKEY 241 | regionStream << rName << Config::getCsvDelim(); //R_NAME 242 | DataSource::addTextString(31,115,regionStream,0); //R_COMMENT 243 | regionStream << endl; 244 | } 245 | -------------------------------------------------------------------------------- /src/TupleGen.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef TUPLEGEN_H 18 | #define TUPLEGEN_H 19 | 20 | #include "DataSource.h" 21 | 22 | #include 23 | #include 24 | 25 | class TupleGen{ 26 | 27 | private: 28 | static std::ofstream warehouseStream; 29 | static std::ofstream districtStream; 30 | static std::ofstream customerStream; 31 | static std::ofstream historyStream; 32 | static std::ofstream neworderStream; 33 | static std::ofstream orderStream; 34 | static std::ofstream orderlineStream; 35 | static std::ofstream itemStream; 36 | static std::ofstream stockStream; 37 | static std::ofstream nationStream; 38 | static std::ofstream supplierStream; 39 | static std::ofstream regionStream; 40 | 41 | public: 42 | static void openOutputFiles(); 43 | static void closeOutputFiles(); 44 | static void genWarehouse(int& wId); 45 | static void genDistrict(int& dId, int& wId); 46 | static void genCustomer(int& cId, int& dId, int& wId, std::string& customerTime); 47 | static void genHistory(int& cId, int& dId, int& wId); 48 | static void genNeworder(int& oId, int& dId, int& wId); 49 | static void genOrder(int& oId, int& dId, int& wId, int& cId, int& olCount, std::string& orderTime); 50 | static void genOrderline(int& oId, int& dId, int& wId, int& olNumber, std::string& orderTime); 51 | static void genItem(int& iId); 52 | static void genStock(int& iId, int& wId); 53 | static void genNation(Nation n); 54 | static void genSupplier(int& suId); 55 | static void genRegion(int& rId, const char* rName); 56 | 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/dialect/Dialect.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef DIALECTBASIS_H 18 | #define DIALECTBASIS_H 19 | 20 | #include 21 | 22 | class Dialect{ 23 | 24 | public: 25 | 26 | virtual ~Dialect(){}; 27 | 28 | //Strings to create initial database 29 | virtual std::vector& getDropExistingSchemaStatements() = 0; 30 | virtual std::vector& getCreateSchemaStatements() = 0; 31 | virtual std::vector& getImportPrefix() = 0; 32 | virtual std::vector& getImportSuffix() = 0; 33 | virtual std::vector& getAdditionalPreparationStatements() = 0; 34 | 35 | //22 adjusted TPC-H OLAP query strings 36 | virtual std::vector& getTpchQueryStrings() = 0; 37 | 38 | //Strings for database check 39 | virtual const char* getSelectCountWarehouse() = 0; 40 | virtual const char* getSelectCountDistrict() = 0; 41 | virtual const char* getSelectCountCustomer() = 0; 42 | virtual const char* getSelectCountOrder() = 0; 43 | virtual const char* getSelectCountOrderline() = 0; 44 | virtual const char* getSelectCountNeworder() = 0; 45 | virtual const char* getSelectCountHistory() = 0; 46 | virtual const char* getSelectCountStock() = 0; 47 | virtual const char* getSelectCountItem() = 0; 48 | virtual const char* getSelectCountSupplier() = 0; 49 | virtual const char* getSelectCountNation() = 0; 50 | virtual const char* getSelectCountRegion() = 0; 51 | 52 | //TPC-C transaction strings 53 | //NewOrder: 54 | virtual const char* getNoWarehouseSelect() = 0; 55 | virtual const char* getNoDistrictSelect() = 0; 56 | virtual const char* getNoDistrictUpdate() = 0; 57 | virtual const char* getNoCustomerSelect() = 0; 58 | virtual const char* getNoOrderInsert() = 0; 59 | virtual const char* getNoNewOrderInsert() = 0; 60 | virtual const char* getNoItemSelect() = 0; 61 | virtual const char* getNoStockSelect01() = 0; 62 | virtual const char* getNoStockSelect02() = 0; 63 | virtual const char* getNoStockSelect03() = 0; 64 | virtual const char* getNoStockSelect04() = 0; 65 | virtual const char* getNoStockSelect05() = 0; 66 | virtual const char* getNoStockSelect06() = 0; 67 | virtual const char* getNoStockSelect07() = 0; 68 | virtual const char* getNoStockSelect08() = 0; 69 | virtual const char* getNoStockSelect09() = 0; 70 | virtual const char* getNoStockSelect10() = 0; 71 | virtual const char* getNoStockUpdate01() = 0; 72 | virtual const char* getNoStockUpdate02() = 0; 73 | virtual const char* getNoOrderlineInsert() = 0; 74 | //Payment: 75 | virtual const char* getPmWarehouseSelect() = 0; 76 | virtual const char* getPmWarehouseUpdate() = 0; 77 | virtual const char* getPmDistrictSelect() = 0; 78 | virtual const char* getPmDistrictUpdate() = 0; 79 | virtual const char* getPmCustomerSelect1() = 0; 80 | virtual const char* getPmCustomerSelect2() = 0; 81 | virtual const char* getPmCustomerSelect3() = 0; 82 | virtual const char* getPmCustomerUpdate1() = 0; 83 | virtual const char* getPmCustomerSelect4() = 0; 84 | virtual const char* getPmCustomerUpdate2() = 0; 85 | virtual const char* getPmHistoryInsert() = 0; 86 | //OrderStatus: 87 | virtual const char* getOsCustomerSelect1() = 0; 88 | virtual const char* getOsCustomerSelect2() = 0; 89 | virtual const char* getOsCustomerSelect3() = 0; 90 | virtual const char* getOsOrderSelect() = 0; 91 | virtual const char* getOsOrderlineSelect() = 0; 92 | //Delivery: 93 | virtual const char* getDlNewOrderSelect() = 0; 94 | virtual const char* getDlNewOrderDelete() = 0; 95 | virtual const char* getDlOrderSelect() = 0; 96 | virtual const char* getDlOrderUpdate() = 0; 97 | virtual const char* getDlOrderlineUpdate() = 0; 98 | virtual const char* getDlOrderlineSelect() = 0; 99 | virtual const char* getDlCustomerUpdate() = 0; 100 | //StockLevel: 101 | virtual const char* getSlDistrictSelect() = 0; 102 | virtual const char* getSlStockSelect() = 0; 103 | 104 | }; 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /src/dialect/DialectStrategy.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "DialectStrategy.h" 18 | #include "MySqlDialect.h" 19 | #include "HanaDialect.h" 20 | 21 | Dialect* DialectStrategy::instance = 0; 22 | 23 | Dialect* DialectStrategy::getInstance(){ 24 | if(instance == 0) 25 | //instance = new HanaDialect(); 26 | instance = new MySqlDialect(); 27 | return instance; 28 | } 29 | -------------------------------------------------------------------------------- /src/dialect/DialectStrategy.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef DIALECT_H 18 | #define DIALECT_H 19 | 20 | #include "Dialect.h" 21 | 22 | class DialectStrategy{ 23 | 24 | private: 25 | static Dialect* instance; 26 | 27 | public: 28 | static Dialect* getInstance(); 29 | 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/dialect/HanaDialect.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Florian Wolf, SAP AG 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #ifndef HANADIALECT_H 18 | #define HANADIALECT_H 19 | 20 | #include "Dialect.h" 21 | 22 | class HanaDialect : public Dialect { 23 | 24 | private: 25 | std::vector dropExistingSchemaStatements = { 26 | "DROP SCHEMA \"TPCCH\" CASCADE" 27 | }; 28 | 29 | std::vector createSchemaStatements = { 30 | "CREATE SCHEMA \"TPCCH\"", 31 | 32 | "CREATE COLUMN TABLE \"TPCCH\".\"WAREHOUSE\" (\n" 33 | " \"W_ID\" INTEGER CS_INT,\n" 34 | " \"W_NAME\" CHAR(10) CS_FIXEDSTRING,\n" 35 | " \"W_STREET_1\" CHAR(20) CS_FIXEDSTRING,\n" 36 | " \"W_STREET_2\" CHAR(20) CS_FIXEDSTRING,\n" 37 | " \"W_CITY\" CHAR(20) CS_FIXEDSTRING,\n" 38 | " \"W_STATE\" CHAR(2) CS_FIXEDSTRING,\n" 39 | " \"W_ZIP\" CHAR(9) CS_FIXEDSTRING,\n" 40 | " \"W_TAX\" DECIMAL(4,4) CS_FIXED,\n" 41 | " \"W_YTD\" DECIMAL(12,2) CS_FIXED,\n" 42 | " PRIMARY KEY (\"W_ID\")\n" 43 | ") UNLOAD PRIORITY 5", 44 | 45 | "CREATE COLUMN TABLE \"TPCCH\".\"DISTRICT\" (\n" 46 | " \"D_ID\" TINYINT CS_INT,\n" 47 | " \"D_W_ID\" INTEGER CS_INT,\n" 48 | " \"D_NAME\" CHAR(10) CS_FIXEDSTRING,\n" 49 | " \"D_STREET_1\" CHAR(20) CS_FIXEDSTRING,\n" 50 | " \"D_STREET_2\" CHAR(20) CS_FIXEDSTRING,\n" 51 | " \"D_CITY\" CHAR(20) CS_FIXEDSTRING,\n" 52 | " \"D_STATE\" CHAR(2) CS_FIXEDSTRING,\n" 53 | " \"D_ZIP\" CHAR(9) CS_FIXEDSTRING,\n" 54 | " \"D_TAX\" DECIMAL(4,4) CS_FIXED,\n" 55 | " \"D_YTD\" DECIMAL(12,2) CS_FIXED,\n" 56 | " \"D_NEXT_O_ID\" INTEGER CS_INT,\n" 57 | " PRIMARY KEY (\"D_W_ID\",\"D_ID\") \n" 58 | ") UNLOAD PRIORITY 5", 59 | 60 | "CREATE INDEX \"FK_DISTRICT_WAREHOUSE\" ON " 61 | "\"TPCCH\".\"DISTRICT\" ( \"D_W_ID\" ASC ) NONLEAF PARTIAL KEY LENGTH 1", 62 | 63 | "CREATE COLUMN TABLE \"TPCCH\".\"CUSTOMER\" (\n" 64 | " \"C_ID\" SMALLINT CS_INT,\n" 65 | " \"C_D_ID\" TINYINT CS_INT,\n" 66 | " \"C_W_ID\" INTEGER CS_INT,\n" 67 | " \"C_FIRST\" CHAR(16) CS_FIXEDSTRING,\n" 68 | " \"C_MIDDLE\" CHAR(2) CS_FIXEDSTRING,\n" 69 | " \"C_LAST\" CHAR(16) CS_FIXEDSTRING,\n" 70 | " \"C_STREET_1\" CHAR(20) CS_FIXEDSTRING,\n" 71 | " \"C_STREET_2\" CHAR(20) CS_FIXEDSTRING,\n" 72 | " \"C_CITY\" CHAR(20) CS_FIXEDSTRING,\n" 73 | " \"C_STATE\" CHAR(2) CS_FIXEDSTRING,\n" 74 | " \"C_ZIP\" CHAR(9) CS_FIXEDSTRING,\n" 75 | " \"C_PHONE\" CHAR(16) CS_FIXEDSTRING,\n" 76 | " \"C_SINCE\" SECONDDATE CS_SECONDDATE,\n" 77 | " \"C_CREDIT\" CHAR(2) CS_FIXEDSTRING,\n" 78 | " \"C_CREDIT_LIM\" DECIMAL(12,2) CS_FIXED,\n" 79 | " \"C_DISCOUNT\" DECIMAL(4,4) CS_FIXED,\n" 80 | " \"C_BALANCE\" DECIMAL(12,2) CS_FIXED,\n" 81 | " \"C_YTD_PAYMENT\" DECIMAL(12,2) CS_FIXED,\n" 82 | " \"C_PAYMENT_CNT\" SMALLINT CS_INT,\n" 83 | " \"C_DELIVERY_CNT\" SMALLINT CS_INT,\n" 84 | " \"C_DATA\" CHAR(500) CS_FIXEDSTRING,\n" 85 | " \"C_N_NATIONKEY\" INTEGER CS_INT,\n" 86 | " PRIMARY KEY(\"C_W_ID\",\"C_D_ID\",\"C_ID\")\n" 87 | ") UNLOAD PRIORITY 5", 88 | 89 | "ALTER TABLE \"TPCCH\".\"CUSTOMER\" WITH PARAMETERS " 90 | "('CONCAT_ATTRIBUTE'=('$C_W_ID$C_D_ID$','C_W_ID','C_D_ID'))", 91 | 92 | "CREATE INDEX \"FK_CUSTOMER_DISTRICT\" ON \"TPCCH\".\"CUSTOMER\" " 93 | "( \"C_W_ID\" ASC,\"C_D_ID\" ASC ) NONLEAF PARTIAL KEY LENGTH 1", 94 | 95 | "CREATE COLUMN TABLE \"TPCCH\".\"HISTORY\" (\n" 96 | " \"H_C_ID\" SMALLINT CS_INT,\n" 97 | " \"H_C_D_ID\" TINYINT CS_INT,\n" 98 | " \"H_C_W_ID\" INTEGER CS_INT,\n" 99 | " \"H_D_ID\" TINYINT CS_INT,\n" 100 | " \"H_W_ID\" INTEGER CS_INT,\n" 101 | " \"H_DATE\" SECONDDATE CS_SECONDDATE,\n" 102 | " \"H_AMOUNT\" DECIMAL(6,2) CS_FIXED,\n" 103 | " \"H_DATA\" CHAR(24) CS_FIXEDSTRING\n" 104 | ") UNLOAD PRIORITY 5", 105 | 106 | "ALTER TABLE \"TPCCH\".\"HISTORY\" WITH PARAMETERS ('CONCAT_ATTRIBUTE'=" 107 | "('$H_C_W_ID$H_C_D_ID$H_C_ID$','H_C_W_ID','H_C_D_ID','H_C_ID'))", 108 | 109 | "ALTER TABLE \"TPCCH\".\"HISTORY\" WITH PARAMETERS ('CONCAT_ATTRIBUTE'=" 110 | "('$H_W_ID$H_D_ID$','H_W_ID','H_D_ID'))", 111 | 112 | "CREATE INDEX \"FK_HISTORY_CUSTOMER\" ON \"TPCCH\".\"HISTORY\" " 113 | "( \"H_C_W_ID\" ASC,\"H_C_D_ID\" ASC,\"H_C_ID\" ASC ) NONLEAF PARTIAL KEY LENGTH 1", 114 | 115 | "CREATE INDEX \"FK_HISTORY_DISTRICT\" ON \"TPCCH\".\"HISTORY\" " 116 | "( \"H_W_ID\" ASC,\"H_D_ID\" ASC ) NONLEAF PARTIAL KEY LENGTH 1", 117 | 118 | "CREATE COLUMN TABLE \"TPCCH\".\"NEWORDER\" (\n" 119 | " \"NO_O_ID\" INTEGER CS_INT,\n" 120 | " \"NO_D_ID\" TINYINT CS_INT,\n" 121 | " \"NO_W_ID\" INTEGER CS_INT,\n" 122 | " PRIMARY KEY (\"NO_W_ID\",\"NO_D_ID\",\"NO_O_ID\")\n" 123 | ") UNLOAD PRIORITY 5", 124 | 125 | "CREATE COLUMN TABLE \"TPCCH\".\"ORDER\" (\n" 126 | " \"O_ID\" INTEGER CS_INT,\n" 127 | " \"O_D_ID\" TINYINT CS_INT,\n" 128 | " \"O_W_ID\" INTEGER CS_INT,\n" 129 | " \"O_C_ID\" SMALLINT CS_INT,\n" 130 | " \"O_ENTRY_D\" SECONDDATE CS_SECONDDATE,\n" 131 | " \"O_CARRIER_ID\" TINYINT CS_INT,\n" 132 | " \"O_OL_CNT\" TINYINT CS_INT,\n" 133 | " \"O_ALL_LOCAL\" TINYINT CS_INT,\n" 134 | " PRIMARY KEY (\"O_W_ID\",\"O_D_ID\",\"O_ID\")\n" 135 | ") UNLOAD PRIORITY 5", 136 | 137 | "ALTER TABLE \"TPCCH\".\"ORDER\" WITH PARAMETERS " 138 | "('CONCAT_ATTRIBUTE'=('$O_W_ID$O_D_ID$O_C_ID$','O_W_ID','O_D_ID','O_C_ID'))", 139 | 140 | "CREATE INDEX \"FK_ORDER_CUSTOMER\" ON \"TPCCH\".\"ORDER\" " 141 | "( \"O_W_ID\" ASC,\"O_D_ID\" ASC,\"O_C_ID\" ASC ) NONLEAF PARTIAL KEY LENGTH 1", 142 | 143 | "CREATE COLUMN TABLE \"TPCCH\".\"ORDERLINE\" (\n" 144 | " \"OL_O_ID\" INTEGER CS_INT,\n" 145 | " \"OL_D_ID\" TINYINT CS_INT,\n" 146 | " \"OL_W_ID\" INTEGER CS_INT,\n" 147 | " \"OL_NUMBER\" TINYINT CS_INT,\n" 148 | " \"OL_I_ID\" INTEGER CS_INT,\n" 149 | " \"OL_SUPPLY_W_ID\" INTEGER CS_INT,\n" 150 | " \"OL_DELIVERY_D\" SECONDDATE CS_SECONDDATE,\n" 151 | " \"OL_QUANTITY\" SMALLINT CS_INT,\n" 152 | " \"OL_AMOUNT\" DECIMAL(6,2) CS_FIXED,\n" 153 | " \"OL_DIST_INFO\" CHAR(24) CS_FIXEDSTRING,\n" 154 | " PRIMARY KEY(\"OL_W_ID\",\"OL_D_ID\",\"OL_O_ID\",\"OL_NUMBER\")\n" 155 | ") UNLOAD PRIORITY 5", 156 | 157 | "ALTER TABLE \"TPCCH\".\"ORDERLINE\" WITH PARAMETERS " 158 | "('CONCAT_ATTRIBUTE'=('$OL_W_ID$OL_D_ID$OL_O_ID$','OL_W_ID','OL_D_ID','OL_O_ID'))", 159 | 160 | "ALTER TABLE \"TPCCH\".\"ORDERLINE\" WITH PARAMETERS " 161 | "('CONCAT_ATTRIBUTE'=('$OL_SUPPLY_W_ID$OL_I_ID$','OL_SUPPLY_W_ID','OL_I_ID'))", 162 | 163 | "CREATE INDEX \"FK_ORDERLINE_ORDER\" ON \"TPCCH\".\"ORDERLINE\" " 164 | "( \"OL_W_ID\" ASC,\"OL_D_ID\" ASC,\"OL_O_ID\" ASC ) NONLEAF PARTIAL KEY LENGTH 1", 165 | 166 | "CREATE INDEX \"FK_ORDERLINE_STOCK\" ON \"TPCCH\".\"ORDERLINE\" " 167 | "( \"OL_SUPPLY_W_ID\" ASC,\"OL_I_ID\" ASC ) NONLEAF PARTIAL KEY LENGTH 1", 168 | 169 | "CREATE COLUMN TABLE \"TPCCH\".\"ITEM\" (\n" 170 | " \"I_ID\" INTEGER CS_INT,\n" 171 | " \"I_IM_ID\" SMALLINT CS_INT,\n" 172 | " \"I_NAME\" CHAR(24) CS_FIXEDSTRING,\n" 173 | " \"I_PRICE\" DECIMAL(5,2) CS_FIXED,\n" 174 | " \"I_DATA\" CHAR(50) CS_FIXEDSTRING,\n" 175 | " PRIMARY KEY(\"I_ID\")\n" 176 | ") UNLOAD PRIORITY 5", 177 | 178 | "CREATE COLUMN TABLE \"TPCCH\".\"STOCK\" (\n" 179 | " \"S_I_ID\" INTEGER CS_INT,\n" 180 | " \"S_W_ID\" INTEGER CS_INT,\n" 181 | " \"S_QUANTITY\" SMALLINT CS_INT,\n" 182 | " \"S_DIST_01\" CHAR(24) CS_FIXEDSTRING,\n" 183 | " \"S_DIST_02\" CHAR(24) CS_FIXEDSTRING,\n" 184 | " \"S_DIST_03\" CHAR(24) CS_FIXEDSTRING,\n" 185 | " \"S_DIST_04\" CHAR(24) CS_FIXEDSTRING,\n" 186 | " \"S_DIST_05\" CHAR(24) CS_FIXEDSTRING,\n" 187 | " \"S_DIST_06\" CHAR(24) CS_FIXEDSTRING,\n" 188 | " \"S_DIST_07\" CHAR(24) CS_FIXEDSTRING,\n" 189 | " \"S_DIST_08\" CHAR(24) CS_FIXEDSTRING,\n" 190 | " \"S_DIST_09\" CHAR(24) CS_FIXEDSTRING,\n" 191 | " \"S_DIST_10\" CHAR(24) CS_FIXEDSTRING,\n" 192 | " \"S_YTD\" INTEGER CS_INT,\n" 193 | " \"S_ORDER_CNT\" SMALLINT CS_INT,\n" 194 | " \"S_REMOTE_CNT\" SMALLINT CS_INT,\n" 195 | " \"S_DATA\" CHAR(50) CS_FIXEDSTRING,\n" 196 | " \"S_SU_SUPPKEY\" INTEGER CS_INT,\n" 197 | " PRIMARY KEY (\"S_W_ID\",\"S_I_ID\")\n" 198 | ") UNLOAD PRIORITY 5", 199 | 200 | "CREATE INDEX \"FK_STOCK_WAREHOUSE\" ON \"TPCCH\".\"STOCK\" " 201 | "( \"S_W_ID\" ASC ) NONLEAF PARTIAL KEY LENGTH 1", 202 | 203 | "CREATE INDEX \"FK_STOCK_ITEM\" ON \"TPCCH\".\"STOCK\" " 204 | "( \"S_I_ID\" ASC ) NONLEAF PARTIAL KEY LENGTH 1", 205 | 206 | "CREATE COLUMN TABLE \"TPCCH\".\"NATION\" (\n" 207 | " \"N_NATIONKEY\" TINYINT CS_INT NOT NULL,\n" 208 | " \"N_NAME\" CHAR(25) CS_FIXEDSTRING NOT NULL,\n" 209 | " \"N_REGIONKEY\" TINYINT CS_INT NOT NULL,\n" 210 | " \"N_COMMENT\" CHAR(152) CS_FIXEDSTRING NOT NULL,\n" 211 | " PRIMARY KEY (\"N_NATIONKEY\")\n" 212 | ") UNLOAD PRIORITY 5", 213 | 214 | "CREATE COLUMN TABLE \"TPCCH\".\"SUPPLIER\" (\n" 215 | " \"SU_SUPPKEY\" SMALLINT CS_INT NOT NULL,\n" 216 | " \"SU_NAME\" CHAR(25) CS_FIXEDSTRING NOT NULL,\n" 217 | " \"SU_ADDRESS\" CHAR(40) CS_FIXEDSTRING NOT NULL,\n" 218 | " \"SU_NATIONKEY\"TINYINT CS_INT NOT NULL,\n" 219 | " \"SU_PHONE\" CHAR(15) CS_FIXEDSTRING NOT NULL,\n" 220 | " \"SU_ACCTBAL\" DECIMAL(12,2) CS_FIXED NOT NULL,\n" 221 | " \"SU_COMMENT\" CHAR(101) CS_FIXEDSTRING NOT NULL,\n" 222 | " PRIMARY KEY(\"SU_SUPPKEY\")\n" 223 | ") UNLOAD PRIORITY 5", 224 | 225 | "CREATE COLUMN TABLE \"TPCCH\".\"REGION\" (\n" 226 | " \"R_REGIONKEY\" TINYINT CS_INT NOT NULL,\n" 227 | " \"R_NAME\" CHAR(55) CS_FIXEDSTRING NOT NULL,\n" 228 | " \"R_COMMENT\" CHAR(152) CS_FIXEDSTRING NOT NULL,\n" 229 | " PRIMARY KEY (\"R_REGIONKEY\")\n" 230 | ") UNLOAD PRIORITY 5" 231 | }; 232 | 233 | std::vector additionalPreparationStatements = { 234 | "load TPCCH.\"WAREHOUSE\" all", 235 | "merge delta of TPCCH.\"WAREHOUSE\"", 236 | "load TPCCH.\"DISTRICT\" all", 237 | "merge delta of TPCCH.\"DISTRICT\"", 238 | "load TPCCH.\"CUSTOMER\" all", 239 | "merge delta of TPCCH.\"CUSTOMER\"", 240 | "load TPCCH.\"HISTORY\" all", 241 | "merge delta of TPCCH.\"HISTORY\"", 242 | "load TPCCH.\"NEWORDER\" all", 243 | "merge delta of TPCCH.\"NEWORDER\"", 244 | "load TPCCH.\"ORDER\" all", 245 | "merge delta of TPCCH.\"ORDER\"", 246 | "load TPCCH.\"ORDERLINE\" all", 247 | "merge delta of TPCCH.\"ORDERLINE\"", 248 | "load TPCCH.\"ITEM\" all", 249 | "merge delta of TPCCH.\"ITEM\"", 250 | "load TPCCH.\"STOCK\" all", 251 | "merge delta of TPCCH.\"STOCK\"", 252 | "load TPCCH.\"NATION\" all", 253 | "merge delta of TPCCH.\"NATION\"", 254 | "load TPCCH.\"SUPPLIER\" all", 255 | "merge delta of TPCCH.\"SUPPLIER\"", 256 | "load TPCCH.\"REGION\" all", 257 | "merge delta of TPCCH.\"REGION\"", 258 | }; 259 | 260 | std::vector importPrefixStrings ={ 261 | "IMPORT FROM CSV FILE '", 262 | "IMPORT FROM CSV FILE '", 263 | "IMPORT FROM CSV FILE '", 264 | "IMPORT FROM CSV FILE '", 265 | "IMPORT FROM CSV FILE '", 266 | "IMPORT FROM CSV FILE '", 267 | "IMPORT FROM CSV FILE '", 268 | "IMPORT FROM CSV FILE '", 269 | "IMPORT FROM CSV FILE '", 270 | "IMPORT FROM CSV FILE '", 271 | "IMPORT FROM CSV FILE '", 272 | "IMPORT FROM CSV FILE '" 273 | }; 274 | 275 | std::vector importSuffixStrings = { 276 | "/WAREHOUSE.tbl' INTO TPCCH.\"WAREHOUSE\" WITH RECORD DELIMITED BY '\n' FIELD DELIMITED BY '|' THREADS 10 TABLE LOCK", 277 | "/DISTRICT.tbl' INTO TPCCH.\"DISTRICT\" WITH RECORD DELIMITED BY '\n' FIELD DELIMITED BY '|' THREADS 10 TABLE LOCK", 278 | "/CUSTOMER.tbl' INTO TPCCH.\"CUSTOMER\" WITH RECORD DELIMITED BY '\n' FIELD DELIMITED BY '|' THREADS 10 TABLE LOCK", 279 | "/HISTORY.tbl' INTO TPCCH.\"HISTORY\" WITH RECORD DELIMITED BY '\n' FIELD DELIMITED BY '|' THREADS 10 TABLE LOCK", 280 | "/NEWORDER.tbl' INTO TPCCH.\"NEWORDER\" WITH RECORD DELIMITED BY '\n' FIELD DELIMITED BY '|' THREADS 10 TABLE LOCK", 281 | "/ORDER.tbl' INTO TPCCH.\"ORDER\" WITH RECORD DELIMITED BY '\n' FIELD DELIMITED BY '|' THREADS 10 TABLE LOCK", 282 | "/ORDERLINE.tbl' INTO TPCCH.\"ORDERLINE\" WITH RECORD DELIMITED BY '\n' FIELD DELIMITED BY '|' THREADS 10 TABLE LOCK", 283 | "/ITEM.tbl' INTO TPCCH.\"ITEM\" WITH RECORD DELIMITED BY '\n' FIELD DELIMITED BY '|' THREADS 10 TABLE LOCK", 284 | "/STOCK.tbl' INTO TPCCH.\"STOCK\" WITH RECORD DELIMITED BY '\n' FIELD DELIMITED BY '|' THREADS 10 TABLE LOCK", 285 | "/NATION.tbl' INTO TPCCH.\"NATION\" WITH RECORD DELIMITED BY '\n' FIELD DELIMITED BY '|' THREADS 10 TABLE LOCK", 286 | "/SUPPLIER.tbl' INTO TPCCH.\"SUPPLIER\" WITH RECORD DELIMITED BY '\n' FIELD DELIMITED BY '|' THREADS 10 TABLE LOCK", 287 | "/REGION.tbl' INTO TPCCH.\"REGION\" WITH RECORD DELIMITED BY '\n' FIELD DELIMITED BY '|' THREADS 10 TABLE LOCK" 288 | }; 289 | 290 | std::vector tpchQueryStrings = { 291 | //TPC-H-Query 1 292 | "select\n" 293 | " ol_number,\n" 294 | " sum(ol_quantity) as sum_qty,\n" 295 | " sum(ol_amount) as sum_amount,\n" 296 | " avg(ol_quantity) as avg_qty," 297 | " avg(ol_amount) as avg_amount,\n" 298 | " count(*) as count_order\n" 299 | "from\n" 300 | " TPCCH.ORDERLINE\n" 301 | "where\n" 302 | " ol_delivery_d > '2007-01-02 00:00:00.000000'\n" 303 | "group by\n" 304 | " ol_number\n" 305 | "order by\n" 306 | " ol_number", 307 | 308 | //TPC-H-Query 2 309 | "select\n" 310 | " su_suppkey, su_name, n_name, i_id, i_name, su_address, su_phone, su_comment\n" 311 | "from\n" 312 | " TPCCH.item, TPCCH.supplier, TPCCH.stock, TPCCH.nation, TPCCH.region,\n" 313 | " ( select\n" 314 | " s_i_id as m_i_id,\n" 315 | " min(s_quantity) as m_s_quantity\n" 316 | " from\n" 317 | " TPCCH.stock, TPCCH.supplier, TPCCH.nation, TPCCH.region\n" 318 | " where\n" 319 | " s_su_suppkey = su_suppkey\n" 320 | " and su_nationkey = n_nationkey\n" 321 | " and n_regionkey = r_regionkey\n" 322 | " and r_name like 'EUROP%'\n" 323 | " group by\n" 324 | " s_i_id\n" 325 | " ) m\n" 326 | "where\n" 327 | " i_id = s_i_id\n" 328 | " and s_su_suppkey = su_suppkey\n" 329 | " and su_nationkey = n_nationkey\n" 330 | " and n_regionkey = r_regionkey\n" 331 | " and i_data like '%b'\n" 332 | " and r_name like 'EUROP%'\n" 333 | " and i_id = m_i_id\n" 334 | " and s_quantity = m_s_quantity\n" 335 | "order by\n" 336 | " n_name, su_name, i_id", 337 | 338 | //TPC-H-Query 3 339 | "select\n" 340 | " ol_o_id, ol_w_id, ol_d_id,\n" 341 | " sum(ol_amount) as revenue, o_entry_d\n" 342 | "from\n" 343 | " TPCCH.customer, TPCCH.neworder, TPCCH.\"ORDER\", TPCCH.orderline\n" 344 | "where\n" 345 | " c_state like 'A%'\n" 346 | " and c_id = o_c_id\n" 347 | " and c_w_id = o_w_id\n" 348 | " and c_d_id = o_d_id\n" 349 | " and no_w_id = o_w_id\n" 350 | " and no_d_id = o_d_id\n" 351 | " and no_o_id = o_id\n" 352 | " and ol_w_id = o_w_id\n" 353 | " and ol_d_id = o_d_id\n" 354 | " and ol_o_id = o_id\n" 355 | " and o_entry_d > '2007-01-02 00:00:00.000000'\n" 356 | "group by\n" 357 | " ol_o_id, ol_w_id, ol_d_id, o_entry_d\n" 358 | "order by\n" 359 | " revenue desc, o_entry_d", 360 | 361 | //TPC-H-Query 4 362 | "select\n" 363 | " o_ol_cnt, count(*) as order_count\n" 364 | "from\n" 365 | " TPCCH.\"ORDER\"\n" 366 | "where\n" 367 | " o_entry_d >= '2007-01-02 00:00:00.000000'\n" 368 | " and o_entry_d < '2012-01-02 00:00:00.000000'\n" 369 | " and exists \n" 370 | " ( select *\n" 371 | " from TPCCH.orderline\n" 372 | " where o_id = ol_o_id\n" 373 | " and o_w_id = ol_w_id\n" 374 | " and o_d_id = ol_d_id\n" 375 | " and ol_delivery_d >= o_entry_d)\n" 376 | "group by\n" 377 | " o_ol_cnt\n" 378 | "order by\n" 379 | " o_ol_cnt", 380 | 381 | //TPC-H-Query 5 382 | "select\n" 383 | " n_name,\n" 384 | " sum(ol_amount) as revenue\n" 385 | "from\n" 386 | " TPCCH.customer, TPCCH.\"ORDER\", TPCCH.orderline, TPCCH.stock, TPCCH.supplier, TPCCH.nation, TPCCH.region\n" 387 | "where\n" 388 | " c_id = o_c_id\n" 389 | " and c_w_id = o_w_id\n" 390 | " and c_d_id = o_d_id\n" 391 | " and ol_o_id = o_id\n" 392 | " and ol_w_id = o_w_id\n" 393 | " and ol_d_id=o_d_id\n" 394 | " and ol_w_id = s_w_id\n" 395 | " and ol_i_id = s_i_id\n" 396 | " and s_su_suppkey = su_suppkey\n" 397 | " and c_n_nationkey = su_nationkey\n" 398 | " and su_nationkey = n_nationkey\n" 399 | " and n_regionkey = r_regionkey\n" 400 | " and r_name = 'EUROPE'\n" 401 | " and o_entry_d >= '2007-01-02 00:00:00.000000'\n" 402 | "group by\n" 403 | " n_name\n" 404 | "order by\n" 405 | " revenue desc", 406 | 407 | //TPC-H-Query 6 408 | "select\n" 409 | " sum(ol_amount) as revenue\n" 410 | "from\n" 411 | " TPCCH.orderline\n" 412 | "where\n" 413 | " ol_delivery_d >= '1999-01-01 00:00:00.000000'\n" 414 | " and ol_delivery_d < '2020-01-01 00:00:00.000000'\n" 415 | " and ol_quantity between 1 and 100000", 416 | 417 | //TPC-H-Query 7 418 | "select\n" 419 | " su_nationkey as supp_nation,\n" 420 | " substr(c_state,1,1) as cust_nation,\n" 421 | " extract(year from o_entry_d) as l_year,\n" 422 | " sum(ol_amount) as revenue\n" 423 | "from\n" 424 | " TPCCH.supplier, TPCCH.stock, TPCCH.orderline, TPCCH.\"ORDER\", TPCCH.customer, TPCCH.nation n1, TPCCH.nation n2\n" 425 | "where\n" 426 | " ol_supply_w_id = s_w_id\n" 427 | " and ol_i_id = s_i_id\n" 428 | " and s_su_suppkey = su_suppkey\n" 429 | " and ol_w_id = o_w_id\n" 430 | " and ol_d_id = o_d_id\n" 431 | " and ol_o_id = o_id\n" 432 | " and c_id = o_c_id\n" 433 | " and c_w_id = o_w_id\n" 434 | " and c_d_id = o_d_id\n" 435 | " and su_nationkey = n1.n_nationkey\n" 436 | " and c_n_nationkey = n2.n_nationkey\n" 437 | " and (\n" 438 | " (n1.n_name = 'GERMANY' and n2.n_name = 'CAMBODIA')\n" 439 | " or\n" 440 | " (n1.n_name = 'CAMBODIA' and n2.n_name = 'GERMANY')\n" 441 | " )\n" 442 | " and ol_delivery_d between '2007-01-02 00:00:00.000000' and '2012-01-02 00:00:00.000000'\n" 443 | "group by\n" 444 | " su_nationkey, substr(c_state,1,1), extract(year from o_entry_d)\n" 445 | "order by\n" 446 | " su_nationkey, cust_nation, l_year", 447 | 448 | //TPC-H-Query 8 449 | "select\n" 450 | " extract(year from o_entry_d) as l_year,\n" 451 | " sum(case when n2.n_name = 'GERMANY' then ol_amount else 0 end) / sum(ol_amount) as mkt_share\n" 452 | "from\n" 453 | " TPCCH.item, TPCCH.supplier, TPCCH.stock, TPCCH.orderline, TPCCH.\"ORDER\", TPCCH.customer, TPCCH.nation n1, TPCCH.nation n2, TPCCH.region\n" 454 | "where\n" 455 | " i_id = s_i_id\n" 456 | " and ol_i_id = s_i_id\n" 457 | " and ol_supply_w_id = s_w_id\n" 458 | " and s_su_suppkey = su_suppkey\n" 459 | " and ol_w_id = o_w_id\n" 460 | " and ol_d_id = o_d_id\n" 461 | " and ol_o_id = o_id\n" 462 | " and c_id = o_c_id\n" 463 | " and c_w_id = o_w_id\n" 464 | " and c_d_id = o_d_id\n" 465 | " and n1.n_nationkey = c_n_nationkey\n" 466 | " and n1.n_regionkey = r_regionkey\n" 467 | " and ol_i_id < 1000\n" 468 | " and r_name = 'EUROPE'\n" 469 | " and su_nationkey = n2.n_nationkey\n" 470 | " and o_entry_d between '2007-01-02 00:00:00.000000' and '2012-01-02 00:00:00.000000'\n" 471 | " and i_data like '%b'\n" 472 | " and i_id = ol_i_id\n" 473 | "group by\n" 474 | " extract(year from o_entry_d)\n" 475 | "order by\n" 476 | " l_year", 477 | 478 | //TPC-H-Query 9 479 | "select\n" 480 | " n_name, extract(year from o_entry_d) as l_year, sum(ol_amount) as sum_profit\n" 481 | "from\n" 482 | " TPCCH.item, TPCCH.stock, TPCCH.supplier, TPCCH.orderline, TPCCH.\"ORDER\", TPCCH.nation\n" 483 | "where\n" 484 | " ol_i_id = s_i_id\n" 485 | " and ol_supply_w_id = s_w_id\n" 486 | " and s_su_suppkey = su_suppkey\n" 487 | " and ol_w_id = o_w_id\n" 488 | " and ol_d_id = o_d_id\n" 489 | " and ol_o_id = o_id\n" 490 | " and ol_i_id = i_id\n" 491 | " and su_nationkey = n_nationkey\n" 492 | " and i_data like '%BB'\n" 493 | "group by\n" 494 | " n_name, extract(year from o_entry_d)\n" 495 | "order by\n" 496 | " n_name, l_year desc", 497 | 498 | //TPC-H-Query 10 499 | "select\n" 500 | " c_id, c_last, sum(ol_amount) as revenue, c_city, c_phone, n_name\n" 501 | "from\n" 502 | " TPCCH.customer, TPCCH.\"ORDER\", TPCCH.orderline, TPCCH.nation\n" 503 | "where\n" 504 | " c_id = o_c_id\n" 505 | " and c_w_id = o_w_id\n" 506 | " and c_d_id = o_d_id\n" 507 | " and ol_w_id = o_w_id\n" 508 | " and ol_d_id = o_d_id\n" 509 | " and ol_o_id = o_id\n" 510 | " and o_entry_d >= '2007-01-02 00:00:00.000000'\n" 511 | " and o_entry_d <= ol_delivery_d\n" 512 | " and n_nationkey = c_n_nationkey\n" 513 | "group by\n" 514 | " c_id, c_last, c_city, c_phone, n_name\n" 515 | "order by\n" 516 | " revenue desc", 517 | 518 | //TPC-H-Query 11 519 | "select\n" 520 | " s_i_id, sum(s_order_cnt) as ordercount\n" 521 | "from\n" 522 | " TPCCH.stock, TPCCH.supplier, TPCCH.nation\n" 523 | "where\n" 524 | " s_su_suppkey = su_suppkey\n" 525 | " and su_nationkey = n_nationkey\n" 526 | " and n_name = 'GERMANY'\n" 527 | "group by\n" 528 | " s_i_id\n" 529 | "having \n" 530 | " sum(s_order_cnt) > (\n" 531 | " select\n" 532 | " sum(s_order_cnt) * .005\n" 533 | " from\n" 534 | " TPCCH.stock, TPCCH.supplier, TPCCH.nation\n" 535 | " where\n" 536 | " s_su_suppkey = su_suppkey\n" 537 | " and su_nationkey = n_nationkey\n" 538 | " and n_name = 'GERMANY')\n" 539 | "order by\n" 540 | " ordercount desc", 541 | 542 | //TPC-H-Query 12 543 | "select\n" 544 | " o_ol_cnt,\n" 545 | " sum(case when o_carrier_id = 1 or o_carrier_id = 2 then 1 else 0 end) as high_line_count,\n" 546 | " sum(case when o_carrier_id <> 1 and o_carrier_id <> 2 then 1 else 0 end) as low_line_count\n" 547 | "from\n" 548 | " TPCCH.\"ORDER\", TPCCH.orderline\n" 549 | "where\n" 550 | " ol_w_id = o_w_id\n" 551 | " and ol_d_id = o_d_id\n" 552 | " and ol_o_id = o_id\n" 553 | " and o_entry_d <= ol_delivery_d\n" 554 | " and ol_delivery_d < '2020-01-01 00:00:00.000000'\n" 555 | "group by\n" 556 | " o_ol_cnt\n" 557 | "order by\n" 558 | " o_ol_cnt", 559 | 560 | //TPC-H-Query 13 561 | "select\n" 562 | " c_count, count(*) as custdist\n" 563 | "from\n" 564 | " ( select\n" 565 | " c_id, count(o_id) as c_count\n" 566 | " from\n" 567 | " TPCCH.customer left outer join TPCCH.\"ORDER\" on (\n" 568 | " c_w_id = o_w_id\n" 569 | " and c_d_id = o_d_id\n" 570 | " and c_id = o_c_id\n" 571 | " and o_carrier_id > 8)\n" 572 | " group by\n" 573 | " c_id\n" 574 | " ) as c_orders\n" 575 | "group by\n" 576 | " c_count\n" 577 | "order by\n" 578 | " custdist desc, c_count desc", 579 | 580 | //TPC-H-Query 14 581 | "select\n" 582 | " 100.00 * sum(case when i_data like 'PR%' then ol_amount else 0 end) / (1+sum(ol_amount)) as promo_revenue\n" 583 | "from\n" 584 | " TPCCH.orderline, TPCCH.item\n" 585 | "where\n" 586 | " ol_i_id = i_id\n" 587 | " and ol_delivery_d >= '2007-01-02 00:00:00.000000'\n" 588 | " and ol_delivery_d < '2020-01-02 00:00:00.000000'", 589 | 590 | //TPC-H-Query 15 591 | "select\n" 592 | " su_suppkey, su_name, su_address, su_phone, total_revenue\n" 593 | "from\n" 594 | " TPCCH.supplier,\n" 595 | " (select\n" 596 | " s_su_suppkey as supplier_no,\n" 597 | " sum(ol_amount) as total_revenue\n" 598 | " from\n" 599 | " TPCCH.orderline, TPCCH.stock\n" 600 | " where\n" 601 | " ol_i_id = s_i_id\n" 602 | " and ol_supply_w_id = s_w_id\n" 603 | " and ol_delivery_d >= '2007-01-02 00:00:00.000000'\n" 604 | " group by\n" 605 | " s_su_suppkey\n" 606 | " ) as revenue\n" 607 | "where\n" 608 | " su_suppkey = supplier_no\n" 609 | " and total_revenue = (\n" 610 | " select max(total_revenue)\n" 611 | " from\n" 612 | " (select\n" 613 | " s_su_suppkey as supplier_no,\n" 614 | " sum(ol_amount) as total_revenue\n" 615 | " from\n" 616 | " TPCCH.orderline, TPCCH.stock\n" 617 | " where\n" 618 | " ol_i_id = s_i_id\n" 619 | " and ol_supply_w_id = s_w_id\n" 620 | " and ol_delivery_d >= '2007-01-02 00:00:00.000000'\n" 621 | " group by\n" 622 | " s_su_suppkey\n" 623 | " ) as revenue\n" 624 | " )\n" 625 | "order by\n" 626 | " su_suppkey", 627 | 628 | //TPC-H-Query 16 629 | "select\n" 630 | " i_name,\n" 631 | " substr(i_data, 1, 3) as brand,\n" 632 | " i_price,\n" 633 | " count(distinct s_su_suppkey) as supplier_cnt\n" 634 | "from\n" 635 | " TPCCH.stock, TPCCH.item\n" 636 | "where\n" 637 | " i_id = s_i_id\n" 638 | " and i_data not like 'zz%'\n" 639 | " and (s_su_suppkey not in\n" 640 | " ( select\n" 641 | " su_suppkey\n" 642 | " from\n" 643 | " TPCCH.supplier\n" 644 | " where\n" 645 | " su_comment like '%bad%')\n" 646 | " )\n" 647 | "group by\n" 648 | " i_name, substr(i_data, 1, 3), i_price\n" 649 | "order by\n" 650 | " supplier_cnt desc", 651 | 652 | //TPC-H-Query 17 653 | "select\n" 654 | " sum(ol_amount) / 2.0 as avg_yearly\n" 655 | "from\n" 656 | " TPCCH.orderline,\n" 657 | " ( select\n" 658 | " i_id, avg(ol_quantity) as a\n" 659 | " from\n" 660 | " TPCCH.item, TPCCH.orderline\n" 661 | " where\n" 662 | " i_data like '%b'\n" 663 | " and ol_i_id = i_id\n" 664 | " group by\n" 665 | " i_id\n" 666 | " ) t\n" 667 | "where\n" 668 | " ol_i_id = t.i_id\n" 669 | " and ol_quantity < t.a", 670 | 671 | //TPC-H-Query 18 672 | "select\n" 673 | " c_last, c_id, o_id, o_entry_d, o_ol_cnt, sum(ol_amount)\n" 674 | "from\n" 675 | " TPCCH.customer, TPCCH.\"ORDER\", TPCCH.orderline\n" 676 | "where\n" 677 | " c_id = o_c_id\n" 678 | " and c_w_id = o_w_id\n" 679 | " and c_d_id = o_d_id\n" 680 | " and ol_w_id = o_w_id\n" 681 | " and ol_d_id = o_d_id\n" 682 | " and ol_o_id = o_id\n" 683 | "group by\n" 684 | " o_id, o_w_id, o_d_id, c_id, c_last, o_entry_d, o_ol_cnt\n" 685 | "having\n" 686 | " sum(ol_amount) > 200\n" 687 | "order by\n" 688 | " sum(ol_amount) desc, o_entry_d", 689 | 690 | //TPC-H-Query 19 691 | "select\n" 692 | " sum(ol_amount) as revenue\n" 693 | "from\n" 694 | " TPCCH.orderline, TPCCH.item\n" 695 | "where\n" 696 | " (\n" 697 | " ol_i_id = i_id\n" 698 | " and i_data like '%a'\n" 699 | " and ol_quantity >= 1\n" 700 | " and ol_quantity <= 10\n" 701 | " and i_price between 1 and 400000\n" 702 | " and ol_w_id in (1,2,3)\n" 703 | " ) or (\n" 704 | " ol_i_id = i_id\n" 705 | " and i_data like '%b'\n" 706 | " and ol_quantity >= 1\n" 707 | " and ol_quantity <= 10\n" 708 | " and i_price between 1 and 400000\n" 709 | " and ol_w_id in (1,2,4)\n" 710 | " ) or (\n" 711 | " ol_i_id = i_id\n" 712 | " and i_data like '%c'\n" 713 | " and ol_quantity >= 1\n" 714 | " and ol_quantity <= 10\n" 715 | " and i_price between 1 and 400000\n" 716 | " and ol_w_id in (1,5,3)\n" 717 | " )", 718 | 719 | //TPC-H-Query 20 720 | "select su_name, su_address\n" 721 | "from TPCCH.supplier, TPCCH.nation\n" 722 | "where su_suppkey in\n" 723 | " (select mod(s_i_id * s_w_id, 10000)\n" 724 | " from TPCCH.stock, TPCCH.orderline\n" 725 | " where s_i_id in\n" 726 | " (select i_id\n" 727 | " from TPCCH.item\n" 728 | " where i_data like 'co%')\n" 729 | " and ol_i_id=s_i_id\n" 730 | " and ol_delivery_d > '2010-05-23 12:00:00'\n" 731 | " group by s_i_id, s_w_id, s_quantity\n" 732 | " having 2*s_quantity > sum(ol_quantity))\n" 733 | " and su_nationkey = n_nationkey\n" 734 | " and n_name = 'GERMANY'\n" 735 | "order by su_name", 736 | 737 | //TPC-H-Query 21 738 | "select\n" 739 | " su_name, count(*) as numwait\n" 740 | "from\n" 741 | " TPCCH.supplier, TPCCH.orderline l1, TPCCH.\"ORDER\", TPCCH.stock, TPCCH.nation\n" 742 | "where\n" 743 | " ol_o_id = o_id\n" 744 | " and ol_w_id = o_w_id\n" 745 | " and ol_d_id = o_d_id\n" 746 | " and ol_w_id = s_w_id\n" 747 | " and ol_i_id = s_i_id\n" 748 | " and s_su_suppkey = su_suppkey\n" 749 | " and l1.ol_delivery_d > o_entry_d\n" 750 | " and not exists (\n" 751 | " select *\n" 752 | " from\n" 753 | " TPCCH.orderline l2\n" 754 | " where\n" 755 | " l2.ol_o_id = l1.ol_o_id\n" 756 | " and l2.ol_w_id = l1.ol_w_id\n" 757 | " and l2.ol_d_id = l1.ol_d_id\n" 758 | " and l2.ol_delivery_d > l1.ol_delivery_d\n" 759 | " )\n" 760 | " and su_nationkey = n_nationkey\n" 761 | " and n_name = 'GERMANY'\n" 762 | "group by\n" 763 | " su_name\n" 764 | "order by\n" 765 | " numwait desc, su_name", 766 | 767 | //TPC-H-Query 22 768 | "select\n" 769 | " substr(c_state,1,1) as country,\n" 770 | " count(*) as numcust,\n" 771 | " sum(c_balance) as totacctbal\n" 772 | "from\n" 773 | " TPCCH.customer\n" 774 | "where\n" 775 | " substr(c_phone,1,1) in ('1','2','3','4','5','6','7')\n" 776 | " and c_balance > (\n" 777 | " select\n" 778 | " avg(c_BALANCE)\n" 779 | " from\n" 780 | " TPCCH.customer\n" 781 | " where\n" 782 | " c_balance > 0.00\n" 783 | " and substr(c_phone,1,1) in ('1','2','3','4','5','6','7')\n" 784 | " )\n" 785 | " and not exists (\n" 786 | " select *\n" 787 | " from\n" 788 | " TPCCH.\"ORDER\"\n" 789 | " where\n" 790 | " o_c_id = c_id\n" 791 | " and o_w_id = c_w_id\n" 792 | " and o_d_id = c_d_id\n" 793 | " )\n" 794 | "group by\n" 795 | " substr(c_state,1,1)\n" 796 | "order by\n" 797 | " substr(c_state,1,1)" 798 | }; 799 | 800 | public: 801 | 802 | //Strings to create initial database 803 | virtual std::vector& getDropExistingSchemaStatements(){ 804 | return dropExistingSchemaStatements; 805 | } 806 | 807 | virtual std::vector& getCreateSchemaStatements(){ 808 | return createSchemaStatements; 809 | } 810 | 811 | virtual std::vector& getImportPrefix(){ 812 | return importPrefixStrings; 813 | } 814 | 815 | virtual std::vector& getImportSuffix(){ 816 | return importSuffixStrings; 817 | } 818 | 819 | 820 | virtual std::vector& getAdditionalPreparationStatements(){ 821 | return additionalPreparationStatements; 822 | } 823 | 824 | //22 adjusted TPC-H OLAP query strings 825 | virtual std::vector& getTpchQueryStrings(){ 826 | return tpchQueryStrings; 827 | } 828 | 829 | //Strings for database check 830 | virtual const char* getSelectCountWarehouse(){ 831 | return "select count(*) from TPCCH.WAREHOUSE"; 832 | } 833 | 834 | virtual const char* getSelectCountDistrict(){ 835 | return "select count(*) from TPCCH.DISTRICT"; 836 | } 837 | 838 | virtual const char* getSelectCountCustomer(){ 839 | return "select count(*) from TPCCH.CUSTOMER"; 840 | } 841 | 842 | virtual const char* getSelectCountOrder(){ 843 | return "select count(*) from TPCCH.\"ORDER\""; 844 | } 845 | 846 | virtual const char* getSelectCountOrderline(){ 847 | return "select count(*) from TPCCH.ORDERLINE"; 848 | } 849 | 850 | virtual const char* getSelectCountNeworder(){ 851 | return "select count(*) from TPCCH.NEWORDER"; 852 | } 853 | 854 | virtual const char* getSelectCountHistory(){ 855 | return "select count(*) from TPCCH.HISTORY"; 856 | } 857 | 858 | virtual const char* getSelectCountStock(){ 859 | return "select count(*) from TPCCH.STOCK"; 860 | } 861 | 862 | virtual const char* getSelectCountItem(){ 863 | return "select count(*) from TPCCH.ITEM"; 864 | } 865 | 866 | virtual const char* getSelectCountSupplier(){ 867 | return "select count(*) from TPCCH.SUPPLIER"; 868 | } 869 | 870 | virtual const char* getSelectCountNation(){ 871 | return "select count(*) from TPCCH.NATION"; 872 | } 873 | 874 | virtual const char* getSelectCountRegion(){ 875 | return "select count(*) from TPCCH.REGION"; 876 | } 877 | 878 | //TPC-C transaction strings 879 | //NewOrder: 880 | virtual const char* getNoWarehouseSelect(){ 881 | return "select W_TAX from TPCCH.WAREHOUSE where W_ID=?"; 882 | } 883 | 884 | virtual const char* getNoDistrictSelect(){ 885 | return "select D_TAX, D_NEXT_O_ID from TPCCH.DISTRICT where D_W_ID=? and D_ID=?"; 886 | } 887 | 888 | virtual const char* getNoDistrictUpdate(){ 889 | return "update TPCCH.DISTRICT set D_NEXT_O_ID=D_NEXT_O_ID+1 where D_W_ID=? and D_ID=?"; 890 | } 891 | 892 | virtual const char* getNoCustomerSelect(){ 893 | return "select C_DISCOUNT,C_LAST,C_CREDIT from TPCCH.CUSTOMER where C_W_ID=? and C_D_ID=? and C_ID=?"; 894 | } 895 | 896 | virtual const char* getNoOrderInsert(){ 897 | return "insert into TPCCH.\"ORDER\" values (?,?,?,?,?,NULL,?,?)"; 898 | } 899 | 900 | virtual const char* getNoNewOrderInsert(){ 901 | return "insert into TPCCH.NEWORDER values(?,?,?)"; 902 | } 903 | 904 | virtual const char* getNoItemSelect(){ 905 | return "select I_PRICE,I_NAME,I_DATA from TPCCH.ITEM where I_ID=?"; 906 | } 907 | 908 | virtual const char* getNoStockSelect01(){ 909 | return "select S_QUANTITY,S_DIST_01,S_DATA from TPCCH.STOCK where S_I_ID=? and S_W_ID=?"; 910 | } 911 | 912 | virtual const char* getNoStockSelect02(){ 913 | return "select S_QUANTITY,S_DIST_02,S_DATA from TPCCH.STOCK where S_I_ID=? and S_W_ID=?"; 914 | } 915 | 916 | virtual const char* getNoStockSelect03(){ 917 | return "select S_QUANTITY,S_DIST_03,S_DATA from TPCCH.STOCK where S_I_ID=? and S_W_ID=?"; 918 | } 919 | 920 | virtual const char* getNoStockSelect04(){ 921 | return "select S_QUANTITY,S_DIST_04,S_DATA from TPCCH.STOCK where S_I_ID=? and S_W_ID=?"; 922 | } 923 | 924 | virtual const char* getNoStockSelect05(){ 925 | return "select S_QUANTITY,S_DIST_05,S_DATA from TPCCH.STOCK where S_I_ID=? and S_W_ID=?"; 926 | } 927 | 928 | virtual const char* getNoStockSelect06(){ 929 | return "select S_QUANTITY,S_DIST_06,S_DATA from TPCCH.STOCK where S_I_ID=? and S_W_ID=?"; 930 | } 931 | 932 | virtual const char* getNoStockSelect07(){ 933 | return "select S_QUANTITY,S_DIST_07,S_DATA from TPCCH.STOCK where S_I_ID=? and S_W_ID=?"; 934 | } 935 | 936 | virtual const char* getNoStockSelect08(){ 937 | return "select S_QUANTITY,S_DIST_08,S_DATA from TPCCH.STOCK where S_I_ID=? and S_W_ID=?"; 938 | } 939 | 940 | virtual const char* getNoStockSelect09(){ 941 | return "select S_QUANTITY,S_DIST_09,S_DATA from TPCCH.STOCK where S_I_ID=? and S_W_ID=?"; 942 | } 943 | 944 | virtual const char* getNoStockSelect10(){ 945 | return "select S_QUANTITY,S_DIST_10,S_DATA from TPCCH.STOCK where S_I_ID=? and S_W_ID=?"; 946 | } 947 | 948 | virtual const char* getNoStockUpdate01(){ 949 | return "update TPCCH.STOCK set S_YTD=S_YTD+?, S_ORDER_CNT=S_ORDER_CNT+1, S_QUANTITY=? where S_I_ID=? and S_W_ID=?"; 950 | } 951 | 952 | virtual const char* getNoStockUpdate02(){ 953 | return "update TPCCH.STOCK set S_YTD=S_YTD+?, S_ORDER_CNT=S_ORDER_CNT+1, S_QUANTITY=?, S_REMOTE_CNT=S_REMOTE_CNT+1 where S_I_ID=? and S_W_ID=?"; 954 | } 955 | 956 | virtual const char* getNoOrderlineInsert(){ 957 | return "insert into TPCCH.ORDERLINE values (?,?,?,?,?,?,NULL,?,?,?)"; 958 | } 959 | 960 | //Payment: 961 | virtual const char* getPmWarehouseSelect(){ 962 | return "select W_NAME, W_STREET_1, W_STREET_2, W_CITY, W_STATE, W_ZIP from TPCCH.WAREHOUSE where W_ID=?"; 963 | } 964 | 965 | virtual const char* getPmWarehouseUpdate(){ 966 | return "update TPCCH.WAREHOUSE set W_YTD=W_YTD+? where W_ID=?"; 967 | } 968 | 969 | virtual const char* getPmDistrictSelect(){ 970 | return "select D_NAME, D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP from TPCCH.DISTRICT where D_W_ID=? and D_ID=?"; 971 | } 972 | 973 | virtual const char* getPmDistrictUpdate(){ 974 | return "update TPCCH.DISTRICT set D_YTD=D_YTD+? where D_W_ID=? and D_ID=?"; 975 | } 976 | 977 | virtual const char* getPmCustomerSelect1(){ 978 | return "select count(*) from TPCCH.CUSTOMER where C_LAST=? and C_D_ID=? and C_W_ID=?"; 979 | } 980 | 981 | virtual const char* getPmCustomerSelect2(){ 982 | return "select C_ID, C_FIRST, C_MIDDLE, C_STREET_1, C_STREET_2, C_CITY, C_STATE, C_ZIP, C_PHONE, C_SINCE, C_CREDIT, C_CREDIT_LIM, C_DISCOUNT, C_BALANCE from TPCCH.CUSTOMER where C_LAST=? and C_D_ID=? and C_W_ID=? order by C_FIRST asc"; 983 | } 984 | 985 | virtual const char* getPmCustomerSelect3(){ 986 | return "select C_FIRST, C_MIDDLE, C_LAST, C_STREET_1, C_STREET_2, C_CITY, C_STATE, C_ZIP, C_PHONE, C_SINCE, C_CREDIT, C_CREDIT_LIM, C_DISCOUNT, C_BALANCE from TPCCH.CUSTOMER where C_ID=? and C_D_ID=? and C_W_ID=?"; 987 | } 988 | 989 | virtual const char* getPmCustomerUpdate1(){ 990 | return "update TPCCH.CUSTOMER set C_BALANCE=C_BALANCE-?, C_YTD_PAYMENT=C_YTD_PAYMENT+?, C_PAYMENT_CNT=C_PAYMENT_CNT+1 where C_ID=? and C_D_ID=? and C_W_ID=?"; 991 | } 992 | 993 | virtual const char* getPmCustomerSelect4(){ 994 | return "select C_DATA from TPCCH.CUSTOMER where C_ID=? and C_D_ID=? and C_W_ID=?"; 995 | } 996 | 997 | virtual const char* getPmCustomerUpdate2(){ 998 | return "update TPCCH.CUSTOMER set C_DATA=? where C_ID=? and C_D_ID=? and C_W_ID=?"; 999 | } 1000 | 1001 | virtual const char* getPmHistoryInsert(){ 1002 | return "insert into TPCCH.History values (?,?,?,?,?,?,?,?)"; 1003 | } 1004 | 1005 | //OrderStatus: 1006 | virtual const char* getOsCustomerSelect1(){ 1007 | return "select count(*) from TPCCH.CUSTOMER where C_LAST=? and C_D_ID=? and C_W_ID=?"; 1008 | } 1009 | 1010 | virtual const char* getOsCustomerSelect2(){ 1011 | return "select C_ID, C_BALANCE, C_FIRST, C_MIDDLE, C_LAST from TPCCH.CUSTOMER where C_LAST=? and C_D_ID=? and C_W_ID=? order by C_FIRST asc"; 1012 | } 1013 | 1014 | virtual const char* getOsCustomerSelect3(){ 1015 | return "select C_BALANCE, C_FIRST, C_MIDDLE, C_LAST from TPCCH.CUSTOMER where C_ID=? and C_D_ID=? and C_W_ID=?"; 1016 | } 1017 | 1018 | virtual const char* getOsOrderSelect(){ 1019 | return "select O_ID, O_ENTRY_D, O_CARRIER_ID from TPCCH.\"ORDER\" where O_W_ID=? and O_D_ID=? and O_C_ID=? and O_ID=(select max(O_ID) from TPCCH.\"ORDER\" where O_W_ID=? and O_D_ID=? and O_C_ID=?)"; 1020 | } 1021 | 1022 | virtual const char* getOsOrderlineSelect(){ 1023 | return "select OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT, OL_DELIVERY_D from TPCCH.ORDERLINE where OL_W_ID=? and OL_D_ID=? and OL_O_ID=?"; 1024 | } 1025 | 1026 | //Delivery: 1027 | virtual const char* getDlNewOrderSelect(){ 1028 | return "select NO_O_ID from TPCCH.NEWORDER where NO_W_ID=? and NO_D_ID=? and NO_O_ID=(select min(NO_O_ID) from TPCCH.NEWORDER where NO_W_ID=? and NO_D_ID=?)"; 1029 | } 1030 | 1031 | virtual const char* getDlNewOrderDelete(){ 1032 | return "delete from TPCCH.NEWORDER where NO_W_ID=? and NO_D_ID=? and NO_O_ID=?"; 1033 | } 1034 | 1035 | virtual const char* getDlOrderSelect(){ 1036 | return "select O_C_ID from TPCCH.\"ORDER\" where O_W_ID=? and O_D_ID=? and O_ID=?"; 1037 | } 1038 | 1039 | virtual const char* getDlOrderUpdate(){ 1040 | return "update TPCCH.\"ORDER\" set O_CARRIER_ID=? where O_W_ID=? and O_D_ID=? and O_ID=?"; 1041 | } 1042 | 1043 | virtual const char* getDlOrderlineUpdate(){ 1044 | return "update TPCCH.ORDERLINE set OL_DELIVERY_D=? where OL_W_ID=? and OL_D_ID=? and OL_O_ID=?"; 1045 | } 1046 | 1047 | virtual const char* getDlOrderlineSelect(){ 1048 | return "select sum(OL_AMOUNT) from TPCCH.ORDERLINE where OL_W_ID=? and OL_D_ID=? and OL_O_ID=?"; 1049 | } 1050 | 1051 | virtual const char* getDlCustomerUpdate(){ 1052 | return "update TPCCH.CUSTOMER set C_BALANCE=C_BALANCE+?, C_DELIVERY_CNT=C_DELIVERY_CNT+1 where C_ID=? and C_D_ID=? and C_W_ID=?"; 1053 | } 1054 | 1055 | //StockLevel: 1056 | virtual const char* getSlDistrictSelect(){ 1057 | return "select D_NEXT_O_ID from TPCCH.DISTRICT where D_W_ID=? and D_ID=?"; 1058 | } 1059 | 1060 | virtual const char* getSlStockSelect(){ 1061 | return "select count(*) from TPCCH.STOCK,(select distinct OL_I_ID from TPCCH.ORDERLINE where OL_W_ID=? and OL_D_ID=? and OL_O_ID=?) where S_I_ID=OL_I_ID and S_W_ID=? and S_QUANTITY dropExistingSchemaStatements = { 26 | "DROP DATABASE IF EXISTS tpcch"}; 27 | 28 | std::vector createSchemaStatements = { 29 | "CREATE DATABASE tpcch", 30 | 31 | "CREATE TABLE tpcch.warehouse (\n" 32 | " w_id integer,\n" 33 | " w_name char(10),\n" 34 | " w_street_1 char(20),\n" 35 | " w_street_2 char(20),\n" 36 | " w_city char(20),\n" 37 | " w_state char(2),\n" 38 | " w_zip char(9),\n" 39 | " w_tax decimal(4,4),\n" 40 | " w_ytd decimal(12,2),\n" 41 | " PRIMARY KEY (w_id)\n" 42 | ")", 43 | 44 | "CREATE TABLE tpcch.district (\n" 45 | " d_id tinyint,\n" 46 | " d_w_id integer,\n" 47 | " d_name char(10),\n" 48 | " d_street_1 char(20),\n" 49 | " d_street_2 char(20),\n" 50 | " d_city char(20),\n" 51 | " d_state char(2),\n" 52 | " d_zip char(9),\n" 53 | " d_tax decimal(4,4),\n" 54 | " d_ytd decimal(12,2),\n" 55 | " d_next_o_id integer,\n" 56 | " PRIMARY KEY (d_w_id, d_id) \n" 57 | ")", 58 | 59 | "CREATE INDEX fk_district_warehouse ON tpcch.district (d_w_id ASC)", 60 | 61 | "CREATE TABLE tpcch.customer (\n" 62 | " c_id smallint,\n" 63 | " c_d_id tinyint,\n" 64 | " c_w_id integer,\n" 65 | " c_first char(16),\n" 66 | " c_middle char(2),\n" 67 | " c_last char(16),\n" 68 | " c_street_1 char(20),\n" 69 | " c_street_2 char(20),\n" 70 | " c_city char(20),\n" 71 | " c_state char(2),\n" 72 | " c_zip char(9),\n" 73 | " c_phone char(16),\n" 74 | " c_since DATE,\n" 75 | " c_credit char(2),\n" 76 | " c_credit_lim decimal(12,2),\n" 77 | " c_discount decimal(4,4),\n" 78 | " c_balance decimal(12,2),\n" 79 | " c_ytd_payment decimal(12,2),\n" 80 | " c_payment_cnt smallint,\n" 81 | " c_delivery_cnt smallint,\n" 82 | " c_data text,\n" 83 | " c_n_nationkey integer,\n" 84 | " PRIMARY KEY(c_w_id, c_d_id, c_id)\n" 85 | ")", 86 | 87 | "CREATE INDEX fk_customer_district ON tpcch.customer" 88 | "(c_w_id ASC, c_d_id ASC)", 89 | 90 | "CREATE TABLE tpcch.history (\n" 91 | " h_c_id smallint,\n" 92 | " h_c_d_id tinyint,\n" 93 | " h_c_w_id integer,\n" 94 | " h_d_id tinyint,\n" 95 | " h_w_id integer,\n" 96 | " h_date date,\n" 97 | " h_amount decimal(6,2),\n" 98 | " h_data char(24)\n" 99 | ")", 100 | 101 | "CREATE INDEX fk_history_customer ON tpcch.history " 102 | "(h_c_w_id ASC, h_c_d_id ASC, h_c_id ASC)", 103 | 104 | "CREATE INDEX fk_history_district ON tpcch.history " 105 | "(h_w_id ASC, h_d_id ASC)", 106 | 107 | "CREATE TABLE tpcch.neworder (\n" 108 | " no_o_id integer,\n" 109 | " no_d_id tinyint,\n" 110 | " no_w_id integer,\n" 111 | " PRIMARY KEY (no_w_id, no_d_id, no_o_id)\n" 112 | ")", 113 | 114 | "CREATE TABLE tpcch.order (\n" 115 | " o_id integer,\n" 116 | " o_d_id tinyint,\n" 117 | " o_w_id integer,\n" 118 | " o_c_id smallint,\n" 119 | " o_entry_d date,\n" 120 | " o_carrier_id tinyint,\n" 121 | " o_ol_cnt tinyint,\n" 122 | " o_all_local tinyint,\n" 123 | " PRIMARY KEY (o_w_id, o_d_id, o_id)\n" 124 | ")", 125 | 126 | "CREATE INDEX fk_order_customer ON tpcch.order " 127 | "(o_w_id ASC, o_d_id ASC, o_c_id ASC)", 128 | 129 | "CREATE TABLE tpcch.orderline (\n" 130 | " ol_o_id integer,\n" 131 | " ol_d_id tinyint,\n" 132 | " ol_w_id integer,\n" 133 | " ol_number tinyint,\n" 134 | " ol_i_id integer,\n" 135 | " ol_supply_w_id integer,\n" 136 | " ol_delivery_d date,\n" 137 | " ol_quantity smallint,\n" 138 | " ol_amount decimal(6,2),\n" 139 | " ol_dist_info char(24),\n" 140 | " PRIMARY KEY (ol_w_id, ol_d_id, ol_o_id, ol_number)\n" 141 | ")", 142 | 143 | "CREATE INDEX fk_orderline_order ON tpcch.orderline " 144 | "(ol_w_id ASC, ol_d_id ASC, ol_o_id ASC)", 145 | 146 | "CREATE INDEX fk_orderline_stock ON tpcch.orderline " 147 | "(ol_supply_w_id ASC, ol_i_id ASC)", 148 | 149 | "CREATE TABLE tpcch.item (\n" 150 | " i_id integer,\n" 151 | " i_im_id smallint,\n" 152 | " i_name char(24),\n" 153 | " i_price decimal(5,2),\n" 154 | " i_data char(50),\n" 155 | " PRIMARY KEY (i_id)\n" 156 | ")", 157 | 158 | "CREATE TABLE tpcch.stock (\n" 159 | " s_i_id integer,\n" 160 | " s_w_id integer,\n" 161 | " s_quantity integer,\n" 162 | " s_dist_01 char(24),\n" 163 | " s_dist_02 char(24),\n" 164 | " s_dist_03 char(24),\n" 165 | " s_dist_04 char(24),\n" 166 | " s_dist_05 char(24),\n" 167 | " s_dist_06 char(24),\n" 168 | " s_dist_07 char(24),\n" 169 | " s_dist_08 char(24),\n" 170 | " s_dist_09 char(24),\n" 171 | " s_dist_10 char(24),\n" 172 | " s_ytd integer,\n" 173 | " s_order_cnt integer,\n" 174 | " s_remote_cnt integer,\n" 175 | " s_data char(50),\n" 176 | " s_su_suppkey integer,\n" 177 | " PRIMARY KEY (s_w_id, s_i_id)\n" 178 | ")", 179 | 180 | "CREATE INDEX fk_stock_warehouse ON tpcch.stock (s_w_id ASC)", 181 | 182 | "CREATE INDEX fk_stock_item ON tpcch.stock (s_i_id ASC)", 183 | 184 | "CREATE TABLE tpcch.nation (\n" 185 | " n_nationkey tinyint NOT NULL,\n" 186 | " n_name char(25) NOT NULL,\n" 187 | " n_regionkey tinyint NOT NULL,\n" 188 | " n_comment char(152) NOT NULL,\n" 189 | " PRIMARY KEY (n_nationkey)\n" 190 | ")", 191 | 192 | "CREATE TABLE tpcch.supplier (\n" 193 | " su_suppkey smallint NOT NULL,\n" 194 | " su_name char(25) NOT NULL,\n" 195 | " su_address char(40) NOT NULL,\n" 196 | " su_nationkey tinyint NOT NULL,\n" 197 | " su_phone char(15) NOT NULL,\n" 198 | " su_acctbal decimal(12,2) NOT NULL,\n" 199 | " su_comment char(101) NOT NULL,\n" 200 | " PRIMARY KEY (su_suppkey)\n" 201 | ")", 202 | 203 | "CREATE TABLE tpcch.region (\n" 204 | " r_regionkey tinyint NOT NULL,\n" 205 | " r_name char(55) NOT NULL,\n" 206 | " r_comment char(152) NOT NULL,\n" 207 | " PRIMARY KEY (r_regionkey)\n" 208 | ")"}; 209 | 210 | std::vector additionalPreparationStatements = {}; 211 | 212 | std::vector importPrefixStrings = { 213 | "LOAD DATA INFILE '", "LOAD DATA INFILE '", "LOAD DATA INFILE '", 214 | "LOAD DATA INFILE '", "LOAD DATA INFILE '", "LOAD DATA INFILE '", 215 | "LOAD DATA INFILE '", "LOAD DATA INFILE '", "LOAD DATA INFILE '", 216 | "LOAD DATA INFILE '", "LOAD DATA INFILE '", "LOAD DATA INFILE '"}; 217 | 218 | std::vector importSuffixStrings = { 219 | "/warehouse.tbl' INTO TABLE tpcch.warehouse FIELDS TERMINATED BY '|'", 220 | "/district.tbl' INTO TABLE tpcch.district FIELDS TERMINATED BY '|'", 221 | "/customer.tbl' INTO TABLE tpcch.customer FIELDS TERMINATED BY '|'", 222 | "/history.tbl' INTO TABLE tpcch.history FIELDS TERMINATED BY '|'", 223 | "/neworder.tbl' INTO TABLE tpcch.neworder FIELDS TERMINATED BY '|'", 224 | "/order.tbl' INTO TABLE tpcch.order FIELDS TERMINATED BY '|' " 225 | " (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, @x, o_ol_cnt, o_all_local) " 226 | " SET o_carrier_id = IF(@x = '', NULL, @x)", 227 | "/orderline.tbl' INTO TABLE tpcch.orderline FIELDS TERMINATED BY '|'" 228 | " (ol_o_id, ol_d_id, ol_w_id, ol_number, ol_i_id, ol_supply_w_id, @x, ol_quantity, ol_amount, ol_dist_info) " 229 | " SET ol_delivery_d = IF(@x = '', NULL, @x)", 230 | "/item.tbl' INTO TABLE tpcch.item FIELDS TERMINATED BY '|'", 231 | "/stock.tbl' INTO TABLE tpcch.stock FIELDS TERMINATED BY '|'", 232 | "/nation.tbl' INTO TABLE tpcch.nation FIELDS TERMINATED BY '|'", 233 | "/supplier.tbl' INTO TABLE tpcch.supplier FIELDS TERMINATED BY '|'", 234 | "/region.tbl' INTO TABLE tpcch.region FIELDS TERMINATED BY '|'"}; 235 | 236 | std::vector tpchQueryStrings = { 237 | // TPC-H-Query 1 238 | "select\n" 239 | " ol_number,\n" 240 | " sum(ol_quantity) as sum_qty,\n" 241 | " sum(ol_amount) as sum_amount,\n" 242 | " avg(ol_quantity) as avg_qty," 243 | " avg(ol_amount) as avg_amount,\n" 244 | " count(*) as count_order\n" 245 | "from\n" 246 | " tpcch.orderline\n" 247 | "where\n" 248 | " ol_delivery_d > '2007-01-02 00:00:00.000000'\n" 249 | "group by\n" 250 | " ol_number\n" 251 | "order by\n" 252 | " ol_number", 253 | 254 | // TPC-H-Query 2 255 | "select\n" 256 | " su_suppkey, su_name, n_name, i_id, i_name, su_address, su_phone, su_comment\n" 257 | "from\n" 258 | " tpcch.item, tpcch.supplier, tpcch.stock, tpcch.nation, tpcch.region,\n" 259 | " ( select\n" 260 | " s_i_id as m_i_id,\n" 261 | " min(s_quantity) as m_s_quantity\n" 262 | " from\n" 263 | " tpcch.stock, tpcch.supplier, tpcch.nation, tpcch.region\n" 264 | " where\n" 265 | " s_su_suppkey = su_suppkey\n" 266 | " and su_nationkey = n_nationkey\n" 267 | " and n_regionkey = r_regionkey\n" 268 | " and r_name like 'EUROP%'\n" 269 | " group by\n" 270 | " s_i_id\n" 271 | " ) m\n" 272 | "where\n" 273 | " i_id = s_i_id\n" 274 | " and s_su_suppkey = su_suppkey\n" 275 | " and su_nationkey = n_nationkey\n" 276 | " and n_regionkey = r_regionkey\n" 277 | " and i_data like '%b'\n" 278 | " and r_name like 'EUROP%'\n" 279 | " and i_id = m_i_id\n" 280 | " and s_quantity = m_s_quantity\n" 281 | "order by\n" 282 | " n_name, su_name, i_id", 283 | 284 | // TPC-H-Query 3 285 | "select\n" 286 | " ol_o_id, ol_w_id, ol_d_id,\n" 287 | " sum(ol_amount) as revenue, o_entry_d\n" 288 | "from\n" 289 | " tpcch.customer, tpcch.neworder, tpcch.order, tpcch.orderline\n" 290 | "where\n" 291 | " c_state like 'A%'\n" 292 | " and c_id = o_c_id\n" 293 | " and c_w_id = o_w_id\n" 294 | " and c_d_id = o_d_id\n" 295 | " and no_w_id = o_w_id\n" 296 | " and no_d_id = o_d_id\n" 297 | " and no_o_id = o_id\n" 298 | " and ol_w_id = o_w_id\n" 299 | " and ol_d_id = o_d_id\n" 300 | " and ol_o_id = o_id\n" 301 | " and o_entry_d > '2007-01-02 00:00:00.000000'\n" 302 | "group by\n" 303 | " ol_o_id, ol_w_id, ol_d_id, o_entry_d\n" 304 | "order by\n" 305 | " revenue desc, o_entry_d", 306 | 307 | // TPC-H-Query 4 308 | "select\n" 309 | " o_ol_cnt, count(*) as order_count\n" 310 | "from\n" 311 | " tpcch.order\n" 312 | "where\n" 313 | " o_entry_d >= '2007-01-02 00:00:00.000000'\n" 314 | " and o_entry_d < '2012-01-02 00:00:00.000000'\n" 315 | " and exists \n" 316 | " ( select *\n" 317 | " from tpcch.orderline\n" 318 | " where o_id = ol_o_id\n" 319 | " and o_w_id = ol_w_id\n" 320 | " and o_d_id = ol_d_id\n" 321 | " and ol_delivery_d >= o_entry_d)\n" 322 | "group by\n" 323 | " o_ol_cnt\n" 324 | "order by\n" 325 | " o_ol_cnt", 326 | 327 | // TPC-H-Query 5 328 | "select\n" 329 | " n_name,\n" 330 | " sum(ol_amount) as revenue\n" 331 | "from\n" 332 | " tpcch.customer, tpcch.order, tpcch.orderline, tpcch.stock, tpcch.supplier, tpcch.nation, tpcch.region\n" 333 | "where\n" 334 | " c_id = o_c_id\n" 335 | " and c_w_id = o_w_id\n" 336 | " and c_d_id = o_d_id\n" 337 | " and ol_o_id = o_id\n" 338 | " and ol_w_id = o_w_id\n" 339 | " and ol_d_id=o_d_id\n" 340 | " and ol_w_id = s_w_id\n" 341 | " and ol_i_id = s_i_id\n" 342 | " and s_su_suppkey = su_suppkey\n" 343 | " and c_n_nationkey = su_nationkey\n" 344 | " and su_nationkey = n_nationkey\n" 345 | " and n_regionkey = r_regionkey\n" 346 | " and r_name = 'EUROPE'\n" 347 | " and o_entry_d >= '2007-01-02 00:00:00.000000'\n" 348 | "group by\n" 349 | " n_name\n" 350 | "order by\n" 351 | " revenue desc", 352 | 353 | // TPC-H-Query 6 354 | "select\n" 355 | " sum(ol_amount) as revenue\n" 356 | "from\n" 357 | " tpcch.orderline\n" 358 | "where\n" 359 | " ol_delivery_d >= '1999-01-01 00:00:00.000000'\n" 360 | " and ol_delivery_d < '2020-01-01 00:00:00.000000'\n" 361 | " and ol_quantity between 1 and 100000", 362 | 363 | // TPC-H-Query 7 364 | "select\n" 365 | " su_nationkey as supp_nation,\n" 366 | " substr(c_state,1,1) as cust_nation,\n" 367 | " extract(year from o_entry_d) as l_year,\n" 368 | " sum(ol_amount) as revenue\n" 369 | "from\n" 370 | " tpcch.supplier, tpcch.stock, tpcch.orderline, tpcch.order, tpcch.customer, tpcch.nation n1, tpcch.nation n2\n" 371 | "where\n" 372 | " ol_supply_w_id = s_w_id\n" 373 | " and ol_i_id = s_i_id\n" 374 | " and s_su_suppkey = su_suppkey\n" 375 | " and ol_w_id = o_w_id\n" 376 | " and ol_d_id = o_d_id\n" 377 | " and ol_o_id = o_id\n" 378 | " and c_id = o_c_id\n" 379 | " and c_w_id = o_w_id\n" 380 | " and c_d_id = o_d_id\n" 381 | " and su_nationkey = n1.n_nationkey\n" 382 | " and c_n_nationkey = n2.n_nationkey\n" 383 | " and (\n" 384 | " (n1.n_name = 'GERMANY' and n2.n_name = 'CAMBODIA')\n" 385 | " or\n" 386 | " (n1.n_name = 'CAMBODIA' and n2.n_name = 'GERMANY')\n" 387 | " )\n" 388 | " and ol_delivery_d between '2007-01-02 00:00:00.000000' and '2012-01-02 00:00:00.000000'\n" 389 | "group by\n" 390 | " su_nationkey, substr(c_state,1,1), extract(year from o_entry_d)\n" 391 | "order by\n" 392 | " su_nationkey, cust_nation, l_year", 393 | 394 | // TPC-H-Query 8 395 | "select\n" 396 | " extract(year from o_entry_d) as l_year,\n" 397 | " sum(case when n2.n_name = 'GERMANY' then ol_amount else 0 end) / sum(ol_amount) as mkt_share\n" 398 | "from\n" 399 | " tpcch.item, tpcch.supplier, tpcch.stock, tpcch.orderline, tpcch.order, tpcch.customer, tpcch.nation n1, tpcch.nation n2, tpcch.region\n" 400 | "where\n" 401 | " i_id = s_i_id\n" 402 | " and ol_i_id = s_i_id\n" 403 | " and ol_supply_w_id = s_w_id\n" 404 | " and s_su_suppkey = su_suppkey\n" 405 | " and ol_w_id = o_w_id\n" 406 | " and ol_d_id = o_d_id\n" 407 | " and ol_o_id = o_id\n" 408 | " and c_id = o_c_id\n" 409 | " and c_w_id = o_w_id\n" 410 | " and c_d_id = o_d_id\n" 411 | " and n1.n_nationkey = c_n_nationkey\n" 412 | " and n1.n_regionkey = r_regionkey\n" 413 | " and ol_i_id < 1000\n" 414 | " and r_name = 'EUROPE'\n" 415 | " and su_nationkey = n2.n_nationkey\n" 416 | " and o_entry_d between '2007-01-02 00:00:00.000000' and '2012-01-02 00:00:00.000000'\n" 417 | " and i_data like '%b'\n" 418 | " and i_id = ol_i_id\n" 419 | "group by\n" 420 | " extract(year from o_entry_d)\n" 421 | "order by\n" 422 | " l_year", 423 | 424 | // TPC-H-Query 9 425 | "select\n" 426 | " n_name, extract(year from o_entry_d) as l_year, sum(ol_amount) as sum_profit\n" 427 | "from\n" 428 | " tpcch.item, tpcch.stock, tpcch.supplier, tpcch.orderline, tpcch.order, tpcch.nation\n" 429 | "where\n" 430 | " ol_i_id = s_i_id\n" 431 | " and ol_supply_w_id = s_w_id\n" 432 | " and s_su_suppkey = su_suppkey\n" 433 | " and ol_w_id = o_w_id\n" 434 | " and ol_d_id = o_d_id\n" 435 | " and ol_o_id = o_id\n" 436 | " and ol_i_id = i_id\n" 437 | " and su_nationkey = n_nationkey\n" 438 | " and i_data like '%BB'\n" 439 | "group by\n" 440 | " n_name, extract(year from o_entry_d)\n" 441 | "order by\n" 442 | " n_name, l_year desc", 443 | 444 | // TPC-H-Query 10 445 | "select\n" 446 | " c_id, c_last, sum(ol_amount) as revenue, c_city, c_phone, n_name\n" 447 | "from\n" 448 | " tpcch.customer, tpcch.order, tpcch.orderline, tpcch.nation\n" 449 | "where\n" 450 | " c_id = o_c_id\n" 451 | " and c_w_id = o_w_id\n" 452 | " and c_d_id = o_d_id\n" 453 | " and ol_w_id = o_w_id\n" 454 | " and ol_d_id = o_d_id\n" 455 | " and ol_o_id = o_id\n" 456 | " and o_entry_d >= '2007-01-02 00:00:00.000000'\n" 457 | " and o_entry_d <= ol_delivery_d\n" 458 | " and n_nationkey = c_n_nationkey\n" 459 | "group by\n" 460 | " c_id, c_last, c_city, c_phone, n_name\n" 461 | "order by\n" 462 | " revenue desc", 463 | 464 | // TPC-H-Query 11 465 | "select\n" 466 | " s_i_id, sum(s_order_cnt) as ordercount\n" 467 | "from\n" 468 | " tpcch.stock, tpcch.supplier, tpcch.nation\n" 469 | "where\n" 470 | " s_su_suppkey = su_suppkey\n" 471 | " and su_nationkey = n_nationkey\n" 472 | " and n_name = 'GERMANY'\n" 473 | "group by\n" 474 | " s_i_id\n" 475 | "having \n" 476 | " sum(s_order_cnt) > (\n" 477 | " select\n" 478 | " sum(s_order_cnt) * .005\n" 479 | " from\n" 480 | " tpcch.stock, tpcch.supplier, tpcch.nation\n" 481 | " where\n" 482 | " s_su_suppkey = su_suppkey\n" 483 | " and su_nationkey = n_nationkey\n" 484 | " and n_name = 'GERMANY')\n" 485 | "order by\n" 486 | " ordercount desc", 487 | 488 | // TPC-H-Query 12 489 | "select\n" 490 | " o_ol_cnt,\n" 491 | " sum(case when o_carrier_id = 1 or o_carrier_id = 2 then 1 else 0 end) as high_line_count,\n" 492 | " sum(case when o_carrier_id <> 1 and o_carrier_id <> 2 then 1 else 0 end) as low_line_count\n" 493 | "from\n" 494 | " tpcch.order, tpcch.orderline\n" 495 | "where\n" 496 | " ol_w_id = o_w_id\n" 497 | " and ol_d_id = o_d_id\n" 498 | " and ol_o_id = o_id\n" 499 | " and o_entry_d <= ol_delivery_d\n" 500 | " and ol_delivery_d < '2020-01-01 00:00:00.000000'\n" 501 | "group by\n" 502 | " o_ol_cnt\n" 503 | "order by\n" 504 | " o_ol_cnt", 505 | 506 | // TPC-H-Query 13 507 | "select\n" 508 | " c_count, count(*) as custdist\n" 509 | "from\n" 510 | " ( select\n" 511 | " c_id, count(o_id) as c_count\n" 512 | " from\n" 513 | " tpcch.customer left outer join tpcch.order on (\n" 514 | " c_w_id = o_w_id\n" 515 | " and c_d_id = o_d_id\n" 516 | " and c_id = o_c_id\n" 517 | " and o_carrier_id > 8)\n" 518 | " group by\n" 519 | " c_id\n" 520 | " ) as c_orders\n" 521 | "group by\n" 522 | " c_count\n" 523 | "order by\n" 524 | " custdist desc, c_count desc", 525 | 526 | // TPC-H-Query 14 527 | "select\n" 528 | " 100.00 * sum(case when i_data like 'PR%' then ol_amount else 0 end) / (1+sum(ol_amount)) as promo_revenue\n" 529 | "from\n" 530 | " tpcch.orderline, tpcch.item\n" 531 | "where\n" 532 | " ol_i_id = i_id\n" 533 | " and ol_delivery_d >= '2007-01-02 00:00:00.000000'\n" 534 | " and ol_delivery_d < '2020-01-02 00:00:00.000000'", 535 | 536 | // TPC-H-Query 15 537 | "select\n" 538 | " su_suppkey, su_name, su_address, su_phone, total_revenue\n" 539 | "from\n" 540 | " tpcch.supplier,\n" 541 | " (select\n" 542 | " s_su_suppkey as supplier_no,\n" 543 | " sum(ol_amount) as total_revenue\n" 544 | " from\n" 545 | " tpcch.orderline, tpcch.stock\n" 546 | " where\n" 547 | " ol_i_id = s_i_id\n" 548 | " and ol_supply_w_id = s_w_id\n" 549 | " and ol_delivery_d >= '2007-01-02 00:00:00.000000'\n" 550 | " group by\n" 551 | " s_su_suppkey\n" 552 | " ) as revenue\n" 553 | "where\n" 554 | " su_suppkey = supplier_no\n" 555 | " and total_revenue = (\n" 556 | " select max(total_revenue)\n" 557 | " from\n" 558 | " (select\n" 559 | " s_su_suppkey as supplier_no,\n" 560 | " sum(ol_amount) as total_revenue\n" 561 | " from\n" 562 | " tpcch.orderline, tpcch.stock\n" 563 | " where\n" 564 | " ol_i_id = s_i_id\n" 565 | " and ol_supply_w_id = s_w_id\n" 566 | " and ol_delivery_d >= '2007-01-02 00:00:00.000000'\n" 567 | " group by\n" 568 | " s_su_suppkey\n" 569 | " ) as revenue\n" 570 | " )\n" 571 | "order by\n" 572 | " su_suppkey", 573 | 574 | // TPC-H-Query 16 575 | "select\n" 576 | " i_name,\n" 577 | " substr(i_data, 1, 3) as brand,\n" 578 | " i_price,\n" 579 | " count(distinct s_su_suppkey) as supplier_cnt\n" 580 | "from\n" 581 | " tpcch.stock, tpcch.item\n" 582 | "where\n" 583 | " i_id = s_i_id\n" 584 | " and i_data not like 'zz%'\n" 585 | " and (s_su_suppkey not in\n" 586 | " ( select\n" 587 | " su_suppkey\n" 588 | " from\n" 589 | " tpcch.supplier\n" 590 | " where\n" 591 | " su_comment like '%bad%')\n" 592 | " )\n" 593 | "group by\n" 594 | " i_name, substr(i_data, 1, 3), i_price\n" 595 | "order by\n" 596 | " supplier_cnt desc", 597 | 598 | // TPC-H-Query 17 599 | "select\n" 600 | " sum(ol_amount) / 2.0 as avg_yearly\n" 601 | "from\n" 602 | " tpcch.orderline,\n" 603 | " ( select\n" 604 | " i_id, avg(ol_quantity) as a\n" 605 | " from\n" 606 | " tpcch.item, tpcch.orderline\n" 607 | " where\n" 608 | " i_data like '%b'\n" 609 | " and ol_i_id = i_id\n" 610 | " group by\n" 611 | " i_id\n" 612 | " ) t\n" 613 | "where\n" 614 | " ol_i_id = t.i_id\n" 615 | " and ol_quantity < t.a", 616 | 617 | // TPC-H-Query 18 618 | "select\n" 619 | " c_last, c_id, o_id, o_entry_d, o_ol_cnt, sum(ol_amount)\n" 620 | "from\n" 621 | " tpcch.customer, tpcch.order, tpcch.orderline\n" 622 | "where\n" 623 | " c_id = o_c_id\n" 624 | " and c_w_id = o_w_id\n" 625 | " and c_d_id = o_d_id\n" 626 | " and ol_w_id = o_w_id\n" 627 | " and ol_d_id = o_d_id\n" 628 | " and ol_o_id = o_id\n" 629 | "group by\n" 630 | " o_id, o_w_id, o_d_id, c_id, c_last, o_entry_d, o_ol_cnt\n" 631 | "having\n" 632 | " sum(ol_amount) > 200\n" 633 | "order by\n" 634 | " sum(ol_amount) desc, o_entry_d", 635 | 636 | // TPC-H-Query 19 637 | "select\n" 638 | " sum(ol_amount) as revenue\n" 639 | "from\n" 640 | " tpcch.orderline, tpcch.item\n" 641 | "where\n" 642 | " (\n" 643 | " ol_i_id = i_id\n" 644 | " and i_data like '%a'\n" 645 | " and ol_quantity >= 1\n" 646 | " and ol_quantity <= 10\n" 647 | " and i_price between 1 and 400000\n" 648 | " and ol_w_id in (1,2,3)\n" 649 | " ) or (\n" 650 | " ol_i_id = i_id\n" 651 | " and i_data like '%b'\n" 652 | " and ol_quantity >= 1\n" 653 | " and ol_quantity <= 10\n" 654 | " and i_price between 1 and 400000\n" 655 | " and ol_w_id in (1,2,4)\n" 656 | " ) or (\n" 657 | " ol_i_id = i_id\n" 658 | " and i_data like '%c'\n" 659 | " and ol_quantity >= 1\n" 660 | " and ol_quantity <= 10\n" 661 | " and i_price between 1 and 400000\n" 662 | " and ol_w_id in (1,5,3)\n" 663 | " )", 664 | 665 | // TPC-H-Query 20 666 | "select su_name, su_address\n" 667 | "from tpcch.supplier, tpcch.nation\n" 668 | "where su_suppkey in\n" 669 | " (select mod(s_i_id * s_w_id, 10000)\n" 670 | " from tpcch.stock, tpcch.orderline\n" 671 | " where s_i_id in\n" 672 | " (select i_id\n" 673 | " from tpcch.item\n" 674 | " where i_data like 'co%')\n" 675 | " and ol_i_id=s_i_id\n" 676 | " and ol_delivery_d > '2010-05-23 12:00:00'\n" 677 | " group by s_i_id, s_w_id, s_quantity\n" 678 | " having 2*s_quantity > sum(ol_quantity))\n" 679 | " and su_nationkey = n_nationkey\n" 680 | " and n_name = 'GERMANY'\n" 681 | "order by su_name", 682 | 683 | // TPC-H-Query 21 684 | "select\n" 685 | " su_name, count(*) as numwait\n" 686 | "from\n" 687 | " tpcch.supplier, tpcch.orderline l1, tpcch.order, tpcch.stock, tpcch.nation\n" 688 | "where\n" 689 | " ol_o_id = o_id\n" 690 | " and ol_w_id = o_w_id\n" 691 | " and ol_d_id = o_d_id\n" 692 | " and ol_w_id = s_w_id\n" 693 | " and ol_i_id = s_i_id\n" 694 | " and s_su_suppkey = su_suppkey\n" 695 | " and l1.ol_delivery_d > o_entry_d\n" 696 | " and not exists (\n" 697 | " select *\n" 698 | " from\n" 699 | " tpcch.orderline l2\n" 700 | " where\n" 701 | " l2.ol_o_id = l1.ol_o_id\n" 702 | " and l2.ol_w_id = l1.ol_w_id\n" 703 | " and l2.ol_d_id = l1.ol_d_id\n" 704 | " and l2.ol_delivery_d > l1.ol_delivery_d\n" 705 | " )\n" 706 | " and su_nationkey = n_nationkey\n" 707 | " and n_name = 'GERMANY'\n" 708 | "group by\n" 709 | " su_name\n" 710 | "order by\n" 711 | " numwait desc, su_name", 712 | 713 | // TPC-H-Query 22 714 | "select\n" 715 | " substr(c_state,1,1) as country,\n" 716 | " count(*) as numcust,\n" 717 | " sum(c_balance) as totacctbal\n" 718 | "from\n" 719 | " tpcch.customer\n" 720 | "where\n" 721 | " substr(c_phone,1,1) in ('1','2','3','4','5','6','7')\n" 722 | " and c_balance > (\n" 723 | " select\n" 724 | " avg(c_BALANCE)\n" 725 | " from\n" 726 | " tpcch.customer\n" 727 | " where\n" 728 | " c_balance > 0.00\n" 729 | " and substr(c_phone,1,1) in ('1','2','3','4','5','6','7')\n" 730 | " )\n" 731 | " and not exists (\n" 732 | " select *\n" 733 | " from\n" 734 | " tpcch.order\n" 735 | " where\n" 736 | " o_c_id = c_id\n" 737 | " and o_w_id = c_w_id\n" 738 | " and o_d_id = c_d_id\n" 739 | " )\n" 740 | "group by\n" 741 | " substr(c_state,1,1)\n" 742 | "order by\n" 743 | " substr(c_state,1,1)"}; 744 | 745 | public: 746 | // Strings to create initial database 747 | virtual std::vector& getDropExistingSchemaStatements() { 748 | return dropExistingSchemaStatements; 749 | } 750 | 751 | virtual std::vector& getCreateSchemaStatements() { 752 | return createSchemaStatements; 753 | } 754 | 755 | virtual std::vector& getImportPrefix() { 756 | return importPrefixStrings; 757 | } 758 | 759 | virtual std::vector& getImportSuffix() { 760 | return importSuffixStrings; 761 | } 762 | 763 | virtual std::vector& getAdditionalPreparationStatements() { 764 | return additionalPreparationStatements; 765 | } 766 | 767 | // 22 adjusted TPC-H OLAP query strings 768 | virtual std::vector& getTpchQueryStrings() { 769 | return tpchQueryStrings; 770 | } 771 | 772 | // Strings for database check 773 | virtual const char* getSelectCountWarehouse() { 774 | return "select count(*) from tpcch.warehouse"; 775 | } 776 | 777 | virtual const char* getSelectCountDistrict() { 778 | return "select count(*) from tpcch.district"; 779 | } 780 | 781 | virtual const char* getSelectCountCustomer() { 782 | return "select count(*) from tpcch.customer"; 783 | } 784 | 785 | virtual const char* getSelectCountOrder() { 786 | return "select count(*) from tpcch.order"; 787 | } 788 | 789 | virtual const char* getSelectCountOrderline() { 790 | return "select count(*) from tpcch.orderline"; 791 | } 792 | 793 | virtual const char* getSelectCountNeworder() { 794 | return "select count(*) from tpcch.neworder"; 795 | } 796 | 797 | virtual const char* getSelectCountHistory() { 798 | return "select count(*) from tpcch.history"; 799 | } 800 | 801 | virtual const char* getSelectCountStock() { 802 | return "select count(*) from tpcch.stock"; 803 | } 804 | 805 | virtual const char* getSelectCountItem() { 806 | return "select count(*) from tpcch.item"; 807 | } 808 | 809 | virtual const char* getSelectCountSupplier() { 810 | return "select count(*) from tpcch.supplier"; 811 | } 812 | 813 | virtual const char* getSelectCountNation() { 814 | return "select count(*) from tpcch.nation"; 815 | } 816 | 817 | virtual const char* getSelectCountRegion() { 818 | return "select count(*) from tpcch.region"; 819 | } 820 | 821 | // TPC-C transaction strings 822 | // NewOrder: 823 | virtual const char* getNoWarehouseSelect() { 824 | return "select W_TAX from tpcch.warehouse where W_ID=?"; 825 | } 826 | 827 | virtual const char* getNoDistrictSelect() { 828 | return "select D_TAX, D_NEXT_O_ID from tpcch.district where D_W_ID=? and D_ID=?"; 829 | } 830 | 831 | virtual const char* getNoDistrictUpdate() { 832 | return "update tpcch.district set D_NEXT_O_ID=D_NEXT_O_ID+1 where D_W_ID=? and D_ID=?"; 833 | } 834 | 835 | virtual const char* getNoCustomerSelect() { 836 | return "select C_DISCOUNT,C_LAST,C_CREDIT from tpcch.customer where C_W_ID=? and C_D_ID=? and C_ID=?"; 837 | } 838 | 839 | virtual const char* getNoOrderInsert() { 840 | return "insert into tpcch.order values (?,?,?,?,?,NULL,?,?)"; 841 | } 842 | 843 | virtual const char* getNoNewOrderInsert() { 844 | return "insert into tpcch.neworder values(?,?,?)"; 845 | } 846 | 847 | virtual const char* getNoItemSelect() { 848 | return "select I_PRICE,I_NAME,I_DATA from tpcch.item where I_ID=?"; 849 | } 850 | 851 | virtual const char* getNoStockSelect01() { 852 | return "select S_QUANTITY,S_DIST_01,S_DATA from tpcch.stock where S_I_ID=? and S_W_ID=?"; 853 | } 854 | 855 | virtual const char* getNoStockSelect02() { 856 | return "select S_QUANTITY,S_DIST_02,S_DATA from tpcch.stock where S_I_ID=? and S_W_ID=?"; 857 | } 858 | 859 | virtual const char* getNoStockSelect03() { 860 | return "select S_QUANTITY,S_DIST_03,S_DATA from tpcch.stock where S_I_ID=? and S_W_ID=?"; 861 | } 862 | 863 | virtual const char* getNoStockSelect04() { 864 | return "select S_QUANTITY,S_DIST_04,S_DATA from tpcch.stock where S_I_ID=? and S_W_ID=?"; 865 | } 866 | 867 | virtual const char* getNoStockSelect05() { 868 | return "select S_QUANTITY,S_DIST_05,S_DATA from tpcch.stock where S_I_ID=? and S_W_ID=?"; 869 | } 870 | 871 | virtual const char* getNoStockSelect06() { 872 | return "select S_QUANTITY,S_DIST_06,S_DATA from tpcch.stock where S_I_ID=? and S_W_ID=?"; 873 | } 874 | 875 | virtual const char* getNoStockSelect07() { 876 | return "select S_QUANTITY,S_DIST_07,S_DATA from tpcch.stock where S_I_ID=? and S_W_ID=?"; 877 | } 878 | 879 | virtual const char* getNoStockSelect08() { 880 | return "select S_QUANTITY,S_DIST_08,S_DATA from tpcch.stock where S_I_ID=? and S_W_ID=?"; 881 | } 882 | 883 | virtual const char* getNoStockSelect09() { 884 | return "select S_QUANTITY,S_DIST_09,S_DATA from tpcch.stock where S_I_ID=? and S_W_ID=?"; 885 | } 886 | 887 | virtual const char* getNoStockSelect10() { 888 | return "select S_QUANTITY,S_DIST_10,S_DATA from tpcch.stock where S_I_ID=? and S_W_ID=?"; 889 | } 890 | 891 | virtual const char* getNoStockUpdate01() { 892 | return "update tpcch.stock set S_YTD=156 where S_I_ID=? and S_W_ID=?"; 893 | } 894 | 895 | virtual const char* getNoStockUpdate02() { 896 | return "update tpcch.stock set S_YTD=S_YTD+?, S_ORDER_CNT=S_ORDER_CNT+1, S_QUANTITY=?, S_REMOTE_CNT=S_REMOTE_CNT+1 where S_I_ID=? and S_W_ID=?"; 897 | } 898 | 899 | virtual const char* getNoOrderlineInsert() { 900 | return "insert into tpcch.orderline values (?,?,?,?,?,?,NULL,?,?,?)"; 901 | } 902 | 903 | // Payment: 904 | virtual const char* getPmWarehouseSelect() { 905 | return "select W_NAME, W_STREET_1, W_STREET_2, W_CITY, W_STATE, W_ZIP from tpcch.warehouse where W_ID=?"; 906 | } 907 | 908 | virtual const char* getPmWarehouseUpdate() { 909 | return "update tpcch.warehouse set W_YTD=W_YTD+? where W_ID=?"; 910 | } 911 | 912 | virtual const char* getPmDistrictSelect() { 913 | return "select D_NAME, D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP from tpcch.district where D_W_ID=? and D_ID=?"; 914 | } 915 | 916 | virtual const char* getPmDistrictUpdate() { 917 | return "update tpcch.district set D_YTD=D_YTD+? where D_W_ID=? and D_ID=?"; 918 | } 919 | 920 | virtual const char* getPmCustomerSelect1() { 921 | return "select count(*) from tpcch.customer where C_LAST=? and C_D_ID=? and C_W_ID=?"; 922 | } 923 | 924 | virtual const char* getPmCustomerSelect2() { 925 | return "select C_ID, C_FIRST, C_MIDDLE, C_STREET_1, C_STREET_2, C_CITY, C_STATE, C_ZIP, C_PHONE, C_SINCE, C_CREDIT, C_CREDIT_LIM, C_DISCOUNT, C_BALANCE from tpcch.customer where C_LAST=? and C_D_ID=? and C_W_ID=? order by C_FIRST asc"; 926 | } 927 | 928 | virtual const char* getPmCustomerSelect3() { 929 | return "select C_FIRST, C_MIDDLE, C_LAST, C_STREET_1, C_STREET_2, C_CITY, C_STATE, C_ZIP, C_PHONE, C_SINCE, C_CREDIT, C_CREDIT_LIM, C_DISCOUNT, C_BALANCE from tpcch.customer where C_ID=? and C_D_ID=? and C_W_ID=?"; 930 | } 931 | 932 | virtual const char* getPmCustomerUpdate1() { 933 | return "update tpcch.customer set C_BALANCE=C_BALANCE-?, C_YTD_PAYMENT=C_YTD_PAYMENT+?, C_PAYMENT_CNT=C_PAYMENT_CNT+1 where C_ID=? and C_D_ID=? and C_W_ID=?"; 934 | } 935 | 936 | virtual const char* getPmCustomerSelect4() { 937 | return "select C_DATA from tpcch.customer where C_ID=? and C_D_ID=? and C_W_ID=?"; 938 | } 939 | 940 | virtual const char* getPmCustomerUpdate2() { 941 | return "update tpcch.customer set C_DATA=? where C_ID=? and C_D_ID=? and C_W_ID=?"; 942 | } 943 | 944 | virtual const char* getPmHistoryInsert() { 945 | return "insert into tpcch.history values (?,?,?,?,?,?,?,?)"; 946 | } 947 | 948 | // OrderStatus: 949 | virtual const char* getOsCustomerSelect1() { 950 | return "select count(*) from tpcch.customer where C_LAST=? and C_D_ID=? and C_W_ID=?"; 951 | } 952 | 953 | virtual const char* getOsCustomerSelect2() { 954 | return "select C_ID, C_BALANCE, C_FIRST, C_MIDDLE, C_LAST from tpcch.customer where C_LAST=? and C_D_ID=? and C_W_ID=? order by C_FIRST asc"; 955 | } 956 | 957 | virtual const char* getOsCustomerSelect3() { 958 | return "select C_BALANCE, C_FIRST, C_MIDDLE, C_LAST from tpcch.customer where C_ID=? and C_D_ID=? and C_W_ID=?"; 959 | } 960 | 961 | virtual const char* getOsOrderSelect() { 962 | return "select O_ID, O_ENTRY_D, O_CARRIER_ID from tpcch.order where O_W_ID=? and O_D_ID=? and O_C_ID=? and O_ID=(select max(O_ID) from tpcch.order where O_W_ID=? and O_D_ID=? and O_C_ID=?)"; 963 | } 964 | 965 | virtual const char* getOsOrderlineSelect() { 966 | return "select OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT, OL_DELIVERY_D from tpcch.orderline where OL_W_ID=? and OL_D_ID=? and OL_O_ID=?"; 967 | } 968 | 969 | // Delivery: 970 | virtual const char* getDlNewOrderSelect() { 971 | return "select NO_O_ID from tpcch.neworder where NO_W_ID=? and NO_D_ID=? and NO_O_ID=(select min(NO_O_ID) from tpcch.neworder where NO_W_ID=? and NO_D_ID=?)"; 972 | } 973 | 974 | virtual const char* getDlNewOrderDelete() { 975 | return "delete from tpcch.neworder where NO_W_ID=? and NO_D_ID=? and NO_O_ID=?"; 976 | } 977 | 978 | virtual const char* getDlOrderSelect() { 979 | return "select O_C_ID from tpcch.order where O_W_ID=? and O_D_ID=? and O_ID=?"; 980 | } 981 | 982 | virtual const char* getDlOrderUpdate() { 983 | return "update tpcch.order set O_CARRIER_ID=? where O_W_ID=? and O_D_ID=? and O_ID=?"; 984 | } 985 | 986 | virtual const char* getDlOrderlineUpdate() { 987 | return "update tpcch.orderline set OL_DELIVERY_D=? where OL_W_ID=? and OL_D_ID=? and OL_O_ID=?"; 988 | } 989 | 990 | virtual const char* getDlOrderlineSelect() { 991 | return "select sum(OL_AMOUNT) from tpcch.orderline where OL_W_ID=? and OL_D_ID=? and OL_O_ID=?"; 992 | } 993 | 994 | virtual const char* getDlCustomerUpdate() { 995 | return "update tpcch.customer set C_BALANCE=C_BALANCE+?, C_DELIVERY_CNT=C_DELIVERY_CNT+1 where C_ID=? and C_D_ID=? and C_W_ID=?"; 996 | } 997 | 998 | // StockLevel: 999 | virtual const char* getSlDistrictSelect() { 1000 | return "select D_NEXT_O_ID from tpcch.district where D_W_ID=? and D_ID=?"; 1001 | } 1002 | 1003 | virtual const char* getSlStockSelect() { 1004 | return "select count(*) from tpcch.stock,(select distinct OL_I_ID from tpcch.orderline where OL_W_ID=? and OL_D_ID=? and OL_O_ID=?) _ where S_I_ID=OL_I_ID and S_W_ID=? and S_QUANTITY