Commit d6049088 authored by yiwenshao's avatar yiwenshao

able to limit count in final_load

parent 0df36de6
loadCount:1000000 loadCount:3
other:1 other:1
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "wrapper/reuse.hh" #include "wrapper/reuse.hh"
#include "wrapper/common.hh" #include "wrapper/common.hh"
#include "wrapper/insert_lib.hh" #include "wrapper/insert_lib.hh"
#include "util/constants.hh"
using std::cout; using std::cout;
using std::cin; using std::cin;
using std::endl; using std::endl;
...@@ -136,9 +137,9 @@ void initGfb(std::vector<FieldMetaTrans> &res,std::string db,std::string table){ ...@@ -136,9 +137,9 @@ void initGfb(std::vector<FieldMetaTrans> &res,std::string db,std::string table){
std::string filename = prefix + gfb.field_names[i]; std::string filename = prefix + gfb.field_names[i];
std::vector<std::string> column; std::vector<std::string> column;
if(IS_NUM(gfb.field_types[i])){ if(IS_NUM(gfb.field_types[i])){
load_num_file(filename,column); load_num_file_count(filename,column,constGlobalConstants.loadCount);
}else{ }else{
load_string_file(filename,column,gfb.field_lengths[i]); load_string_file_count(filename,column,gfb.field_lengths[i],constGlobalConstants.loadCount);
} }
gfb.annoOnionNameToFileVector[gfb.field_names[i]] = std::move(column); gfb.annoOnionNameToFileVector[gfb.field_names[i]] = std::move(column);
} }
......
...@@ -8,7 +8,7 @@ const char *cryptdb_dir = getenv("CRYPTDB_DIR"); ...@@ -8,7 +8,7 @@ const char *cryptdb_dir = getenv("CRYPTDB_DIR");
//assert(cryptdb_dir!=NULL); //assert(cryptdb_dir!=NULL);
const globalConstants constGlobalConstants = initGlobalConstants(); const globalConstants constGlobalConstants = initGlobalConstants();
globalConstants initGlobalConstants(){ globalConstants initGlobalConstants(){
printf("%s",cryptdb_dir); // printf("%s",cryptdb_dir);
assert(cryptdb_dir != NULL); assert(cryptdb_dir != NULL);
assert(cryptdb_dir[0]=='/'); assert(cryptdb_dir[0]=='/');
std::string prefix = std::string(cryptdb_dir); std::string prefix = std::string(cryptdb_dir);
......
...@@ -8,13 +8,12 @@ added by et. all et related things. ...@@ -8,13 +8,12 @@ added by et. all et related things.
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
extern const char* cryptdb_dir;
extern const int gtoken;
struct globalConstants{ struct globalConstants{
int loadCount;/*used to limit the number of final_load*/ int loadCount;/*used to limit the number of final_load*/
}; };
extern const char* cryptdb_dir;
extern const int gtoken;
extern const globalConstants constGlobalConstants; extern const globalConstants constGlobalConstants;
globalConstants initGlobalConstants(); globalConstants initGlobalConstants();
...@@ -438,17 +438,22 @@ void load_num_file(std::string filename,std::vector<std::string> &res){ ...@@ -438,17 +438,22 @@ void load_num_file(std::string filename,std::vector<std::string> &res){
} }
infile.close(); infile.close();
} }
/*
void load_num_file(std::string filename,std::vector<Item> &res,enum_field_types intype){ void
load_num_file_count(std::string filename,
std::vector<std::string> &res,
int count) {
std::ifstream infile(filename); std::ifstream infile(filename);
std::string line; std::string line;
int localCount = 0;
while(std::getline(infile,line)){ while(std::getline(infile,line)){
res.pusb_back((void*)MySQLFieldTypeToItem(intype,line)); res.push_back(std::move(line));
localCount++;
if(localCount==count)
break;
} }
infile.close(); infile.close();
}*/ }
void load_string_file(std::string filename, std::vector<std::string> &res,unsigned long length){ void load_string_file(std::string filename, std::vector<std::string> &res,unsigned long length){
char *buf = new char[length]; char *buf = new char[length];
...@@ -457,20 +462,30 @@ void load_string_file(std::string filename, std::vector<std::string> &res,unsign ...@@ -457,20 +462,30 @@ void load_string_file(std::string filename, std::vector<std::string> &res,unsign
while(read(fd,buf,length)!=0){ while(read(fd,buf,length)!=0){
res.push_back(std::move(std::string(buf,length))); res.push_back(std::move(std::string(buf,length)));
} }
delete buf;
close(fd); close(fd);
} }
/*
void load_string_file(std::string filename,std::vector<void*> &res,unsigned long length,enum_field_types intype){ void
load_string_file_count(std::string filename,
std::vector<std::string> &res,
unsigned long length,
int count) {
char *buf = new char[length]; char *buf = new char[length];
int localCount=0;
int fd = open(filename.c_str(),O_RDONLY); int fd = open(filename.c_str(),O_RDONLY);
if(fd==-1) assert(0);//reading from -1 may cause errors if(fd==-1) assert(0);//reading from -1 may cause errors
while(read(fd,buf,length)!=0){ while(read(fd,buf,length)!=0){
res.push_back((void*)MySQLFieldTypeToItem(intype,std::string(buf,length))); res.push_back(std::move(std::string(buf,length)));
localCount++;
if(localCount==count)
break;
} }
delete buf;
close(fd); close(fd);
} }
*/
std::ostream& std::ostream&
insertManyValues(std::ostream &out,List<List_item> &newList){ insertManyValues(std::ostream &out,List<List_item> &newList){
......
...@@ -186,10 +186,17 @@ std::unique_ptr<Item> ...@@ -186,10 +186,17 @@ std::unique_ptr<Item>
getStringItem(std::string s); getStringItem(std::string s);
//Item* do not work void
//void load_num_file(std::string filename,std::vector<Item> &res,enum_field_types intype); load_num_file_count(std::string filename,
std::vector<std::string> &res,
int count);
void
load_string_file_count(std::string filename,
std::vector<std::string> &res,
unsigned long length,
int count);
//void load_string_file(std::string filename,std::vector<Item> &res,unsigned long length,enum_field_types intype);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment