/// Extract all subfunctions of the main conjunction, but depending only on the specified columns static void extractFunctions(ASTPtr expression, const NameSet & columns, std::vector<ASTPtr> & result) { const ASTFunction * function = typeid_cast<const ASTFunction *>(&*expression); if (function && function->name == "and") { for (size_t i = 0; i < function->arguments->children.size(); ++i) extractFunctions(function->arguments->children[i], columns, result); } else if (isValidFunction(expression, columns)) { result.push_back(expression->clone()); } }
/// Verifying that the function depends only on the specified columns static bool isValidFunction(ASTPtr expression, const NameSet & columns) { for (size_t i = 0; i < expression->children.size(); ++i) if (!isValidFunction(expression->children[i], columns)) return false; if (const ASTIdentifier * identifier = typeid_cast<const ASTIdentifier *>(&*expression)) { if (identifier->kind == ASTIdentifier::Kind::Column) return columns.count(identifier->name); } return true; }
void Aggregate::setFunction(unsigned func_idx, Function *func) { //Case the function index is invalid raises an error if(func_idx!=FINAL_FUNC && func_idx!=TRANSITION_FUNC) throw Exception(ERR_REF_FUNCTION_INV_TYPE,__PRETTY_FUNCTION__,__FILE__,__LINE__); //Checks if the function is valid, if not the case raises an error if(!isValidFunction(func_idx, func)) throw Exception(Exception::getErrorMessage(ERR_USING_INV_FUNC_CONFIG) .arg(Utf8String::create(this->getName())) .arg(BaseObject::getTypeName(OBJ_AGGREGATE)), ERR_USING_INV_FUNC_CONFIG,__PRETTY_FUNCTION__,__FILE__,__LINE__); functions[func_idx]=func; }