@Override public TExecuteStatementResp ExecuteStatement(TExecuteStatementReq req) throws TException { TExecuteStatementResp resp = new TExecuteStatementResp(); try { SessionHandle sessionHandle = new SessionHandle(req.getSessionHandle()); String statement = req.getStatement(); Map<String, String> confOverlay = req.getConfOverlay(); Boolean runAsync = req.isRunAsync(); long queryTimeout = req.getQueryTimeout(); OperationHandle operationHandle = runAsync ? cliService.executeStatementAsync(sessionHandle, statement, confOverlay, queryTimeout) : cliService.executeStatement(sessionHandle, statement, confOverlay, queryTimeout); resp.setOperationHandle(operationHandle.toTOperationHandle()); resp.setStatus(OK_STATUS); } catch (Exception e) { // Note: it's rather important that this (and other methods) catch Exception, not Throwable; // in combination with HiveSessionProxy.invoke code, perhaps unintentionally, it used // to also catch all errors; and now it allows OOMs only to propagate. LOG.warn("Error executing statement: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }
@Override protected OperationHandle executeSync(SessionHandle sessionHandle, String statement) throws HiveSQLException, ExploreException { return getCliService().executeStatement(sessionHandle, statement, ImmutableMap.<String, String>of()); }
@Override public TExecuteStatementResp ExecuteStatement(TExecuteStatementReq req) throws TException { TExecuteStatementResp resp = new TExecuteStatementResp(); try { SessionHandle sessionHandle = new SessionHandle(req.getSessionHandle()); String statement = req.getStatement(); Map<String, String> confOverlay = req.getConfOverlay(); Boolean runAsync = req.isRunAsync(); OperationHandle operationHandle = runAsync ? cliService.executeStatementAsync(sessionHandle, statement, confOverlay) : cliService.executeStatement(sessionHandle, statement, confOverlay); resp.setOperationHandle(operationHandle.toTOperationHandle()); resp.setStatus(OK_STATUS); } catch (Exception e) { LOG.warn("Error executing statement: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }
@Override protected OperationHandle executeSync(SessionHandle sessionHandle, String statement) throws HiveSQLException, ExploreException { return getCliService().executeStatement(sessionHandle, statement, ImmutableMap.<String, String>of()); }
@Override public TExecuteStatementResp ExecuteStatement(TExecuteStatementReq req) throws TException { TExecuteStatementResp resp = new TExecuteStatementResp(); try { SessionHandle sessionHandle = new SessionHandle(req.getSessionHandle()); String statement = req.getStatement(); Map<String, String> confOverlay = req.getConfOverlay(); Boolean runAsync = req.isRunAsync(); OperationHandle operationHandle = runAsync ? cliService.executeStatementAsync(sessionHandle, statement, confOverlay) : cliService.executeStatement(sessionHandle, statement, confOverlay); resp.setOperationHandle(operationHandle.toTOperationHandle()); resp.setStatus(OK_STATUS); } catch (Exception e) { LOG.warn("Error executing statement: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }
@Override protected OperationHandle executeSync(SessionHandle sessionHandle, String statement) throws HiveSQLException, ExploreException { return getCliService().executeStatement(sessionHandle, statement, ImmutableMap.<String, String>of()); }
@Override public TExecuteStatementResp ExecuteStatement(TExecuteStatementReq req) throws TException { TExecuteStatementResp resp = new TExecuteStatementResp(); try { SessionHandle sessionHandle = new SessionHandle(req.getSessionHandle()); String statement = req.getStatement(); Map<String, String> confOverlay = req.getConfOverlay(); Boolean runAsync = req.isRunAsync(); OperationHandle operationHandle = runAsync ? cliService.executeStatementAsync(sessionHandle, statement, confOverlay) : cliService.executeStatement(sessionHandle, statement, confOverlay); resp.setOperationHandle(operationHandle.toTOperationHandle()); resp.setStatus(OK_STATUS); } catch (Exception e) { LOG.warn("Error executing statement: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }
@Override protected OperationHandle executeSync(SessionHandle sessionHandle, String statement) throws HiveSQLException, ExploreException { return getCliService().executeStatement(sessionHandle, statement, ImmutableMap.<String, String>of()); }
@Override public TExecuteStatementResp ExecuteStatement(TExecuteStatementReq req) throws TException { TExecuteStatementResp resp = new TExecuteStatementResp(); try { SessionHandle sessionHandle = new SessionHandle(req.getSessionHandle()); String statement = req.getStatement(); Map<String, String> confOverlay = req.getConfOverlay(); Boolean runAsync = req.isRunAsync(); OperationHandle operationHandle = runAsync ? cliService.executeStatementAsync(sessionHandle, statement, confOverlay) : cliService.executeStatement(sessionHandle, statement, confOverlay); resp.setOperationHandle(operationHandle.toTOperationHandle()); resp.setStatus(OK_STATUS); } catch (Exception e) { LOG.warn("Error executing statement: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }
@Override protected OperationHandle executeSync(SessionHandle sessionHandle, String statement) throws HiveSQLException, ExploreException { return getCliService().executeStatement(sessionHandle, statement, new HashMap<String, String>()); }
@Override public TExecuteStatementResp ExecuteStatement(TExecuteStatementReq req) throws TException { TExecuteStatementResp resp = new TExecuteStatementResp(); try { SessionHandle sessionHandle = new SessionHandle(req.getSessionHandle()); String statement = req.getStatement(); Map<String, String> confOverlay = req.getConfOverlay(); Boolean runAsync = req.isRunAsync(); long queryTimeout = req.getQueryTimeout(); OperationHandle operationHandle = runAsync ? cliService.executeStatementAsync(sessionHandle, statement, confOverlay, queryTimeout) : cliService.executeStatement(sessionHandle, statement, confOverlay, queryTimeout); resp.setOperationHandle(operationHandle.toTOperationHandle()); resp.setStatus(OK_STATUS); } catch (Exception e) { // Note: it's rather important that this (and other methods) catch Exception, not Throwable; // in combination with HiveSessionProxy.invoke code, perhaps unintentionally, it used // to also catch all errors; and now it allows OOMs only to propagate. LOG.warn("Error executing statement: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }
@Override protected OperationHandle executeSync(SessionHandle sessionHandle, String statement) throws HiveSQLException, ExploreException { return getCliService().executeStatement(sessionHandle, statement, ImmutableMap.<String, String>of()); }
@Override protected OperationHandle executeSync(SessionHandle sessionHandle, String statement) throws HiveSQLException, ExploreException { return getCliService().executeStatement(sessionHandle, statement, ImmutableMap.<String, String>of()); }
@Override protected OperationHandle executeSync(SessionHandle sessionHandle, String statement) throws HiveSQLException, ExploreException { return getCliService().executeStatement(sessionHandle, statement, new HashMap<String, String>()); }
public List<Object[]> executeStatement(String hiveql) { try { OperationHandle handle = client.executeStatement(sessionHandle, hiveql, new HashMap<String, String>()); List<Object[]> resultSet = new ArrayList<>(); if (handle.hasResultSet()) { /* fetchResults will by default return 100 rows per fetch (hive 14). For big result sets we need to continuously fetch the result set until all rows are fetched. */ RowSet rowSet; while ((rowSet = client.fetchResults(handle)) != null && rowSet.numRows() > 0) { for (Object[] row : rowSet) { resultSet.add(row.clone()); } } } LOGGER.debug("ResultSet:\n" + Joiner.on("\n").join(Iterables.transform(resultSet, new Function<Object[], String>() { @Nullable @Override public String apply(@Nullable Object[] objects) { return Joiner.on(", ").useForNull("null").join(objects); } }))); return resultSet; } catch (HiveSQLException e) { throw new IllegalArgumentException("Failed to executeQuery Hive query " + hiveql + ": " + e.getMessage(), e); } }
public List<Object[]> executeStatement(String hiveql) { try { OperationHandle handle = client.executeStatement(sessionHandle, hiveql, new HashMap<String, String>()); List<Object[]> resultSet = new ArrayList<>(); if (handle.hasResultSet()) { /* fetchResults will by default return 100 rows per fetch (hive 14). For big result sets we need to continuously fetch the result set until all rows are fetched. */ RowSet rowSet; while ((rowSet = client.fetchResults(handle)) != null && rowSet.numRows() > 0) { for (Object[] row : rowSet) { resultSet.add(row.clone()); } } } LOGGER.debug("ResultSet:\n" + Joiner.on("\n").join(Iterables.transform(resultSet, new Function<Object[], String>() { @Nullable @Override public String apply(@Nullable Object[] objects) { return Joiner.on(", ").useForNull("null").join(objects); } }))); return resultSet; } catch (HiveSQLException e) { throw new IllegalArgumentException("Failed to executeQuery Hive query " + hiveql + ": " + e.getMessage(), e); } }
@Override protected SessionHandle doOpenHiveSession(Map<String, String> sessionConf) throws HiveSQLException { SessionHandle sessionHandle = super.doOpenHiveSession(sessionConf); // HDP Hive 12 only sets SessionState when an operation is executed. // The SessionState is not set during an openSession call. // Hence execute a dummy statement during openSession, so that SessionState gets set. OperationHandle opHandle = null; try { opHandle = getCliService().executeStatement(sessionHandle, "set cdap_tmp_var=1", Collections.<String, String>emptyMap()); } catch (Throwable t) { LOG.error("Error setting temporary variable to set session state", t); } finally { if (opHandle != null) { try { getCliService().closeOperation(opHandle); } catch (Throwable t) { LOG.debug("Caught exception while closing opHandle", t); } } } return sessionHandle; } }
@Override protected SessionHandle doOpenHiveSession(Map<String, String> sessionConf) throws HiveSQLException { SessionHandle sessionHandle = super.doOpenHiveSession(sessionConf); // HDP Hive 12 only sets SessionState when an operation is executed. // The SessionState is not set during an openSession call. // Hence execute a dummy statement during openSession, so that SessionState gets set. OperationHandle opHandle = null; try { opHandle = getCliService().executeStatement(sessionHandle, "set cdap_tmp_var=1", Collections.<String, String>emptyMap()); } catch (Throwable t) { LOG.error("Error setting temporary variable to set session state", t); } finally { if (opHandle != null) { try { getCliService().closeOperation(opHandle); } catch (Throwable t) { LOG.debug("Caught exception while closing opHandle", t); } } } return sessionHandle; } }
/** * Sets the session parameter. * * @param sessionid the sessionid * @param config map of string-string. each entry represents key and the value to be set for that key */ protected void setSessionParameters(LensSessionHandle sessionid, Map<String, String> config) { log.info("Request to Set params:" + config); try { acquire(sessionid); // set in session conf for(Map.Entry<String, String> entry: config.entrySet()) { String var = entry.getKey(); if (var.indexOf(SystemVariables.HIVECONF_PREFIX) == 0) { var = var.substring(SystemVariables.HIVECONF_PREFIX.length()); } getSession(sessionid).getSessionConf().set(var, entry.getValue()); String command = "set" + " " + entry.getKey() + "= " + entry.getValue(); closeCliServiceOp(getCliService().executeStatement(getHiveSessionHandle(sessionid), command, null)); } // add to persist getSession(sessionid).setConfig(config); log.info("Set params:" + config); } catch (HiveSQLException e) { throw new WebApplicationException(e); } finally { release(sessionid); } }
/** * {@inheritDoc} */ @Override public void deleteResource(LensSessionHandle sessionid, String type, String path) { String command = "delete " + type.toLowerCase() + " " + path; try { acquire(sessionid); closeCliServiceOp(getCliService().executeStatement(getHiveSessionHandle(sessionid), command, null)); getSession(sessionid).removeResource(type, path); try { LENS_SERVER_DAO.updateActiveSession(getSession(sessionid).getLensSessionPersistInfo()); } catch (LensException e) { log.warn("Failed to update active session table with error," + e.toString()); } } catch (HiveSQLException e) { throw new WebApplicationException(e); } finally { release(sessionid); } }