Search in sources :

Example 1 with HiveMetaStoreBridge

use of org.apache.atlas.hive.bridge.HiveMetaStoreBridge in project incubator-atlas by apache.

the class HiveHook method collect.

private void collect(HiveEventContext event) throws Exception {
    assert event.getHookType() == HookContext.HookType.POST_EXEC_HOOK : "Non-POST_EXEC_HOOK not supported!";
    LOG.info("Entered Atlas hook for hook type {}, operation {} , user {} as {}", event.getHookType(), event.getOperation(), event.getUgi().getRealUser(), event.getUgi().getShortUserName());
    HiveMetaStoreBridge dgiBridge = new HiveMetaStoreBridge(atlasProperties, hiveConf);
    switch(event.getOperation()) {
        case CREATEDATABASE:
            handleEventOutputs(dgiBridge, event, Type.DATABASE);
            break;
        case CREATETABLE:
            LinkedHashMap<Type, Referenceable> tablesCreated = handleEventOutputs(dgiBridge, event, Type.TABLE);
            if (tablesCreated != null && tablesCreated.size() > 0) {
                handleExternalTables(dgiBridge, event, tablesCreated);
            }
            break;
        case CREATETABLE_AS_SELECT:
        case CREATEVIEW:
        case ALTERVIEW_AS:
        case LOAD:
        case EXPORT:
        case IMPORT:
        case QUERY:
        case TRUNCATETABLE:
            registerProcess(dgiBridge, event);
            break;
        case ALTERTABLE_RENAME:
        case ALTERVIEW_RENAME:
            renameTable(dgiBridge, event);
            break;
        case ALTERTABLE_FILEFORMAT:
        case ALTERTABLE_CLUSTER_SORT:
        case ALTERTABLE_BUCKETNUM:
        case ALTERTABLE_PROPERTIES:
        case ALTERVIEW_PROPERTIES:
        case ALTERTABLE_SERDEPROPERTIES:
        case ALTERTABLE_SERIALIZER:
        case ALTERTABLE_ADDCOLS:
        case ALTERTABLE_REPLACECOLS:
        case ALTERTABLE_PARTCOLTYPE:
            handleEventOutputs(dgiBridge, event, Type.TABLE);
            break;
        case ALTERTABLE_RENAMECOL:
            renameColumn(dgiBridge, event);
            break;
        case ALTERTABLE_LOCATION:
            LinkedHashMap<Type, Referenceable> tablesUpdated = handleEventOutputs(dgiBridge, event, Type.TABLE);
            if (tablesUpdated != null && tablesUpdated.size() > 0) {
                //Track altered lineage in case of external tables
                handleExternalTables(dgiBridge, event, tablesUpdated);
            }
            break;
        case ALTERDATABASE:
        case ALTERDATABASE_OWNER:
            handleEventOutputs(dgiBridge, event, Type.DATABASE);
            break;
        case DROPTABLE:
        case DROPVIEW:
            deleteTable(dgiBridge, event);
            break;
        case DROPDATABASE:
            deleteDatabase(dgiBridge, event);
            break;
        default:
    }
}
Also used : HiveMetaStoreBridge(org.apache.atlas.hive.bridge.HiveMetaStoreBridge) Type(org.apache.hadoop.hive.ql.hooks.Entity.Type) TableType(org.apache.hadoop.hive.metastore.TableType) Referenceable(org.apache.atlas.typesystem.Referenceable)

Example 2 with HiveMetaStoreBridge

use of org.apache.atlas.hive.bridge.HiveMetaStoreBridge in project incubator-atlas by apache.

the class HiveITBase method setUp.

@BeforeClass
public void setUp() throws Exception {
    //Set-up hive session
    conf = new HiveConf();
    conf.setClassLoader(Thread.currentThread().getContextClassLoader());
    driver = new Driver(conf);
    ss = new SessionState(conf);
    ss = SessionState.start(ss);
    SessionState.setCurrentSessionState(ss);
    Configuration configuration = ApplicationProperties.get();
    String[] atlasEndPoint = configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT);
    if (atlasEndPoint == null || atlasEndPoint.length == 0) {
        atlasEndPoint = new String[] { DGI_URL };
    }
    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        atlasClient = new AtlasClient(atlasEndPoint, new String[] { "admin", "admin" });
    } else {
        atlasClient = new AtlasClient(atlasEndPoint);
    }
    hiveMetaStoreBridge = new HiveMetaStoreBridge(configuration, conf, atlasClient);
    HiveConf conf = new HiveConf();
    conf.set("hive.exec.post.hooks", "");
    SessionState ss = new SessionState(conf);
    ss = SessionState.start(ss);
    SessionState.setCurrentSessionState(ss);
    driverWithoutContext = new Driver(conf);
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) HiveMetaStoreBridge(org.apache.atlas.hive.bridge.HiveMetaStoreBridge) Configuration(org.apache.commons.configuration.Configuration) Driver(org.apache.hadoop.hive.ql.Driver) HiveConf(org.apache.hadoop.hive.conf.HiveConf) AtlasClient(org.apache.atlas.AtlasClient) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

HiveMetaStoreBridge (org.apache.atlas.hive.bridge.HiveMetaStoreBridge)2 AtlasClient (org.apache.atlas.AtlasClient)1 Referenceable (org.apache.atlas.typesystem.Referenceable)1 Configuration (org.apache.commons.configuration.Configuration)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 TableType (org.apache.hadoop.hive.metastore.TableType)1 Driver (org.apache.hadoop.hive.ql.Driver)1 Type (org.apache.hadoop.hive.ql.hooks.Entity.Type)1 SessionState (org.apache.hadoop.hive.ql.session.SessionState)1 BeforeClass (org.testng.annotations.BeforeClass)1