Search in sources :

Example 1 with PreprocessAction

use of org.apache.atlas.hive.hook.HiveHook.PreprocessAction in project atlas by apache.

the class BaseHiveEvent method toTableEntity.

protected AtlasEntity toTableEntity(AtlasObjectId dbId, Table table, AtlasEntityExtInfo entityExtInfo) throws Exception {
    String tblQualifiedName = getQualifiedName(table);
    boolean isKnownTable = context.isKnownTable(tblQualifiedName);
    AtlasEntity ret = context.getEntity(tblQualifiedName);
    if (ret == null) {
        PreprocessAction action = context.getPreprocessActionForHiveTable(tblQualifiedName);
        if (action == PreprocessAction.IGNORE) {
            LOG.info("ignoring table {}", tblQualifiedName);
        } else {
            ret = new AtlasEntity(HIVE_TYPE_TABLE);
            // - cause Atlas server to resolve the entity by its qualifiedName
            if (isKnownTable && !isAlterTableOperation()) {
                ret.setGuid(null);
            }
            long createTime = getTableCreateTime(table);
            long lastAccessTime = table.getLastAccessTime() > 0 ? (table.getLastAccessTime() * MILLIS_CONVERT_FACTOR) : createTime;
            AtlasRelatedObjectId dbRelatedObject = new AtlasRelatedObjectId(dbId, RELATIONSHIP_HIVE_TABLE_DB);
            ret.setRelationshipAttribute(ATTRIBUTE_DB, dbRelatedObject);
            ret.setAttribute(ATTRIBUTE_QUALIFIED_NAME, tblQualifiedName);
            ret.setAttribute(ATTRIBUTE_NAME, table.getTableName().toLowerCase());
            ret.setAttribute(ATTRIBUTE_OWNER, table.getOwner());
            ret.setAttribute(ATTRIBUTE_CREATE_TIME, createTime);
            ret.setAttribute(ATTRIBUTE_LAST_ACCESS_TIME, lastAccessTime);
            ret.setAttribute(ATTRIBUTE_RETENTION, table.getRetention());
            ret.setAttribute(ATTRIBUTE_PARAMETERS, table.getParameters());
            ret.setAttribute(ATTRIBUTE_COMMENT, table.getParameters().get(ATTRIBUTE_COMMENT));
            ret.setAttribute(ATTRIBUTE_TABLE_TYPE, table.getTableType().name());
            ret.setAttribute(ATTRIBUTE_TEMPORARY, table.isTemporary());
            if (table.getViewOriginalText() != null) {
                ret.setAttribute(ATTRIBUTE_VIEW_ORIGINAL_TEXT, table.getViewOriginalText());
            }
            if (table.getViewExpandedText() != null) {
                ret.setAttribute(ATTRIBUTE_VIEW_EXPANDED_TEXT, table.getViewExpandedText());
            }
            boolean pruneTable = table.isTemporary() || action == PreprocessAction.PRUNE;
            if (pruneTable) {
                LOG.info("ignoring details of table {}", tblQualifiedName);
            } else {
                AtlasObjectId tableId = AtlasTypeUtil.getObjectId(ret);
                AtlasEntity sd = getStorageDescEntity(tableId, table);
                List<AtlasEntity> partitionKeys = getColumnEntities(tableId, table, table.getPartitionKeys(), RELATIONSHIP_HIVE_TABLE_PART_KEYS);
                List<AtlasEntity> columns = getColumnEntities(tableId, table, table.getCols(), RELATIONSHIP_HIVE_TABLE_COLUMNS);
                if (entityExtInfo != null) {
                    entityExtInfo.addReferredEntity(sd);
                    if (partitionKeys != null) {
                        for (AtlasEntity partitionKey : partitionKeys) {
                            entityExtInfo.addReferredEntity(partitionKey);
                        }
                    }
                    if (columns != null) {
                        for (AtlasEntity column : columns) {
                            entityExtInfo.addReferredEntity(column);
                        }
                    }
                }
                ret.setRelationshipAttribute(ATTRIBUTE_STORAGEDESC, AtlasTypeUtil.getAtlasRelatedObjectId(sd, RELATIONSHIP_HIVE_TABLE_STORAGE_DESC));
                ret.setRelationshipAttribute(ATTRIBUTE_PARTITION_KEYS, AtlasTypeUtil.getAtlasRelatedObjectIds(partitionKeys, RELATIONSHIP_HIVE_TABLE_PART_KEYS));
                ret.setRelationshipAttribute(ATTRIBUTE_COLUMNS, AtlasTypeUtil.getAtlasRelatedObjectIds(columns, RELATIONSHIP_HIVE_TABLE_COLUMNS));
            }
            context.putEntity(tblQualifiedName, ret);
        }
    }
    return ret;
}
Also used : PreprocessAction(org.apache.atlas.hive.hook.HiveHook.PreprocessAction) AtlasRelatedObjectId(org.apache.atlas.model.instance.AtlasRelatedObjectId) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId)

Aggregations

PreprocessAction (org.apache.atlas.hive.hook.HiveHook.PreprocessAction)1 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)1 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)1 AtlasRelatedObjectId (org.apache.atlas.model.instance.AtlasRelatedObjectId)1