Search in sources :

Example 6 with TSessionHandle

use of org.apache.hive.service.rpc.thrift.TSessionHandle in project hive by apache.

the class TestHiveStatement method testSetFetchSizeZero.

/**
 * Gives the JDBC driver a hint as to the number of rows that should be
 * fetched from the database when more rows are needed for ResultSet objects
 * generated by this Statement. If the value specified is zero, then the hint
 * is ignored. Test for a value of zero (hint is ignored).
 */
@Test
public void testSetFetchSizeZero() throws SQLException {
    final HiveConnection connection = mock(HiveConnection.class);
    final Iface iface = mock(Iface.class);
    final TSessionHandle handle = mock(TSessionHandle.class);
    // so it falls-back to the configuration default value
    try (HiveStatement stmt = new HiveStatement(connection, iface, handle)) {
        stmt.setFetchSize(0);
        assertEquals(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_RESULTSET_DEFAULT_FETCH_SIZE.defaultIntVal, stmt.getFetchSize());
    }
}
Also used : TSessionHandle(org.apache.hive.service.rpc.thrift.TSessionHandle) Iface(org.apache.hive.service.rpc.thrift.TCLIService.Iface) Test(org.junit.Test)

Example 7 with TSessionHandle

use of org.apache.hive.service.rpc.thrift.TSessionHandle in project hive by apache.

the class TestHiveStatement method testSetFetchSize.

/**
 * Gives the JDBC driver a hint as to the number of rows that should be
 * fetched from the database when more rows are needed for ResultSet objects
 * generated by this Statement. If the value specified is zero, then the hint
 * is ignored. Test a value greater than zero is accepted.
 */
@Test
public void testSetFetchSize() throws SQLException {
    final HiveConnection connection = mock(HiveConnection.class);
    final Iface iface = mock(Iface.class);
    final TSessionHandle handle = mock(TSessionHandle.class);
    try (HiveStatement stmt = new HiveStatement(connection, iface, handle)) {
        stmt.setFetchSize(123);
        assertEquals(123, stmt.getFetchSize());
    }
}
Also used : TSessionHandle(org.apache.hive.service.rpc.thrift.TSessionHandle) Iface(org.apache.hive.service.rpc.thrift.TCLIService.Iface) Test(org.junit.Test)

Example 8 with TSessionHandle

use of org.apache.hive.service.rpc.thrift.TSessionHandle in project hive by apache.

the class SessionHandle method toTSessionHandle.

public TSessionHandle toTSessionHandle() {
    TSessionHandle tSessionHandle = new TSessionHandle();
    tSessionHandle.setSessionId(getHandleIdentifier().toTHandleIdentifier());
    return tSessionHandle;
}
Also used : TSessionHandle(org.apache.hive.service.rpc.thrift.TSessionHandle)

Example 9 with TSessionHandle

use of org.apache.hive.service.rpc.thrift.TSessionHandle in project hive by apache.

the class TestThriftCliServiceWithInfoMessage method testExecuteReturnWithInfoMessage.

@Test
public void testExecuteReturnWithInfoMessage() throws Exception {
    TTransport transport = HiveAuthUtils.getSocketTransport(host, cliPort, 0);
    try {
        transport.open();
        TCLIService.Iface client = new TCLIService.Client(new TBinaryProtocol(transport));
        TOpenSessionReq openReq = new TOpenSessionReq();
        openReq.setClient_protocol(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V11);
        TOpenSessionResp sessionResp = client.OpenSession(openReq);
        Map<String, String> serverHiveConf = sessionResp.getConfiguration();
        assertNotNull(serverHiveConf);
        assertTrue(Boolean.parseBoolean(serverHiveConf.get(ConfVars.HIVE_DEFAULT_NULLS_LAST.varname)));
        TSessionHandle sessHandle = sessionResp.getSessionHandle();
        TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, "select 1");
        execReq.setRunAsync(true);
        TExecuteStatementResp execResp = client.ExecuteStatement(execReq);
        TStatus status = execResp.getStatus();
        assertTrue(status.getStatusCode() == TStatusCode.SUCCESS_WITH_INFO_STATUS);
        assertNotNull(status.getInfoMessages());
        assertTrue(status.getInfoMessages().size() > 0);
        Pattern pattern = Pattern.compile("http://.*:(\\d+)/query_page\\.html\\?operationId=(.+)$");
        Matcher matcher = pattern.matcher(status.getInfoMessages().get(0));
        assertTrue(matcher.find());
        assertEquals(webuiPort + "", matcher.group(1));
        OperationHandle operationHandle = new OperationHandle(execResp.getOperationHandle());
        assertEquals(operationHandle.getHandleIdentifier().toString(), matcher.group(2));
        // Cancel the operation
        TCancelOperationReq cancelReq = new TCancelOperationReq();
        cancelReq.setOperationHandle(execResp.getOperationHandle());
        client.CancelOperation(cancelReq);
        // Disable showing the link
        Map<String, String> overlayConf = new HashMap<>();
        overlayConf.put(ConfVars.HIVE_SERVER2_SHOW_OPERATION_DRILLDOWN_LINK.varname, "false");
        execReq = new TExecuteStatementReq(sessHandle, "select 1");
        execReq.setRunAsync(true);
        execReq.setConfOverlay(overlayConf);
        execResp = client.ExecuteStatement(execReq);
        status = execResp.getStatus();
        assertTrue(status.getStatusCode() == TStatusCode.SUCCESS_STATUS);
        assertTrue(status.getInfoMessages() == null);
    } finally {
        transport.close();
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) TExecuteStatementReq(org.apache.hive.service.rpc.thrift.TExecuteStatementReq) OperationHandle(org.apache.hive.service.cli.OperationHandle) TCLIService(org.apache.hive.service.rpc.thrift.TCLIService) TSessionHandle(org.apache.hive.service.rpc.thrift.TSessionHandle) TCancelOperationReq(org.apache.hive.service.rpc.thrift.TCancelOperationReq) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TStatus(org.apache.hive.service.rpc.thrift.TStatus) TTransport(org.apache.thrift.transport.TTransport) TOpenSessionReq(org.apache.hive.service.rpc.thrift.TOpenSessionReq) TOpenSessionResp(org.apache.hive.service.rpc.thrift.TOpenSessionResp) TExecuteStatementResp(org.apache.hive.service.rpc.thrift.TExecuteStatementResp) Test(org.junit.Test)

Aggregations

TSessionHandle (org.apache.hive.service.rpc.thrift.TSessionHandle)9 Test (org.junit.Test)8 Iface (org.apache.hive.service.rpc.thrift.TCLIService.Iface)6 TCLIService (org.apache.hive.service.rpc.thrift.TCLIService)2 TOpenSessionReq (org.apache.hive.service.rpc.thrift.TOpenSessionReq)2 TOpenSessionResp (org.apache.hive.service.rpc.thrift.TOpenSessionResp)2 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 CodahaleMetrics (org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics)1 OperationHandle (org.apache.hive.service.cli.OperationHandle)1 TCancelOperationReq (org.apache.hive.service.rpc.thrift.TCancelOperationReq)1 TCloseSessionReq (org.apache.hive.service.rpc.thrift.TCloseSessionReq)1 TExecuteStatementReq (org.apache.hive.service.rpc.thrift.TExecuteStatementReq)1 TExecuteStatementResp (org.apache.hive.service.rpc.thrift.TExecuteStatementResp)1 TStatus (org.apache.hive.service.rpc.thrift.TStatus)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TTransport (org.apache.thrift.transport.TTransport)1