@Test public void testExplainPartitionedTable() throws Exception { int handleSize = getHandleSize(); createPartitionedTable("test_part_table"); SessionState.setCurrentSessionState(ss); DriverQueryPlan plan = driver.explain(createExplainContext("SELECT ID FROM test_part_table", queryConf)); assertHandleSize(handleSize); assertTrue(plan instanceof HiveQueryPlan); assertNotNull(plan.getTablesQueried()); assertEquals(plan.getTablesQueried().size(), 1); System.out.println("Tables:" + plan.getTablesQueried()); assertEquals(plan.getTableWeight(dataBase + ".test_part_table"), 500.0); System.out.println("Parts:" + plan.getPartitions()); assertFalse(plan.getPartitions().isEmpty()); assertEquals(plan.getPartitions().size(), 1); assertTrue(((String) plan.getPartitions().get(dataBase + ".test_part_table").iterator().next()).contains("today")); assertTrue(((String) plan.getPartitions().get(dataBase + ".test_part_table").iterator().next()).contains("dt")); }
@Override public HiveQueryPlan 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 (HiveQueryPlan) explainCtx.getDriverContext().getDriverQueryPlan(this); } log.info("{} Explain: {}", getFullyQualifiedName(), explainCtx.getDriverQuery(this)); Configuration explainConf = new Configuration(explainCtx.getDriverConf(this)); explainConf.setClassLoader(explainCtx.getConf().getClassLoader()); explainConf.setBoolean(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, false); final String explainQuery = "EXPLAIN EXTENDED " + explainCtx.getDriverQuery(this); QueryContext explainQueryCtx = QueryContext.createContextWithSingleDriver(explainQuery, explainCtx.getSubmittedUser(), new LensConf(), explainConf, this, explainCtx.getLensSessionIdentifier(), false); InMemoryResultSet inMemoryResultSet = (InMemoryResultSet) execute(explainQueryCtx); List<String> explainOutput = new ArrayList<>(); while (inMemoryResultSet.hasNext()) { explainOutput.add((String) inMemoryResultSet.next().getValues().get(0)); } closeQuery(explainQueryCtx.getQueryHandle()); try { hiveConf.setClassLoader(explainCtx.getConf().getClassLoader()); HiveQueryPlan hqp = new HiveQueryPlan(explainOutput, null, hiveConf, calculateQueryCost(explainCtx)); explainCtx.getDriverContext().setDriverQueryPlan(this, hqp); return hqp; } catch (HiveException e) { throw new LensException("Unable to create hive query plan", e); } }
HiveDriver extends AbstractLensDriver { @Override public HiveQueryPlan 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 (HiveQueryPlan) explainCtx.getDriverContext().getDriverQueryPlan(this); } log.info("{} Explain: {}", getFullyQualifiedName(), explainCtx.getDriverQuery(this)); Configuration explainConf = new Configuration(explainCtx.getDriverConf(this)); explainConf.setClassLoader(explainCtx.getConf().getClassLoader()); explainConf.setBoolean(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, false); final String explainQuery = "EXPLAIN EXTENDED " + explainCtx.getDriverQuery(this); QueryContext explainQueryCtx = QueryContext.createContextWithSingleDriver(explainQuery, explainCtx.getSubmittedUser(), new LensConf(), explainConf, this, explainCtx.getLensSessionIdentifier(), false); InMemoryResultSet inMemoryResultSet = (InMemoryResultSet) execute(explainQueryCtx); List<String> explainOutput = new ArrayList<>(); while (inMemoryResultSet.hasNext()) { explainOutput.add((String) inMemoryResultSet.next().getValues().get(0)); } closeQuery(explainQueryCtx.getQueryHandle()); try { hiveConf.setClassLoader(explainCtx.getConf().getClassLoader()); HiveQueryPlan hqp = new HiveQueryPlan(explainOutput, null, hiveConf, calculateQueryCost(explainCtx)); explainCtx.getDriverContext().setDriverQueryPlan(this, hqp); return hqp; } catch (HiveException e) { throw new LensException("Unable to create hive query plan", e); } } }
HiveDriver extends AbstractLensDriver { @Override public HiveQueryPlan 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 (HiveQueryPlan) explainCtx.getDriverContext().getDriverQueryPlan(this); } log.info("{} Explain: {}", getFullyQualifiedName(), explainCtx.getDriverQuery(this)); Configuration explainConf = new Configuration(explainCtx.getDriverConf(this)); explainConf.setClassLoader(explainCtx.getConf().getClassLoader()); explainConf.setBoolean(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, false); final String explainQuery = "EXPLAIN EXTENDED " + explainCtx.getDriverQuery(this); QueryContext explainQueryCtx = QueryContext.createContextWithSingleDriver(explainQuery, explainCtx.getSubmittedUser(), new LensConf(), explainConf, this, explainCtx.getLensSessionIdentifier(), false); InMemoryResultSet inMemoryResultSet = (InMemoryResultSet) execute(explainQueryCtx); List<String> explainOutput = new ArrayList<>(); while (inMemoryResultSet.hasNext()) { explainOutput.add((String) inMemoryResultSet.next().getValues().get(0)); } closeQuery(explainQueryCtx.getQueryHandle()); try { hiveConf.setClassLoader(explainCtx.getConf().getClassLoader()); HiveQueryPlan hqp = new HiveQueryPlan(explainOutput, null, hiveConf, calculateQueryCost(explainCtx)); explainCtx.getDriverContext().setDriverQueryPlan(this, hqp); return hqp; } catch (HiveException e) { throw new LensException("Unable to create hive query plan", e); } } HiveDriver(); }
HiveDriver extends AbstractLensDriver { @Override public HiveQueryPlan 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 (HiveQueryPlan) explainCtx.getDriverContext().getDriverQueryPlan(this); } log.info("{} Explain: {}", getFullyQualifiedName(), explainCtx.getDriverQuery(this)); Configuration explainConf = new Configuration(explainCtx.getDriverConf(this)); explainConf.setClassLoader(explainCtx.getConf().getClassLoader()); explainConf.setBoolean(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, false); final String explainQuery = "EXPLAIN EXTENDED " + explainCtx.getDriverQuery(this); QueryContext explainQueryCtx = QueryContext.createContextWithSingleDriver(explainQuery, explainCtx.getSubmittedUser(), new LensConf(), explainConf, this, explainCtx.getLensSessionIdentifier(), false); InMemoryResultSet inMemoryResultSet = (InMemoryResultSet) execute(explainQueryCtx); List<String> explainOutput = new ArrayList<>(); while (inMemoryResultSet.hasNext()) { explainOutput.add((String) inMemoryResultSet.next().getValues().get(0)); } closeQuery(explainQueryCtx.getQueryHandle()); try { hiveConf.setClassLoader(explainCtx.getConf().getClassLoader()); HiveQueryPlan hqp = new HiveQueryPlan(explainOutput, null, hiveConf, calculateQueryCost(explainCtx)); explainCtx.getDriverContext().setDriverQueryPlan(this, hqp); return hqp; } catch (HiveException e) { throw new LensException("Unable to create hive query plan", e); } } HiveDriver(); boolean areDBResourcesAddedForSession(String sessionHandle, String database); void setResourcesAddedForSession(String sessionHandle, String database); @Override void configure(Configuration conf, String driverType, String driverName); @Override QueryCost estimate(AbstractQueryContext qctx); @Override HiveQueryPlan explain(AbstractQueryContext explainCtx); @Override DriverQueryPlan explainAndPrepare(PreparedQueryContext pContext); @Override void prepare(PreparedQueryContext pContext); @Override void closePreparedQuery(QueryPrepareHandle handle); LensResultSet execute(QueryContext ctx); @Override void executeAsync(QueryContext ctx); @Override void updateStatus(QueryContext context); @Override void closeResultSet(QueryHandle handle); @Override void closeQuery(QueryHandle handle); @Override boolean cancelQuery(QueryHandle handle); @Override void close(); @Override void registerDriverEventListener(LensEventListener<DriverEvent> driverEventListener); @Override Priority decidePriority(AbstractQueryContext ctx); @Override void registerForCompletionNotification(
    QueryContext context, long timeoutMillis, QueryCompletionListener listener); @Override void readExternal(ObjectInput in); @Override void writeExternal(ObjectOutput out); void closeSession(LensSessionHandle sessionHandle); boolean hasLensSession(LensSessionHandle session); }
