in asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/rewrite/visitor/GraphixLoweringVisitor.java [128:193]
public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws CompilationException {
SelectExpression selectExpression = (SelectExpression) arg;
if (selectBlock.hasFromClause() && selectBlock.getFromClause() instanceof FromGraphClause) {
FromGraphClause fromGraphClause = (FromGraphClause) selectBlock.getFromClause();
MetadataProvider metadataProvider = graphixRewritingContext.getMetadataProvider();
GraphIdentifier graphIdentifier = fromGraphClause.getGraphIdentifier(metadataProvider);
SourceLocation sourceLocation = fromGraphClause.getSourceLocation();
// Initialize a new lowering environment.
LoweringEnvironment newEnvironment =
new LoweringEnvironment(graphixRewritingContext, graphIdentifier, sourceLocation);
actionFactory.reset(graphIdentifier);
// We will remove the FROM-GRAPH node and replace this with a FROM node on the child visit.
environmentStack.addLast(newEnvironment);
super.visit(selectBlock, arg);
environmentStack.removeLast();
// See if we need to perform a pass for schema enrichment. By default, we decorate "as-needed".
String schemaDecorateVertexKey = SchemaDecorateVertexOption.OPTION_KEY_NAME;
String schemaDecorateEdgeKey = SchemaDecorateEdgeOption.OPTION_KEY_NAME;
IGraphixCompilerOption vertexModeOption = graphixRewritingContext.getSetting(schemaDecorateVertexKey);
IGraphixCompilerOption edgeModeOption = graphixRewritingContext.getSetting(schemaDecorateEdgeKey);
SchemaDecorateVertexOption vertexMode = (SchemaDecorateVertexOption) vertexModeOption;
SchemaDecorateEdgeOption edgeMode = (SchemaDecorateEdgeOption) edgeModeOption;
// See if there are any Graphix functions used in our query.
Set<FunctionIdentifier> graphixFunctionSet = new LinkedHashSet<>();
topLevelSelectExpression.accept(new AbstractGraphixQueryVisitor() {
@Override
public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
FunctionSignature functionSignature = callExpr.getFunctionSignature();
if (functionSignature.getDataverseName().equals(GraphixFunctionIdentifiers.GRAPHIX_DV)) {
FunctionIdentifier functionID = functionSignature.createFunctionIdentifier();
if ((vertexMode == SchemaDecorateVertexOption.NEVER && isVertexFunction(functionID))
|| (edgeMode == SchemaDecorateEdgeOption.NEVER && isEdgeFunction(functionID))) {
throw new CompilationException(ErrorCode.COMPILATION_ERROR, callExpr.getSourceLocation(),
"Schema-decorate mode has been set to 'NEVER', but schema-decoration is required "
+ "to realize the function" + functionSignature + "!");
}
graphixFunctionSet.add(functionID);
}
return super.visit(callExpr, arg);
}
}, null);
// Perform a pass for schema enrichment, if needed.
boolean isVertexModeAlways = vertexMode == SchemaDecorateVertexOption.ALWAYS;
boolean isEdgeModeAlways = edgeMode == SchemaDecorateEdgeOption.ALWAYS;
if (!graphixFunctionSet.isEmpty() || isVertexModeAlways || isEdgeModeAlways) {
SchemaEnrichmentVisitor schemaEnrichmentVisitor = new SchemaEnrichmentVisitor(vertexMode, edgeMode,
elementLookupTable, branchLookupTable, graphIdentifier, selectBlock, graphixFunctionSet);
selectExpression.accept(schemaEnrichmentVisitor, null);
if (selectExpression.hasOrderby()) {
selectExpression.getOrderbyClause().accept(schemaEnrichmentVisitor, null);
}
if (selectExpression.hasLimit()) {
selectExpression.getLimitClause().accept(schemaEnrichmentVisitor, null);
}
}
} else {
super.visit(selectBlock, arg);
}
return null;
}