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);
}
}
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);
}
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));
}
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);
}
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));
}
Aggregations