use of org.apache.atlas.groovy.LiteralExpression 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.groovy.LiteralExpression in project incubator-atlas by apache.
the class ExpandOrsOptimization method moveTransformationsToResultExpression.
private GroovyExpression moveTransformationsToResultExpression(GroovyExpression expr, OptimizationContext context) {
GroovyExpression traveralExpression = expr;
// Determine the 'split point'. This is the expression that will become
// the deepest function call in the result expression. If a split
// point is found, its caller is changed. The new caller is
// set to the graph traversal expression in the result expression.
// The original caller becomes the new traversal expression that
// will be carried through the rest of the 'or' expansion processing.
//
// Example: g.V().has('x').as('x').select('x')
// Here, select('x') is the split expression
// so :
// 1) the result expression in OptimizationContext becomes [base result expression].select('x')
// 2) we return g.V().has('x').as('x')
SplitPointFinder finder = new SplitPointFinder(factory);
GremlinQueryOptimizer.visitCallHierarchy(traveralExpression, finder);
AbstractFunctionExpression splitPoint = finder.getSplitPoint();
List<LiteralExpression> aliases = new ArrayList<>();
//the aliases.
if (splitPoint != null) {
traveralExpression = splitPoint.getCaller();
AliasFinder aliasFinder = new AliasFinder();
GremlinQueryOptimizer.visitCallHierarchy(traveralExpression, aliasFinder);
aliases.addAll(aliasFinder.getAliases());
if (aliasFinder.isFinalAliasNeeded()) {
//The last alias in the expression does not capture the final vertex in the traverser,
//so we need to create an alias to record that.
traveralExpression = factory.generateAliasExpression(traveralExpression, context.getFinalAliasName());
aliases.add(new LiteralExpression(context.getFinalAliasName()));
}
GroovyExpression resultExpr = getBaseResultExpression(context, aliases);
splitPoint.setCaller(resultExpr);
expr = removeMapFromPathsIfNeeded(expr, aliases);
context.setResultExpression(expr);
}
//Add expression(s) to the end of the traversal expression to add the vertices
//that were found into the intermediate variable ('r')
traveralExpression = addCallToUpdateResultVariable(traveralExpression, aliases, context);
return traveralExpression;
}
use of org.apache.atlas.groovy.LiteralExpression in project incubator-atlas by apache.
the class Gremlin2ExpressionFactory method getAliasesRequiredByExpression.
public List<String> getAliasesRequiredByExpression(GroovyExpression expr) {
if (!(expr instanceof FunctionCallExpression)) {
return Collections.emptyList();
}
FunctionCallExpression fc = (FunctionCallExpression) expr;
if (!fc.getFunctionName().equals(LOOP_METHOD)) {
return Collections.emptyList();
}
LiteralExpression aliasName = (LiteralExpression) fc.getArguments().get(0);
return Collections.singletonList(aliasName.getValue().toString());
}
use of org.apache.atlas.groovy.LiteralExpression in project incubator-atlas by apache.
the class Gremlin3ExpressionFactory method setRangeParameters.
@Override
public void setRangeParameters(GroovyExpression expr, int startIndex, int endIndex) {
if (isRangeExpression(expr)) {
FunctionCallExpression rangeExpression = (FunctionCallExpression) expr;
rangeExpression.setArgument(0, new LiteralExpression(Integer.valueOf(startIndex)));
rangeExpression.setArgument(1, new LiteralExpression(Integer.valueOf(endIndex)));
} else {
throw new IllegalArgumentException(expr + " is not a valid range expression");
}
}
use of org.apache.atlas.groovy.LiteralExpression in project incubator-atlas by apache.
the class Gremlin3ExpressionFactory method escapePropertyValue.
private GroovyExpression escapePropertyValue(GroovyExpression propertyValue) {
GroovyExpression ret = propertyValue;
if (propertyValue instanceof LiteralExpression) {
LiteralExpression exp = (LiteralExpression) propertyValue;
if (exp != null && exp.getValue() instanceof String) {
String stringValue = (String) exp.getValue();
// replace '*' with ".*", replace '?' with '.'
stringValue = stringValue.replaceAll("\\*", ".*").replaceAll("\\?", ".");
ret = new LiteralExpression(stringValue);
}
}
return ret;
}
Aggregations