use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class AQLFormatPrintUtil method toString.
public static String toString(List<ILangExpression> exprs) throws CompilationException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrintWriter output = new PrintWriter(bos);
AQLFormatPrintVisitor visitor = new AQLFormatPrintVisitor(output);
for (ILangExpression expr : exprs) {
expr.accept(visitor, 0);
}
output.close();
return bos.toString();
}
use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class AqlBuiltinFunctionRewriteVisitor method visit.
@Override
public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
FunctionSignature functionSignature = callExpr.getFunctionSignature();
callExpr.setFunctionSignature(CommonFunctionMapUtil.normalizeBuiltinFunctionSignature(functionSignature));
List<Expression> newExprList = new ArrayList<>();
for (Expression expr : callExpr.getExprList()) {
newExprList.add(expr.accept(this, arg));
}
callExpr.setExprList(newExprList);
return callExpr;
}
use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class SqlppCloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(NestClause nestClause, VariableSubstitutionEnvironment env) throws CompilationException {
VariableExpr rightVar = nestClause.getRightVariable();
VariableExpr newRightVar = generateNewVariable(context, rightVar);
VariableExpr newRightPosVar = nestClause.hasPositionalVariable() ? generateNewVariable(context, nestClause.getPositionalVariable()) : null;
// Visits the right expression.
Expression rightExpr = (Expression) nestClause.getRightExpression().accept(this, env).first;
// Visits the condition.
VariableSubstitutionEnvironment currentEnv = new VariableSubstitutionEnvironment(env);
currentEnv.removeSubstitution(newRightVar);
if (newRightPosVar != null) {
currentEnv.removeSubstitution(newRightPosVar);
}
// The condition can refer to the newRightVar and newRightPosVar.
Expression conditionExpr = (Expression) nestClause.getConditionExpression().accept(this, currentEnv).first;
NestClause newJoinClause = new NestClause(nestClause.getJoinType(), rightExpr, newRightVar, newRightPosVar, conditionExpr);
return new Pair<>(newJoinClause, currentEnv);
}
use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class SqlppCloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FromClause fromClause, VariableSubstitutionEnvironment env) throws CompilationException {
VariableSubstitutionEnvironment currentEnv = new VariableSubstitutionEnvironment(env);
List<FromTerm> newFromTerms = new ArrayList<>();
for (FromTerm fromTerm : fromClause.getFromTerms()) {
Pair<ILangExpression, VariableSubstitutionEnvironment> p = fromTerm.accept(this, currentEnv);
newFromTerms.add((FromTerm) p.first);
// A right from term could be correlated from a left from term,
// therefore we propagate the substitution environment.
currentEnv = p.second;
}
return new Pair<>(new FromClause(newFromTerms), currentEnv);
}
use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.
the class SqlppCloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FromTerm fromTerm, VariableSubstitutionEnvironment env) throws CompilationException {
VariableExpr leftVar = fromTerm.getLeftVariable();
VariableExpr newLeftVar = generateNewVariable(context, leftVar);
VariableExpr newLeftPosVar = fromTerm.hasPositionalVariable() ? generateNewVariable(context, fromTerm.getPositionalVariable()) : null;
Expression newLeftExpr = (Expression) visitUnnesBindingExpression(fromTerm.getLeftExpression(), env).first;
List<AbstractBinaryCorrelateClause> newCorrelateClauses = new ArrayList<>();
VariableSubstitutionEnvironment currentEnv = new VariableSubstitutionEnvironment(env);
currentEnv.removeSubstitution(newLeftVar);
if (newLeftPosVar != null) {
currentEnv.removeSubstitution(newLeftPosVar);
}
for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) {
if (correlateClause.getClauseType() == ClauseType.UNNEST_CLAUSE) {
// The right-hand-side of unnest could be correlated with the left side,
// therefore we propagate the substitution environment of the left-side.
Pair<ILangExpression, VariableSubstitutionEnvironment> p = correlateClause.accept(this, currentEnv);
currentEnv = p.second;
newCorrelateClauses.add((AbstractBinaryCorrelateClause) p.first);
} else {
// The right-hand-side of join and nest could not be correlated with the left side,
// therefore we propagate the original substitution environment.
newCorrelateClauses.add((AbstractBinaryCorrelateClause) correlateClause.accept(this, env).first);
// Join binding variables should be removed for further traversal.
currentEnv.removeSubstitution(correlateClause.getRightVariable());
if (correlateClause.hasPositionalVariable()) {
currentEnv.removeSubstitution(correlateClause.getPositionalVariable());
}
}
}
return new Pair<>(new FromTerm(newLeftExpr, newLeftVar, newLeftPosVar, newCorrelateClauses), currentEnv);
}
Aggregations