public void addDatabaseToCache(Database db) { try { cacheLock.writeLock().lock(); Database dbCopy = db.deepCopy(); // ObjectStore also stores db name in lowercase dbCopy.setName(dbCopy.getName().toLowerCase()); dbCopy.setCatalogName(dbCopy.getCatalogName().toLowerCase()); databaseCache.put(CacheUtils.buildDbKey(dbCopy.getCatalogName(), dbCopy.getName()), dbCopy); isDatabaseCacheDirty.set(true); } finally { cacheLock.writeLock().unlock(); } }
/** * Create a new Database * @param db * @throws AlreadyExistsException * @throws InvalidObjectException * @throws MetaException * @throws TException * @see org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.Iface#create_database(Database) */ @Override public void createDatabase(Database db) throws AlreadyExistsException, InvalidObjectException, MetaException, TException { if (!db.isSetCatalogName()) { db.setCatalogName(getDefaultCatalog(conf)); } client.create_database(db); }
private void createDefaultDB_core(RawStore ms) throws MetaException, InvalidObjectException { try { ms.getDatabase(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME); } catch (NoSuchObjectException e) { Database db = new Database(DEFAULT_DATABASE_NAME, DEFAULT_DATABASE_COMMENT, wh.getDefaultDatabasePath(DEFAULT_DATABASE_NAME).toString(), null); db.setOwnerName(PUBLIC); db.setOwnerType(PrincipalType.ROLE); db.setCatalogName(DEFAULT_CATALOG_NAME); long time = System.currentTimeMillis() / 1000; db.setCreateTime((int) time); ms.createDatabase(db); } }
private Database createTestDb(String dbName, String dbOwner) { String dbDescription = dbName; String dbLocation = "file:/tmp"; Map<String, String> dbParams = new HashMap<>(); Database db = new Database(dbName, dbDescription, dbLocation, dbParams); db.setOwnerName(dbOwner); db.setOwnerType(PrincipalType.USER); db.setCatalogName(DEFAULT_CATALOG_NAME); db.setCreateTime((int) (System.currentTimeMillis() / 1000)); return db; }
db.setOwnerType( (null == type || type.trim().isEmpty()) ? null : PrincipalType.valueOf(type)); db.setCatalogName(MetastoreDirectSqlUtils.extractSqlString(dbline[6])); db.setCreateTime(MetastoreDirectSqlUtils.extractSqlInt(dbline[7])); db.setParameters(MetaStoreServerUtils.trimMapNulls(dbParams,convertMapNullsToEmptyStrings));
public Database build(Configuration conf) throws MetaException { if (name == null) throw new MetaException("You must name the database"); if (catalogName == null) catalogName = MetaStoreUtils.getDefaultCatalog(conf); Database db = new Database(name, description, location, params); db.setCatalogName(catalogName); db.setCreateTime(createTime); try { if (ownerName == null) ownerName = SecurityUtils.getUser(); db.setOwnerName(ownerName); if (ownerType == null) ownerType = PrincipalType.USER; db.setOwnerType(ownerType); return db; } catch (IOException e) { throw MetaStoreUtils.newMetaException(e); } }
@Test public void testGetTableMetaFetchGroup() throws MetaException, InvalidObjectException, InvalidOperationException { objectStore = createObjectStore(); Database db = new Database(DB1, "description", "locurl", null); db.setCatalogName("hive"); objectStore.createDatabase(db); objectStore.createTable(makeTable(DB1, TBL1)); List<TableMeta> tableMeta = objectStore.getTableMeta("hive", "*", "*", Collections.emptyList()); Assert.assertEquals("Number of items for tableMeta is incorrect", 1, tableMeta.size()); Assert.assertEquals("Table name incorrect", TBL1, tableMeta.get(0).getTableName()); Assert.assertEquals("Db name incorrect", DB1, tableMeta.get(0).getDbName()); }
/** * Test database operations */ @Test public void testDatabaseOps() throws MetaException, InvalidObjectException, NoSuchObjectException { String catName = "tdo1_cat"; createTestCatalog(catName); Database db1 = new Database(DB1, "description", "locationurl", null); Database db2 = new Database(DB2, "description", "locationurl", null); db1.setCatalogName(catName); db2.setCatalogName(catName); objectStore.createDatabase(db1); objectStore.createDatabase(db2); List<String> databases = objectStore.getAllDatabases(catName); LOG.info("databases: " + databases); Assert.assertEquals(2, databases.size()); Assert.assertEquals(DB1, databases.get(0)); Assert.assertEquals(DB2, databases.get(1)); objectStore.dropDatabase(catName, DB1); databases = objectStore.getAllDatabases(catName); Assert.assertEquals(1, databases.size()); Assert.assertEquals(DB2, databases.get(0)); objectStore.dropDatabase(catName, DB2); }
Exception ex = null; if (!db.isSetCatalogName()) { db.setCatalogName(getDefaultCatalog(conf));
db.setCatalogName(DEFAULT_CATALOG_NAME); cachedStore.createDatabase(db);
"Default database for catalog " + catalog.getName(), catalog.getLocationUri(), Collections.emptyMap()); db.setCatalogName(catalog.getName()); create_database_core(ms, db);
@Before public void setUp() throws Exception { System.setProperty("hive.metastore.event.listeners", DummyListener.class.getName()); conf = MetastoreConf.newMetastoreConf(); MetastoreConf.setLongVar(conf, ConfVars.THRIFT_CONNECTION_RETRIES, 3); MetastoreConf.setBoolVar(conf, ConfVars.HIVE_SUPPORT_CONCURRENCY, false); MetaStoreTestUtils.setConfForStandloneMode(conf); MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); msc = new HiveMetaStoreClient(conf); msc.dropDatabase(dbName, true, true); Map<String, String> envProperties = new HashMap<>(); envProperties.put("hadoop.job.ugi", "test_user"); envContext = new EnvironmentContext(envProperties); db.setName(dbName); db.setCatalogName(DEFAULT_CATALOG_NAME); table = new TableBuilder() .setDbName(dbName) .setTableName(tblName) .addTableParam("a", "string") .addPartCol("b", "string") .addCol("a", "string") .addCol("b", "string") .build(conf); partition = new PartitionBuilder() .inTable(table) .addValue("2011") .build(conf); DummyListener.notifyList.clear(); }
db.setCatalogName(DEFAULT_CATALOG_NAME); cachedStore.createDatabase(db);
db.setCatalogName(catName); db.setName(dbName); msc.createDatabase(db);
public Database getJDODatabase(String catName, String name) throws NoSuchObjectException { MDatabase mdb = null; boolean commited = false; try { openTransaction(); mdb = getMDatabase(catName, name); commited = commitTransaction(); } finally { if (!commited) { rollbackTransaction(); } } Database db = new Database(); db.setName(mdb.getName()); db.setDescription(mdb.getDescription()); db.setLocationUri(mdb.getLocationUri()); db.setParameters(convertMap(mdb.getParameters())); db.setOwnerName(mdb.getOwnerName()); String type = org.apache.commons.lang.StringUtils.defaultIfBlank(mdb.getOwnerType(), null); PrincipalType principalType = (type == null) ? null : PrincipalType.valueOf(type); db.setOwnerType(principalType); db.setCatalogName(catName); db.setCreateTime(mdb.getCreateTime()); return db; }
unsetCatalogName(); } else { setCatalogName((String)value);
@Test public void testAlterDatabaseNotNullableFields() throws Exception { Database database = getDatabaseWithAllParametersSet(); client.createDatabase(database); Database originalDatabase = client.getDatabase(database.getName()); Database newDatabase = new Database(); newDatabase.setName("new_name"); newDatabase.setCatalogName(DEFAULT_CATALOG_NAME); client.alterDatabase(originalDatabase.getName(), newDatabase); // The name should not be changed, so reload the db with the original name Database alteredDatabase = client.getDatabase(originalDatabase.getName()); Assert.assertEquals("Database name should not change", originalDatabase.getName(), alteredDatabase.getName()); Assert.assertEquals("Database description should not change", originalDatabase.getDescription(), alteredDatabase.getDescription()); Assert.assertEquals("Database location should not change", originalDatabase.getLocationUri(), alteredDatabase.getLocationUri()); Assert.assertEquals("Database parameters should be empty", new HashMap<String, String>(), alteredDatabase.getParameters()); Assert.assertNull("Database owner should be empty", alteredDatabase.getOwnerName()); Assert.assertEquals("Database owner type should not change", originalDatabase.getOwnerType(), alteredDatabase.getOwnerType()); Assert.assertNull("Database privileges should be empty", alteredDatabase.getPrivileges()); }
private void createDefaultDB_core(RawStore ms) throws MetaException, InvalidObjectException { try { ms.getDatabase(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME); } catch (NoSuchObjectException e) { Database db = new Database(DEFAULT_DATABASE_NAME, DEFAULT_DATABASE_COMMENT, wh.getDefaultDatabasePath(DEFAULT_DATABASE_NAME).toString(), null); db.setOwnerName(PUBLIC); db.setOwnerType(PrincipalType.ROLE); db.setCatalogName(DEFAULT_CATALOG_NAME); ms.createDatabase(db); } }
public Database build(Configuration conf) throws MetaException { if (name == null) throw new MetaException("You must name the database"); if (catalogName == null) catalogName = MetaStoreUtils.getDefaultCatalog(conf); Database db = new Database(name, description, location, params); db.setCatalogName(catalogName); try { if (ownerName == null) ownerName = SecurityUtils.getUser(); db.setOwnerName(ownerName); if (ownerType == null) ownerType = PrincipalType.USER; db.setOwnerType(ownerType); return db; } catch (IOException e) { throw MetaStoreUtils.newMetaException(e); } }
public Database getJDODatabase(String catName, String name) throws NoSuchObjectException { MDatabase mdb = null; boolean commited = false; try { openTransaction(); mdb = getMDatabase(catName, name); commited = commitTransaction(); } finally { if (!commited) { rollbackTransaction(); } } Database db = new Database(); db.setName(mdb.getName()); db.setDescription(mdb.getDescription()); db.setLocationUri(mdb.getLocationUri()); db.setParameters(convertMap(mdb.getParameters())); db.setOwnerName(mdb.getOwnerName()); String type = org.apache.commons.lang.StringUtils.defaultIfBlank(mdb.getOwnerType(), null); PrincipalType principalType = (type == null) ? null : PrincipalType.valueOf(type); db.setOwnerType(principalType); db.setCatalogName(catName); return db; }