use of org.apache.atlas.typesystem.types.AttributeInfo in project incubator-atlas by apache.
the class StoreBackedTypeCacheTest method verifyHierarchicalType.
private <T extends HierarchicalType> void verifyHierarchicalType(T dataType, T expectedDataType) throws AtlasException {
Assert.assertEquals(dataType.numFields, expectedDataType.numFields);
Assert.assertEquals(dataType.immediateAttrs.size(), expectedDataType.immediateAttrs.size());
Assert.assertEquals(dataType.fieldMapping().fields.size(), expectedDataType.fieldMapping().fields.size());
ImmutableSet<String> superTypes = dataType.superTypes;
Assert.assertEquals(superTypes.size(), expectedDataType.superTypes.size());
// Verify that any attribute and super types were also cached.
for (String superTypeName : superTypes) {
Assert.assertTrue(typeCache.has(superTypeName));
}
for (AttributeInfo attrInfo : dataType.fieldMapping().fields.values()) {
switch(attrInfo.dataType().getTypeCategory()) {
case CLASS:
case STRUCT:
case ENUM:
Assert.assertTrue(typeCache.has(attrInfo.dataType().getName()), attrInfo.dataType().getName() + " should be cached");
break;
case ARRAY:
String elementTypeName = TypeUtils.parseAsArrayType(attrInfo.dataType().getName());
if (!ts.getCoreTypes().contains(elementTypeName)) {
Assert.assertTrue(typeCache.has(elementTypeName), elementTypeName + " should be cached");
}
break;
case MAP:
String[] mapTypeNames = TypeUtils.parseAsMapType(attrInfo.dataType().getName());
for (String typeName : mapTypeNames) {
if (!ts.getCoreTypes().contains(typeName)) {
Assert.assertTrue(typeCache.has(typeName), typeName + " should be cached");
}
}
break;
default:
break;
}
}
}
use of org.apache.atlas.typesystem.types.AttributeInfo in project incubator-atlas by apache.
the class Gremlin3ExpressionFactory method generateFieldExpression.
@Override
public GroovyExpression generateFieldExpression(GroovyExpression parent, FieldInfo fInfo, String propertyName, boolean inSelect) {
AttributeInfo attrInfo = fInfo.attrInfo();
IDataType attrType = attrInfo.dataType();
GroovyExpression propertyNameExpr = new LiteralExpression(propertyName);
//Whether it is the user or shared graph does not matter here, since we're
//just getting the conversion expression. Ideally that would be moved someplace else.
AtlasGraph graph = AtlasGraphProvider.getGraphInstance();
if (inSelect) {
GroovyExpression expr = new FunctionCallExpression(parent, PROPERTY_METHOD, propertyNameExpr);
expr = new FunctionCallExpression(expr, OR_ELSE_METHOD, LiteralExpression.NULL);
return graph.generatePersisentToLogicalConversionExpression(expr, attrType);
} else {
GroovyExpression unmapped = new FunctionCallExpression(TraversalStepType.FLAT_MAP_TO_VALUES, parent, VALUES_METHOD, propertyNameExpr);
if (graph.isPropertyValueConversionNeeded(attrType)) {
GroovyExpression toConvert = new FunctionCallExpression(getItVariable(), GET_METHOD);
GroovyExpression conversionFunction = graph.generatePersisentToLogicalConversionExpression(toConvert, attrType);
return new FunctionCallExpression(TraversalStepType.MAP_TO_VALUE, unmapped, MAP_METHOD, new ClosureExpression(conversionFunction));
} else {
return unmapped;
}
}
}
use of org.apache.atlas.typesystem.types.AttributeInfo in project incubator-atlas by apache.
the class DefaultPropertyMapperTest method testToCleanName_specifiedMappings.
@Test
public void testToCleanName_specifiedMappings() {
String typeName = "testType";
HierarchicalType dataType = createNiceMock(HierarchicalType.class);
// currently only use key in map
Map<String, AttributeInfo> fields = new HashMap<>();
fields.put("foo", null);
fields.put("prop", null);
// can't mock FieldMapping due to direct access to final instance var 'fields'
FieldMapping fieldMapping = new FieldMapping(fields, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
// mock expectations
expect(dataType.fieldMapping()).andReturn(fieldMapping).anyTimes();
replay(dataType);
Map<String, String> cleanToQualifiedMap = new HashMap<>();
cleanToQualifiedMap.put("prop1", "property_1");
Map<String, String> qualifiedToCleanMap = new HashMap<>();
qualifiedToCleanMap.put("property_1", "prop1");
PropertyMapper propertyMapper = new TestDefaultPropertyMapper(typeName, qualifiedToCleanMap, cleanToQualifiedMap, dataType);
assertEquals(propertyMapper.toCleanName("property_1", typeName), "prop1");
assertEquals(propertyMapper.toCleanName("Prefix.prop", typeName), "prop");
assertEquals(propertyMapper.toCleanName("foo", typeName), "foo");
assertEquals(propertyMapper.toCleanName("other", typeName), "other");
assertEquals(propertyMapper.toCleanName("Prefix.other", typeName), "Prefix.other");
verify(dataType);
}
use of org.apache.atlas.typesystem.types.AttributeInfo in project incubator-atlas by apache.
the class BaseResourceDefinition method registerProperty.
protected void registerProperty(AttributeDefinition propertyDefinition) {
try {
propertyDefs.put(propertyDefinition.name, propertyDefinition);
properties.put(propertyDefinition.name, new AttributeInfo(typeSystem, propertyDefinition, null));
} catch (AtlasException e) {
throw new CatalogRuntimeException("Unable to create attribute: " + propertyDefinition.name, e);
}
}
use of org.apache.atlas.typesystem.types.AttributeInfo in project incubator-atlas by apache.
the class StructStore method store.
@Override
protected void store(StructInstance instance, int colPos, int pos) throws RepositoryException {
StructInstance s = instance.structs[colPos];
for (Map.Entry<AttributeInfo, IAttributeStore> e : attrStores.entrySet()) {
IAttributeStore attributeStore = e.getValue();
attributeStore.store(pos, structType, s);
}
}
Aggregations