Commit d6049088 authored by yiwenshao's avatar yiwenshao

able to limit count in final_load

parent 0df36de6
loadCount:1000000
loadCount:3
other:1
......@@ -14,6 +14,7 @@
#include "wrapper/reuse.hh"
#include "wrapper/common.hh"
#include "wrapper/insert_lib.hh"
#include "util/constants.hh"
using std::cout;
using std::cin;
using std::endl;
......@@ -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::vector<std::string> column;
if(IS_NUM(gfb.field_types[i])){
load_num_file(filename,column);
load_num_file_count(filename,column,constGlobalConstants.loadCount);
}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);
}
......
......@@ -8,7 +8,7 @@ const char *cryptdb_dir = getenv("CRYPTDB_DIR");
//assert(cryptdb_dir!=NULL);
const globalConstants constGlobalConstants = initGlobalConstants();
globalConstants initGlobalConstants(){
printf("%s",cryptdb_dir);
// printf("%s",cryptdb_dir);
assert(cryptdb_dir != NULL);
assert(cryptdb_dir[0]=='/');
std::string prefix = std::string(cryptdb_dir);
......
......@@ -8,13 +8,12 @@ added by et. all et related things.
#include <stdlib.h>
#include <stdio.h>
extern const char* cryptdb_dir;
extern const int gtoken;
struct globalConstants{
int loadCount;/*used to limit the number of final_load*/
};
extern const char* cryptdb_dir;
extern const int gtoken;
extern const globalConstants constGlobalConstants;
globalConstants initGlobalConstants();
......@@ -438,17 +438,22 @@ void load_num_file(std::string filename,std::vector<std::string> &res){
}
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::string line;
int localCount = 0;
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();
}*/
}
void load_string_file(std::string filename, std::vector<std::string> &res,unsigned long length){
char *buf = new char[length];
......@@ -457,20 +462,30 @@ void load_string_file(std::string filename, std::vector<std::string> &res,unsign
while(read(fd,buf,length)!=0){
res.push_back(std::move(std::string(buf,length)));
}
delete buf;
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];
int localCount=0;
int fd = open(filename.c_str(),O_RDONLY);
if(fd==-1) assert(0);//reading from -1 may cause errors
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);
}
*/
std::ostream&
insertManyValues(std::ostream &out,List<List_item> &newList){
......
......@@ -186,10 +186,17 @@ std::unique_ptr<Item>
getStringItem(std::string s);
//Item* do not work
//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);
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