MaterializedViewMetadata::MaterializedViewMetadata( PersistentTable *srcTable, PersistentTable *destTable, catalog::MaterializedViewInfo *metadata) : m_target(destTable), m_filterPredicate(NULL) { // try to load the predicate from the catalog view parsePredicate(metadata); // set up the group by columns from the catalog info m_groupByColumnCount = metadata->groupbycols().size(); m_groupByColumns = new int32_t[m_groupByColumnCount]; std::map<std::string, catalog::ColumnRef*>::const_iterator colRefIterator; for (colRefIterator = metadata->groupbycols().begin(); colRefIterator != metadata->groupbycols().end(); colRefIterator++) { int32_t grouping_order_offset = colRefIterator->second->index(); m_groupByColumns[grouping_order_offset] = colRefIterator->second->column()->index(); } // set up the mapping from input col to output col m_outputColumnCount = metadata->dest()->columns().size(); m_outputColumnSrcTableIndexes = new int32_t[m_outputColumnCount]; m_outputColumnAggTypes = new ExpressionType[m_outputColumnCount]; std::map<std::string, catalog::Column*>::const_iterator colIterator; // iterate the source table for (colIterator = metadata->dest()->columns().begin(); colIterator != metadata->dest()->columns().end(); colIterator++) { const catalog::Column *destCol = colIterator->second; int destIndex = destCol->index(); const catalog::Column *srcCol = destCol->matviewsource(); if (srcCol) { m_outputColumnSrcTableIndexes[destIndex] = srcCol->index(); m_outputColumnAggTypes[destIndex] = static_cast<ExpressionType>(destCol->aggregatetype()); } else { m_outputColumnSrcTableIndexes[destIndex] = -1; m_outputColumnAggTypes[destIndex] = EXPRESSION_TYPE_INVALID; } } m_index = m_target->primaryKeyIndex(); m_searchKey = TableTuple(m_index->getKeySchema()); m_searchKeyBackingStore = new char[m_index->getKeySchema()->tupleLength() + 1]; memset(m_searchKeyBackingStore, 0, m_index->getKeySchema()->tupleLength() + 1); m_searchKey.move(m_searchKeyBackingStore); m_existingTuple = TableTuple(m_target->schema()); m_updatedTuple = TableTuple(m_target->schema()); m_updatedTupleBackingStore = new char[m_target->schema()->tupleLength() + 1]; memset(m_updatedTupleBackingStore, 0, m_target->schema()->tupleLength() + 1); m_updatedTuple.move(m_updatedTupleBackingStore); m_emptyTuple = TableTuple(m_target->schema()); m_emptyTupleBackingStore = new char[m_target->schema()->tupleLength() + 1]; memset(m_emptyTupleBackingStore, 0, m_target->schema()->tupleLength() + 1); m_emptyTuple.move(m_emptyTupleBackingStore); }
int Lvk::Nlp::Parser::parseIf(const QString &s, Nlp::Predicate **pred, QString *body, int offset) { int i = m_ifRegex.indexIn(s, offset); if (i != -1) { qDebug() << "Parsed if" << m_ifRegex.cap(1) << m_ifRegex.cap(2) << m_ifRegex.cap(3) << m_ifRegex.cap(4); if (pred) { *pred = parsePredicate(m_ifRegex.cap(1).trimmed(), m_ifRegex.cap(3).trimmed(), m_ifRegex.cap(2).trimmed()); } if (body) { *body = m_ifRegex.cap(4).trimmed(); } } return i; }
bool PlayAscii::parse(const char *string, int &n) { // Initialize fixed roles. fixed_roles.clear(); for (int i=0; i<MAX_PLAY_ROLES; i++) { fixed_roles.push_back(i); } // Initialize timeout //默认每个tactics最多维持25秒 play_timeout = 25.0; // Find PLAY keyword. static char w[5]; n += Parse::pWord(string + n, w, 4); if (strcmp(w, "PLAY") != 0) { fprintf(stderr, "ERROR: PlayAscii could not find PLAY keyword.\n"); printErrorLine(string, n); return false; } // Read name. n += Parse::pLine(string + n, &name); n += Parse::skipLine(string + n); // Read conditions. while (1) { char *word; n += Parse::pWord(string + n, &word); if (strcmp(word, "APPLICABLE") == 0) { //解析规则启动条件 applicable.push_back(parsePredicate(string, n)); n += Parse::skipLine(string + n); } else if (strcmp(word, "DONE") == 0) { //解析规则终止条件(可能是多个) static char rv[16]; n += Parse::pWord(string + n, rv, 16); if (strcmp(rv, "succeeded") == 0) done_status.push_back(Succeeded); else if (strcmp(rv, "failed") == 0) done_status.push_back(Failed); else if (strcmp(rv, "aborted") == 0) done_status.push_back(Aborted); else if (strcmp(rv, "completed") == 0) done_status.push_back(Completed); else { fprintf(stderr, "ERROR: PlayAscii unknown done status, %s.\n", rv); printErrorLine(string, n); done_status.push_back(Failed); } done.push_back(parsePredicate(string, n)); } else if (strcmp(word, "FIXEDROLES") == 0) { //固定角色 for (int i=0; i<MAX_PLAY_ROLES; i++) { n += Parse::pInt(string + n, fixed_roles[i]); } n += Parse::skipLine(string + n); } else if (strcmp(word, "TIMEOUT") == 0) { //超时 n += Parse::pDouble(string + n, play_timeout); } else if (strcmp(word, "OROLE") == 0) { //用于告知系统,本play关心哪些对手角色 //对方角色 OpponentRole o = parseORole(string, n); if (o) opponent_roles.push_back(o); } else if (strcmp(word, "ROLE") == 0) { //己方角色 n -= 4; delete [] word; break; } else { fprintf(stderr, "ERROR: PlayAscii unknown key word, %s.\n", word); printErrorLine(string, n); n += Parse::skipLine(string + n); } delete [] word; } // Read roles. for (int i=0; i<MAX_PLAY_ROLES; i++) { static bool error; PlayRole r(string, n, error); if (error) { printErrorLine(string, n); return false; } roles.push_back(r); } return true; }
MaterializedViewMetadata::MaterializedViewMetadata( PersistentTable *srcTable, PersistentTable *destTable, catalog::MaterializedViewInfo *metadata) : m_target(destTable), m_filterPredicate(NULL) { // DEBUG_STREAM_HERE("New mat view on source table " << srcTable->name() << " @" << srcTable << " view table " << m_target->name() << " @" << m_target); // best not to have to worry about the destination table disappearing out from under the source table that feeds it. m_target->incrementRefcount(); srcTable->addMaterializedView(this); // try to load the predicate from the catalog view parsePredicate(metadata); // set up the group by columns from the catalog info m_groupByColumnCount = metadata->groupbycols().size(); m_groupByColumns = new int32_t[m_groupByColumnCount]; std::map<std::string, catalog::ColumnRef*>::const_iterator colRefIterator; for (colRefIterator = metadata->groupbycols().begin(); colRefIterator != metadata->groupbycols().end(); colRefIterator++) { int32_t grouping_order_offset = colRefIterator->second->index(); m_groupByColumns[grouping_order_offset] = colRefIterator->second->column()->index(); } // set up the mapping from input col to output col m_outputColumnCount = metadata->dest()->columns().size(); m_outputColumnSrcTableIndexes = new int32_t[m_outputColumnCount]; m_outputColumnAggTypes = new ExpressionType[m_outputColumnCount]; std::map<std::string, catalog::Column*>::const_iterator colIterator; // iterate the source table for (colIterator = metadata->dest()->columns().begin(); colIterator != metadata->dest()->columns().end(); colIterator++) { const catalog::Column *destCol = colIterator->second; int destIndex = destCol->index(); const catalog::Column *srcCol = destCol->matviewsource(); if (srcCol) { m_outputColumnSrcTableIndexes[destIndex] = srcCol->index(); m_outputColumnAggTypes[destIndex] = static_cast<ExpressionType>(destCol->aggregatetype()); } else { m_outputColumnSrcTableIndexes[destIndex] = -1; m_outputColumnAggTypes[destIndex] = EXPRESSION_TYPE_INVALID; } } m_index = m_target->primaryKeyIndex(); // When updateTupleWithSpecificIndexes needs to be called, // the context is lost that identifies which base table columns potentially changed. // So the minimal set of indexes that MIGHT need to be updated must include // any that are not solely based on primary key components. // Until the DDL compiler does this analysis and marks the indexes accordingly, // include all target table indexes except the actual primary key index on the group by columns. const std::vector<TableIndex*>& targetIndexes = m_target->allIndexes(); BOOST_FOREACH(TableIndex *index, targetIndexes) { if (index != m_index) { m_updatableIndexList.push_back(index); } } allocateBackedTuples(); // Catch up on pre-existing source tuples UNLESS target tuples have already been migrated in. if (( ! srcTable->isPersistentTableEmpty()) && m_target->isPersistentTableEmpty()) { TableTuple scannedTuple(srcTable->schema()); TableIterator &iterator = srcTable->iterator(); while (iterator.next(scannedTuple)) { processTupleInsert(scannedTuple, false); } } }