bool IsEqualTuples(Tuple tup1, Tuple tup2)
{
	if(tup1.isNull() || tup2.isNull()) return false;
	Schema schemat1 = tup1.getSchema();
	Schema schemat2 = tup2.getSchema();

	if(schemat1!=schemat2) return false;

	vector<string> field_names = schemat1.getFieldNames();

	vector<string>::iterator myiterator;

	for(myiterator = field_names.begin(); myiterator!=field_names.end(); myiterator++)
	{
		if(schemat1.getFieldType(*myiterator) == INT)
		{
			if(tup1.getField(*myiterator).integer != tup2.getField(*myiterator).integer)
				return false;
		}
		else
		{
			string val1 = *(tup1.getField(*myiterator).str);
			string val2 = *(tup2.getField(*myiterator).str);
			if(val1 != val2)
				return false;
		}
	}

	return true;
}
Example #2
0
//Compare two tuples
//Return true if equals else returns false
bool IsEqual(Tuple t1, Tuple t2)
{
	if(t1.isNull() || t2.isNull()) return false;
	Schema st1 = t1.getSchema();
	Schema st2 = t2.getSchema();
	
	if(st1!=st2) return false;

	vector<string> fieldNames = st1.getFieldNames();

	vector<string>::iterator iter;

	for(iter = fieldNames.begin(); iter!=fieldNames.end(); iter++)
	{
		if(st1.getFieldType(*iter) == INT)
		{
			if(t1.getField(*iter).integer != t2.getField(*iter).integer)
				return false;
		}
		else
		{
			string val1 = *(t1.getField(*iter).str);
			string val2 = *(t2.getField(*iter).str);
			if(val1 != val2)
				return false;
		}
	}

	return true;
}
void printTuple(Tuple tuple){
  // Print the information about the tuple
  cout << "Created a tuple " << tuple << " through the relation" << endl;
  cout << "The tuple is invalid? " << (tuple.isNull()?"TRUE":"FALSE") << endl;
  Schema tuple_schema = tuple.getSchema();
  cout << "The tuple has schema" << endl;
  cout << tuple_schema << endl;
  cout << "A block can allow at most " << tuple.getTuplesPerBlock() << " such tuples" << endl;
  
  cout << "The tuple has fields: " << endl;
  for (int i=0; i<tuple.getNumOfFields(); i++) {
    if (tuple_schema.getFieldType(i)==INT)
      cout << tuple.getField(i).integer << "\t";
    else
      cout << *(tuple.getField(i).str) << "\t";
  }
  cout << endl << endl;
}
bool Tuple_Comparison::operator()(Tuple& tuple1, Tuple& tuple2)
{
	if(tuple1.isNull() && tuple2.isNull())
		return false;
	if((!tuple1.isNull()) && tuple2.isNull())
		return true;
	if(tuple1.isNull() && (!tuple2.isNull()))
		return false;

	vector<string>::iterator start = field_names.begin();
	vector<string>::iterator stop = field_names.end();
	vector<string>::iterator index;
	Schema schema_tuple1 = tuple1.getSchema();
	Schema schema_tuple2 = tuple2.getSchema();

//	cout<< "comparing "<<tuple1<<"  "<<tuple2<<endl;
	if(schema_tuple1 != schema_tuple2)
		throw string("Error!! Tuple comparison failed - Tuple_Comparison::operator()");

	for(index = start; index!=stop; index++)
	{
		string column_name = *index;
		FIELD_TYPE field_type = schema_tuple1.getFieldType(column_name);
		if(field_type == INT)
		{
			int value1, value2;
			value1 = tuple1.getField(column_name).integer;
			value2 = tuple2.getField(column_name).integer;
			if(value1 != value2)
				return value1<value2;
		}
		else //FIELD_TYPE == STR20
		{
			string value1, value2;
			value1 = *(tuple1.getField(column_name).str);
			value2 =  *(tuple2.getField(column_name).str);
			if(value1.compare(value2) < 0) return true;
			else if(value1.compare(value2) > 0) return false;

		}
	}
	return false;
}
Example #5
0
bool CompareTuple::operator()(Tuple& first, Tuple& second)
{
	if(first.isNull() && second.isNull())
		return false;
	if((!first.isNull()) && second.isNull())
		return true;
	if(first.isNull() && (!second.isNull()))
		return false;

	vector<string>::iterator beg = fieldNames.begin();
	vector<string>::iterator end = fieldNames.end();
	vector<string>::iterator i;
	Schema tupleSchemaOne = first.getSchema();
	Schema tupleSchemaTwo = second.getSchema();

//	cout<< "comparing "<<first<<"  "<<second<<endl;
	if(tupleSchemaOne != tupleSchemaTwo)
		throw string("Tuple Schema Comparision Error!!!! - In PUtility::ComapreTuple::Opeartor()");
		
	for(i = beg; i!=end; i++)
	{
		string colName = *i;
		FIELD_TYPE ftype = tupleSchemaOne.getFieldType(colName);
		if(ftype == INT)
		{
			int firstVal, secVal;
			firstVal = first.getField(colName).integer;
			secVal = second.getField(colName).integer;
			if(firstVal != secVal)
				return firstVal<secVal;
		}
		else //FIELD_TYPE == STR20
		{
			string firstVal, secVal;
			firstVal = *(first.getField(colName).str); 
			secVal =  *(second.getField(colName).str);
			if(firstVal.compare(secVal) < 0) return true;
			else if(firstVal.compare(secVal) > 0) return false;
			//else == 0, continue comparing next tuple
		}
	}
	return false;
}