int main_plan(int argc, char* argv[]) { if (argc != 2) return -1; Plan p; p.fromFile(argv[1]); p.print(std::cout); return 0; }
int main(int argc, char** argv) { // if (argc != 2) { // cerr << "usage: " << argv[0] << " <planFile>" << endl; // return -1; // } // parse schema cout << "-- parse schema from " << fileCreate << endl; Parser parser(fileCreate); unique_ptr<Schema> schema; try { schema = parser.parse(); cout << schema->toString() << endl; } catch (ParserError& e) { cerr << e.what() << endl; return -1; } // setting everything up cout << endl << "-- init Buffer- and SegmentManager" << endl; BufferManager bm("/tmp/db", 10ul * 1024ul * 1024ul); // bogus arguments SegmentManager sm(bm); SegmentID spId = sm.createSegment(Segment::SegmentType::Schema, 200); SchemaSegment& scs = static_cast<SchemaSegment&>(sm.getSegment(spId)); // read schema scs.readSchemaFromFile(fileCreate, &sm); // insert tuples cout << endl << "-- insert 5 tuples in each relation" << endl; SPSegment& students = static_cast<SPSegment&>(sm.getSegment(scs.getRelationSegmentID("student"))); struct {int id; char name[64];} sstudent; for(int i=1; i<=5; i++){ sstudent.id = i; // sstudent.name = "Student "+string(i); stringstream ss; ss << "Student " << i; strcpy(sstudent.name, ss.str().c_str()); Record r(sizeof(sstudent), (char*) ((void*) (&sstudent))); students.insert(r); // TID id = } SPSegment& lectures = static_cast<SPSegment&>(sm.getSegment( scs.getRelationSegmentID("lecture"))); struct { int id; char name[64]; } slecture; for (int i = 1; i <= 5; i++) { slecture.id = i; stringstream ss; ss << "Lecture " << i; strcpy(slecture.name, ss.str().c_str()); Record r(sizeof(slecture), (char*) ((void*) (&slecture))); lectures.insert(r); } SPSegment& exams = static_cast<SPSegment&>(sm.getSegment( scs.getRelationSegmentID("exam"))); struct { int l_id; int s_id; int grade; } sexam; for (int i = 1; i <= 5; i++) { sexam.l_id = i; sexam.s_id = i; // 5-i sexam.grade = i + 3; Record r(sizeof(sexam), (char*) ((void*) (&sexam))); exams.insert(r); } // parse query plan cout << endl << "-- parse query plan from " << filePlan << endl; Plan p; p.fromFile(argv[1]); p.print(cout); // const plan::Operator* root = &p.getRoot(); // walk down tree and execute the corresponding physical operators cout << endl << "-- generate tree of physical operators" << endl; operators::Operator* op = walkTree(p.getRoot(), scs, sm); // print results cout << endl << "-- print results" << endl; operators::Print print(op, cout); print.open(); while(print.next()){} print.close(); return 0; }