Search in sources :

Example 1 with TExecuteStatementReq

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

the class ThriftCLIServiceClient method executeStatementInternal.

private OperationHandle executeStatementInternal(SessionHandle sessionHandle, String statement, Map<String, String> confOverlay, boolean isAsync, long queryTimeout) throws HiveSQLException {
    try {
        TExecuteStatementReq req = new TExecuteStatementReq(sessionHandle.toTSessionHandle(), statement);
        req.setConfOverlay(confOverlay);
        req.setRunAsync(isAsync);
        req.setQueryTimeout(queryTimeout);
        TExecuteStatementResp resp = cliService.ExecuteStatement(req);
        checkStatus(resp.getStatus());
        TProtocolVersion protocol = sessionHandle.getProtocolVersion();
        return new OperationHandle(resp.getOperationHandle(), protocol);
    } catch (HiveSQLException e) {
        throw e;
    } catch (Exception e) {
        throw new HiveSQLException(e);
    }
}
Also used : TProtocolVersion(org.apache.hive.service.rpc.thrift.TProtocolVersion) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TExecuteStatementReq(org.apache.hive.service.rpc.thrift.TExecuteStatementReq) OperationHandle(org.apache.hive.service.cli.OperationHandle) TExecuteStatementResp(org.apache.hive.service.rpc.thrift.TExecuteStatementResp) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException)

Example 2 with TExecuteStatementReq

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

the class HiveStatement method runAsyncOnServer.

private void runAsyncOnServer(String sql) throws SQLException {
    checkConnection("execute");
    closeClientOperation();
    initFlags();
    TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, sql);
    /**
     * Run asynchronously whenever possible
     * Currently only a SQLOperation can be run asynchronously,
     * in a background operation thread
     * Compilation can run asynchronously or synchronously and execution run asynchronously
     */
    execReq.setRunAsync(true);
    execReq.setConfOverlay(sessConf);
    execReq.setQueryTimeout(queryTimeout);
    try {
        TExecuteStatementResp execResp = client.ExecuteStatement(execReq);
        Utils.verifySuccessWithInfo(execResp.getStatus());
        stmtHandle = execResp.getOperationHandle();
        isExecuteStatementFailed = false;
    } catch (SQLException eS) {
        isExecuteStatementFailed = true;
        throw eS;
    } catch (Exception ex) {
        isExecuteStatementFailed = true;
        throw new SQLException(ex.toString(), "08S01", ex);
    }
}
Also used : SQLException(java.sql.SQLException) TExecuteStatementReq(org.apache.hive.service.rpc.thrift.TExecuteStatementReq) TExecuteStatementResp(org.apache.hive.service.rpc.thrift.TExecuteStatementResp) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLTimeoutException(java.sql.SQLTimeoutException) SQLException(java.sql.SQLException) TException(org.apache.thrift.TException)

Example 3 with TExecuteStatementReq

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

the class TestThriftHttpCLIServiceFeatures method verifyForwardedHeaders.

private void verifyForwardedHeaders(ArrayList<String> headerIPs, String cmd) throws Exception {
    TTransport transport;
    DefaultHttpClient hClient = new DefaultHttpClient();
    String httpUrl = getHttpUrl();
    // add an interceptor that adds the X-Forwarded-For header with given ips
    if (!headerIPs.isEmpty()) {
        Header xForwardHeader = new BasicHeader("X-Forwarded-For", Joiner.on(",").join(headerIPs));
        RequestDefaultHeaders headerInterceptor = new RequestDefaultHeaders(Arrays.asList(xForwardHeader));
        hClient.addRequestInterceptor(headerInterceptor);
    }
    // interceptor for adding username, pwd
    HttpBasicAuthInterceptor authInt = new HttpBasicAuthInterceptor(ThriftCLIServiceTest.USERNAME, ThriftCLIServiceTest.PASSWORD, null, null, false, null);
    hClient.addRequestInterceptor(authInt);
    transport = new THttpClient(httpUrl, hClient);
    TCLIService.Client httpClient = getClient(transport);
    // Create a new open session request object
    TOpenSessionReq openReq = new TOpenSessionReq();
    TOpenSessionResp openResp = httpClient.OpenSession(openReq);
    //execute a query
    TExecuteStatementReq execReq = new TExecuteStatementReq(openResp.getSessionHandle(), "show tables");
    httpClient.ExecuteStatement(execReq);
    // capture arguments to authorizer impl call and verify ip addresses passed
    ArgumentCaptor<HiveAuthzContext> contextCapturer = ArgumentCaptor.forClass(HiveAuthzContext.class);
    verify(mockedAuthorizer).checkPrivileges(any(HiveOperationType.class), Matchers.anyListOf(HivePrivilegeObject.class), Matchers.anyListOf(HivePrivilegeObject.class), contextCapturer.capture());
    HiveAuthzContext context = contextCapturer.getValue();
    System.err.println("Forwarded IP Addresses " + context.getForwardedAddresses());
    List<String> auditIPAddresses = new ArrayList<String>(context.getForwardedAddresses());
    Collections.sort(auditIPAddresses);
    Collections.sort(headerIPs);
    Assert.assertEquals("Checking forwarded IP Address", headerIPs, auditIPAddresses);
}
Also used : RequestDefaultHeaders(org.apache.http.client.protocol.RequestDefaultHeaders) HiveAuthzContext(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzContext) ArrayList(java.util.ArrayList) THttpClient(org.apache.thrift.transport.THttpClient) TExecuteStatementReq(org.apache.hive.service.rpc.thrift.TExecuteStatementReq) HiveOperationType(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveOperationType) HivePrivilegeObject(org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) TCLIService(org.apache.hive.service.rpc.thrift.TCLIService) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) TTransport(org.apache.thrift.transport.TTransport) TOpenSessionReq(org.apache.hive.service.rpc.thrift.TOpenSessionReq) TOpenSessionResp(org.apache.hive.service.rpc.thrift.TOpenSessionResp) BasicHeader(org.apache.http.message.BasicHeader) HttpBasicAuthInterceptor(org.apache.hive.jdbc.HttpBasicAuthInterceptor)

Aggregations

TExecuteStatementReq (org.apache.hive.service.rpc.thrift.TExecuteStatementReq)3 TExecuteStatementResp (org.apache.hive.service.rpc.thrift.TExecuteStatementResp)2 TException (org.apache.thrift.TException)2 SQLException (java.sql.SQLException)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 SQLTimeoutException (java.sql.SQLTimeoutException)1 ArrayList (java.util.ArrayList)1 HiveAuthzContext (org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzContext)1 HiveOperationType (org.apache.hadoop.hive.ql.security.authorization.plugin.HiveOperationType)1 HivePrivilegeObject (org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject)1 HttpBasicAuthInterceptor (org.apache.hive.jdbc.HttpBasicAuthInterceptor)1 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)1 OperationHandle (org.apache.hive.service.cli.OperationHandle)1 TCLIService (org.apache.hive.service.rpc.thrift.TCLIService)1 TOpenSessionReq (org.apache.hive.service.rpc.thrift.TOpenSessionReq)1 TOpenSessionResp (org.apache.hive.service.rpc.thrift.TOpenSessionResp)1 TProtocolVersion (org.apache.hive.service.rpc.thrift.TProtocolVersion)1 Header (org.apache.http.Header)1 RequestDefaultHeaders (org.apache.http.client.protocol.RequestDefaultHeaders)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1