当前位置: 首页>>代码示例>>C++>>正文


C++ Tuple::setField方法代码示例

本文整理汇总了C++中Tuple::setField方法的典型用法代码示例。如果您正苦于以下问题:C++ Tuple::setField方法的具体用法?C++ Tuple::setField怎么用?C++ Tuple::setField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tuple的用法示例。


在下文中一共展示了Tuple::setField方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addTupleToBlock

/*
void addTupleToBlock(Tuple tuple, MainMemory &mem) {
  //===================Block=============================
  cout << "===================Block=============================" << endl;
   
  // Set up a block in the memory
//  cout << "Clear the memory block 0" << endl;
//  Block* block_ptr=mem.getBlock(0); //access to memory block 0
//  block_ptr->clear(); //clear the block
	

  
  // A block stores at most 2 tuples in this case
  // -----------first tuple-----------
  cout << "Set the tuple at offset 0 of the memory block 0" << endl;
  block_ptr->setTuple(0,tuple); // You can also use appendTuple()
  cout << "Now the memory block 0 contains:" << endl;
  cout << *block_ptr << endl;

  cout << "The block is full? " << (block_ptr->isFull()==1?"true":"false") << endl;
  cout << "The block currently has " << block_ptr->getNumTuples() << " tuples" << endl;
  cout << "The tuple at offset 0 of the block is:" << endl;
  cout << block_ptr->getTuple(0) << endl << endl;
  
  return;
}
*/
void processInsert(string line, vector<string> cmdStr, SchemaManager schema_manager,
  MainMemory &mem) {
  
  string tableName = cmdStr[2];
  Relation* relation_ptr = schema_manager.getRelation(tableName);
  cout << "Inside the INSERT function" << endl;
  int memory_block_index=0;
  //====================Tuple=============================
  cout << "====================Tuple=============================" << endl;
  // Set up the first tuple
  Tuple tuple = relation_ptr->createTuple(); //The only way to create a tuple is to call "Relation"
  printRelation(relation_ptr);
  vector<string> insertStr = splitString(line, "\()");
  vector<string> attr = splitString(insertStr[1], ", ");
  vector<string> val = splitString(insertStr[3], ", ");
/* TODO commented unordered insert giving errors
  for (int i = 0; i < attr.size(); i++)
  {
	if (tuple.getSchema().getFieldType(i)==INT){
	  cout << "Errored?? " << endl;
	  tuple.setField(attr[i], atoi(val[i].c_str()));
	}
	else{
	  tuple.setField(attr[i], val[i]);
	}
  }
*/
  for (int i = 0; i < attr.size(); i++)
  {
    //cout << "HAHAHHAHHA " << tuple.getField(attr[i])[0] << endl << endl;
    if (tuple.getSchema().getFieldType(attr[i])==INT){
	//if (tuple.getField(attr[i])==INT){
	  cout << "Errored?? " << endl;
	  tuple.setField(attr[i], atoi(val[i].c_str()));
	}
	else{
	  tuple.setField(attr[i], val[i]);
	}
  }
  // TODO to send file
  //see that tuple was properly filled
  printTuple(tuple);
  cout << "My test function on blocks " << endl;
  memory_block_index = findBlockForTuple(mem);
  appendTupleToRelation(relation_ptr, mem, memory_block_index, tuple);
  //addTupleToBlock(tuple, mem);
  cout << "After insertion of tuble now the reation stuff is " << endl;
  printRelation(relation_ptr);
  
  // Now write the tuple in a Disk Block.
  
/*
  vector<string>::iterator it;
  cout << "Printing new things" << endl;
  for(it=str.begin(); it!=str.end(); ++it) {
    cout << *it << endl;
  }
*/
  return;
}
开发者ID:cjb3768,项目名称:CSCE-608-Project-2,代码行数:87,代码来源:working_11_13.cpp

示例2: 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;
}
开发者ID:ravitx,项目名称:608,代码行数:44,代码来源:core.cpp

示例3: processInsert

