8 Replies Latest reply on Feb 22, 2013 12:28 AM by rakeshsagar

    Generating Query Plan from test case

    rakeshsagar

      Hi all,

       

      Is there a way to generate the Query Plan from the test case using Teiid Embedded Server?

       

      Thanks

      Rakesh.

        • 1. Re: Generating Query Plan from test case
          rareddy
          • 2. Re: Generating Query Plan from test case
            rakeshsagar

            Thanks Ramesh.

             

            Does this apply to the Continuous Executions as well? I tried the same thing but looks like the Query Plan is not getting generated.

             

            The following is the code snippet that I am using:

             

                    final TeiidDriver td = server.getDriver();

                    final Connection c = td.connect("jdbc:teiid:Chorus", null);

                    final Statement stmt = c.createStatement();

                    stmt.execute("SET SHOWPLAN ON");

                    final TeiidStatement tstatement = stmt.unwrap(TeiidStatement.class);

             

                    tstatement.submitExecute(sql, new StatementCallback()

                    {

                          @Override

                        public void onRow(final Statement s, final ResultSet rs) throws Exception

                        {

                            System.out.println("Row returned"

                                               + rs.getObject(1));

                        }

                          @Override

                        public void onException(final Statement s, final Exception e) throws Exception

                        {

                            e.printStackTrace();

                        }

                          @Override

                        public void onComplete(final Statement s) throws Exception

                        {

                            System.out.println("Complete");

                        }

                    }, new RequestOptions().continuous(true));

                   

                    final org.teiid.client.plan.PlanNode queryPlan = tstatement.getPlanDescription();

                    System.out.println("Plan: " + queryPlan);

             

            Please let me know if I am missing anything here.

             

            Thanks

            Rakesh

            • 3. Re: Generating Query Plan from test case
              shawkins

              Rakesh,

               

              Continuous executions are asynch wrt the calling thread.  So no plan description will be available immediately after you issue a submit.  The simpliest approach is just turn execution off "SET NOEXEC ON" and issue the query as a regular statement.

               

              Steve

              • 4. Re: Generating Query Plan from test case
                rakeshsagar

                Thanks Steve.

                 

                I tried this and I get the plan description as null.

                • 5. Re: Generating Query Plan from test case
                  shawkins

                  Can you show me what "this" is?

                   

                  Steve

                  • 6. Re: Generating Query Plan from test case
                    rakeshsagar

                    Attached the test case to the original post.

                     

                    Thanks

                    Rakesh

                    • 7. Re: Generating Query Plan from test case
                      shawkins

                      You need to just follow the link that Ramesh sent.  The basic flow is:

                       

                      stmt.execute("SET SHOWPLAN ON");

                      stmt.execute("SET NOEXEC ON"); //this is optional, but more than likely you just want the plan

                      stmt.execute(sql);

                      PlanNode p = stmt.getPlanDescription(); //or stmt.executeQuery("SHOW PLAN");

                      ...

                      • 8. Re: Generating Query Plan from test case
                        rakeshsagar

                        Thanks Steve.