Search in sources :

Example 11 with IDataType

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

the class Gremlin3ExpressionFactory method generateHasExpression.

@Override
public GroovyExpression generateHasExpression(GraphPersistenceStrategies s, GroovyExpression parent, String propertyName, String symbol, GroovyExpression requiredValue, FieldInfo fInfo) throws AtlasException {
    AttributeInfo attrInfo = fInfo.attrInfo();
    IDataType attrType = attrInfo.dataType();
    GroovyExpression propertNameExpr = new LiteralExpression(propertyName);
    if (s.isPropertyValueConversionNeeded(attrType)) {
        // for some types, the logical value cannot be stored directly in
        // the underlying graph,
        // and conversion logic is needed to convert the persistent form of
        // the value
        // to the actual value. In cases like this, we generate a conversion
        // expression to
        // do this conversion and use the filter step to perform the
        // comparsion in the gremlin query
        GroovyExpression itExpr = getItVariable();
        GroovyExpression vertexExpr = new CastExpression(new FunctionCallExpression(itExpr, GET_METHOD), VERTEX_CLASS);
        GroovyExpression propertyValueExpr = new FunctionCallExpression(vertexExpr, VALUE_METHOD, propertNameExpr);
        GroovyExpression conversionExpr = s.generatePersisentToLogicalConversionExpression(propertyValueExpr, attrType);
        GroovyExpression propertyIsPresentExpression = new FunctionCallExpression(new FunctionCallExpression(vertexExpr, PROPERTY_METHOD, propertNameExpr), IS_PRESENT_METHOD);
        GroovyExpression valueMatchesExpr = new ComparisonExpression(conversionExpr, getGroovyOperator(symbol), requiredValue);
        GroovyExpression filterCondition = new LogicalExpression(propertyIsPresentExpression, LogicalOperator.AND, valueMatchesExpr);
        GroovyExpression filterFunction = new ClosureExpression(filterCondition);
        return new FunctionCallExpression(TraversalStepType.FILTER, parent, FILTER_METHOD, filterFunction);
    } else {
        GroovyExpression valueMatches = new FunctionCallExpression(getComparisonFunction(symbol), requiredValue);
        return new FunctionCallExpression(TraversalStepType.FILTER, parent, HAS_METHOD, propertNameExpr, valueMatches);
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) ComparisonExpression(org.apache.atlas.groovy.ComparisonExpression) LogicalExpression(org.apache.atlas.groovy.LogicalExpression) LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) CastExpression(org.apache.atlas.groovy.CastExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) IDataType(org.apache.atlas.typesystem.types.IDataType) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 12 with IDataType

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

the class GraphBackedDiscoveryServiceTest method addIndexesForNewTypes.

private void addIndexesForNewTypes(Collection<String> oldTypeNames, final TypeSystem typeSystem) throws AtlasException {
    Set<String> newTypeNames = new HashSet<>();
    newTypeNames.addAll(typeSystem.getTypeNames());
    newTypeNames.removeAll(oldTypeNames);
    Collection<IDataType> newTypes = new ArrayList<>();
    for (String name : newTypeNames) {
        try {
            newTypes.add(typeSystem.getDataType(IDataType.class, name));
        } catch (AtlasException e) {
            e.printStackTrace();
        }
    }
    //We need to commit the transaction before creating the indices to release the locks held by the transaction.
    //otherwise, the index commit will fail while waiting for the those locks to be released.
    AtlasGraphProvider.getGraphInstance().commit();
    GraphBackedSearchIndexer idx = new GraphBackedSearchIndexer(new AtlasTypeRegistry());
    idx.onAdd(newTypes);
}
Also used : GraphBackedSearchIndexer(org.apache.atlas.repository.graph.GraphBackedSearchIndexer) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) IDataType(org.apache.atlas.typesystem.types.IDataType) AtlasException(org.apache.atlas.AtlasException)

Example 13 with IDataType

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

the class DefaultTypeCacheTest method testCacheGetType.

@Test
public void testCacheGetType() throws Exception {
    IDataType custType = cache.get(CLASSTYPE_CUSTOMER);
    verifyType(custType, CLASSTYPE_CUSTOMER, ClassType.class);
    IDataType addrType = cache.get(STRUCTTYPE_ADDRESS);
    verifyType(addrType, STRUCTTYPE_ADDRESS, StructType.class);
    IDataType privTrait = cache.get(TRAITTYPE_PRIVILEGED);
    verifyType(privTrait, TRAITTYPE_PRIVILEGED, TraitType.class);
    IDataType shippingEnum = cache.get(ENUMTYPE_SHIPPING);
    verifyType(shippingEnum, ENUMTYPE_SHIPPING, EnumType.class);
    assertNull(cache.get(UNKNOWN_TYPE));
}
Also used : IDataType(org.apache.atlas.typesystem.types.IDataType) Test(org.testng.annotations.Test)

Example 14 with IDataType

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

the class DefaultTypeCacheTest method testCacheBulkInsert.

@Test
public void testCacheBulkInsert() throws Exception {
    List<IDataType> allTypes = new ArrayList<>();
    allTypes.add(customerType);
    allTypes.add(addressType);
    allTypes.add(privilegedTrait);
    allTypes.add(shippingEnum);
    // create a new cache instead of using the one setup for every method call
    cache = new DefaultTypeCache();
    cache.putAll(allTypes);
    IDataType custType = cache.get(CLASSTYPE_CUSTOMER);
    verifyType(custType, CLASSTYPE_CUSTOMER, ClassType.class);
    IDataType addrType = cache.get(STRUCTTYPE_ADDRESS);
    verifyType(addrType, STRUCTTYPE_ADDRESS, StructType.class);
    IDataType privTrait = cache.get(TRAITTYPE_PRIVILEGED);
    verifyType(privTrait, TRAITTYPE_PRIVILEGED, TraitType.class);
    IDataType shippingEnum = cache.get(ENUMTYPE_SHIPPING);
    verifyType(shippingEnum, ENUMTYPE_SHIPPING, EnumType.class);
}
Also used : ArrayList(java.util.ArrayList) IDataType(org.apache.atlas.typesystem.types.IDataType) Test(org.testng.annotations.Test)

Example 15 with IDataType

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

the class DefaultTypeCacheTest method testCacheGetTypeByCategory.

@Test
public void testCacheGetTypeByCategory() throws Exception {
    IDataType custType = cache.get(TypeCategory.CLASS, CLASSTYPE_CUSTOMER);
    verifyType(custType, CLASSTYPE_CUSTOMER, ClassType.class);
    IDataType addrType = cache.get(TypeCategory.STRUCT, STRUCTTYPE_ADDRESS);
    verifyType(addrType, STRUCTTYPE_ADDRESS, StructType.class);
    IDataType privTrait = cache.get(TypeCategory.TRAIT, TRAITTYPE_PRIVILEGED);
    verifyType(privTrait, TRAITTYPE_PRIVILEGED, TraitType.class);
    IDataType shippingEnum = cache.get(TypeCategory.ENUM, ENUMTYPE_SHIPPING);
    verifyType(shippingEnum, ENUMTYPE_SHIPPING, EnumType.class);
    assertNull(cache.get(UNKNOWN_TYPE));
}
Also used : IDataType(org.apache.atlas.typesystem.types.IDataType) Test(org.testng.annotations.Test)

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