in asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/rewrite/visitor/ElementLookupTableVisitor.java [83:152]
public Expression visit(FromGraphClause fromGraphClause, ILangExpression arg) throws CompilationException {
for (MatchClause m : fromGraphClause.getMatchClauses()) {
m.accept(this, null);
}
GraphConstructor graphConstructor = fromGraphClause.getGraphConstructor();
GraphIdentifier graphIdentifier = fromGraphClause.getGraphIdentifier(metadataProvider);
if (graphConstructor == null) {
DataverseName dataverseName = (fromGraphClause.getDataverseName() == null)
? metadataProvider.getDefaultDataverseName() : fromGraphClause.getDataverseName();
Identifier graphName = fromGraphClause.getGraphName();
// Our query refers to a named graph. First see if we can find this in our declared graph set.
DeclareGraphStatement declaredGraph = declaredGraphs.get(graphIdentifier);
if (declaredGraph != null) {
graphConstructor = declaredGraph.getGraphConstructor();
} else {
// Otherwise, load this from our metadata.
Graph graphFromMetadata;
try {
graphFromMetadata = GraphixMetadataExtension.getGraph(metadataProvider.getMetadataTxnContext(),
dataverseName, graphName.getValue());
if (graphFromMetadata == null) {
throw new CompilationException(ErrorCode.COMPILATION_ERROR, fromGraphClause.getSourceLocation(),
"Graph " + graphName.getValue() + " does not exist.");
}
} catch (AlgebricksException e) {
throw new CompilationException(ErrorCode.COMPILATION_ERROR, fromGraphClause.getSourceLocation(),
"Graph " + graphName.getValue() + " does not exist.");
}
for (Vertex vertex : graphFromMetadata.getGraphSchema().getVertices()) {
if (referencedElementLabels.contains(vertex.getLabel())) {
GraphElementDeclaration vertexDecl = parse(vertex, parserFactory, warningCollector);
elementLookupTable.put(vertex.getIdentifier(), vertexDecl);
elementLookupTable.putVertexKey(vertex.getIdentifier(), vertex.getPrimaryKeyFieldNames());
}
}
for (Edge edge : graphFromMetadata.getGraphSchema().getEdges()) {
if (referencedEdgeLabels.contains(edge.getLabel())) {
GraphElementDeclaration edgeDecl = parse(edge, parserFactory, warningCollector);
elementLookupTable.put(edge.getIdentifier(), edgeDecl);
elementLookupTable.putEdgeKeys(edge.getIdentifier(), edge.getSourceKeyFieldNames(),
edge.getDestinationKeyFieldNames());
}
}
}
}
if (graphConstructor != null) {
for (GraphConstructor.VertexConstructor vertex : graphConstructor.getVertexElements()) {
if (referencedElementLabels.contains(vertex.getLabel())) {
VertexIdentifier identifier = new VertexIdentifier(graphIdentifier, vertex.getLabel());
elementLookupTable.put(identifier, new GraphElementDeclaration(identifier, vertex.getExpression()));
elementLookupTable.putVertexKey(identifier, vertex.getPrimaryKeyFields());
}
}
for (GraphConstructor.EdgeConstructor edge : graphConstructor.getEdgeElements()) {
if (referencedEdgeLabels.contains(edge.getEdgeLabel())) {
EdgeIdentifier identifier = new EdgeIdentifier(graphIdentifier, edge.getSourceLabel(),
edge.getEdgeLabel(), edge.getDestinationLabel());
elementLookupTable.put(identifier, new GraphElementDeclaration(identifier, edge.getExpression()));
elementLookupTable.putEdgeKeys(identifier, edge.getSourceKeyFields(),
edge.getDestinationKeyFields());
}
}
}
return null;
}