Search in sources :

Example 16 with IDataType

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

the class VertexLookupContext method findReferencedInstancesToPreLoad.

private void findReferencedInstancesToPreLoad(ITypedReferenceableInstance newInstance) throws AtlasException {
    //pre-load vertices for reference fields
    for (AttributeInfo info : newInstance.fieldMapping().fields.values()) {
        if (info.dataType().getTypeCategory() == TypeCategory.CLASS) {
            ITypedReferenceableInstance newAttributeValue = (ITypedReferenceableInstance) newInstance.get(info.name);
            addAdditionalInstance(newAttributeValue);
        }
        if (info.dataType().getTypeCategory() == TypeCategory.ARRAY) {
            IDataType elementType = ((DataTypes.ArrayType) info.dataType()).getElemType();
            if (elementType.getTypeCategory() == TypeCategory.CLASS) {
                List<ITypedReferenceableInstance> newElements = (List) newInstance.get(info.name);
                addAdditionalInstances(newElements);
            }
        }
        if (info.dataType().getTypeCategory() == TypeCategory.MAP) {
            IDataType elementType = ((DataTypes.MapType) info.dataType()).getValueType();
            if (elementType.getTypeCategory() == TypeCategory.CLASS) {
                Map<Object, ITypedReferenceableInstance> newAttribute = (Map<Object, ITypedReferenceableInstance>) newInstance.get(info.name);
                if (newAttribute != null) {
                    addAdditionalInstances(newAttribute.values());
                }
            }
        }
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList) List(java.util.List) IDataType(org.apache.atlas.typesystem.types.IDataType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with IDataType

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

the class StoreBackedTypeCache method onTypeFault.

/**
     * Check the type store for the requested type. 
     * If found in the type store, the type and any required super and attribute types
     * are loaded from the type store, and added to the cache.
     */
@Override
public IDataType onTypeFault(String typeName) throws AtlasException {
    // Type is not cached - check the type store.
    // Any super and attribute types needed by the requested type
    // which are not cached will also be loaded from the store.
    Context context = new Context();
    TypesDef typesDef = getTypeFromStore(typeName, context);
    if (typesDef.isEmpty()) {
        // Type not found in the type store.
        return null;
    }
    // Add all types that were loaded from the store to the cache.
    TransientTypeSystem transientTypeSystem = typeSystem.createTransientTypeSystem(context.getTypesDef(), false);
    Map<String, IDataType> typesAdded = transientTypeSystem.getTypesAdded();
    putAll(typesAdded.values());
    return typesAdded.get(typeName);
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef) TransientTypeSystem(org.apache.atlas.typesystem.types.TypeSystem.TransientTypeSystem) IDataType(org.apache.atlas.typesystem.types.IDataType)

Example 18 with IDataType

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

the class DefaultTypeCache method putAll.

/*
     * (non-Javadoc)
     * @see
     * org.apache.atlas.typesystem.types.cache.TypeCache#putAll(java
     * .util.Collection)
     */
@Override
public void putAll(Collection<IDataType> types) throws AtlasException {
    for (IDataType type : types) {
        assertValidType(type);
        types_.put(type.getName(), type);
    }
}
Also used : IDataType(org.apache.atlas.typesystem.types.IDataType)

Example 19 with IDataType

use of org.apache.atlas.typesystem.types.IDataType 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 20 with IDataType

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

the class GraphBackedMetadataRepository method getEntityDefinition.

@Override
@GraphTransaction
public ITypedReferenceableInstance getEntityDefinition(String entityType, String attribute, Object value) throws AtlasException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Retrieving entity with type={} and {}={}", entityType, attribute, value);
    }
    IDataType type = typeSystem.getDataType(IDataType.class, entityType);
    String propertyKey = getFieldNameInVertex(type, attribute);
    AtlasVertex instanceVertex = graphHelper.findVertex(propertyKey, value, Constants.ENTITY_TYPE_PROPERTY_KEY, entityType, Constants.STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name());
    String guid = GraphHelper.getGuid(instanceVertex);
    ITypedReferenceableInstance cached = RequestContext.get().getInstanceV1(guid);
    if (cached != null) {
        return cached;
    }
    return graphToInstanceMapper.mapGraphToTypedInstance(guid, instanceVertex);
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) IDataType(org.apache.atlas.typesystem.types.IDataType) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Aggregations

IDataType (org.apache.atlas.typesystem.types.IDataType)22 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)6 Test (org.testng.annotations.Test)5 ArrayList (java.util.ArrayList)4 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)4 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)4 DataTypes (org.apache.atlas.typesystem.types.DataTypes)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)3 Id (org.apache.atlas.typesystem.persistence.Id)3 List (java.util.List)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 ClassType (org.apache.atlas.typesystem.types.ClassType)2 HashSet (java.util.HashSet)1 Stack (java.util.Stack)1 AtlasException (org.apache.atlas.AtlasException)1