Search in sources :

Example 1 with QueryInfo

use of org.apache.hadoop.hive.ql.QueryInfo in project hive by apache.

the class TestQueryDisplay method testQueryDisplay.

/**
 * Test if query display captures information on current/historic SQL operations.
 */
@Test
public void testQueryDisplay() throws Exception {
    HiveSession session = sessionManager.createSession(new SessionHandle(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8), TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8, "testuser", "", "", new HashMap<String, String>(), false, "");
    SessionState.start(conf);
    OperationHandle opHandle1 = session.executeStatement("show databases", null);
    SessionState.start(conf);
    OperationHandle opHandle2 = session.executeStatement("show tables", null);
    List<QueryInfo> liveSqlOperations, historicSqlOperations;
    liveSqlOperations = sessionManager.getOperationManager().getLiveQueryInfos();
    historicSqlOperations = sessionManager.getOperationManager().getHistoricalQueryInfos();
    Assert.assertEquals(liveSqlOperations.size(), 2);
    Assert.assertEquals(historicSqlOperations.size(), 0);
    verifyDDL(liveSqlOperations.get(0), "show databases", opHandle1.getHandleIdentifier().toString(), false);
    verifyDDL(liveSqlOperations.get(1), "show tables", opHandle2.getHandleIdentifier().toString(), false);
    session.closeOperation(opHandle1);
    liveSqlOperations = sessionManager.getOperationManager().getLiveQueryInfos();
    historicSqlOperations = sessionManager.getOperationManager().getHistoricalQueryInfos();
    Assert.assertEquals(liveSqlOperations.size(), 1);
    Assert.assertEquals(historicSqlOperations.size(), 1);
    verifyDDL(historicSqlOperations.get(0), "show databases", opHandle1.getHandleIdentifier().toString(), true);
    verifyDDL(liveSqlOperations.get(0), "show tables", opHandle2.getHandleIdentifier().toString(), false);
    session.closeOperation(opHandle2);
    liveSqlOperations = sessionManager.getOperationManager().getLiveQueryInfos();
    historicSqlOperations = sessionManager.getOperationManager().getHistoricalQueryInfos();
    Assert.assertEquals(liveSqlOperations.size(), 0);
    Assert.assertEquals(historicSqlOperations.size(), 2);
    verifyDDL(historicSqlOperations.get(1), "show databases", opHandle1.getHandleIdentifier().toString(), true);
    verifyDDL(historicSqlOperations.get(0), "show tables", opHandle2.getHandleIdentifier().toString(), true);
    session.close();
}
Also used : SessionHandle(org.apache.hive.service.cli.SessionHandle) QueryInfo(org.apache.hadoop.hive.ql.QueryInfo) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 2 with QueryInfo

use of org.apache.hadoop.hive.ql.QueryInfo in project hive by apache.

the class TestQueryDisplay method verifyDDLHtml.

/**
 * Sanity check if basic information is delivered in this html.  Let's not go too crazy and
 * assert each element, to make it easier to add UI improvements.
 */
private void verifyDDLHtml(String stmt, String opHandle) 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.assertTrue(html.contains(stmt));
    Assert.assertTrue(html.contains("testuser"));
}
Also used : StringWriter(java.io.StringWriter) QueryProfileTmpl(org.apache.hive.tmpl.QueryProfileTmpl) HiveConf(org.apache.hadoop.hive.conf.HiveConf) QueryInfo(org.apache.hadoop.hive.ql.QueryInfo)

Example 3 with QueryInfo

use of org.apache.hadoop.hive.ql.QueryInfo in project hive by apache.

the class OperationManager method removeSafeQueryInfo.

private void removeSafeQueryInfo(OperationHandle operationHandle) {
    synchronized (webuiLock) {
        String opKey = operationHandle.getHandleIdentifier().toString();
        // remove from list of live operations
        QueryInfo display = liveQueryInfos.remove(opKey);
        if (display == null) {
            LOG.debug("Unexpected display object value of null for operation {}", opKey);
        } else if (historicalQueryInfos != null) {
            // add to list of saved historic operations
            historicalQueryInfos.put(opKey, display);
        }
    }
}
Also used : QueryInfo(org.apache.hadoop.hive.ql.QueryInfo)

Example 4 with QueryInfo

use of org.apache.hadoop.hive.ql.QueryInfo in project hive by apache.

the class QueryProfileServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String opId = (String) request.getParameter("operationId");
    ServletContext ctx = getServletContext();
    SessionManager sessionManager = (SessionManager) ctx.getAttribute("hive.sm");
    OperationManager opManager = sessionManager.getOperationManager();
    QueryInfo queryInfo = opManager.getQueryInfo(opId);
    HiveConf hiveConf = opManager.getHiveConf();
    if (queryInfo == null) {
        LOG.debug("No display object found for operation {} ", opId);
        return;
    }
    new QueryProfileTmpl().render(response.getWriter(), queryInfo, hiveConf);
}
Also used : SessionManager(org.apache.hive.service.cli.session.SessionManager) QueryProfileTmpl(org.apache.hive.tmpl.QueryProfileTmpl) ServletContext(javax.servlet.ServletContext) HiveConf(org.apache.hadoop.hive.conf.HiveConf) OperationManager(org.apache.hive.service.cli.operation.OperationManager) QueryInfo(org.apache.hadoop.hive.ql.QueryInfo)

Aggregations

QueryInfo (org.apache.hadoop.hive.ql.QueryInfo)4 HiveConf (org.apache.hadoop.hive.conf.HiveConf)2 QueryProfileTmpl (org.apache.hive.tmpl.QueryProfileTmpl)2 StringWriter (java.io.StringWriter)1 ServletContext (javax.servlet.ServletContext)1 OperationHandle (org.apache.hive.service.cli.OperationHandle)1 SessionHandle (org.apache.hive.service.cli.SessionHandle)1 OperationManager (org.apache.hive.service.cli.operation.OperationManager)1 SessionManager (org.apache.hive.service.cli.session.SessionManager)1 Test (org.junit.Test)1