use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class OperatorExpressionVisitor method visit.
@Override
public Expression visit(OperatorExpr operatorExpr, ILangExpression arg) throws CompilationException {
List<Expression> newExprList = new ArrayList<>();
for (Expression expr : operatorExpr.getExprList()) {
newExprList.add(expr.accept(this, operatorExpr));
}
operatorExpr.setExprList(newExprList);
OperatorType opType = operatorExpr.getOpList().get(0);
switch(opType) {
// There can only be one LIKE/NOT_LIKE/IN/NOT_IN in an operator expression (according to the grammar).
case LIKE:
case NOT_LIKE:
return processLikeOperator(operatorExpr, opType);
case IN:
case NOT_IN:
return processInOperator(operatorExpr, opType);
case CONCAT:
// There can be multiple "||"s in one operator expression (according to the grammar).
return processConcatOperator(operatorExpr);
case BETWEEN:
case NOT_BETWEEN:
return processBetweenOperator(operatorExpr, opType);
default:
break;
}
return operatorExpr;
}
use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class SqlppQueryRewriter method inlineDeclaredUdfs.
protected void inlineDeclaredUdfs() throws CompilationException {
List<FunctionSignature> funIds = new ArrayList<FunctionSignature>();
for (FunctionDecl fdecl : declaredFunctions) {
funIds.add(fdecl.getSignature());
}
List<FunctionDecl> usedStoredFunctionDecls = new ArrayList<>();
for (Expression topLevelExpr : topExpr.getDirectlyEnclosedExpressions()) {
usedStoredFunctionDecls.addAll(FunctionUtil.retrieveUsedStoredFunctions(metadataProvider, topLevelExpr, funIds, null, expr -> getFunctionCalls(expr), func -> functionRepository.getFunctionDecl(func), signature -> FunctionMapUtil.normalizeBuiltinFunctionSignature(signature, false)));
}
declaredFunctions.addAll(usedStoredFunctionDecls);
if (!declaredFunctions.isEmpty()) {
SqlppInlineUdfsVisitor visitor = new SqlppInlineUdfsVisitor(context, new SqlppFunctionBodyRewriterFactory(), /* the rewriter for function bodies expressions*/
declaredFunctions, metadataProvider);
while (topExpr.accept(visitor, declaredFunctions)) {
// loop until no more changes
}
}
declaredFunctions.removeAll(usedStoredFunctionDecls);
}
use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class SqlppInlineUdfsVisitor method extractLetBindingVariableExpressionMappings.
private Map<Expression, Expression> extractLetBindingVariableExpressionMappings(List<LetClause> letClauses) throws CompilationException {
Map<Expression, Expression> varExprMap = new HashMap<>();
for (LetClause lc : letClauses) {
// inline let variables one by one iteratively.
lc.setBindingExpr(SqlppRewriteUtil.substituteExpression(lc.getBindingExpr(), varExprMap, context));
varExprMap.put(lc.getVarExpr(), lc.getBindingExpr());
}
return varExprMap;
}
use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class SqlppListInputFunctionRewriteVisitor method visit.
@Override
public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
List<Expression> newExprList = new ArrayList<>();
for (Expression expr : callExpr.getExprList()) {
newExprList.add(expr.accept(this, arg));
}
callExpr.setExprList(newExprList);
return FunctionMapUtil.normalizedListInputFunctions(callExpr);
}
use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class SubstituteGroupbyExpressionVisitor method visit.
@Override
public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws CompilationException {
if (selectBlock.hasGroupbyClause()) {
Map<Expression, Expression> map = new HashMap<>();
for (GbyVariableExpressionPair gbyKeyPair : selectBlock.getGroupbyClause().getGbyPairList()) {
Expression gbyKeyExpr = gbyKeyPair.getExpr();
if (gbyKeyExpr.getKind() != Kind.VARIABLE_EXPRESSION) {
map.put(gbyKeyExpr, gbyKeyPair.getVar());
}
}
// Creates a substitution visitor.
SubstituteGroupbyExpressionVisitor visitor = new SubstituteGroupbyExpressionVisitor(context, map);
// Rewrites LET/HAVING/SELECT clauses.
if (selectBlock.hasLetClausesAfterGroupby()) {
for (LetClause letClause : selectBlock.getLetListAfterGroupby()) {
letClause.accept(this, arg);
}
}
if (selectBlock.hasHavingClause()) {
selectBlock.getHavingClause().accept(visitor, arg);
}
selectBlock.getSelectClause().accept(visitor, arg);
SelectExpression selectExpression = (SelectExpression) arg;
// For SET operation queries, the GROUP BY key variables will not substitute ORDER BY nor LIMIT expressions.
if (!selectExpression.getSelectSetOperation().hasRightInputs()) {
if (selectExpression.hasOrderby()) {
selectExpression.getOrderbyClause().accept(visitor, arg);
}
if (selectExpression.hasLimit()) {
selectExpression.getLimitClause().accept(visitor, arg);
}
}
}
return super.visit(selectBlock, arg);
}
Aggregations