@Override public RowSet fetchResults(OperationHandle opHandle) throws HiveSQLException { return fetchResults( opHandle, FetchOrientation.FETCH_NEXT, defaultFetchRows, FetchType.QUERY_OUTPUT); }
@Override public void closeSession(SessionHandle sessionHandle) throws HiveSQLException { try { TCloseSessionReq req = new TCloseSessionReq(sessionHandle.toTSessionHandle()); TCloseSessionResp resp = cliService.CloseSession(req); checkStatus(resp.getStatus()); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }
@Override public OperationHandle executeStatementAsync(SessionHandle sessionHandle, String statement, Map<String, String> confOverlay) throws HiveSQLException { return executeStatementInternal(sessionHandle, statement, confOverlay, true, 0); }
@Test public void testSessionHook () throws Exception { // create session, test if the hook got fired by checking the expected property SessionHandle sessionHandle = client.openSession(sessionUserName, "foobar", Collections.<String, String>emptyMap()); Assert.assertEquals(1, SessionHookTest.runCount.get()); client.closeSession(sessionHandle); }
@Test public void testGetFunctions() throws Exception { SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>()); assertNotNull("Session handle should not be null", sessHandle); String catalogName = null; String schemaName = null; String functionName = "*"; OperationHandle opHandle = client.getFunctions(sessHandle, catalogName, schemaName, functionName); assertNotNull("Operation handle should not be null", opHandle); client.closeSession(sessHandle); }
private void verifyInitProperty(String key, String value, SessionHandle sessionHandle) throws Exception { OperationHandle operationHandle = client.executeStatement(sessionHandle, "set " + key, null); RowSet rowSet = client.fetchResults(operationHandle); Assert.assertEquals(1, rowSet.numRows()); // we know rowSet has only one element Assert.assertEquals(key + "=" + value, rowSet.iterator().next()[0]); client.closeOperation(operationHandle); } }
Map<String, String> opConf = new HashMap<String, String>(); SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, opConf); client.executeStatement(sessHandle, queryString, opConf); client.executeStatement(sessHandle, queryString, opConf); client.executeStatement(sessHandle, queryString, opConf); OperationHandle opHandle = client.executeStatement(sessHandle, queryString, opConf); assertNotNull(opHandle); OperationStatus opStatus = client.getOperationStatus(opHandle, false); assertNotNull(opStatus); client.executeStatement(sessHandle, queryString, opConf); client.closeSession(sessHandle);
@Test // This is to test session temporary files are cleaned up after HIVE-11768 public void testTempSessionFileCleanup() throws Exception { EmbeddedThriftBinaryCLIService service = new EmbeddedThriftBinaryCLIService(); HiveConf hiveConf = new HiveConf(); hiveConf .setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory"); service.init(hiveConf); ThriftCLIServiceClient client = new ThriftCLIServiceClient(service); Set<String> existingPipeoutFiles = new HashSet<String>(Arrays.asList(getPipeoutFiles())); SessionHandle sessionHandle = client.openSession("user1", "foobar", Collections.<String, String>emptyMap()); client.executeStatement(sessionHandle, "set a=b", null); File operationLogRootDir = new File( new HiveConf().getVar(ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LOG_LOCATION)); Assert.assertNotEquals(operationLogRootDir.list().length, 0); client.closeSession(sessionHandle); // Check if session files are removed Assert.assertEquals(operationLogRootDir.list().length, 0); // Check if the pipeout files are removed Set<String> finalPipeoutFiles = new HashSet<String>(Arrays.asList(getPipeoutFiles())); finalPipeoutFiles.removeAll(existingPipeoutFiles); Assert.assertTrue(finalPipeoutFiles.isEmpty()); }
static ThriftCLIServiceClient getServiceClientInternal() { for (Service service : hiveServer2.getServices()) { if (service instanceof ThriftBinaryCLIService) { return new ThriftCLIServiceClient((ThriftBinaryCLIService) service); } if (service instanceof ThriftHttpCLIService) { return new ThriftCLIServiceClient((ThriftHttpCLIService) service); } } throw new IllegalStateException("HiveServer2 not running Thrift service"); }
@Test public void testSessionImplWithUGI() throws Exception { HiveConf hiveConf = new HiveConf(); hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER.getDefaultValue()); hiveConf.setVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_WITH_UGI_CLASSNAME, SampleHiveSessionImplWithUGI.class.getName()); hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS, true); CLIService cliService = new CLIService(null, true); cliService.init(hiveConf); ThriftBinaryCLIService service = new ThriftBinaryCLIService(cliService, null); service.init(hiveConf); ThriftCLIServiceClient client = new ThriftCLIServiceClient(service); SessionHandle sessionHandle = null; sessionHandle = client.openSession("tom", "password"); assertEquals(SampleHiveSessionImplWithUGI.class.getName(), service.getHiveConf().getVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_WITH_UGI_CLASSNAME)); HiveSession session = cliService.getSessionManager().getSession(sessionHandle); assertEquals(SampleHiveSessionImplWithUGI.MAGIC_RETURN_VALUE, session.getNoOperationTime()); client.closeSession(sessionHandle); }
public void closeSession(SessionHandle sessionHandle) throws HiveSQLException { try (SessionStateContext ignored = new SessionStateContext()) { super.closeSession(sessionHandle); } }
public void closeOperation(OperationHandle opHandle) throws HiveSQLException { try (SessionStateContext ignored = new SessionStateContext()) { super.closeOperation(opHandle); } }
public OperationHandle executeStatementAsync(SessionHandle sessionHandle, String statement, Map<String, String> confOverlay) throws HiveSQLException { try (SessionStateContext ignored = new SessionStateContext()) { return super.executeStatementAsync(sessionHandle, statement, confOverlay); } }
public OperationHandle executeStatement(SessionHandle sessionHandle, String statement, Map<String, String> confOverlay) throws HiveSQLException { try (SessionStateContext ignored = new SessionStateContext()) { return super.executeStatement(sessionHandle, statement, confOverlay); } }
Map<String, String> opConf = new HashMap<String, String>(); SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, opConf); client.executeStatement(sessHandle, queryString, opConf); client.executeStatement(sessHandle, queryString, opConf); client.executeStatement(sessHandle, queryString, opConf); OperationHandle opHandle = client.executeStatement(sessHandle, queryString, opConf); assertNotNull(opHandle); OperationStatus opStatus = client.getOperationStatus(opHandle, false); assertNotNull(opStatus); client.executeStatement(sessHandle, queryString, opConf); client.closeSession(sessHandle);
protected static ThriftCLIServiceClient getServiceClientInternal() { for (Service service : hiveServer2.getServices()) { if (service instanceof ThriftBinaryCLIService) { return new ThriftCLIServiceClient((ThriftBinaryCLIService) service); } if (service instanceof ThriftHttpCLIService) { return new ThriftCLIServiceClient((ThriftHttpCLIService) service); } } throw new IllegalStateException("HiveServer2 not running Thrift service"); }
@Test public void testSessionImpl() throws Exception { HiveConf hiveConf = new HiveConf(); hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER.getDefaultValue()); hiveConf.setVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_CLASSNAME, SampleHiveSessionImpl.class.getName()); hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS, false); CLIService cliService = new CLIService(null, true); cliService.init(hiveConf); ThriftBinaryCLIService service = new ThriftBinaryCLIService(cliService, null); service.init(hiveConf); ThriftCLIServiceClient client = new ThriftCLIServiceClient(service); SessionHandle sessionHandle = null; sessionHandle = client.openSession("tom", "password"); assertEquals(SampleHiveSessionImpl.class.getName(), service.getHiveConf().getVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_CLASSNAME)); HiveSession session = cliService.getSessionManager().getSession(sessionHandle); assertEquals(SampleHiveSessionImpl.MAGIC_RETURN_VALUE, session.getNoOperationTime()); client.closeSession(sessionHandle); }
@Test public void testOpenSession() throws Exception { // Open a new client session SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>()); // Session handle should not be null assertNotNull("Session handle should not be null", sessHandle); // Close client session client.closeSession(sessHandle); }
@Test public void testGetFunctions() throws Exception { SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>()); assertNotNull("Session handle should not be null", sessHandle); String catalogName = null; String schemaName = null; String functionName = "*"; OperationHandle opHandle = client.getFunctions(sessHandle, catalogName, schemaName, functionName); assertNotNull("Operation handle should not be null", opHandle); client.closeSession(sessHandle); }
public void closeSession(SessionHandle sessionHandle) throws HiveSQLException { try (SessionStateContext ignored = new SessionStateContext()) { super.closeSession(sessionHandle); } }