BadgerDB
|
00001 00008 #include <cstring> 00009 #include "catalog.h" 00010 #include "query.h" 00011 #include "index.h" 00012 #include "exceptions/end_of_file_exception.h" 00013 #include "exceptions/no_more_records_exception.h" 00014 #include "utility.h" 00015 #include "exceptions/end_of_file_exception.h" 00016 #include "exceptions/bad_param_exception.h" 00017 #include "exceptions/file_open_exception.h" 00018 #include "buffer.h" 00019 #include <cstdio> 00020 #include <fcntl.h> 00021 #include <string> 00022 00023 extern badgerdb::BufMgr *bufMgr; 00024 00025 namespace badgerdb 00026 { 00027 void Operators::Select(const std::string & result, // name of the output relation 00028 int projCnt, // number of attributes in the projection 00029 const attrInfo projNames[], // the list of projection attributes 00030 const attrInfo *attr, // attribute used inthe selection predicate 00031 Operator op, // predicate operation 00032 const void *attrValue) // literal value in the predicate 00033 { 00034 00035 if((op == Operator(EQ))){ //NEED TO CHECK IF THERE IS AN INDEX ALSO 00036 //INDEX SELECT 00037 IndexSelect(result, projCnt, projNames, attr, op, attrValue); 00038 }else{ 00039 //Scan select 00040 //printAttrInfo(&projNames[0]); 00041 //printAttrInfo(attr); 00042 ScanSelect(result, projCnt, projNames, attr, op, attrValue); 00043 } 00044 00045 00046 } 00047 void Operators::ScanSelect(const std::string & result, int projCnt, const attrInfo projNames[], const attrInfo *attr, Operator op, const void *attrValue){ 00048 std::string relation = projNames[0].relName; 00049 //int size = sizeof projNames/sizeof(attrInfo); 00050 int i, j = 0; 00051 std::string s1, s2; 00052 RelDesc rd; 00053 AttrDesc *attrs; 00054 int attrCnt; 00055 00056 relCat->getInfo(relation, rd); 00057 00058 // get attribute data 00059 attrCat->getRelInfo(rd.relName, attrCnt, attrs); 00060 int projToAttrMap[projCnt]; 00061 //Utilities::UT_computeWidth(attrCnt, attrs, attrWidth); 00062 00063 for(i = 0; i < projCnt; i++){ 00064 s1 = projNames[i].attrName; 00065 for(j = 0; j < attrCnt; j++){ 00066 s2 = attrs[j].attrName; 00067 if(s1.compare(s2) == 0){ 00068 projToAttrMap[i] =j; 00069 break; 00070 } 00071 } 00072 } 00073 00074 00075 00076 00077 00078 // compute width of output columns 00079 00080 // UT_computeWidth(attrCnt, attrs, attrWidth); 00081 00082 // open data file 00083 FileScan filescan(rd.relName, bufMgr); 00084 FileScan fscan(result, bufMgr); 00085 RecordId rid; 00086 int records = 0; 00087 while(1) 00088 { 00089 try 00090 { 00091 filescan.scanNext(rid); 00092 std::string recordStr = filescan.getRecord(); 00093 std::string insertstr; 00094 00095 if(DEBUG){ 00096 std::cout<<"\nRecord String size: "<<recordStr.size()<<"\n"; 00097 std::cout<<recordStr; 00098 } 00099 fscan.insertRecord(recordStr, rid); 00100 records++; 00101 } 00102 catch(EndOfFileException &e) 00103 { 00104 break; 00105 } 00106 } 00107 fscan.flushFile(); 00108 } 00109 00110 void Operators::IndexSelect(const std::string & result, int projCnt, const attrInfo projNames[], const attrInfo *attr, Operator op, const void *attrValue){ 00111 } 00112 }