@Test public void testTemptable() throws Exception { int handleSize = getHandleSize(); createTestTable("test_temp"); queryConf.setBoolean(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, false); Hive.get(hiveConf).dropTable("test_temp_output"); String query = "CREATE TABLE test_temp_output AS SELECT ID FROM test_temp"; QueryContext context = createContext(query, queryConf); LensResultSet resultSet = driver.execute(context); assertNull(resultSet); assertHandleSize(handleSize); String select = "SELECT * FROM test_temp_output"; context = createContext(select, queryConf); resultSet = driver.execute(context); assertHandleSize(handleSize); validateInMemoryResult(resultSet, "test_temp_output"); assertHandleSize(handleSize); }
public LensResultSet execute(QueryContext ctx) throws LensException { OperationHandle op = null; LensResultSet result = null; try { addPersistentPath(ctx); Configuration qdconf = ctx.getDriverConf(this); qdconf.set("mapred.job.name", ctx.getQueryHandle().toString()); SessionHandle sessionHandle = getSession(ctx); op = getClient().executeStatement(sessionHandle, ctx.getSelectedDriverQuery(), qdconf.getValByRegex(".*")); log.info("The hive operation handle: {}", op); ctx.setDriverOpHandle(op.toString()); hiveHandles.put(ctx.getQueryHandle(), op); opHandleToSession.put(op, sessionHandle); updateStatus(ctx); OperationStatus status = getClient().getOperationStatus(op); if (status.getState() == OperationState.ERROR) { throw new LensException("Unknown error while running query " + ctx.getUserQuery()); } result = createResultSet(ctx, true); if (result == null || !(result instanceof InMemoryResultSet)) { closeQuery(ctx.getQueryHandle()); } hiveHandles.remove(ctx.getQueryHandle()); } catch (IOException e) { throw new LensException("Error adding persistent path", e); } catch (HiveSQLException hiveErr) { handleHiveServerError(ctx, hiveErr); handleHiveSQLException(hiveErr); } finally { if (null != op) { opHandleToSession.remove(op); } } return result; }
HiveDriver extends AbstractLensDriver { public LensResultSet execute(QueryContext ctx) throws LensException { OperationHandle op = null; LensResultSet result = null; try { addPersistentPath(ctx); Configuration qdconf = ctx.getDriverConf(this); qdconf.set("mapred.job.name", ctx.getQueryHandle().toString()); SessionHandle sessionHandle = getSession(ctx); op = getClient().executeStatement(sessionHandle, ctx.getSelectedDriverQuery(), qdconf.getValByRegex(".*")); log.info("The hive operation handle: {}", op); ctx.setDriverOpHandle(op.toString()); hiveHandles.put(ctx.getQueryHandle(), op); opHandleToSession.put(op, sessionHandle); updateStatus(ctx); OperationStatus status = getClient().getOperationStatus(op); if (status.getState() == OperationState.ERROR) { throw new LensException("Unknown error while running query " + ctx.getUserQuery()); } result = createResultSet(ctx, true); if (result == null || !(result instanceof InMemoryResultSet)) { closeQuery(ctx.getQueryHandle()); } hiveHandles.remove(ctx.getQueryHandle()); } catch (IOException e) { throw new LensException("Error adding persistent path", e); } catch (HiveSQLException hiveErr) { handleHiveServerError(ctx, hiveErr); handleHiveSQLException(hiveErr); } finally { if (null != op) { opHandleToSession.remove(op); } } return result; } }
HiveDriver extends AbstractLensDriver { public LensResultSet execute(QueryContext ctx) throws LensException { OperationHandle op = null; LensResultSet result = null; try { addPersistentPath(ctx); Configuration qdconf = ctx.getDriverConf(this); qdconf.set("mapred.job.name", ctx.getQueryHandle().toString()); SessionHandle sessionHandle = getSession(ctx); op = getClient().executeStatement(sessionHandle, ctx.getSelectedDriverQuery(), qdconf.getValByRegex(".*")); log.info("The hive operation handle: {}", op); ctx.setDriverOpHandle(op.toString()); hiveHandles.put(ctx.getQueryHandle(), op); opHandleToSession.put(op, sessionHandle); updateStatus(ctx); OperationStatus status = getClient().getOperationStatus(op); if (status.getState() == OperationState.ERROR) { throw new LensException("Unknown error while running query " + ctx.getUserQuery()); } result = createResultSet(ctx, true); if (result == null || !(result instanceof InMemoryResultSet)) { closeQuery(ctx.getQueryHandle()); } hiveHandles.remove(ctx.getQueryHandle()); } catch (IOException e) { throw new LensException("Error adding persistent path", e); } catch (HiveSQLException hiveErr) { handleHiveServerError(ctx, hiveErr); handleHiveSQLException(hiveErr); } finally { if (null != op) { opHandleToSession.remove(op); } } return result; } HiveDriver(); }
HiveDriver extends AbstractLensDriver { public LensResultSet execute(QueryContext ctx) throws LensException { OperationHandle op = null; LensResultSet result = null; try { addPersistentPath(ctx); Configuration qdconf = ctx.getDriverConf(this); qdconf.set("mapred.job.name", ctx.getQueryHandle().toString()); SessionHandle sessionHandle = getSession(ctx); op = getClient().executeStatement(sessionHandle, ctx.getSelectedDriverQuery(), qdconf.getValByRegex(".*")); log.info("The hive operation handle: {}", op); ctx.setDriverOpHandle(op.toString()); hiveHandles.put(ctx.getQueryHandle(), op); opHandleToSession.put(op, sessionHandle); updateStatus(ctx); OperationStatus status = getClient().getOperationStatus(op); if (status.getState() == OperationState.ERROR) { throw new LensException("Unknown error while running query " + ctx.getUserQuery()); } result = createResultSet(ctx, true); if (result == null || !(result instanceof InMemoryResultSet)) { closeQuery(ctx.getQueryHandle()); } hiveHandles.remove(ctx.getQueryHandle()); } catch (IOException e) { throw new LensException("Error adding persistent path", e); } catch (HiveSQLException hiveErr) { handleHiveServerError(ctx, hiveErr); handleHiveSQLException(hiveErr); } finally { if (null != op) { opHandleToSession.remove(op); } } return result; } 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 { public LensResultSet execute(QueryContext ctx) throws LensException { OperationHandle op = null; LensResultSet result = null; try { addPersistentPath(ctx); Configuration qdconf = ctx.getDriverConf(this); qdconf.set("mapred.job.name", ctx.getQueryHandle().toString()); SessionHandle sessionHandle = getSession(ctx); op = getClient().executeStatement(sessionHandle, ctx.getSelectedDriverQuery(), qdconf.getValByRegex(".*")); log.info("The hive operation handle: {}", op); ctx.setDriverOpHandle(op.toString()); hiveHandles.put(ctx.getQueryHandle(), op); opHandleToSession.put(op, sessionHandle); updateStatus(ctx); OperationStatus status = getClient().getOperationStatus(op); if (status.getState() == OperationState.ERROR) { throw new LensException("Unknown error while running query " + ctx.getUserQuery()); } result = createResultSet(ctx, true); if (result == null || !(result instanceof InMemoryResultSet)) { closeQuery(ctx.getQueryHandle()); } hiveHandles.remove(ctx.getQueryHandle()); } catch (IOException e) { throw new LensException("Error adding persistent path", e); } catch (HiveSQLException hiveErr) { handleHiveServerError(ctx, hiveErr); handleHiveSQLException(hiveErr); } finally { if (null != op) { opHandleToSession.remove(op); } } return result; } 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; }