Search in sources :

Example 1 with IDataConnectorProvider

use of org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider in project hive by apache.

the class DataConnectorProviderFactory method getDataConnectorProvider.

public static synchronized IDataConnectorProvider getDataConnectorProvider(Database db) throws MetaException {
    IDataConnectorProvider provider = null;
    DataConnector connector = null;
    if (db.getType() == DatabaseType.NATIVE) {
        throw new MetaException("Database " + db.getName() + " is of type NATIVE, no connector available");
    }
    String scopedDb = (db.getRemote_dbname() != null) ? db.getRemote_dbname() : db.getName();
    if (cache.containsKey(db.getConnector_name().toLowerCase())) {
        provider = cache.get(db.getConnector_name().toLowerCase());
        if (provider != null) {
            provider.setScope(scopedDb);
        }
        return provider;
    }
    try {
        connector = hmsHandler.get_dataconnector_core(db.getConnector_name());
    } catch (NoSuchObjectException notexists) {
        throw new MetaException("Data connector " + db.getConnector_name() + " associated with database " + db.getName() + " does not exist");
    }
    String type = connector.getType();
    switch(type) {
        case DERBY_TYPE:
        case MSSQL_TYPE:
        case MYSQL_TYPE:
        case ORACLE_TYPE:
        case POSTGRES_TYPE:
            try {
                provider = JDBCConnectorProviderFactory.get(scopedDb, connector);
            } catch (Exception e) {
                throw new MetaException("Could not instantiate a provider for database " + db.getName());
            }
            break;
        default:
            throw new MetaException("Data connector of type " + connector.getType() + " not implemented yet");
    }
    cache.put(connector.getName().toLowerCase(), provider);
    return provider;
}
Also used : IDataConnectorProvider(org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) DataConnector(org.apache.hadoop.hive.metastore.api.DataConnector) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

DataConnector (org.apache.hadoop.hive.metastore.api.DataConnector)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 IDataConnectorProvider (org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider)1