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));
}
}
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);
}
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;
}
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);
}
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);
}
Aggregations