@Override public Database getDatabase(String name) throws TException { return getDatabase(getDefaultCatalog(conf), name); }
protected void testFilterForDb(boolean filterAtServer) throws Exception { // Skip this call when testing filter hook at HMS server because HMS server calls authorization // API for getDatabase(), and does not call filter hook if (!filterAtServer) { try { assertNotNull(client.getDatabase(DBNAME1)); fail("getDatabase() should fail with blocking mode"); } catch (NoSuchObjectException e) { // Excepted } } assertEquals(0, client.getDatabases("*").size()); assertEquals(0, client.getAllDatabases().size()); assertEquals(0, client.getDatabases(DBNAME1).size()); }
throws NoSuchObjectException, InvalidOperationException, MetaException, TException { try { getDatabase(catalogName, dbName); } catch (NoSuchObjectException e) { if (!ignoreUnknownDb) {
/** * Disable filtering at HMS client * By default, the HMS server side filtering is diabled, so we can see HMS client filtering behavior * @throws Exception */ @Test public void testHMSClientWithoutFilter() throws Exception { MetastoreConf.setBoolVar(conf, ConfVars.METASTORE_CLIENT_FILTER_ENABLED, false); DBNAME1 = "db_testHMSClientWithoutFilter_1"; DBNAME2 = "db_testHMSClientWithoutFilter_2"; creatEnv(conf); assertNotNull(client.getTable(DBNAME1, TAB1)); assertEquals(2, client.getTables(DBNAME1, "*").size()); assertEquals(2, client.getAllTables(DBNAME1).size()); assertEquals(1, client.getTables(DBNAME1, TAB2).size()); assertEquals(0, client.getAllTables(DBNAME2).size()); assertNotNull(client.getDatabase(DBNAME1)); assertEquals(2, client.getDatabases("*testHMSClientWithoutFilter*").size()); assertEquals(1, client.getDatabases(DBNAME1).size()); assertNotNull(client.getPartition(DBNAME1, TAB2, "name=value1")); assertEquals(1, client.getPartitionsByNames(DBNAME1, TAB2, Lists.newArrayList("name=value1")).size()); }
void processDatabase(String dbName) throws IOException, HiveException, MetaException, TException { LOG.info("Processing database {}", dbName); Database dbObj = hms.getDatabase(dbName);
/** * The default configuration should be disable filtering at HMS server * Disable the HMS client side filtering in order to see HMS server filtering behavior * @throws Exception */ @Test public void testHMSServerWithoutFilter() throws Exception { MetastoreConf.setBoolVar(conf, ConfVars.METASTORE_CLIENT_FILTER_ENABLED, false); DBNAME1 = "db_testHMSServerWithoutFilter_1"; DBNAME2 = "db_testHMSServerWithoutFilter_2"; creatEnv(conf); assertNotNull(client.getTable(DBNAME1, TAB1)); assertEquals(2, client.getTables(DBNAME1, "*").size()); assertEquals(2, client.getAllTables(DBNAME1).size()); assertEquals(1, client.getTables(DBNAME1, TAB2).size()); assertEquals(0, client.getAllTables(DBNAME2).size()); assertNotNull(client.getDatabase(DBNAME1)); assertEquals(2, client.getDatabases("*testHMSServerWithoutFilter*").size()); assertEquals(1, client.getDatabases(DBNAME1).size()); assertNotNull(client.getPartition(DBNAME1, TAB2, "name=value1")); assertEquals(1, client.getPartitionsByNames(DBNAME1, TAB2, Lists.newArrayList("name=value1")).size()); }
private void checkDbOwnerType(String dbName, String ownerName, PrincipalType ownerType) throws TException { Database db = client.getDatabase(dbName); assertEquals("Owner name", ownerName, db.getOwnerName()); assertEquals("Owner type", ownerType, db.getOwnerType()); }
client.createDatabase(db); db = client.getDatabase(TEST_DB1_NAME); .create(client, conf); db2 = client.getDatabase(TEST_DB2_NAME);
@Test public void testDBOwner() throws TException { Database db = client.getDatabase(Warehouse.DEFAULT_DATABASE_NAME); assertEquals(db.getOwnerName(), HiveMetaStore.PUBLIC); assertEquals(db.getOwnerType(), PrincipalType.ROLE); }
@Test public void testDBLocationChange() throws IOException, TException { final String dbName = "alterDbLocation"; String defaultUri = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/default_location.db"; String newUri = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/new_location.db"; new DatabaseBuilder() .setName(dbName) .setLocation(defaultUri) .create(client, conf); Database db = client.getDatabase(dbName); assertEquals("Incorrect default location of the database", warehouse.getDnsPath(new Path(defaultUri)).toString(), db.getLocationUri()); db.setLocationUri(newUri); client.alterDatabase(dbName, db); db = client.getDatabase(dbName); assertEquals("Incorrect new location of the database", warehouse.getDnsPath(new Path(newUri)).toString(), db.getLocationUri()); client.dropDatabase(dbName); silentDropDatabase(dbName); }
.create(client, conf); Database db = client.getDatabase(TEST_DB1_NAME); client.getDatabase(TEST_DB1_NAME); } catch (NoSuchObjectException e) { objectNotExist = true; client.getDatabase(TEST_DB1_NAME); } catch (NoSuchObjectException e) { objectNotExist = true;
assertNotNull((client.getDatabase(dbName).getLocationUri()));
.setLocation(dbLocation) .create(client, conf); Database db = client.getDatabase(dbName);
.setName(dbName) .create(client, conf); Database db = client.getDatabase(dbName); Path dbPath = new Path(db.getLocationUri()); FileSystem fs = FileSystem.get(dbPath.toUri(), conf);
listSize++; PreCreateDatabaseEvent preDbEvent = (PreCreateDatabaseEvent)(preNotifyList.get(preNotifyList.size() - 1)); Database db = msc.getDatabase(dbName); assertEquals(listSize, notifyList.size()); assertEquals(listSize + 1, preNotifyList.size());
msc.getDatabase("UnknownDB"); } catch (Exception e) {
@Override public Boolean run(HiveMetaStoreClient client) throws TException { return client.getDatabase(dbName) != null; }}); } catch (NoSuchObjectException e) {
public void dropDatabase(String name, boolean deleteData, boolean ignoreUnknownDb) throws NoSuchObjectException, InvalidOperationException, MetaException, TException { try { getDatabase(name); } catch (NoSuchObjectException e) { if (!ignoreUnknownDb) { throw e; } return; } client.drop_database(name, deleteData); }
@GET @Path("{name}") @Produces("text/html") public Viewable db(@PathParam(value = "name") String name) { HiveConf hiveConf = new HiveConf(SessionState.class); try { HiveMetaStoreClient client = new HiveMetaStoreClient(hiveConf); Database db = client.getDatabase(name); List<String> tables = client.getAllTables(name); client.close(); request.setAttribute("db", db); request.setAttribute("tables", tables); } catch (Exception e) { throw new WebApplicationException(e); } return new Viewable("/schema/db.vm"); }
public void dropDatabase(String name, boolean deleteData, boolean ignoreUnknownDb, boolean cascade) throws NoSuchObjectException, InvalidOperationException, MetaException, TException { try { getDatabase(name); } catch (NoSuchObjectException e) { if (!ignoreUnknownDb) { throw e; } return; } if (cascade) { List<String> tableList = getAllTables(name); for (String table : tableList) { try { dropTable(name, table, deleteData, false); } catch (UnsupportedOperationException e) { // Ignore Index tables, those will be dropped with parent tables } } } client.drop_database(name, deleteData, cascade); }