void PlanNodeFragment::nodeListFromJSONObject(PlanNodeFragment *pnf, PlannerDomValue planNodesList, PlannerDomValue executeList, int stmtId) { assert(pnf->m_stmtExecutionListMap.find(stmtId) == pnf->m_stmtExecutionListMap.end()); // NODE_LIST std::vector<AbstractPlanNode*> planNodes; for (int i = 0; i < planNodesList.arrayLen(); i++) { AbstractPlanNode *node = AbstractPlanNode::fromJSONObject(planNodesList.valueAtIndex(i)); assert(node); assert(pnf->m_idToNodeMap.find(node->getPlanNodeId()) == pnf->m_idToNodeMap.end()); pnf->m_idToNodeMap[node->getPlanNodeId()] = node; planNodes.push_back(node); } // walk the plannodes and complete each plannode's id-to-node maps for (std::vector< AbstractPlanNode* >::const_iterator node = planNodes.begin(); node != planNodes.end(); ++node) { const std::vector<CatalogId>& childIds = (*node)->getChildIds(); for (int zz = 0; zz < childIds.size(); zz++) { (*node)->addChild(pnf->m_idToNodeMap[childIds[zz]]); } } // EXECUTE_LIST std::auto_ptr<std::vector<AbstractPlanNode*> > executeNodeList(new std::vector<AbstractPlanNode*>()); for (int i = 0; i < executeList.arrayLen(); i++) { executeNodeList->push_back(pnf->m_idToNodeMap[executeList.valueAtIndex(i).asInt()]); } pnf->m_stmtExecutionListMap.insert(std::make_pair(stmtId, executeNodeList.get())); executeNodeList.release(); }
PlanNodeFragment * PlanNodeFragment::fromJSONObject(PlannerDomValue obj) { auto_ptr<PlanNodeFragment> pnf(new PlanNodeFragment()); // read and construct plannodes from json object PlannerDomValue planNodesArray = obj.valueForKey("PLAN_NODES"); for (int i = 0; i < planNodesArray.arrayLen(); i++) { AbstractPlanNode *node = NULL; node = AbstractPlanNode::fromJSONObject(planNodesArray.valueAtIndex(i)); assert(node); pnf->m_planNodes.push_back(node); pnf->m_idToNodeMap[node->getPlanNodeId()] = node; } // walk the plannodes and complete each plannode's id-to-node maps for (std::vector< AbstractPlanNode* >::const_iterator node = pnf->m_planNodes.begin(); node != pnf->m_planNodes.end(); ++node) { const std::vector<CatalogId> childIds = (*node)->getChildIds(); for (int zz = 0; zz < childIds.size(); zz++) { (*node)->addChild(pnf->m_idToNodeMap[childIds[zz]]); } } pnf->loadFromJSONObject(obj); PlanNodeFragment *retval = pnf.get(); pnf.release(); assert(retval); return retval; }
PlanNodeFragment * PlanNodeFragment::fromJSONObject(json_spirit::Object &obj) { json_spirit::Value planNodesValue = json_spirit::find_value( obj, "PLAN_NODES"); if (planNodesValue == json_spirit::Value::null) { throwFatalException("Failure attempting to load plan a plan node fragment from a " "json_spirit::Object. There was no value \"PLAN_NODES\""); } PlanNodeFragment * pnf = new PlanNodeFragment(); // read and construct plannodes from json object json_spirit::Array planNodesArray = planNodesValue.get_array(); for (int ii = 0; ii < planNodesArray.size(); ii++) { AbstractPlanNode *node = NULL; try { node = AbstractPlanNode::fromJSONObject(planNodesArray[ii].get_obj()); } catch (SerializableEEException &ex) { delete pnf; throw; } pnf->m_planNodes.push_back(node); pnf->m_idToNodeMap[node->getPlanNodeId()] = node; } // walk the plannodes and complete each plannode's id-to-node maps for (std::vector< AbstractPlanNode* >::const_iterator node = pnf->m_planNodes.begin(); node != pnf->m_planNodes.end(); ++node) { const std::vector<CatalogId> childIds = (*node)->getChildIds(); std::vector<AbstractPlanNode*> &children = (*node)->getChildren(); for (int zz = 0; zz < childIds.size(); zz++) { children.push_back(pnf->m_idToNodeMap[childIds[zz]]); } const std::vector<CatalogId> parentIds = (*node)->getParentIds(); std::vector<AbstractPlanNode*> &parents = (*node)->getParents(); for (int zz = 0; zz < parentIds.size(); zz++) { parents.push_back(pnf->m_idToNodeMap[parentIds[zz]]); } } try { pnf->loadFromJSONObject(obj); } catch (SerializableEEException &eeEx) { delete pnf; throw; } return pnf; }