commit c008d5c038e0d8cf94f2a6d9e30a01ac091c85ea Author: Bharath Krishna Date: Thu Apr 12 10:37:57 2018 -0700 HIVE-18469 : Introduce separate option to show query on web ui. - Adding option HIVE_SERVER2_WEBUI_EXPLAIN_OUTPUT diff --git common/src/java/org/apache/hadoop/hive/conf/HiveConf.java common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index e540d023bdda5fbb6152d7ba93c134c0542bf9dd..fd9c964279f8df9e3a520b83f2826fdaaa4ffd40 100644 --- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -2821,9 +2821,8 @@ private static void populateLlapDaemonVarsSet(Set llapDaemonVarsSetLocal " drawbacks."), HIVE_LOG_EXPLAIN_OUTPUT("hive.log.explain.output", false, - "Whether to log explain output for every query.\n" + - "When enabled, will log EXPLAIN EXTENDED output for the query at INFO log4j log level\n" + - "and in WebUI / Drilldown / Show Query."), + "Whether to log explain output for every query.\n" + + "When enabled, will log EXPLAIN EXTENDED output for the query at INFO log4j log level."), HIVE_EXPLAIN_USER("hive.explain.user", true, "Whether to show explain result at user level.\n" + "When enabled, will log EXPLAIN output for the query at user level. Tez only."), @@ -2983,6 +2982,8 @@ private static void populateLlapDaemonVarsSet(Set llapDaemonVarsSetLocal "The maximum number of past queries to show in HiverSever2 WebUI."), HIVE_SERVER2_WEBUI_USE_PAM("hive.server2.webui.use.pam", false, "If true, the HiveServer2 WebUI will be secured with PAM."), + HIVE_SERVER2_WEBUI_EXPLAIN_OUTPUT("hive.server2.webui.explain.output", false, + "When set to true, the EXPLAIN output for every query is displayed in the HS2 WebUI / Drilldown / Query Plan tab.\n"), // Tez session settings HIVE_SERVER2_ACTIVE_PASSIVE_HA_ENABLE("hive.server2.active.passive.ha.enable", false, diff --git itests/hive-unit/src/test/java/org/apache/hive/service/cli/session/TestQueryDisplay.java itests/hive-unit/src/test/java/org/apache/hive/service/cli/session/TestQueryDisplay.java index b51523fd2574c5b4b8c1dfe114b4e23bd93f2f1a..f47d2d03734198c8296cd1c6ef7881014c1d30be 100644 --- itests/hive-unit/src/test/java/org/apache/hive/service/cli/session/TestQueryDisplay.java +++ itests/hive-unit/src/test/java/org/apache/hive/service/cli/session/TestQueryDisplay.java @@ -25,7 +25,6 @@ import org.apache.hive.service.cli.OperationHandle; import org.apache.hive.service.cli.SessionHandle; import org.apache.hive.service.rpc.thrift.TProtocolVersion; -import org.apache.hive.service.server.HiveServer2; import org.apache.hive.tmpl.QueryProfileTmpl; import org.junit.Assert; import org.junit.Before; @@ -122,6 +121,36 @@ public void testWebUI() throws Exception { session.close(); } + /** + * Test for the HiveConf option HIVE_SERVER2_WEBUI_EXPLAIN_OUTPUT. + */ + @Test + public void checkWebuiExplainOutput() throws Exception { + + //check cases when HIVE_SERVER2_WEBUI_EXPLAIN_OUTPUT is set and not set + boolean[] webuiExplainConfValues = new boolean[]{true, false}; + + for(boolean confValue : webuiExplainConfValues) + { + conf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_WEBUI_EXPLAIN_OUTPUT, confValue); + HiveSession session = sessionManager + .createSession(new SessionHandle(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8), + TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8, "testuser", "", "", + new HashMap(), false, ""); + SessionState.start(conf); + + OperationHandle opHandle = session.executeStatement("show tables", null); + session.closeOperation(opHandle); + //STAGE PLANS is something which will be shown as part of EXPLAIN query + verifyDDLHtml("STAGE PLANS", opHandle.getHandleIdentifier().toString(), confValue); + //Check that the following message is not shown when this option is set + verifyDDLHtml( + "Set configuration hive.server2.webui.explain.output to true to view future query plans", + opHandle.getHandleIdentifier().toString(), !confValue); + session.close(); + } + } + private void verifyDDL(QueryInfo queryInfo, String stmt, String handle, boolean finished) { Assert.assertEquals(queryInfo.getUserName(), "testuser"); @@ -168,14 +197,18 @@ private void verifyDDL(QueryInfo queryInfo, String stmt, String handle, boolean * assert each element, to make it easier to add UI improvements. */ private void verifyDDLHtml(String stmt, String opHandle) throws Exception { + verifyDDLHtml(stmt,opHandle,true); + } + + private void verifyDDLHtml(String stmt, String opHandle, boolean assertCondition) throws Exception { StringWriter sw = new StringWriter(); QueryInfo queryInfo = sessionManager.getOperationManager().getQueryInfo( opHandle); HiveConf hiveConf = sessionManager.getOperationManager().getHiveConf(); new QueryProfileTmpl().render(sw, queryInfo, hiveConf); String html = sw.toString(); + Assert.assertEquals(assertCondition, html.contains(stmt)); - Assert.assertTrue(html.contains(stmt)); Assert.assertTrue(html.contains("testuser")); } diff --git ql/src/java/org/apache/hadoop/hive/ql/Driver.java ql/src/java/org/apache/hadoop/hive/ql/Driver.java index a88453c97835db847d74b4b4c3ef318d4d6c0ce5..3d4f21718fcb69696143a9c6da55ef60b0bdd125 100644 --- ql/src/java/org/apache/hadoop/hive/ql/Driver.java +++ ql/src/java/org/apache/hadoop/hive/ql/Driver.java @@ -689,12 +689,16 @@ public void run() { } } - if (conf.getBoolVar(ConfVars.HIVE_LOG_EXPLAIN_OUTPUT)) { + if (conf.getBoolVar(ConfVars.HIVE_LOG_EXPLAIN_OUTPUT) + || conf.getBoolVar(ConfVars.HIVE_SERVER2_WEBUI_EXPLAIN_OUTPUT)) { String explainOutput = getExplainOutput(sem, plan, tree); if (explainOutput != null) { - LOG.info("EXPLAIN output for queryid " + queryId + " : " - + explainOutput); - if (conf.isWebUiQueryInfoCacheEnabled()) { + if (conf.getBoolVar(ConfVars.HIVE_LOG_EXPLAIN_OUTPUT)) { + LOG.info("EXPLAIN output for queryid " + queryId + " : " + + explainOutput); + } + if (conf.isWebUiQueryInfoCacheEnabled() + && conf.getBoolVar(ConfVars.HIVE_SERVER2_WEBUI_EXPLAIN_OUTPUT)) { queryDisplay.setExplainPlan(explainOutput); } } diff --git service/src/jamon/org/apache/hive/tmpl/QueryProfileTmpl.jamon service/src/jamon/org/apache/hive/tmpl/QueryProfileTmpl.jamon index 366198e1470df0aef240f523bc2fa97b6dfadb71..f04d65544098f1919dba231df1e9cff7190e266a 100644 --- service/src/jamon/org/apache/hive/tmpl/QueryProfileTmpl.jamon +++ service/src/jamon/org/apache/hive/tmpl/QueryProfileTmpl.jamon @@ -204,13 +204,13 @@ org.apache.hadoop.hive.conf.HiveConf;
Explain plan
- <%if hiveConf.getBoolVar(HiveConf.ConfVars.HIVE_LOG_EXPLAIN_OUTPUT) %> + <%if hiveConf.getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_WEBUI_EXPLAIN_OUTPUT) %>
           <% queryInfo.getQueryDisplay() == null ? "Unknown" : queryInfo.getQueryDisplay().getExplainPlan() %>
           
<%else>
-          Set configuration hive.log.explain.output to true to view future query plans
+          Set configuration hive.server2.webui.explain.output to true to view future query plans