use of org.apache.asterix.lang.common.base.Clause in project asterixdb by apache.
the class AqlExpressionToPlanTranslator method expressionNeedsNoNesting.
@Override
protected boolean expressionNeedsNoNesting(Expression expr) {
boolean isFLWOGR = expr.getKind() == Kind.FLWOGR_EXPRESSION;
boolean letOnly = true;
// No nesting is needed for a FLWOR expression that only has LETs and RETURN.
if (isFLWOGR) {
FLWOGRExpression flwor = (FLWOGRExpression) expr;
for (Clause clause : flwor.getClauseList()) {
letOnly &= clause.getClauseType() == Clause.ClauseType.LET_CLAUSE;
}
}
return (isFLWOGR && letOnly) || super.expressionNeedsNoNesting(expr);
}
use of org.apache.asterix.lang.common.base.Clause in project asterixdb by apache.
the class AqlPlusExpressionToPlanTranslator method visitJoinClause.
@Override
public Pair<ILogicalOperator, LogicalVariable> visitJoinClause(JoinClause jc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
Mutable<ILogicalOperator> opRef = tupSource;
Pair<ILogicalOperator, LogicalVariable> leftSide = null;
for (Clause c : jc.getLeftClauses()) {
leftSide = c.accept(this, opRef);
opRef = new MutableObject<ILogicalOperator>(leftSide.first);
}
opRef = tupSource;
Pair<ILogicalOperator, LogicalVariable> rightSide = null;
for (Clause c : jc.getRightClauses()) {
rightSide = c.accept(this, opRef);
opRef = new MutableObject<ILogicalOperator>(rightSide.first);
}
Pair<ILogicalExpression, Mutable<ILogicalOperator>> whereCond = langExprToAlgExpression(jc.getWhereExpr(), tupSource);
AbstractBinaryJoinOperator join;
switch(jc.getKind()) {
case INNER:
join = new InnerJoinOperator(new MutableObject<ILogicalExpression>(whereCond.first));
break;
case LEFT_OUTER:
join = new LeftOuterJoinOperator(new MutableObject<ILogicalExpression>(whereCond.first));
break;
default:
throw new CompilationException(ErrorCode.COMPILATION_AQLPLUS_NO_SUCH_JOIN_TYPE);
}
join.getInputs().add(new MutableObject<ILogicalOperator>(leftSide.first));
join.getInputs().add(new MutableObject<ILogicalOperator>(rightSide.first));
return new Pair<ILogicalOperator, LogicalVariable>(join, null);
}
use of org.apache.asterix.lang.common.base.Clause in project asterixdb by apache.
the class AqlExpressionToPlanTranslator method visit.
@Override
public Pair<ILogicalOperator, LogicalVariable> visit(FLWOGRExpression flwor, Mutable<ILogicalOperator> tupSource) throws CompilationException {
Mutable<ILogicalOperator> flworPlan = tupSource;
boolean isTop = context.isTopFlwor();
if (!isTop) {
context.enterSubplan();
}
if (isTop) {
context.setTopFlwor(false);
}
for (Clause c : flwor.getClauseList()) {
Pair<ILogicalOperator, LogicalVariable> pC = c.accept(this, flworPlan);
flworPlan = new MutableObject<>(pC.first);
}
Expression r = flwor.getReturnExpr();
boolean noForClause = flwor.noForClause();
Pair<ILogicalOperator, LogicalVariable> result;
if (r.getKind() == Kind.VARIABLE_EXPRESSION) {
VariableExpr v = (VariableExpr) r;
LogicalVariable var = context.getVar(v.getVar().getId());
result = produceFlworPlan(noForClause, isTop, flworPlan, var);
} else {
Mutable<ILogicalOperator> baseOp = new MutableObject<>(flworPlan.getValue());
Pair<ILogicalOperator, LogicalVariable> rRes = r.accept(this, baseOp);
ILogicalOperator rOp = rRes.first;
ILogicalOperator resOp;
if (expressionNeedsNoNesting(r)) {
baseOp.setValue(flworPlan.getValue());
resOp = rOp;
} else {
SubplanOperator s = new SubplanOperator(rOp);
s.getInputs().add(flworPlan);
resOp = s;
baseOp.setValue(new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(s)));
}
Mutable<ILogicalOperator> resOpRef = new MutableObject<>(resOp);
result = produceFlworPlan(noForClause, isTop, resOpRef, rRes.second);
}
if (!isTop) {
context.exitSubplan();
}
return result;
}
use of org.apache.asterix.lang.common.base.Clause in project asterixdb by apache.
the class ClauseComparator method extractLetBindingVariables.
// Extracts the variables to be substituted.
private Map<VariableExpr, Expression> extractLetBindingVariables(List<Clause> clauses, GroupbyClause cuttingGbyClause) throws CompilationException {
Map<VariableExpr, Expression> varExprMap = new HashMap<VariableExpr, Expression>();
int gbyIndex = clauses.indexOf(cuttingGbyClause);
for (int i = gbyIndex + 1; i < clauses.size(); i++) {
Clause cl = clauses.get(i);
if (cl.getClauseType() == ClauseType.LET_CLAUSE) {
LetClause letClause = (LetClause) cl;
// inline let variables one by one iteratively.
letClause.setBindingExpr((Expression) AQLVariableSubstitutionUtil.substituteVariable(letClause.getBindingExpr(), varExprMap));
varExprMap.put(letClause.getVarExpr(), letClause.getBindingExpr());
}
}
return varExprMap;
}
use of org.apache.asterix.lang.common.base.Clause in project asterixdb by apache.
the class ClauseComparator method processLeadingLetClauses.
// Processes leading "let"s in a FLWOGR.
private void processLeadingLetClauses(Integer step, List<Clause> clauseList) throws CompilationException {
List<Clause> processedLetList = new ArrayList<Clause>();
boolean firstLet = true;
int size = clauseList.size();
for (int i = 0; i < size; ++i) {
Clause cl = clauseList.get(i);
if (cl.getClauseType() != ClauseType.LET_CLAUSE) {
break;
}
boolean hasConsequentLet = false;
if (i < size - 1) {
Clause nextCl = clauseList.get(i + 1);
hasConsequentLet = nextCl.getClauseType() == ClauseType.LET_CLAUSE;
}
visitLetClause((LetClause) cl, step, firstLet, hasConsequentLet);
firstLet = false;
processedLetList.add(cl);
}
clauseList.removeAll(processedLetList);
}
Aggregations