### Question:
HiveDriver extends AbstractLensDriver { @Override public QueryCost estimate(AbstractQueryContext qctx) throws LensException { log.info("{} Estimate: {}", getFullyQualifiedName(), qctx.getDriverQuery(this)); if (qctx.getDriverQuery(this) == null) { throw new NullPointerException("Null driver query for " + qctx.getUserQuery()); } if (qctx.getDriverContext().getDriverQueryCost(this) != null) { return qctx.getDriverContext().getDriverQueryCost(this); } if (qctx.isOlapQuery()) { return calculateQueryCost(qctx); } else { return explain(qctx).getCost(); } } 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; }### Answer:
@Test(expectedExceptions = {UnsupportedOperationException.class}) public void testEstimateNativeQuery() throws Exception { createTestTable("test_estimate"); SessionState.setCurrentSessionState(ss); QueryCost cost = driver.estimate(createExplainContext("SELECT ID FROM test_estimate", queryConf)); assertEquals(cost.getEstimatedResourceUsage(), Double.MAX_VALUE); cost.getEstimatedExecTimeMillis(); }
@Test(expectedExceptions = {UnsupportedOperationException.class}) public void testEstimateOlapQuery() throws Exception { SessionState.setCurrentSessionState(ss); ExplainQueryContext ctx = createExplainContext("cube SELECT ID FROM test_cube", queryConf); ctx.setOlapQuery(true); ctx.getDriverContext().setDriverRewriterPlan(driver, new DriverQueryPlan() { @Override public String getPlan() { return null; } @Override public QueryCost getCost() { return null; } @Override public Map<String, Set<?>> getPartitions() { return Maps.newHashMap(); } }); QueryCost cost = driver.estimate(ctx); assertEquals(cost.getEstimatedResourceUsage(), 0.0); cost.getEstimatedExecTimeMillis(); }
@Test public void testExplainNativeFailingQuery() throws Exception { SessionState.setCurrentSessionState(ss); try { driver.estimate(createExplainContext("SELECT ID FROM nonexist", queryConf)); fail("Should not reach here"); } catch (LensException e) { assertTrue(LensUtil.getCauseMessage(e).contains("Line 1:32 Table not found 'nonexist'")); } }