GroupExpression *Memo::InsertExpression(std::shared_ptr<GroupExpression> gexpr, GroupID target_group, bool enforced) { // If leaf, then just return if (gexpr->Op().GetType() == OpType::Leaf) { const LeafOperator *leaf = gexpr->Op().As<LeafOperator>(); PELOTON_ASSERT(target_group == UNDEFINED_GROUP || target_group == leaf->origin_group); gexpr->SetGroupID(leaf->origin_group); return nullptr; } // Lookup in hash table auto it = group_expressions_.find(gexpr.get()); if (it != group_expressions_.end()) { gexpr->SetGroupID((*it)->GetGroupID()); return *it; } else { group_expressions_.insert(gexpr.get()); // New expression, so try to insert into an existing group or // create a new group if none specified GroupID group_id; if (target_group == UNDEFINED_GROUP) { group_id = AddNewGroup(gexpr); } else { group_id = target_group; } Group *group = GetGroupByID(group_id); group->AddExpression(gexpr, enforced); return gexpr.get(); } }
GroupID Memo::AddNewGroup(std::shared_ptr<GroupExpression> gexpr) { GroupID new_group_id = groups_.size(); // Find out the table alias that this group represents std::unordered_set<std::string> table_aliases; auto op_type = gexpr->Op().GetType(); if (op_type == OpType::Get) { // For base group, the table alias can get directly from logical get const LogicalGet *logical_get = gexpr->Op().As<LogicalGet>(); table_aliases.insert(logical_get->table_alias); } else if (op_type == OpType::LogicalQueryDerivedGet) { const LogicalQueryDerivedGet *query_get = gexpr->Op().As<LogicalQueryDerivedGet>(); table_aliases.insert(query_get->table_alias); } else { // For other groups, need to aggregate the table alias from children for (auto child_group_id : gexpr->GetChildGroupIDs()) { Group *child_group = GetGroupByID(child_group_id); for (auto &table_alias : child_group->GetTableAliases()) { table_aliases.insert(table_alias); } } } groups_.emplace_back( new Group(new_group_id, std::move(table_aliases))); return new_group_id; }
bool Memo::InsertExpression(std::shared_ptr<GroupExpression> gexpr, GroupID target_group) { // If leaf, then just return if (gexpr->Op().type() == OpType::Leaf) { const LeafOperator *leaf = gexpr->Op().as<LeafOperator>(); assert(target_group == UNDEFINED_GROUP || target_group == leaf->origin_group); gexpr->SetGroupID(leaf->origin_group); return false; } // Lookup in hash table auto it = group_expressions.find(gexpr.get()); bool new_expression; if (it != group_expressions.end()) { new_expression = false; assert(target_group == UNDEFINED_GROUP || target_group == (*it)->GetGroupID()); gexpr->SetGroupID((*it)->GetGroupID()); } else { new_expression = true; group_expressions.insert(gexpr.get()); // New expression, so try to insert into an existing group or // create a new group if none specified GroupID group_id; if (target_group == UNDEFINED_GROUP) { group_id = AddNewGroup(); } else { group_id = target_group; } Group *group = GetGroupByID(group_id); group->AddExpression(gexpr); } return new_expression; }
VOID CBeikeSafeSoftmgrNecessHandler::GenerateSoftList( int nId ) { BOOL bFreeChecked = m_pMainDlg->GetItemCheck(IDC_SOFT_NECESS_SHOW_FREE_SOFT); BOOL bPlugChecked = m_pMainDlg->GetItemCheck(IDC_SOFT_NECESS_SHOW_NOPLUG_SOFT); m_arrRightList.RemoveAll(); if (m_arrNecess.GetSize() <= nId) return; BOOL bQuerySoft = FALSE; NECESS_GROUP& groupInfo = GetGroupByID(nId); for ( int i=0; i < groupInfo.typeList.GetSize(); i++ ) { NECESS_SOFT_LIST_DATA datax; NECESS_TYPE& typeInfo = groupInfo.typeList[i]; BOOL bPushType = FALSE; datax.bTitle = TRUE; datax.strTitleName = typeInfo.strTypeName; for ( int kk=0; kk < typeInfo.softList.GetSize(); kk++) { NECESS_SOFT& softInfo = typeInfo.softList[kk]; NECESS_SOFT_LIST_DATA datasoft; CSoftListItemData* pSoftData = GetSoftDataByIDFromMap(softInfo.strSoftID); BOOL bCanInsert = FALSE; if (pSoftData!=NULL) { if( bPlugChecked && bFreeChecked ) { if ( !pSoftData->m_bCharge && !pSoftData->m_bPlug ) bCanInsert = TRUE; } else if ( bPlugChecked && !bFreeChecked ) { if ( !pSoftData->m_bPlug ) bCanInsert = TRUE; } else if ( !bPlugChecked && bFreeChecked ) { if ( !pSoftData->m_bCharge ) bCanInsert = TRUE; } else bCanInsert = TRUE; if (bCanInsert) { if (!bPushType) { bPushType = TRUE; m_arrRightList.Add(datax); } datasoft.bTitle = FALSE; datasoft.strSoftId = softInfo.strSoftID; m_arrRightList.Add(datasoft); if ( m_pSoftMgrMainUI->m_pInfoQuery ) { CSoftListItemData* pData = GetSoftDataByID(datasoft.strSoftId); if ( pData && pData->m_fMark == 0 ) { m_pSoftMgrMainUI->m_pInfoQuery->AddSoft( _ttoi(datasoft.strSoftId) ); bQuerySoft = TRUE; } } } } } } if (bQuerySoft) { m_pSoftMgrMainUI->m_pInfoQuery->Query(); } }