in asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/rewrite/visitor/GraphixLoweringVisitor.java [196:244]
public Expression visit(FromGraphClause fromGraphClause, ILangExpression arg) throws CompilationException {
// Perform an analysis pass over each element body. We need to determine what we can and can't inline.
for (GraphElementDeclaration graphElementDeclaration : elementLookupTable) {
ElementBodyAnalysisVisitor elementBodyAnalysisVisitor = new ElementBodyAnalysisVisitor();
IElementIdentifier elementIdentifier = graphElementDeclaration.getIdentifier();
graphElementDeclaration.getNormalizedBody().accept(elementBodyAnalysisVisitor, null);
analysisContextMap.put(elementIdentifier, elementBodyAnalysisVisitor.getElementBodyAnalysisContext());
}
LoweringEnvironment workingEnvironment = environmentStack.getLast();
// TODO (GLENN): Perform smarter analysis to determine when a vertex / edge is inlineable w/ LEFT-MATCH.
Stream<MatchClause> matchClauseStream = fromGraphClause.getMatchClauses().stream();
workingEnvironment.setInlineLegal(matchClauseStream.noneMatch(c -> c.getMatchType() == MatchType.LEFTOUTER));
// Lower our MATCH-CLAUSEs. We should be working with canonical-ized patterns.
for (MatchClause matchClause : fromGraphClause.getMatchClauses()) {
if (matchClause.getMatchType() == MatchType.LEFTOUTER) {
workingEnvironment.beginLeftMatch();
}
for (PathPatternExpr pathPatternExpr : matchClause.getPathExpressions()) {
for (EdgePatternExpr edgePatternExpr : pathPatternExpr.getEdgeExpressions()) {
edgePatternExpr.accept(this, fromGraphClause);
}
for (VertexPatternExpr vertexPatternExpr : pathPatternExpr.getVertexExpressions()) {
VariableExpr vertexVariableExpr = vertexPatternExpr.getVariableExpr();
if (aliasLookupTable.getIterationAlias(vertexVariableExpr) != null) {
continue;
}
workingEnvironment.acceptAction(actionFactory.buildDanglingVertexAction(vertexPatternExpr));
}
workingEnvironment.acceptAction(actionFactory.buildPathPatternAction(pathPatternExpr));
}
if (matchClause.getMatchType() == MatchType.LEFTOUTER) {
workingEnvironment.endLeftMatch();
}
}
workingEnvironment.acceptAction(actionFactory.buildMatchSemanticAction(fromGraphClause));
// Finalize our lowering by moving our lower list to our environment.
workingEnvironment.endLowering(fromGraphClause);
// Add our correlate clauses, if any, to our tail FROM-TERM.
if (!fromGraphClause.getCorrelateClauses().isEmpty()) {
LowerListClause lowerClause = (LowerListClause) fromGraphClause.getLowerClause();
ClauseCollection clauseCollection = lowerClause.getClauseCollection();
fromGraphClause.getCorrelateClauses().forEach(clauseCollection::addUserDefinedCorrelateClause);
}
return null;
}