Search in sources :

Example 61 with Referenceable

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

the class DataSetLineageServiceTest 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)

Example 62 with Referenceable

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

the class BaseRepositoryTest method view.

Id view(String name, Id dbId, List<Id> inputTables, String... traitNames) throws Exception {
    Referenceable referenceable = new Referenceable(VIEW_TYPE, traitNames);
    referenceable.set("name", name);
    referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
    referenceable.set("db", dbId);
    referenceable.set("inputTables", inputTables);
    ClassType clsType = TypeSystem.getInstance().getDataType(ClassType.class, VIEW_TYPE);
    return createInstance(referenceable, clsType);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable)

Example 63 with Referenceable

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

the class TestUtils method createInstance.

/**
     * Creates an entity in the graph and does basic validation
     * of the GuidMapping that was created in the process.
     *
     */
public static String createInstance(MetadataService metadataService, Referenceable entity) throws Exception {
    RequestContext.createContext();
    String entityjson = InstanceSerialization.toJson(entity, true);
    JSONArray entitiesJson = new JSONArray();
    entitiesJson.put(entityjson);
    CreateUpdateEntitiesResult creationResult = metadataService.createEntities(entitiesJson.toString());
    Map<String, String> guidMap = creationResult.getGuidMapping().getGuidAssignments();
    Map<Id, Referenceable> referencedObjects = findReferencedObjects(entity);
    for (Map.Entry<Id, Referenceable> entry : referencedObjects.entrySet()) {
        Id foundId = entry.getKey();
        if (foundId.isUnassigned()) {
            String guid = guidMap.get(entry.getKey()._getId());
            Referenceable obj = entry.getValue();
            loadAndDoSimpleValidation(guid, obj, metadataService);
        }
    }
    List<String> guids = creationResult.getCreatedEntities();
    if (guids != null && guids.size() > 0) {
        return guids.get(guids.size() - 1);
    }
    return null;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) JSONArray(org.codehaus.jettison.json.JSONArray) Id(org.apache.atlas.typesystem.persistence.Id) Map(java.util.Map) HashMap(java.util.HashMap)

Example 64 with Referenceable

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

the class GraphBackedDiscoveryServiceTest method createInstances.

private void createInstances() throws Exception {
    Referenceable instance = new Referenceable("D");
    instance.set("d", 1);
    instance.set("c", 1);
    instance.set("b", true);
    instance.set("a", 1);
    ClassType deptType = TypeSystem.getInstance().getDataType(ClassType.class, "D");
    ITypedReferenceableInstance typedInstance = deptType.convert(instance, Multiplicity.REQUIRED);
    repositoryService.createEntities(typedInstance);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 65 with Referenceable

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

the class QuickStart method view.

Id view(String name, Id dbId, List<Id> inputTables, String... traitNames) throws AtlasBaseException {
    try {
        Referenceable referenceable = new Referenceable(VIEW_TYPE, traitNames);
        referenceable.set("name", name);
        referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
        referenceable.set("db", dbId);
        referenceable.set(INPUT_TABLES_ATTRIBUTE, inputTables);
        return createInstance(referenceable);
    } catch (Exception e) {
        throw new AtlasBaseException(AtlasErrorCode.QUICK_START, e, String.format("%s Id creation", name));
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.typesystem.Referenceable) AtlasException(org.apache.atlas.AtlasException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

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