Package org.apache.hadoop.hive.service

Examples of org.apache.hadoop.hive.service.HiveClient


    @Override
    public void start() throws Exception {
        log.info(String.format("Starting Hive Thrift/Client on [%s][%d]...", host, port));

        TSocket transport = new TSocket(host, port, (int) TimeUnit.MINUTES.toMillis(2));
        client = new HiveClient(new TBinaryProtocol(transport));
        transport.open();
    }
View Full Code Here


    return true;
  }

  protected HiveClient createHiveClient() {
    TSocket transport = new TSocket(host, port, timeout);
    HiveClient hive = new HiveClient(new TBinaryProtocol(transport));

    try {
      transport.open();

      if (!CollectionUtils.isEmpty(scripts)) {
View Full Code Here

   * @throws DataAccessException exception
   */
  @Override
  public <T> T execute(HiveClientCallback<T> action) throws DataAccessException {
    Assert.notNull(action, "a valid callback is required");
    HiveClient hiveClient = createHiveClient();
    try {
      return action.doInHive(hiveClient);
    } catch (Exception ex) {
      throw convertHiveAccessException(ex);
    } finally {
      try {
        hiveClient.shutdown();
      } catch (Exception ex) {
        // ignore for now
      }
    }
  }
View Full Code Here

      }
      catch (Exception e) {
      }
      TTransport transport = new TSocket(host, port);
      TProtocol protocol = new TBinaryProtocol(transport);
      client = new HiveClient(protocol);
      transport.open();
    }
  }
View Full Code Here

    super.setUp();
    if (standAloneServer) {
      try {
        transport = new TSocket(host, port);
        TProtocol protocol = new TBinaryProtocol(transport);
        client = new HiveClient(protocol);
        transport.open();
      }
      catch (Throwable e) {
        e.printStackTrace();
      }
View Full Code Here

    }

    @Override
    public HiveClient getClient() {

      HiveClient result = mock(HiveClient.class);
      if (ClientResult.RETURN_OK.equals(this.result)) {
        List<String> fetchResult = new ArrayList<String>(1);
        fetchResult.add("test result");
        try {
          when(result.fetchN(anyInt())).thenReturn(fetchResult);
        } catch (HiveServerException e) {
        } catch (Exception e) {
        }
      } else if (ClientResult.RETURN_SERVER_EXCEPTION.equals(this.result)) {
        HiveServerException exception = new HiveServerException("test HiveServerException", 10,
            "sql state");
        try {
          when(result.fetchN(anyInt())).thenThrow(exception);

          when(result.fetchN(anyInt())).thenThrow(exception);
        } catch (TException e) {
          ;
        }
        return result;
      } else if (ClientResult.RETURN_T_EXCEPTION.equals(this.result)) {
        TException exception = new TException("test TException");
        try {
          // org.mockito.Mockito.
          doThrow(exception).when(result).clean();
          when(result.fetchN(anyInt())).thenThrow(exception);
        } catch (TException e) {
          e.printStackTrace();
        }
        return result;
      }
View Full Code Here

        if (s != null && !s.isEmpty()) {
          ss.out.println(StringUtils.join(s, "\n"));
        }
      }
    } else if (ss.isRemoteMode()) { // remote mode -- connecting to remote hive server
      HiveClient client = ss.getClient();
      PrintStream out = ss.out;
      PrintStream err = ss.err;

      try {
        client.execute(cmd_trimmed);
        List<String> results;
        do {
          results = client.fetchN(LINES_TO_FETCH);
          for (String line : results) {
            out.println(line);
          }
        } while (results.size() == LINES_TO_FETCH);
      } catch (HiveServerException e) {
        ret = e.getErrorCode();
        if (ret != 0) { // OK if ret == 0 -- reached the EOF
          String errMsg = e.getMessage();
          if (errMsg == null) {
            errMsg = e.toString();
          }
          ret = e.getErrorCode();
          err.println("[Hive Error]: " + errMsg);
        }
      } catch (TException e) {
        String errMsg = e.getMessage();
        if (errMsg == null) {
          errMsg = e.toString();
        }
        ret = -10002;
        err.println("[Thrift Error]: " + errMsg);
      } finally {
        try {
          client.clean();
        } catch (TException e) {
          String errMsg = e.getMessage();
          if (errMsg == null) {
            errMsg = e.toString();
          }
View Full Code Here

        port = Integer.parseInt(hostport[1]);
      } catch (Exception e) {
      }
      transport = new TSocket(host, port);
      TProtocol protocol = new TBinaryProtocol(transport);
      client = new HiveClient(protocol);
      try {
        transport.open();
      } catch (TTransportException e) {
        throw new SQLException("Could not establish connecton to "
            + originalUri + ": " + e.getMessage(), "08S01");
View Full Code Here

        if (s != null && !s.isEmpty()) {
          ss.out.println(StringUtils.join(s, "\n"));
        }
      }
    } else if (ss.isRemoteMode()) { // remote mode -- connecting to remote hive server
      HiveClient client = ss.getClient();
      PrintStream out = ss.out;
      PrintStream err = ss.err;

      try {
        client.execute(cmd_trimmed);
        List<String> results;
        do {
          results = client.fetchN(LINES_TO_FETCH);
          for (String line : results) {
            out.println(line);
          }
        } while (results.size() == LINES_TO_FETCH);
      } catch (HiveServerException e) {
        ret = e.getErrorCode();
        if (ret != 0) { // OK if ret == 0 -- reached the EOF
          String errMsg = e.getMessage();
          if (errMsg == null) {
            errMsg = e.toString();
          }
          ret = e.getErrorCode();
          err.println("[Hive Error]: " + errMsg);
        }
      } catch (TException e) {
        String errMsg = e.getMessage();
        if (errMsg == null) {
          errMsg = e.toString();
        }
        ret = -10002;
        err.println("[Thrift Error]: " + errMsg);
      } finally {
        try {
          client.clean();
        } catch (TException e) {
          String errMsg = e.getMessage();
          if (errMsg == null) {
            errMsg = e.toString();
          }
View Full Code Here

   * Connect to Hive Server
   */
  public void connect() throws TTransportException {
    transport = new TSocket(host, port);
    TProtocol protocol = new TBinaryProtocol(transport);
    client = new HiveClient(protocol);
    transport.open();
    remoteMode = true;
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.service.HiveClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.