use of org.apache.asterix.lang.common.struct.VarIdentifier in project asterixdb by apache.
the class InlineColumnAliasVisitor method mapRecordConstructor.
private Map<Expression, Expression> mapRecordConstructor(RecordConstructor rc) {
Map<Expression, Expression> exprMap = new HashMap<>();
for (FieldBinding binding : rc.getFbList()) {
Expression leftExpr = binding.getLeftExpr();
// (e.g., foo.name AS name) in regular SQL SELECT.
if (leftExpr.getKind() != Kind.LITERAL_EXPRESSION) {
continue;
}
LiteralExpr literalExpr = (LiteralExpr) leftExpr;
if (literalExpr.getValue().getLiteralType() == Literal.Type.STRING) {
String fieldName = SqlppVariableUtil.toInternalVariableName(literalExpr.getValue().getStringValue());
exprMap.put(new VariableExpr(new VarIdentifier(fieldName)), binding.getRightExpr());
}
}
return exprMap;
}
use of org.apache.asterix.lang.common.struct.VarIdentifier in project asterixdb by apache.
the class FunctionParser method getFunctionDecl.
public FunctionDecl getFunctionDecl(Function function) throws CompilationException {
String functionBody = function.getFunctionBody();
List<String> params = function.getParams();
StringBuilder builder = new StringBuilder();
builder.append(" use " + function.getDataverseName() + ";");
builder.append(" declare function " + function.getName().split("@")[0]);
builder.append("(");
for (String param : params) {
VarIdentifier varId = SqlppVariableUtil.toUserDefinedVariableName(param);
builder.append(varId);
builder.append(",");
}
if (params.size() > 0) {
builder.delete(builder.length() - 1, builder.length());
}
builder.append(")");
builder.append("{");
builder.append("\n");
builder.append(functionBody);
builder.append("\n");
builder.append("}");
IParser parser = parserFactory.createParser(new StringReader(new String(builder)));
List<Statement> statements = parser.parse();
FunctionDecl decl = (FunctionDecl) statements.get(1);
return decl;
}
use of org.apache.asterix.lang.common.struct.VarIdentifier in project asterixdb by apache.
the class CloneAndSubstituteVariablesVisitor method generateNewVariable.
/**
* Generates a new variable for an existing variable.
*
* @param context
* , the language rewriting context which keeps all the rewriting variable-int-id to variable-string-identifier mappings.
* @param varExpr
* , the existing variable expression.
* @return the new variable expression.
*/
public VariableExpr generateNewVariable(LangRewritingContext context, VariableExpr varExpr) {
VarIdentifier vi = varExpr.getVar();
VarIdentifier newVar = context.mapOldId(vi.getId(), vi.getValue());
return new VariableExpr(newVar);
}
use of org.apache.asterix.lang.common.struct.VarIdentifier in project asterixdb by apache.
the class Scope method getLiveVariables.
public Set<VariableExpr> getLiveVariables() {
Set<VariableExpr> vars = new HashSet<VariableExpr>();
Iterator<Identifier> identifierIterator = liveSymbols();
while (identifierIterator.hasNext()) {
Identifier identifier = identifierIterator.next();
if (identifier instanceof VarIdentifier) {
vars.add(new VariableExpr((VarIdentifier) identifier));
}
}
return vars;
}
use of org.apache.asterix.lang.common.struct.VarIdentifier 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;
}
Aggregations