Search in sources :

Example 6 with PlanNodeTree

use of org.voltdb.plannodes.PlanNodeTree in project voltdb by VoltDB.

the class AdHocPlannedStmtBatch method explainStatement.

/**
     * 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) {
    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(collpnt.getRootPlanNode());
        }
        String result = pnt.getRootPlanNode().toExplainPlanString();
        return result;
    } catch (JSONException e) {
        System.out.println(e);
        return "Internal Error (JSONException): " + e.getMessage();
    }
}
Also used : JSONObject(org.json_voltpatches.JSONObject) SendPlanNode(org.voltdb.plannodes.SendPlanNode) JSONException(org.json_voltpatches.JSONException) PlanNodeTree(org.voltdb.plannodes.PlanNodeTree)

Example 7 with PlanNodeTree

use of org.voltdb.plannodes.PlanNodeTree in project voltdb by VoltDB.

the class MaterializedViewProcessor method getPlanNodeTreeFromCatalogStatement.

private PlanNodeTree getPlanNodeTreeFromCatalogStatement(Database db, Statement stmt) {
    PlanNodeTree pnt = new PlanNodeTree();
    try {
        JSONObject jsonPlan = new JSONObject(org.voltdb.utils.Encoder.decodeBase64AndDecompress(stmt.getFragments().get("0").getPlannodetree()));
        pnt.loadFromJSONPlan(jsonPlan, db);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return pnt;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONException(org.json_voltpatches.JSONException) PlanNodeTree(org.voltdb.plannodes.PlanNodeTree)

Aggregations

PlanNodeTree (org.voltdb.plannodes.PlanNodeTree)7 JSONObject (org.json_voltpatches.JSONObject)4 JSONException (org.json_voltpatches.JSONException)3 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)3 IOException (java.io.IOException)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 Database (org.voltdb.catalog.Database)1 SendPlanNode (org.voltdb.plannodes.SendPlanNode)1