use of org.apache.asterix.lang.common.struct.VarIdentifier 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.struct.VarIdentifier in project asterixdb by apache.
the class AbstractSqlppExpressionScopingVisitor method visit.
@Override
public Expression visit(VariableExpr varExpr, ILangExpression arg) throws CompilationException {
String varName = varExpr.getVar().getValue();
if (scopeChecker.isInForbiddenScopes(varName)) {
throw new CompilationException("Inside limit clauses, it is disallowed to reference a variable having the same name as any variable bound in the same scope as the limit clause.");
}
Identifier ident = scopeChecker.lookupSymbol(varName);
if (ident != null) {
// Exists such an identifier, then this is a variable reference instead of a variable
// definition.
varExpr.setIsNewVar(false);
varExpr.setVar((VarIdentifier) ident);
}
return varExpr;
}
use of org.apache.asterix.lang.common.struct.VarIdentifier in project asterixdb by apache.
the class ExpressionToVariableUtil method getGeneratedVariable.
/**
* Generates a variable according to an expression.
*
* @param expr
* the input expression.
* @param raiseError,
* if it is not possible to generate a variable from the input expression,
* to raise the error if true, and to return a null if false.
* @return the generated variable.
* @throws ParseException
*/
public static VariableExpr getGeneratedVariable(Expression expr, boolean raiseError) throws ParseException {
try {
String varName = getGeneratedIdentifier(expr);
VarIdentifier var = new VarIdentifier(varName);
VariableExpr varExpr = new VariableExpr();
varExpr.setVar(var);
return varExpr;
} catch (ParseException e) {
if (raiseError) {
throw e;
}
return null;
}
}
use of org.apache.asterix.lang.common.struct.VarIdentifier in project asterixdb by apache.
the class VariableCheckAndRewriteVisitor method rewriteNeeded.
// Whether a rewrite is needed for a variable reference expression.
private boolean rewriteNeeded(VariableExpr varExpr) throws CompilationException {
String varName = varExpr.getVar().getValue();
Identifier ident = scopeChecker.lookupSymbol(varName);
if (ident != null) {
// Exists such an identifier
varExpr.setIsNewVar(false);
varExpr.setVar((VarIdentifier) ident);
return false;
} else {
// Meets a undefined variable
return overwrite;
}
}
use of org.apache.asterix.lang.common.struct.VarIdentifier in project asterixdb by apache.
the class DeepCopyVisitor method visit.
@Override
public VariableExpr visit(VariableExpr varExpr, Void arg) throws CompilationException {
VariableExpr clonedVar = new VariableExpr(new VarIdentifier(varExpr.getVar()));
clonedVar.setIsNewVar(varExpr.getIsNewVar());
return clonedVar;
}
Aggregations