本文整理汇总了C++中Relation::createTuple方法的典型用法代码示例。如果您正苦于以下问题:C++ Relation::createTuple方法的具体用法?C++ Relation::createTuple怎么用?C++ Relation::createTuple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Relation
的用法示例。
在下文中一共展示了Relation::createTuple方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertIntoTable
void insertIntoTable(string tableName, vector<string> fieldNames, vector<string> fieldValues) {
if(!schemaManager.relationExists(tableName)) {
cout<<"Illegal Tablename"<<endl;
return;
}
Relation *relation = schemaManager.getRelation(tableName);
Tuple tuple = relation->createTuple();
Schema schema = relation->getSchema();
vector<string>::iterator it,it1;
for(it = fieldNames.begin(),it1 = fieldValues.begin();it!=fieldNames.end();it++, it1++) {
string str=*it,str1=*it1;
str = removeSpaces(str);
int type = schema.getFieldType(str);
if(!type) {
str1 = removeSpaces(str1);
if(isNumber(str1)) {
tuple.setField(str,stoi(str1));
}
else {
cout<<"Data type is not supported\n";
return;
}
}
else {
regex exp("\\ *\"(.*)\"");
cmatch match;
if(regex_match(str1.c_str(),match,exp)) {
str1 = match[1];
if(str1.length()>20) {
cout<<"Data type is not supported\n";
return;
}
else tuple.setField(str,str1);
}
else {
cout<<"Data type is not supported\n";
return;
}
}
}
insertTuple(tableName, tuple);
cout<<disk.getDiskIOs()<<endl;
}
示例2: join
void join(Tuple tuple1, Tuple tuple2, string tableName1, string tableName2, string whereCondition, bool multi, vector<string> attributes) {
Relation *relation = schemaManager.getRelation(tableName2+"_join");
Tuple tuple =relation->createTuple();
if(!multi) {
for(int i=0;i<tuple1.getNumOfFields();i++) {
if(tuple1.getSchema().getFieldType(i) == INT)
tuple.setField(tableName1+"."+tuple1.getSchema().getFieldName(i), tuple1.getField(i).integer);
else
tuple.setField(tableName1+"."+tuple1.getSchema().getFieldName(i), *(tuple1.getField(i).str) );
}
}
else {
for(int i=0;i<tuple1.getNumOfFields();i++) {
if(tuple1.getSchema().getFieldType(i) == INT)
tuple.setField(tuple1.getSchema().getFieldName(i), tuple1.getField(i).integer);
else
tuple.setField(tuple1.getSchema().getFieldName(i), *(tuple1.getField(i).str) );
}
}
for(int i=0;i<tuple2.getNumOfFields();i++) {
if(tuple2.getSchema().getFieldType(i) == INT)
tuple.setField(tableName2+"."+tuple2.getSchema().getFieldName(i), tuple2.getField(i).integer);
else
tuple.setField(tableName2+"."+tuple2.getSchema().getFieldName(i), *(tuple2.getField(i).str) );
}
if((attributes.size()==1 && attributes[0]=="*") || multi) {
if(whereConditionEvaluator(whereCondition, tuple))
insertTuple(tableName2+"_join", tuple);
}
else {
Relation *relation1 = schemaManager.getRelation(tableName2+"_joinp");
Tuple tuplep = relation1->createTuple();
for(int i=0;i<attributes.size();i++) {
if(tuplep.getSchema().getFieldType(attributes[i]) == INT)
tuplep.setField(attributes[i], tuple.getField(attributes[i]).integer);
else
tuplep.setField(attributes[i], *(tuple.getField(attributes[i]).str));
}
if(whereConditionEvaluator(whereCondition, tuple))
insertTuple(tableName2+"_joinp", tuplep);
}
}
示例3: string
//.........这里部分代码省略.........
if(table_name != NULL) { (*table_name ) = string( this->info[0] ) ;}
if(temp.size() != 0){
Schema s = temp[0].getSchema() ;
vector<string> field_names ;
vector<enum FIELD_TYPE> field_types ;
for(vector<string>::iterator it= this->info.begin(); it != this->info.end(); it++){
unsigned long found = it->rfind('.') ;
string s_table ;
if(found == std::string::npos){
s_table = string( table_n + "." + (*it) ) ;
}else{
s_table = string( it->substr( it->rfind('.') + 1 ) ) ;
}
if( s.fieldNameExists( *it ) ){
field_names.push_back(string(*it) ) ;
field_types.push_back(s.getFieldType( *it) ) ;
}else{
if(s.fieldNameExists(s_table) ) {
field_names.push_back(string( s_table ) ) ;
field_types.push_back( s.getFieldType( s_table ) );
} else{
perror( "exec: No such field");
}
}
}
string temp_table_name = "temp_table" ;
Relation *rlt = NULL;
while(p->schema_manager.relationExists(temp_table_name) ){
temp_table_name += "-a" ;
}
rlt = p->CreateTable(temp_table_name, field_names, field_types) ;
temp_relations.push_back(temp_table_name ) ;
for(vector<Tuple>::iterator tit = temp.begin(); tit != temp.end(); tit++){
Tuple t = rlt->createTuple() ;
for(vector<string>::iterator it = field_names.begin(); it != field_names.end() ; it++){
union Field f= tit->getField(*it) ;
if( s.getFieldType(*it) == INT ){
t.setField( *it, f.integer ) ;
}else{
t.setField( *it, *(f.str)) ;
}
}
ret.push_back( t ) ;
}
}else{
return ret;
}
}else if(this->type == PRODUCT){
vector<string> ptables;
vector<Relation *> relations ;
map<string, Qexpression *> sigma_operation ;
vector<string> commons ;
map<string, bool> joined_keys;
vector<string>::iterator it = ptables.begin();
ptables.insert(ptables.end(), this->info.begin(), this->info.end() );
if(output_s.empty() ){
}else if(output_s.top()->type == INTEGER || output_s.top()->type == LITERAL ){
Tuple *t = NULL;
if(output_s.top()->judge(*t) ){
/* WHERE clasuse always true */
while(! output_s.empty() ){ output_s.top()->free() ;output_s.pop();}
}else{
示例4: projection
string projection(vector<string> attributes, string tableName, string whereCondition) {
Relation *relation = schemaManager.getRelation(tableName);
Schema tableSchema = relation->getSchema();
vector<string> fieldNames;
vector<enum FIELD_TYPE> fieldTypes;
vector<string>::iterator it;
int flag=-1;
bool print=true;
for(it=attributes.begin();it!=attributes.end();it++) {
for(int i=0;i<tableSchema.getNumOfFields();i++) {
string temp = *it;
if(tableSchema.getFieldName(i)==temp || tableName+"."+tableSchema.getFieldName(i) == temp)
flag=i;
}
if(flag!=-1) {
fieldNames.push_back(tableSchema.getFieldName(flag));
fieldTypes.push_back(tableSchema.getFieldType(flag));
flag = -1;
}
}
if(attributes.size()==1 && attributes[0] == "*") {
if(whereCondition.empty()) return tableName;
fieldNames = tableSchema.getFieldNames();
fieldTypes = tableSchema.getFieldTypes();
}
Schema dupSchema(fieldNames,fieldTypes);
Relation *relationDup = schemaManager.createRelation(tableName.append("_dup"), dupSchema);
Tuple tuple = relationDup->createTuple();
vector<Tuple>::iterator it1;
Block *block = mainMemory.getBlock(9);
block->clear();
int index=0;
for(int i=0;i<relation->getNumOfBlocks();i++) {
relation->getBlock(i,0);
vector<Tuple> t = mainMemory.getBlock(0)->getTuples();
for(it1=t.begin();it1!=t.end();it1++) {
if(!it1->isNull()){
for(int j=0;j<fieldNames.size();j++) {
if(fieldTypes[j]==INT)
tuple.setField(fieldNames[j],it1->getField(fieldNames[j]).integer);
else
tuple.setField(fieldNames[j],*(it1->getField(fieldNames[j]).str));
}
bool ttp = whereConditionEvaluator(whereCondition, *it1);
if(ttp) {
if(!block->isFull())
block->appendTuple(tuple);
else {
relationDup->setBlock(index,9);
index++;
block->clear();
block->appendTuple(tuple);
}
}
}
}
}
if(index!=relationDup->getNumOfBlocks()-1)
relationDup->setBlock(index, 9);
return tableName;
}