Пример #1
0
std::pair<int, std::string> KNRebuild::Run() throw(DatabaseRCException)
{	
	pair<int, string> res;	
	if(table_test->IsEmptyRCTable()) {
		res.first = 0;
		res.second = string("RC Table could not be read.");
		return res;
	}
	RCTable& rct = table_test->GetRCTable();
	RCAttr* rca = rct.GetAttr(column_number);
	char s[1024];
	try {		
		IBFile ib_f;
		if (rca->PackType() == PackN) {			
			sprintf(s, "%s.%d.%d.rsi", (knfolder_path + DIR_SEPARATOR_STRING + string("HIST")).c_str(), rct.GetID(), column_number);
			RSIndex_Hist kn;
			if(DoesFileExist(string(s)))
				ib_f.OpenReadOnly(string(s));
			else {
				res.first = 0;
				res.second = string("Histogram for column " + boost::lexical_cast<string>(column_number) + string(" not found."));
				return res;
			}
			kn.Load(&ib_f, rca->GetCurReadLocation());
			if(kn.NoObj()!=0 && (kn.GetFixed() != ATI::IsFixedNumericType(rca->TypeName()))) {
				res.first = 2;
				res.second = string("Value of RCAttr::fixed parameter in histogram is inconsistent with column type.");
				return res;
			} else {
				res.first = 1;
				res.second = string("");
				return res;
			}
		} else if(rca->PackType() == PackS) {
			res.first = 0;
			res.second = string("");
			return res;
		} else {
			res.first = 0;
			res.second = string("No KNs for column ") + string(rct.AttrName(column_number)) + string(" found.");
			return res;
		}
	} catch(DatabaseRCException& e) {
		res.first = 2;
		res.second = string("Error") + e.what();
		return res;
	}
	return res;		
}
Пример #2
0
std::pair<int, std::string> TestOfLookups::Run() throw(DatabaseRCException)
{
//	assert((table_test->rc_table)->IsLookup(column_number));
	pair<int, string> res;
	if(table_test->IsEmptyRCTable()) {
		res.first = 0;
		res.second = string("RC Table could not be read.");
		return res;
	}
	RCTable& rct = table_test->GetRCTable();
	RCAttr* rca = rct.GetAttr(column_number);
	try {
		if(rct.NoObj()==0) {
			res.first = 1;
			res.second = string("");
			return res;
		}
		rca->LoadLookupDictFromFile();
		switch (rca->dic->CheckConsistency()) {
		case 0:
			res.first = 1;
			res.second = string("");
			break;
		case 1:
			res.first = 2;
			res.second = string("Invalid lookup value length.");
			break;
		case 2:
			res.first = 2;
			res.second = string("Lookup values are not unique.");
			break;
		}
	} catch (...) {
		res.first = 2;
		res.second = string("Lookup dictionary of column ") + string(rct.AttrName(column_number)) + string(" could not be read.");
		return res;
	}

	return res;
}
std::pair<int, std::string> TestOfNoObjFirstColumnVsDelMask::Run() throw(DatabaseRCException)
{
	pair<int, string> res;
	RCAttr* rca;
	Filter& dm = table_test->GetDeleteMask();
	RCTable& rct = table_test->GetRCTable();
	int ex_dm = table_test->ExistsProperDelMaskInFolder();

	if(table_test->IsEmptyDelMask() || ex_dm==0) {
		res.first = 0;
		res.second = string("No delete mask found.");
		return res;
	}
	if(ex_dm==1) {
		res.first = 2;
		res.second = string("No proper file with delete mask found");
		return res;
	}

	if(table_test->IsEmptyRCTable()){
		res.first = 0;
		res.second = string("RC Table could not be read.");
		return res;
	}
	rca = rct.GetAttr(0);
	_int64 rcan = rca->NoObj();
	_int64 dmn = dm.NoObj();
	if(rcan == dmn){
		res.first = 1;
		res.second = string("");
	}
	else {
		res.first = 2;
		res.second = string("Inconsistent number of obj. in column file (") + boost::lexical_cast<string>(rcan) +
				string(") and in delete mask (") + boost::lexical_cast<string>(dmn) + string(")");
	}

	return res;
}
std::pair<int, std::string> TestOfKNsConsistencyLight::Run() throw(DatabaseRCException)
{	
	pair<int, string> res;	
	if(table_test->IsEmptyRCTable()) {
		res.first = 0;
		res.second = string("RC Table could not be read.");
		return res;
	}
	RCTable& rct = table_test->GetRCTable();
	RCAttr* rca = rct.GetAttr(column_number);
	string kn_type, kn_name;
	if (rca->PackType() == PackN){
		kn_type = string("HIST");
		kn_name = string("Histogram");
	} else {
		kn_type = string("CMAP");
		kn_name = string("CMap");
	}
	char s[1024];
	try {		
		IBFile ib_f;
		sprintf(s, (knfolder_path + DIR_SEPARATOR_CHAR + string("%s.%d.%d.rsi")).c_str(), kn_type.c_str(), rca->table_number, column_number);
		if(DoesFileExist(string(s))) {
			ib_f.OpenReadOnly(string(s));
			if(ib_f.Seek(0,SEEK_END)==0){
				res.first = 2;
				res.second = string(kn_name + string(" file is zero-length for this column."));
				return res;
			}
		}
		else {
			bool should_exist = false;
			if(rca->PackType() == PackN) {
				for(int p = 0; !should_exist && p < rca->NoPack(); p++)
					if (rca->GetNoNulls(p) < rca->GetNoValues(p) && rca->GetMinInt64(p) != rca->GetMaxInt64(p))
						should_exist = true;
			} else if (rca->PackType() == PackS && !RequiresUTFConversions(rca->Type().GetCollation())) {
				for(int p = 0; !should_exist && p < rca->NoPack(); p++)
					if (rca->GetNoNulls(p) < rca->GetNoValues(p))
						should_exist = true;
			}

			if (should_exist) {
				res.first = 0;
				res.second = kn_name + string(" for column " + boost::lexical_cast<string>(column_number) + string(" not found."));
				return res;
			} else {
				res.first = 1;
				res.second = string("");
				return res;
			}
		}

		if(rca->PackType() == PackN){			
			RSIndex_Hist kn;
			kn.Load(&ib_f, rca->GetCurReadLocation());
			// check consistency of number of objects in dpn vs kn 	
			// deprecated
			//if((kn->NoObj()!=0) && (rca->NoObj() < kn->NoObj())) {
			//	res.first = 3;
			//	res.second = string("Number of objects in ") + kn_name + string(" exceed number of objects in DPN.");
			//	return res;
			//}		
			if(kn.NoObj()!=0 &&
				( (!rct.IsLookup(column_number) && (ATI::IsFixedNumericType(rca->TypeName()) || ATI::IsDateTimeType(rca->TypeName())) != kn.GetFixed()) ||
					(rct.IsLookup(column_number) && kn.GetFixed() != 1) )) {
				res.first = 2;
				res.second = string("Value of RCAttr::fixed parameter in histogram is inconsistent with column type.");
				return res;
			}

		} else if (rca->PackType() == PackS) {
			RSIndex_CMap kn;
			kn.Load(&ib_f, rca->GetCurReadLocation());
			// check consistency of number of objects in dpn vs kn
			// deprecated
			//if((kn->NoObj()!=0) && (rca->NoObj() < kn->NoObj())) {
			//	res.first = 3;
			//	res.second = string("Number of objects in ") + kn_name + string(" exceed number of objects in DPN.");
			//	return res;
			//}		
		} else {
			res.first = 0;
			res.second = string("No KNs for column ") + string(rct.AttrName(column_number)) + string(" found.");
			return res;
		}

		res.first = 1;
		res.second = string("");
		return res;	

	} catch(DatabaseRCException&) {
		res.first = 2;
		res.second = kn_name + string(" file for column ") + string(rct.AttrName(column_number)) + string(" could not be read.");
		return res;
	}
	return res;		
}