org.apache.hive.service.Service Java Examples

The following examples show how to use org.apache.hive.service.Service. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HiveTester.java    From transport with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createHiveServer() {
  HiveServer2 server = new HiveServer2();
  server.init(new HiveConf());
  for (Service service : server.getServices()) {
    if (service instanceof CLIService) {
      _client = (CLIService) service;
    }
  }
  Preconditions.checkNotNull(_client, "CLI service not found in local Hive server");
  try {
    _sessionHandle = _client.openSession(null, null, null);
    _functionRegistry = SessionState.getRegistryForWrite();
    // "map_from_entries" UDF is required to create maps with non-primitive key types
    _functionRegistry.registerGenericUDF("map_from_entries", MapFromEntriesWrapper.class);
    // TODO: This is a hack. Hive's public API does not have a way to register an already created GenericUDF object
    // It only accepts a class name after which the parameterless constructor of the class is called to create a
    // GenericUDF object. This does not work for HiveTestStdUDFWrapper as it accepts the UDF classes as parameters.
    // However, Hive has an internal method which does allow passing GenericUDF objects instead of classes.
    _functionRegistryAddFunctionMethod =
        _functionRegistry.getClass().getDeclaredMethod("addFunction", String.class, FunctionInfo.class);
    _functionRegistryAddFunctionMethod.setAccessible(true);
  } catch (HiveSQLException | NoSuchMethodException e) {
    throw new RuntimeException(e);
  }
}
 
Example #2
Source File: HiveServer2Core.java    From beeju with Apache License 2.0 5 votes vote down vote up
private void waitForHiveServer2StartUp() throws InterruptedException {
  int retries = 0;
  int maxRetries = 5;
  while (hiveServer2.getServiceState() != Service.STATE.STARTED && retries < maxRetries) {
    Thread.sleep(1000);
    retries++;
  }
  if (retries >= maxRetries) {
    throw new RuntimeException("HiveServer2 did not start in a reasonable time");
  }
}
 
Example #3
Source File: HiveServer2CoreTest.java    From beeju with Apache License 2.0 5 votes vote down vote up
@Test
public void initiateServer() throws InterruptedException {
  hiveServer2Core.initialise();
  assertThat(hiveServer2Core.getJdbcConnectionUrl(),
      is("jdbc:hive2://localhost:" + hiveServer2Core.getPort() + "/" + core.databaseName()));
  assertThat(hiveServer2Core.getHiveServer2().getServiceState(), is(Service.STATE.STARTED));
}
 
Example #4
Source File: HiveServer2CoreTest.java    From beeju with Apache License 2.0 5 votes vote down vote up
@Test
public void closeServer() throws InterruptedException, IOException {
  hiveServer2Core.startServerSocket();
  hiveServer2Core.initialise();
  hiveServer2Core.shutdown();

  assertThat(hiveServer2Core.getHiveServer2().getServiceState(), is(Service.STATE.STOPPED));
}
 
Example #5
Source File: HiveEmbeddedServer2.java    From elasticsearch-hadoop with Apache License 2.0 5 votes vote down vote up
private CLIService getServiceClientInternal() {
    for (Service service : hiveServer.getServices()) {
        if (service instanceof CLIService) {
            return (CLIService) service;
        }
    }
    throw new IllegalStateException("Cannot find CLIService");
}
 
Example #6
Source File: HiveServerContainer.java    From HiveRunner with Apache License 2.0 5 votes vote down vote up
/**
 * Will start the HiveServer.
 *
 * @param testConfig Specific test case properties. Will be merged with the HiveConf of the context
 * @param hiveVars   HiveVars to pass on to the HiveServer for this session
 */
public void init(Map<String, String> testConfig, Map<String, String> hiveVars) {

    context.init();

    HiveConf hiveConf = context.getHiveConf();

    // merge test case properties with hive conf before HiveServer is started.
    for (Map.Entry<String, String> property : testConfig.entrySet()) {
        hiveConf.set(property.getKey(), property.getValue());
    }

    try {
        hiveServer2 = new HiveServer2();
        hiveServer2.init(hiveConf);

        // Locate the ClIService in the HiveServer2
        for (Service service : hiveServer2.getServices()) {
            if (service instanceof CLIService) {
                client = (CLIService) service;
            }
        }

        Preconditions.checkNotNull(client, "ClIService was not initialized by HiveServer2");

        sessionHandle = client.openSession("noUser", "noPassword", null);

        SessionState sessionState = client.getSessionManager().getSession(sessionHandle).getSessionState();
        currentSessionState = sessionState;
        currentSessionState.setHiveVariables(hiveVars);
    } catch (Exception e) {
        throw new IllegalStateException("Failed to create HiveServer :" + e.getMessage(), e);
    }

    // Ping hive server before we do anything more with it! If validation
    // is switched on, this will fail if metastorage is not set up properly
    pingHiveServer();
}