Search in sources :

Example 1 with OperationManager

use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.

the class TestSessionGlobalInitFile method doTestSessionGlobalInitFile.

/**
   * create session, and fetch the property set in global init file. Test if
   * the global init file .hiverc is loaded correctly by checking the expected
   * setting property.
   */
private void doTestSessionGlobalInitFile() throws Exception {
    OperationManager operationManager = service.getService().getSessionManager().getOperationManager();
    SessionHandle sessionHandle = client.openSession(null, null, null);
    // ensure there is no operation related object leak
    Assert.assertEquals("Verifying all operations used for init file are closed", 0, operationManager.getOperations().size());
    verifyInitProperty("a", "1", sessionHandle);
    verifyInitProperty("b", "1", sessionHandle);
    verifyInitProperty("c", "1", sessionHandle);
    verifyInitProperty("hivevar:c", "1", sessionHandle);
    verifyInitProperty("d", "1", sessionHandle);
    /**
     * TODO: client.executeStatement do not support listing resources command
     * (beeline> list jar)
     */
    // Assert.assertEquals("expected uri", api.getAddedResource("jar"));
    Assert.assertEquals("Verifying all operations used for checks are closed", 0, operationManager.getOperations().size());
    client.closeSession(sessionHandle);
}
Also used : SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationManager(org.apache.hive.service.cli.operation.OperationManager)

Example 2 with OperationManager

use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.

the class TestSessionManagerMetrics method testActiveSessionMetrics.

@Test
public void testActiveSessionMetrics() throws Exception {
    final CyclicBarrier ready = new CyclicBarrier(2);
    CyclicBarrier completed = new CyclicBarrier(2);
    String json = metrics.dumpJson();
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_ACTIVE_SESSIONS, 0);
    SessionHandle handle = sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap<String, String>());
    final HiveSession session = sm.getSession(handle);
    OperationManager operationManager = mock(OperationManager.class);
    when(operationManager.newGetTablesOperation(session, "catalog", "schema", "table", null)).thenReturn(new BlockingOperation(session, OperationType.GET_TABLES, ready, completed));
    session.setOperationManager(operationManager);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                OperationHandle handle = session.getTables("catalog", "schema", "table", null);
                session.closeOperation(handle);
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                try {
                    ready.await();
                } catch (InterruptedException | BrokenBarrierException e) {
                // ignore
                }
            }
        }
    }).start();
    ready.await(2, TimeUnit.SECONDS);
    ready.reset();
    json = metrics.dumpJson();
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_ACTIVE_SESSIONS, 1);
    completed.await(2, TimeUnit.SECONDS);
    ready.await(2, TimeUnit.SECONDS);
    json = metrics.dumpJson();
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_ACTIVE_SESSIONS, 0);
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) TimeoutException(java.util.concurrent.TimeoutException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) CyclicBarrier(java.util.concurrent.CyclicBarrier) OperationManager(org.apache.hive.service.cli.operation.OperationManager) Test(org.junit.Test)

Example 3 with OperationManager

use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.

the class HiveSessionImpl method getTableTypes.

@Override
public OperationHandle getTableTypes() throws HiveSQLException {
    acquire(true, true);
    OperationManager operationManager = getOperationManager();
    GetTableTypesOperation operation = operationManager.newGetTableTypesOperation(getSession());
    OperationHandle opHandle = operation.getHandle();
    try {
        operation.run();
        addOpHandle(opHandle);
        return opHandle;
    } catch (HiveSQLException e) {
        operationManager.closeOperation(opHandle);
        throw e;
    } finally {
        release(true, true);
    }
}
Also used : GetTableTypesOperation(org.apache.hive.service.cli.operation.GetTableTypesOperation) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) OperationManager(org.apache.hive.service.cli.operation.OperationManager) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 4 with OperationManager

use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.

the class HiveSessionImpl method getCatalogs.

@Override
public OperationHandle getCatalogs() throws HiveSQLException {
    acquire(true, true);
    OperationManager operationManager = getOperationManager();
    GetCatalogsOperation operation = operationManager.newGetCatalogsOperation(getSession());
    OperationHandle opHandle = operation.getHandle();
    try {
        operation.run();
        addOpHandle(opHandle);
        return opHandle;
    } catch (HiveSQLException e) {
        operationManager.closeOperation(opHandle);
        throw e;
    } finally {
        release(true, true);
    }
}
Also used : GetCatalogsOperation(org.apache.hive.service.cli.operation.GetCatalogsOperation) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) OperationManager(org.apache.hive.service.cli.operation.OperationManager) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 5 with OperationManager

use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.

the class HiveSessionImpl method getCrossReference.

@Override
public OperationHandle getCrossReference(String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws HiveSQLException {
    acquire(true, true);
    OperationManager operationManager = getOperationManager();
    GetCrossReferenceOperation operation = operationManager.newGetCrossReferenceOperation(getSession(), primaryCatalog, primarySchema, primaryTable, foreignCatalog, foreignSchema, foreignTable);
    OperationHandle opHandle = operation.getHandle();
    try {
        operation.run();
        addOpHandle(opHandle);
        return opHandle;
    } catch (HiveSQLException e) {
        operationManager.closeOperation(opHandle);
        throw e;
    } finally {
        release(true, true);
    }
}
Also used : GetCrossReferenceOperation(org.apache.hive.service.cli.operation.GetCrossReferenceOperation) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) OperationManager(org.apache.hive.service.cli.operation.OperationManager) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Aggregations

OperationManager (org.apache.hive.service.cli.operation.OperationManager)14 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)12 OperationHandle (org.apache.hive.service.cli.OperationHandle)12 SessionHandle (org.apache.hive.service.cli.SessionHandle)3 Test (org.junit.Test)3 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 TimeoutException (java.util.concurrent.TimeoutException)2 HashMap (java.util.HashMap)1 ServletContext (javax.servlet.ServletContext)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)1 ExecuteStatementOperation (org.apache.hive.service.cli.operation.ExecuteStatementOperation)1 GetCatalogsOperation (org.apache.hive.service.cli.operation.GetCatalogsOperation)1 GetColumnsOperation (org.apache.hive.service.cli.operation.GetColumnsOperation)1 GetCrossReferenceOperation (org.apache.hive.service.cli.operation.GetCrossReferenceOperation)1 GetFunctionsOperation (org.apache.hive.service.cli.operation.GetFunctionsOperation)1 GetPrimaryKeysOperation (org.apache.hive.service.cli.operation.GetPrimaryKeysOperation)1 GetSchemasOperation (org.apache.hive.service.cli.operation.GetSchemasOperation)1 GetTableTypesOperation (org.apache.hive.service.cli.operation.GetTableTypesOperation)1