void processInsert(string line, vector<string> cmdStr, SchemaManager schema_manager,
  MainMemory &mem) {
  
  string tableName = cmdStr[2];
  Relation* relation_ptr = schema_manager.getRelation(tableName);
  cout << "Inside the INSERT function" << endl;
  
  //====================Tuple=============================
  cout << "====================Tuple=============================" << endl;
  // Set up the first tuple
  Tuple tuple = relation_ptr->createTuple(); //The only way to create a tuple is to call "Relation"
  //printRelation(relation_ptr);
  vector<string> insertStr = splitString(line, "\()");
  vector<string> attr = splitString(insertStr[1], ", ");
  vector<string> val = splitString(insertStr[3], ", ");

  for (int i = 0; i < attr.size(); i++)
  {
	if (tuple.getSchema().getFieldType(i)==INT){
	  tuple.setField(attr[i], atoi(val[i].c_str()));
	}
	else{
	  tuple.setField(attr[i], val[i]);
	}
  }
  //see that tuple was properly filled
  printTuple(tuple);
  
  // Now write the tuple in a Disk Block.
  
/*
  vector<string>::iterator it;
  cout << "Printing new things" << endl;
  for(it=str.begin(); it!=str.end(); ++it) {
    cout << *it << endl;
  }
*/
  return;
}
开发者ID:cjb3768,项目名称:CSCE-608-Project-2,代码行数:39,代码来源:last_working.cpp

示例4: 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);
	}
}
开发者ID:ravitx,项目名称:608,代码行数:42,代码来源:core.cpp

示例5: if


