public FunctionBuilder inDb(Database db) { this.dbName = db.getName(); this.catName = db.getCatalogName(); return this; }
public TableBuilder inDb(Database db) { this.dbName = db.getName(); this.catName = db.getCatalogName(); return this; }
public ISchemaBuilder inDb(Database db) { this.catName = db.getCatalogName(); this.dbName = db.getName(); return this; }
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(); } }
@Override public void onAlterDatabase(AlterDatabaseEvent dbEvent) throws MetaException { Database oldDb = dbEvent.getOldDatabase(); Database newDb = dbEvent.getNewDatabase(); if(!oldDb.getCatalogName().equalsIgnoreCase(newDb.getCatalogName()) || !oldDb.getName().equalsIgnoreCase(newDb.getName())) { txnHandler = getTxnHandler(); txnHandler.onRename( oldDb.getCatalogName(), oldDb.getName(), null, null, newDb.getCatalogName(), newDb.getName(), null, null); } }
/** * Get the path specified by the database. In the case of the default database the root of the * warehouse is returned. * @param db database to get the path of * @return path to the database directory * @throws MetaException when the file path cannot be properly determined from the configured * file system. */ public Path getDatabasePath(Database db) throws MetaException { if (db.getCatalogName().equalsIgnoreCase(DEFAULT_CATALOG_NAME) && db.getName().equalsIgnoreCase(DEFAULT_DATABASE_NAME)) { return getWhRoot(); } return new Path(db.getLocationUri()); }
public void populateDatabasesInCache(List<Database> databases) { for (Database db : databases) { Database dbCopy = db.deepCopy(); // ObjectStore also stores db name in lowercase dbCopy.setName(dbCopy.getName().toLowerCase()); try { cacheLock.writeLock().lock(); // Since we allow write operations on cache while prewarm is happening: // 1. Don't add databases that were deleted while we were preparing list for prewarm // 2. Skip overwriting exisiting db object // (which is present because it was added after prewarm started) String key = CacheUtils.buildDbKey(dbCopy.getCatalogName().toLowerCase(), dbCopy.getName().toLowerCase()); if (databasesDeletedDuringPrewarm.contains(key)) { continue; } databaseCache.putIfAbsent(key, dbCopy); databasesDeletedDuringPrewarm.clear(); isDatabaseCachePrewarmed = true; } finally { cacheLock.writeLock().unlock(); } } }
public Object getFieldValue(_Fields field) { switch (field) { case NAME: return getName(); case DESCRIPTION: return getDescription(); case LOCATION_URI: return getLocationUri(); case PARAMETERS: return getParameters(); case PRIVILEGES: return getPrivileges(); case OWNER_NAME: return getOwnerName(); case OWNER_TYPE: return getOwnerType(); case CATALOG_NAME: return getCatalogName(); case CREATE_TIME: return getCreateTime(); } throw new IllegalStateException(); }
Assert.assertEquals(expectedCatalog(), fetched.getCatalogName()); Assert.assertEquals(expectedLocation, fetched.getLocationUri() + "/"); String db0Location = new URI(fetched.getLocationUri()).getPath(); File dir = new File(db0Location); Assert.assertTrue(dir.exists() && dir.isDirectory()); Assert.assertEquals(expectedCatalog(), fetched.getCatalogName()); dir = new File(new URI(fetched.getLocationUri()).getPath()); Assert.assertTrue(dir.exists() && dir.isDirectory()); Assert.assertEquals(expectedCatalog(), fetched.getCatalogName());
@Override public void createDatabase(Database db) throws InvalidObjectException, MetaException { boolean commited = false; MDatabase mdb = new MDatabase(); assert db.getCatalogName() != null; mdb.setCatalogName(normalizeIdentifier(db.getCatalogName())); assert mdb.getCatalogName() != null; mdb.setName(db.getName().toLowerCase()); mdb.setLocationUri(db.getLocationUri()); mdb.setDescription(db.getDescription()); mdb.setParameters(db.getParameters()); mdb.setOwnerName(db.getOwnerName()); PrincipalType ownerType = db.getOwnerType(); mdb.setOwnerType((null == ownerType ? PrincipalType.USER.name() : ownerType.name())); mdb.setCreateTime(db.getCreateTime()); try { openTransaction(); pm.makePersistent(mdb); commited = commitTransaction(); } finally { if (!commited) { rollbackTransaction(); } } }
/** * @param dbEvent database event * @throws MetaException */ @Override public void onCreateDatabase(CreateDatabaseEvent dbEvent) throws MetaException { Database db = dbEvent.getDatabase(); CreateDatabaseMessage msg = MessageBuilder.getInstance() .buildCreateDatabaseMessage(db); NotificationEvent event = new NotificationEvent(0, now(), EventType.CREATE_DATABASE.toString(), msgEncoder.getSerializer().serialize(msg)); event.setCatName(db.isSetCatalogName() ? db.getCatalogName() : DEFAULT_CATALOG_NAME); event.setDbName(db.getName()); process(event, dbEvent); }
/** * @param dbEvent database event * @throws MetaException */ @Override public void onDropDatabase(DropDatabaseEvent dbEvent) throws MetaException { Database db = dbEvent.getDatabase(); DropDatabaseMessage msg = MessageBuilder.getInstance() .buildDropDatabaseMessage(db); NotificationEvent event = new NotificationEvent(0, now(), EventType.DROP_DATABASE.toString(), msgEncoder.getSerializer().serialize(msg)); event.setCatName(db.isSetCatalogName() ? db.getCatalogName() : DEFAULT_CATALOG_NAME); event.setDbName(db.getName()); process(event, dbEvent); }
if (null != get_database_core(db.getCatalogName(), db.getName())) { throw new AlreadyExistsException("Database " + db.getName() + " already exists");
/** * @param dbEvent alter database event * @throws MetaException */ @Override public void onAlterDatabase(AlterDatabaseEvent dbEvent) throws MetaException { Database oldDb = dbEvent.getOldDatabase(); Database newDb = dbEvent.getNewDatabase(); AlterDatabaseMessage msg = MessageBuilder.getInstance() .buildAlterDatabaseMessage(oldDb, newDb); NotificationEvent event = new NotificationEvent(0, now(), EventType.ALTER_DATABASE.toString(), msgEncoder.getSerializer().serialize(msg) ); event.setCatName(oldDb.isSetCatalogName() ? oldDb.getCatalogName() : DEFAULT_CATALOG_NAME); event.setDbName(oldDb.getName()); process(event, dbEvent); }
objectStore.dropDatabase(db1.getCatalogName(), DB1);
assertEquals(db.getOwnerName(), SecurityUtils.getUser()); assertEquals(db.getOwnerType(), PrincipalType.USER); assertEquals(Warehouse.DEFAULT_CATALOG_NAME, db.getCatalogName()); Database db2 = new DatabaseBuilder() .setName(TEST_DB2_NAME)
@Test public void iSchema() throws TException { Database db = createUniqueDatabaseForTest(); ISchema schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), "no.such.schema")); Assert.assertNull(schema); objectStore.createISchema(schema); schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), schemaName)); Assert.assertNotNull(schema); schema.setSchemaGroup(schemaGroup); schema.setDescription(description); objectStore.alterISchema(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), schema); schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), schemaName)); Assert.assertNotNull(schema); Assert.assertEquals(description, schema.getDescription()); objectStore.dropISchema(new ISchemaName(db.getCatalogName(), db.getName(), schemaName)); schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), schemaName)); Assert.assertNull(schema);
String schemaName = "schema371234"; int version = 1; SchemaVersion schemaVersion = objectStore.getSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version)); Assert.assertNull(schemaVersion); objectStore.addSchemaVersion(schemaVersion); schemaVersion = objectStore.getSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version)); Assert.assertNotNull(schemaVersion); Assert.assertEquals(schemaName, schemaVersion.getSchema().getSchemaName()); Assert.assertEquals(db.getName(), schemaVersion.getSchema().getDbName()); Assert.assertEquals(db.getCatalogName(), schemaVersion.getSchema().getCatName()); Assert.assertEquals(version, schemaVersion.getVersion()); Assert.assertEquals(SchemaVersionState.INITIATED, schemaVersion.getState()); serde.setDeserializerClass(deserializer); schemaVersion.setSerDe(serde); objectStore.alterSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version), schemaVersion); schemaVersion = objectStore.getSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version)); Assert.assertNotNull(schemaVersion); Assert.assertEquals(schemaName, schemaVersion.getSchema().getSchemaName()); Assert.assertEquals(db.getName(), schemaVersion.getSchema().getDbName()); Assert.assertEquals(db.getCatalogName(), schemaVersion.getSchema().getCatName()); Assert.assertEquals(version, schemaVersion.getVersion()); Assert.assertEquals(SchemaVersionState.REVIEWED, schemaVersion.getState());
@Test(expected = AlreadyExistsException.class) public void schemaAlreadyExists() throws TException { Database db = createUniqueDatabaseForTest(); String schemaName = "schema2"; ISchema schema = new ISchemaBuilder() .setSchemaType(SchemaType.HIVE) .setName(schemaName) .inDb(db) .build(); objectStore.createISchema(schema); schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), schemaName)); Assert.assertNotNull(schema); Assert.assertEquals(SchemaType.HIVE, schema.getSchemaType()); Assert.assertEquals(schemaName, schema.getName()); Assert.assertEquals(SchemaCompatibility.BACKWARD, schema.getCompatibility()); Assert.assertEquals(SchemaValidation.ALL, schema.getValidationLevel()); Assert.assertTrue(schema.isCanEvolve()); // This second attempt to create it should throw objectStore.createISchema(schema); }
@Test(expected = AlreadyExistsException.class) public void addDuplicateSchemaVersion() throws TException { Database db = createUniqueDatabaseForTest(); String schemaName = "schema1234"; int version = 1; SchemaVersion schemaVersion = objectStore.getSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version)); Assert.assertNull(schemaVersion); ISchema schema = new ISchemaBuilder() .setSchemaType(SchemaType.AVRO) .setName(schemaName) .inDb(db) .build(); objectStore.createISchema(schema); schemaVersion = new SchemaVersionBuilder() .versionOf(schema) .setVersion(version) .addCol("a", ColumnType.INT_TYPE_NAME) .addCol("b", ColumnType.FLOAT_TYPE_NAME) .build(); objectStore.addSchemaVersion(schemaVersion); objectStore.addSchemaVersion(schemaVersion); }