public Expression visit()

in asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/rewrite/visitor/PreRewriteCheckVisitor.java [95:138]


    public Expression visit(GraphConstructor graphConstructor, ILangExpression arg) throws CompilationException {
        GraphIdentifier graphIdentifier = ((FromGraphClause) arg).getGraphIdentifier(metadataProvider);
        Schema.Builder schemaBuilder = new Schema.Builder(graphIdentifier);

        // Perform the same validation we do for named graphs-- but don't build the schema object.
        for (GraphConstructor.VertexConstructor vertex : graphConstructor.getVertexElements()) {
            schemaBuilder.addVertex(vertex.getLabel(), vertex.getPrimaryKeyFields(), vertex.getDefinition());
            if (schemaBuilder.getLastError() == Schema.Builder.Error.VERTEX_LABEL_CONFLICT) {
                throw new CompilationException(ErrorCode.COMPILATION_ERROR, vertex.getSourceLocation(),
                        "Conflicting vertex label found: " + vertex.getLabel());

            } else if (schemaBuilder.getLastError() != Schema.Builder.Error.NO_ERROR) {
                throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, vertex.getSourceLocation(),
                        "Constructor vertex was not returned, but the error is not a conflicting vertex label!");
            }
        }
        for (GraphConstructor.EdgeConstructor edge : graphConstructor.getEdgeElements()) {
            schemaBuilder.addEdge(edge.getEdgeLabel(), edge.getDestinationLabel(), edge.getSourceLabel(),
                    edge.getDestinationKeyFields(), edge.getSourceKeyFields(), edge.getDefinition());
            switch (schemaBuilder.getLastError()) {
                case NO_ERROR:
                    continue;

                case SOURCE_VERTEX_NOT_FOUND:
                    throw new CompilationException(ErrorCode.COMPILATION_ERROR, edge.getSourceLocation(),
                            "Source vertex " + edge.getSourceLabel() + " not found in the edge " + edge.getEdgeLabel()
                                    + ".");

                case DESTINATION_VERTEX_NOT_FOUND:
                    throw new CompilationException(ErrorCode.COMPILATION_ERROR, edge.getSourceLocation(),
                            "Destination vertex " + edge.getDestinationLabel() + " not found in the edge "
                                    + edge.getEdgeLabel() + ".");

                case EDGE_LABEL_CONFLICT:
                    throw new CompilationException(ErrorCode.COMPILATION_ERROR, edge.getSourceLocation(),
                            "Conflicting edge label found: " + edge.getEdgeLabel());

                default:
                    throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, edge.getSourceLocation(),
                            "Edge constructor was not returned, and an unexpected error encountered");
            }
        }
        return null;
    }