Search in sources :

Example 26 with AttributeInfo

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;
        }
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo)

Example 27 with AttributeInfo

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;
        }
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) IDataType(org.apache.atlas.typesystem.types.IDataType) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 28 with AttributeInfo

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);
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) HashMap(java.util.HashMap) FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType) Test(org.testng.annotations.Test)

Example 29 with AttributeInfo

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);
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) CatalogRuntimeException(org.apache.atlas.catalog.exception.CatalogRuntimeException) AtlasException(org.apache.atlas.AtlasException)

Example 30 with AttributeInfo

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);
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) StructInstance(org.apache.atlas.typesystem.persistence.StructInstance) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Aggregations

AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)47 AtlasException (org.apache.atlas.AtlasException)26 HashMap (java.util.HashMap)6 IDataType (org.apache.atlas.typesystem.types.IDataType)6 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)5 FieldMapping (org.apache.atlas.typesystem.types.FieldMapping)5 Map (java.util.Map)4 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)4 HierarchicalType (org.apache.atlas.typesystem.types.HierarchicalType)4 Test (org.testng.annotations.Test)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)3 Id (org.apache.atlas.typesystem.persistence.Id)3 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 ClosureExpression (org.apache.atlas.groovy.ClosureExpression)2 FunctionCallExpression (org.apache.atlas.groovy.FunctionCallExpression)2 GroovyExpression (org.apache.atlas.groovy.GroovyExpression)2 LiteralExpression (org.apache.atlas.groovy.LiteralExpression)2