use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class AbstractSqlppExpressionScopingVisitor method visit.
@Override
public Expression visit(GroupbyClause gc, ILangExpression arg) throws CompilationException {
// After a GROUP BY, variables defined before the current SELECT BLOCK (e.g., in a WITH clause
// or an outer scope query) should still be visible.
Scope newScope = new Scope(scopeChecker, scopeChecker.getCurrentScope().getParentScope());
// Puts all group-by variables into the symbol set of the new scope.
for (GbyVariableExpressionPair gbyKeyVarExpr : gc.getGbyPairList()) {
gbyKeyVarExpr.setExpr(visit(gbyKeyVarExpr.getExpr(), gc));
VariableExpr gbyKeyVar = gbyKeyVarExpr.getVar();
if (gbyKeyVar != null) {
addNewVarSymbolToScope(newScope, gbyKeyVar.getVar());
}
}
if (gc.hasGroupFieldList()) {
for (Pair<Expression, Identifier> gbyField : gc.getGroupFieldList()) {
gbyField.first = visit(gbyField.first, arg);
}
}
if (gc.hasDecorList()) {
for (GbyVariableExpressionPair decorVarExpr : gc.getDecorPairList()) {
decorVarExpr.setExpr(visit(decorVarExpr.getExpr(), gc));
VariableExpr decorVar = decorVarExpr.getVar();
if (decorVar != null) {
addNewVarSymbolToScope(newScope, decorVar.getVar());
}
}
}
if (gc.hasGroupVar()) {
addNewVarSymbolToScope(scopeChecker.getCurrentScope(), gc.getGroupVar().getVar());
}
if (gc.hasWithMap()) {
Map<Expression, VariableExpr> newWithMap = new HashMap<>();
for (Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) {
Expression expr = visit(entry.getKey(), arg);
Expression newKey = expr;
VariableExpr value = entry.getValue();
addNewVarSymbolToScope(newScope, value.getVar());
newWithMap.put(newKey, value);
}
gc.setWithVarMap(newWithMap);
}
// Replaces the current scope with the new scope.
scopeChecker.replaceCurrentScope(newScope);
return null;
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class OperatorExpressionVisitor method processInOperator.
private Expression processInOperator(OperatorExpr operatorExpr, OperatorType opType) throws CompilationException {
VariableExpr bindingVar = new VariableExpr(context.newVariable());
Expression itemExpr = operatorExpr.getExprList().get(0);
Expression collectionExpr = operatorExpr.getExprList().get(1);
OperatorExpr comparison = new OperatorExpr();
comparison.addOperand(itemExpr);
comparison.addOperand(bindingVar);
comparison.setCurrentop(true);
if (opType == OperatorType.IN) {
comparison.addOperator("=");
return new QuantifiedExpression(Quantifier.SOME, new ArrayList<>(Collections.singletonList(new QuantifiedPair(bindingVar, collectionExpr))), comparison);
} else {
comparison.addOperator("!=");
return new QuantifiedExpression(Quantifier.EVERY, new ArrayList<>(Collections.singletonList(new QuantifiedPair(bindingVar, collectionExpr))), comparison);
}
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class DeepCopyVisitor method visit.
@Override
public NestClause visit(NestClause nestClause, Void arg) throws CompilationException {
Expression rightExpression = (Expression) nestClause.getRightExpression().accept(this, arg);
VariableExpr rightVar = (VariableExpr) nestClause.getRightVariable().accept(this, arg);
VariableExpr rightPositionVar = nestClause.getPositionalVariable() == null ? null : (VariableExpr) nestClause.getPositionalVariable().accept(this, arg);
Expression conditionExpresion = (Expression) nestClause.getConditionExpression().accept(this, arg);
return new NestClause(nestClause.getJoinType(), rightExpression, rightVar, rightPositionVar, conditionExpresion);
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class DeepCopyVisitor method visit.
@Override
public JoinClause visit(JoinClause joinClause, Void arg) throws CompilationException {
Expression rightExpression = (Expression) joinClause.getRightExpression().accept(this, arg);
VariableExpr rightVar = (VariableExpr) joinClause.getRightVariable().accept(this, arg);
VariableExpr rightPositionVar = joinClause.getPositionalVariable() == null ? null : (VariableExpr) joinClause.getPositionalVariable().accept(this, arg);
Expression conditionExpresion = (Expression) joinClause.getConditionExpression().accept(this, arg);
return new JoinClause(joinClause.getJoinType(), rightExpression, rightVar, rightPositionVar, conditionExpresion);
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class VariableCheckAndRewriteVisitor method visit.
@Override
public Expression visit(FieldAccessor fa, ILangExpression parent) throws CompilationException {
Expression leadingExpr = fa.getExpr();
if (leadingExpr.getKind() != Kind.VARIABLE_EXPRESSION) {
fa.setExpr(leadingExpr.accept(this, fa));
return fa;
} else {
VariableExpr varExpr = (VariableExpr) leadingExpr;
String lastIdentifier = fa.getIdent().getValue();
Expression resolvedExpr = resolve(varExpr, /** Resolves within the dataverse that has the same name as the variable name. */
SqlppVariableUtil.toUserDefinedVariableName(varExpr.getVar().getValue()).getValue(), lastIdentifier, fa, parent);
if (resolvedExpr.getKind() == Kind.CALL_EXPRESSION) {
CallExpr callExpr = (CallExpr) resolvedExpr;
if (callExpr.getFunctionSignature().equals(datasetFunction)) {
// The field access is resolved to be a dataset access in the form of "dataverse.dataset".
return resolvedExpr;
}
}
fa.setExpr(resolvedExpr);
return fa;
}
}
Aggregations