private void configureSession(Map<String, String> sessionConfMap) throws HiveSQLException { SessionState.setCurrentSessionState(sessionState); for (Map.Entry<String, String> entry : sessionConfMap.entrySet()) { String key = entry.getKey(); if (key.startsWith("set:")) { try { SetProcessor.setVariable(key.substring(4), entry.getValue()); } catch (Exception e) { throw new HiveSQLException(e); } } else if (key.startsWith("use:")) { try { if (sessionHive.getDatabase(entry.getValue()) == null) { throw new HiveSQLException("Database " + entry.getValue() + " does not exist"); } } catch (HiveException e) { throw new HiveSQLException(e); } SessionState.get().setCurrentDatabase(entry.getValue()); } else { sessionConf.verifyAndSet(key, entry.getValue()); } } }
/** * Switch to a different Database * @param db * @param switchDb * @return Always returns 0 * @throws HiveException */ private int switchDatabase(Hive db, SwitchDatabaseDesc switchDb) throws HiveException { String dbName = switchDb.getDatabaseName(); if (!db.databaseExists(dbName)) { throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName); } SessionState.get().setCurrentDatabase(dbName); // set database specific parameters Database database = db.getDatabase(dbName); assert(database != null); Map<String, String> dbParams = database.getParameters(); if (dbParams != null) { for (HiveConf.ConfVars var: HiveConf.dbVars) { String newValue = dbParams.get(var.varname); if (newValue != null) { LOG.info("Changing {} from {} to {}", var.varname, conf.getVar(var), newValue); conf.setVar(var, newValue); } } } return 0; }
/** * Switch to a different Database * @param db * @param switchDb * @return Always returns 0 * @throws HiveException */ private int switchDatabase(Hive db, SwitchDatabaseDesc switchDb) throws HiveException { String dbName = switchDb.getDatabaseName(); if (!db.databaseExists(dbName)) { throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName); } SessionState.get().setCurrentDatabase(dbName); // set database specific parameters Database database = db.getDatabase(dbName); assert(database != null); Map<String, String> dbParams = database.getParameters(); if (dbParams != null) { for (HiveConf.ConfVars var: HiveConf.dbVars) { String newValue = dbParams.get(var.varname); if (newValue != null) { LOG.info("Changing " + var.varname + " from " + conf.getVar(var) + " to " + newValue); conf.setVar(var, newValue); } } } return 0; }
public void testSingleReadTable() throws Exception { SessionState.get().setCurrentDatabase("db1");
/** * test set and get db */ @Test public void testgetDbName() throws Exception { //check that we start with default db assertEquals(Warehouse.DEFAULT_DATABASE_NAME, SessionState.get().getCurrentDatabase()); final String newdb = "DB_2"; //set new db and verify get SessionState.get().setCurrentDatabase(newdb); assertEquals(newdb, SessionState.get().getCurrentDatabase()); //verify that a new sessionstate has default db SessionState.start(new HiveConf()); assertEquals(Warehouse.DEFAULT_DATABASE_NAME, SessionState.get().getCurrentDatabase()); }
SessionState.get().setCurrentDatabase(dbName); for (String tblName : db.getAllTables()) { Table tblObj = null; SessionState.get().setCurrentDatabase(dbName); for (String tblName : db.getAllTables()) { if (!DEFAULT_DATABASE_NAME.equals(dbName) || !srcTables.contains(tblName)) { SessionState.get().setCurrentDatabase(DEFAULT_DATABASE_NAME);
private void setCurrentDatabase(String dbName) { SessionState.get().setCurrentDatabase(dbName); }
private void setCurrentDatabase(String dbName) { SessionState.get().setCurrentDatabase(dbName); }
private void configureSession(Map<String, String> sessionConfMap) throws HiveSQLException { SessionState.setCurrentSessionState(sessionState); for (Map.Entry<String, String> entry : sessionConfMap.entrySet()) { String key = entry.getKey(); if (key.startsWith("set:")) { try { setVariable(key.substring(4), entry.getValue()); } catch (Exception e) { throw new HiveSQLException(e); } } else if (key.startsWith("use:")) { SessionState.get().setCurrentDatabase(entry.getValue()); } else { hiveConf.verifyAndSet(key, entry.getValue()); } } }
private void configureSession(Map<String, String> sessionConfMap) throws HiveSQLException { SessionState.setCurrentSessionState(sessionState); for (Map.Entry<String, String> entry : sessionConfMap.entrySet()) { String key = entry.getKey(); if (key.startsWith("set:")) { try { SetProcessor.setVariable(key.substring(4), entry.getValue()); } catch (Exception e) { throw new HiveSQLException(e); } } else if (key.startsWith("use:")) { SessionState.get().setCurrentDatabase(entry.getValue()); } else { hiveConf.verifyAndSet(key, entry.getValue()); } } }
private void configureSession(Map<String, String> sessionConfMap) throws HiveSQLException { SessionState.setCurrentSessionState(sessionState); for (Map.Entry<String, String> entry : sessionConfMap.entrySet()) { String key = entry.getKey(); if (key.startsWith("set:")) { try { setVariable(key.substring(4), entry.getValue()); } catch (Exception e) { throw new HiveSQLException(e); } } else if (key.startsWith("use:")) { SessionState.get().setCurrentDatabase(entry.getValue()); } else { hiveConf.verifyAndSet(key, entry.getValue()); } } }
private void configureSession(Map<String, String> sessionConfMap) throws HiveSQLException { SessionState.setCurrentSessionState(sessionState); for (Map.Entry<String, String> entry : sessionConfMap.entrySet()) { String key = entry.getKey(); if (key.startsWith("set:")) { try { SetProcessor.setVariable(key.substring(4), entry.getValue()); } catch (Exception e) { throw new HiveSQLException(e); } } else if (key.startsWith("use:")) { SessionState.get().setCurrentDatabase(entry.getValue()); } else { hiveConf.verifyAndSet(key, entry.getValue()); } } }
public void setCurrentDatabase(String currentDatabase) { persistInfo.setDatabase(currentDatabase); getSessionState().setCurrentDatabase(currentDatabase); // Make sure entry is there in classloader cache synchronized (sessionDbClassLoaders) { updateSessionDbClassLoader(currentDatabase); } }
private void configureSession(Map<String, String> sessionConfMap) throws HiveSQLException { SessionState.setCurrentSessionState(sessionState); for (Map.Entry<String, String> entry : sessionConfMap.entrySet()) { String key = entry.getKey(); if (key.startsWith("set:")) { try { SetProcessor.setVariable(key.substring(4), entry.getValue()); } catch (Exception e) { throw new HiveSQLException(e); } } else if (key.startsWith("use:")) { try { if (sessionHive.getDatabase(entry.getValue()) == null) { throw new HiveSQLException("Database " + entry.getValue() + " does not exist"); } } catch (HiveException e) { throw new HiveSQLException(e); } SessionState.get().setCurrentDatabase(entry.getValue()); } else { sessionConf.verifyAndSet(key, entry.getValue()); } } }
@BeforeClass public static void setupSession() throws Exception { SessionState.start(hconf); SessionState.get().setCurrentDatabase(TestQueryRewrite.class.getSimpleName()); }
/** * Switch to a different Database * @param db * @param switchDb * @return Always returns 0 * @throws HiveException */ private int switchDatabase(Hive db, SwitchDatabaseDesc switchDb) throws HiveException { String dbName = switchDb.getDatabaseName(); if (!db.databaseExists(dbName)) { throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName); } SessionState.get().setCurrentDatabase(dbName); // set database specific parameters Database database = db.getDatabase(dbName); assert(database != null); Map<String, String> dbParams = database.getParameters(); if (dbParams != null) { for (HiveConf.ConfVars var: HiveConf.dbVars) { String newValue = dbParams.get(var.varname); if (newValue != null) { LOG.info("Changing " + var.varname + " from " + conf.getVar(var) + " to " + newValue); conf.setVar(var, newValue); } } } return 0; }
/** * Setup. * * @throws AlreadyExistsException the already exists exception * @throws HiveException the hive exception * @throws IOException Signals that an I/O exception has occurred. */ @BeforeTest public void setup() throws AlreadyExistsException, HiveException, IOException { SessionState.start(conf); Hive client = Hive.get(conf); Database database = new Database(); database.setName(TestDBStorage.class.getSimpleName()); client.createDatabase(database); SessionState.get().setCurrentDatabase(TestDBStorage.class.getSimpleName()); }
/** * Before test. * * @throws Exception the exception */ @BeforeTest public void beforeTest() throws Exception { // Check if hadoop property set System.out.println("###HADOOP_PATH " + System.getProperty("hadoop.bin.path")); assertNotNull(System.getProperty("hadoop.bin.path")); createDriver(); ss = new SessionState(hiveConf, "testuser"); SessionState.start(ss); Hive client = Hive.get(hiveConf); Database database = new Database(); database.setName(dataBase); client.createDatabase(database, true); SessionState.get().setCurrentDatabase(dataBase); sessionid = SessionState.get().getSessionId(); driverConf.setBoolean(LensConfConstants.QUERY_ADD_INSERT_OVEWRITE, false); QueryContext context = createContext("USE " + dataBase, this.queryConf); driver.execute(context); driverConf.setBoolean(LensConfConstants.QUERY_ADD_INSERT_OVEWRITE, true); driverConf.setBoolean(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, true); }
@BeforeClass public static void setup() throws HiveException, AlreadyExistsException, LensException { SessionState.start(conf); conf.set(LensConfConstants.AUTHORIZER_CLASS, "org.apache.lens.cube.parse.MockAuthorizer"); LensAuthorizer.get().init(conf); Database database = new Database(); database.setName(TestCubeMetastoreClient.class.getSimpleName()); Hive.get(conf).createDatabase(database); SessionState.get().setCurrentDatabase(TestCubeMetastoreClient.class.getSimpleName()); client = CubeMetastoreClient.getInstance(conf); client.getConf().setBoolean(LensConfConstants.ENABLE_METASTORE_SCHEMA_AUTHORIZATION_CHECK, true); client.getConf().setBoolean(LensConfConstants.USER_GROUPS_BASED_AUTHORIZATION, true); SessionState.getSessionConf().set(LensConfConstants.SESSION_USER_GROUPS, "lens-auth-test1"); defineCube(CUBE_NAME, CUBE_NAME_WITH_PROPS, DERIVED_CUBE_NAME, DERIVED_CUBE_NAME_WITH_PROPS); defineUberDims(); }
public void createSources(HiveConf conf, String dbName) throws Exception { try { Database database = new Database(); database.setName(dbName); Hive.get(conf).dropDatabase(dbName, true, true, true); Hive.get(conf).createDatabase(database); SessionState.get().setCurrentDatabase(dbName); CubeMetastoreClient client = CubeMetastoreClient.getInstance(conf); createFromXML(client); assertTestFactTimelineClass(client); createCubeCheapFactPartitions(client); // commenting this as the week date format throws IllegalPatternException // createCubeFactWeekly(client); createTestFact2Partitions(client); createTestFact2RawPartitions(client); createBaseCubeFactPartitions(client); createSummaryPartitions(client); // dump(client); } catch (Exception exc) { log.error("Exception while creating sources.", exc); throw exc; } } private static final StrSubstitutor GREGORIAN_SUBSTITUTOR = new StrSubstitutor(new StrLookup<String>() {