use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.
the class CloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(IndexAccessor ia, VariableSubstitutionEnvironment env) throws CompilationException {
Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = ia.getExpr().accept(this, env);
Expression indexExpr = null;
if (!ia.isAny()) {
Pair<ILangExpression, VariableSubstitutionEnvironment> p2 = ia.getIndexExpr().accept(this, env);
indexExpr = (Expression) p2.first;
}
IndexAccessor i = new IndexAccessor((Expression) p1.first, indexExpr);
i.setAny(ia.isAny());
return new Pair<>(i, env);
}
use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.
the class CloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(QuantifiedExpression qe, VariableSubstitutionEnvironment env) throws CompilationException {
List<QuantifiedPair> oldPairs = qe.getQuantifiedList();
List<QuantifiedPair> newPairs = new ArrayList<>(oldPairs.size());
VariableSubstitutionEnvironment newSubs = env;
for (QuantifiedPair t : oldPairs) {
VariableExpr newVar = generateNewVariable(context, t.getVarExpr());
newSubs = VariableCloneAndSubstitutionUtil.eliminateSubstFromList(newVar, newSubs);
Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = visitUnnesBindingExpression(t.getExpr(), newSubs);
QuantifiedPair t2 = new QuantifiedPair(newVar, (Expression) p1.first);
newPairs.add(t2);
}
Pair<ILangExpression, VariableSubstitutionEnvironment> p2 = qe.getSatisfiesExpr().accept(this, newSubs);
QuantifiedExpression qe2 = new QuantifiedExpression(qe.getQuantifier(), newPairs, (Expression) p2.first);
return new Pair<>(qe2, newSubs);
}
use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.
the class CloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(GroupbyClause gc, VariableSubstitutionEnvironment env) throws CompilationException {
VariableSubstitutionEnvironment newSubs = env;
List<GbyVariableExpressionPair> newGbyList = VariableCloneAndSubstitutionUtil.substInVarExprPair(context, gc.getGbyPairList(), newSubs, this);
List<GbyVariableExpressionPair> newDecorList = gc.hasDecorList() ? VariableCloneAndSubstitutionUtil.substInVarExprPair(context, gc.getDecorPairList(), newSubs, this) : new ArrayList<>();
VariableExpr newGroupVar = null;
if (gc.hasGroupVar()) {
newGroupVar = generateNewVariable(context, gc.getGroupVar());
}
Map<Expression, VariableExpr> newWithMap = new HashMap<>();
if (gc.hasWithMap()) {
for (Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) {
Expression newKeyVar = (Expression) entry.getKey().accept(this, env).first;
VariableExpr newValueVar = generateNewVariable(context, entry.getValue());
newWithMap.put(newKeyVar, newValueVar);
}
}
List<Pair<Expression, Identifier>> newGroupFieldList = new ArrayList<>();
if (gc.hasGroupFieldList()) {
for (Pair<Expression, Identifier> varId : gc.getGroupFieldList()) {
Expression newExpr = (Expression) varId.first.accept(this, env).first;
newGroupFieldList.add(new Pair<>(newExpr, varId.second));
}
}
GroupbyClause newGroup = new GroupbyClause(newGbyList, newDecorList, newWithMap, newGroupVar, newGroupFieldList, gc.hasHashGroupByHint(), gc.isGroupAll());
return new Pair<>(newGroup, newSubs);
}
use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.
the class CloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(OperatorExpr op, VariableSubstitutionEnvironment env) throws CompilationException {
List<Expression> oldExprList = op.getExprList();
List<Expression> exprs = new ArrayList<>(oldExprList.size());
for (Expression e : oldExprList) {
Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = e.accept(this, env);
exprs.add((Expression) p1.first);
}
OperatorExpr oe = new OperatorExpr(exprs, op.getExprBroadcastIdx(), op.getOpList(), op.isCurrentop());
return new Pair<>(oe, env);
}
use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.
the class CloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FieldAccessor fa, VariableSubstitutionEnvironment env) throws CompilationException {
Pair<ILangExpression, VariableSubstitutionEnvironment> p = fa.getExpr().accept(this, env);
FieldAccessor newF = new FieldAccessor((Expression) p.first, fa.getIdent());
return new Pair<>(newF, p.second);
}
Aggregations