Package org.voltdb.plannodes

Examples of org.voltdb.plannodes.PlanNodeTree


        testLoadQueryPlanTree("select count(*) from l where lname=? and id < ?;");
    }

    public void testLoadQueryPlanTree(String sql) throws JSONException {
        AbstractPlanNode pn = compile(sql);
        PlanNodeTree pnt = new PlanNodeTree(pn);
        String str = pnt.toJSONString();
        System.out.println(str);
        JSONArray jarray = new JSONObject(str)
                .getJSONArray(PlanNodeTree.Members.PLAN_NODES.name());
        PlanNodeTree pnt1 = new PlanNodeTree();
        pnt1.loadFromJSONArray(jarray, getDatabase());
        String str1 = pnt1.toJSONString();
        assertTrue(str.equals(str1));
    }
View Full Code Here


        System.out.println( pn.toJSONString() );
        System.out.println( pn.toExplainPlanString() );
        plannerTester.writePlanToFile( pn, path, "prettyJson.txt", "");

        ArrayList<String> getsql = new ArrayList<String>();
        PlanNodeTree pnt = plannerTester.loadPlanFromFile(path+"prettyJson.txt", getsql);
        System.out.println( pnt.toJSONString() );
        System.out.println( pnt.getRootPlanNode().toExplainPlanString() );
        ArrayList<AbstractPlanNode> list1 = pn.getPlanNodeList();
        ArrayList<AbstractPlanNode> list2 = pnt.getRootPlanNode().getPlanNodeList();
        assertTrue( list1.size() == list2.size() );
        for( int i = 0; i < list1.size(); i++ ) {
            Map<PlanNodeType, AbstractPlanNode> inlineNodes1 = list1.get(i).getInlinePlanNodes();
            Map<PlanNodeType, AbstractPlanNode> inlineNodes2 = list2.get(i).getInlinePlanNodes();
            ifinlineNodes1 != null ) {
View Full Code Here

        System.out.println( pn.toExplainPlanString() );
        System.out.println( pn.toJSONString() );
        plannerTester.writePlanToFile( pn, path, "prettyJson.txt", "");

        ArrayList<String> getsql = new ArrayList<String>();
        PlanNodeTree pnt = plannerTester.loadPlanFromFile(path+"prettyJson.txt", getsql);
        System.out.println( pnt.toJSONString() );
        System.out.println( pnt.getRootPlanNode().toExplainPlanString() );
        ArrayList<AbstractPlanNode> list1 = pn.getPlanNodeList();
        ArrayList<AbstractPlanNode> list2 = pnt.getRootPlanNode().getPlanNodeList();
        assertTrue( list1.size() == list2.size() );
        for( int i = 0; i < list1.size(); i++ ) {
            Map<PlanNodeType, AbstractPlanNode> inlineNodes1 = list1.get(i).getInlinePlanNodes();
            Map<PlanNodeType, AbstractPlanNode> inlineNodes2 = list2.get(i).getInlinePlanNodes();
            ifinlineNodes1 != null ) {
View Full Code Here

    public static void writePlanToFile( AbstractPlanNode pn, String pathToDir, String fileName, String sql) {
        if( pn == null ) {
            System.err.println("the plan node is null, nothing to write");
            return;
        }
        PlanNodeTree pnt = new PlanNodeTree( pn );
        String prettyJson = pnt.toJSONString();
        if( !new File(pathToDir).exists() ) {
            new File(pathToDir).mkdirs();
        }
        try {
            BufferedWriter writer = new BufferedWriter( new FileWriter( pathToDir+fileName ) );
View Full Code Here

            e.printStackTrace();
        }
    }

    public static PlanNodeTree loadPlanFromFile( String path, ArrayList<String> getsql ) throws FileNotFoundException {
        PlanNodeTree pnt = new PlanNodeTree();
        String prettyJson = "";
        String line = null;
        BufferedReader reader = new BufferedReader( new FileReader( path ));
        try {
            getsql.add( reader.readLine() );
            while( (line = reader.readLine() ) != null ){
                line = line.trim();
                prettyJson += line;
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        JSONObject jobj;
        try {
            jobj = new JSONObject( prettyJson );
            JSONArray jarray =  jobj.getJSONArray("PLAN_NODES");
            Database db = s_singleton.getDatabase();
            pnt.loadFromJSONArray(jarray, db);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return pnt;
    }
View Full Code Here

    public static void configDiff(String config) throws Exception {
        if ( ! setUp( config )) {
            return;
        }
        m_reportWriter.write( "===================================================================Begin "+config+"\n" );
        PlanNodeTree pnt1 = null;
        PlanNodeTree pnt2 = null;
        int size = m_stmts.size();
        String baseStmt = null;
        for( int i = 0; i < size; i++ ){
            //* Enable for debug:*/ System.out.println("DEBUG: comparing " + m_savePlanPath+config+".plan"+i + " and " + m_baselinePath+config+".plan"+i);
            ArrayList<String> getsql = new ArrayList<String>();
            try {
                pnt1 = loadPlanFromFile( m_baselinePath+config+".plan"+i, getsql );
                baseStmt = getsql.get(0);
            } catch (FileNotFoundException e) {
                String message = "ERROR: Plan file "+m_baselinePath+config+".plan"+i+" doesn't exist. Use -s (the Compile/Save option) or 'ant plannertestrefresh -Dconfig="+config + " ' to generate plans to the baseline directory.\n";
                System.err.print(message);
                m_reportWriter.write(message);
                System.exit(1);
            }

            //if sql stmts not consistent
            if( !baseStmt.equalsIgnoreCase( m_stmts.get(i)) ) {
                diffPair strPair = new diffPair( baseStmt, m_stmts.get(i) );
                m_reportWriter.write("Statement "+i+" of "+config+"/config:\n SQL statement is not consistent with the one in baseline :"+"\n"+
                        strPair.toString()+"\n");
                m_numFail++;
                continue;
            }

            try{
                pnt2  = loadPlanFromFile( m_workPath+config+".plan"+i, getsql );
            } catch (FileNotFoundException e) {
                String message = "ERROR: Temporary plan file "+m_workPath+config+".plan"+i+" was not generated.\n";
                System.err.print(message);
                m_reportWriter.write(message);
                System.exit(1);
            }
            AbstractPlanNode pn1 = pnt1.getRootPlanNode();
            AbstractPlanNode pn2 = pnt2.getRootPlanNode();


            if( diff( pn1, pn2, false ) ) {
                m_numPass++;
                if( m_reportExplainedPlan ) {
View Full Code Here

     */
    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 );
            JSONArray jarray =  jobj.getJSONArray(PlanNodeTree.Members.PLAN_NODES.name());
            pnt.loadFromJSONArray(jarray, 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
                jobj = new JSONObject( collplan );
                jarray =  jobj.getJSONArray(PlanNodeTree.Members.PLAN_NODES.name());
                collpnt.loadFromJSONArray(jarray, db);
                assert( collpnt.getRootPlanNode() instanceof SendPlanNode);
                pnt.getRootPlanNode().reattachFragment( (SendPlanNode) collpnt.getRootPlanNode() );
            }
            str = pnt.getRootPlanNode().toExplainPlanString();
        } catch (JSONException e) {
            System.out.println(e.getMessage());
        }
View Full Code Here

TOP

Related Classes of org.voltdb.plannodes.PlanNodeTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.