/** * Get all existing databases that match the given * pattern. The matching occurs as per Java regular expressions * * @param databasePattern * java re pattern * @return list of database names * @throws HiveException */ public List<String> getDatabasesByPattern(String databasePattern) throws HiveException { try { return getMSC().getDatabases(databasePattern); } catch (Exception e) { throw new HiveException(e); } }
/** * Get all existing databases that match the given * pattern. The matching occurs as per Java regular expressions * * @param databasePattern * java re pattern * @return list of database names * @throws HiveException */ public List<String> getDatabasesByPattern(String databasePattern) throws HiveException { try { return getMSC().getDatabases(databasePattern); } catch (Exception e) { throw new HiveException(e); } }
@Override public List<String> listDatabaseNamesByPattern(String pattern) throws HCatException { List<String> dbNames = null; try { dbNames = hmsClient.getDatabases(pattern); } catch (MetaException exp) { throw new HCatException("MetaException while listing db names. " + exp.getMessage(), exp); } catch (TException e) { throw new HCatException("Transport Exception while listing db names. " + e.getMessage(), e); } return dbNames; }
@Test public void testGetDatabasesCaseInsensitive() throws Exception { // Check case insensitive search List<String> databases = client.getDatabases("*_tO_FiND*"); Assert.assertEquals("Found databases size", 2, databases.size()); Assert.assertTrue("Should contain", databases.contains("test_database_to_find_1")); Assert.assertTrue("Should contain", databases.contains("test_database_to_find_2")); }
@Override public void runInternal() throws HiveSQLException { setState(OperationState.RUNNING); LOG.info("Fetching schema metadata"); if (isAuthV2Enabled()) { String cmdStr = "catalog : " + catalogName + ", schemaPattern : " + schemaName; authorizeMetaGets(HiveOperationType.GET_SCHEMAS, null, cmdStr); } try { IMetaStoreClient metastoreClient = getParentSession().getMetaStoreClient(); String schemaPattern = convertSchemaPattern(schemaName); for (String dbName : metastoreClient.getDatabases(schemaPattern)) { rowSet.addRow(new Object[] {dbName, DEFAULT_HIVE_CATALOG}); if (LOG.isDebugEnabled()) { String debugMessage = getDebugMessage("schema", RESULT_SET_SCHEMA); LOG.debug(debugMessage, dbName, DEFAULT_HIVE_CATALOG); } } if (LOG.isDebugEnabled() && rowSet.numRows() == 0) { LOG.debug("No schema metadata has been returned."); } setState(OperationState.FINISHED); LOG.info("Fetching schema metadata has been successfully finished"); } catch (Exception e) { setState(OperationState.ERROR); throw new HiveSQLException(e); } }
@Test public void testGetDatabases() throws Exception { // Find databases which name contains _to_find_ List<String> databases = client.getDatabases("*_to_find_*"); Assert.assertEquals("Found databases size", 2, databases.size()); Assert.assertTrue("Should contain", databases.contains("test_database_to_find_1")); Assert.assertTrue("Should contain", databases.contains("test_database_to_find_2")); // Find databases which name contains _to_find_ or _hidden_ databases = client.getDatabases("*_to_find_*|*_hidden_*"); Assert.assertEquals("Found databases size", 3, databases.size()); Assert.assertTrue("Should contain", databases.contains("test_database_to_find_1")); Assert.assertTrue("Should contain", databases.contains("test_database_to_find_2")); Assert.assertTrue("Should contain", databases.contains("test_database_hidden_1")); // Look for databases but do not find any databases = client.getDatabases("*_not_such_database_*"); Assert.assertEquals("No such databases size", 0, databases.size()); // Look for databases without pattern databases = client.getDatabases(null); Assert.assertEquals("Search databases without pattern size", 5, databases.size()); }
List<String> matchingDbs; try { matchingDbs = metastoreClient.getDatabases(schemaPattern); } catch (TException e) { setState(OperationState.ERROR);
IMetaStoreClient metastoreClient = getParentSession().getMetaStoreClient(); String schemaPattern = convertSchemaPattern(schemaName); List<String> matchingDbs = metastoreClient.getDatabases(schemaPattern); if(isAuthV2Enabled()){ List<HivePrivilegeObject> privObjs = HivePrivilegeObjectUtils.getHivePrivDbObjects(matchingDbs); for (String dbName : metastoreClient.getDatabases(schemaPattern)) { for (TableMeta tableMeta : metastoreClient.getTableMeta(dbName, tablePattern, tableTypeList)) {
List<String> dbNames = metastoreClient.getDatabases(schemaPattern); Collections.sort(dbNames); Map<String, List<String>> db2Tabs = new HashMap<>();
Assert.assertTrue(fetchedDbs.contains(Warehouse.DEFAULT_DATABASE_NAME)); fetchedDbs = new HashSet<>(client.getDatabases(catName, "d*")); Assert.assertEquals(3, fetchedDbs.size()); for (String dbName : dbNames) Assert.assertTrue(fetchedDbs.contains(dbName)); fetchedDbs = new HashSet<>(client.getDatabases("d*")); Assert.assertEquals(1, fetchedDbs.size()); Assert.assertTrue(fetchedDbs.contains(Warehouse.DEFAULT_DATABASE_NAME)); fetchedDbs = new HashSet<>(client.getDatabases("d*")); Assert.assertEquals(1, fetchedDbs.size()); Assert.assertTrue(fetchedDbs.contains(Warehouse.DEFAULT_DATABASE_NAME)); fetchedDbs = new HashSet<>(client.getDatabases(catName, "*1")); Assert.assertEquals(1, fetchedDbs.size()); Assert.assertTrue(fetchedDbs.contains(dbNames[0])); fetchedDbs = new HashSet<>(client.getDatabases("*9")); Assert.assertEquals(0, fetchedDbs.size()); fetchedDbs = new HashSet<>(client.getDatabases("*9")); Assert.assertEquals(0, fetchedDbs.size()); fetchedDbs = new HashSet<>(client.getDatabases(catName, "*x")); Assert.assertEquals(0, fetchedDbs.size());
for (String dbName : dbNames) Assert.assertTrue(fetchedDbs.contains(dbName)); fetchedDbs = new HashSet<>(client.getDatabases("db*")); Assert.assertEquals(2, fetchedDbs.size()); for (String dbName : dbNames) Assert.assertTrue(fetchedDbs.contains(dbName));
/** * Get all existing databases that match the given * pattern. The matching occurs as per Java regular expressions * * @param databasePattern * java re pattern * @return list of database names * @throws HiveException */ public List<String> getDatabasesByPattern(String databasePattern) throws HiveException { try { return getMSC().getDatabases(databasePattern); } catch (Exception e) { throw new HiveException(e); } }
/** * Get all existing databases that match the given * pattern. The matching occurs as per Java regular expressions * * @param databasePattern * java re pattern * @return list of database names * @throws HiveException */ public List<String> getDatabasesByPattern(String databasePattern) throws HiveException { try { return getMSC().getDatabases(databasePattern); } catch (Exception e) { throw new HiveException(e); } }
@Override public List<String> listDatabaseNamesByPattern(String pattern) throws HCatException { List<String> dbNames = null; try { dbNames = hmsClient.getDatabases(pattern); } catch (MetaException exp) { throw new HCatException("MetaException while listing db names. " + exp.getMessage(), exp); } catch (TException e) { throw new HCatException("Transport Exception while listing db names. " + e.getMessage(), e); } return dbNames; }
@Override public List<String> listDatabaseNamesByPattern(String pattern) throws HCatException { List<String> dbNames = null; try { dbNames = hmsClient.getDatabases(pattern); } catch (MetaException exp) { throw new HCatException("MetaException while listing db names. " + exp.getMessage(), exp); } catch (TException e) { throw new HCatException("Transport Exception while listing db names. " + e.getMessage(), e); } return dbNames; }
@Override public List<String> listDatabaseNamesByPattern(String pattern) throws HCatException { List<String> dbNames = null; try { dbNames = hmsClient.getDatabases(pattern); } catch (MetaException exp) { throw new HCatException("MetaException while listing db names. " + exp.getMessage(), exp); } catch (TException e) { throw new HCatException("Transport Exception while listing db names. " + e.getMessage(), e); } return dbNames; }
@Override public synchronized void start() { super.start(); // Initialize and test a connection to the metastore IMetaStoreClient metastoreClient = null; try { metastoreClient = new HiveMetaStoreClient(hiveConf); metastoreClient.getDatabases("default"); } catch (Exception e) { throw new ServiceException("Unable to connect to MetaStore!", e); } finally { if (metastoreClient != null) { metastoreClient.close(); } } }
@Override public synchronized void start() { super.start(); // Initialize and test a connection to the metastore IMetaStoreClient metastoreClient = null; try { metastoreClient = new HiveMetaStoreClient(hiveConf); metastoreClient.getDatabases("default"); } catch (Exception e) { throw new ServiceException("Unable to connect to MetaStore!", e); } finally { if (metastoreClient != null) { metastoreClient.close(); } } }
@Override public synchronized void start() { super.start(); // Initialize and test a connection to the metastore IMetaStoreClient metastoreClient = null; try { metastoreClient = new HiveMetaStoreClient(hiveConf); metastoreClient.getDatabases("default"); } catch (Exception e) { throw new ServiceException("Unable to connect to MetaStore!", e); } finally { if (metastoreClient != null) { metastoreClient.close(); } } }
@Override public void runInternal() throws HiveSQLException { setState(OperationState.RUNNING); if (isAuthV2Enabled()) { String cmdStr = "catalog : " + catalogName + ", schemaPattern : " + schemaName; authorizeMetaGets(HiveOperationType.GET_SCHEMAS, null, cmdStr); } try { IMetaStoreClient metastoreClient = getParentSession().getMetaStoreClient(); String schemaPattern = convertSchemaPattern(schemaName); for (String dbName : metastoreClient.getDatabases(schemaPattern)) { rowSet.addRow(new Object[] {dbName, DEFAULT_HIVE_CATALOG}); } setState(OperationState.FINISHED); } catch (Exception e) { setState(OperationState.ERROR); throw new HiveSQLException(e); } }