-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc.test
More file actions
143 lines (116 loc) · 3.22 KB
/
main.cc.test
File metadata and controls
143 lines (116 loc) · 3.22 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <vector>
#include <string>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include "Schema.h"
#include "Catalog.h"
using namespace std;
int main (int argc, char* argv[]) {
if (argc != 4) {
cout << "Usage: main [sqlite_file] [no_tables] [no_atts]" << endl;
return -1;
}
string dbFile = argv[1];
int tNo = atoi(argv[2]);
int aNo = atoi(argv[3]);
Catalog catalog(dbFile);
cout << catalog << endl; cout.flush();
////////////////////////////////
for (int i = 0; i < tNo; i++) {
char tN[20]; sprintf(tN, "T_%d", i);
string tName = tN;
int taNo = i * aNo;
vector<string> atts;
vector<string> types;
for (int j = 0; j < taNo; j++) {
char aN[20]; sprintf(aN, "A_%d_%d", i, j);
string aName = aN;
atts.push_back(aN);
string aType;
int at = j % 3;
if (0 == at) aType = "INTEGER";
else if (1 == at) aType = "FLOAT";
else if (2 == at) aType = "STRING";
types.push_back(aType);
}
bool ret = catalog.CreateTable(tName, atts, types);
if (true == ret) {
cout << "CREATE TABLE " << tName << " OK" << endl;
for (int j = 0; j < taNo; j++) {
unsigned int dist = i * 10 + j;
string aN = atts[j];
cout<< atts[j] <<endl;
catalog.SetNoDistinct(tName, aN, dist);
}
unsigned int tuples = i * 1000;
catalog.SetNoTuples(tName, tuples);
//catalog.GetNoTuples(tName, tuples);
//cout<<"Get No of Tuples "<<tuples<<endl;
string path = tName + ".dat";
catalog.SetDataFile(tName, path);
//catalog.GetDataFile(tName, path);
//cout<<"Set Data Path"<<path<<endl;
}
else {
cout << "CREATE TABLE " << tName << " FAIL" << endl;
}
}
////////////////////////////////
catalog.Save();
cout << "Catalog saved"<<endl;
cout << catalog << endl;
cout.flush();
////////////////////////////////
vector<string> tables;
catalog.GetTables(tables);
for (vector<string>::iterator it = tables.begin();
it != tables.end(); it++) {
cout << *it << endl;
}
cout << endl;
////////////////////////////////
for (int i = 0; i < 1000; i++) {
int r = rand() % tNo + 1;
char tN[20]; sprintf(tN, "T_%d", r);
string tName = tN;
unsigned int tuples;
catalog.GetNoTuples(tName, tuples);
cout << tName << " tuples = " << tuples << endl;
string path;
catalog.GetDataFile(tName, path);
cout << tName << " path = " << path << endl;
vector<string> atts;
catalog.GetAttributes(tName, atts);
for (vector<string>::iterator it = atts.begin();
it != atts.end(); it++) {
cout << *it << " ";
}
cout << endl;
Schema schema;
catalog.GetSchema(tName, schema);
cout << schema << endl;
////////////////////////////////
for (int j = 0; j < 10; j++) {
int s = rand() % (r * aNo) + 1;
char aN[20]; sprintf(aN, "A_%d_%d", r, s);
string aName = aN;
unsigned int distinct;
catalog.GetNoDistinct(tName, aName, distinct);
cout << tName << "." << aName << " distinct = " << distinct << endl;
}
}
////////////////////////////////
for (int i = 0; i < 5; i++) {
char tN[20]; sprintf(tN, "T_%d", i);
string tName = tN;
bool ret = catalog.DropTable(tName);
if (true == ret) {
cout << "DROP TABLE " << tName << " OK" << endl;
}
else {
cout << "DROP TABLE " << tName << " FAIL" << endl;
}
}
return 0;
}