-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
72 lines (59 loc) · 2.58 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "Swordfish.h"
#include <iostream>
#include <string>
using std::shared_ptr;
using std::make_shared;
using oltp::DB;
using oltp::Connection;
int main() {
DolphinDBLib::initializeRuntime();
oltp::DBOption option;
shared_ptr<DB> db = make_shared<DB>("test_db", option);
Connection conn(*db);
auto session = conn.getCurrentSession();
// run .dos on local path
bool success = session->run("../../demo/streamEngineDemo/streamEngineTest.dos");
if(!success) {
throw RuntimeException(session->getLastErrorMessage());
}
std::cout << "================= create oltp table ================="<< std::endl;
const string tableName = "result";
auto tableNameList = conn.listAllTable();
if(std::count(tableNameList.begin(), tableNameList.end(), tableName) != 0) {
conn.dropTable(tableName);
}
std::vector<ColumnDesc> colDesc;
colDesc.emplace_back("sym", DT_STRING, 1);
colDesc.emplace_back("time", DT_TIMESTAMP, 2);
colDesc.emplace_back("factor1", DT_DOUBLE, 3);
std::vector<std::string> primaryKey { "time", "sym" };
std::vector<std::pair<bool, std::vector<std::string>>> secondaryKeys;
conn.createTable(tableName, colDesc, primaryKey, secondaryKeys);
auto resultTable = conn.execute("select * from objByName(`"+tableName +")");
std::cout << resultTable->getString() << std::endl;
// create stream engine
// by calling the function defined in the .dos file
conn.execute("createEngine(`"+ tableName +")");
std::cout << "================= intput to stream engine ================="<< std::endl;
int BLK_SIZE = 20;
int WT_LIMIT = 200;
for(int start = 0; start < WT_LIMIT; start += BLK_SIZE) {
std::string code = "produceData("+ std::to_string(BLK_SIZE) +")";
conn.execute(code);
std::cout << code << std::endl;
code = "exec count(*) from objByName(`"+tableName +")";
auto tableSize = conn.execute(code);
std::cout << code << std::endl;
std::cout << tableSize->getString() << std::endl;
code = "select * from objByName(`"+tableName +") order by time limit " + std::to_string(start) + ", " + std::to_string(BLK_SIZE);
resultTable = conn.execute(code);
std::cout << code << std::endl;
std::cout << resultTable->getString() << std::endl;
sleep(1);
}
std::cout << "================= clean environment ================="<< std::endl;
conn.execute("cleanEnvironment()");
conn.dropTable(tableName);
DolphinDBLib::finalizeRuntime();
return 0;
}