Search in sources :

Example 31 with Struct

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

the class EntityNotificationImplTest method testGetAllTraitsSuperTraits.

@Test
public void testGetAllTraitsSuperTraits() throws Exception {
    TypeSystem typeSystem = mock(TypeSystem.class);
    String traitName = "MyTrait";
    IStruct myTrait = new Struct(traitName);
    String superTraitName = "MySuperTrait";
    TraitType traitDef = mock(TraitType.class);
    Set<String> superTypeNames = Collections.singleton(superTraitName);
    TraitType superTraitDef = mock(TraitType.class);
    Set<String> superSuperTypeNames = Collections.emptySet();
    Referenceable entity = getEntity("id", myTrait);
    when(typeSystem.getDataType(TraitType.class, traitName)).thenReturn(traitDef);
    when(typeSystem.getDataType(TraitType.class, superTraitName)).thenReturn(superTraitDef);
    when(traitDef.getAllSuperTypeNames()).thenReturn(superTypeNames);
    when(superTraitDef.getAllSuperTypeNames()).thenReturn(superSuperTypeNames);
    EntityNotificationImpl entityNotification = new EntityNotificationImpl(entity, EntityNotification.OperationType.TRAIT_ADD, typeSystem);
    List<IStruct> allTraits = entityNotification.getAllTraits();
    assertEquals(2, allTraits.size());
    for (IStruct trait : allTraits) {
        String typeName = trait.getTypeName();
        assertTrue(typeName.equals(traitName) || typeName.equals(superTraitName));
    }
}
Also used : TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) Referenceable(org.apache.atlas.typesystem.Referenceable) TraitType(org.apache.atlas.typesystem.types.TraitType) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 32 with Struct

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

the class GraphRepoMapperScaleTest method createHiveTableInstance.

private ITypedReferenceableInstance createHiveTableInstance(Referenceable databaseInstance, int uberIndex) throws Exception {
    Referenceable tableInstance = new Referenceable(TestUtils.TABLE_TYPE);
    tableInstance.set("name", TABLE_NAME + "-" + uberIndex);
    tableInstance.set("description", "bar table" + "-" + uberIndex);
    tableInstance.set("type", "managed");
    tableInstance.set("created", new Date(TestUtils.TEST_DATE_IN_LONG));
    // enum
    tableInstance.set("tableType", 1);
    // refer to an existing class
    tableInstance.set("database", databaseInstance);
    ArrayList<String> columnNames = new ArrayList<>();
    columnNames.add("first_name" + "-" + uberIndex);
    columnNames.add("last_name" + "-" + uberIndex);
    tableInstance.set("columnNames", columnNames);
    Struct serde1Instance = new Struct("serdeType");
    serde1Instance.set("name", "serde1" + "-" + uberIndex);
    serde1Instance.set("serde", "serde1" + "-" + uberIndex);
    tableInstance.set("serde1", serde1Instance);
    Struct serde2Instance = new Struct("serdeType");
    serde2Instance.set("name", "serde2" + "-" + uberIndex);
    serde2Instance.set("serde", "serde2" + "-" + uberIndex);
    tableInstance.set("serde2", serde2Instance);
    ArrayList<Referenceable> columns = new ArrayList<>();
    for (int index = 0; index < 5; index++) {
        Referenceable columnInstance = new Referenceable("column_type");
        columnInstance.set("name", "column_" + "-" + uberIndex + "-" + index);
        columnInstance.set("type", "string");
        columns.add(columnInstance);
    }
    tableInstance.set("columns", columns);
    ArrayList<Struct> partitions = new ArrayList<>();
    for (int index = 0; index < 5; index++) {
        Struct partitionInstance = new Struct(TestUtils.PARTITION_STRUCT_TYPE);
        partitionInstance.set("name", "partition_" + "-" + uberIndex + "-" + index);
        partitions.add(partitionInstance);
    }
    tableInstance.set("partitions", partitions);
    ClassType tableType = typeSystem.getDataType(ClassType.class, TestUtils.TABLE_TYPE);
    return tableType.convert(tableInstance, Multiplicity.REQUIRED);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ArrayList(java.util.ArrayList) ClassType(org.apache.atlas.typesystem.types.ClassType) Date(java.util.Date) Struct(org.apache.atlas.typesystem.Struct)

Example 33 with Struct

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

the class NotificationEntityChangeListener method getSuperTraits.

private static List<IStruct> getSuperTraits(String typeName, Map<String, Object> values, TypeSystem typeSystem) throws AtlasException {
    List<IStruct> superTypes = new LinkedList<>();
    TraitType traitDef = typeSystem.getDataType(TraitType.class, typeName);
    Set<String> superTypeNames = traitDef.getAllSuperTypeNames();
    for (String superTypeName : superTypeNames) {
        TraitType superTraitDef = typeSystem.getDataType(TraitType.class, superTypeName);
        Map<String, Object> superTypeValues = new HashMap<>();
        FieldMapping fieldMapping = superTraitDef.fieldMapping();
        if (fieldMapping != null) {
            Set<String> superTypeAttributeNames = fieldMapping.fields.keySet();
            for (String superTypeAttributeName : superTypeAttributeNames) {
                if (values.containsKey(superTypeAttributeName)) {
                    superTypeValues.put(superTypeAttributeName, values.get(superTypeAttributeName));
                }
            }
        }
        IStruct superTrait = new Struct(superTypeName, superTypeValues);
        superTypes.add(superTrait);
        superTypes.addAll(getSuperTraits(superTypeName, values, typeSystem));
    }
    return superTypes;
}
Also used : HashMap(java.util.HashMap) TraitType(org.apache.atlas.typesystem.types.TraitType) FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) LinkedList(java.util.LinkedList) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct)

