public Driver(QueryState queryState, String userName, QueryInfo queryInfo, HiveTxnManager txnMgr) { this.queryState = queryState; this.conf = queryState.getConf(); this.userName = userName; this.hookRunner = new HookRunner(conf, console); this.queryInfo = queryInfo; this.initTxnMgr = txnMgr; }
public void runFailureHooks(HookContext hookContext) throws HiveException { initialize(); invokeGeneralHook(onFailureHooks, PerfLogger.FAILURE_HOOK, hookContext); }
public void initialize() { if (initialized) { return; } initialized = true; queryHooks.addAll(loadHooksFromConf(HiveConf.ConfVars.HIVE_QUERY_LIFETIME_HOOKS, QueryLifeTimeHook.class)); saHooks.addAll(loadHooksFromConf(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK, HiveSemanticAnalyzerHook.class)); driverRunHooks.addAll(loadHooksFromConf(HiveConf.ConfVars.HIVE_DRIVER_RUN_HOOKS, HiveDriverRunHook.class)); preExecHooks.addAll(loadHooksFromConf(HiveConf.ConfVars.PREEXECHOOKS, ExecuteWithHookContext.class)); postExecHooks.addAll(loadHooksFromConf(HiveConf.ConfVars.POSTEXECHOOKS, ExecuteWithHookContext.class)); onFailureHooks.addAll(loadHooksFromConf(HiveConf.ConfVars.ONFAILUREHOOKS, ExecuteWithHookContext.class)); if (conf.getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_METRICS_ENABLED)) { queryHooks.add(new MetricsQueryLifeTimeHook()); } }
hookRunner.runBeforeParseHook(command); throw e; } finally { hookRunner.runAfterParseHook(command, parseError); hookRunner.runBeforeCompileHook(command); boolean executeHooks = hookRunner.hasPreAnalyzeHooks(); hookCtx.setHiveOperation(queryState.getHiveOperation()); tree = hookRunner.runPreAnalyzeHooks(hookCtx, tree); hookRunner.runPostAnalyzeHooks(hookCtx, sem.getAllRootTasks()); hookRunner.runAfterCompilationHook(command, compileError); } catch (Exception e) { LOG.warn("Failed when invoking query after-compilation hook.", e);
public void runPostDriverHooks(HiveDriverRunHookContext hookContext) throws HiveException { initialize(); try { for (HiveDriverRunHook driverRunHook : driverRunHooks) { driverRunHook.postDriverRun(hookContext); } } catch (HiveException e) { throw e; } catch (Exception e) { throw new HiveException("Error while invoking PostDriverHooks:" + HiveStringUtils.stringifyException(e), e); } }
@Override public void initialize(Driver driver) { coreDriver = driver; coreDriver.getHookRunner().addOnFailureHook(new LocalHook()); statsReaderHook = new OperatorStatsReaderHook(); coreDriver.getHookRunner().addOnFailureHook(statsReaderHook); coreDriver.getHookRunner().addPostHook(statsReaderHook); alwaysCollectStats = driver.getConf().getBoolVar(ConfVars.HIVE_QUERY_REEXECUTION_ALWAYS_COLLECT_OPERATOR_STATS); statsReaderHook.setCollectOnSuccess(alwaysCollectStats); coreDriver.setStatsSource(StatsSources.getStatsSource(driver.getConf())); }
@Test public void testQueryLifeTimeWithParseHooksWithParseError() throws Exception { String query = "invalidquery"; ArgumentMatcher<QueryLifeTimeHookContext> argMatcher = new QueryLifeTimeHookContextMatcher(query); QueryLifeTimeHookWithParseHooks mockHook = mock(QueryLifeTimeHookWithParseHooks.class); Driver driver = createDriver(); driver.getHookRunner().addLifeTimeHook(mockHook); int ret = driver.run(query).getResponseCode(); assertNotEquals("Expected parsing to fail", 0, ret); verify(mockHook).beforeParse(argThat(argMatcher)); verify(mockHook).afterParse(argThat(argMatcher), eq(true)); verify(mockHook, never()).beforeCompile(any()); verify(mockHook, never()).afterCompile(any(), anyBoolean()); verify(mockHook, never()).beforeExecution(any()); verify(mockHook, never()).afterExecution(any(), anyBoolean()); }
public ReExecDriver(QueryState queryState, String userName, QueryInfo queryInfo, ArrayList<IReExecutionPlugin> plugins) { this.queryState = queryState; coreDriver = new Driver(queryState, userName, queryInfo, null); coreDriver.getHookRunner().addSemanticAnalyzerHook(new HandleReOptimizationExplain()); this.plugins = plugins; for (IReExecutionPlugin p : plugins) { p.initialize(coreDriver); } }
@Override public void initialize(Driver driver) { this.driver = driver; driver.getHookRunner().addOnFailureHook(new LocalHook()); HiveConf conf = driver.getConf(); subtree = conf.subtree("reexec.overlay"); }
public void runPreDriverHooks(HiveDriverRunHookContext hookContext) throws HiveException { initialize(); try { for (HiveDriverRunHook driverRunHook : driverRunHooks) { driverRunHook.preDriverRun(hookContext); } } catch (HiveException e) { throw e; } catch (Exception e) { throw new HiveException("Error while invoking PreDriverHooks:" + HiveStringUtils.stringifyException(e), e); } }
@Test public void testQueryLifeTimeWithCompileError() throws Exception { String query = "select * from foo"; ArgumentMatcher<QueryLifeTimeHookContext> argMatcher = new QueryLifeTimeHookContextMatcher(query); QueryLifeTimeHook mockHook = mock(QueryLifeTimeHook.class); Driver driver = createDriver(); driver.getHookRunner().addLifeTimeHook(mockHook); int ret = driver.run(query).getResponseCode(); assertNotEquals("Expected compilation to fail", 0, ret); verify(mockHook).beforeCompile(argThat(argMatcher)); verify(mockHook).afterCompile(argThat(argMatcher), eq(true)); verify(mockHook, never()).beforeExecution(any()); verify(mockHook, never()).afterExecution(any(), anyBoolean()); }
public void runPreHooks(HookContext hookContext) throws HiveException { initialize(); invokeGeneralHook(preExecHooks, PerfLogger.PRE_HOOK, hookContext); }
public ASTNode runPreAnalyzeHooks(HiveSemanticAnalyzerHookContext hookCtx, ASTNode tree) throws HiveException { initialize(); try { for (HiveSemanticAnalyzerHook hook : saHooks) { tree = hook.preAnalyze(hookCtx, tree); } return tree; } catch (HiveException e) { throw e; } catch (Exception e) { throw new HiveException("Error while invoking PreAnalyzeHooks:" + HiveStringUtils.stringifyException(e), e); } }
@Test public void testQueryLifeTimeWithParseHooksWithCompileError() throws Exception { String query = "select * from foo"; ArgumentMatcher<QueryLifeTimeHookContext> argMatcher = new QueryLifeTimeHookContextMatcher(query); QueryLifeTimeHookWithParseHooks mockHook = mock(QueryLifeTimeHookWithParseHooks.class); Driver driver = createDriver(); driver.getHookRunner().addLifeTimeHook(mockHook); int ret = driver.run(query).getResponseCode(); assertNotEquals("Expected compilation to fail", 0, ret); verify(mockHook).beforeParse(argThat(argMatcher)); verify(mockHook).afterParse(argThat(argMatcher), eq(false)); verify(mockHook).beforeCompile(argThat(argMatcher)); verify(mockHook).afterCompile(argThat(argMatcher), eq(true)); verify(mockHook, never()).beforeExecution(any()); verify(mockHook, never()).afterExecution(any(), anyBoolean()); }
public void runPostExecHooks(HookContext hookContext) throws HiveException { initialize(); invokeGeneralHook(postExecHooks, PerfLogger.POST_HOOK, hookContext); }
public void runPostAnalyzeHooks(HiveSemanticAnalyzerHookContext hookCtx, List<Task<? extends Serializable>> allRootTasks) throws HiveException { initialize(); try { for (HiveSemanticAnalyzerHook hook : saHooks) { hook.postAnalyze(hookCtx, allRootTasks); } } catch (HiveException e) { throw e; } catch (Exception e) { throw new HiveException("Error while invoking PostAnalyzeHooks:" + HiveStringUtils.stringifyException(e), e); } }
@Test public void testAllQueryLifeTimeHooks() throws Exception { String query = "select 1"; ArgumentMatcher<QueryLifeTimeHookContext> argMatcher = new QueryLifeTimeHookContextMatcher(query); QueryLifeTimeHook mockHook = mock(QueryLifeTimeHook.class); Driver driver = createDriver(); driver.getHookRunner().addLifeTimeHook(mockHook); int ret = driver.run(query).getResponseCode(); assertEquals("Expected query to succeed", 0, ret); verify(mockHook).beforeCompile(argThat(argMatcher)); verify(mockHook).afterCompile(argThat(argMatcher), eq(false)); verify(mockHook).beforeExecution(argThat(argMatcher)); verify(mockHook).afterExecution(argThat(argMatcher), eq(false)); }
/** * Dispatches {@link QueryLifeTimeHook#afterCompile(QueryLifeTimeHookContext, boolean)}. * * @param command the Hive command that is being run * @param compileError true if there was an error while compiling the command, false otherwise */ void runAfterCompilationHook(String command, boolean compileError) { initialize(); if (!queryHooks.isEmpty()) { QueryLifeTimeHookContext qhc = new QueryLifeTimeHookContextImpl.Builder().withHiveConf(conf).withCommand(command).build(); for (QueryLifeTimeHook hook : queryHooks) { hook.afterCompile(qhc, compileError); } } }
@Test public void testAllQueryLifeTimeWithParseHooks() throws Exception { String query = "select 1"; ArgumentMatcher<QueryLifeTimeHookContext> argMatcher = new QueryLifeTimeHookContextMatcher(query); QueryLifeTimeHookWithParseHooks mockHook = mock(QueryLifeTimeHookWithParseHooks.class); Driver driver = createDriver(); driver.getHookRunner().addLifeTimeHook(mockHook); int ret = driver.run(query).getResponseCode(); assertEquals("Expected query to succeed", 0, ret); verify(mockHook).beforeParse(argThat(argMatcher)); verify(mockHook).afterParse(argThat(argMatcher), eq(false)); verify(mockHook).beforeCompile(argThat(argMatcher)); verify(mockHook).afterCompile(argThat(argMatcher), eq(false)); verify(mockHook).beforeExecution(argThat(argMatcher)); verify(mockHook).afterExecution(argThat(argMatcher), eq(false)); }
/** * Dispatches {@link QueryLifeTimeHook#beforeCompile(QueryLifeTimeHookContext)}. * * @param command the Hive command that is being run */ void runBeforeCompileHook(String command) { initialize(); if (!queryHooks.isEmpty()) { QueryLifeTimeHookContext qhc = new QueryLifeTimeHookContextImpl.Builder().withHiveConf(conf).withCommand(command).build(); for (QueryLifeTimeHook hook : queryHooks) { hook.beforeCompile(qhc); } } }