use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class ClauseComparator method collectProducedVariablesFromGroupby.
// Collects produced variables from group-by.
private List<VariableExpr> collectProducedVariablesFromGroupby(GroupbyClause gbyClause) {
List<VariableExpr> producedVars = new ArrayList<VariableExpr>();
for (GbyVariableExpressionPair keyPair : gbyClause.getGbyPairList()) {
producedVars.add(keyPair.getVar());
}
for (GbyVariableExpressionPair keyPair : gbyClause.getDecorPairList()) {
producedVars.add(keyPair.getVar());
}
producedVars.addAll(gbyClause.getWithVarMap().values());
return producedVars;
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class ClauseComparator method extractDefinedCollectionVariables.
// Extracts the variables to be substituted with a path access.
private Map<VariableExpr, Expression> extractDefinedCollectionVariables(List<Clause> clauses, GroupbyClause cuttingGbyClause, String generatedAlias) {
Map<VariableExpr, Expression> varExprMap = new HashMap<VariableExpr, Expression>();
List<VariableExpr> varToSubstitute = collectProducedVariablesFromGroupby(cuttingGbyClause);
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) {
varToSubstitute.add(((LetClause) cl).getVarExpr());
}
}
for (VariableExpr var : varToSubstitute) {
varExprMap.put(var, new FieldAccessor(new VariableExpr(new VarIdentifier(generatedAlias)), new VarIdentifier(var.getVar().getValue().substring(1))));
}
return varExprMap;
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class AqlDeleteRewriteVisitor method visit.
@Override
public Void visit(DeleteStatement deleteStmt, Void visitArg) {
List<Expression> arguments = new ArrayList<>();
Identifier dataverseName = deleteStmt.getDataverseName();
Identifier datasetName = deleteStmt.getDatasetName();
String arg = dataverseName == null ? datasetName.getValue() : dataverseName.getValue() + "." + datasetName.getValue();
LiteralExpr argumentLiteral = new LiteralExpr(new StringLiteral(arg));
arguments.add(argumentLiteral);
CallExpr callExpression = new CallExpr(new FunctionSignature(FunctionConstants.ASTERIX_NS, "dataset", 1), arguments);
List<Clause> clauseList = new ArrayList<>();
VariableExpr var = deleteStmt.getVariableExpr();
Clause forClause = new ForClause(var, callExpression);
clauseList.add(forClause);
Clause whereClause = null;
Expression condition = deleteStmt.getCondition();
if (condition != null) {
whereClause = new WhereClause(condition);
clauseList.add(whereClause);
}
VariableExpr returnExpr = new VariableExpr(var.getVar());
returnExpr.setIsNewVar(false);
FLWOGRExpression flowgr = new FLWOGRExpression(clauseList, returnExpr);
Query query = new Query(false);
query.setBody(flowgr);
deleteStmt.setQuery(query);
return null;
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class AqlQueryRewriter method wrapInLets.
private void wrapInLets() {
// it into a let clause.
if (topStatement == null) {
return;
}
Expression body = topStatement.getBody();
if (body.getKind() != Kind.FLWOGR_EXPRESSION) {
VarIdentifier var = context.newVariable();
VariableExpr v = new VariableExpr(var);
LetClause c1 = new LetClause(v, body);
ArrayList<Clause> clauseList = new ArrayList<>(1);
clauseList.add(c1);
FLWOGRExpression newBody = new FLWOGRExpression(clauseList, new VariableExpr(var));
topStatement.setBody(newBody);
}
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class SqlppCloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(JoinClause joinClause, VariableSubstitutionEnvironment env) throws CompilationException {
VariableExpr rightVar = joinClause.getRightVariable();
VariableExpr newRightVar = generateNewVariable(context, rightVar);
VariableExpr newRightPosVar = joinClause.hasPositionalVariable() ? generateNewVariable(context, joinClause.getPositionalVariable()) : null;
// Visits the right expression.
Expression newRightExpr = (Expression) visitUnnesBindingExpression(joinClause.getRightExpression(), 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) joinClause.getConditionExpression().accept(this, currentEnv).first;
JoinClause newJoinClause = new JoinClause(joinClause.getJoinType(), newRightExpr, newRightVar, newRightPosVar, conditionExpr);
return new Pair<>(newJoinClause, currentEnv);
}
Aggregations