HiveDriver extends AbstractLensDriver { @Override public HiveQueryPlan 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 (HiveQueryPlan) explainCtx.getDriverContext().getDriverQueryPlan(this); } log.info("{} Explain: {}", getFullyQualifiedName(), explainCtx.getDriverQuery(this)); Configuration explainConf = new Configuration(explainCtx.getDriverConf(this)); explainConf.setClassLoader(explainCtx.getConf().getClassLoader()); explainConf.setBoolean(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, false); final String explainQuery = "EXPLAIN EXTENDED " + explainCtx.getDriverQuery(this); QueryContext explainQueryCtx = QueryContext.createContextWithSingleDriver(explainQuery, explainCtx.getSubmittedUser(), new LensConf(), explainConf, this, explainCtx.getLensSessionIdentifier(), false); InMemoryResultSet inMemoryResultSet = (InMemoryResultSet) execute(explainQueryCtx); List<String> explainOutput = new ArrayList<>(); while (inMemoryResultSet.hasNext()) { explainOutput.add((String) inMemoryResultSet.next().getValues().get(0)); } closeQuery(explainQueryCtx.getQueryHandle()); try { hiveConf.setClassLoader(explainCtx.getConf().getClassLoader()); HiveQueryPlan hqp = new HiveQueryPlan(explainOutput, null, hiveConf, calculateQueryCost(explainCtx)); explainCtx.getDriverContext().setDriverQueryPlan(this, hqp); return hqp; } catch (HiveException e) { throw new LensException("Unable to create hive query plan", e); } } HiveDriver(); boolean areDBResourcesAddedForSession(String sessionHandle, String database); void setResourcesAddedForSession(String sessionHandle, String database); @Override void configure(Configuration conf, String driverType, String driverName); @Override QueryCost estimate(AbstractQueryContext qctx); @Override HiveQueryPlan explain(AbstractQueryContext explainCtx); @Override DriverQueryPlan explainAndPrepare(PreparedQueryContext pContext); @Override void prepare(PreparedQueryContext pContext); @Override void closePreparedQuery(QueryPrepareHandle handle); LensResultSet execute(QueryContext ctx); @Override void executeAsync(QueryContext ctx); @Override void updateStatus(QueryContext context); @Override void closeResultSet(QueryHandle handle); @Override void closeQuery(QueryHandle handle); @Override boolean cancelQuery(QueryHandle handle); @Override void close(); @Override void registerDriverEventListener(LensEventListener<DriverEvent> driverEventListener); @Override Priority decidePriority(AbstractQueryContext ctx); @Override void registerForCompletionNotification(
    QueryContext context, long timeoutMillis, QueryCompletionListener listener); @Override void readExternal(ObjectInput in); @Override void writeExternal(ObjectOutput out); void closeSession(LensSessionHandle sessionHandle); boolean hasLensSession(LensSessionHandle session); static final String HIVE_CONNECTION_CLASS; static final String HS2_CONNECTION_EXPIRY_DELAY; static final String HS2_CALCULATE_PRIORITY; static final String HS2_COST_CALCULATOR; static final String HS2_PRIORITY_RANGES; static final long DEFAULT_EXPIRY_DELAY; static final String HS2_PRIORITY_DEFAULT_RANGES; static final String SESSION_KEY_DELIMITER; }