/** * start a new session and set it to current session. */ public static SessionState start(HiveConf conf) { SessionState ss = new SessionState(conf); return start(ss); }
/** * start a new session and set it to current session. */ public static SessionState start(HiveConf conf) { SessionState ss = new SessionState(conf); return start(ss); }
@Override public void preDriverRun(HiveDriverRunHookContext hookContext) throws Exception { SessionState sess = new SessionState((HiveConf)hookContext.getConf()); PrintStream stream = sess.getConsole().getOutStream(); stream.println(hookContext.getCommand()); }
private void applyAuthorizationConfigPolicy(HiveConf newHiveConf) throws HiveException, MetaException { // authorization setup using SessionState should be revisited eventually, as // authorization and authentication are not session specific settings SessionState ss = new SessionState(newHiveConf); ss.setIsHiveServerQuery(true); SessionState.start(ss); ss.applyAuthorizationPolicy(); }
@Override public void preDriverRun(HiveDriverRunHookContext hookContext) throws Exception { SessionState sess = new SessionState((HiveConf)hookContext.getConf()); PrintStream stream = sess.getConsole().getOutStream(); stream.println(hookContext.getCommand()); }
@Override public void run() { try { SessionState ss = new SessionState(db.getConf()); ss.setIsHiveServerQuery(true); // All is served from HS2, we do not need e.g. Tez sessions SessionState.start(ss); final boolean cache = !db.getConf() .get(HiveConf.ConfVars.HIVE_SERVER2_MATERIALIZED_VIEWS_REGISTRY_IMPL.varname).equals("DUMMY"); for (String dbName : db.getAllDatabases()) { for (Table mv : db.getAllMaterializedViewObjects(dbName)) { addMaterializedView(db.getConf(), mv, OpType.LOAD, cache); } } initialized.set(true); LOG.info("Materialized views registry has been initialized"); } catch (HiveException e) { LOG.error("Problem connecting to the metastore when initializing the view registry", e); } } }
public static SessionState setUpSessionState(HiveConf conf, String user, boolean doStart) { SessionState sessionState = SessionState.get(); if (sessionState == null) { // Note: we assume that workers run on the same threads repeatedly, so we can set up // the session here and it will be reused without explicitly storing in the worker. sessionState = new SessionState(conf, user); if (doStart) { // TODO: Required due to SessionState.getHDFSSessionPath. Why wasn't it required before? sessionState.setIsHiveServerQuery(true); SessionState.start(sessionState); } SessionState.setCurrentSessionState(sessionState); } return sessionState; } }
public void runWithinSession(Consumer<Driver> driverConsumer) { final HiveConf hiveConf = new HiveConf(SessionState.class); driverConf.forEach(hiveConf::set); SessionState ss = new SessionState(hiveConf); try (Closeable ssClose = ss::close) { SessionState.start(ss); driverConsumer.accept(new Driver(hiveConf)); } catch (IOException e) { throw new RuntimeException("Exception was thrown while closing SessionState", e); } }
@Override public void applyAction(final Map<TezSessionState, Trigger> queriesViolated) { for (Map.Entry<TezSessionState, Trigger> entry : queriesViolated.entrySet()) { switch (entry.getValue().getAction().getType()) { case KILL_QUERY: TezSessionState sessionState = entry.getKey(); String queryId = sessionState.getWmContext().getQueryId(); try { SessionState ss = new SessionState(new HiveConf()); ss.setIsHiveServerQuery(true); SessionState.start(ss); KillQuery killQuery = sessionState.getKillQuery(); // if kill query is null then session might have been released to pool or closed already if (killQuery != null) { sessionState.getKillQuery().killQuery(queryId, entry.getValue().getViolationMsg(), sessionState.getConf()); } } catch (HiveException e) { LOG.warn("Unable to kill query {} for trigger violation", queryId); } break; default: throw new RuntimeException("Unsupported action: " + entry.getValue()); } } } }
public TestExpressionEvaluator() { SessionState ss = new SessionState(new HiveConf()); SessionState.setCurrentSessionState(ss);
@Test public void testClassLoaderEquality() throws Exception { HiveConf conf = new HiveConf(); final SessionState ss1 = new SessionState(conf); RegisterJarRunnable otherThread = new RegisterJarRunnable("./build/contrib/test/test-udfs.jar", ss1); Thread th1 = new Thread(otherThread); th1.start(); th1.join(); // set state in current thread SessionState.start(ss1); SessionState ss2 = SessionState.get(); ClassLoader loader2 = ss2.getConf().getClassLoader(); System.out.println("Loader1:(Set in other thread) " + otherThread.loader); System.out.println("Loader2:(Set in SessionState.conf) " + loader2); System.out.println("Loader3:(CurrentThread.getContextClassLoader()) " + Thread.currentThread().getContextClassLoader()); assertEquals("Other thread loader and session state loader", otherThread.loader, loader2); assertEquals("Other thread loader and current thread loader", otherThread.loader, Thread.currentThread().getContextClassLoader()); }
/** * Test that the groupNames are retrieved properly from UGI * @throws Exception */ @Test public void testSessionGetGroupNames() throws Exception { final String testUser = "authtestuser"; final List<String> testGroups = Arrays.asList("group1", "group2"); UserGroupInformation.createUserForTesting(testUser, testGroups.toArray(new String[0])); SessionState ss = new SessionState(getAuthV2HiveConf(), testUser); setupDataNucleusFreeHive(ss.getConf()); assertEquals("check groups", testGroups, ss.getAuthenticator().getGroupNames()); }
/** * Test if the authorization factory gets the username set in the SessionState constructor * @throws Exception */ @Test public void testSessionConstructorUser() throws Exception { final String USER_NAME = "authtestuser"; SessionState ss = new SessionState(getAuthV2HiveConf(), USER_NAME); setupDataNucleusFreeHive(ss.getConf()); SessionState.start(ss); ss.getAuthenticator(); Assert.assertEquals("check username", USER_NAME, HiveAuthorizerStoringUserNameFactory.username); }
public TestVectorFilterCompare() { // Arithmetic operations rely on getting conf from SessionState, need to initialize here. SessionState ss = new SessionState(new HiveConf()); ss.getConf().setVar(HiveConf.ConfVars.HIVE_COMPAT, "latest"); SessionState.setCurrentSessionState(ss); }
public AbstractTestGenericUDFOPNumeric() { // Arithmetic operations rely on getting conf from SessionState, need to initialize here. SessionState ss = new SessionState(new HiveConf()); ss.getConf().setVar(HiveConf.ConfVars.HIVE_COMPAT, "latest"); SessionState.setCurrentSessionState(ss); }
public TestVectorArithmetic() { // Arithmetic operations rely on getting conf from SessionState, need to initialize here. SessionState ss = new SessionState(new HiveConf()); ss.getConf().setVar(HiveConf.ConfVars.HIVE_COMPAT, "default"); SessionState.setCurrentSessionState(ss); }
@Test public void testReloadAuxJars2() { HiveConf conf = new HiveConf(); HiveConf.setVar(conf, ConfVars.HIVERELOADABLEJARS, hiveReloadPath); SessionState ss = new SessionState(conf); SessionState.start(ss); ss = SessionState.get(); File dist = null; try { dist = new File(reloadFolder.getAbsolutePath() + File.separator + reloadClazzFileName); Files.copy(new File(HiveTestUtils.getFileFromClasspath(clazzDistFileName)), dist); ss.loadReloadableAuxJars(); Assert.assertEquals("version1", getReloadedClazzVersion(ss.getConf().getClassLoader())); } catch (Exception e) { LOG.error("Reload auxiliary jar test fail with message: ", e); Assert.fail(e.getMessage()); } finally { FileUtils.deleteQuietly(dist); try { ss.close(); } catch (IOException ioException) { Assert.fail(ioException.getMessage()); LOG.error("Fail to close the created session: ", ioException); } } }
public TestVectorNegative() { // Arithmetic operations rely on getting conf from SessionState, need to initialize here. SessionState ss = new SessionState(new HiveConf()); ss.getConf().setVar(HiveConf.ConfVars.HIVE_COMPAT, "latest"); SessionState.setCurrentSessionState(ss); }
/** * Test if the authorization factory gets the username provided by * the authenticator, if SesstionState is created without username * @throws Exception */ @Test public void testSessionDefaultUser() throws Exception { SessionState ss = new SessionState(getAuthV2HiveConf()); setupDataNucleusFreeHive(ss.getConf()); SessionState.start(ss); Assert.assertEquals("check username", ss.getAuthenticator().getUserName(), HiveAuthorizerStoringUserNameFactory.username); }
/** * Test that the groupNames returned is null, when the user name is null. The user name is null * in the case of embedded HS2 and we assert that we don't throw an NPE in that case. * @throws Exception */ @Test public void testSessionNullUser() throws Exception { SessionState ss = new SessionState(getAuthV2HiveConf(), null); setupDataNucleusFreeHive(ss.getConf()); SessionState.start(ss); assertNull("getGroupNames when userName == null", ss.getAuthenticator().getGroupNames()); }