use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.
the class MetaKeyExpressionReferenceTransform method transform.
@Override
public boolean transform(Mutable<ILogicalExpression> exprRef) throws AlgebricksException {
ILogicalExpression expr = exprRef.getValue();
if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return false;
}
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
if (!funcExpr.getFunctionIdentifier().equals(BuiltinFunctions.META_KEY)) {
return false;
}
// Function is meta key access
for (int i = 0; i < metaKeyAccessExpressions.size(); i++) {
if (metaKeyAccessExpressions.get(i).equals(funcExpr)) {
exprRef.setValue(new VariableReferenceExpression(keyVars.get(i)));
return true;
}
}
return false;
}
use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.
the class PushAggFuncIntoStandaloneAggregateRule method containsAggregate.
/**
* Recursively check whether the list of expressions contains an aggregate function.
*
* @param exprRefs
* @return true if the list contains an aggregate function and false otherwise.
*/
private boolean containsAggregate(List<Mutable<ILogicalExpression>> exprRefs) {
for (Mutable<ILogicalExpression> exprRef : exprRefs) {
ILogicalExpression expr = exprRef.getValue();
if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
continue;
}
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
FunctionIdentifier funcIdent = BuiltinFunctions.getAggregateFunction(funcExpr.getFunctionIdentifier());
if (funcIdent == null) {
// Recursively look in func args.
if (containsAggregate(funcExpr.getArguments())) {
return true;
}
} else {
// This is an aggregation function.
return true;
}
}
return false;
}
use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.
the class PushAggFuncIntoStandaloneAggregateRule method fingAggFuncExprRef.
private boolean fingAggFuncExprRef(List<Mutable<ILogicalExpression>> exprRefs, LogicalVariable aggVar, List<Mutable<ILogicalExpression>> srcAssignExprRefs) {
for (Mutable<ILogicalExpression> exprRef : exprRefs) {
ILogicalExpression expr = exprRef.getValue();
if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
if (((VariableReferenceExpression) expr).getVariableReference().equals(aggVar)) {
return false;
}
}
if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
continue;
}
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
FunctionIdentifier funcIdent = BuiltinFunctions.getAggregateFunction(funcExpr.getFunctionIdentifier());
if (funcIdent == null) {
// Recursively look in func args.
if (fingAggFuncExprRef(funcExpr.getArguments(), aggVar, srcAssignExprRefs) == false) {
return false;
}
} else {
// Check if this is the expr that uses aggVar.
Collection<LogicalVariable> usedVars = new HashSet<LogicalVariable>();
funcExpr.getUsedVariables(usedVars);
if (usedVars.contains(aggVar)) {
srcAssignExprRefs.add(exprRef);
}
}
}
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.
the class InlineUnnestFunctionRule method inlineVariable.
/**
* This method is to inline one variable
*
* @param usedVar
* A variable that is used by the scan-collection function in the unnest operator
* @param unnestOp
* The unnest operator.
* @throws AlgebricksException
*/
private void inlineVariable(LogicalVariable usedVar, UnnestOperator unnestOp) throws AlgebricksException {
AbstractFunctionCallExpression expr = (AbstractFunctionCallExpression) unnestOp.getExpressionRef().getValue();
List<Pair<AbstractFunctionCallExpression, Integer>> parentAndIndexList = new ArrayList<Pair<AbstractFunctionCallExpression, Integer>>();
getParentFunctionExpression(usedVar, expr, parentAndIndexList);
ILogicalExpression usedVarOrginExpr = findUsedVarOrigin(usedVar, unnestOp, (AbstractLogicalOperator) unnestOp.getInputs().get(0).getValue());
if (usedVarOrginExpr != null) {
for (Pair<AbstractFunctionCallExpression, Integer> parentAndIndex : parentAndIndexList) {
//we only rewrite the top scan-collection function
if (parentAndIndex.first.getFunctionIdentifier() == BuiltinFunctions.SCAN_COLLECTION && parentAndIndex.first == expr) {
unnestOp.getExpressionRef().setValue(usedVarOrginExpr);
}
}
}
}
use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.
the class InlineUnnestFunctionRule method findUsedVarOrigin.
private ILogicalExpression findUsedVarOrigin(LogicalVariable usedVar, AbstractLogicalOperator parentOp, AbstractLogicalOperator currentOp) throws AlgebricksException {
ILogicalExpression ret = null;
if (currentOp.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
List<LogicalVariable> producedVars = new ArrayList<LogicalVariable>();
VariableUtilities.getProducedVariables(currentOp, producedVars);
if (producedVars.contains(usedVar)) {
AssignOperator assignOp = (AssignOperator) currentOp;
int index = assignOp.getVariables().indexOf(usedVar);
ILogicalExpression returnedExpr = assignOp.getExpressions().get(index).getValue();
if (returnedExpr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) returnedExpr;
if (BuiltinFunctions.isBuiltinUnnestingFunction(funcExpr.getFunctionIdentifier())) {
// we only inline for unnest functions
removeUnecessaryAssign(parentOp, currentOp, assignOp, index);
ret = returnedExpr;
}
} else if (returnedExpr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
//recusively inline
VariableReferenceExpression varExpr = (VariableReferenceExpression) returnedExpr;
LogicalVariable var = varExpr.getVariableReference();
ILogicalExpression finalExpr = findUsedVarOrigin(var, currentOp, (AbstractLogicalOperator) currentOp.getInputs().get(0).getValue());
if (finalExpr != null) {
removeUnecessaryAssign(parentOp, currentOp, assignOp, index);
ret = finalExpr;
}
}
}
} else {
for (Mutable<ILogicalOperator> child : currentOp.getInputs()) {
ILogicalExpression expr = findUsedVarOrigin(usedVar, currentOp, (AbstractLogicalOperator) child.getValue());
if (expr != null) {
ret = expr;
}
}
}
return ret;
}
Aggregations