@Override public String toJSONString() { JSONStringer stringer = new JSONStringer(); try { stringer.object(); super.toJSONString(stringer); stringer.key(Members.EXECUTE_LIST.name()).array(); for (AbstractPlanNode node : m_list) { stringer.value(node.getPlanNodeId().intValue()); } stringer.endArray(); // end execution list stringer.endObject(); // end PlanNodeList } catch (JSONException e) { // HACK ugly ugly to make the JSON handling // in QueryPlanner generate a JSONException for a plan we know // here that we can't serialize. Making this method throw // JSONException pushes that exception deep into the bowels of // Volt with no good place to catch it and handle the error. // Consider this the coward's way out. return "This JSON error message is a lie"; } return stringer.toString(); }
public void constructList() throws Exception { // // Create a counter for each node based on the # of children that it has // If any node has no children, put it in the execute list // List<AbstractPlanNode> execute_list = Collections.synchronizedList(new ArrayList<AbstractPlanNode>()); Map<AbstractPlanNode, Integer> child_cnts = new HashMap<AbstractPlanNode, Integer>(); for (AbstractPlanNode node : m_planNodes) { int num_of_children = node.getChildCount(); if (num_of_children == 0) { execute_list.add(node); } else { child_cnts.put(node, num_of_children); } } // // Now run through a simulation // Doing it this way maintains the nuances of the parent-child relationships // m_list.clear(); while (!execute_list.isEmpty()) { AbstractPlanNode node = execute_list.remove(0); // // Add the node to our execution list // m_list.add(node); // // Then update all of this node's parents and reduce their wait counter by 1 // If the counter is at zero, then we'll add it to end of our list // for (int i = 0; i < node.getParentCount(); i++) { AbstractPlanNode parent = node.getParent(i); int remaining = child_cnts.get(parent) - 1; child_cnts.put(parent, remaining); if (remaining == 0) { execute_list.add(parent); } } } // // Important! Make sure that our list has the same number of entries in our tree // if (m_list.size() != m_planNodes.size()) { throw new Exception( "ERROR: The execution list has '" + m_list.size() + "' PlanNodes but our original tree has '" + m_planNodes.size() + "' PlanNode entries"); } return; }
public String toDOTString(String name) { StringBuilder sb = new StringBuilder(); sb.append("digraph ").append(name).append(" {\n"); for (AbstractPlanNode node : m_list) { sb.append(node.toDOTString()); } sb.append("\n}\n"); return sb.toString(); }