use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class GraphBackedMetadataRepositoryTest method testCreateEntityWithTwoNestingLevels.
@Test
public void testCreateEntityWithTwoNestingLevels() throws AtlasException {
List<Referenceable> toVerify = new ArrayList<>();
Referenceable dept = new Referenceable(TestUtils.DEPARTMENT_TYPE);
toVerify.add(dept);
dept.set(TestUtils.NAME, "test2");
Referenceable wallace = new Referenceable(TestUtils.PERSON_TYPE);
toVerify.add(wallace);
wallace.set(TestUtils.NAME, "Wallace");
wallace.set(TestUtils.DEPARTMENT_ATTR, dept);
Referenceable wallaceComputer = new Referenceable(TestUtils.ASSET_TYPE);
toVerify.add(wallaceComputer);
wallaceComputer.set("name", "wallaceComputer");
wallace.set(TestUtils.ASSETS_ATTR, ImmutableList.of(wallaceComputer));
Referenceable jordan = new Referenceable(TestUtils.PERSON_TYPE);
toVerify.add(jordan);
jordan.set(TestUtils.NAME, "Jordan");
jordan.set(TestUtils.DEPARTMENT_ATTR, dept);
Referenceable jordanComputer = new Referenceable(TestUtils.ASSET_TYPE);
toVerify.add(jordanComputer);
jordanComputer.set("name", "jordanComputer");
jordan.set(TestUtils.ASSETS_ATTR, ImmutableList.of(jordanComputer));
dept.set(TestUtils.EMPLOYEES_ATTR, ImmutableList.of(wallace, jordan));
Map<String, Referenceable> positions = new HashMap<>();
final String JANITOR = "janitor";
final String RECEPTIONIST = "receptionist";
positions.put(JANITOR, wallace);
positions.put(RECEPTIONIST, jordan);
dept.set(TestUtils.POSITIONS_ATTR, positions);
ClassType deptType = TypeSystem.getInstance().getDataType(ClassType.class, TestUtils.DEPARTMENT_TYPE);
ITypedReferenceableInstance deptInstance = deptType.convert(dept, Multiplicity.REQUIRED);
CreateUpdateEntitiesResult result = repositoryService.createEntities(deptInstance);
validateGuidMapping(toVerify, result);
}
use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class GraphBackedMetadataRepositoryTest method createEntity.
private List<String> createEntity(Referenceable entity) throws Exception {
ClassType type = typeSystem.getDataType(ClassType.class, entity.getTypeName());
ITypedReferenceableInstance instance = type.convert(entity, Multiplicity.REQUIRED);
return createEntities(instance);
}
use of org.apache.atlas.typesystem.types.ClassType 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);
}
use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class QuickStart method createTypeDefinitions.
TypesDef createTypeDefinitions() throws Exception {
HierarchicalTypeDefinition<ClassType> dbClsDef = TypesUtil.createClassTypeDef(DATABASE_TYPE, DATABASE_TYPE, null, TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), attrDef("description", DataTypes.STRING_TYPE), attrDef("locationUri", DataTypes.STRING_TYPE), attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE));
HierarchicalTypeDefinition<ClassType> storageDescClsDef = TypesUtil.createClassTypeDef(STORAGE_DESC_TYPE, STORAGE_DESC_TYPE, null, attrDef("location", DataTypes.STRING_TYPE), attrDef("inputFormat", DataTypes.STRING_TYPE), attrDef("outputFormat", DataTypes.STRING_TYPE), attrDef("compressed", DataTypes.STRING_TYPE, Multiplicity.REQUIRED, false, null));
HierarchicalTypeDefinition<ClassType> columnClsDef = TypesUtil.createClassTypeDef(COLUMN_TYPE, COLUMN_TYPE, null, attrDef("name", DataTypes.STRING_TYPE), attrDef("dataType", DataTypes.STRING_TYPE), attrDef("comment", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil.createClassTypeDef(TABLE_TYPE, TABLE_TYPE, ImmutableSet.of("DataSet"), new AttributeDefinition(DB_ATTRIBUTE, DATABASE_TYPE, Multiplicity.REQUIRED, false, null), new AttributeDefinition("sd", STORAGE_DESC_TYPE, Multiplicity.REQUIRED, true, null), attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE), attrDef("lastAccessTime", DataTypes.LONG_TYPE), attrDef("retention", DataTypes.LONG_TYPE), attrDef("viewOriginalText", DataTypes.STRING_TYPE), attrDef("viewExpandedText", DataTypes.STRING_TYPE), attrDef("tableType", DataTypes.STRING_TYPE), attrDef("temporary", DataTypes.BOOLEAN_TYPE), new AttributeDefinition(COLUMNS_ATTRIBUTE, DataTypes.arrayTypeName(COLUMN_TYPE), Multiplicity.COLLECTION, true, null));
HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil.createClassTypeDef(LOAD_PROCESS_TYPE, LOAD_PROCESS_TYPE, ImmutableSet.of("Process"), attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.LONG_TYPE), attrDef("endTime", DataTypes.LONG_TYPE), attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), attrDef("queryPlan", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), attrDef("queryId", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), attrDef("queryGraph", DataTypes.STRING_TYPE, Multiplicity.REQUIRED));
HierarchicalTypeDefinition<ClassType> viewClsDef = TypesUtil.createClassTypeDef(VIEW_TYPE, VIEW_TYPE, ImmutableSet.of("DataSet"), new AttributeDefinition("db", DATABASE_TYPE, Multiplicity.REQUIRED, false, null), new AttributeDefinition("inputTables", DataTypes.arrayTypeName(TABLE_TYPE), Multiplicity.COLLECTION, false, null));
HierarchicalTypeDefinition<TraitType> dimTraitDef = TypesUtil.createTraitTypeDef("Dimension_v1", "Dimension Trait", null);
HierarchicalTypeDefinition<TraitType> factTraitDef = TypesUtil.createTraitTypeDef("Fact_v1", "Fact Trait", null);
HierarchicalTypeDefinition<TraitType> piiTraitDef = TypesUtil.createTraitTypeDef("PII_v1", "PII Trait", null);
HierarchicalTypeDefinition<TraitType> metricTraitDef = TypesUtil.createTraitTypeDef("Metric_v1", "Metric Trait", null);
HierarchicalTypeDefinition<TraitType> etlTraitDef = TypesUtil.createTraitTypeDef("ETL_v1", "ETL Trait", null);
HierarchicalTypeDefinition<TraitType> jdbcTraitDef = TypesUtil.createTraitTypeDef("JdbcAccess_v1", "JdbcAccess Trait", null);
HierarchicalTypeDefinition<TraitType> logTraitDef = TypesUtil.createTraitTypeDef("Log Data_v1", "LogData Trait", null);
return TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.of(dimTraitDef, factTraitDef, piiTraitDef, metricTraitDef, etlTraitDef, jdbcTraitDef, logTraitDef), ImmutableList.of(dbClsDef, storageDescClsDef, columnClsDef, tblClsDef, loadProcessClsDef, viewClsDef));
}
use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class FieldMappingTest method testOutputStruct.
@Test
public void testOutputStruct() throws Exception {
// ATLAS-645: verify that FieldMapping.output(IStruct) does not infinitely recurse
// when an IStruct and ITypedReferenceableInstance reference each other.
HierarchicalTypeDefinition<ClassType> valueDef = TypesUtil.createClassTypeDef("Value", ImmutableSet.<String>of(), new AttributeDefinition("owner", "Owner", Multiplicity.OPTIONAL, false, null));
// Define struct type with reference, where the value is a class reference to Value.
StructTypeDefinition ownerDef = TypesUtil.createStructTypeDef("Owner", new AttributeDefinition("value", "Value", Multiplicity.OPTIONAL, false, null));
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.of(ownerDef), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(valueDef));
TypeSystem typeSystem = TypeSystem.getInstance();
typeSystem.reset();
typeSystem.defineTypes(typesDef);
StructType ownerType = typeSystem.getDataType(StructType.class, "Owner");
ClassType valueType = typeSystem.getDataType(ClassType.class, "Value");
// Prior to fix for ATLAS-645, this call would throw a StackOverflowError
try {
ownerType.toString();
} catch (StackOverflowError e) {
Assert.fail("Infinite recursion in StructType.toString() caused StackOverflowError");
}
// Create instances of Owner and Value that reference each other.
ITypedStruct ownerInstance = ownerType.createInstance();
ITypedReferenceableInstance valueInstance = valueType.createInstance();
// Set Owner.value reference to Value instance.
ownerInstance.set("value", valueInstance);
// Set Value.owner reference on Owner instance.
valueInstance.set("owner", ownerInstance);
// Prior to fix for ATLAS-645, this call would throw a StackOverflowError
try {
ownerInstance.fieldMapping().output(ownerInstance, new StringBuilder(), "", null);
} catch (StackOverflowError e) {
Assert.fail("Infinite recursion in FieldMapping.output() caused StackOverflowError");
}
}
Aggregations