Example 34 with Struct

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

the class DataSetLineageJerseyResourceIT method testInputsGraphForEntity.

@Test
public void testInputsGraphForEntity() throws Exception {
    String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
    JSONObject results = atlasClientV1.getInputGraphForEntity(tableId);
    Assert.assertNotNull(results);
    Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
    Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
    Assert.assertEquals(vertices.size(), 4);
    Struct vertex = vertices.get(tableId);
    assertEquals(((Struct) vertex.get("vertexId")).get("state"), Id.EntityState.ACTIVE.name());
    Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
    Assert.assertEquals(edges.size(), 4);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) Map(java.util.Map) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 35 with Struct

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

the class DataSetLineageJerseyResourceIT method testOutputsGraph.

@Test
public void testOutputsGraph() throws Exception {
    JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_OUTPUTS_GRAPH, null, salesFactTable, "outputs", "graph");
    Assert.assertNotNull(response);
    System.out.println("outputs graph= " + response);
    Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
    JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
    Assert.assertNotNull(results);
    Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
    Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
    Assert.assertEquals(vertices.size(), 3);
    Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
    Assert.assertEquals(edges.size(), 4);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) Map(java.util.Map) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Aggregations

Struct (org.apache.atlas.typesystem.Struct)56 Test (org.testng.annotations.Test)36 IStruct (org.apache.atlas.typesystem.IStruct)29 Referenceable (org.apache.atlas.typesystem.Referenceable)25 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)17 TraitType (org.apache.atlas.typesystem.types.TraitType)12 ArrayList (java.util.ArrayList)9 LinkedList (java.util.LinkedList)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Id (org.apache.atlas.typesystem.persistence.Id)7 JSONObject (org.codehaus.jettison.json.JSONObject)7 BeforeTest (org.testng.annotations.BeforeTest)6 AfterTest (org.testng.annotations.AfterTest)5 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 ITypedInstance (org.apache.atlas.typesystem.ITypedInstance)4 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)4 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)4 Date (java.util.Date)3