Search in sources :

Example 11 with DataConnector

use of org.apache.hadoop.hive.metastore.api.DataConnector in project hive by apache.

the class TestHiveMetaStore method testRemoteDatabase.

@Test
public void testRemoteDatabase() throws Throwable {
    final String connector_name1 = "test_connector1";
    final String mysql_type = "mysql";
    final String mysql_url = "jdbc:mysql://nightly1.apache.org:3306/hive1";
    final String db_name = "mysql_remote";
    final String db2 = "mysql_dup";
    try {
        DataConnector connector = new DataConnector(connector_name1, mysql_type, mysql_url);
        Map<String, String> params = new HashMap<>();
        params.put(AbstractJDBCConnectorProvider.JDBC_USERNAME, "hive");
        params.put(AbstractJDBCConnectorProvider.JDBC_PASSWORD, "hive");
        connector.setParameters(params);
        client.createDataConnector(connector);
        DataConnector dConn = client.getDataConnector(connector_name1);
        new DatabaseBuilder().setName(db_name).setType(DatabaseType.REMOTE).setConnectorName(connector_name1).setRemoteDBName(db_name).create(client, conf);
        Database db = client.getDatabase(db_name);
        assertNotNull(db);
        assertEquals(db.getType(), DatabaseType.REMOTE);
        assertEquals(db.getConnector_name(), connector_name1);
        assertEquals(db.getRemote_dbname(), db_name);
        // new db in hive pointing to same remote db.
        new DatabaseBuilder().setName(db2).setType(DatabaseType.REMOTE).setConnectorName(connector_name1).setRemoteDBName(db_name).create(client, conf);
        db = client.getDatabase(db2);
        assertNotNull(db);
        assertEquals(db.getType(), DatabaseType.REMOTE);
        assertEquals(db.getConnector_name(), connector_name1);
        assertEquals(db.getRemote_dbname(), db_name);
        client.dropDataConnector(connector_name1, false, false);
        client.dropDatabase(db_name);
        client.dropDatabase(db2);
    } catch (Throwable e) {
        System.err.println(StringUtils.stringifyException(e));
        System.err.println("testRemoteDatabase() failed.");
        throw e;
    }
}
Also used : DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Database(org.apache.hadoop.hive.metastore.api.Database) DataConnector(org.apache.hadoop.hive.metastore.api.DataConnector) Test(org.junit.Test)

Example 12 with DataConnector

use of org.apache.hadoop.hive.metastore.api.DataConnector in project hive by apache.

the class ObjectStore method getDataConnector.

@Override
public DataConnector getDataConnector(String name) throws NoSuchObjectException {
    MDataConnector mdc = null;
    boolean commited = false;
    try {
        openTransaction();
        mdc = getMDataConnector(name);
        commited = commitTransaction();
    } catch (NoSuchObjectException no) {
        throw new NoSuchObjectException("Dataconnector named " + name + " does not exist:" + no.getCause());
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
    DataConnector connector = new DataConnector();
    connector.setName(mdc.getName());
    connector.setType(mdc.getType());
    connector.setUrl(mdc.getUrl());
    connector.setDescription(mdc.getDescription());
    connector.setParameters(convertMap(mdc.getParameters()));
    connector.setOwnerName(mdc.getOwnerName());
    String type = org.apache.commons.lang3.StringUtils.defaultIfBlank(mdc.getOwnerType(), null);
    PrincipalType principalType = (type == null) ? null : PrincipalType.valueOf(type);
    connector.setOwnerType(principalType);
    connector.setCreateTime(mdc.getCreateTime());
    return connector;
}
Also used : MDataConnector(org.apache.hadoop.hive.metastore.model.MDataConnector) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) DataConnector(org.apache.hadoop.hive.metastore.api.DataConnector) MDataConnector(org.apache.hadoop.hive.metastore.model.MDataConnector) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType)

Aggregations

DataConnector (org.apache.hadoop.hive.metastore.api.DataConnector)12 DDLWork (org.apache.hadoop.hive.ql.ddl.DDLWork)4 WriteEntity (org.apache.hadoop.hive.ql.hooks.WriteEntity)4 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)4 Database (org.apache.hadoop.hive.metastore.api.Database)3 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 ReadEntity (org.apache.hadoop.hive.ql.hooks.ReadEntity)2 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)2 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)2 Test (org.junit.Test)2 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 SQLException (java.sql.SQLException)1 Path (org.apache.hadoop.fs.Path)1 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)1