public void testLoadQueryPlanTree(String sql) throws JSONException {
   AbstractPlanNode pn = compile(sql);
   PlanNodeTree pnt = new PlanNodeTree(pn);
   String str = pnt.toJSONString();
   JSONObject jsonPlan = new JSONObject(str);
   PlanNodeTree pnt1 = new PlanNodeTree();
   pnt1.loadFromJSONPlan(jsonPlan, getDatabase());
   String str1 = pnt1.toJSONString();
   assertTrue(str.equals(str1));
 }
  /**
   * Return the "EXPLAIN" string of the batched statement at the index
   *
   * @param i the index
   * @param db the database context (for adding catalog details).
   */
  public String explainStatement(int i, Database db) {
    String str = "";
    AdHocPlannedStatement plannedStatement = plannedStatements.get(i);
    String aggplan = new String(plannedStatement.core.aggregatorFragment, Constants.UTF8ENCODING);
    PlanNodeTree pnt = new PlanNodeTree();
    try {
      JSONObject jobj = new JSONObject(aggplan);
      pnt.loadFromJSONPlan(jobj, db);

      if (plannedStatement.core.collectorFragment != null) {
        // multi-partition query plan
        String collplan =
            new String(plannedStatement.core.collectorFragment, Constants.UTF8ENCODING);
        PlanNodeTree collpnt = new PlanNodeTree();
        // reattach plan fragments
        JSONObject jobMP = new JSONObject(collplan);
        collpnt.loadFromJSONPlan(jobMP, db);
        assert (collpnt.getRootPlanNode() instanceof SendPlanNode);
        pnt.getRootPlanNode().reattachFragment((SendPlanNode) collpnt.getRootPlanNode());
      }
      str = pnt.getRootPlanNode().toExplainPlanString();
    } catch (JSONException e) {
      System.out.println(e.getMessage());
    }
    return str;
  }