Search in sources :

Example 66 with Id

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

the class ReplaceIdWithInstance method processNode.

@Override
public void processNode(ObjectGraphWalker.Node nd) throws AtlasException {
    if (nd.attributeName != null) {
        if (nd.aInfo.isComposite && nd.value != null) {
            if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
                if (nd.value instanceof Id) {
                    Id id = (Id) nd.value;
                    ITypedReferenceableInstance r = getInstance(id);
                    nd.instance.set(nd.attributeName, r);
                }
            } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) {
                DataTypes.ArrayType aT = (DataTypes.ArrayType) nd.aInfo.dataType();
                nd.instance.set(nd.attributeName, convertToInstances((ImmutableCollection) nd.value, nd.aInfo.multiplicity, aT));
            } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
                DataTypes.MapType mT = (DataTypes.MapType) nd.aInfo.dataType();
                nd.instance.set(nd.attributeName, convertToInstances((ImmutableMap) nd.value, nd.aInfo.multiplicity, mT));
            }
        }
    }
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) ImmutableMap(com.google.common.collect.ImmutableMap) DataTypes(org.apache.atlas.typesystem.types.DataTypes)

Example 67 with Id

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

the class TypedInstanceToGraphMapper method createGuidMapping.

public GuidMapping createGuidMapping() {
    Map<String, String> mapping = new HashMap<>(idToVertexMap.size());
    for (Map.Entry<Id, AtlasVertex> entry : idToVertexMap.entrySet()) {
        Id id = entry.getKey();
        if (id.isUnassigned()) {
            AtlasVertex classVertex = entry.getValue();
            mapping.put(id._getId(), GraphHelper.getGuid(classVertex));
        }
    }
    return new GuidMapping(mapping);
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) HashMap(java.util.HashMap) Id(org.apache.atlas.typesystem.persistence.Id) HashMap(java.util.HashMap) Map(java.util.Map) GuidMapping(org.apache.atlas.model.instance.GuidMapping)

Example 68 with Id

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

the class TypedInstanceToGraphMapper method addToEntityCache.

private void addToEntityCache(RequestContext context, ITypedReferenceableInstance instance) throws EntityNotFoundException {
    Id instanceId = instance.getId();
    if (instanceId.isUnassigned()) {
        if (instance instanceof ReferenceableInstance) {
            //When the id is unassigned, we can only cache the instance of it is
            //an instance of ReferenceableInstance, since replaceWithNewId is not
            //currently in the ITypedReferenceableInstance interface.
            Id id = getId(instance);
            ((ReferenceableInstance) instance).replaceWithNewId(id);
            context.cache(instance);
        }
    } else {
        context.cache(instance);
    }
}
Also used : Id(org.apache.atlas.typesystem.persistence.Id) ReferenceableInstance(org.apache.atlas.typesystem.persistence.ReferenceableInstance) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance)

Example 69 with Id

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

the class TypedInstanceToGraphMapper method getId.

private Id getId(ITypedReferenceableInstance typedReference) throws EntityNotFoundException {
    if (typedReference == null) {
        throw new IllegalArgumentException("typedReference must be non-null");
    }
    Id id = typedReference instanceof Id ? (Id) typedReference : typedReference.getId();
    if (id.isUnassigned()) {
        AtlasVertex classVertex = idToVertexMap.get(id);
        String guid = GraphHelper.getGuid(classVertex);
        id = new Id(guid, 0, typedReference.getTypeName());
    }
    return id;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) Id(org.apache.atlas.typesystem.persistence.Id)

Example 70 with Id

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

the class EntityLineageServiceTest method createTable.

private void createTable(String tableName, int numCols, boolean createLineage) throws Exception {
    String dbId = getEntityId(DATABASE_TYPE, "name", "Sales");
    Id salesDB = new Id(dbId, 0, DATABASE_TYPE);
    //Create the entity again and schema should return the new schema
    List<Referenceable> columns = new ArrayStack();
    for (int i = 0; i < numCols; i++) {
        columns.add(column("col" + random(), "int", "column descr"));
    }
    Referenceable sd = storageDescriptor("hdfs://host:8000/apps/warehouse/sales", "TextInputFormat", "TextOutputFormat", true, ImmutableList.of(column("time_id", "int", "time id")));
    Id table = table(tableName, "test table", salesDB, sd, "fetl", "External", columns);
    if (createLineage) {
        Id inTable = table("table" + random(), "test table", salesDB, sd, "fetl", "External", columns);
        Id outTable = table("table" + random(), "test table", salesDB, sd, "fetl", "External", columns);
        loadProcess("process" + random(), "hive query for monthly summary", "Tim ETL", ImmutableList.of(inTable), ImmutableList.of(table), "create table as select ", "plan", "id", "graph", "ETL");
        loadProcess("process" + random(), "hive query for monthly summary", "Tim ETL", ImmutableList.of(table), ImmutableList.of(outTable), "create table as select ", "plan", "id", "graph", "ETL");
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Id(org.apache.atlas.typesystem.persistence.Id) ArrayStack(org.apache.commons.collections.ArrayStack)

Aggregations

Id (org.apache.atlas.typesystem.persistence.Id)94 Referenceable (org.apache.atlas.typesystem.Referenceable)50 Test (org.testng.annotations.Test)37 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)28 List (java.util.List)17 ArrayList (java.util.ArrayList)12 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)12 ImmutableList (com.google.common.collect.ImmutableList)10 TraitType (org.apache.atlas.typesystem.types.TraitType)10 JSONObject (org.codehaus.jettison.json.JSONObject)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AtlasServiceException (org.apache.atlas.AtlasServiceException)7 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)7 Struct (org.apache.atlas.typesystem.Struct)7 ClassType (org.apache.atlas.typesystem.types.ClassType)7 AtlasException (org.apache.atlas.AtlasException)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)5