void QueryEvaluator::evaluateQuery() {
	if (checkValid) {
		TNode * select_node = tree.getRoot();
		//select_node->printTNode();
		ResultManager result_manager = ResultManager(); 
		bool is_satisfied = true;

		int size = select_node->getNumChildren();
		// ignore result node and process with all clause node
		for (int i=1; i<size; i++) {
			TNode * clause_node = select_node->getChildAtIndex(i);
			vector<string> symbols = getSymbolsUsedBy(clause_node);
			ResultTable * temp_results = result_manager.extractTable(symbols);
			is_satisfied = evaluateClause(clause_node, temp_results);
			if (!is_satisfied) {
				break;
			} else {
				result_manager.insertTable(temp_results);
			}
			if (AbstractWrapper::GlobalStop) {
				vector<string> result;
				resultList.push_back(result);
			}
		}
		TNode * result_node = select_node->getChildAtIndex(0);
		vector<string> result = extractResult(result_node, &result_manager, is_satisfied);
		resultList.push_back(result);
	} else {
		vector<string> result = extractResult();
		resultList.push_back(result);
	}	
}
示例#2
0
文件: expr.c 项目: gleclaire/macross
  addressType
evaluateMswitch(void)
{
	addressType	pattern;

	pattern = evaluateExpression();
	while (*pc != END_TAG)
		if (evaluateClause(pattern))
			break;
	while (*pc != END_TAG)
		skipClause();
	overByte();
	return(0);
}
bool QueryEvaluator::evaluateClause(TNode * clause_node, ResultTable * temp_results) {
	bool is_satisfied = true;
	int size = temp_results->getSize();
	if (size==0) {
		// insert a dummy row into temp_results
		int symbol_num = temp_results->getSymbolSize();
		vector<int> dummy_values (symbol_num, -1);
		temp_results->insertValRow(dummy_values, false);
		size = 1;
	}
	for (int i=0; i<size; i++) {
		vector<int> row = temp_results->getValRow(i);
		vector<vector<int>> new_rows;
		is_satisfied = evaluateClause(clause_node, row, &new_rows, temp_results);
		if (is_satisfied) {
			temp_results->insertValRow(new_rows, true);
		}
	}
	temp_results->deleleInvalidRows();
	if (temp_results->getSymbolSize()==0) return is_satisfied;
	return (temp_results->getSize()!=0);
}