//.........这里部分代码省略.........
	i1 = j1 = 1;
	bool done = false;
	int block_id, tuple_offset;
	while(!done)
	{

		vector<Tuple> tuples_r1 = mem.getTuples(0, num_sublists_r1);
		vector<Tuple> tuples_r2 = mem.getTuples(num_sublists_r1, num_sublists_r2);

			Tuple tuple = rptr3->createTuple();
			int rel_no = 0;
			int id = findSmallest(tuples_r1, tuples_r2, fields1, fields2, rel_no);
			if(disp)
				cout<<"id: "<<id<<"rel: "<<rel_no<<endl;
			if(rel_no == 1)
			{
				if(disp)
					cout<<"Smallest Tuple: "<<tuples_r1[id]<<endl;
		

				for(m = 0; m < tuples_r2.size(); m++)
				{
					if(isJoinTuple(tuples_r1[id], tuples_r2[m], fields1, fields2, op))
					{
					if(disp)
					{
						cout<<"\n********************\nJoining:"<<endl;
						cout<<tuples_r1[id]<<endl;
						cout<<tuples_r2[m]<<endl;
					}
					for(int l =0; l < fields_r1.size(); l++)
						{
							if(s3.getFieldType(rptr1->getRelationName() + "." + fields_r1[l]) == INT)
								tuple.setField(rptr1->getRelationName() + "." + fields_r1[l],tuples_r1[id].getField(fields_r1[l]).integer);
							else
								tuple.setField(rptr1->getRelationName() + "." + fields_r1[l],*(tuples_r1[id].getField(fields_r1[l]).str));
						}
						for(int l =0; l < fields_r2.size(); l++)
						{	
							int flag = 1;
							for(int n = 0; n < op.size(); n++)
							{								
								if(op[n] == "=" && fields_r2[l].compare(fields2[n]) == 0)
								{
									flag = 0;
									break;
								}
							}
							if(flag)
							{
								if(s3.getFieldType(rptr2->getRelationName() + "." + fields_r2[l]) == INT)
									tuple.setField(rptr2->getRelationName() + "." + fields_r2[l],tuples_r2[m].getField(fields_r2[l]).integer);
								else
									tuple.setField(rptr2->getRelationName() + "." + fields_r2[l],*(tuples_r2[m].getField(fields_r2[l]).str));
							}	
						}

						if(disp)
							cout<<"New Tuple:"<<tuple<<endl;

						tuples_r3.push_back(tuple);
						block_r3->appendTuple(tuple);
						//If main memory block is full, write it to disk and clear that block
						if(tuples_r3.size() == s3.getTuplesPerBlock())
						{
							rptr3->setBlock(rptr3->getNumOfBlocks(),max_blocks - 1);
开发者ID:v33n,项目名称:tinysql,代码行数:67,代码来源:Join.cpp

示例6:

Relation *onePassNaturalJoin(Relation *rptr1, Relation *rptr2, string r3, vector<string> fields1, vector<string> fields2, vector<string> op, string r1_name, string r2_name)
{
	Schema s1, s2;
	bool flag = 1;
	vector <string> fields_r1, fields_r2, fields_r3;
	vector <enum FIELD_TYPE> types_r3;
	
	//Relation *rptr1, *rptr2;
	vector<string> values_r3;
	int num_blocks_r1, num_blocks_r2;
	num_blocks_r1 = rptr1->getNumOfBlocks();
	num_blocks_r2 = rptr2->getNumOfBlocks();

	s1 = rptr1->getSchema();
	s2 = rptr2->getSchema();
	fields_r1 = s1.getFieldNames();
	fields_r2 = s2.getFieldNames();

	for(int i=0; i<fields_r1.size(); i++){			
		fields_r3.push_back(r1_name + "." + fields_r1[i]);
		types_r3.push_back(s1.getFieldType(fields_r1[i]));
	}	

	//Find common attributes of both relations
	for(int i=0; i<fields_r2.size(); i++)
	{
		flag = 1;
		for(int k=0; k<op.size(); k++)
		{
			if(op[k] == "=" && fields_r2[i] == fields2[k] )
			{
				flag = 0;
				break;
			}
		}	
		if(flag)
		{
			fields_r3.push_back(r2_name + "." + fields_r2[i]);
			types_r3.push_back(s2.getFieldType(fields_r2[i]));
		}	
	}

	Schema s3(fields_r3,types_r3);
	//string r3 = rptr1->getRelationName() + "." + rptr2->getRelationName() + ".NaturalJoin";
	Relation *rptr3 = schema_manager.createRelation(r3, s3);

	if(disp)
	{
		displayRelationInfo(rptr3);
		cout<<s3<<endl;
	}

	//Get tuples of smaller relation into Main Memory, assuming all can fit in
	if( num_blocks_r1 > num_blocks_r2 ) 
	{
		rptr2->getBlocks(0, 0, num_blocks_r2);
		vector<Tuple> tuples_r3, tuples_r2 = mem.getTuples(0, num_blocks_r2);
	
		//Read one block of relation into Main memory and combine each tuple in the block
		//with all the tuples in the other
		Block *block_r1 = mem.getBlock(num_blocks_r2);
		Block *block_r3 = mem.getBlock(num_blocks_r2 + 1);
   	   	block_r3->clear();    
		for(int i=0; i<num_blocks_r1; i++)
		{				
	  		block_r1->clear();    
		    rptr1->getBlock(i, num_blocks_r2);
  			vector<Tuple> tuples_r1 = block_r1->getTuples();

			for(int j =0; j < tuples_r1.size(); j++)
			{
				//Check for holes
				if(tuples_r1[j].isNull())
					continue;
				for(int k=0; k < tuples_r2.size(); k++)
				{
					//Check for holes
					if(tuples_r2[k].isNull())
						continue;
					Tuple tuple = rptr3->createTuple();
					if(isJoinTuple(tuples_r1[j], tuples_r2[k], fields1, fields2, op))
					{
						for(int l =0; l < fields_r1.size(); l++)
						{
							if(s3.getFieldType(r1_name + "." + fields_r1[l]) == INT)
								tuple.setField(r1_name + "." + fields_r1[l],tuples_r1[j].getField(fields_r1[l]).integer);
							else
								tuple.setField(r1_name + "." + fields_r1[l],*(tuples_r1[j].getField(fields_r1[l]).str));
						}
	
						for(int l =0; l < fields_r2.size(); l++)
						{
							flag = 1;
							for(int m = 0; m < op.size(); m++)
							{
								if(op[m] == "=" && fields_r2[l].compare(fields2[m]) == 0)
								{
									flag = 0;
									break;
								}
//.........这里部分代码省略.........
开发者ID:v33n,项目名称:tinysql,代码行数:101,代码来源:Join.cpp

示例7: Insert

Relation* Insert(vector<string> &words, string &line, SchemaManager &schema_manager, MainMemory &mem){
	Relation* relation_ptr = schema_manager.getRelation(words[2]);

	vector<string>::iterator it = find(words.begin(), words.end(), "SELECT");
	// no select
	if (it == words.end()){
		// get insert vals
		vector<string> content = splitBy(line, "()");
		vector<string> fields = splitBy(content[1], ", ");
		vector<string> vals = splitBy(content[3], ",");
		//preProcess(vector<string>(1, words[2]), fields, schema_manager);
		preProcess(vector<string>(1, words[2]), vals, schema_manager);

		assert(fields.size() == vals.size());

		Tuple tuple = relation_ptr->createTuple();

		// standard insert doesn't have table names
		vector<string> col_names = nakedFieldNames(relation_ptr);

		// comparing 
		for (int i = 0; i < fields.size(); i++){
			for (int j = 0; j < col_names.size(); j++){
				// this is a match
				if (fields[i] == col_names[j]){
					if (tuple.getSchema().getFieldType(j) == INT){
						tuple.setField(j, atoi(vals[i].c_str()));
					}
					else{
						tuple.setField(j, vals[i]);
					}
					break;
				}
			}
		}
		appendTupleToRelation(relation_ptr, mem, tuple);
	}
	// with SELECT
	else{
		vector<string> SFW(it, words.end());	
		Relation* new_relation = Select(SFW, schema_manager, mem);
		assert(new_relation);

		vector<string> new_field_names = nakedFieldNames(new_relation);
		vector<string> field_names = nakedFieldNames(relation_ptr);

		// mapping: index of new_field_names to field_names 
		vector<int> mapping(new_field_names.size(), -1);
		for (int i = 0; i < new_field_names.size(); i++){
			for (int j = 0; j < field_names.size(); j++){
				if (new_field_names[i] == field_names[j]){
					mapping[i] = j;
					break;
				}
			}
		}

		int new_field_size = new_relation->getSchema().getNumOfFields();

		// warning: new_relation and relation_ptr might be the same!
		// get all tuples from the new_relation in one run
		vector<Tuple> new_tuples;
		for (int i = 0; i < new_relation->getNumOfBlocks(); i++){

			assert(!free_blocks.empty());
			int memory_block_index = free_blocks.front();
			free_blocks.pop();

			// read the relation block by block
			new_relation->getBlock(i, memory_block_index);
			Block* block_ptr = mem.getBlock(memory_block_index);
			assert(block_ptr);
			vector<Tuple> block_tuples = block_ptr->getTuples();
			new_tuples.insert(new_tuples.end(), block_tuples.begin(), block_tuples.end());
			if(new_tuples.empty()){
				cerr<<"Warning: Insert from SFW, No tuples in the current mem block!"<<endl;
			}
			free_blocks.push(memory_block_index);
		}

		for (int j = 0; j < new_tuples.size(); j++){
			Tuple tuple = relation_ptr->createTuple();
			for (int k = 0; k < new_field_size; k++){
				if (mapping[k] != -1){
					int idx = mapping[k];
					assert(idx < relation_ptr->getSchema().getNumOfFields() && idx >= 0);
					if (tuple.getSchema().getFieldType(idx) == INT){
						int val = new_tuples[j].getField(k).integer;
						tuple.setField(field_names[idx], val);
					}
					else{
						string *str = new_tuples[j].getField(k).str;
						tuple.setField(field_names[idx], *str);
					}
				}
			}
			appendTupleToRelation(relation_ptr, mem, tuple);
		}
		cout<<*relation_ptr<<endl;
	}
//.........这里部分代码省略.........
开发者ID:tonywang1990,项目名称:TinySQL-implementation,代码行数:101,代码来源:query.cpp

示例8: string


//.........这里部分代码省略.........
			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{
				/* empty results */
				return ret; 
			}
		}else{
			Qexpression *optimized = output_s.top()->optimize_sigma(&sigma_operation) ;
开发者ID:xvxiaopei,项目名称:Database,代码行数:67,代码来源:main.cpp

示例9: 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;
}
开发者ID:ravitx,项目名称:608,代码行数:62,代码来源:core.cpp


注:本文中的Tuple::setField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。