@Test public void testExplain() throws Exception { createTable("explain_test"); insertData("explain_test"); String query1 = "SELECT * FROM explain_test"; String query2 = "SELECT * FROM explain_test1"; ExplainQueryContext ctx = createExplainContext(query1, baseConf); Assert.assertNull(ctx.getFinalDriverQuery(driver)); driver.explain(ctx); Assert.assertNotNull(ctx.getFinalDriverQuery(driver)); try { driver.explain(createExplainContext(query2, baseConf)); Assert.fail("Running explain on a non existing table."); } catch (LensException ex) { System.out.println("Error : " + ex); } }
@Override public DriverQueryPlan explain(AbstractQueryContext explainCtx) throws LensException { if (explainCtx.getDriverQuery(this) == null) { throw new NullPointerException("Null driver query for " + explainCtx.getUserQuery()); } if (explainCtx.getDriverContext().getDriverQueryPlan(this) != null) { return explainCtx.getDriverContext().getDriverQueryPlan(this); } checkConfigured(); String explainQuery; String rewrittenQuery = rewriteQuery(explainCtx); Configuration explainConf = explainCtx.getDriverConf(this); String explainKeyword = explainConf.get(JDBC_EXPLAIN_KEYWORD_PARAM, DEFAULT_JDBC_EXPLAIN_KEYWORD); boolean explainBeforeSelect = explainConf.getBoolean(JDBC_EXPLAIN_KEYWORD_BEFORE_SELECT, DEFAULT_JDBC_EXPLAIN_KEYWORD_BEFORE_SELECT); if (explainBeforeSelect) { explainQuery = explainKeyword + " " + rewrittenQuery; } else { explainQuery = rewrittenQuery.replaceAll("select ", "select " + explainKeyword + " "); } log.info("{} Explain Query : {}", getFullyQualifiedName(), explainQuery); QueryContext explainQueryCtx = QueryContext.createContextWithSingleDriver(explainQuery, null, new LensConf(), explainConf, this, explainCtx.getLensSessionIdentifier(), false); QueryResult result = null; try { result = executeInternal(explainQueryCtx, explainQuery); if (result.error != null) { throw new LensException("Query explain failed!", result.error); } } finally { if (result != null) { result.close(); } } JDBCQueryPlan jqp = new JDBCQueryPlan(calculateQueryCost(explainCtx)); explainCtx.getDriverContext().setDriverQueryPlan(this, jqp); return jqp; }
JDBCDriver extends AbstractLensDriver { @Override public DriverQueryPlan explain(AbstractQueryContext explainCtx) throws LensException { if (explainCtx.getDriverQuery(this) == null) { throw new NullPointerException("Null driver query for " + explainCtx.getUserQuery()); } if (explainCtx.getDriverContext().getDriverQueryPlan(this) != null) { return explainCtx.getDriverContext().getDriverQueryPlan(this); } checkConfigured(); String explainQuery; String rewrittenQuery = rewriteQuery(explainCtx); Configuration explainConf = explainCtx.getDriverConf(this); String explainKeyword = explainConf.get(JDBC_EXPLAIN_KEYWORD_PARAM, DEFAULT_JDBC_EXPLAIN_KEYWORD); boolean explainBeforeSelect = explainConf.getBoolean(JDBC_EXPLAIN_KEYWORD_BEFORE_SELECT, DEFAULT_JDBC_EXPLAIN_KEYWORD_BEFORE_SELECT); if (explainBeforeSelect) { explainQuery = explainKeyword + " " + rewrittenQuery; } else { explainQuery = rewrittenQuery.replaceAll("select ", "select " + explainKeyword + " "); } log.info("{} Explain Query : {}", getFullyQualifiedName(), explainQuery); QueryContext explainQueryCtx = QueryContext.createContextWithSingleDriver(explainQuery, null, new LensConf(), explainConf, this, explainCtx.getLensSessionIdentifier(), false); QueryResult result = null; try { result = executeInternal(explainQueryCtx, explainQuery); if (result.error != null) { throw new LensException("Query explain failed!", result.error); } } finally { if (result != null) { result.close(); } } JDBCQueryPlan jqp = new JDBCQueryPlan(calculateQueryCost(explainCtx)); explainCtx.getDriverContext().setDriverQueryPlan(this, jqp); return jqp; } }
JDBCDriver extends AbstractLensDriver { @Override public DriverQueryPlan explain(AbstractQueryContext explainCtx) throws LensException { if (explainCtx.getDriverQuery(this) == null) { throw new NullPointerException("Null driver query for " + explainCtx.getUserQuery()); } if (explainCtx.getDriverContext().getDriverQueryPlan(this) != null) { return explainCtx.getDriverContext().getDriverQueryPlan(this); } checkConfigured(); String explainQuery; String rewrittenQuery = rewriteQuery(explainCtx); Configuration explainConf = explainCtx.getDriverConf(this); String explainKeyword = explainConf.get(JDBC_EXPLAIN_KEYWORD_PARAM, DEFAULT_JDBC_EXPLAIN_KEYWORD); boolean explainBeforeSelect = explainConf.getBoolean(JDBC_EXPLAIN_KEYWORD_BEFORE_SELECT, DEFAULT_JDBC_EXPLAIN_KEYWORD_BEFORE_SELECT); if (explainBeforeSelect) { explainQuery = explainKeyword + " " + rewrittenQuery; } else { explainQuery = rewrittenQuery.replaceAll("select ", "select " + explainKeyword + " "); } log.info("{} Explain Query : {}", getFullyQualifiedName(), explainQuery); QueryContext explainQueryCtx = QueryContext.createContextWithSingleDriver(explainQuery, null, new LensConf(), explainConf, this, explainCtx.getLensSessionIdentifier(), false); QueryResult result = null; try { result = executeInternal(explainQueryCtx, explainQuery); if (result.error != null) { throw new LensException("Query explain failed!", result.error); } } finally { if (result != null) { result.close(); } } JDBCQueryPlan jqp = new JDBCQueryPlan(calculateQueryCost(explainCtx)); explainCtx.getDriverContext().setDriverQueryPlan(this, jqp); return jqp; }  }
JDBCDriver extends AbstractLensDriver { @Override public DriverQueryPlan explain(AbstractQueryContext explainCtx) throws LensException { if (explainCtx.getDriverQuery(this) == null) { throw new NullPointerException("Null driver query for " + explainCtx.getUserQuery()); } if (explainCtx.getDriverContext().getDriverQueryPlan(this) != null) { return explainCtx.getDriverContext().getDriverQueryPlan(this); } checkConfigured(); String explainQuery; String rewrittenQuery = rewriteQuery(explainCtx); Configuration explainConf = explainCtx.getDriverConf(this); String explainKeyword = explainConf.get(JDBC_EXPLAIN_KEYWORD_PARAM, DEFAULT_JDBC_EXPLAIN_KEYWORD); boolean explainBeforeSelect = explainConf.getBoolean(JDBC_EXPLAIN_KEYWORD_BEFORE_SELECT, DEFAULT_JDBC_EXPLAIN_KEYWORD_BEFORE_SELECT); if (explainBeforeSelect) { explainQuery = explainKeyword + " " + rewrittenQuery; } else { explainQuery = rewrittenQuery.replaceAll("select ", "select " + explainKeyword + " "); } log.info("{} Explain Query : {}", getFullyQualifiedName(), explainQuery); QueryContext explainQueryCtx = QueryContext.createContextWithSingleDriver(explainQuery, null, new LensConf(), explainConf, this, explainCtx.getLensSessionIdentifier(), false); QueryResult result = null; try { result = executeInternal(explainQueryCtx, explainQuery); if (result.error != null) { throw new LensException("Query explain failed!", result.error); } } finally { if (result != null) { result.close(); } } JDBCQueryPlan jqp = new JDBCQueryPlan(calculateQueryCost(explainCtx)); explainCtx.getDriverContext().setDriverQueryPlan(this, jqp); return jqp; }  @Override void configure(Configuration conf, String driverType, String driverName); void init(); QueryCost calculateQueryCost(AbstractQueryContext qctx); @Override QueryCost estimate(AbstractQueryContext qctx); @Override DriverQueryPlan explain(AbstractQueryContext explainCtx); void validate(AbstractQueryContext pContext); @Override void prepare(PreparedQueryContext pContext); @Override DriverQueryPlan explainAndPrepare(PreparedQueryContext pContext); @Override void closePreparedQuery(QueryPrepareHandle handle); @Override LensResultSet execute(QueryContext context); @Override void executeAsync(QueryContext context); @Override void updateStatus(QueryContext context); @Override void closeResultSet(QueryHandle handle); @Override boolean cancelQuery(QueryHandle handle); @Override void closeQuery(QueryHandle handle); @Override void close(); @Override void registerDriverEventListener(LensEventListener<DriverEvent> driverEventListener); @Override void readExternal(ObjectInput arg0); @Override void writeExternal(ObjectOutput arg0); @Override StatusUpdateMethod getStatusUpdateMethod(); }
JDBCDriver extends AbstractLensDriver { @Override public DriverQueryPlan explain(AbstractQueryContext explainCtx) throws LensException { if (explainCtx.getDriverQuery(this) == null) { throw new NullPointerException("Null driver query for " + explainCtx.getUserQuery()); } if (explainCtx.getDriverContext().getDriverQueryPlan(this) != null) { return explainCtx.getDriverContext().getDriverQueryPlan(this); } checkConfigured(); String explainQuery; String rewrittenQuery = rewriteQuery(explainCtx); Configuration explainConf = explainCtx.getDriverConf(this); String explainKeyword = explainConf.get(JDBC_EXPLAIN_KEYWORD_PARAM, DEFAULT_JDBC_EXPLAIN_KEYWORD); boolean explainBeforeSelect = explainConf.getBoolean(JDBC_EXPLAIN_KEYWORD_BEFORE_SELECT, DEFAULT_JDBC_EXPLAIN_KEYWORD_BEFORE_SELECT); if (explainBeforeSelect) { explainQuery = explainKeyword + " " + rewrittenQuery; } else { explainQuery = rewrittenQuery.replaceAll("select ", "select " + explainKeyword + " "); } log.info("{} Explain Query : {}", getFullyQualifiedName(), explainQuery); QueryContext explainQueryCtx = QueryContext.createContextWithSingleDriver(explainQuery, null, new LensConf(), explainConf, this, explainCtx.getLensSessionIdentifier(), false); QueryResult result = null; try { result = executeInternal(explainQueryCtx, explainQuery); if (result.error != null) { throw new LensException("Query explain failed!", result.error); } } finally { if (result != null) { result.close(); } } JDBCQueryPlan jqp = new JDBCQueryPlan(calculateQueryCost(explainCtx)); explainCtx.getDriverContext().setDriverQueryPlan(this, jqp); return jqp; }  @Override void configure(Configuration conf, String driverType, String driverName); void init(); QueryCost calculateQueryCost(AbstractQueryContext qctx); @Override QueryCost estimate(AbstractQueryContext qctx); @Override DriverQueryPlan explain(AbstractQueryContext explainCtx); void validate(AbstractQueryContext pContext); @Override void prepare(PreparedQueryContext pContext); @Override DriverQueryPlan explainAndPrepare(PreparedQueryContext pContext); @Override void closePreparedQuery(QueryPrepareHandle handle); @Override LensResultSet execute(QueryContext context); @Override void executeAsync(QueryContext context); @Override void updateStatus(QueryContext context); @Override void closeResultSet(QueryHandle handle); @Override boolean cancelQuery(QueryHandle handle); @Override void closeQuery(QueryHandle handle); @Override void close(); @Override void registerDriverEventListener(LensEventListener<DriverEvent> driverEventListener); @Override void readExternal(ObjectInput arg0); @Override void writeExternal(ObjectOutput arg0); @Override StatusUpdateMethod getStatusUpdateMethod(); static final AtomicInteger THID; }