Search in sources :

Example 11 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class HiveMetaStoreBridgeTest method createTableReference.

private Referenceable createTableReference() {
    Referenceable tableReference = new Referenceable(HiveDataTypes.HIVE_TABLE.getName());
    Referenceable sdReference = new Referenceable(HiveDataTypes.HIVE_STORAGEDESC.getName());
    tableReference.set(HiveMetaStoreBridge.STORAGE_DESC, sdReference);
    return tableReference;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable)

Example 12 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class HiveMetaStoreBridge method registerDatabase.

/**
     * Checks if db is already registered, else creates and registers db entity
     * @param databaseName
     * @return
     * @throws Exception
     */
private Referenceable registerDatabase(String databaseName) throws Exception {
    Referenceable dbRef = getDatabaseReference(clusterName, databaseName);
    Database db = hiveClient.getDatabase(databaseName);
    if (db != null) {
        if (dbRef == null) {
            dbRef = createDBInstance(db);
            dbRef = registerInstance(dbRef);
        } else {
            LOG.info("Database {} is already registered with id {}. Updating it.", databaseName, dbRef.getId().id);
            dbRef = createOrUpdateDBInstance(db, dbRef);
            updateInstance(dbRef);
        }
    }
    return dbRef;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Database(org.apache.hadoop.hive.metastore.api.Database)

Example 13 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class HiveMetaStoreBridge method createOrUpdateTableInstance.

private Referenceable createOrUpdateTableInstance(Referenceable dbReference, Referenceable tableReference, final Table hiveTable) throws AtlasHookException {
    LOG.info("Importing objects from {}.{}", hiveTable.getDbName(), hiveTable.getTableName());
    if (tableReference == null) {
        tableReference = new Referenceable(HiveDataTypes.HIVE_TABLE.getName());
    }
    String tableQualifiedName = getTableQualifiedName(clusterName, hiveTable);
    tableReference.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableQualifiedName);
    tableReference.set(AtlasClient.NAME, hiveTable.getTableName().toLowerCase());
    tableReference.set(AtlasClient.OWNER, hiveTable.getOwner());
    Date createDate = new Date();
    if (hiveTable.getTTable() != null) {
        try {
            createDate = getTableCreatedTime(hiveTable);
            LOG.debug("Setting create time to {} ", createDate);
            tableReference.set(CREATE_TIME, createDate);
        } catch (Exception ne) {
            LOG.error("Error while setting createTime for the table {} ", hiveTable.getCompleteName(), ne);
        }
    }
    Date lastAccessTime = createDate;
    if (hiveTable.getLastAccessTime() > 0) {
        lastAccessTime = new Date(hiveTable.getLastAccessTime() * MILLIS_CONVERT_FACTOR);
    }
    tableReference.set(LAST_ACCESS_TIME, lastAccessTime);
    tableReference.set("retention", hiveTable.getRetention());
    tableReference.set(COMMENT, hiveTable.getParameters().get(COMMENT));
    // add reference to the database
    tableReference.set(DB, dbReference);
    // add reference to the StorageDescriptor
    Referenceable sdReferenceable = fillStorageDesc(hiveTable.getSd(), tableQualifiedName, getStorageDescQFName(tableQualifiedName), tableReference.getId());
    tableReference.set(STORAGE_DESC, sdReferenceable);
    tableReference.set(PARAMETERS, hiveTable.getParameters());
    if (hiveTable.getViewOriginalText() != null) {
        tableReference.set("viewOriginalText", hiveTable.getViewOriginalText());
    }
    if (hiveTable.getViewExpandedText() != null) {
        tableReference.set("viewExpandedText", hiveTable.getViewExpandedText());
    }
    tableReference.set(TABLE_TYPE_ATTR, hiveTable.getTableType().name());
    tableReference.set("temporary", hiveTable.isTemporary());
    // add reference to the Partition Keys
    List<Referenceable> partKeys = getColumns(hiveTable.getPartitionKeys(), tableReference);
    tableReference.set("partitionKeys", partKeys);
    tableReference.set(COLUMNS, getColumns(hiveTable.getCols(), tableReference));
    return tableReference;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Date(java.util.Date) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasHookException(org.apache.atlas.hook.AtlasHookException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException)

Example 14 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class HiveITBase method validateHDFSPaths.

protected void validateHDFSPaths(Referenceable processReference, String attributeName, String... testPaths) throws Exception {
    List<Id> hdfsPathRefs = (List<Id>) processReference.get(attributeName);
    for (String testPath : testPaths) {
        final Path path = new Path(testPath);
        final String testPathNormed = lower(path.toString());
        String hdfsPathId = assertHDFSPathIsRegistered(testPathNormed);
        Assert.assertEquals(hdfsPathRefs.get(0)._getId(), hdfsPathId);
        Referenceable hdfsPathRef = atlasClient.getEntity(hdfsPathId);
        Assert.assertEquals(hdfsPathRef.get("path"), testPathNormed);
        Assert.assertEquals(hdfsPathRef.get(NAME), Path.getPathWithoutSchemeAndAuthority(path).toString().toLowerCase());
        Assert.assertEquals(hdfsPathRef.get(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME), testPathNormed);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Referenceable(org.apache.atlas.typesystem.Referenceable) List(java.util.List) Id(org.apache.atlas.typesystem.persistence.Id)

Example 15 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class HiveHookIT method getSortedProcessDataSets.

private <T extends Entity> SortedMap<T, Referenceable> getSortedProcessDataSets(Set<T> inputTbls) {
    SortedMap<T, Referenceable> inputs = new TreeMap<>(entityComparator);
    if (inputTbls != null) {
        for (final T tbl : inputTbls) {
            Referenceable inputTableRef = new Referenceable(getDSTypeName(tbl), new HashMap<String, Object>() {

                {
                    put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tbl.getName());
                }
            });
            inputs.put(tbl, inputTableRef);
        }
    }
    return inputs;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) JSONObject(org.codehaus.jettison.json.JSONObject)

Aggregations

Referenceable (org.apache.atlas.typesystem.Referenceable)235 Test (org.testng.annotations.Test)114 Id (org.apache.atlas.typesystem.persistence.Id)50 ArrayList (java.util.ArrayList)45 List (java.util.List)25 Struct (org.apache.atlas.typesystem.Struct)25 HashMap (java.util.HashMap)24 BeforeTest (org.testng.annotations.BeforeTest)24 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)22 AfterTest (org.testng.annotations.AfterTest)22 HookNotification (org.apache.atlas.notification.hook.HookNotification)20 IStruct (org.apache.atlas.typesystem.IStruct)18 ClassType (org.apache.atlas.typesystem.types.ClassType)16 JSONObject (org.codehaus.jettison.json.JSONObject)16 ImmutableList (com.google.common.collect.ImmutableList)15 AtlasServiceException (org.apache.atlas.AtlasServiceException)14 TraitType (org.apache.atlas.typesystem.types.TraitType)12 WriteEntity (org.apache.hadoop.hive.ql.hooks.WriteEntity)12 Date (java.util.Date)11 AtlasException (org.apache.atlas.AtlasException)11