use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.
the class AQLCloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(ForClause fc, VariableSubstitutionEnvironment env) throws CompilationException {
Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = fc.getInExpr().accept(this, env);
VariableExpr varExpr = fc.getVarExpr();
VariableExpr newVe = generateNewVariable(context, varExpr);
VariableSubstitutionEnvironment resultEnv = new VariableSubstitutionEnvironment(env);
resultEnv.removeSubstitution(varExpr);
VariableExpr newPosVarExpr = null;
if (fc.hasPosVar()) {
VariableExpr posVarExpr = fc.getPosVarExpr();
newPosVarExpr = generateNewVariable(context, posVarExpr);
resultEnv.removeSubstitution(posVarExpr);
}
ForClause newFor = new ForClause(newVe, (Expression) p1.first, newPosVarExpr);
return new Pair<ILangExpression, VariableSubstitutionEnvironment>(newFor, resultEnv);
}
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(RecordConstructor rc, VariableSubstitutionEnvironment env) throws CompilationException {
List<FieldBinding> oldFbs = rc.getFbList();
ArrayList<FieldBinding> newFbs = new ArrayList<>(oldFbs.size());
for (FieldBinding fb : oldFbs) {
Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = fb.getLeftExpr().accept(this, env);
Pair<ILangExpression, VariableSubstitutionEnvironment> p2 = fb.getRightExpr().accept(this, env);
FieldBinding fb2 = new FieldBinding((Expression) p1.first, (Expression) p2.first);
newFbs.add(fb2);
}
RecordConstructor newRc = new RecordConstructor(newFbs);
return new Pair<>(newRc, 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(WhereClause wc, VariableSubstitutionEnvironment env) throws CompilationException {
Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = wc.getWhereExpr().accept(this, env);
WhereClause newW = new WhereClause((Expression) p1.first);
return new Pair<>(newW, p1.second);
}
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(FunctionDecl fd, VariableSubstitutionEnvironment env) throws CompilationException {
List<VarIdentifier> newList = new ArrayList<>(fd.getParamList().size());
for (VarIdentifier vi : fd.getParamList()) {
VariableExpr varExpr = new VariableExpr(vi);
if (!env.constainsOldVar(varExpr)) {
throw new CompilationException("Parameter " + vi + " does not appear in the substitution list.");
}
Expression newExpr = env.findSubstitution(varExpr);
if (newExpr.getKind() != Kind.VARIABLE_EXPRESSION) {
throw new CompilationException("Parameter " + vi + " cannot be substituted by a non-variable expression.");
}
newList.add(((VariableExpr) newExpr).getVar());
}
Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = fd.getFuncBody().accept(this, env);
FunctionDecl newF = new FunctionDecl(fd.getSignature(), newList, (Expression) p1.first);
return new Pair<>(newF, env);
}
use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.
the class Scope method getVarSubstitutionEnvironment.
/**
* @return the variable substituion environment for inlining variable references by its original
*/
public VariableSubstitutionEnvironment getVarSubstitutionEnvironment() {
VariableSubstitutionEnvironment env = new VariableSubstitutionEnvironment();
env.addMappings(varExprMap);
return env;
}
Aggregations