in asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/rewrite/visitor/PreRewriteCheckVisitor.java [141:201]
public Expression visit(FromGraphClause fromGraphClause, ILangExpression arg) throws CompilationException {
environmentMap.put(fromGraphClause, new PreRewriteCheckEnvironment());
// Establish the vertex and edge labels associated with this FROM-GRAPH-CLAUSE.
GraphConstructor graphConstructor = fromGraphClause.getGraphConstructor();
if (graphConstructor == null) {
DataverseName dataverseName = (fromGraphClause.getDataverseName() == null)
? metadataProvider.getDefaultDataverseName() : fromGraphClause.getDataverseName();
Identifier graphName = fromGraphClause.getGraphName();
// First, see if we can fetch the graph constructor from our declared graphs.
GraphIdentifier graphIdentifier = fromGraphClause.getGraphIdentifier(metadataProvider);
DeclareGraphStatement declaredGraph = declaredGraphs.get(graphIdentifier);
if (declaredGraph != null) {
graphConstructor = declaredGraph.getGraphConstructor();
} else {
// Otherwise, fetch the graph from our metadata.
try {
Graph graphFromMetadata =
getGraph(metadataProvider.getMetadataTxnContext(), dataverseName, graphName.getValue());
if (graphFromMetadata == null) {
throw new CompilationException(ErrorCode.COMPILATION_ERROR, fromGraphClause.getSourceLocation(),
"Graph " + graphName.getValue() + " does not exist.");
} else {
graphFromMetadata.getGraphSchema().getVertices().stream().map(Vertex::getLabel)
.forEach(environmentMap.get(fromGraphClause).elementLabels::add);
graphFromMetadata.getGraphSchema().getEdges().forEach(e -> {
environmentMap.get(fromGraphClause).elementLabels.add(e.getSourceLabel());
environmentMap.get(fromGraphClause).elementLabels.add(e.getDestinationLabel());
environmentMap.get(fromGraphClause).edgeLabels.add(e.getLabel());
});
}
} catch (AlgebricksException e) {
throw new CompilationException(ErrorCode.COMPILATION_ERROR, fromGraphClause.getSourceLocation(),
"Graph " + graphName.getValue() + " does not exist.");
}
}
}
if (graphConstructor != null) {
graphConstructor.getVertexElements().stream().map(GraphConstructor.VertexConstructor::getLabel)
.forEach(environmentMap.get(fromGraphClause).elementLabels::add);
graphConstructor.getEdgeElements().forEach(e -> {
environmentMap.get(fromGraphClause).elementLabels.add(e.getSourceLabel());
environmentMap.get(fromGraphClause).elementLabels.add(e.getDestinationLabel());
environmentMap.get(fromGraphClause).edgeLabels.add(e.getEdgeLabel());
});
graphConstructor.accept(this, fromGraphClause);
}
// We need to pass our FROM-GRAPH-CLAUSE to our MATCH-CLAUSE.
for (MatchClause matchClause : fromGraphClause.getMatchClauses()) {
matchClause.accept(this, fromGraphClause);
}
for (AbstractBinaryCorrelateClause correlateClause : fromGraphClause.getCorrelateClauses()) {
correlateClause.accept(this, arg);
}
return null;
}