use of org.vertexium.cypher.exceptions.VertexiumCypherNotImplemented in project vertexium by visallo.
the class MatchClauseExecutor method executeFirstMatchConstraint.
private static IterableWithTotalHits<? extends Element> executeFirstMatchConstraint(VertexiumCypherQueryContext ctx, MatchConstraint<?, ?> matchConstraint, ExpressionScope scope, Long limit) {
try {
List<String> labelNames = getLabelNamesFromMatchConstraint(matchConstraint);
ListMultimap<String, CypherAstBase> propertiesMap = getPropertiesMapFromElementPatterns(ctx, matchConstraint.getPatterns());
QueryResultsIterable<? extends Element> elements;
Query query = ctx.getGraph().query(ctx.getAuthorizations()).limit(limit);
if (labelNames.size() == 0 && propertiesMap.size() == 0) {
elements = executeQuery(ctx, query, matchConstraint);
} else {
if (labelNames.size() > 0) {
Stream<String> labelNamesStream = labelNames.stream().map(ctx::normalizeLabelName);
if (matchConstraint instanceof NodeMatchConstraint) {
query = labelNamesStream.reduce(query, (q, labelName) -> q.has(ctx.getLabelPropertyName(), labelName), (q, q2) -> q);
} else if (matchConstraint instanceof RelationshipMatchConstraint) {
List<String> normalizedLabelNames = labelNamesStream.collect(Collectors.toList());
query = query.hasEdgeLabel(normalizedLabelNames);
} else {
throw new VertexiumCypherNotImplemented("unexpected constraint type: " + matchConstraint.getClass().getName());
}
}
for (Map.Entry<String, CypherAstBase> propertyMatch : propertiesMap.entries()) {
Object value = ctx.getExpressionExecutor().executeExpression(ctx, propertyMatch.getValue(), scope);
if (value instanceof CypherAstBase) {
throw new VertexiumException("unexpected value: " + value.getClass().getName() + ": " + value);
}
if (value instanceof Stream) {
value = ((Stream<?>) value).collect(Collectors.toList());
}
if (value instanceof Collection) {
query.has(propertyMatch.getKey(), Contains.IN, value);
} else {
query.has(propertyMatch.getKey(), value);
}
}
elements = executeQuery(ctx, query, matchConstraint);
}
return elements;
} catch (VertexiumPropertyNotDefinedException e) {
LOGGER.error(e.getMessage());
return new EmptyResultsQueryResultsIterable<>();
}
}
use of org.vertexium.cypher.exceptions.VertexiumCypherNotImplemented in project vertexium by visallo.
the class SetClauseExecutor method executeSetProperty.
private void executeSetProperty(VertexiumCypherQueryContext ctx, CypherSetProperty setItem, VertexiumCypherScope.Item item) {
Object left = ctx.getExpressionExecutor().executeExpression(ctx, setItem.getLeft().getAtom(), item);
VertexiumCypherTypeErrorException.assertType(left, Element.class, null);
if (left == null) {
return;
}
String propertyName = setItem.getLeft().getProperty();
Object value = ctx.getExpressionExecutor().executeExpression(ctx, setItem.getRight(), item);
Element element = (Element) left;
ExistingElementMutation<Element> m = element.prepareMutation();
switch(setItem.getOp()) {
case EQUAL:
if (value == null) {
ctx.removeProperty(m, propertyName);
} else {
ctx.setProperty(m, propertyName, value);
}
break;
default:
throw new VertexiumCypherNotImplemented("" + setItem);
}
ctx.saveElement(m);
}
use of org.vertexium.cypher.exceptions.VertexiumCypherNotImplemented in project vertexium by visallo.
the class ExpressionExecutor method executeExpression.
public Object executeExpression(VertexiumCypherQueryContext ctx, CypherAstBase expression, ExpressionScope scope) {
if (expression == null) {
return null;
}
if (expression instanceof CypherExpression) {
if (expression instanceof CypherBinaryExpression) {
return executeBinaryExpression(ctx, (CypherBinaryExpression) expression, scope);
} else if (expression instanceof CypherComparisonExpression) {
return executeComparisonExpression(ctx, (CypherComparisonExpression) expression, scope);
} else if (expression instanceof CypherUnaryExpression) {
return executeUnaryExpression(ctx, (CypherUnaryExpression) expression, scope);
} else if (expression instanceof CypherTrueExpression) {
return true;
} else if (expression instanceof CypherNegateExpression) {
return executeNegateExpression(ctx, (CypherNegateExpression) expression, scope);
}
throw new VertexiumCypherNotImplemented("" + expression);
}
if (expression instanceof CypherListLiteral) {
// noinspection unchecked
CypherListLiteral<? extends CypherAstBase> list = (CypherListLiteral<? extends CypherAstBase>) expression;
return executeList(ctx, list, scope);
}
if (expression instanceof CypherLiteral) {
CypherLiteral literal = (CypherLiteral) expression;
return literal.getValue();
}
if (expression instanceof CypherVariable) {
CypherVariable variable = (CypherVariable) expression;
return executeObject(ctx, executeVariable(ctx, variable, scope), scope);
}
if (expression instanceof CypherLookup) {
CypherLookup lookup = (CypherLookup) expression;
return executeLookup(ctx, lookup, scope);
}
if (expression instanceof CypherFunctionInvocation) {
CypherFunctionInvocation functionInvocation = (CypherFunctionInvocation) expression;
return executeFunctionInvocation(ctx, functionInvocation, scope);
}
if (expression instanceof CypherIn) {
CypherIn in = (CypherIn) expression;
return executeIn(ctx, in, scope);
}
if (expression instanceof CypherArrayAccess) {
CypherArrayAccess arrayAccess = (CypherArrayAccess) expression;
return executeArrayAccess(ctx, arrayAccess, scope);
}
if (expression instanceof CypherArraySlice) {
CypherArraySlice arraySlice = (CypherArraySlice) expression;
return executeArraySlice(ctx, arraySlice, scope);
}
if (expression instanceof CypherParameter) {
CypherParameter parameter = (CypherParameter) expression;
return executeParameter(ctx, parameter);
}
if (expression instanceof CypherIsNull) {
CypherIsNull isNull = (CypherIsNull) expression;
return executeIsNull(ctx, isNull, scope);
}
if (expression instanceof CypherIsNotNull) {
CypherIsNotNull isNotNull = (CypherIsNotNull) expression;
return executeIsNotNull(ctx, isNotNull, scope);
}
if (expression instanceof CypherListComprehension) {
CypherListComprehension listComprehension = (CypherListComprehension) expression;
return executeListComprehension(ctx, listComprehension, scope);
}
if (expression instanceof CypherStringMatch) {
CypherStringMatch startWith = (CypherStringMatch) expression;
return executeStringMatch(ctx, startWith, scope);
}
if (expression instanceof CypherPatternComprehension) {
CypherPatternComprehension patternComprehension = (CypherPatternComprehension) expression;
VertexiumCypherScope matchScope = scope instanceof VertexiumCypherScope ? (VertexiumCypherScope) scope : VertexiumCypherScope.newSingleItemScope((VertexiumCypherScope.Item) scope);
VertexiumCypherScope results = ctx.getMatchClauseExecutor().execute(ctx, Lists.newArrayList(patternComprehension.getMatchClause()), matchScope);
return results.stream().map(item -> executeExpression(ctx, patternComprehension.getExpression(), item));
}
throw new VertexiumException("not implemented \"" + expression.getClass().getName() + "\": " + expression);
}
Aggregations