public Expression visit()

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


    public Expression visit(VertexPatternExpr vertexExpression, ILangExpression arg) throws CompilationException {
        PreRewriteCheckEnvironment workingEnvironment = environmentMap.get(arg);
        Set<ElementLabel> environmentLabels = workingEnvironment.elementLabels;
        for (ElementLabel elementLabel : vertexExpression.getLabels()) {
            if (environmentLabels.stream().noneMatch(e -> e.getLabelName().equals(elementLabel.getLabelName()))) {
                throw new CompilationException(ErrorCode.COMPILATION_ERROR, vertexExpression.getSourceLocation(),
                        "Vertex label " + elementLabel + " does not exist in the given graph schema.");
            }
        }
        if (vertexExpression.getFilterExpr() != null) {
            vertexExpression.getFilterExpr().accept(new AbstractGraphixQueryVisitor() {
                @Override
                public Expression visit(VariableExpr varExpr, ILangExpression arg) throws CompilationException {
                    if (workingEnvironment.allElementVariables.contains(varExpr.getVar())) {
                        SourceLocation sourceLocation = vertexExpression.getFilterExpr().getSourceLocation();
                        throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLocation,
                                "Cannot reference other graph elements in a filter expression! Consider putting your "
                                        + "condition in a WHERE clause.");
                    }
                    return super.visit(varExpr, arg);
                }
            }, null);
        }
        if (vertexExpression.getVariableExpr() != null && !vertexExpression.getLabels().isEmpty()) {
            Identifier vertexIdentifier = vertexExpression.getVariableExpr().getVar();
            if (workingEnvironment.vertexVariablesWithLabels.contains(vertexIdentifier)) {
                throw new CompilationException(ErrorCode.COMPILATION_ERROR, vertexExpression.getSourceLocation(),
                        "Vertex " + vertexIdentifier + " defined with a label more than once. Labels can only be "
                                + "bound to vertices once.");
            }
            workingEnvironment.vertexVariablesWithLabels.add(vertexIdentifier);
            workingEnvironment.allElementVariables.add(vertexIdentifier);
        }
        return vertexExpression;
    }